@delightui/components 0.1.162-alpha.5 → 0.1.163

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 +3 -7
  33. package/dist/cjs/components/organisms/Form/useForm.d.ts +40 -43
  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 +3 -7
  68. package/dist/esm/components/organisms/Form/useForm.d.ts +40 -43
  69. package/dist/esm/library.js +3 -3
  70. package/dist/esm/library.js.map +1 -1
  71. package/dist/index.d.ts +228 -319
  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,58 +1,36 @@
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
-
5
3
  ## Description
6
4
 
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.
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.
8
6
 
9
7
  ## Aliases
10
8
 
11
9
  - FormField
10
+ - FieldWrapper
11
+ - InputWrapper
12
+ - FormGroup
12
13
  - Field
13
14
 
14
- ## Props Breakdown (Inside Form)
15
+ ## Props Breakdown
16
+
17
+ **Extends:** `HTMLAttributes<HTMLDivElement>`
15
18
 
16
19
  | Prop | Type | Default | Required | Description |
17
20
  |------|------|---------|----------|-------------|
18
- | `name` | `string` (type-safe) | - | Yes | Name of the form field (type-checked against form values) |
21
+ | `name` | `string` | - | Yes | Name of the form field |
19
22
  | `label` | `string` | - | No | Label for the form field |
20
23
  | `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 |
21
27
  | `required` | `boolean` | `false` | No | Whether the form field is required |
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 |
28
+ | `validate` | `FieldValidationFunction` | - | No | Validation function for the form field |
26
29
  | `disabled` | `boolean` | `false` | No | Whether the form field is disabled |
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 |
30
+ | `invalid` | `boolean` | `false` | No | Whether the form field is invalid |
30
31
  | `id` | `string` | - | No | ID for the form field |
31
32
 
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
33
+ Plus all standard HTML div attributes (className, style, onClick, etc.).
56
34
 
57
35
  ## Examples
58
36
 
@@ -186,26 +164,28 @@ function InputTypesExample() {
186
164
  }
187
165
  ```
188
166
 
189
- ### Custom Validation (NEW API)
167
+ ### Custom Validation
190
168
  ```tsx
191
169
  function CustomValidationExample() {
192
- const validateAge = (value: string) => {
170
+ const validateAge = (setError, value) => {
193
171
  if (!value) {
194
- return 'Age is required';
172
+ setError('Age is required');
173
+ return false;
195
174
  }
196
-
175
+
197
176
  const age = parseInt(value);
198
177
  if (isNaN(age) || age < 18 || age > 120) {
199
- return 'Age must be between 18 and 120';
178
+ setError('Age must be between 18 and 120');
179
+ return false;
200
180
  }
201
-
202
- return undefined; // Valid
181
+
182
+ return true;
203
183
  };
204
184
 
205
185
  return (
206
- <FormField
207
- name="age"
208
- label="Age"
186
+ <FormField
187
+ name="age"
188
+ label="Age"
209
189
  required
210
190
  validate={validateAge}
211
191
  >
@@ -215,116 +195,41 @@ function CustomValidationExample() {
215
195
  }
216
196
  ```
217
197
 
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)
198
+ ### Form Integration
277
199
  ```tsx
278
200
  function FormIntegrationExample() {
279
- const handleSubmit = (values: {
280
- firstName: string;
281
- lastName: string;
282
- email: string;
283
- phone: string;
284
- message: string;
285
- }) => {
201
+ const handleSubmit = (values, setError) => {
286
202
  console.log('Form values:', values);
287
203
  };
288
204
 
289
205
  return (
290
- <Form
291
- defaultValues={{ firstName: '', lastName: '', email: '', phone: '', message: '' }}
292
- onSubmit={handleSubmit}
293
- >
206
+ <Form onSubmit={handleSubmit}>
294
207
  <FormField name="firstName" label="First Name" required>
295
208
  <Input />
296
209
  </FormField>
297
-
210
+
298
211
  <FormField name="lastName" label="Last Name" required>
299
212
  <Input />
300
213
  </FormField>
301
-
214
+
302
215
  <FormField name="email" label="Email" required>
303
216
  <Input inputType="Email" />
304
217
  </FormField>
305
-
218
+
306
219
  <FormField name="phone" label="Phone Number">
307
220
  <Input inputType="Tel" />
308
221
  </FormField>
309
-
222
+
310
223
  <FormField name="message" label="Message">
311
224
  <TextArea rows={4} />
312
225
  </FormField>
313
-
226
+
314
227
  <Button actionType="submit">Submit</Button>
315
228
  </Form>
316
229
  );
317
230
  }
318
231
  ```
319
232
 
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
-
328
233
  ### Conditional Fields
329
234
  ```tsx
330
235
  function ConditionalFieldsExample() {