@delightui/components 0.1.162-alpha.5 → 0.1.163
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.
- package/dist/cjs/components/atoms/Checkbox/Checkbox.d.ts +1 -1
- package/dist/cjs/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
- package/dist/cjs/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
- package/dist/cjs/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
- package/dist/cjs/components/atoms/Input/Input.d.ts +1 -1
- package/dist/cjs/components/atoms/Input/Input.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/Password/Password.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/RadioButton/RadioButton.d.ts +1 -1
- package/dist/cjs/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
- package/dist/cjs/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/TextArea/TextArea.d.ts +1 -1
- package/dist/cjs/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
- package/dist/cjs/components/atoms/Toggle/Toggle.d.ts +1 -1
- package/dist/cjs/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
- package/dist/cjs/components/molecules/FormField/FormField.d.ts +2 -28
- package/dist/cjs/components/molecules/FormField/FormField.presenter.d.ts +8 -17
- package/dist/cjs/components/molecules/FormField/FormField.types.d.ts +52 -115
- package/dist/cjs/components/molecules/FormField/FormField.utils.d.ts +11 -8
- package/dist/cjs/components/molecules/FormField/index.d.ts +2 -1
- package/dist/cjs/components/molecules/Search/Search.d.ts +1 -1
- package/dist/cjs/components/molecules/Search/Search.presenter.d.ts +2 -2
- package/dist/cjs/components/molecules/Select/Select.presenter.d.ts +4 -4
- package/dist/cjs/components/organisms/Form/DropzoneFormExample.d.ts +6 -0
- package/dist/cjs/components/organisms/Form/Form.d.ts +1 -22
- package/dist/cjs/components/organisms/Form/Form.types.d.ts +93 -64
- package/dist/cjs/components/organisms/Form/Form.utils.d.ts +2 -0
- package/dist/cjs/components/organisms/Form/FormContext.d.ts +5 -0
- package/dist/cjs/components/organisms/Form/UpdatedFormExample.d.ts +23 -0
- package/dist/cjs/components/organisms/Form/{examples/UseFormExample.d.ts → UseFormExample.d.ts} +3 -0
- package/dist/cjs/components/organisms/Form/index.d.ts +3 -7
- package/dist/cjs/components/organisms/Form/useForm.d.ts +40 -43
- package/dist/cjs/library.js +3 -3
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/atoms/Checkbox/Checkbox.d.ts +1 -1
- package/dist/esm/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
- package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
- package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
- package/dist/esm/components/atoms/Input/Input.d.ts +1 -1
- package/dist/esm/components/atoms/Input/Input.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/Password/Password.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/RadioButton/RadioButton.d.ts +1 -1
- package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
- package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/TextArea/TextArea.d.ts +1 -1
- package/dist/esm/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
- package/dist/esm/components/atoms/Toggle/Toggle.d.ts +1 -1
- package/dist/esm/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
- package/dist/esm/components/molecules/FormField/FormField.d.ts +2 -28
- package/dist/esm/components/molecules/FormField/FormField.presenter.d.ts +8 -17
- package/dist/esm/components/molecules/FormField/FormField.types.d.ts +52 -115
- package/dist/esm/components/molecules/FormField/FormField.utils.d.ts +11 -8
- package/dist/esm/components/molecules/FormField/index.d.ts +2 -1
- package/dist/esm/components/molecules/Search/Search.d.ts +1 -1
- package/dist/esm/components/molecules/Search/Search.presenter.d.ts +2 -2
- package/dist/esm/components/molecules/Select/Select.presenter.d.ts +4 -4
- package/dist/esm/components/organisms/Form/DropzoneFormExample.d.ts +6 -0
- package/dist/esm/components/organisms/Form/Form.d.ts +1 -22
- package/dist/esm/components/organisms/Form/Form.types.d.ts +93 -64
- package/dist/esm/components/organisms/Form/Form.utils.d.ts +2 -0
- package/dist/esm/components/organisms/Form/FormContext.d.ts +5 -0
- package/dist/esm/components/organisms/Form/UpdatedFormExample.d.ts +23 -0
- package/dist/esm/components/organisms/Form/{examples/UseFormExample.d.ts → UseFormExample.d.ts} +3 -0
- package/dist/esm/components/organisms/Form/index.d.ts +3 -7
- package/dist/esm/components/organisms/Form/useForm.d.ts +40 -43
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +228 -319
- package/docs/components/molecules/FormField.md +34 -129
- package/docs/components/organisms/Form.md +162 -858
- package/package.json +1 -4
- package/dist/cjs/components/molecules/FormField/useSafeController.d.ts +0 -14
- package/dist/cjs/components/molecules/FormField/useSafeFormContext.d.ts +0 -8
- package/dist/cjs/components/organisms/Form/Form.presenter.d.ts +0 -290
- package/dist/cjs/components/organisms/Form/examples/DropzoneFormExample.d.ts +0 -6
- package/dist/cjs/components/organisms/Form/examples/UpdatedFormExample.d.ts +0 -2
- package/dist/cjs/components/organisms/Form/useAutosave.d.ts +0 -10
- package/dist/esm/components/molecules/FormField/useSafeController.d.ts +0 -14
- package/dist/esm/components/molecules/FormField/useSafeFormContext.d.ts +0 -8
- package/dist/esm/components/organisms/Form/Form.presenter.d.ts +0 -290
- package/dist/esm/components/organisms/Form/examples/DropzoneFormExample.d.ts +0 -6
- package/dist/esm/components/organisms/Form/examples/UpdatedFormExample.d.ts +0 -2
- package/dist/esm/components/organisms/Form/useAutosave.d.ts +0 -10
- package/docs/FORM_MIGRATION_GUIDE.md +0 -631
- /package/dist/cjs/components/organisms/Form/{examples/AutosaveFormExample.d.ts → AutosaveFormExample.d.ts} +0 -0
- /package/dist/esm/components/organisms/Form/{examples/AutosaveFormExample.d.ts → AutosaveFormExample.d.ts} +0 -0
|
@@ -1,35 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
export type { FieldValue, FieldValidationFunction, AsyncFieldValidationFunction, } from '../../molecules/FormField/FormField.types';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FormHTMLAttributes, Ref } from 'react';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Type representing the allowed values for form fields
|
|
6
5
|
*/
|
|
7
|
-
export type
|
|
6
|
+
export type FieldValue = string | number | Date | boolean | File | Array<string | number | Date | File>;
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
* Use the new FormSubmitHandler signature without setError instead.
|
|
11
|
-
*
|
|
12
|
-
* Type representing a function that handles form submission.
|
|
13
|
-
* It takes updated form state and a function to set error messages for specific fields.
|
|
14
|
-
*
|
|
15
|
-
* @template T - The type of the form state, defaulting to FieldValues.
|
|
16
|
-
*
|
|
17
|
-
* @param {T} values - The updated form state values.
|
|
18
|
-
* @param {(field: keyof T, errorMessage: string) => void} setError - A function to set error messages for specific fields.
|
|
19
|
-
*
|
|
8
|
+
* Type representing the form values as a partial record of field names to field values
|
|
20
9
|
* @example
|
|
21
10
|
* ```typescript
|
|
22
|
-
* const
|
|
23
|
-
*
|
|
24
|
-
*
|
|
11
|
+
* const formState: FormState = {
|
|
12
|
+
* name: 'John Doe',
|
|
13
|
+
* age: 30,
|
|
14
|
+
* dob: new Date('1990-01-01')
|
|
25
15
|
* };
|
|
26
16
|
* ```
|
|
27
17
|
*/
|
|
28
|
-
export type
|
|
18
|
+
export type FormState<T extends FieldValue = FieldValue> = Partial<Record<string, T>>;
|
|
19
|
+
/**
|
|
20
|
+
* Type representing the form errors as a partial record of field names to error messages
|
|
21
|
+
*/
|
|
22
|
+
export type FormErrors<T extends FormState = FormState> = Partial<Record<keyof T, string>>;
|
|
23
|
+
/**
|
|
24
|
+
* Type representing a validation function for a form field
|
|
25
|
+
* It takes an error setter function and the field value (optional) and returns a boolean indicating if the value is valid
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const nameValidator: FieldValidationFunction = (setError, value) => {
|
|
29
|
+
* if (!value) {
|
|
30
|
+
* setError('Name is required');
|
|
31
|
+
* return false;
|
|
32
|
+
* }
|
|
33
|
+
* return true;
|
|
34
|
+
* };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type FieldValidationFunction<T extends FieldValue = FieldValue> = (setError: (message: string) => void, value?: T) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Type representing the required fields in a form
|
|
40
|
+
* It's a partial record of field names to a boolean indicating if the field is required
|
|
41
|
+
*/
|
|
42
|
+
export type RequiredFields<T extends FormState = FormState> = Partial<Record<keyof T, boolean>>;
|
|
43
|
+
/**
|
|
44
|
+
* Type representing the validation functions for each field in a form
|
|
45
|
+
* It's a partial record of field names to validation functions (or undefined)
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const nameValidator: FieldValidationFunction = (setError, value) => {
|
|
49
|
+
* if (!value) {
|
|
50
|
+
* setError('Name is required');
|
|
51
|
+
* return false;
|
|
52
|
+
* }
|
|
53
|
+
* return true;
|
|
54
|
+
* };
|
|
55
|
+
* const fieldValidators: FieldValidators = {
|
|
56
|
+
* name: nameValidator,
|
|
57
|
+
* age: undefined,
|
|
58
|
+
* };
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export type FieldValidators<T extends FormState = FormState> = Partial<Record<keyof T, FieldValidationFunction | undefined>>;
|
|
29
62
|
/**
|
|
30
|
-
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
31
|
-
* Use React Hook Form's built-in validation or field-level validation instead.
|
|
32
|
-
*
|
|
33
63
|
* Type representing a function that handles form state changes
|
|
34
64
|
* It takes the new form state and an error setter function and doesn't return anything
|
|
35
65
|
* @example
|
|
@@ -42,11 +72,8 @@ export type LegacyFormSubmitHandler<T extends FieldValues = FieldValues> = (valu
|
|
|
42
72
|
* };
|
|
43
73
|
* ```
|
|
44
74
|
*/
|
|
45
|
-
export type FormStateChangeHandler<T extends
|
|
75
|
+
export type FormStateChangeHandler<T extends FormState = FormState> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => void;
|
|
46
76
|
/**
|
|
47
|
-
* @deprecated This type is deprecated and maintained for backwards compatibility only.
|
|
48
|
-
* Use React Hook Form's resolver or field-level validation instead.
|
|
49
|
-
*
|
|
50
77
|
* Type representing a function that validates the entire form
|
|
51
78
|
* It takes the form values and an error setter function and returns a boolean indicating if the form is valid
|
|
52
79
|
* @example
|
|
@@ -65,45 +92,47 @@ export type FormStateChangeHandler<T extends FieldValues = FieldValues> = (state
|
|
|
65
92
|
* };
|
|
66
93
|
* ```
|
|
67
94
|
*/
|
|
68
|
-
export type FormValidator<T extends
|
|
95
|
+
export type FormValidator<T extends FormState = FormState> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => boolean;
|
|
69
96
|
/**
|
|
70
|
-
*
|
|
97
|
+
* Type representing a function that handles form submission.
|
|
98
|
+
* It takes updated form state and a function to set error messages for specific fields.
|
|
99
|
+
*
|
|
100
|
+
* @template T - The type of the form state, defaulting to `FormState`.
|
|
101
|
+
*
|
|
102
|
+
* @param {T} values - The updated form state values.
|
|
103
|
+
* @param {(field: keyof T, errorMessage: string) => void} setError - A function to set error messages for specific fields.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const handleFormSubmit: FormSubmitHandler = (values, setError) => {
|
|
108
|
+
* // Submit form data
|
|
109
|
+
* console.log(values);
|
|
110
|
+
* };
|
|
111
|
+
* ```
|
|
71
112
|
*/
|
|
72
|
-
export type
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
113
|
+
export type FormSubmitHandler<T extends FormState = FormState> = (values: T, setError: (field: keyof T, errorMessage: string) => void) => void;
|
|
114
|
+
export type FormProps = Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit'> & {
|
|
115
|
+
formRef?: Ref<HTMLFormElement>;
|
|
116
|
+
};
|
|
117
|
+
export type FormContextValues<T extends FormState = FormState> = {
|
|
118
|
+
formRef?: Ref<HTMLFormElement>;
|
|
119
|
+
formState?: T;
|
|
120
|
+
updateFieldValue: (name: string, value: FieldValue) => void;
|
|
121
|
+
formErrors: FormErrors<T>;
|
|
122
|
+
updateFieldError: (name: keyof T, errorMessage: string) => void;
|
|
123
|
+
onFormSubmit: React.FormEventHandler<HTMLFormElement>;
|
|
124
|
+
updateFieldValidators: (name: keyof T, validate?: FieldValidationFunction) => void;
|
|
125
|
+
updateRequiredFields: (name: keyof T, required?: boolean) => void;
|
|
126
|
+
resetForm: () => void;
|
|
127
|
+
};
|
|
128
|
+
export type FormProviderProps<T extends FormState = FormState> = {
|
|
129
|
+
formRef?: Ref<HTMLFormElement>;
|
|
130
|
+
children?: React.ReactNode;
|
|
131
|
+
formState?: T;
|
|
132
|
+
onFormStateChange?: FormStateChangeHandler<T>;
|
|
133
|
+
formValidator?: FormValidator<T>;
|
|
134
|
+
onSubmit?: FormSubmitHandler<T>;
|
|
135
|
+
validateOnChange?: boolean;
|
|
78
136
|
autosave?: boolean;
|
|
79
|
-
/** Autosave debounce delay in milliseconds */
|
|
80
137
|
autosaveDelayMs?: number;
|
|
81
|
-
/** RHF validation mode */
|
|
82
|
-
mode?: UseFormProps<TFormValues>['mode'];
|
|
83
|
-
/** Additional RHF options */
|
|
84
|
-
formOptions?: Omit<UseFormProps<TFormValues>, 'defaultValues' | 'mode'>;
|
|
85
|
-
/** Ref to the form element */
|
|
86
|
-
formRef?: React.Ref<HTMLFormElement>;
|
|
87
|
-
/**
|
|
88
|
-
* @deprecated Use defaultValues instead. This prop is maintained for backwards compatibility only.
|
|
89
|
-
* Alias for defaultValues - initial form values
|
|
90
|
-
*/
|
|
91
|
-
formState?: UseFormProps<TFormValues>['defaultValues'];
|
|
92
|
-
/**
|
|
93
|
-
* @deprecated Use React Hook Form's useWatch hook or field-level validation instead.
|
|
94
|
-
* This prop is maintained for backwards compatibility only.
|
|
95
|
-
* Callback fired whenever form values change
|
|
96
|
-
*/
|
|
97
|
-
onFormStateChange?: FormStateChangeHandler<TFormValues>;
|
|
98
|
-
/**
|
|
99
|
-
* @deprecated Use React Hook Form's resolver or field-level validation instead.
|
|
100
|
-
* This prop is maintained for backwards compatibility only.
|
|
101
|
-
* Custom validator function for the entire form
|
|
102
|
-
*/
|
|
103
|
-
formValidator?: FormValidator<TFormValues>;
|
|
104
138
|
};
|
|
105
|
-
/**
|
|
106
|
-
* @deprecated Use FormProps instead
|
|
107
|
-
* Legacy alias for backwards compatibility
|
|
108
|
-
*/
|
|
109
|
-
export type FormProviderProps<TFormValues extends FieldValues = FieldValues> = Omit<FormProps<TFormValues>, 'className' | 'style' | 'formRef'>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FormContextValues, FormProviderProps, FormState, FieldValue } from './Form.types';
|
|
3
|
+
declare const FormContext: React.Context<FormContextValues<Partial<Record<string, FieldValue>>> | undefined>;
|
|
4
|
+
export declare const FormProvider: <T extends FormState>(props: FormProviderProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export default FormContext;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ProfileFormValues = {
|
|
2
|
+
name: string;
|
|
3
|
+
email: string;
|
|
4
|
+
address: string;
|
|
5
|
+
password: string;
|
|
6
|
+
termsAccepted: boolean;
|
|
7
|
+
gender: string;
|
|
8
|
+
interests: boolean;
|
|
9
|
+
skillLevel: number;
|
|
10
|
+
experienceRange: [number, number];
|
|
11
|
+
favoriteFramework: string[];
|
|
12
|
+
skills: string[];
|
|
13
|
+
birthdate: string | Date;
|
|
14
|
+
availableForWork: boolean;
|
|
15
|
+
wantsNewsletter: boolean;
|
|
16
|
+
promotionalEmails: boolean;
|
|
17
|
+
darkMode: boolean;
|
|
18
|
+
notifications: boolean;
|
|
19
|
+
preferredContactMethod: string;
|
|
20
|
+
acceptedGuidelines: boolean;
|
|
21
|
+
};
|
|
22
|
+
declare const ProfileForm: () => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export default ProfileForm;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { FormProps, FormProviderProps, FormState } from './Form.types';
|
|
2
|
+
declare const Form: <T extends FormState>(props: FormProviderProps<T> & FormProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
3
|
export default Form;
|
|
3
|
-
export
|
|
4
|
-
LegacyFormSubmitHandler, // deprecated
|
|
5
|
-
FormStateChangeHandler, // deprecated
|
|
6
|
-
FormValidator, } from './Form.types';
|
|
7
|
-
export type { FieldValue } from './Form.types';
|
|
8
|
-
export { useAutosave } from './useAutosave';
|
|
4
|
+
export * from './Form.types';
|
|
9
5
|
export { useForm, useFormTyped } from './useForm';
|
|
@@ -1,53 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { FieldValue } from './Form.types';
|
|
1
|
+
import type { FormContextValues, FormState } from './Form.types';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3
|
+
* Custom hook to access form context values.
|
|
4
|
+
* Provides direct access to all form state management functions and values.
|
|
5
|
+
*
|
|
6
|
+
* @throws {Error} If used outside of a Form component
|
|
7
|
+
* @returns {FormContextValues} Object containing form state and control functions
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```tsx
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* const MyCustomField = () => {
|
|
12
|
+
* const {
|
|
13
|
+
* formState,
|
|
14
|
+
* formErrors,
|
|
15
|
+
* updateFieldValue,
|
|
16
|
+
* resetForm
|
|
17
|
+
* } = useForm();
|
|
14
18
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <input
|
|
22
|
+
* value={formState.myField || ''}
|
|
23
|
+
* onChange={(e) => updateFieldValue('myField', e.target.value)}
|
|
24
|
+
* />
|
|
25
|
+
* {formErrors.myField && <span>{formErrors.myField}</span>}
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* };
|
|
20
29
|
* ```
|
|
21
30
|
*/
|
|
22
|
-
export declare const useForm: <T extends
|
|
23
|
-
/** Current form values */
|
|
24
|
-
formState: T;
|
|
25
|
-
/** Current form errors as { fieldName: "error message" } */
|
|
26
|
-
formErrors: Record<keyof T, string>;
|
|
27
|
-
/** Update a field value */
|
|
28
|
-
updateFieldValue: (name: keyof T | string, value: FieldValue) => void;
|
|
29
|
-
/** Set an error for a field */
|
|
30
|
-
updateFieldError: (name: keyof T | string, errorMessage: string) => void;
|
|
31
|
-
/** Reset form to initial values */
|
|
32
|
-
resetForm: () => void;
|
|
33
|
-
/** Submit handler (wrap your submit function) */
|
|
34
|
-
onFormSubmit: import("react-hook-form").UseFormHandleSubmit<T, T>;
|
|
35
|
-
};
|
|
31
|
+
export declare const useForm: <T extends FormState = Partial<Record<string, import("./Form.types").FieldValue>>>() => FormContextValues<T>;
|
|
36
32
|
/**
|
|
37
|
-
* @deprecated Use useForm instead, or better yet, use react-hook-form hooks directly.
|
|
38
33
|
* Type-safe version of useForm that returns properly typed form context
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* interface MyFormData {
|
|
38
|
+
* name: string;
|
|
39
|
+
* email: string;
|
|
40
|
+
* age: number;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* const MyComponent = () => {
|
|
44
|
+
* const form = useFormTyped<MyFormData>();
|
|
45
|
+
* // form.formState is now typed as MyFormData
|
|
46
|
+
* // form.formErrors is now typed as FormErrors<MyFormData>
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
39
49
|
*/
|
|
40
|
-
export declare const useFormTyped: <T extends
|
|
41
|
-
/** Current form values */
|
|
42
|
-
formState: T;
|
|
43
|
-
/** Current form errors as { fieldName: "error message" } */
|
|
44
|
-
formErrors: Record<keyof T, string>;
|
|
45
|
-
/** Update a field value */
|
|
46
|
-
updateFieldValue: (name: string | keyof T, value: FieldValue) => void;
|
|
47
|
-
/** Set an error for a field */
|
|
48
|
-
updateFieldError: (name: string | keyof T, errorMessage: string) => void;
|
|
49
|
-
/** Reset form to initial values */
|
|
50
|
-
resetForm: () => void;
|
|
51
|
-
/** Submit handler (wrap your submit function) */
|
|
52
|
-
onFormSubmit: import("react-hook-form").UseFormHandleSubmit<T, T>;
|
|
53
|
-
};
|
|
50
|
+
export declare const useFormTyped: <T extends FormState>() => FormContextValues<T>;
|