- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
A frontmatter (YAML metadata) editor over Field, whose fields bind each control to one key of the document and show the error the caller computes.
Installation#
pnpm dlx shadcn@latest add @zui/frontmatter-formThe CLI writes components/data-entry/frontmatter-form.tsx and installs Field
with the items it needs.
Usage#
import {
FrontmatterForm,
FrontmatterFormField,
FrontmatterFormFieldControl,
FrontmatterFormFieldError,
FrontmatterFormFieldLabel,
} from '@/components/data-entry/frontmatter-form';
import { Input } from '@/components/ui/input';<FrontmatterForm value={value} onValueChange={setValue}>
<FrontmatterFormField name="name">
<FrontmatterFormFieldLabel>Name</FrontmatterFormFieldLabel>
<FrontmatterFormFieldControl render={<Input aria-label="Name" placeholder="my-skill" />} />
<FrontmatterFormFieldError />
</FrontmatterFormField>
</FrontmatterForm>The caller composes one FrontmatterFormField per key and owns every label, hint (FieldDescription), control
and validation rule; the component ships no rules of its own. Bind a non-text control, such as a Switch, through
useFrontmatterFormField instead of FrontmatterFormFieldControl.
Composition#
FrontmatterForm
`-- FrontmatterFormField
|-- FrontmatterFormFieldLabel
|-- FrontmatterFormFieldControl
`-- FrontmatterFormFieldErrorInvalid fields#
<FrontmatterForm value={value} onValueChange={setValue} errors={value.name ? {} : { name: 'A name is required.' }}>
<FrontmatterFormField name="name">
<FrontmatterFormFieldLabel>Name</FrontmatterFormFieldLabel>
<FrontmatterFormFieldControl render={<Input aria-label="Name" placeholder="my-skill" />} />
<FrontmatterFormFieldError />
</FrontmatterFormField>
</FrontmatterForm>A field whose key errors holds draws its label in the destructive colour, its control with the destructive
border, and the message below it, which a screen reader announces as it appears. The control is given the message
as its accessibilityHint, since React Native announces no aria-invalid.
API reference#
useFrontmatterFormField#
useFrontmatterFormField(): { name: string; value: unknown; setValue: (fieldValue: unknown) => void; error: string | undefined; labelId: string } - reads the current field's binding. labelId is the label's nativeID, which a
control names in aria-labelledby. Use it to bind a control FrontmatterFormFieldControl does not cover (a Switch,
a tag input). Throws outside a FrontmatterFormField.
FrontmatterForm#
Takes every prop of FieldGroup, plus:
| Prop | Type | Default |
|---|---|---|
value | FrontmatterFormValue | required |
onValueChange | (value: FrontmatterFormValue) => void | required |
errors | Record<string, string> | {} |
The root holds the document and its field setters; FrontmatterFormValue is an object of arbitrary keys, values
usually strings. A change reports the whole document with that key set.
FrontmatterFormField#
Takes every prop of Field, plus:
| Prop | Type | Default |
|---|---|---|
name | string | required |
One field, bound to name, invalid while the root's errors hold name.
FrontmatterFormFieldLabel#
Takes every prop of FieldLabel except nativeID, which it sets to the
field's labelId.
FrontmatterFormFieldControl#
| Prop | Type | Default |
|---|---|---|
render | ReactElement<FrontmatterFormFieldControlElementProps> | required |
Clones render, the text control to bind, such as <Input placeholder="my-skill" /> or <Textarea />, with the
field's value as a string (a missing one as empty), onChangeText, aria-invalid and aria-labelledby naming the
label, which replace its own. While the field is invalid the error replaces its accessibilityHint; while it is
valid its own hint stays. Its own onChangeText still runs, before the field's.
FrontmatterFormFieldError#
Takes every prop of FieldError. The current field's message from the root's
errors; draws nothing while the field is valid.
Differences from the web#
- The label names its control through its
nativeIDand the control'saria-labelledby, which Android reads; iOS reads only the control's ownaria-label, so give the control one too, as the demo does. Pressing the label does not focus the control. - The error reaches a screen reader as the control's
accessibilityHint, in place of the web'saria-describedby. The hook giveslabelIdin place of the web'scontrolIdanderrorId. onChangeTextstands in for the web'sonChange.- The label's container-query classes are not set; a horizontal Field already lets its label grow.
- The web's
data-slotanddata-invalidattributes are not set; a View takes no data attributes.