clerk / javascript

Official Javascript repository for Clerk authentication
https://clerk.com
MIT License
1.12k stars 246 forks source link

chore(astro): Allow child elements in unstyled Astro components #4122

Closed wobsoriano closed 1 month ago

wobsoriano commented 1 month ago

Description

This PR adds the option to use custom elements/components inside our unstyled components, similar to the React counterpart, and adds a deprecation notice for the as prop.

With this change, we can now do:

---
import { SignInButton } from '@clerk/components/astro'
---
<SignInButton asChild>
  <button>Sign in with Clerk</button>
</SignInButton>

The new asChild prop determines if we should render the default slot as an element or just a string. We need this prop because Astro doesn't have a way to determine if a slot contains an element/component or a string.

Previously, we used the as prop to render a different element:

---
import { SignInButton } from '@clerk/components/astro'
---
<SignInButton as="button">
  Sign in with Clerk
</SignInButton>

The problem with the old approach was that we couldn't use an existing component or inherit styles. This PR offers better flexibility.

Resolves ECO-187

Checklist

Type of change

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: 034c3024251b73697fcb7a521ef9fb747bc413ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------ | ----- | | @clerk/astro | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR