-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathinterfaces.ts
More file actions
46 lines (35 loc) · 1.65 KB
/
interfaces.ts
File metadata and controls
46 lines (35 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { ComponentClass } from 'react';
import { WrapperProps, WrapperState } from './withFormsy';
export interface Values {
[key: string]: any;
}
export type IModel = any;
export type IResetModel = (model?: IModel) => void;
export type IUpdateInputsWithValue<V> = (values: { [key: string]: V }, validate?: boolean) => void;
export type IUpdateInputsWithError = (errors: { [key: string]: ValidationError }, invalidate?: boolean) => void;
export type ValidationError = string | React.ReactNode;
export type ValidationFunction<V> = (values: Values, value: V, extra?: any) => boolean | ValidationError;
export type Validation<V> = any | ValidationFunction<V>;
export type Validations<V> = ValidationsStructure<V> | string | object;
export interface ValidationsStructure<V> {
[key: string]: Validation<V>;
}
export type RequiredValidation<V> = boolean | Validations<V>;
export interface ComponentWithStaticAttributes extends ComponentClass {
defaultValue?: any;
}
export type WrappedComponentClass = React.FC | ComponentWithStaticAttributes;
export interface InputComponent<V> extends React.Component<WrapperProps<V>, WrapperState<V>> {
validations?: Validations<V>;
requiredValidations?: Validations<V>;
}
export interface FormsyContextInterface {
attachToForm: (component: InputComponent<any>) => void;
detachFromForm: (component: InputComponent<any>) => void;
isFormDisabled: boolean;
isValidValue: (component: InputComponent<any>, value: any) => boolean;
validate: (component: InputComponent<any>) => void;
runValidation: (
component: InputComponent<any>,
) => { isRequired: boolean; isValid: boolean; validationError: ValidationError[] };
}