-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Add support for
showOptionalFields
layout prop (#4198)
- Loading branch information
1 parent
6275c24
commit 5e0da19
Showing
3 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
--- | ||
--- |
This file contains 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 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,11 +1,34 @@ | ||
import type { Attribute, AttributeData } from '@clerk/types'; | ||
|
||
import { useAppearance } from '~/contexts'; | ||
|
||
import { useEnvironment } from './use-environment'; | ||
|
||
export function useAttributes(attribute: Attribute): AttributeData { | ||
const environment = useEnvironment(); | ||
|
||
const userSettingsAttributes = environment.userSettings.attributes; | ||
|
||
return userSettingsAttributes[attribute]; | ||
} | ||
|
||
type SignUpAttributeData = AttributeData & { | ||
/** | ||
* Should the field be visible to the user durning sign up flow. | ||
*/ | ||
show: boolean; | ||
}; | ||
|
||
/** | ||
* Custom attributes for sign up flow that includes whether or not a field should be shown | ||
* based on enabled/required and showOptionalFields layout prop. | ||
*/ | ||
export function useSignUpAttributes(attribute: Attribute): SignUpAttributeData { | ||
const attr = useAttributes(attribute); | ||
const { layout } = useAppearance().parsedAppearance; | ||
const { showOptionalFields } = layout; | ||
|
||
return { | ||
...attr, | ||
show: (showOptionalFields || attr.required) && attr.enabled, | ||
}; | ||
} |