-
Notifications
You must be signed in to change notification settings - Fork 0
/
fiora.d.ts
75 lines (61 loc) · 1.69 KB
/
fiora.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
import * as React from 'react';
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type NativeFormProps = Omit<
React.FormHTMLAttributes<HTMLFormElement>,
'children' | 'onSubmit' | 'onReset'
>;
type FieldValue = any;
type FieldError = any;
type FormValues = Record<string, FieldValue>;
type FormErrors = Record<string, FieldError> | null | undefined;
/**
* From props. Supports all HTML form attributes
*/
export interface FormProps extends NativeFormProps {
initialValues?: FormValues;
children: React.ReactNode;
onSubmit?: (formValues: FormValues) => FormErrors | Promise<FormErrors>;
onReset?: (event: React.FormEvent<HTMLFormElement>) => void;
onValidate?: (formValues: FormValues) => FormErrors | Promise<FormErrors>;
}
/**
* Field children render props.
*/
export interface FieldRenderProps {
value: FieldValue;
error: FieldError;
isTouched: boolean;
isValidating: boolean;
updateValue: (newValue: FieldValue) => void;
validate: () => void;
}
/**
* Field props.
*/
export interface FieldProps {
name: string;
onValidate?: (value: FieldValue) => FieldError | Promise<FieldError>;
children: (props: FieldRenderProps) => React.ReactNode;
}
/**
* FormMeta children render props.
*/
export interface FormMetaRenderProps {
error: FieldError;
isValidating: boolean;
isSubmitting: boolean;
isTouched: boolean;
isValid: boolean;
}
/**
* FormMeta props.
*/
export interface FormMetaProps {
children: (props: FormMetaRenderProps) => React.ReactNode;
}
export function createFiora(): {
Form: React.ComponentClass<FormProps>;
Field: React.StatelessComponent<FieldProps>;
FormMeta: React.StatelessComponent<FormMetaProps>;
};
export default createFiora;