import { useForm } from 'react-hook-form'; import { Button } from '@/components/button'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/components/form'; import { Input } from '@/components/input'; import type { Entry } from './types'; /** `displayName` for `chrome/lib/codegen.ts` — see `ControlledSortDemo` in `./data`. */ function ProfileForm() { const form = useForm<{ username: string; website: string }>({ defaultValues: { username: '', website: '' }, mode: 'onSubmit', }); return (
{ /* Nothing to submit to — the point is the validation display. */ })} > ( Username Shown next to everything you publish. )} /> ( Website )} /> ); } ProfileForm.displayName = 'ProfileForm'; export const form: Entry = { slug: 'form', name: 'Form', group: 'Forms', description: 'react-hook-form bound to the kit’s field anatomy: FormControl wires id, aria-describedby and aria-invalid from the field state, so an error is announced rather than only coloured. It is deliberately absent from the root barrel — react-hook-form is an *optional* peer dependency, and re-exporting it would break every consumer that has not installed it. Import it only at the subpath.', imports: { subpath: 'form', names: ['Form', 'FormField', 'FormItem'] }, compositions: [ { name: 'Validated fields', description: 'Submit with the fields empty to see FormMessage take over from FormDescription.', render: () => , }, ], };