export type ValidationRule = (value: T) => string | undefined; export interface FieldConfig { /** Initial value */ initialValue: T; /** Validation rules (return error string or undefined) */ validate?: ValidationRule[]; /** Whether field is required */ required?: boolean; /** Custom required message */ requiredMessage?: string; } export interface FormFieldState { value: T; error?: string; touched: boolean; dirty: boolean; } export interface UseFormValidationOptions> { /** Field configurations */ fields: { [K in keyof T]: FieldConfig; }; /** Validate on change (default: only after blur) */ validateOnChange?: boolean; /** Validate on blur (default: true) */ validateOnBlur?: boolean; } export interface UseFormValidationResult> { /** Current form values */ values: T; /** Field errors */ errors: Partial>; /** Which fields have been touched (blurred) */ touched: Partial>; /** Which fields have been modified */ dirty: Partial>; /** Whether the form is valid */ isValid: boolean; /** Whether any field has been modified */ isDirty: boolean; /** Set a field value */ setValue: (field: K, value: T[K]) => void; /** Set multiple values at once */ setValues: (values: Partial) => void; /** Mark a field as touched (trigger validation) */ setTouched: (field: keyof T) => void; /** Validate a single field */ validateField: (field: keyof T) => string | undefined; /** Validate all fields */ validateAll: () => boolean; /** Reset form to initial values */ reset: () => void; /** Reset a single field */ resetField: (field: keyof T) => void; /** Get props for an input field */ getFieldProps: (field: K) => { value: T[K]; onChange: (e: React.ChangeEvent) => void; onBlur: () => void; name: string; 'aria-invalid': boolean; }; /** Get error message for a field (only if touched) */ getFieldError: (field: keyof T) => string | undefined; } /** * useFormValidation Hook * * A comprehensive form validation hook with touched state tracking, * field-level validation, and accessibility support. * * @example * ```tsx * const { values, errors, getFieldProps, getFieldError, validateAll, isValid } = useFormValidation({ * fields: { * email: { * initialValue: '', * required: true, * requiredMessage: 'Email is required', * validate: [ * (v) => !v.includes('@') ? 'Invalid email format' : undefined, * ], * }, * password: { * initialValue: '', * required: true, * validate: [ * (v) => v.length < 8 ? 'Password must be at least 8 characters' : undefined, * ], * }, * }, * }); * * const handleSubmit = (e: FormEvent) => { * e.preventDefault(); * if (validateAll()) { * // Submit form * } * }; * * return ( *
* * {getFieldError('email') && {getFieldError('email')}} * * * {getFieldError('password') && {getFieldError('password')}} * * *
* ); * ``` */ export declare function useFormValidation>({ fields, validateOnChange, validateOnBlur, }: UseFormValidationOptions): UseFormValidationResult; export default useFormValidation; //# sourceMappingURL=useFormValidation.d.ts.map