@delightui/components 0.1.138 → 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/molecules/Select/Select.types.d.ts +4 -0
- package/dist/cjs/components/molecules/Select/Select.utils.d.ts +0 -7
- 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.css +1 -0
- package/dist/cjs/library.js +3 -3
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/molecules/Select/Select.types.d.ts +4 -0
- package/dist/esm/components/molecules/Select/Select.utils.d.ts +0 -7
- 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.css +1 -0
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +55 -1
- package/docs/hooks/useForm.md +248 -0
- package/package.json +1 -1
|
@@ -20,6 +20,10 @@ export type SelectContextType = {
|
|
|
20
20
|
* Function to reset the selected value to its default state.
|
|
21
21
|
*/
|
|
22
22
|
resetSelectedValue: () => void;
|
|
23
|
+
/**
|
|
24
|
+
* Function to register an option's value-label pair.
|
|
25
|
+
*/
|
|
26
|
+
registerOption: (optionValue: FieldValue, label: React.ReactNode) => void;
|
|
23
27
|
/**
|
|
24
28
|
* Function to get the display label for a value.
|
|
25
29
|
*/
|
|
@@ -33,10 +33,3 @@ export declare const handleSelectionChange: (newValue: string | number, selected
|
|
|
33
33
|
* @returns Whether the option is selected or not.
|
|
34
34
|
*/
|
|
35
35
|
export declare const checkIsSelected: (optionValue?: string, selectedValue?: FieldValue) => boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Utility to recursively find Option components and extract their props
|
|
38
|
-
*/
|
|
39
|
-
export declare const extractOptionProps: (children: React.ReactNode, OptionComponent: React.ComponentType<any>) => Array<{
|
|
40
|
-
value: FieldValue;
|
|
41
|
-
label: React.ReactNode;
|
|
42
|
-
}>;
|
|
@@ -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>;
|
package/dist/esm/library.css
CHANGED