@delightui/components 0.1.162-alpha.4 → 0.1.162-alpha.5
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/organisms/Form/index.d.ts +1 -0
- package/dist/cjs/components/organisms/Form/useAutosave.d.ts +2 -2
- package/dist/cjs/components/organisms/Form/useForm.d.ts +53 -0
- package/dist/cjs/library.js +1 -1
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/organisms/Form/index.d.ts +1 -0
- package/dist/esm/components/organisms/Form/useAutosave.d.ts +2 -2
- package/dist/esm/components/organisms/Form/useForm.d.ts +53 -0
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +55 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FieldValues } from 'react-hook-form';
|
|
2
|
-
import type { FormSubmitHandler } from './Form.types';
|
|
2
|
+
import type { FormSubmitHandler, LegacyFormSubmitHandler } from './Form.types';
|
|
3
3
|
/**
|
|
4
4
|
* Hook to enable autosave functionality for forms
|
|
5
5
|
* Debounces changes and validates before submitting
|
|
@@ -7,4 +7,4 @@ import type { FormSubmitHandler } from './Form.types';
|
|
|
7
7
|
* Note: Uses formState.isDirty to detect changes instead of watching all values
|
|
8
8
|
* for better performance
|
|
9
9
|
*/
|
|
10
|
-
export declare const useAutosave: <TFormValues extends FieldValues>(enabled: boolean, onSubmit: FormSubmitHandler<TFormValues> | undefined, delayMs?: number) => void;
|
|
10
|
+
export declare const useAutosave: <TFormValues extends FieldValues>(enabled: boolean, onSubmit: FormSubmitHandler<TFormValues> | LegacyFormSubmitHandler<TFormValues> | undefined, delayMs?: number) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type FieldValues } from 'react-hook-form';
|
|
2
|
+
import type { FieldValue } from './Form.types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated This hook is deprecated and maintained for backwards compatibility only.
|
|
5
|
+
* Use react-hook-form hooks directly instead:
|
|
6
|
+
* - `useFormContext()` for setValue, setError, reset, handleSubmit
|
|
7
|
+
* - `useWatch()` for form values
|
|
8
|
+
* - `useFormState()` for errors, isDirty, isValid, etc.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* // Old API (deprecated)
|
|
13
|
+
* const { formState, formErrors, updateFieldValue, resetForm } = useForm();
|
|
14
|
+
*
|
|
15
|
+
* // New API (recommended)
|
|
16
|
+
* import { useFormContext, useWatch, useFormState } from 'react-hook-form';
|
|
17
|
+
* const { setValue, setError, reset } = useFormContext();
|
|
18
|
+
* const formValues = useWatch();
|
|
19
|
+
* const { errors } = useFormState();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const useForm: <T extends FieldValues = FieldValues>() => {
|
|
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
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use useForm instead, or better yet, use react-hook-form hooks directly.
|
|
38
|
+
* Type-safe version of useForm that returns properly typed form context
|
|
39
|
+
*/
|
|
40
|
+
export declare const useFormTyped: <T extends FieldValues>() => {
|
|
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
|
+
};
|