UNPKG

react-bfm

Version:

A basic field / form manager for React using hooks

23 lines (22 loc) 1.13 kB
import { FocusEventHandler } from 'react'; import { ConnectFieldChangeHandler, DirtyCheckFunction, TransformEventToValueFunction, TransformValueToInputFunction, ValidatorFunction } from './common'; interface ConnectFieldEventHandlerProps<T = unknown> { onFocus: FocusEventHandler<T>; onChange: ConnectFieldChangeHandler; onBlur: FocusEventHandler<T>; } export interface ConnectFieldReturnProps<T = HTMLInputElement> extends ConnectFieldEventHandlerProps<T> { readonly value: any; } export interface ConnectFieldProps<T = HTMLInputElement> extends Partial<ConnectFieldEventHandlerProps<T>> { namespace: string; fieldName: string; initialValue?: any; validator?: ValidatorFunction; dirtyCheck?: DirtyCheckFunction; transformValueToInput?: TransformValueToInputFunction; transformEventToValue?: TransformEventToValueFunction; } export type FactoryWithoutConnectFieldProps<P> = Omit<P, keyof ConnectFieldProps>; export declare const useConnectField: <P = unknown, T = HTMLInputElement>(props: ConnectFieldProps<T>) => FactoryWithoutConnectFieldProps<P> & ConnectFieldReturnProps<T>; export {};