UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

55 lines (54 loc) 2.62 kB
import { UseFormProps } from 'react-hook-form'; import { z } from 'zod'; type FieldValues = Record<string, unknown>; /** * Enhanced version of [react-hook-form's useForm](https://react-hook-form.com/docs/useform). * Provides Zod schema validation and additional utilities for form handling. * * Features: * - Zod schema validation * - Form-level error handling * - Async submission handling * - Submit button state management * * @example * ```tsx * const form = useForm({ * formSchema: z.object({ * email: z.email(), * password: z.string().min(8) * }) * }); * ``` */ export declare const useForm: <Schema extends z.ZodType<FieldValues, FieldValues>, Context>({ formSchema, ...props }: UseFormProps<z.input<Schema>, Context, z.output<Schema>> & { formSchema: Schema; }) => { submitAsync: () => Promise<z.core.output<Schema>>; formError: (Record<string, Partial<{ type: string | number; message: import('react-hook-form').Message; }>> & Partial<{ type: string | number; message: import('react-hook-form').Message; }>) | undefined; setFormError: (error: unknown, options?: Parameters<import('react-hook-form').UseFormSetError<z.core.input<Schema>>>[2]) => void; isSubmitDisabled: boolean; handleSubmit: import('react-hook-form').UseFormHandleSubmit<z.core.input<Schema>, z.core.output<Schema>>; watch: import('react-hook-form').UseFormWatch<z.core.input<Schema>>; getValues: import('react-hook-form').UseFormGetValues<z.core.input<Schema>>; getFieldState: import('react-hook-form').UseFormGetFieldState<z.core.input<Schema>>; setError: import('react-hook-form').UseFormSetError<z.core.input<Schema>>; clearErrors: import('react-hook-form').UseFormClearErrors<z.core.input<Schema>>; setValue: import('react-hook-form').UseFormSetValue<z.core.input<Schema>>; trigger: import('react-hook-form').UseFormTrigger<z.core.input<Schema>>; formState: import('react-hook-form').FormState<z.core.input<Schema>>; resetField: import('react-hook-form').UseFormResetField<z.core.input<Schema>>; reset: import('react-hook-form').UseFormReset<z.core.input<Schema>>; unregister: import('react-hook-form').UseFormUnregister<z.core.input<Schema>>; control: import('react-hook-form').Control<z.core.input<Schema>, Context, z.core.output<Schema>>; register: import('react-hook-form').UseFormRegister<z.core.input<Schema>>; setFocus: import('react-hook-form').UseFormSetFocus<z.core.input<Schema>>; subscribe: import('react-hook-form').UseFormSubscribe<z.core.input<Schema>>; }; export {};