chowa
Version:
UI component library based on React
61 lines (60 loc) • 1.78 kB
TypeScript
/**
* @license chowa v1.1.3
*
* Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import * as PropTypes from 'prop-types';
export interface Rule {
message: string;
required?: boolean;
length?: number;
min?: number;
max?: number;
regex?: RegExp;
validation?: (value: any) => boolean;
}
export interface ValidatorStatus {
value: any;
error: boolean;
verifyFiled?: () => boolean;
resetFiled?: (value?: any) => void;
resetValidator?: () => void;
}
export interface FormValidatorProps {
children: React.ReactElement<any>;
name: string;
rules?: Rule[];
appendField?: (name: string, status: ValidatorStatus) => void;
removeField?: (name: string) => void;
updateField?: (name: string, status: ValidatorStatus) => void;
}
export interface FormValidatorState {
value: any;
initValue: any;
error: boolean;
message: string;
}
export declare type IoType = 'IO_VALUE' | 'IO_BOOLEAN';
declare class FormValidator extends React.PureComponent<FormValidatorProps, FormValidatorState> {
static propTypes: {
name: PropTypes.Validator<string>;
rule: PropTypes.Requireable<any[]>;
};
private ioType;
constructor(props: FormValidatorProps);
private computedIoType;
private computedIoInitValue;
componentDidUpdate(preProps: FormValidatorProps): void;
private onChangeHandler;
componentDidMount(): void;
componentWillUnmount(): void;
verifyFiled(): boolean;
resetFiled(value?: any): any;
resetValidator(): void;
render(): JSX.Element;
}
export default FormValidator;