Form
A form wrapper that provides validation, error handling, and accessible form controls. Built to work with React Hook Form and Zod for schema-based validation.
Preview
Usage
tsx
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import {
Form,
FormField,
FormItem,
FormLabel,
FormControl,
FormMessage,
} from "zostel-ui";
import { Input } from "zostel-ui";
import { Button } from "zostel-ui";
const schema = z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Invalid email"),
});
function BookingForm() {
const form = useForm({
resolver: zodResolver(schema),
});
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
form | UseFormReturn | — | The form instance from react-hook-form useForm(). |
children | ReactNode | — | Form content including FormField components. |
formType:
UseFormReturnDefault: —
The form instance from react-hook-form useForm().
childrenType:
ReactNodeDefault: —
Form content including FormField components.
Sub-components
| Prop | Type | Default | Description |
|---|---|---|---|
FormField | component | — | Connects a form field to react-hook-form with control and name props. |
FormItem | component | — | Wraps a form field with consistent spacing. |
FormLabel | component | — | An accessible label connected to the form field. |
FormControl | component | — | Wraps the input control with aria attributes. |
FormDescription | component | — | Helper text displayed below the input. |
FormMessage | component | — | Displays validation error messages. |
FormFieldType:
componentDefault: —
Connects a form field to react-hook-form with control and name props.
FormItemType:
componentDefault: —
Wraps a form field with consistent spacing.
FormLabelType:
componentDefault: —
An accessible label connected to the form field.
FormControlType:
componentDefault: —
Wraps the input control with aria attributes.
FormDescriptionType:
componentDefault: —
Helper text displayed below the input.
FormMessageType:
componentDefault: —
Displays validation error messages.