import type { ChangeEvent } from 'react'; export type UseFieldOptions = { /** Name of the field. Required. */ name: string; /** Value of the field. @default '' */ value?: T; /** If the field is changed. @default false */ touched?: boolean; /** If the field is disabled. @default false */ disabled?: boolean; /** If the field is required. @default false */ required?: boolean; /** If the field is loading. @default false */ loading?: boolean; /** What the field will validate on. */ showValidationOn?: 'blur' | 'change'; /** Error message if field is invalid. @default 'This field is required.' */ requiredErrorMessage?: string; /** If the field should have a validation function. @default {} */ validation?: { [key: string]: ((value: T) => boolean) | RegExp }; }; export type UseFieldProps< T extends string | boolean = string, Element = HTMLInputElement, > = { name: string; disabled: boolean; required: boolean; errorMessage: string | undefined; isValid: boolean; onChange: (event: ChangeEvent) => void; onFocus: UseFieldResults['untouch']; } & (T extends boolean ? { checked: T } : { value: T; loading?: boolean }); export type UseFieldResults< T extends string | boolean = string, Element = HTMLInputElement, > = { /** Returns the default values of the field. */ initial: { value: T; errorMessage: string; isLoading: boolean; isDisabled: boolean; isTouched: boolean; isRequired: boolean; isValid: boolean; }; /** Returns the name of the field. */ name: string; /** Returns the new updated values of the field. */ props: UseFieldProps; update: (field: Partial['initial']>) => void; touch: () => void; untouch: () => void; // biome-ignore lint/suspicious/noExplicitAny: value is controlled by callee value: any; isValid: boolean; }; /** @deprecated */ export declare const useField: < T extends string | boolean = string, Element = HTMLInputElement, >( options: UseFieldOptions, ) => UseFieldResults;