react-form-with-constraints
Version:
Simple form validation for React
52 lines (51 loc) • 2.13 kB
TypeScript
import * as React from 'react';
import { AsyncChildContext } from './Async';
import { Field } from './Field';
import { FieldFeedbacksChildContext } from './FieldFeedbacks';
import { FieldFeedbackType } from './FieldFeedbackType';
import { FieldFeedbackValidation } from './FieldFeedbackValidation';
import { FormWithConstraintsChildContext } from './FormWithConstraints';
import { InputElement } from './InputElement';
import { Nullable } from './Nullable';
declare type WhenString = 'valid' | '*' | 'badInput' | 'patternMismatch' | 'rangeOverflow' | 'rangeUnderflow' | 'stepMismatch' | 'tooLong' | 'tooShort' | 'typeMismatch' | 'valueMissing';
declare type WhenFn = (value: string) => boolean;
declare type When = WhenString | WhenFn;
export interface FieldFeedbackClasses {
classes?: {
[index: string]: string | undefined;
error?: string;
warning?: string;
info?: string;
whenValid?: string;
};
}
export interface FieldFeedbackBaseProps {
when?: When;
error?: boolean;
warning?: boolean;
info?: boolean;
}
export interface FieldFeedbackProps extends FieldFeedbackBaseProps, FieldFeedbackClasses, React.HTMLAttributes<HTMLSpanElement> {
}
interface FieldFeedbackState {
validation: FieldFeedbackValidation;
validationMessage: string;
}
export declare type FieldFeedbackContext = FormWithConstraintsChildContext & FieldFeedbacksChildContext & Partial<Nullable<AsyncChildContext>>;
export declare class FieldFeedback<Props extends FieldFeedbackBaseProps = FieldFeedbackProps> extends React.Component<Props, FieldFeedbackState> {
static defaultProps: FieldFeedbackProps;
static contextTypes: React.ValidationMap<FieldFeedbackContext>;
context: FieldFeedbackContext;
readonly key: string;
constructor(props: Props, context: FieldFeedbackContext);
componentDidMount(): void;
componentWillUnmount(): void;
validate: (input: InputElement) => {
key: string;
type: FieldFeedbackType;
show: boolean | undefined;
};
fieldDidReset: (field: Field) => void;
render(): JSX.Element | null;
}
export {};