Add the Nook "Form" component to this project, exactly as Nook ships it.
A form whose fields explain their own errors.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add form`. It writes `components/ui/form.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/form.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Field, FieldControl, FieldDescription, FieldError, FieldLabel, Form } from "@/components/ui/form";
import { Textarea } from "@/components/ui/textarea";
export default function FormDefault() {
const [sent, setSent] = React.useState(false);
return (
);
}
```
API
- `Form`: The form.
- `onFormSubmit` (`(values) => void`): Called with the values as an object when every field is valid.
- `errors` (`Record`): Errors from the server, by field name.
- `validationMode` (`"onSubmit" | "onBlur" | "onChange"`, default "onSubmit"): When fields are checked.
- `Field`: One labelled control.
- `name` (`string`): Ties the field to the form values and errors.
- `validate` (`(value) => string | null`): A custom rule. Return the error text, or null.
- `disabled` (`boolean`): Disables the control and dims the label.
- `FieldControl`: The control: an Input unless `render` says otherwise.
- `render` (`ReactElement`, default ): Another control, such as ``.
- `FieldLabel, FieldDescription`: The label and the hint.
- `FieldError`: The error text.
- `match` (`keyof ValidityState | boolean`): Show only for one kind of problem, such as `valueMissing`.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Each label, hint and error is tied to its control. On submit, focus moves to the first field with a problem and its error is announced. Errors are text with an underline, never color alone.
Done when the component renders like the example in light and dark mode and the project type-checks.