UNPKG

react-mui-form-validator

Version:

Validator for forms designed with material-ui components.

180 lines (170 loc) 5.81 kB
import * as React$1 from 'react'; import React__default from 'react'; import { FilledTextFieldProps, OutlinedTextFieldProps, StandardTextFieldProps, BoxProps } from '@mui/material'; import { CountryCode, NumberType } from 'libphonenumber-js'; interface required { validator: "required"; } interface matchRegexp { validator: "matchRegexp"; regexp: RegExp | string; } interface isEmail { validator: "isEmail"; } interface isEmpty { validator: "isEmpty"; } interface trim { validator: "trim"; } interface isNumber { validator: "isNumber"; } interface isFloat { validator: "isFloat"; } interface isPositive { validator: "isPositive"; } interface maxNumber { validator: "maxNumber"; max: number; } interface minNumber { validator: "minNumber"; min: number; } interface maxFloat { validator: "maxFloat"; max: number; } interface minFloat { validator: "minFloat"; min: number; } interface isString { validator: "isString"; } interface minStringLength { validator: "minStringLength"; min: number; } interface maxStringLength { validator: "maxStringLength"; max: number; } interface isFile { validator: "isFile"; } interface maxFileSize { validator: "maxFileSize"; max: number; } interface allowedExtensions { validator: "allowedExtensions"; fileTypes: string; } type Validator = required | matchRegexp | isEmail | isEmpty | trim | isNumber | isFloat | isPositive | maxNumber | minNumber | maxFloat | minFloat | isString | minStringLength | maxStringLength | isFile | maxFileSize | allowedExtensions; type MuiTelInputReason = 'country' | 'input'; interface MuiTelInputInfo { countryCode: CountryCode | null; countryCallingCode: string | null; nationalNumber: string | null; numberType: Exclude<NumberType, undefined> | null; numberValue: string | null; reason: MuiTelInputReason; } type ComponentProps = { errorMessages?: string | string[]; validators?: Validator[]; value: any; validatorListener?: (value: boolean) => void; withRequiredValidator?: boolean; containerProps?: object; onChangeTel?: (value: string, info: MuiTelInputInfo) => void; }; type ValidatorComponentProps = (FilledTextFieldProps | OutlinedTextFieldProps | StandardTextFieldProps) & ComponentProps; interface ValidatorComponentState { isValid?: boolean; value: any; errorMessages?: string | string[]; validators?: Validator[]; } interface ValidatorFormProps { children: React.ReactNode; onSubmit: () => void; instantValidate?: boolean; onError?: (errors: any) => void; debounceTime?: number; } declare class ValidatorForm extends React$1.Component<ValidatorFormProps & BoxProps> { static getValidator: (validator: Validator, value: any, includeRequired: boolean) => boolean; getFormHelpers: () => { form: { attachToForm: (component: any) => void; detachFromForm: (component: any) => void; instantValidate: boolean; debounceTime: number; }; }; instantValidate: boolean; childs: any[]; errors: any[]; debounceTime: number; attachToForm: (component: any) => void; detachFromForm: (component: any) => void; submit: (event: React$1.FormEvent<HTMLFormElement>) => void; walk: (children: any[], dryRun?: boolean) => Promise<boolean>; checkInput: (input: any, dryRun?: boolean) => Promise<boolean>; validate: (input: any, includeRequired: boolean, dryRun?: boolean) => Promise<boolean>; find: (collection: any[], fn: (item: any) => boolean) => any; resetValidations: () => void; isFormValid: (dryRun?: boolean) => Promise<boolean>; render(): React$1.JSX.Element; } declare class ValidatorComponent extends React$1.Component<ValidatorComponentProps, ValidatorComponentState> { renderValidatorComponent(): React$1.ReactNode; validateDebounced: any; form: any; debounceTime: any; getSnapshotBeforeUpdate(nextProps: ValidatorComponentProps, prevState: ValidatorComponentState): { value: any; validators: Validator[]; errorMessages: string | string[]; } | { value: any; validators?: undefined; errorMessages?: undefined; }; state: { isValid: boolean; value: any; errorMessages: string | string[] | undefined; validators: Validator[] | undefined; }; componentDidMount(): void; shouldComponentUpdate(nextProps: ValidatorComponentProps, nextState: ValidatorComponentState): boolean; componentDidUpdate(prevProps: ValidatorComponentProps, prevState: ValidatorComponentState): void; componentWillUnmount(): void; getErrorMessage: () => string | boolean | string[]; instantValidate: boolean; invalid: number[]; configure: () => void; validate: (value: any, includeRequired?: boolean, dryRun?: boolean) => Promise<boolean>; isValid: () => boolean; makeInvalid: () => void; makeValid: () => void; renderComponent: (form: ValidatorForm) => React$1.ReactNode; render(): React$1.JSX.Element; } declare class MuiSelect extends ValidatorComponent { renderValidatorComponent(): React$1.JSX.Element; } declare class MuiTextField extends ValidatorComponent { renderValidatorComponent(): React__default.JSX.Element; } declare class MuiTelInputDefault extends ValidatorComponent { renderValidatorComponent(): React__default.JSX.Element; } export { ValidatorComponent as MuiComponent, ValidatorForm as MuiForm, MuiTelInputDefault as MuiPhoneNumber, MuiSelect, MuiTextField, Validator as MuiValidator };