-
Notifications
You must be signed in to change notification settings - Fork 438
feat(clerk-react,astro,vue): Add appearance option to modal components #5125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexcarpenter
merged 10 commits into
main
from
alexcarpenter/sdki-863-add-appearance-option-to-signinbutton-signupbutton
Feb 11, 2025
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1830fa9
feat(react): Add appearance option to modal components
alexcarpenter 2e34fd1
add changeset
alexcarpenter f7bf109
appearance is optional
alexcarpenter e07cdbc
extract type to clerk/types
alexcarpenter c1c724e
add changeset
alexcarpenter 9f5ae19
Delete .changeset/yellow-bats-provide.md
alexcarpenter f10339f
refactor to use PropsWithChildren
alexcarpenter 4b8057b
add changeset
alexcarpenter 356f547
Apply suggestions from code review
alexcarpenter d691864
feat(astro): Add appearance option to Astro unstyled components (#5134)
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@clerk/astro': patch | ||
| '@clerk/clerk-react': patch | ||
| '@clerk/types': patch | ||
alexcarpenter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| '@clerk/vue': patch | ||
| --- | ||
|
|
||
| Add the ability to specify an appearance for modal component usages. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| Extract common button component props. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,48 @@ | ||
| import type { SignInProps } from '@clerk/types'; | ||
| import type { SignInButtonProps, SignInProps } from '@clerk/types'; | ||
| import React from 'react'; | ||
|
|
||
| import type { SignInButtonProps } from './types'; | ||
| import { assertSingleChild, normalizeWithDefaultValue, safeExecute, withClerk, type WithClerkProp } from './utils'; | ||
|
|
||
| export type { SignInButtonProps }; | ||
|
|
||
| export const SignInButton = withClerk(({ clerk, children, ...props }: WithClerkProp<SignInButtonProps>) => { | ||
| const { signUpFallbackRedirectUrl, forceRedirectUrl, fallbackRedirectUrl, signUpForceRedirectUrl, mode, ...rest } = | ||
| props; | ||
| children = normalizeWithDefaultValue(children, 'Sign in'); | ||
| const child = assertSingleChild(children)('SignInButton'); | ||
|
|
||
| const clickHandler = () => { | ||
| const opts: SignInProps = { | ||
| forceRedirectUrl, | ||
| fallbackRedirectUrl, | ||
| signUpFallbackRedirectUrl, | ||
| signUpForceRedirectUrl, | ||
| export const SignInButton = withClerk( | ||
| ({ clerk, children, ...props }: WithClerkProp<React.PropsWithChildren<SignInButtonProps>>) => { | ||
| const { signUpFallbackRedirectUrl, forceRedirectUrl, fallbackRedirectUrl, signUpForceRedirectUrl, mode, ...rest } = | ||
| props; | ||
| children = normalizeWithDefaultValue(children, 'Sign in'); | ||
| const child = assertSingleChild(children)('SignInButton'); | ||
|
|
||
| const clickHandler = () => { | ||
| const opts: SignInProps = { | ||
| forceRedirectUrl, | ||
| fallbackRedirectUrl, | ||
| signUpFallbackRedirectUrl, | ||
| signUpForceRedirectUrl, | ||
| }; | ||
|
|
||
| if (!clerk) { | ||
| return; | ||
| } | ||
|
|
||
| if (mode === 'modal') { | ||
| return clerk.openSignIn({ ...opts, appearance: props.appearance }); | ||
| } | ||
| return clerk.redirectToSignIn({ | ||
| ...opts, | ||
| signInFallbackRedirectUrl: fallbackRedirectUrl, | ||
| signInForceRedirectUrl: forceRedirectUrl, | ||
| }); | ||
| }; | ||
|
|
||
| if (!clerk) { | ||
| return; | ||
| } | ||
|
|
||
| if (mode === 'modal') { | ||
| return clerk.openSignIn(opts); | ||
| } | ||
| return clerk.redirectToSignIn({ | ||
| ...opts, | ||
| signInFallbackRedirectUrl: fallbackRedirectUrl, | ||
| signInForceRedirectUrl: forceRedirectUrl, | ||
| }); | ||
| }; | ||
|
|
||
| const wrappedChildClickHandler: React.MouseEventHandler = async e => { | ||
| if (child && typeof child === 'object' && 'props' in child) { | ||
| await safeExecute(child.props.onClick)(e); | ||
| } | ||
| return clickHandler(); | ||
| }; | ||
|
|
||
| const childProps = { ...rest, onClick: wrappedChildClickHandler }; | ||
| return React.cloneElement(child as React.ReactElement<unknown>, childProps); | ||
| }, 'SignInButton'); | ||
| const wrappedChildClickHandler: React.MouseEventHandler = async e => { | ||
| if (child && typeof child === 'object' && 'props' in child) { | ||
| await safeExecute(child.props.onClick)(e); | ||
| } | ||
| return clickHandler(); | ||
| }; | ||
|
|
||
| const childProps = { ...rest, onClick: wrappedChildClickHandler }; | ||
| return React.cloneElement(child as React.ReactElement<unknown>, childProps); | ||
| }, | ||
| 'SignInButton', | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,58 @@ | ||
| import type { SignUpProps } from '@clerk/types'; | ||
| import type { SignUpButtonProps, SignUpProps } from '@clerk/types'; | ||
| import React from 'react'; | ||
|
|
||
| import type { SignUpButtonProps } from './types'; | ||
| import { assertSingleChild, normalizeWithDefaultValue, safeExecute, withClerk, type WithClerkProp } from './utils'; | ||
|
|
||
| export type { SignUpButtonProps }; | ||
|
|
||
| export const SignUpButton = withClerk(({ clerk, children, ...props }: WithClerkProp<SignUpButtonProps>) => { | ||
| const { | ||
| fallbackRedirectUrl, | ||
| forceRedirectUrl, | ||
| signInFallbackRedirectUrl, | ||
| signInForceRedirectUrl, | ||
| mode, | ||
| unsafeMetadata, | ||
| ...rest | ||
| } = props; | ||
|
|
||
| children = normalizeWithDefaultValue(children, 'Sign up'); | ||
| const child = assertSingleChild(children)('SignUpButton'); | ||
|
|
||
| const clickHandler = () => { | ||
| const opts: SignUpProps = { | ||
| export const SignUpButton = withClerk( | ||
| ({ clerk, children, ...props }: WithClerkProp<React.PropsWithChildren<SignUpButtonProps>>) => { | ||
| const { | ||
| fallbackRedirectUrl, | ||
| forceRedirectUrl, | ||
| signInFallbackRedirectUrl, | ||
| signInForceRedirectUrl, | ||
| mode, | ||
| unsafeMetadata, | ||
| ...rest | ||
| } = props; | ||
|
|
||
| children = normalizeWithDefaultValue(children, 'Sign up'); | ||
| const child = assertSingleChild(children)('SignUpButton'); | ||
|
|
||
| const clickHandler = () => { | ||
| const opts: SignUpProps = { | ||
| fallbackRedirectUrl, | ||
| forceRedirectUrl, | ||
| signInFallbackRedirectUrl, | ||
| signInForceRedirectUrl, | ||
| unsafeMetadata, | ||
| }; | ||
|
|
||
| if (!clerk) { | ||
| return; | ||
| } | ||
|
|
||
| if (mode === 'modal') { | ||
| return clerk.openSignUp({ ...opts, appearance: props.appearance }); | ||
| } | ||
|
|
||
| return clerk.redirectToSignUp({ | ||
| ...opts, | ||
| signUpFallbackRedirectUrl: fallbackRedirectUrl, | ||
| signUpForceRedirectUrl: forceRedirectUrl, | ||
| }); | ||
| }; | ||
|
|
||
| if (!clerk) { | ||
| return; | ||
| } | ||
|
|
||
| if (mode === 'modal') { | ||
| return clerk.openSignUp(opts); | ||
| } | ||
|
|
||
| return clerk.redirectToSignUp({ | ||
| ...opts, | ||
| signUpFallbackRedirectUrl: fallbackRedirectUrl, | ||
| signUpForceRedirectUrl: forceRedirectUrl, | ||
| }); | ||
| }; | ||
|
|
||
| const wrappedChildClickHandler: React.MouseEventHandler = async e => { | ||
| if (child && typeof child === 'object' && 'props' in child) { | ||
| await safeExecute(child.props.onClick)(e); | ||
| } | ||
| return clickHandler(); | ||
| }; | ||
|
|
||
| const childProps = { ...rest, onClick: wrappedChildClickHandler }; | ||
| return React.cloneElement(child as React.ReactElement<unknown>, childProps); | ||
| }, 'SignUpButton'); | ||
| const wrappedChildClickHandler: React.MouseEventHandler = async e => { | ||
| if (child && typeof child === 'object' && 'props' in child) { | ||
| await safeExecute(child.props.onClick)(e); | ||
| } | ||
| return clickHandler(); | ||
| }; | ||
|
|
||
| const childProps = { ...rest, onClick: wrappedChildClickHandler }; | ||
| return React.cloneElement(child as React.ReactElement<unknown>, childProps); | ||
| }, | ||
| 'SignUpButton', | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,9 @@ | ||
| import type { SignInProps, SignUpProps } from '@clerk/types'; | ||
| import type { SignInButtonProps as _SignInButtonProps, SignUpButtonProps as _SignUpButtonProps } from '@clerk/types'; | ||
|
|
||
| // TODO-SHARED: Duplicate from @clerk/clerk-react | ||
| type ButtonProps = { | ||
| mode?: 'redirect' | 'modal'; | ||
| export type SignInButtonProps = _SignInButtonProps & { | ||
| children?: React.ReactNode; | ||
| }; | ||
|
|
||
| // TODO-SHARED: Duplicate from @clerk/clerk-react | ||
| export type SignInButtonProps = ButtonProps & | ||
| Pick< | ||
| SignInProps, | ||
| 'fallbackRedirectUrl' | 'forceRedirectUrl' | 'signUpForceRedirectUrl' | 'signUpFallbackRedirectUrl' | ||
| >; | ||
|
|
||
| // TODO-SHARED: Duplicate from @clerk/clerk-react | ||
| export type SignUpButtonProps = { | ||
| unsafeMetadata?: SignUpUnsafeMetadata; | ||
| } & ButtonProps & | ||
| Pick< | ||
| SignUpProps, | ||
| 'fallbackRedirectUrl' | 'forceRedirectUrl' | 'signInForceRedirectUrl' | 'signInFallbackRedirectUrl' | ||
| >; | ||
| export type SignUpButtonProps = _SignUpButtonProps & { | ||
| children?: React.ReactNode; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.