/** * @fileoverview Form primitive — form field wrappers integrating React Hook Form with accessible labels, * descriptions, and error messages. Uses Radix UI Slot for composable form controls. * Part of the Saasflare base component layer. * @module packages/ui/components/ui/form * @layer core * * @requires react-hook-form — peer dependency. * @requires @hookform/resolvers — peer dependency (for zod/yup/etc resolver glue). * @requires zod — peer dependency (or substitute schema lib via @hookform/resolvers). * * @component * @example * import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from '@saasflare/ui'; *
* ( * * Email * * * * )} /> * */ import * as React from "react"; import type * as LabelPrimitive from "@radix-ui/react-label"; import * as Slot from "@radix-ui/react-slot"; import { type ControllerProps, type FieldPath, type FieldValues } from "react-hook-form"; import { type SaasflareComponentProps } from "../../providers"; /** * Form root — re-export of react-hook-form's `FormProvider`. Spread the object * returned by `useForm()` into it to make form state available to nested * {@link FormField} compositions. * * @component * @layer core */ declare const Form: (props: import("react-hook-form").FormProviderProps) => React.JSX.Element; /** * Controlled field binding — wraps react-hook-form's `Controller` and exposes * the field name via context so {@link useFormField} can resolve ids and * validation state for the label, control, description, and message. * * @component * @layer core */ declare const FormField: = FieldPath>({ ...props }: ControllerProps) => import("react/jsx-runtime").JSX.Element; /** * Resolves the current field's accessibility wiring and validation state. * Returns the field `id`/`name`, the derived `formItemId`, `formDescriptionId`, * and `formMessageId`, plus the react-hook-form field state (`error`, * `invalid`, `isDirty`, `isTouched`). Must be called inside both * `` and ``, under a `
` provider — throws otherwise. */ declare const useFormField: () => { invalid: boolean; isDirty: boolean; isTouched: boolean; isValidating: boolean; error?: import("react-hook-form").FieldError; id: string; name: string; formItemId: string; formDescriptionId: string; formMessageId: string; }; /** * Field wrapper — generates the unique id shared by label, control, * description, and message, and stacks them in a vertical grid. * * @component * @layer core */ declare function FormItem({ className, ...props }: React.ComponentProps<"div">): import("react/jsx-runtime").JSX.Element; /** * Props for {@link FormLabel}. Extends {@link SaasflareComponentProps} so * `surface`, `radius`, `animated`, and `iconWeight` can override the * context per instance. */ interface FormLabelProps extends Omit, keyof SaasflareComponentProps>, SaasflareComponentProps { } /** * Field label — wired to the control via `htmlFor` and tinted destructive when * the field has a validation error. * * @component * @layer core */ declare function FormLabel({ className, surface, radius, animated, iconWeight, ...props }: FormLabelProps): import("react/jsx-runtime").JSX.Element; /** * Slot that wires the wrapped input to its label, description, and message via * `id`, `aria-describedby`, and `aria-invalid`. Place the actual form control * as its single child. * * @component * @layer core */ declare function FormControl({ ...props }: React.ComponentProps): import("react/jsx-runtime").JSX.Element; /** * Props for {@link FormDescription}. Extends {@link SaasflareComponentProps} * for per-instance `surface` / `radius` / `animated` / `iconWeight` overrides. */ interface FormDescriptionProps extends Omit, keyof SaasflareComponentProps>, SaasflareComponentProps { } /** * Muted helper text below the control, referenced by the control's * `aria-describedby`. * * @component * @layer core */ declare function FormDescription({ className, surface, radius, animated, iconWeight, ...props }: FormDescriptionProps): import("react/jsx-runtime").JSX.Element; /** * Props for {@link FormMessage}. Extends {@link SaasflareComponentProps} * for per-instance `surface` / `radius` / `animated` / `iconWeight` overrides. */ interface FormMessageProps extends Omit, keyof SaasflareComponentProps>, SaasflareComponentProps { } /** * Validation message — shows the field's error message when present, otherwise * its children; renders nothing when both are empty. * * @component * @layer core */ declare function FormMessage({ className, surface, radius, animated, iconWeight, ...props }: FormMessageProps): import("react/jsx-runtime").JSX.Element | null; export { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, type FormLabelProps, type FormDescriptionProps, type FormMessageProps, };