-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathindex.d.ts
102 lines (88 loc) · 2.79 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
/// <reference lib="svelte2tsx" />
import type {SvelteComponentTyped} from 'svelte';
import type {Readable, Writable} from 'svelte/store';
import type {ObjectSchema} from 'yup';
export type FormProps<Inf = Record<string, unknown>> = {
context?: FormState;
initialValues?: Inf;
onSubmit?: ((values: Inf) => any) | ((values: Inf) => Promise<any>);
validate?: (values: Inf) => any | undefined;
validationSchema?: ObjectSchema<any>;
} & svelte.JSX.HTMLAttributes<HTMLFormElement>;
type FieldProperties = {
name: string;
type?: string;
value?: string;
} & svelte.JSX.HTMLProps<HTMLInputElement>;
type SelectProperties = {
name: string;
} & svelte.JSX.HTMLProps<HTMLSelectElement>;
type ErrorProperties = {
name: string;
} & svelte.JSX.HTMLProps<HTMLDivElement>;
type TextareaProperties = {
name: string;
} & svelte.JSX.HTMLProps<HTMLTextAreaElement>;
type FormState<Inf = Record<string, any>> = {
form: Writable<Inf>;
errors: Writable<Record<keyof Inf, string>>;
touched: Writable<Record<keyof Inf, boolean>>;
modified: Readable<Record<keyof Inf, boolean>>;
isValid: Readable<boolean>;
isSubmitting: Writable<boolean>;
isValidating: Writable<boolean>;
isModified: Readable<boolean>;
updateField: (field: keyof Inf, value: any) => void;
updateValidateField: (field: keyof Inf, value: any) => void;
updateTouched: (field: keyof Inf, value: any) => void;
validateField: (field: keyof Inf) => Promise<any>;
updateInitialValues: (newValues: Inf) => void;
handleReset: () => void;
state: Readable<{
form: Inf;
errors: Record<keyof Inf, string>;
touched: Record<keyof Inf, boolean>;
modified: Record<keyof Inf, boolean>;
isValid: boolean;
isSubmitting: boolean;
isValidating: boolean;
isModified: boolean;
}>;
handleChange: (event: Event) => any;
handleSubmit: (event: Event) => any;
};
declare function createForm<Inf = Record<string, any>>(formProperties: {
initialValues: Inf;
onSubmit: (values: Inf) => any | Promise<any>;
validate?: (values: Inf) => any | undefined;
validationSchema?: ObjectSchema<any>;
}): FormState<Inf>;
declare class Form extends SvelteComponentTyped<
FormProps,
Record<string, unknown>,
{
default: FormState;
}
> {}
declare class Field extends SvelteComponentTyped<
FieldProperties,
Record<string, unknown>,
Record<string, unknown>
> {}
declare class Textarea extends SvelteComponentTyped<
TextareaProperties,
Record<string, unknown>,
Record<string, unknown>
> {}
declare class Select extends SvelteComponentTyped<
SelectProperties,
Record<string, unknown>,
{default: any}
> {}
declare class ErrorMessage extends SvelteComponentTyped<
ErrorProperties,
Record<string, unknown>,
{default: any}
> {}
declare const key: {};
export {createForm, key, Form, Field, Select, ErrorMessage, Textarea};