@delightui/components 0.1.162-alpha.5 → 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.
- package/dist/cjs/components/atoms/Checkbox/Checkbox.d.ts +1 -1
- package/dist/cjs/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
- package/dist/cjs/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
- package/dist/cjs/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
- package/dist/cjs/components/atoms/Input/Input.d.ts +1 -1
- package/dist/cjs/components/atoms/Input/Input.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/Password/Password.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/RadioButton/RadioButton.d.ts +1 -1
- package/dist/cjs/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
- package/dist/cjs/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/TextArea/TextArea.d.ts +1 -1
- package/dist/cjs/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
- package/dist/cjs/components/atoms/Toggle/Toggle.d.ts +1 -1
- package/dist/cjs/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
- package/dist/cjs/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
- package/dist/cjs/components/molecules/FormField/FormField.d.ts +2 -28
- package/dist/cjs/components/molecules/FormField/FormField.presenter.d.ts +8 -17
- package/dist/cjs/components/molecules/FormField/FormField.types.d.ts +52 -115
- package/dist/cjs/components/molecules/FormField/FormField.utils.d.ts +11 -8
- package/dist/cjs/components/molecules/FormField/index.d.ts +2 -1
- package/dist/cjs/components/molecules/Search/Search.d.ts +1 -1
- package/dist/cjs/components/molecules/Search/Search.presenter.d.ts +2 -2
- package/dist/cjs/components/molecules/Select/Select.presenter.d.ts +4 -4
- package/dist/cjs/components/organisms/Form/DropzoneFormExample.d.ts +6 -0
- package/dist/cjs/components/organisms/Form/Form.d.ts +1 -22
- package/dist/cjs/components/organisms/Form/Form.types.d.ts +93 -64
- package/dist/cjs/components/organisms/Form/Form.utils.d.ts +2 -0
- package/dist/cjs/components/organisms/Form/FormContext.d.ts +5 -0
- package/dist/cjs/components/organisms/Form/UpdatedFormExample.d.ts +23 -0
- package/dist/cjs/components/organisms/Form/{examples/UseFormExample.d.ts → UseFormExample.d.ts} +3 -0
- package/dist/cjs/components/organisms/Form/index.d.ts +3 -7
- package/dist/cjs/components/organisms/Form/useForm.d.ts +40 -43
- package/dist/cjs/library.js +3 -3
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/atoms/Checkbox/Checkbox.d.ts +1 -1
- package/dist/esm/components/atoms/Checkbox/Checkbox.presenter.d.ts +1 -1
- package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.d.ts +1 -1
- package/dist/esm/components/atoms/CheckboxItem/CheckboxItem.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/CustomToggle/CustomToggle.d.ts +1 -1
- package/dist/esm/components/atoms/Input/Input.d.ts +1 -1
- package/dist/esm/components/atoms/Input/Input.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/Password/Password.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/RadioButton/RadioButton.d.ts +1 -1
- package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.d.ts +1 -1
- package/dist/esm/components/atoms/RadioButtonItem/RadioButtonItem.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/TextArea/TextArea.d.ts +1 -1
- package/dist/esm/components/atoms/TextArea/TextArea.presenter.d.ts +1 -1
- package/dist/esm/components/atoms/Toggle/Toggle.d.ts +1 -1
- package/dist/esm/components/atoms/Toggle/Toggle.presenter.d.ts +2 -2
- package/dist/esm/components/atoms/ToggleButton/ToggleButton.d.ts +1 -1
- package/dist/esm/components/molecules/FormField/FormField.d.ts +2 -28
- package/dist/esm/components/molecules/FormField/FormField.presenter.d.ts +8 -17
- package/dist/esm/components/molecules/FormField/FormField.types.d.ts +52 -115
- package/dist/esm/components/molecules/FormField/FormField.utils.d.ts +11 -8
- package/dist/esm/components/molecules/FormField/index.d.ts +2 -1
- package/dist/esm/components/molecules/Search/Search.d.ts +1 -1
- package/dist/esm/components/molecules/Search/Search.presenter.d.ts +2 -2
- package/dist/esm/components/molecules/Select/Select.presenter.d.ts +4 -4
- package/dist/esm/components/organisms/Form/DropzoneFormExample.d.ts +6 -0
- package/dist/esm/components/organisms/Form/Form.d.ts +1 -22
- package/dist/esm/components/organisms/Form/Form.types.d.ts +93 -64
- package/dist/esm/components/organisms/Form/Form.utils.d.ts +2 -0
- package/dist/esm/components/organisms/Form/FormContext.d.ts +5 -0
- package/dist/esm/components/organisms/Form/UpdatedFormExample.d.ts +23 -0
- package/dist/esm/components/organisms/Form/{examples/UseFormExample.d.ts → UseFormExample.d.ts} +3 -0
- package/dist/esm/components/organisms/Form/index.d.ts +3 -7
- package/dist/esm/components/organisms/Form/useForm.d.ts +40 -43
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +228 -319
- package/docs/components/molecules/FormField.md +34 -129
- package/docs/components/organisms/Form.md +162 -858
- package/package.json +1 -4
- package/dist/cjs/components/molecules/FormField/useSafeController.d.ts +0 -14
- package/dist/cjs/components/molecules/FormField/useSafeFormContext.d.ts +0 -8
- package/dist/cjs/components/organisms/Form/Form.presenter.d.ts +0 -290
- package/dist/cjs/components/organisms/Form/examples/DropzoneFormExample.d.ts +0 -6
- package/dist/cjs/components/organisms/Form/examples/UpdatedFormExample.d.ts +0 -2
- package/dist/cjs/components/organisms/Form/useAutosave.d.ts +0 -10
- package/dist/esm/components/molecules/FormField/useSafeController.d.ts +0 -14
- package/dist/esm/components/molecules/FormField/useSafeFormContext.d.ts +0 -8
- package/dist/esm/components/organisms/Form/Form.presenter.d.ts +0 -290
- package/dist/esm/components/organisms/Form/examples/DropzoneFormExample.d.ts +0 -6
- package/dist/esm/components/organisms/Form/examples/UpdatedFormExample.d.ts +0 -2
- package/dist/esm/components/organisms/Form/useAutosave.d.ts +0 -10
- package/docs/FORM_MIGRATION_GUIDE.md +0 -631
- /package/dist/cjs/components/organisms/Form/{examples/AutosaveFormExample.d.ts → AutosaveFormExample.d.ts} +0 -0
- /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.
|
|
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
|
|
15
|
+
## Props Breakdown
|
|
16
|
+
|
|
17
|
+
**Extends:** `HTMLAttributes<HTMLDivElement>`
|
|
15
18
|
|
|
16
19
|
| Prop | Type | Default | Required | Description |
|
|
17
20
|
|------|------|---------|----------|-------------|
|
|
18
|
-
| `name` | `string`
|
|
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` | `
|
|
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 |
|
|
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
|
-
|
|
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
|
|
167
|
+
### Custom Validation
|
|
190
168
|
```tsx
|
|
191
169
|
function CustomValidationExample() {
|
|
192
|
-
const validateAge = (value
|
|
170
|
+
const validateAge = (setError, value) => {
|
|
193
171
|
if (!value) {
|
|
194
|
-
|
|
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
|
-
|
|
178
|
+
setError('Age must be between 18 and 120');
|
|
179
|
+
return false;
|
|
200
180
|
}
|
|
201
|
-
|
|
202
|
-
return
|
|
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
|
-
###
|
|
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() {
|