ynotsoft-dynamic-form 1.0.12 → 1.0.13
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/README.md +615 -9
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,622 @@
|
|
|
1
|
-
# React + Vite
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# DynamicForm Component - Complete Field Reference
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
## Overview
|
|
5
|
+
The DynamicForm component provides a flexible, declarative way to build forms with various field types, validation, conditional logic, and styling options.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
7
|
+
## Basic Usage
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
```javascript
|
|
10
|
+
import DynamicForm from './lib/DynamicForm/DynamicForm';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const formDefinition = {
|
|
13
|
+
fields: [
|
|
14
|
+
// Field definitions here
|
|
15
|
+
]
|
|
16
|
+
};
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
<DynamicForm
|
|
19
|
+
formDefinition={formDefinition}
|
|
20
|
+
defaultValues={{ name: 'John Doe' }}
|
|
21
|
+
sendFormValues={(values) => console.log(values)}
|
|
22
|
+
onFieldsChange={(values) => console.log('Changed:', values)}
|
|
23
|
+
/>
|
|
24
|
+
```
|
|
15
25
|
|
|
16
|
-
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Field Types
|
|
29
|
+
|
|
30
|
+
### 1. Header Field
|
|
31
|
+
Used for section titles and form organization.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
{
|
|
35
|
+
type: 'header',
|
|
36
|
+
label: 'Personal Information',
|
|
37
|
+
size: 'xl', // 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl'
|
|
38
|
+
align: 'left', // 'left' | 'center' | 'right'
|
|
39
|
+
underline: true // Boolean - adds bottom border
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Input Field
|
|
44
|
+
Standard text input with shadcn/ui styling.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
{
|
|
48
|
+
name: 'fullName',
|
|
49
|
+
label: 'Full Name',
|
|
50
|
+
type: 'input',
|
|
51
|
+
required: true,
|
|
52
|
+
placeholder: 'Enter your name',
|
|
53
|
+
value: 'John Doe',
|
|
54
|
+
disabled: false,
|
|
55
|
+
maxLength: 100,
|
|
56
|
+
validate: (value) => {
|
|
57
|
+
if (value.length < 2) return 'Name must be at least 2 characters';
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. Email Field
|
|
64
|
+
Email input with validation and shadcn/ui styling.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
{
|
|
68
|
+
name: 'email',
|
|
69
|
+
label: 'Email Address',
|
|
70
|
+
type: 'email',
|
|
71
|
+
required: true,
|
|
72
|
+
placeholder: 'you@example.com',
|
|
73
|
+
value: 'john@example.com'
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 4. TextArea Field
|
|
78
|
+
Multi-line text input.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
{
|
|
82
|
+
name: 'description',
|
|
83
|
+
label: 'Description',
|
|
84
|
+
type: 'textarea',
|
|
85
|
+
required: false,
|
|
86
|
+
placeholder: 'Enter description...',
|
|
87
|
+
rows: 4,
|
|
88
|
+
maxLength: 500,
|
|
89
|
+
showCharCount: true,
|
|
90
|
+
value: 'Initial description'
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 5. Select Field
|
|
95
|
+
Dropdown selection with single choice.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
{
|
|
99
|
+
name: 'country',
|
|
100
|
+
label: 'Country',
|
|
101
|
+
type: 'select',
|
|
102
|
+
required: true,
|
|
103
|
+
value: 'us',
|
|
104
|
+
options: [
|
|
105
|
+
{ value: '', label: 'Select a country' },
|
|
106
|
+
{ value: 'us', label: 'United States' },
|
|
107
|
+
{ value: 'uk', label: 'United Kingdom' },
|
|
108
|
+
{ value: 'ca', label: 'Canada' }
|
|
109
|
+
],
|
|
110
|
+
// Dynamic options from API
|
|
111
|
+
optionsUrl: '/api/countries',
|
|
112
|
+
dependsOn: 'region' // Reload when 'region' changes
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 6. MultiSelect Field
|
|
117
|
+
Multiple selection dropdown.
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
{
|
|
121
|
+
name: 'interests',
|
|
122
|
+
label: 'Interests',
|
|
123
|
+
type: 'multiselect',
|
|
124
|
+
required: true,
|
|
125
|
+
value: ['sports', 'tech'],
|
|
126
|
+
options: [
|
|
127
|
+
{ value: 'sports', label: 'Sports' },
|
|
128
|
+
{ value: 'music', label: 'Music' },
|
|
129
|
+
{ value: 'tech', label: 'Technology' },
|
|
130
|
+
{ value: 'travel', label: 'Travel' }
|
|
131
|
+
],
|
|
132
|
+
validate: (value) => {
|
|
133
|
+
if (value && value.length > 3) return 'Select up to 3 interests';
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 7. Checkbox Field
|
|
140
|
+
Single checkbox with flexible layouts and card styling.
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
{
|
|
144
|
+
name: 'agreeTerms',
|
|
145
|
+
label: 'I agree to terms',
|
|
146
|
+
type: 'checkbox',
|
|
147
|
+
required: true,
|
|
148
|
+
value: false,
|
|
149
|
+
description: 'By checking this, you agree to our terms and conditions',
|
|
150
|
+
|
|
151
|
+
// Layout options
|
|
152
|
+
layout: 'inline', // 'inline' | 'stacked' | 'default'
|
|
153
|
+
|
|
154
|
+
// Card container styling
|
|
155
|
+
containerStyle: 'card', // Wraps in bordered card
|
|
156
|
+
color: 'blue', // 'green' | 'blue' | 'red' | 'yellow' | 'purple' | 'indigo' | 'gray' | 'pink' | 'orange'
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Checkbox Layouts:**
|
|
161
|
+
- `default`: Standard checkbox with label above
|
|
162
|
+
- `inline`: Checkbox and label side-by-side
|
|
163
|
+
- `stacked`: Checkbox, label, and description stacked vertically
|
|
164
|
+
|
|
165
|
+
### 8. Radio Group Field
|
|
166
|
+
Single selection from multiple options using Radix UI.
|
|
167
|
+
|
|
168
|
+
```javascript
|
|
169
|
+
{
|
|
170
|
+
name: 'paymentMethod',
|
|
171
|
+
label: 'Payment Method',
|
|
172
|
+
type: 'radiogroup',
|
|
173
|
+
required: true,
|
|
174
|
+
value: 'card',
|
|
175
|
+
options: [
|
|
176
|
+
{ value: 'card', label: 'Credit Card' },
|
|
177
|
+
{ value: 'paypal', label: 'PayPal' },
|
|
178
|
+
{ value: 'bank', label: 'Bank Transfer' }
|
|
179
|
+
],
|
|
180
|
+
|
|
181
|
+
// Layout options
|
|
182
|
+
inline: true, // Display options horizontally
|
|
183
|
+
|
|
184
|
+
// Color variants
|
|
185
|
+
color: 'blue', // 'green' | 'blue' | 'red' | 'yellow' | 'purple' | 'indigo' | 'gray' | 'pink' | 'orange'
|
|
186
|
+
|
|
187
|
+
// Card container styling
|
|
188
|
+
containerStyle: 'card',
|
|
189
|
+
color: 'green'
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 9. Date Picker Field
|
|
194
|
+
Single date selection with shadcn/ui calendar.
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
{
|
|
198
|
+
name: 'birthDate',
|
|
199
|
+
label: 'Birth Date',
|
|
200
|
+
type: 'date',
|
|
201
|
+
required: true,
|
|
202
|
+
placeholder: 'Select date',
|
|
203
|
+
value: new Date('1990-01-01')
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Features:**
|
|
208
|
+
- Year/month dropdown selectors
|
|
209
|
+
- Clear and Done buttons
|
|
210
|
+
- Blue highlight for selected date
|
|
211
|
+
- Popover interface
|
|
212
|
+
|
|
213
|
+
### 10. Date Range Picker Field
|
|
214
|
+
Select date ranges (from/to).
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
{
|
|
218
|
+
name: 'projectDates',
|
|
219
|
+
label: 'Project Timeline',
|
|
220
|
+
type: 'dateRange',
|
|
221
|
+
required: true,
|
|
222
|
+
placeholder: 'Select date range',
|
|
223
|
+
value: {
|
|
224
|
+
from: new Date('2025-01-01'),
|
|
225
|
+
to: new Date('2025-12-31')
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 11. Time Field
|
|
231
|
+
Time picker with AM/PM selection.
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
{
|
|
235
|
+
name: 'appointmentTime',
|
|
236
|
+
label: 'Appointment Time',
|
|
237
|
+
type: 'time',
|
|
238
|
+
required: true,
|
|
239
|
+
placeholder: 'Select time',
|
|
240
|
+
value: '03:45 PM'
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Features:**
|
|
245
|
+
- Hour/minute spinners
|
|
246
|
+
- AM/PM toggle buttons
|
|
247
|
+
- Clear and Done buttons
|
|
248
|
+
- Format: "HH:MM AM/PM"
|
|
249
|
+
|
|
250
|
+
### 12. Date Time Picker Field
|
|
251
|
+
Combined date and time selection.
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
{
|
|
255
|
+
name: 'meetingDateTime',
|
|
256
|
+
label: 'Meeting Date & Time',
|
|
257
|
+
type: 'dayTimePicker',
|
|
258
|
+
required: true,
|
|
259
|
+
value: new Date('2025-10-17T15:30:00')
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### 13. File Upload Field
|
|
264
|
+
Single or multiple file uploads.
|
|
265
|
+
|
|
266
|
+
```javascript
|
|
267
|
+
{
|
|
268
|
+
name: 'documents',
|
|
269
|
+
label: 'Upload Documents',
|
|
270
|
+
type: 'file', // or 'multifile' for multiple
|
|
271
|
+
required: true,
|
|
272
|
+
accept: '.pdf,.doc,.docx,.jpg,.jpeg,.png',
|
|
273
|
+
maxSize: 5 * 1024 * 1024, // 5 MB
|
|
274
|
+
multiple: false
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### 14. Hidden Field
|
|
279
|
+
Store hidden values in the form.
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
{
|
|
283
|
+
name: 'userId',
|
|
284
|
+
type: 'hidden',
|
|
285
|
+
value: '12345'
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### 15. HTML/Literal Field
|
|
290
|
+
Display rich HTML content (non-editable).
|
|
291
|
+
|
|
292
|
+
```javascript
|
|
293
|
+
{
|
|
294
|
+
type: 'litertext',
|
|
295
|
+
content: '<div class="alert">Important notice here</div>'
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### 16. Alert Message Field
|
|
300
|
+
Display contextual alert messages with icons (info, success, warning, error).
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
{
|
|
304
|
+
type: 'alert',
|
|
305
|
+
variant: 'info', // 'info' | 'success' | 'warning' | 'error' | 'danger'
|
|
306
|
+
message: 'This is an informational message'
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Success alert
|
|
310
|
+
{
|
|
311
|
+
type: 'alert',
|
|
312
|
+
variant: 'success',
|
|
313
|
+
message: 'Your form was submitted successfully!'
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Warning alert
|
|
317
|
+
{
|
|
318
|
+
type: 'alert',
|
|
319
|
+
variant: 'warning',
|
|
320
|
+
message: 'Please review your information before submitting'
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Error alert
|
|
324
|
+
{
|
|
325
|
+
type: 'alert',
|
|
326
|
+
variant: 'error',
|
|
327
|
+
message: 'There was an error processing your request'
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**Features:**
|
|
332
|
+
- Color-coded backgrounds (blue, green, yellow, red)
|
|
333
|
+
- Icon indicators for each variant
|
|
334
|
+
- Clean, accessible design
|
|
335
|
+
- No user interaction required (display only)
|
|
336
|
+
|
|
337
|
+
### 17. Line Break Field
|
|
338
|
+
Add visual spacing between sections.
|
|
339
|
+
|
|
340
|
+
```javascript
|
|
341
|
+
{
|
|
342
|
+
type: 'linebreak'
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## Global Field Format Options
|
|
349
|
+
|
|
350
|
+
Apply consistent styling to all fields (except header, html, linebreak, hidden, alert):
|
|
351
|
+
|
|
352
|
+
```javascript
|
|
353
|
+
{
|
|
354
|
+
name: 'email',
|
|
355
|
+
label: 'Email',
|
|
356
|
+
type: 'email',
|
|
357
|
+
|
|
358
|
+
// Card container
|
|
359
|
+
containerStyle: 'card',
|
|
360
|
+
color: 'blue', // Card border/accent color
|
|
361
|
+
|
|
362
|
+
// Layout for checkbox/radio
|
|
363
|
+
layout: 'inline', // or 'stacked' | 'default'
|
|
364
|
+
inline: true, // For radio groups
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Advanced Features
|
|
371
|
+
|
|
372
|
+
### Conditional Display
|
|
373
|
+
Show/hide fields based on other values:
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
{
|
|
377
|
+
name: 'state',
|
|
378
|
+
label: 'State',
|
|
379
|
+
type: 'select',
|
|
380
|
+
showIf: (values) => values.country === 'us',
|
|
381
|
+
options: [...]
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Conditional Disable
|
|
386
|
+
Disable fields based on conditions:
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
{
|
|
390
|
+
name: 'billingAddress',
|
|
391
|
+
label: 'Billing Address',
|
|
392
|
+
type: 'input',
|
|
393
|
+
disabled: (values) => values.sameAsShipping === true
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Custom Validation
|
|
398
|
+
Field-level validation functions:
|
|
399
|
+
|
|
400
|
+
```javascript
|
|
401
|
+
{
|
|
402
|
+
name: 'password',
|
|
403
|
+
label: 'Password',
|
|
404
|
+
type: 'input',
|
|
405
|
+
validate: (value) => {
|
|
406
|
+
if (value.length < 8) return 'Password must be at least 8 characters';
|
|
407
|
+
if (!/[A-Z]/.test(value)) return 'Must contain uppercase letter';
|
|
408
|
+
if (!/[0-9]/.test(value)) return 'Must contain a number';
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Dynamic Options
|
|
415
|
+
Load options from API:
|
|
416
|
+
|
|
417
|
+
```javascript
|
|
418
|
+
{
|
|
419
|
+
name: 'city',
|
|
420
|
+
label: 'City',
|
|
421
|
+
type: 'select',
|
|
422
|
+
optionsUrl: '/api/cities',
|
|
423
|
+
dependsOn: 'state', // Reload when state changes
|
|
424
|
+
}
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## Complete Example
|
|
430
|
+
|
|
431
|
+
```javascript
|
|
432
|
+
const formDefinition = {
|
|
433
|
+
fields: [
|
|
434
|
+
// Section Header
|
|
435
|
+
{
|
|
436
|
+
type: 'header',
|
|
437
|
+
label: 'Personal Information',
|
|
438
|
+
size: 'xl',
|
|
439
|
+
underline: true
|
|
440
|
+
},
|
|
441
|
+
|
|
442
|
+
// Alert Message
|
|
443
|
+
{
|
|
444
|
+
type: 'alert',
|
|
445
|
+
variant: 'info',
|
|
446
|
+
message: 'Please provide accurate information. All fields marked with * are required.'
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
// Input Field
|
|
450
|
+
{
|
|
451
|
+
name: 'fullName',
|
|
452
|
+
label: 'Full Name',
|
|
453
|
+
type: 'input',
|
|
454
|
+
required: true,
|
|
455
|
+
placeholder: 'John Doe',
|
|
456
|
+
containerStyle: 'card',
|
|
457
|
+
color: 'blue'
|
|
458
|
+
},
|
|
459
|
+
|
|
460
|
+
// Email Field
|
|
461
|
+
{
|
|
462
|
+
name: 'email',
|
|
463
|
+
label: 'Email',
|
|
464
|
+
type: 'email',
|
|
465
|
+
required: true,
|
|
466
|
+
placeholder: 'you@example.com'
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
// Date Picker
|
|
470
|
+
{
|
|
471
|
+
name: 'birthDate',
|
|
472
|
+
label: 'Birth Date',
|
|
473
|
+
type: 'date',
|
|
474
|
+
required: true,
|
|
475
|
+
placeholder: 'Select your birth date'
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
// Time Picker
|
|
479
|
+
{
|
|
480
|
+
name: 'preferredTime',
|
|
481
|
+
label: 'Preferred Contact Time',
|
|
482
|
+
type: 'time',
|
|
483
|
+
placeholder: 'Select time'
|
|
484
|
+
},
|
|
485
|
+
|
|
486
|
+
// Section Header
|
|
487
|
+
{
|
|
488
|
+
type: 'header',
|
|
489
|
+
label: 'Preferences',
|
|
490
|
+
size: 'lg',
|
|
491
|
+
underline: true
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
// Radio Group
|
|
495
|
+
{
|
|
496
|
+
name: 'contactMethod',
|
|
497
|
+
label: 'Preferred Contact Method',
|
|
498
|
+
type: 'radiogroup',
|
|
499
|
+
required: true,
|
|
500
|
+
value: 'email',
|
|
501
|
+
inline: true,
|
|
502
|
+
color: 'green',
|
|
503
|
+
options: [
|
|
504
|
+
{ value: 'email', label: 'Email' },
|
|
505
|
+
{ value: 'phone', label: 'Phone' },
|
|
506
|
+
{ value: 'sms', label: 'SMS' }
|
|
507
|
+
]
|
|
508
|
+
},
|
|
509
|
+
|
|
510
|
+
// MultiSelect
|
|
511
|
+
{
|
|
512
|
+
name: 'interests',
|
|
513
|
+
label: 'Areas of Interest',
|
|
514
|
+
type: 'multiselect',
|
|
515
|
+
value: [],
|
|
516
|
+
options: [
|
|
517
|
+
{ value: 'sports', label: 'Sports' },
|
|
518
|
+
{ value: 'tech', label: 'Technology' },
|
|
519
|
+
{ value: 'travel', label: 'Travel' },
|
|
520
|
+
{ value: 'food', label: 'Food & Dining' }
|
|
521
|
+
]
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
// Checkbox
|
|
525
|
+
{
|
|
526
|
+
name: 'newsletter',
|
|
527
|
+
label: 'Subscribe to newsletter',
|
|
528
|
+
type: 'checkbox',
|
|
529
|
+
layout: 'inline',
|
|
530
|
+
description: 'Get weekly updates and special offers',
|
|
531
|
+
containerStyle: 'card',
|
|
532
|
+
color: 'purple'
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
// TextArea
|
|
536
|
+
{
|
|
537
|
+
name: 'comments',
|
|
538
|
+
label: 'Additional Comments',
|
|
539
|
+
type: 'textarea',
|
|
540
|
+
rows: 4,
|
|
541
|
+
maxLength: 500,
|
|
542
|
+
showCharCount: true,
|
|
543
|
+
placeholder: 'Any additional information...'
|
|
544
|
+
},
|
|
545
|
+
|
|
546
|
+
// File Upload
|
|
547
|
+
{
|
|
548
|
+
name: 'documents',
|
|
549
|
+
label: 'Upload Documents',
|
|
550
|
+
type: 'file',
|
|
551
|
+
accept: '.pdf,.doc,.docx',
|
|
552
|
+
maxSize: 5 * 1024 * 1024
|
|
553
|
+
}
|
|
554
|
+
]
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// Usage
|
|
558
|
+
<DynamicForm
|
|
559
|
+
formDefinition={formDefinition}
|
|
560
|
+
defaultValues={{
|
|
561
|
+
fullName: 'John Doe',
|
|
562
|
+
email: 'john@example.com',
|
|
563
|
+
contactMethod: 'email'
|
|
564
|
+
}}
|
|
565
|
+
sendFormValues={(values) => {
|
|
566
|
+
console.log('Form submitted:', values);
|
|
567
|
+
}}
|
|
568
|
+
onFieldsChange={(values) => {
|
|
569
|
+
console.log('Form changed:', values);
|
|
570
|
+
}}
|
|
571
|
+
/>
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
## Styling Reference
|
|
577
|
+
|
|
578
|
+
### Card Container Colors
|
|
579
|
+
Available for `containerStyle='card'`:
|
|
580
|
+
- `green` - Green border and accent
|
|
581
|
+
- `blue` - Blue border and accent
|
|
582
|
+
- `red` - Red border and accent
|
|
583
|
+
- `yellow` - Yellow border and accent
|
|
584
|
+
- `purple` - Purple border and accent
|
|
585
|
+
- `indigo` - Indigo border and accent
|
|
586
|
+
- `gray` - Gray border and accent
|
|
587
|
+
- `pink` - Pink border and accent
|
|
588
|
+
- `orange` - Orange border and accent
|
|
589
|
+
|
|
590
|
+
### Header Sizes
|
|
591
|
+
- `sm` - Small header
|
|
592
|
+
- `md` - Medium header
|
|
593
|
+
- `lg` - Large header
|
|
594
|
+
- `xl` - Extra large (default)
|
|
595
|
+
- `2xl` - 2X large
|
|
596
|
+
- `3xl` - 3X large
|
|
597
|
+
- `4xl` - 4X large
|
|
598
|
+
|
|
599
|
+
### Layout Options (Checkbox/Radio)
|
|
600
|
+
- `default` - Standard vertical layout
|
|
601
|
+
- `inline` - Horizontal with label beside control
|
|
602
|
+
- `stacked` - Vertical with description below
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
## Props
|
|
607
|
+
|
|
608
|
+
### DynamicForm Props
|
|
609
|
+
- `formDefinition` - Object containing field definitions
|
|
610
|
+
- `defaultValues` - Initial form values
|
|
611
|
+
- `sendFormValues` - Callback when form is submitted
|
|
612
|
+
- `onFieldsChange` - Callback when any field changes
|
|
613
|
+
- `children` - Additional content (e.g., submit button)
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## Notes
|
|
618
|
+
- All fields support `required`, `disabled`, `showIf` properties
|
|
619
|
+
- Fields are automatically validated on blur and submit
|
|
620
|
+
- Error messages display below invalid fields
|
|
621
|
+
- Form values are managed internally with React state
|
|
622
|
+
- shadcn/ui components used for consistent styling
|