|
1 | 1 | import type { ErrorObject } from "ajv"; |
2 | | -import { useForm2, type FormAPI, type UseFormOptions2 } from "@sjsf/form"; |
| 2 | +import { type FormInternals, type FormState, type FormOptions, createForm3 } from "@sjsf/form"; |
3 | 3 | import { translation } from "@sjsf/form/translations/en"; |
4 | 4 | import { theme } from "@sjsf/form/basic-theme"; |
5 | 5 | import { createValidator2 } from "@sjsf/ajv8-validator"; |
6 | 6 |
|
7 | 7 | type Defaults = "widgets" | "components" | "validator" | "translation"; |
8 | 8 |
|
9 | | -export type CustomOptions<T, E> = Omit<UseFormOptions2<T, E>, Defaults> & |
10 | | - Partial<Pick<UseFormOptions2<T, E>, Defaults>>; |
| 9 | +export type CustomOptions<T, E> = Omit<FormOptions<T, E>, Defaults> & |
| 10 | + Partial<Pick<FormOptions<T, E>, Defaults>>; |
11 | 11 |
|
12 | | -export function useCustomForm<T, E = ErrorObject>( |
| 12 | +export function createCustomForm<T, E = ErrorObject>( |
13 | 13 | options: CustomOptions<T, E> |
14 | | -): FormAPI<T, E> { |
| 14 | +): FormState<T, E> & FormInternals { |
15 | 15 | const validator = createValidator2(); |
16 | | - const defaults: Pick<UseFormOptions2<T, ErrorObject>, Defaults> = { |
| 16 | + const defaults: Pick<FormOptions<T, ErrorObject>, Defaults> = { |
17 | 17 | ...theme, |
18 | 18 | validator, |
19 | 19 | translation, |
20 | 20 | }; |
21 | | - return useForm2( |
| 21 | + return createForm3( |
22 | 22 | new Proxy(options, { |
23 | 23 | get(target, p, receiver) { |
24 | 24 | if (!(p in target)) { |
25 | 25 | return defaults[p as Defaults]; |
26 | 26 | } |
27 | 27 | return Reflect.get(target, p, receiver); |
28 | 28 | }, |
29 | | - }) as UseFormOptions2<T, E> |
| 29 | + }) as FormOptions<T, E> |
30 | 30 | ); |
31 | 31 | } |
0 commit comments