Skip to content
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

docs(elements): Add docs for FieldState config field #1330

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/elements/reference/common.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ By having access to both `message` and `code` you can enrich the incoming `messa

Enables you to programmatically access additional information from the parent `<Field>` component. By default, you'll have access to `state`. `state` will also contain the field's [`ValidityState`](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState). `<FieldState>` is useful for implementing animations if you need direct access to the `state` value.

If you use `<Input type="password" validatePassword>`, additional information in the form of `message` and `codes` is provided.
If you use `<Input type="password" validatePassword>`, additional information in the form of `message`, `codes`, and `config` is provided.

### Properties {{ toc: false }}

| Name | Type | Description |
| - | - | - |
| `children` | `(args: { state: 'success' \| 'error' \| 'warning' \| 'info' \| 'idle'; message: string \| undefined; codes: ErrorMessageKey[] \| undefined }) => React.ReactNode` | Use this function to access the field's state. Optionally, information regarding password validation is given. |
| `children` | `(args: { state: 'success' \| 'error' \| 'warning' \| 'info' \| 'idle'; message: string \| undefined; codes: ErrorMessageKey[] \| undefined, config: PasswordConfig }) => React.ReactNode` | Use this function to access the field's state. Optionally, information regarding password validation is given. |

### Usage {{ toc: false }}

Expand All @@ -137,8 +137,11 @@ If you use `<Input type="password" validatePassword>`, additional information in

If you're using [`<Input type="password" validatePassword>`](#input-type-password), the `<FieldState>`'s children function receives additional arguments:

- `message` - The standardized English message generated for the current state of the input. This message is generated based on the codes associated with the `<FieldState>`.
- `codes` - The codes associated with the `<FieldState>`. You can use these codes to return custom `message` or localize its contents.
| Name | Type | Description |
| - | - | - |
| `message` | `string` | The standardized English message generated for the current state of the input. This message is generated based on the codes associated with the `<FieldState>`. |
| `codes` | `string[]` | The codes associated with the `<FieldState>`. You can use these codes to return a custom `message` or localize its contents. |
| `config` | `{ allowed_special_characters: string; min_length: number; max_length: number; require_special_char: boolean; require_numbers: boolean; require_uppercase: boolean; require_lowercase: boolean; }` | The password complexity configuration for your application. |

Initially, the `<Input>` will have a `state` of `idle` until the user interacts with the input. Depending on the user's input, the `state` will change to `'success' | 'error' | 'warning' | 'info'`.

Expand All @@ -147,11 +150,12 @@ Initially, the `<Input>` will have a `state` of `idle` until the user interacts
<Clerk.Label>Password</Clerk.Label>
<Clerk.Input type="password" validatePassword />
<Clerk.FieldState>
{({ state, codes, message }) => (
{({ state, codes, message, config }) => (
<div>
<pre>Field state: {state}</pre>
<pre>Field msg: {message}</pre>
<pre>Codes: {codes?.join(', ')}</pre>
<pre>Config: {JSON.stringify(config, null, 2)}</pre>
</div>
)}
</Clerk.FieldState>
Expand Down
Loading