formular
Version:
Build forms in React. Easy-Peasy!
69 lines • 2.25 kB
TypeScript
import React from 'react';
import { CancelablePromise } from './util';
import Form from './Form';
export declare const eventNames: {
readonly stateChange: "state change";
readonly valueChange: "value change";
readonly change: "change";
readonly unset: "unset";
readonly focus: "focus";
readonly blur: "blur";
readonly startValidate: "start validate";
readonly validate: "validate";
};
export declare type FieldEventName = typeof eventNames[keyof typeof eventNames];
export declare type Validator = (value: any, fields: {
[key: string]: Field<any>;
}) => void;
export declare type FieldOpts<Value> = {
name?: string;
node?: HTMLInputElement;
value?: Value;
validate?: Validator[];
readOnly?: boolean;
validationDelay?: number;
};
export declare type State<Value> = {
value: Value;
error: any;
isChanged: boolean;
isValidating: boolean;
isValidated: boolean;
isValid: boolean;
};
declare class Field<Value> {
form?: Form<any>;
name?: string;
opts?: FieldOpts<Value>;
node?: HTMLInputElement;
validators: Validator[];
readOnly: boolean;
debounceValidate: Function;
state: State<Value>;
props: {
ref: (node: HTMLInputElement) => void;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
onFocus: (event: FocusEvent | React.FocusEvent<HTMLInputElement>) => void;
onBlur: (event: FocusEvent | React.FocusEvent<HTMLInputElement>) => void;
};
private _events;
private _initialValue;
private _cancelablePromise;
static modifyValue(value: any): any;
constructor(opts?: FieldOpts<Value>, form?: Form<any>);
setState(values: Partial<State<Value>>): void;
setRef(node: HTMLInputElement): void;
unsetRef(): void;
private handleFocus;
private handleBlur;
set(value: any, opts?: {
silent: boolean;
}): void;
unset(): void;
setError(error: any): void;
validate: () => CancelablePromise;
on(eventName: FieldEventName, handler: Function): void;
off(eventName: FieldEventName, handler: Function): void;
}
export default Field;
//# sourceMappingURL=Field.d.ts.map