@delightui/components 0.1.162-alpha.4 → 0.1.162

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.
Files changed (89) hide show
  1. package/dist/cjs/components/atoms/Checkbox/Checkbox.d.ts +1 -1
  2. package/dist/cjs/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
  3. package/dist/cjs/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
  4. package/dist/cjs/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
  5. package/dist/cjs/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
  6. package/dist/cjs/components/atoms/Input/Input.d.ts +1 -1
  7. package/dist/cjs/components/atoms/Input/Input.presenter.d.ts +2 -2
  8. package/dist/cjs/components/atoms/Password/Password.presenter.d.ts +2 -2
  9. package/dist/cjs/components/atoms/RadioButton/RadioButton.d.ts +1 -1
  10. package/dist/cjs/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
  11. package/dist/cjs/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
  12. package/dist/cjs/components/atoms/TextArea/TextArea.d.ts +1 -1
  13. package/dist/cjs/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
  14. package/dist/cjs/components/atoms/Toggle/Toggle.d.ts +1 -1
  15. package/dist/cjs/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
  16. package/dist/cjs/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
  17. package/dist/cjs/components/molecules/FormField/FormField.d.ts +2 -28
  18. package/dist/cjs/components/molecules/FormField/FormField.presenter.d.ts +8 -17
  19. package/dist/cjs/components/molecules/FormField/FormField.types.d.ts +52 -115
  20. package/dist/cjs/components/molecules/FormField/FormField.utils.d.ts +11 -8
  21. package/dist/cjs/components/molecules/FormField/index.d.ts +2 -1
  22. package/dist/cjs/components/molecules/Search/Search.d.ts +1 -1
  23. package/dist/cjs/components/molecules/Search/Search.presenter.d.ts +2 -2
  24. package/dist/cjs/components/molecules/Select/Select.presenter.d.ts +4 -4
  25. package/dist/cjs/components/organisms/Form/DropzoneFormExample.d.ts +6 -0
  26. package/dist/cjs/components/organisms/Form/Form.d.ts +1 -22
  27. package/dist/cjs/components/organisms/Form/Form.types.d.ts +93 -64
  28. package/dist/cjs/components/organisms/Form/Form.utils.d.ts +2 -0
  29. package/dist/cjs/components/organisms/Form/FormContext.d.ts +5 -0
  30. package/dist/cjs/components/organisms/Form/UpdatedFormExample.d.ts +23 -0
  31. package/dist/cjs/components/organisms/Form/{examples/UseFormExample.d.ts → UseFormExample.d.ts} +3 -0
  32. package/dist/cjs/components/organisms/Form/index.d.ts +4 -7
  33. package/dist/cjs/components/organisms/Form/useForm.d.ts +50 -0
  34. package/dist/cjs/library.js +3 -3
  35. package/dist/cjs/library.js.map +1 -1
  36. package/dist/esm/components/atoms/Checkbox/Checkbox.d.ts +1 -1
  37. package/dist/esm/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
  38. package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
  39. package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
  40. package/dist/esm/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
  41. package/dist/esm/components/atoms/Input/Input.d.ts +1 -1
  42. package/dist/esm/components/atoms/Input/Input.presenter.d.ts +2 -2
  43. package/dist/esm/components/atoms/Password/Password.presenter.d.ts +2 -2
  44. package/dist/esm/components/atoms/RadioButton/RadioButton.d.ts +1 -1
  45. package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
  46. package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
  47. package/dist/esm/components/atoms/TextArea/TextArea.d.ts +1 -1
  48. package/dist/esm/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
  49. package/dist/esm/components/atoms/Toggle/Toggle.d.ts +1 -1
  50. package/dist/esm/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
  51. package/dist/esm/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
  52. package/dist/esm/components/molecules/FormField/FormField.d.ts +2 -28
  53. package/dist/esm/components/molecules/FormField/FormField.presenter.d.ts +8 -17
  54. package/dist/esm/components/molecules/FormField/FormField.types.d.ts +52 -115
  55. package/dist/esm/components/molecules/FormField/FormField.utils.d.ts +11 -8
  56. package/dist/esm/components/molecules/FormField/index.d.ts +2 -1
  57. package/dist/esm/components/molecules/Search/Search.d.ts +1 -1
  58. package/dist/esm/components/molecules/Search/Search.presenter.d.ts +2 -2
  59. package/dist/esm/components/molecules/Select/Select.presenter.d.ts +4 -4
  60. package/dist/esm/components/organisms/Form/DropzoneFormExample.d.ts +6 -0
  61. package/dist/esm/components/organisms/Form/Form.d.ts +1 -22
  62. package/dist/esm/components/organisms/Form/Form.types.d.ts +93 -64
  63. package/dist/esm/components/organisms/Form/Form.utils.d.ts +2 -0
  64. package/dist/esm/components/organisms/Form/FormContext.d.ts +5 -0
  65. package/dist/esm/components/organisms/Form/UpdatedFormExample.d.ts +23 -0
  66. package/dist/esm/components/organisms/Form/{examples/UseFormExample.d.ts → UseFormExample.d.ts} +3 -0
  67. package/dist/esm/components/organisms/Form/index.d.ts +4 -7
  68. package/dist/esm/components/organisms/Form/useForm.d.ts +50 -0
  69. package/dist/esm/library.js +3 -3
  70. package/dist/esm/library.js.map +1 -1
  71. package/dist/index.d.ts +232 -270
  72. package/docs/components/molecules/FormField.md +34 -129
  73. package/docs/components/organisms/Form.md +162 -858
  74. package/package.json +1 -4
  75. package/dist/cjs/components/molecules/FormField/useSafeController.d.ts +0 -14
  76. package/dist/cjs/components/molecules/FormField/useSafeFormContext.d.ts +0 -8
  77. package/dist/cjs/components/organisms/Form/Form.presenter.d.ts +0 -290
  78. package/dist/cjs/components/organisms/Form/examples/DropzoneFormExample.d.ts +0 -6
  79. package/dist/cjs/components/organisms/Form/examples/UpdatedFormExample.d.ts +0 -2
  80. package/dist/cjs/components/organisms/Form/useAutosave.d.ts +0 -10
  81. package/dist/esm/components/molecules/FormField/useSafeController.d.ts +0 -14
  82. package/dist/esm/components/molecules/FormField/useSafeFormContext.d.ts +0 -8
  83. package/dist/esm/components/organisms/Form/Form.presenter.d.ts +0 -290
  84. package/dist/esm/components/organisms/Form/examples/DropzoneFormExample.d.ts +0 -6
  85. package/dist/esm/components/organisms/Form/examples/UpdatedFormExample.d.ts +0 -2
  86. package/dist/esm/components/organisms/Form/useAutosave.d.ts +0 -10
  87. package/docs/FORM_MIGRATION_GUIDE.md +0 -631
  88. /package/dist/cjs/components/organisms/Form/{examples/AutosaveFormExample.d.ts → AutosaveFormExample.d.ts} +0 -0
  89. /package/dist/esm/components/organisms/Form/{examples/AutosaveFormExample.d.ts → AutosaveFormExample.d.ts} +0 -0
@@ -1,35 +1,65 @@
1
- import type { FormHTMLAttributes } from 'react';
2
- import type { FieldValues, UseFormProps } from 'react-hook-form';
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
- * Form submission handler
4
+ * Type representing the allowed values for form fields
6
5
  */
7
- export type FormSubmitHandler<TFormValues extends FieldValues = FieldValues> = (values: TFormValues) => void | Promise<void>;
6
+ export type FieldValue = string | number | Date | boolean | File | Array<string | number | Date | File>;
8
7
  /**
9
- * @deprecated This type is deprecated and maintained for backwards compatibility only.
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 handleFormSubmit: LegacyFormSubmitHandler = (values, setError) => {
23
- * // Submit form data
24
- * console.log(values);
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 LegacyFormSubmitHandler<T extends FieldValues = FieldValues> = (values: T, setError: (field: keyof T, errorMessage: string) => void) => void | Promise<void>;
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 FieldValues = FieldValues> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => void;
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 FieldValues = FieldValues> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => boolean;
95
+ export type FormValidator<T extends FormState = FormState> = (state: T, setError: (field: keyof T, errorMessage: string) => void) => boolean;
69
96
  /**
70
- * Form component props
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 FormProps<TFormValues extends FieldValues = FieldValues> = Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'ref'> & {
73
- /** Initial form values (uncontrolled mode) */
74
- defaultValues?: UseFormProps<TFormValues>['defaultValues'];
75
- /** Form submission handler - receives typed form values (supports both new and legacy signatures) */
76
- onSubmit?: FormSubmitHandler<TFormValues> | LegacyFormSubmitHandler<TFormValues>;
77
- /** Enable autosave functionality */
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,2 @@
1
+ import { FieldValue, FormState } from "./Form.types";
2
+ export declare const isEqualFormState: <T extends FieldValue>(state1: FormState<T>, state2: FormState<T>) => boolean;
@@ -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,2 +1,5 @@
1
+ /**
2
+ * Main example demonstrating the useForm hook
3
+ */
1
4
  declare const UseFormExample: () => import("react/jsx-runtime").JSX.Element;
2
5
  export default UseFormExample;
@@ -1,8 +1,5 @@
1
- import Form from './Form';
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 type { FormProps, FormSubmitHandler, FormProviderProps, // deprecated
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';
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>;