@delightui/components 0.1.161 → 0.1.162-alpha.0

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 +28 -2
  18. package/dist/cjs/components/molecules/FormField/FormField.presenter.d.ts +14 -8
  19. package/dist/cjs/components/molecules/FormField/FormField.types.d.ts +85 -52
  20. package/dist/cjs/components/molecules/FormField/FormField.utils.d.ts +8 -11
  21. package/dist/cjs/components/molecules/FormField/index.d.ts +1 -2
  22. package/dist/cjs/components/molecules/FormField/useSafeController.d.ts +14 -0
  23. package/dist/cjs/components/molecules/FormField/useSafeFormContext.d.ts +8 -0
  24. package/dist/cjs/components/molecules/Search/Search.d.ts +1 -1
  25. package/dist/cjs/components/molecules/Search/Search.presenter.d.ts +2 -2
  26. package/dist/cjs/components/molecules/Select/Select.presenter.d.ts +4 -4
  27. package/dist/cjs/components/organisms/Form/Form.d.ts +22 -1
  28. package/dist/cjs/components/organisms/Form/Form.presenter.d.ts +21 -0
  29. package/dist/cjs/components/organisms/Form/Form.types.d.ts +27 -131
  30. package/dist/cjs/components/organisms/Form/examples/DropzoneFormExample.d.ts +6 -0
  31. package/dist/cjs/components/organisms/Form/examples/UpdatedFormExample.d.ts +2 -0
  32. package/dist/cjs/components/organisms/Form/{UseFormExample.d.ts → examples/UseFormExample.d.ts} +0 -3
  33. package/dist/cjs/components/organisms/Form/index.d.ts +4 -4
  34. package/dist/cjs/components/organisms/Form/useAutosave.d.ts +10 -0
  35. package/dist/cjs/library.js +3 -3
  36. package/dist/cjs/library.js.map +1 -1
  37. package/dist/esm/components/atoms/Checkbox/Checkbox.d.ts +1 -1
  38. package/dist/esm/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
  39. package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
  40. package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
  41. package/dist/esm/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
  42. package/dist/esm/components/atoms/Input/Input.d.ts +1 -1
  43. package/dist/esm/components/atoms/Input/Input.presenter.d.ts +2 -2
  44. package/dist/esm/components/atoms/Password/Password.presenter.d.ts +2 -2
  45. package/dist/esm/components/atoms/RadioButton/RadioButton.d.ts +1 -1
  46. package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
  47. package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
  48. package/dist/esm/components/atoms/TextArea/TextArea.d.ts +1 -1
  49. package/dist/esm/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
  50. package/dist/esm/components/atoms/Toggle/Toggle.d.ts +1 -1
  51. package/dist/esm/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
  52. package/dist/esm/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
  53. package/dist/esm/components/molecules/FormField/FormField.d.ts +28 -2
  54. package/dist/esm/components/molecules/FormField/FormField.presenter.d.ts +14 -8
  55. package/dist/esm/components/molecules/FormField/FormField.types.d.ts +85 -52
  56. package/dist/esm/components/molecules/FormField/FormField.utils.d.ts +8 -11
  57. package/dist/esm/components/molecules/FormField/index.d.ts +1 -2
  58. package/dist/esm/components/molecules/FormField/useSafeController.d.ts +14 -0
  59. package/dist/esm/components/molecules/FormField/useSafeFormContext.d.ts +8 -0
  60. package/dist/esm/components/molecules/Search/Search.d.ts +1 -1
  61. package/dist/esm/components/molecules/Search/Search.presenter.d.ts +2 -2
  62. package/dist/esm/components/molecules/Select/Select.presenter.d.ts +4 -4
  63. package/dist/esm/components/organisms/Form/Form.d.ts +22 -1
  64. package/dist/esm/components/organisms/Form/Form.presenter.d.ts +21 -0
  65. package/dist/esm/components/organisms/Form/Form.types.d.ts +27 -131
  66. package/dist/esm/components/organisms/Form/examples/DropzoneFormExample.d.ts +6 -0
  67. package/dist/esm/components/organisms/Form/examples/UpdatedFormExample.d.ts +2 -0
  68. package/dist/esm/components/organisms/Form/{UseFormExample.d.ts → examples/UseFormExample.d.ts} +0 -3
  69. package/dist/esm/components/organisms/Form/index.d.ts +4 -4
  70. package/dist/esm/components/organisms/Form/useAutosave.d.ts +10 -0
  71. package/dist/esm/library.js +3 -3
  72. package/dist/esm/library.js.map +1 -1
  73. package/dist/index.d.ts +165 -232
  74. package/docs/FORM_MIGRATION_GUIDE.md +631 -0
  75. package/docs/components/molecules/FormField.md +129 -34
  76. package/docs/components/organisms/Form.md +858 -162
  77. package/package.json +4 -1
  78. package/dist/cjs/components/organisms/Form/DropzoneFormExample.d.ts +0 -6
  79. package/dist/cjs/components/organisms/Form/Form.utils.d.ts +0 -2
  80. package/dist/cjs/components/organisms/Form/FormContext.d.ts +0 -5
  81. package/dist/cjs/components/organisms/Form/UpdatedFormExample.d.ts +0 -23
  82. package/dist/cjs/components/organisms/Form/useForm.d.ts +0 -50
  83. package/dist/esm/components/organisms/Form/DropzoneFormExample.d.ts +0 -6
  84. package/dist/esm/components/organisms/Form/Form.utils.d.ts +0 -2
  85. package/dist/esm/components/organisms/Form/FormContext.d.ts +0 -5
  86. package/dist/esm/components/organisms/Form/UpdatedFormExample.d.ts +0 -23
  87. package/dist/esm/components/organisms/Form/useForm.d.ts +0 -50
  88. /package/dist/cjs/components/organisms/Form/{AutosaveFormExample.d.ts → examples/AutosaveFormExample.d.ts} +0 -0
  89. /package/dist/esm/components/organisms/Form/{AutosaveFormExample.d.ts → examples/AutosaveFormExample.d.ts} +0 -0
@@ -1,36 +1,58 @@
1
1
  # FormField
2
2
 
3
+ > **⚠️ BREAKING CHANGES:** The FormField component has been updated to work with the new React Hook Form-based Form component. See the [Migration Guide](../../../FORM_MIGRATION_GUIDE.md) for details.
4
+
3
5
  ## Description
4
6
 
5
- A form field wrapper component that provides consistent labeling, validation messaging, and styling for form inputs. Integrates seamlessly with the Form component to provide a complete form field experience with error handling, required field indicators, and accessibility features.
7
+ A form field wrapper component that provides consistent labeling, validation messaging, and styling for form inputs. Works seamlessly with the Form component (React Hook Form) or standalone with controlled value/onChange props. Features error handling, required field indicators, async validation, and full TypeScript support.
6
8
 
7
9
  ## Aliases
8
10
 
9
11
  - FormField
10
- - FieldWrapper
11
- - InputWrapper
12
- - FormGroup
13
12
  - Field
14
13
 
15
- ## Props Breakdown
16
-
17
- **Extends:** `HTMLAttributes<HTMLDivElement>`
14
+ ## Props Breakdown (Inside Form)
18
15
 
19
16
  | Prop | Type | Default | Required | Description |
20
17
  |------|------|---------|----------|-------------|
21
- | `name` | `string` | - | Yes | Name of the form field |
18
+ | `name` | `string` (type-safe) | - | Yes | Name of the form field (type-checked against form values) |
22
19
  | `label` | `string` | - | No | Label for the form field |
23
20
  | `children` | `ReactNode` | - | Yes | Form input component to wrap |
24
- | `message` | `string` | - | No | Message for the form field |
25
- | `hasMessage` | `boolean` | `false` | No | Whether there is a message/error for the field |
26
- | `infoIcon` | `ReactNode` | - | No | Info icon for the form field |
27
21
  | `required` | `boolean` | `false` | No | Whether the form field is required |
28
- | `validate` | `FieldValidationFunction` | - | No | Validation function for the form field |
22
+ | `validate` | `(value) => string \| undefined` | - | No | Sync validation function (returns error message or undefined) |
23
+ | `asyncValidate` | `(value) => Promise<string \| undefined>` | - | No | Async validation function |
24
+ | `defaultValue` | `TValue` | - | No | Default value for this field |
25
+ | `message` | `string` | - | No | Info/helper message to display |
29
26
  | `disabled` | `boolean` | `false` | No | Whether the form field is disabled |
30
- | `invalid` | `boolean` | `false` | No | Whether the form field is invalid |
27
+ | `invalid` | `boolean` | `false` | No | External invalid state |
28
+ | `infoIcon` | `ReactNode` | - | No | Info icon element |
29
+ | `displayName` | `string` | - | No | Custom name for validation error messages |
31
30
  | `id` | `string` | - | No | ID for the form field |
32
31
 
33
- Plus all standard HTML div attributes (className, style, onClick, etc.).
32
+ ## Props Breakdown (Standalone Mode)
33
+
34
+ | Prop | Type | Default | Required | Description |
35
+ |------|------|---------|----------|-------------|
36
+ | `name` | `string` | - | Yes | Name of the form field |
37
+ | `value` | `TValue` | - | No | Controlled value |
38
+ | `onChange` | `(value: TValue) => void` | - | No | Change handler |
39
+ | `error` | `string` | - | No | External error message |
40
+ | All other props same as above | | | | |
41
+
42
+ ### Removed Props (Breaking Changes)
43
+
44
+ | OLD Prop | Migration Path |
45
+ |----------|----------------|
46
+ | `hasMessage` | No longer needed - remove it |
47
+ | `validate: (setError, value) => boolean` | Change to `(value) => string \| undefined` |
48
+
49
+ ### Key Differences from Old API
50
+
51
+ - ✅ **`validate`** now returns error message string instead of calling `setError`
52
+ - ✅ **`asyncValidate`** added for async validation
53
+ - ✅ **Standalone mode** - works without Form using `value`/`onChange`
54
+ - ✅ **Type-safe** - field names are type-checked against form values
55
+ - ✅ **`displayName`** for custom error message field names
34
56
 
35
57
  ## Examples
36
58
 
@@ -164,28 +186,26 @@ function InputTypesExample() {
164
186
  }
165
187
  ```
166
188
 
167
- ### Custom Validation
189
+ ### Custom Validation (NEW API)
168
190
  ```tsx
169
191
  function CustomValidationExample() {
170
- const validateAge = (setError, value) => {
192
+ const validateAge = (value: string) => {
171
193
  if (!value) {
172
- setError('Age is required');
173
- return false;
194
+ return 'Age is required';
174
195
  }
175
-
196
+
176
197
  const age = parseInt(value);
177
198
  if (isNaN(age) || age < 18 || age > 120) {
178
- setError('Age must be between 18 and 120');
179
- return false;
199
+ return 'Age must be between 18 and 120';
180
200
  }
181
-
182
- return true;
201
+
202
+ return undefined; // Valid
183
203
  };
184
204
 
185
205
  return (
186
- <FormField
187
- name="age"
188
- label="Age"
206
+ <FormField
207
+ name="age"
208
+ label="Age"
189
209
  required
190
210
  validate={validateAge}
191
211
  >
@@ -195,41 +215,116 @@ function CustomValidationExample() {
195
215
  }
196
216
  ```
197
217
 
198
- ### Form Integration
218
+ ### Async Validation (NEW)
219
+ ```tsx
220
+ function AsyncValidationExample() {
221
+ const validateEmail = async (value: string) => {
222
+ if (!value) return 'Email is required';
223
+
224
+ // Check if email is already registered
225
+ const response = await fetch(`/api/check-email?email=${value}`);
226
+ const { exists } = await response.json();
227
+
228
+ if (exists) {
229
+ return 'Email is already registered';
230
+ }
231
+ return undefined;
232
+ };
233
+
234
+ return (
235
+ <FormField
236
+ name="email"
237
+ label="Email"
238
+ required
239
+ asyncValidate={validateEmail}
240
+ >
241
+ <Input inputType="Email" placeholder="Enter your email" />
242
+ </FormField>
243
+ );
244
+ }
245
+ ```
246
+
247
+ ### Standalone Mode (NEW - No Form Required)
248
+ ```tsx
249
+ import { useState } from 'react';
250
+
251
+ function StandaloneFieldExample() {
252
+ const [email, setEmail] = useState('');
253
+
254
+ const validateEmail = (value: string) => {
255
+ if (!value.includes('@')) {
256
+ return 'Please enter a valid email';
257
+ }
258
+ return undefined;
259
+ };
260
+
261
+ return (
262
+ <FormField
263
+ name="email"
264
+ label="Email Address"
265
+ value={email}
266
+ onChange={setEmail}
267
+ required
268
+ validate={validateEmail}
269
+ >
270
+ <Input inputType="Email" placeholder="Enter email" />
271
+ </FormField>
272
+ );
273
+ }
274
+ ```
275
+
276
+ ### Form Integration (NEW API)
199
277
  ```tsx
200
278
  function FormIntegrationExample() {
201
- const handleSubmit = (values, setError) => {
279
+ const handleSubmit = (values: {
280
+ firstName: string;
281
+ lastName: string;
282
+ email: string;
283
+ phone: string;
284
+ message: string;
285
+ }) => {
202
286
  console.log('Form values:', values);
203
287
  };
204
288
 
205
289
  return (
206
- <Form onSubmit={handleSubmit}>
290
+ <Form
291
+ defaultValues={{ firstName: '', lastName: '', email: '', phone: '', message: '' }}
292
+ onSubmit={handleSubmit}
293
+ >
207
294
  <FormField name="firstName" label="First Name" required>
208
295
  <Input />
209
296
  </FormField>
210
-
297
+
211
298
  <FormField name="lastName" label="Last Name" required>
212
299
  <Input />
213
300
  </FormField>
214
-
301
+
215
302
  <FormField name="email" label="Email" required>
216
303
  <Input inputType="Email" />
217
304
  </FormField>
218
-
305
+
219
306
  <FormField name="phone" label="Phone Number">
220
307
  <Input inputType="Tel" />
221
308
  </FormField>
222
-
309
+
223
310
  <FormField name="message" label="Message">
224
311
  <TextArea rows={4} />
225
312
  </FormField>
226
-
313
+
227
314
  <Button actionType="submit">Submit</Button>
228
315
  </Form>
229
316
  );
230
317
  }
231
318
  ```
232
319
 
320
+ ---
321
+
322
+ ## Additional Resources
323
+
324
+ - [Form Documentation](../../organisms/Form.md)
325
+ - [Migration Guide](../../../FORM_MIGRATION_GUIDE.md)
326
+ - [React Hook Form Documentation](https://react-hook-form.com/)
327
+
233
328
  ### Conditional Fields
234
329
  ```tsx
235
330
  function ConditionalFieldsExample() {