import { MutableRefObject } from 'react'; import { AsyncValidator, Validator } from '@gecogvidanto/shared'; export interface ValidationEvent { valid: boolean; target: T; } interface FieldElement extends Element { value: string; } interface InputProps { validators?: Validator[]; asyncValidators?: AsyncValidator[]; onValidate?: (event: ValidationEvent) => void; } interface OutputProps { fieldRef: MutableRefObject; onChange: () => void; onBlur: () => void; errors: string[] | undefined; } /** * The field validator can be used to validate the content of a field against given validators. The * validation event is sent at mount and update if the field is valid, so that it can be considered invalid * until event received. **Note** that the component using this hook must be an observer. * * @param (unnamed) - Validation parameters. * @param (unnamed).validators - The synchronous validators. * @param (unnamed).asyncValidators - The asynchronous validators. * @param (unnamed).onValidate - Function to call when valid state changes. * @returns The output properties. */ export default function useFieldValidator({ validators, asyncValidators, onValidate, }: InputProps): OutputProps; export {};