Skip to content

Commit fade95c

Browse files
authored
chore(astro): Remove deprecated as prop from unstyled components (#7839)
1 parent e5933b5 commit fade95c

File tree

9 files changed

+50
-86
lines changed

9 files changed

+50
-86
lines changed

.changeset/metal-buckets-occur.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@clerk/astro': major
3+
---
4+
5+
Remove deprecated `as` prop from unstyled button components (`SignInButton`, `SignUpButton`, `SignOutButton`, `CheckoutButton`, `PlanDetailsButton`, `SubscriptionDetailsButton`). Use the `asChild` prop with a custom element in the default slot instead.
6+
7+
**Before:**
8+
9+
```astro
10+
<SignInButton as="a" href="/sign-in">
11+
Sign in
12+
</SignInButton>
13+
```
14+
15+
**After:**
16+
17+
```astro
18+
<SignInButton asChild>
19+
<a href="/sign-in">Sign in</a>
20+
</SignInButton>
21+
```

packages/astro/src/astro-components/unstyled/CheckoutButton.astro

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
---
2-
import type { HTMLTag, Polymorphic } from 'astro/types';
32
import type { __experimental_CheckoutButtonProps } from '@clerk/shared/types';
43
import type { ButtonProps } from '../../types';
5-
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils';
4+
import { addUnstyledAttributeToFirstTag } from './utils';
65
7-
type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> &
6+
type Props = ButtonProps &
87
Omit<__experimental_CheckoutButtonProps, 'onSubscriptionComplete'> & { clickIdentifier?: string };
98
109
import { generateSafeId } from '@clerk/astro/internal';
1110
1211
const safeId = generateSafeId();
1312
14-
if ('as' in Astro.props) {
15-
logAsPropUsageDeprecation();
16-
}
17-
1813
const {
19-
as: Tag = 'button',
2014
asChild,
2115
planId,
2216
planPeriod,
@@ -48,12 +42,12 @@ if (asChild) {
4842
asChild ? (
4943
<Fragment set:html={htmlElement} />
5044
) : (
51-
<Tag
45+
<button
5246
{...props}
5347
data-clerk-unstyled-id={safeId}
5448
>
5549
<slot>Checkout</slot>
56-
</Tag>
50+
</button>
5751
)
5852
}
5953

packages/astro/src/astro-components/unstyled/PlanDetailsButton.astro

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
---
2-
import type { HTMLTag, Polymorphic } from 'astro/types';
32
import type { __experimental_PlanDetailsButtonProps } from '@clerk/shared/types';
43
import type { ButtonProps } from '../../types';
5-
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils';
4+
import { addUnstyledAttributeToFirstTag } from './utils';
65
7-
type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> & __experimental_PlanDetailsButtonProps;
6+
type Props = ButtonProps & __experimental_PlanDetailsButtonProps;
87
98
import { generateSafeId } from '@clerk/astro/internal';
109
1110
const safeId = generateSafeId();
1211
13-
if ('as' in Astro.props) {
14-
logAsPropUsageDeprecation();
15-
}
16-
17-
const { as: Tag = 'button', asChild, plan, planId, initialPlanPeriod, planDetailsProps, ...props } = Astro.props;
12+
const { asChild, plan, planId, initialPlanPeriod, planDetailsProps, ...props } = Astro.props;
1813
1914
const planDetailsOptions = {
2015
plan,
@@ -35,12 +30,12 @@ if (asChild) {
3530
asChild ? (
3631
<Fragment set:html={htmlElement} />
3732
) : (
38-
<Tag
33+
<button
3934
{...props}
4035
data-clerk-unstyled-id={safeId}
4136
>
4237
<slot>Plan details</slot>
43-
</Tag>
38+
</button>
4439
)
4540
}
4641

packages/astro/src/astro-components/unstyled/SignInButton.astro

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
---
2-
import type { HTMLTag, Polymorphic } from 'astro/types';
32
import type { SignInButtonProps } from '@clerk/shared/types';
43
import type { ButtonProps } from '../../types';
5-
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils';
4+
import { addUnstyledAttributeToFirstTag } from './utils';
65
7-
type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> & SignInButtonProps;
6+
type Props = ButtonProps & SignInButtonProps;
87
98
import { generateSafeId } from '@clerk/astro/internal';
109
1110
const safeId = generateSafeId();
1211
13-
if ('as' in Astro.props) {
14-
logAsPropUsageDeprecation();
15-
}
16-
1712
const {
18-
as: Tag = 'button',
1913
asChild,
2014
forceRedirectUrl,
2115
fallbackRedirectUrl,
@@ -44,12 +38,12 @@ if (asChild) {
4438
asChild ? (
4539
<Fragment set:html={htmlElement} />
4640
) : (
47-
<Tag
41+
<button
4842
{...props}
4943
data-clerk-unstyled-id={safeId}
5044
>
5145
<slot>Sign in</slot>
52-
</Tag>
46+
</button>
5347
)
5448
}
5549

packages/astro/src/astro-components/unstyled/SignOutButton.astro

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
---
2-
import type { HTMLTag, Polymorphic } from 'astro/types';
3-
import type { SignOutOptions, Without } from '@clerk/shared/types';
2+
import type { SignOutOptions } from '@clerk/shared/types';
43
import type { ButtonProps } from '../../types';
5-
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils';
4+
import { addUnstyledAttributeToFirstTag } from './utils';
65
7-
type Props<Tag extends HTMLTag = 'button'> = Polymorphic<SignOutOptions & ButtonProps<Tag>>;
6+
type Props = SignOutOptions & ButtonProps;
87
98
import { generateSafeId } from '@clerk/astro/internal';
109
1110
const safeId = generateSafeId();
1211
13-
if ('as' in Astro.props) {
14-
logAsPropUsageDeprecation();
15-
}
16-
17-
const { as: Tag = 'button', asChild, redirectUrl = '/', sessionId, ...elementProps } = Astro.props;
12+
const { asChild, redirectUrl = '/', sessionId, ...elementProps } = Astro.props;
1813
1914
let htmlElement = '';
2015
@@ -28,12 +23,12 @@ if (asChild) {
2823
asChild ? (
2924
<Fragment set:html={htmlElement} />
3025
) : (
31-
<Tag
26+
<button
3227
{...elementProps}
3328
data-clerk-unstyled-id={safeId}
3429
>
3530
<slot>Sign out</slot>
36-
</Tag>
31+
</button>
3732
)
3833
}
3934

packages/astro/src/astro-components/unstyled/SignUpButton.astro

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
---
2-
import type { HTMLTag, Polymorphic } from 'astro/types';
32
import type { SignUpButtonProps } from '@clerk/shared/types';
43
import type { ButtonProps } from '../../types';
5-
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils';
4+
import { addUnstyledAttributeToFirstTag } from './utils';
65
7-
type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> & SignUpButtonProps;
6+
type Props = ButtonProps & SignUpButtonProps;
87
98
import { generateSafeId } from '@clerk/astro/internal';
109
1110
const safeId = generateSafeId();
1211
13-
if ('as' in Astro.props) {
14-
logAsPropUsageDeprecation();
15-
}
16-
1712
const {
18-
as: Tag = 'button',
1913
asChild,
2014
fallbackRedirectUrl,
2115
forceRedirectUrl,
@@ -46,12 +40,12 @@ if (asChild) {
4640
asChild ? (
4741
<Fragment set:html={htmlElement} />
4842
) : (
49-
<Tag
43+
<button
5044
{...props}
5145
data-clerk-unstyled-id={safeId}
5246
>
5347
<slot>Sign up</slot>
54-
</Tag>
48+
</button>
5549
)
5650
}
5751

packages/astro/src/astro-components/unstyled/SubscriptionDetailsButton.astro

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
---
22
import type { __experimental_SubscriptionDetailsButtonProps } from '@clerk/shared/types';
3-
4-
import type { HTMLTag, Polymorphic } from 'astro/types';
53
import type { ButtonProps } from '../../types';
6-
import { addUnstyledAttributeToFirstTag, logAsPropUsageDeprecation } from './utils';
4+
import { addUnstyledAttributeToFirstTag } from './utils';
75
8-
type Props<Tag extends HTMLTag = 'button'> = Polymorphic<ButtonProps<Tag>> &
6+
type Props = ButtonProps &
97
Omit<__experimental_SubscriptionDetailsButtonProps, 'onSubscriptionCancel'> & { clickIdentifier?: string };
108
119
import { generateSafeId } from '@clerk/astro/internal';
1210
1311
const safeId = generateSafeId();
1412
15-
if ('as' in Astro.props) {
16-
logAsPropUsageDeprecation();
17-
}
18-
19-
const { as: Tag = 'button', asChild, for: _for, clickIdentifier, subscriptionDetailsProps, ...props } = Astro.props;
13+
const { asChild, for: _for, clickIdentifier, subscriptionDetailsProps, ...props } = Astro.props;
2014
2115
const subscriptionDetailsOptions = {
2216
for: _for,
@@ -36,12 +30,12 @@ if (asChild) {
3630
asChild ? (
3731
<Fragment set:html={htmlElement} />
3832
) : (
39-
<Tag
33+
<button
4034
{...props}
4135
data-clerk-unstyled-id={safeId}
4236
>
4337
<slot>Subscription details</slot>
44-
</Tag>
38+
</button>
4539
)
4640
}
4741

packages/astro/src/astro-components/unstyled/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,3 @@
55
export function addUnstyledAttributeToFirstTag(html: string, attributeValue: string): string {
66
return html.replace(/(<[^>]+)>/, `$1 data-clerk-unstyled-id="${attributeValue}">`);
77
}
8-
9-
/**
10-
* Logs a deprecation warning when the 'as' prop is used.
11-
*/
12-
export function logAsPropUsageDeprecation() {
13-
if (import.meta.env.PROD) {
14-
return;
15-
}
16-
17-
console.warn(
18-
`[@clerk/astro] The 'as' prop is deprecated and will be removed in a future version. ` +
19-
`Use the default slot with the 'asChild' prop instead. `,
20-
);
21-
}

packages/astro/src/types.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,7 @@ export type {
8383
// Backward compatibility alias
8484
export type ProtectProps = ProtectParams;
8585

86-
export type ButtonProps<Tag> = {
87-
/**
88-
* @deprecated The `'as'` prop will be removed in a future version.
89-
* Use the default slot with the `'asChild'` prop instead.
90-
* @example
91-
* <SignInButton asChild>
92-
* <button>Sign in</button>
93-
* </SignInButton>
94-
*/
95-
as: Tag;
86+
export type ButtonProps = {
9687
asChild?: boolean;
9788
};
9889

0 commit comments

Comments
 (0)