@sberdevices/plasma-temple
Version:
SberDevices CanvasApp Templates.
33 lines • 1.09 kB
TypeScript
import React from 'react';
import { AnyObject } from '../types';
declare type ErrorRecord<T> = Record<keyof T, string>;
declare type Validators<T extends AnyObject> = Partial<Record<keyof T, Validation>>;
interface FormOptions<T extends AnyObject> {
validators?: Validators<T>;
initialValues?: Partial<T>;
onChange?: (value: T) => void;
onSubmit?: () => void;
}
interface Validation {
required?: {
value: boolean;
message: string;
};
pattern?: {
value: string;
message: string;
};
custom?: {
isValid: (value: string) => boolean;
message: string;
};
}
interface FormState<T extends AnyObject = AnyObject> {
data: T;
errors: ErrorRecord<T> | null;
handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
handleSubmit: (event: React.SyntheticEvent) => void;
}
export declare const useForm: <T extends Record<string, any> = Record<string, any>>({ validators, initialValues, onChange, onSubmit, }: FormOptions<T>) => FormState<T>;
export {};
//# sourceMappingURL=useForm.d.ts.map