UNPKG

2.21 kBTypeScriptView Raw
1import PropTypes from 'prop-types';
2import React from 'react';
3import { RequiredValidation, ValidationError, Validations } from './interfaces';
4export declare const propTypes: {
5 innerRef: PropTypes.Requireable<(...args: any[]) => any>;
6 name: PropTypes.Validator<string>;
7 required: PropTypes.Requireable<string | boolean | object>;
8 validations: PropTypes.Requireable<string | object>;
9 value: PropTypes.Requireable<any>;
10};
11export interface WrapperProps<V> {
12 innerRef?: (ref: React.Ref<any>) => void;
13 name: string;
14 required?: RequiredValidation<V>;
15 validationError?: ValidationError;
16 validationErrors?: {
17 [key: string]: ValidationError;
18 };
19 validations?: Validations<V>;
20 value?: V;
21}
22export interface WrapperState<V> {
23 [key: string]: unknown;
24 formSubmitted: boolean;
25 isPristine: boolean;
26 isRequired: boolean;
27 isValid: boolean;
28 pristineValue: V;
29 validationError: ValidationError[];
30 value: V;
31}
32export interface InjectedProps<V> {
33 errorMessage: ValidationError;
34 errorMessages: ValidationError[];
35 hasValue: boolean;
36 isFormDisabled: boolean;
37 isFormSubmitted: boolean;
38 isPristine: boolean;
39 isRequired: boolean;
40 isValid: boolean;
41 isValidValue: (value: V) => boolean;
42 ref?: React.Ref<any>;
43 resetValue: () => void;
44 setValidations: (validations: Validations<V>, required: RequiredValidation<V>) => void;
45 setValue: (value: V, validate?: boolean) => void;
46 showError: boolean;
47 showRequired: boolean;
48}
49export interface WrapperInstanceMethods<V> {
50 getErrorMessage: () => null | ValidationError;
51 getErrorMessages: () => ValidationError[];
52 getValue: () => V;
53 isFormDisabled: () => boolean;
54 isFormSubmitted: () => boolean;
55 isValid: () => boolean;
56 isValidValue: (value: V) => boolean;
57 setValue: (value: V, validate?: boolean) => void;
58}
59export declare type PassDownProps<V> = WrapperProps<V> & InjectedProps<V>;
60export default function withFormsy<T, V>(WrappedComponent: React.ComponentType<T & PassDownProps<V>>): React.ComponentType<Omit<T & WrapperProps<V>, keyof InjectedProps<V>>>;