import { type ChangeEventHandler, type FocusEventHandler, FormEventHandler, RefObject } from "react"; import type { BaseIssue, BaseSchema, InferIssue } from "valibot"; import { type ValidateElement } from "../../utils/form"; export type OnValidationError> = (issues: Array) => void; export type ValidationProps> = { validate?: Schema; onValidationError?: OnValidationError>; }; export type UseInputValidationArgs> = { name?: string; validate?: Schema; required?: boolean; onValidationError?: OnValidationError>; onChange?: ChangeEventHandler; onBlur?: FocusEventHandler; requireDirty?: boolean; reportValidityTarget?: RefObject; }; /** * Hook to handle input validation logic. * * @remarks * This hook integrates with the `Form` context and `valibot` schemas to validate input elements. * It handles `onChange`, `onBlur`, and `onInvalid` events to trigger validation at appropriate times. * It supports both immediate validation (after submit/blur) and lazy validation. * * @typeParam E - The input element type. * @typeParam Schema - The Valibot schema type. * @param args - The hook arguments. * @returns Event handlers and a validate function. * * @example * ```tsx * const { onChange, onBlur } = useInputValidation({ * name: "email", * validate: emailSchema, * onChange: (e) => console.log(e.target.value) * }); * return ; * ``` */ export declare function useInputValidation>({ name, validate, required, onValidationError, onChange, onBlur, reportValidityTarget, }: UseInputValidationArgs): { onChange: ChangeEventHandler; onBlur: FocusEventHandler; onInvalid: FormEventHandler; validate: (elm: E) => [any, ...any[]] | null | undefined; };