UNPKG

lynx-form-x

Version:

LynxFormX is a lightweight and intuitive form library built for the Lynx framework for mobile development. It streamlines form management by automatically binding fields, handling validation, and providing easy-to-use hooks for custom field manipulation—a

27 lines (26 loc) • 1.01 kB
import { ZodObject, ZodTransformer } from 'zod'; import { type Errors, type FormState } from '../reducers/formReducer.jsx'; interface InputEvent { detail: { value: string; }; } export type BindInput = (event: InputEvent) => any; export type SetValue<T> = (field: keyof T, value: any) => any; export type SetError<T> = (field: keyof T, error: any) => any; export type ValidateFunc<T> = (values: T) => Errors<T>; export type OnSubmit<T> = (values: T, helpers: { setValue: SetValue<T>; setError: SetError<T>; }) => any; export declare const useForm: <T>(onSubmit: OnSubmit<T>, initialValues?: T, validate?: ValidateFunc<T>, schema?: ZodObject<any> | ZodTransformer<any>) => FormHookValue<T>; export type FormHookValue<T> = FormState<T> & { handleInput: (field: keyof T) => BindInput; handleBlur: (field: keyof T) => () => any; handleSubmit: () => any; resetForm: () => any; setValue: SetValue<T>; setError: SetError<T>; isSubmitting: boolean; }; export {};