@delightui/components 0.1.139 → 0.1.140
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/UseFormExample.d.ts +5 -0
- package/dist/cjs/components/organisms/Form/index.d.ts +1 -0
- package/dist/cjs/components/organisms/Form/useForm.d.ts +50 -0
- package/dist/cjs/library.js +3 -3
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/organisms/Form/UseFormExample.d.ts +5 -0
- package/dist/esm/components/organisms/Form/index.d.ts +1 -0
- package/dist/esm/components/organisms/Form/useForm.d.ts +50 -0
- package/dist/esm/library.js +2 -2
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +51 -1
- package/docs/hooks/useForm.md +248 -0
- package/package.json +1 -1
|
@@ -2,3 +2,4 @@ import type { FormProps, FormProviderProps, FormState } from './Form.types';
|
|
|
2
2
|
declare const Form: <T extends FormState>(props: FormProviderProps<T> & FormProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Form;
|
|
4
4
|
export * from './Form.types';
|
|
5
|
+
export { useForm, useFormTyped } from './useForm';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { FormContextValues, FormState } from './Form.types';
|
|
2
|
+
/**
|
|
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
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const MyCustomField = () => {
|
|
12
|
+
* const {
|
|
13
|
+
* formState,
|
|
14
|
+
* formErrors,
|
|
15
|
+
* updateFieldValue,
|
|
16
|
+
* resetForm
|
|
17
|
+
* } = useForm();
|
|
18
|
+
*
|
|
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
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const useForm: <T extends FormState = Partial<Record<string, import("./Form.types").FieldValue>>>() => FormContextValues<T>;
|
|
32
|
+
/**
|
|
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
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const useFormTyped: <T extends FormState>() => FormContextValues<T>;
|