-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
138 lines (102 loc) · 3.97 KB
/
index.d.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** Declaration file generated by dts-gen */
import * as React from "react";
import * as Immutable from "immutable";
export type InitialState = {
fields: Immutable.Map<string, Immutable.Map<string, Immutable.Map<string, any>>>;
};
export type Values = {[key: string]: any};
export type Error = string;
export type Valid = null;
export type Validation = (value: any, otherValues?: Values) => (Error | Valid);
export type OnChangeEvent = (event: {target: { name: string, value: any}}) => void;
export type OnFormEvent = (event: {target: { name: string}}) => void;
export type OnionFormChangeEvent = (v: {name: string, value: any}) => void;
export interface PossibleOverrideProps {
error?: string | null;
hint?: string | null;
label?: string | null;
name?: string | null;
onChange?: OnFormEvent | any;
onBlur?: OnFormEvent | any;
onFocus?: OnFormEvent | any;
placeholder?: string | null;
tooltip?: string | null;
}
export interface InputProps extends PossibleOverrideProps {
name: string;
onChange: OnionFormChangeEvent | OnChangeEvent | any;
onionFormName: string;
value: any;
liveValidation: boolean;
apiError: string | null;
}
export type Action = {
type: string;
form: string;
field?: string;
property?: string;
value?: any;
values?: Values;
};
export interface FieldProps {
component: Object;
name: String | string;
}
export class Field extends React.Component<FieldProps, any> {
}
export interface FormProps {
method?: "POST" | "GET" | "PUT" | "DELETE";
name: String | string;
onError?: (e: {name: string, errors: {[key: string]: any}}) => void;
onSubmit?: (s: {name: string, values: {[key: string]: any}}) => void;
validations?: {[key: string]: Validation[]};
}
declare class Form extends React.Component<FormProps, any> {
constructor(...args: any[]);
static defaultProps: {
method: string;
validations: {[key: string]: Validation[]};
};
}
export interface SubmitProps {
disabled?: boolean;
hasErrors?: boolean;
isValid?: boolean;
hasValues?: boolean;
onClick?: () => void;
}
declare class Submit extends React.Component<SubmitProps, any> {
}
export interface ButtonProps {
disabled?: boolean;
children: React.ReactChild;
onClick: () => void;
}
declare class Button extends React.Component<ButtonProps, any> {
}
type ComponentClass<P> = React.ComponentClass<P>;
type StatelessComponent<P> = React.StatelessComponent<P>;
type PureComponent<P> = React.PureComponent<P, void>;
interface ComponentDecorator<P> {
(component: ComponentClass<P> | StatelessComponent<P> | PureComponent<P> | any): ComponentClass<P>;
}
export function connectField<P>(fieldName: string, defaultProps?: (Values & PossibleOverrideProps), customValidations?: Validation[]): ComponentDecorator<P & PossibleOverrideProps>;
export function connectSubmit(Submit: any): any;
export function extractPropertyFromFields(fields: any, property: string): any;
export function extractPropertyFromState(state: any, formName: any, property: string): any;
export function reducer(state: InitialState, action: Action): InitialState;
export function validateField(value: any, validations: Validation[], otherValues?: Values): any;
export namespace actions {
const CLEAR_ONION_FORM: string;
const CLEAR_ONION_FORM_PROPERTY: string;
const SET_ONION_FORM_FIELD_PROPERTY: string;
const SET_ONION_FORM_MULTIPLE_FIELDS: string;
function clearForm(form: string): Action;
function clearFormProperty(form: string, property: string): Action;
function setFieldApiError(form: string, field: string, error: string | null): Action;
function setFieldError(form: string, field: string, error: string | null): Action;
function setFieldLiveValidation(form: string, field: boolean): Action;
function setFieldValue(form: string, field: string, value: any): Action;
function setFormFieldProperty(form: string, field: string, property: string, value: any): Action;
function setMultipleFields(form: string, property: string, values: Values): Action;
}