UNPKG

4.08 kBTypeScriptView Raw
1import PropTypes from 'prop-types';
2import React from 'react';
3import { FormsyContextInterface, IModel, InputComponent, IResetModel, IUpdateInputsWithError, IUpdateInputsWithValue, ValidationError } from './interfaces';
4import { PassDownProps } from './withFormsy';
5declare type FormHTMLAttributesCleaned = Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onChange' | 'onSubmit'>;
6declare type OnSubmitCallback = (model: IModel, resetModel: IResetModel, updateInputsWithError: IUpdateInputsWithError, event: React.SyntheticEvent<HTMLFormElement>) => void;
7declare type FormElementType = string | React.ComponentType<{
8 onReset?: (e: React.SyntheticEvent) => void;
9 onSubmit?: (e: React.SyntheticEvent) => void;
10 disabled?: boolean;
11 children?: React.ReactChildren;
12}>;
13export interface FormsyProps extends FormHTMLAttributesCleaned {
14 disabled: boolean;
15 mapping: null | ((model: IModel) => IModel);
16 onChange: (model: IModel, isChanged: boolean) => void;
17 onInvalid: () => void;
18 onReset?: () => void;
19 onSubmit?: OnSubmitCallback;
20 onValidSubmit?: OnSubmitCallback;
21 onInvalidSubmit: OnSubmitCallback;
22 onValid: () => void;
23 preventDefaultSubmit?: boolean;
24 preventExternalInvalidation?: boolean;
25 validationErrors?: null | object;
26 formElement?: FormElementType;
27}
28export interface FormsyState {
29 canChange: boolean;
30 contextValue: FormsyContextInterface;
31 formSubmitted?: boolean;
32 isPristine?: boolean;
33 isSubmitting: boolean;
34 isValid: boolean;
35}
36export declare class Formsy extends React.Component<FormsyProps, FormsyState> {
37 inputs: InstanceType<any & PassDownProps<any>>[];
38 emptyArray: any[];
39 prevInputNames: any[] | null;
40 static displayName: string;
41 static propTypes: {
42 disabled: PropTypes.Requireable<boolean>;
43 mapping: PropTypes.Requireable<(...args: any[]) => any>;
44 formElement: PropTypes.Requireable<string | object>;
45 onChange: PropTypes.Requireable<(...args: any[]) => any>;
46 onInvalid: PropTypes.Requireable<(...args: any[]) => any>;
47 onInvalidSubmit: PropTypes.Requireable<(...args: any[]) => any>;
48 onReset: PropTypes.Requireable<(...args: any[]) => any>;
49 onSubmit: PropTypes.Requireable<(...args: any[]) => any>;
50 onValid: PropTypes.Requireable<(...args: any[]) => any>;
51 onValidSubmit: PropTypes.Requireable<(...args: any[]) => any>;
52 preventDefaultSubmit: PropTypes.Requireable<boolean>;
53 preventExternalInvalidation: PropTypes.Requireable<boolean>;
54 validationErrors: PropTypes.Requireable<object>;
55 };
56 static defaultProps: Partial<FormsyProps>;
57 private readonly debouncedValidateForm;
58 constructor(props: FormsyProps);
59 componentDidMount: () => void;
60 componentDidUpdate: (prevProps: FormsyProps) => void;
61 getCurrentValues: () => any;
62 getModel: () => any;
63 getPristineValues: () => any;
64 setFormPristine: (isPristine: boolean) => void;
65 setInputValidationErrors: (errors: any) => void;
66 setFormValidState: (allIsValid: boolean) => void;
67 isValidValue: (component: any, value: any) => boolean;
68 isFormDisabled: () => boolean;
69 mapModel: (model: IModel) => IModel;
70 reset: (model?: IModel) => void;
71 private resetInternal;
72 private resetModel;
73 runValidation: <V>(component: InputComponent<V>, value?: V) => {
74 isRequired: boolean;
75 isValid: boolean;
76 validationError: ValidationError[];
77 };
78 attachToForm: (component: any) => void;
79 detachFromForm: <V>(component: InputComponent<V>) => void;
80 isChanged: () => boolean;
81 submit: (event?: React.SyntheticEvent<HTMLFormElement>) => void;
82 updateInputsWithError: IUpdateInputsWithError;
83 updateInputsWithValue: IUpdateInputsWithValue<any>;
84 validate: <V>(component: InputComponent<V>) => void;
85 validateForm: () => void;
86 render(): React.FunctionComponentElement<React.ProviderProps<FormsyContextInterface>>;
87}
88export {};