UNPKG

react-form-toolkit

Version:

A form validation toolkit for React, specializing in simple to medium-sized, secure forms. It provides an easy-to-use API to validate form inputs and ensure data integrity.

42 lines (41 loc) 1.22 kB
/// <reference types="react" /> export type FormState<T> = { [K in keyof T]: T[K]; }; export type ValidValueType = string | number | boolean | File | null; export type ResolverSuccess<T> = { data: T; errors: null; }; export type ResolverError = { data: null; errors: string; }; export type Resolver<T> = ResolverSuccess<T> | ResolverError; export type FormResolver<T> = (data: FormState<T>) => Promise<Resolver<T>>; export type FormSubmitHandler<T> = (data: FormState<T>) => Promise<void> | void; export type ValidatorFn = (value: ValidValueType) => boolean; export type FormValidation = { [key: string]: [ValidatorFn, string]; }; export type FormValidationState = { [key: string]: string | null; }; export interface ChangeEvent { target: { name: string; value: any; type?: string; checked?: boolean; files?: FileList; }; } export interface FocusEvent { target: { name: string; }; } export interface MyChangeEvent extends React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement> { } export interface MyFocusEvent extends React.FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement> { }