@form-engine-ts/react 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,67 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import { FormSchema, TranslationAdapter, FormField, FormValue, ValidationIssue, FormValues, FieldType } from '@form-engine-ts/core';
4
+
5
+ interface FormBuilderProps {
6
+ readonly schema: FormSchema;
7
+ readonly onChange: (newSchema: FormSchema) => void;
8
+ readonly locale?: string;
9
+ readonly translator?: TranslationAdapter;
10
+ }
11
+ declare function FormBuilder({ schema, onChange, locale, translator }: FormBuilderProps): react.JSX.Element;
12
+
13
+ type SubmitStatus = "idle" | "submitting" | "success" | "error";
14
+ interface FormContextValue {
15
+ readonly schema: FormSchema;
16
+ readonly locale: string;
17
+ readonly translator: TranslationAdapter;
18
+ readonly values: FormValues;
19
+ readonly visibility: Readonly<Record<string, boolean>>;
20
+ readonly errors: Readonly<Record<string, ValidationIssue | undefined>>;
21
+ readonly submitStatus: SubmitStatus;
22
+ readonly submitError: Error | null;
23
+ readonly isSubmitting: boolean;
24
+ readonly setValue: (fieldId: string, value: FormValue) => void;
25
+ readonly reset: () => void;
26
+ readonly submit: () => Promise<boolean>;
27
+ readonly translate: (key: string, params?: Readonly<Record<string, string | number>>) => string;
28
+ }
29
+ interface FormProviderProps {
30
+ readonly schema: FormSchema;
31
+ readonly locale: string;
32
+ readonly translator: TranslationAdapter;
33
+ readonly initialValues?: FormValues;
34
+ readonly resetOnSuccess?: boolean;
35
+ readonly onSubmit: (values: FormValues) => void | Promise<void>;
36
+ readonly children: ReactNode;
37
+ }
38
+ declare function FormProvider({ schema, locale, translator, initialValues, resetOnSuccess, onSubmit, children }: FormProviderProps): react.JSX.Element;
39
+ declare function useForm(): FormContextValue;
40
+ interface FieldState {
41
+ readonly field: FormField;
42
+ readonly value: FormValue;
43
+ readonly error: ValidationIssue | undefined;
44
+ readonly setValue: (value: FormValue) => void;
45
+ }
46
+ declare function useField(fieldId: string): FieldState;
47
+
48
+ interface FieldComponentProps {
49
+ readonly field: FormField;
50
+ readonly value: FormValue;
51
+ readonly error: ValidationIssue | undefined;
52
+ readonly setValue: (value: FormValue) => void;
53
+ readonly translate: (key: string, params?: Readonly<Record<string, string | number>>) => string;
54
+ readonly inputId: string;
55
+ readonly errorId: string;
56
+ readonly helpId: string;
57
+ }
58
+ type FieldComponents = Partial<Record<FieldType, ComponentType<FieldComponentProps>>>;
59
+ interface FormRendererProps {
60
+ readonly components?: FieldComponents;
61
+ readonly className?: string;
62
+ readonly successMessageKey?: string;
63
+ readonly errorMessageKey?: string;
64
+ }
65
+ declare function FormRenderer({ components, className, successMessageKey, errorMessageKey }: FormRendererProps): react.JSX.Element;
66
+
67
+ export { type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderProps, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererProps, type SubmitStatus, useField, useForm };
@@ -0,0 +1,67 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import { FormSchema, TranslationAdapter, FormField, FormValue, ValidationIssue, FormValues, FieldType } from '@form-engine-ts/core';
4
+
5
+ interface FormBuilderProps {
6
+ readonly schema: FormSchema;
7
+ readonly onChange: (newSchema: FormSchema) => void;
8
+ readonly locale?: string;
9
+ readonly translator?: TranslationAdapter;
10
+ }
11
+ declare function FormBuilder({ schema, onChange, locale, translator }: FormBuilderProps): react.JSX.Element;
12
+
13
+ type SubmitStatus = "idle" | "submitting" | "success" | "error";
14
+ interface FormContextValue {
15
+ readonly schema: FormSchema;
16
+ readonly locale: string;
17
+ readonly translator: TranslationAdapter;
18
+ readonly values: FormValues;
19
+ readonly visibility: Readonly<Record<string, boolean>>;
20
+ readonly errors: Readonly<Record<string, ValidationIssue | undefined>>;
21
+ readonly submitStatus: SubmitStatus;
22
+ readonly submitError: Error | null;
23
+ readonly isSubmitting: boolean;
24
+ readonly setValue: (fieldId: string, value: FormValue) => void;
25
+ readonly reset: () => void;
26
+ readonly submit: () => Promise<boolean>;
27
+ readonly translate: (key: string, params?: Readonly<Record<string, string | number>>) => string;
28
+ }
29
+ interface FormProviderProps {
30
+ readonly schema: FormSchema;
31
+ readonly locale: string;
32
+ readonly translator: TranslationAdapter;
33
+ readonly initialValues?: FormValues;
34
+ readonly resetOnSuccess?: boolean;
35
+ readonly onSubmit: (values: FormValues) => void | Promise<void>;
36
+ readonly children: ReactNode;
37
+ }
38
+ declare function FormProvider({ schema, locale, translator, initialValues, resetOnSuccess, onSubmit, children }: FormProviderProps): react.JSX.Element;
39
+ declare function useForm(): FormContextValue;
40
+ interface FieldState {
41
+ readonly field: FormField;
42
+ readonly value: FormValue;
43
+ readonly error: ValidationIssue | undefined;
44
+ readonly setValue: (value: FormValue) => void;
45
+ }
46
+ declare function useField(fieldId: string): FieldState;
47
+
48
+ interface FieldComponentProps {
49
+ readonly field: FormField;
50
+ readonly value: FormValue;
51
+ readonly error: ValidationIssue | undefined;
52
+ readonly setValue: (value: FormValue) => void;
53
+ readonly translate: (key: string, params?: Readonly<Record<string, string | number>>) => string;
54
+ readonly inputId: string;
55
+ readonly errorId: string;
56
+ readonly helpId: string;
57
+ }
58
+ type FieldComponents = Partial<Record<FieldType, ComponentType<FieldComponentProps>>>;
59
+ interface FormRendererProps {
60
+ readonly components?: FieldComponents;
61
+ readonly className?: string;
62
+ readonly successMessageKey?: string;
63
+ readonly errorMessageKey?: string;
64
+ }
65
+ declare function FormRenderer({ components, className, successMessageKey, errorMessageKey }: FormRendererProps): react.JSX.Element;
66
+
67
+ export { type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderProps, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererProps, type SubmitStatus, useField, useForm };