|
| 1 | +/// <reference path="svelte-jsx.d.ts" /> |
1 | 2 | import type {SvelteComponentTyped} from 'svelte'; |
2 | 3 | import type {Readable, Writable} from 'svelte/store'; |
3 | 4 | import type {ObjectSchema} from 'yup'; |
4 | 5 |
|
5 | | -/** |
6 | | - * Unfortunately svelte currently does not support generics in components so we export it to use it in scripts like this |
7 | | - * |
8 | | - * const formProps: FormProps = { |
9 | | - * intitialValues: {...}, |
10 | | - * onSubmit: values => {...} -> values will be inffered from initialValues |
11 | | - * } |
12 | | - * |
13 | | - * */ |
14 | | -export type FormProps<Inf = Record<string, unknown>> = { |
| 6 | +export type FormProps<Inf = Record<string, any>> = { |
15 | 7 | initialValues: Inf; |
16 | 8 | onSubmit: ((values: Inf) => any) | ((values: Inf) => Promise<any>); |
17 | 9 | validate?: (values: Inf) => any | undefined; |
18 | 10 | validationSchema?: ObjectSchema<any>; |
19 | | -} |
| 11 | +} & svelte.JSX.HTMLAttributes<HTMLFormElement>; |
20 | 12 |
|
21 | 13 | type FieldProps = { |
22 | 14 | name: string; |
23 | 15 | type?: string; |
24 | 16 | value?: string; |
25 | | -}; |
| 17 | +} & svelte.JSX.HTMLProps<HTMLInputElement>; |
26 | 18 |
|
27 | 19 | type SelectProps = { |
28 | 20 | name: string; |
29 | | - class?: string; |
30 | | - value?: string; |
31 | | -}; |
| 21 | +} & svelte.JSX.HTMLProps<HTMLSelectElement>; |
32 | 22 |
|
33 | 23 | type ErrorProps = { |
34 | 24 | name: string; |
35 | | - class?: string; |
36 | | -}; |
| 25 | +} & svelte.JSX.HTMLProps<HTMLDivElement>; |
37 | 26 |
|
38 | 27 | type TextareaProps = { |
39 | 28 | name: string; |
40 | | - class?: string; |
41 | | - cols?: number; |
42 | | - rows?: number; |
43 | | -}; |
| 29 | +} & svelte.JSX.HTMLProps<HTMLTextAreaElement>; |
44 | 30 |
|
45 | | -type FormState<Inf = Record<string, unknown>> = { |
| 31 | +type FormState<Inf = Record<string, any>> = { |
46 | 32 | form: Writable<Inf>; |
47 | 33 | errors: Writable<Record<keyof Inf, string>>; |
48 | 34 | touched: Writable<Record<keyof Inf, boolean>>; |
@@ -71,30 +57,18 @@ type FormState<Inf = Record<string, unknown>> = { |
71 | 57 | handleSubmit: () => any; |
72 | 58 | }; |
73 | 59 |
|
74 | | -declare function createForm<Inf = Record<string, unknown>>(formProps: { |
| 60 | +declare function createForm<Inf = Record<string, any>>(formProps: { |
75 | 61 | initialValues: Inf; |
76 | 62 | onSubmit: (values: Inf) => any | Promise<any>; |
77 | 63 | validate?: (values: Inf) => any | undefined; |
78 | 64 | validationSchema?: ObjectSchema<any>; |
79 | 65 | }): FormState<Inf>; |
80 | 66 |
|
81 | 67 | declare class Form extends SvelteComponentTyped< |
82 | | - FormProps & { |
83 | | - class?: string; |
84 | | - }, |
| 68 | + FormProps, |
85 | 69 | {}, |
86 | 70 | { |
87 | | - default: Pick< |
88 | | - FormState, |
89 | | - | 'errors' |
90 | | - | 'touched' |
91 | | - | 'updateField' |
92 | | - | 'updateTouched' |
93 | | - | 'handleChange' |
94 | | - | 'handleSubmit' |
95 | | - | 'form' |
96 | | - | 'state' |
97 | | - >; |
| 71 | + default: FormState; |
98 | 72 | } |
99 | 73 | > {} |
100 | 74 |
|
|
0 commit comments