UNPKG

@undermuz/use-form

Version:
63 lines (60 loc) 2.69 kB
import { IAction } from '../utils/useReducer.js'; declare const FORM_ACTIONS: { SET_ERRORS: string; SET_VALUES: string; SET_VALUE: string; SET_TESTS: string; SET_TOUCHED_FIELD: string; SET_TOUCHED: string; SET_CUSTOM_ERRORS: string; SET_CUSTOM_ERROR_FIELD: string; SET_FIELDS: string; SET_VALIDATE: string; SET_IS_SENDING: string; SET_IS_CANCELING: string; SET_IS_SUCCESS: string; SET_SEND_ERROR: string; VALIDATE_FORM: string; SEND_FORM: string; }; type IValueTest = [Array<string>, Array<Function>, string?]; type ValidateFunction = (formState: IFormState, debug?: boolean) => IErrors; interface IFields { [s: string]: any; } type ITouched = Array<string>; type IValues<T extends Record<string, unknown> = Record<string, unknown>> = T; type IError = Array<string | IErrors>; interface IErrors { [s: string]: IError; } declare enum EnumFormStatus { Initial = "initial" } interface IFormState<T extends IValues = IValues> { status: EnumFormStatus; isSending: boolean; isCanceling: boolean; isSuccess: boolean; sendError: any; values: T; tests: IValueTest[]; validate: ValidateFunction; touched: ITouched; fields: IFields; errors: IErrors; customErrors: IErrors; } declare const valuesReducer: (state: IValues, action: IAction) => IValues; declare const testsReducer: (state: IValueTest[], action: IAction) => IValueTest[]; declare const touchedReducer: (state: ITouched, action: IAction) => ITouched; declare const errorsReducer: (state: IErrors, action: IAction) => IErrors; declare const customErrorsReducer: (state: IErrors, action: IAction) => IErrors; declare const fieldsReducer: (state: IFields, action: IAction) => IFields; declare const validateReducer: (state: ValidateFunction, action: IAction) => ValidateFunction; declare const isSendingReducer: (state: boolean, action: IAction) => boolean; declare const isCancelingReducer: (state: boolean, action: IAction) => boolean; declare const isSuccessReducer: (state: boolean, action: IAction) => boolean; declare const sendErrorReducer: (state: any, action: IAction) => any; declare const formReducer: <T extends Record<string, unknown> = Record<string, unknown>>(state: IFormState<T>, action: IAction) => IFormState<T>; export { EnumFormStatus, FORM_ACTIONS, IError, IErrors, IFields, IFormState, ITouched, IValueTest, IValues, ValidateFunction, customErrorsReducer, errorsReducer, fieldsReducer, formReducer, isCancelingReducer, isSendingReducer, isSuccessReducer, sendErrorReducer, testsReducer, touchedReducer, validateReducer, valuesReducer };