UNPKG

frontend-hamroun

Version:

A lightweight frontend JavaScript framework with React-like syntax

41 lines 1.23 kB
export interface FormField { value: any; error?: string; touched: boolean; dirty: boolean; } export interface FormState { fields: Record<string, FormField>; isValid: boolean; isDirty: boolean; isSubmitting: boolean; submitCount: number; } export interface FormOptions<T> { initialValues: T; validate?: (values: T) => Record<string, string>; onSubmit?: (values: T, form: FormState) => void | Promise<void>; } export interface FormConfig<T> { values: T; errors: Record<string, string>; touched: Record<string, boolean>; dirty: Record<string, boolean>; isValid: boolean; isDirty: boolean; isSubmitting: boolean; submitCount: number; handleChange: (e: any) => void; handleBlur: (e: any) => void; handleSubmit: (e: any) => void; setFieldValue: (field: string, value: any) => void; setFieldError: (field: string, error: string) => void; setValues: (values: Partial<T>) => void; resetForm: () => void; } export declare function useForm<T extends Record<string, any>>(options: FormOptions<T>): FormConfig<T>; declare const _default: { useForm: typeof useForm; }; export default _default; //# sourceMappingURL=forms.d.ts.map