-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: selectField w/ required error message
- Loading branch information
1 parent
eda10d6
commit e7e2e71
Showing
6 changed files
with
57 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Meta, Markdown } from "@storybook/blocks"; | ||
|
||
import Config from "./config.md?raw"; | ||
|
||
<Meta title="fields/selectField" /> | ||
|
||
# `selectField<Value = string>(): ValidatedFieldAtom<Value | undefined>` | ||
|
||
A generic choice field to hold a key of some options e.g. in `<input type="radio" />` or `<select />` elements. | ||
The `undefined` empty value means that no option is selected. | ||
|
||
```ts | ||
import { selectField } from "@form-atoms/field"; | ||
|
||
// required string, must be filled to submit | ||
const favoriteCategory = selectField(); | ||
|
||
// optional string, can be empty to submit | ||
const companySize = selectField({ optional: true }); | ||
``` | ||
|
||
## Initial Config | ||
|
||
<Markdown>{Config}</Markdown> | ||
|
||
## Examples | ||
|
||
### Number select | ||
|
||
By default the select field works with `string` values. You can specify your own type. For example to make a rating field with choices 1-5 | ||
you will need a `numericSelectField`: | ||
|
||
```ts | ||
import { selectField } from "@form-atoms/field"; | ||
import { useFieldActions } from "form-atoms"; | ||
|
||
const rating = selectField<number>({ schema: z.number() }); | ||
|
||
const actions = useFieldActions(rating); | ||
|
||
actions.setValue("4"); // ERR! | ||
actions.setValue(4); // OK | ||
``` |
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,5 @@ | ||
| Param | Value | | ||
| ---------------- | ------------------- | | ||
| `value` | `undefined` | | ||
| `schema` | `z.string()` | | ||
| `optionalSchema` | `schema.optional()` | |
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