ynotsoft-dynamic-form 1.0.20 → 1.0.22

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 CHANGED
@@ -1,26 +1,40 @@
1
-
2
1
  # DynamicForm Component - Complete Field Reference
3
2
 
3
+ ## Install
4
+
5
+ ```
6
+ npm install ynotsoft-dynamic-form
7
+
8
+ # install peer dependencies
9
+ npm install react-hot-toast dayjs react-select react-day-picker dompurify @radix-ui/react-label @radix-ui/react-popover @radix-ui/react-radio-group @radix-ui/react-select @radix-ui/react-separator @heroicons/react
10
+
11
+ ```
12
+
13
+ ### TODO:
14
+
15
+ - remove radixui as dependency, maybe replace with ShadCN and maintain it ourselves
16
+
4
17
  ## Overview
18
+
5
19
  The DynamicForm component provides a flexible, declarative way to build forms with various field types, validation, conditional logic, and styling options.
6
20
 
7
21
  ## Basic Usage
8
22
 
9
23
  ```javascript
10
- import DynamicForm from './lib/DynamicForm/DynamicForm';
24
+ import DynamicForm from "./lib/DynamicForm/DynamicForm";
11
25
 
12
26
  const formDefinition = {
13
27
  fields: [
14
28
  // Field definitions here
15
- ]
29
+ ],
16
30
  };
17
31
 
18
32
  <DynamicForm
19
33
  formDefinition={formDefinition}
20
- defaultValues={{ name: 'John Doe' }}
34
+ defaultValues={{ name: "John Doe" }}
21
35
  sendFormValues={(values) => console.log(values)}
22
- onFieldsChange={(values) => console.log('Changed:', values)}
23
- />
36
+ onFieldsChange={(values) => console.log("Changed:", values)}
37
+ />;
24
38
  ```
25
39
 
26
40
  ---
@@ -28,6 +42,7 @@ const formDefinition = {
28
42
  ## Field Types
29
43
 
30
44
  ### 1. Header Field
45
+
31
46
  Used for section titles and form organization.
32
47
 
33
48
  ```javascript
@@ -41,6 +56,7 @@ Used for section titles and form organization.
41
56
  ```
42
57
 
43
58
  ### 2. Input Field
59
+
44
60
  Standard text input with shadcn/ui styling.
45
61
 
46
62
  ```javascript
@@ -61,6 +77,7 @@ Standard text input with shadcn/ui styling.
61
77
  ```
62
78
 
63
79
  ### 3. Email Field
80
+
64
81
  Email input with validation and shadcn/ui styling.
65
82
 
66
83
  ```javascript
@@ -75,6 +92,7 @@ Email input with validation and shadcn/ui styling.
75
92
  ```
76
93
 
77
94
  ### 4. TextArea Field
95
+
78
96
  Multi-line text input.
79
97
 
80
98
  ```javascript
@@ -92,6 +110,7 @@ Multi-line text input.
92
110
  ```
93
111
 
94
112
  ### 5. Select Field
113
+
95
114
  Dropdown selection with single choice.
96
115
 
97
116
  ```javascript
@@ -114,6 +133,7 @@ Dropdown selection with single choice.
114
133
  ```
115
134
 
116
135
  ### 6. MultiSelect Field
136
+
117
137
  Multiple selection dropdown.
118
138
 
119
139
  ```javascript
@@ -137,6 +157,7 @@ Multiple selection dropdown.
137
157
  ```
138
158
 
139
159
  ### 7. Checkbox Field
160
+
140
161
  Single checkbox with flexible layouts and card styling.
141
162
 
142
163
  ```javascript
@@ -147,10 +168,10 @@ Single checkbox with flexible layouts and card styling.
147
168
  required: true,
148
169
  value: false,
149
170
  description: 'By checking this, you agree to our terms and conditions',
150
-
171
+
151
172
  // Layout options
152
173
  layout: 'inline', // 'inline' | 'stacked' | 'default'
153
-
174
+
154
175
  // Card container styling
155
176
  containerStyle: 'card', // Wraps in bordered card
156
177
  color: 'blue', // 'green' | 'blue' | 'red' | 'yellow' | 'purple' | 'indigo' | 'gray' | 'pink' | 'orange'
@@ -158,11 +179,13 @@ Single checkbox with flexible layouts and card styling.
158
179
  ```
159
180
 
160
181
  **Checkbox Layouts:**
182
+
161
183
  - `default`: Standard checkbox with label above
162
184
  - `inline`: Checkbox and label side-by-side
163
185
  - `stacked`: Checkbox, label, and description stacked vertically
164
186
 
165
187
  ### 8. Radio Group Field
188
+
166
189
  Single selection from multiple options using Radix UI.
167
190
 
168
191
  ```javascript
@@ -177,13 +200,13 @@ Single selection from multiple options using Radix UI.
177
200
  { value: 'paypal', label: 'PayPal' },
178
201
  { value: 'bank', label: 'Bank Transfer' }
179
202
  ],
180
-
203
+
181
204
  // Layout options
182
205
  inline: true, // Display options horizontally
183
-
206
+
184
207
  // Color variants
185
208
  color: 'blue', // 'green' | 'blue' | 'red' | 'yellow' | 'purple' | 'indigo' | 'gray' | 'pink' | 'orange'
186
-
209
+
187
210
  // Card container styling
188
211
  containerStyle: 'card',
189
212
  color: 'green'
@@ -191,6 +214,7 @@ Single selection from multiple options using Radix UI.
191
214
  ```
192
215
 
193
216
  ### 9. Date Picker Field
217
+
194
218
  Single date selection with shadcn/ui calendar.
195
219
 
196
220
  ```javascript
@@ -205,12 +229,14 @@ Single date selection with shadcn/ui calendar.
205
229
  ```
206
230
 
207
231
  **Features:**
232
+
208
233
  - Year/month dropdown selectors
209
234
  - Clear and Done buttons
210
235
  - Blue highlight for selected date
211
236
  - Popover interface
212
237
 
213
238
  ### 10. Date Range Picker Field
239
+
214
240
  Select date ranges (from/to).
215
241
 
216
242
  ```javascript
@@ -228,6 +254,7 @@ Select date ranges (from/to).
228
254
  ```
229
255
 
230
256
  ### 11. Time Field
257
+
231
258
  Time picker with AM/PM selection.
232
259
 
233
260
  ```javascript
@@ -242,12 +269,14 @@ Time picker with AM/PM selection.
242
269
  ```
243
270
 
244
271
  **Features:**
272
+
245
273
  - Hour/minute spinners
246
274
  - AM/PM toggle buttons
247
275
  - Clear and Done buttons
248
276
  - Format: "HH:MM AM/PM"
249
277
 
250
278
  ### 12. Date Time Picker Field
279
+
251
280
  Combined date and time selection.
252
281
 
253
282
  ```javascript
@@ -261,6 +290,7 @@ Combined date and time selection.
261
290
  ```
262
291
 
263
292
  ### 13. File Upload Field
293
+
264
294
  Single or multiple file uploads.
265
295
 
266
296
  ```javascript
@@ -276,6 +306,7 @@ Single or multiple file uploads.
276
306
  ```
277
307
 
278
308
  ### 14. Hidden Field
309
+
279
310
  Store hidden values in the form.
280
311
 
281
312
  ```javascript
@@ -287,6 +318,7 @@ Store hidden values in the form.
287
318
  ```
288
319
 
289
320
  ### 15. HTML/Literal Field
321
+
290
322
  Display rich HTML content (non-editable).
291
323
 
292
324
  ```javascript
@@ -297,6 +329,7 @@ Display rich HTML content (non-editable).
297
329
  ```
298
330
 
299
331
  ### 16. Alert Message Field
332
+
300
333
  Display contextual alert messages with icons (info, success, warning, error).
301
334
 
302
335
  ```javascript
@@ -329,17 +362,19 @@ Display contextual alert messages with icons (info, success, warning, error).
329
362
  ```
330
363
 
331
364
  **Features:**
365
+
332
366
  - Color-coded backgrounds (blue, green, yellow, red)
333
367
  - Icon indicators for each variant
334
368
  - Clean, accessible design
335
369
  - No user interaction required (display only)
336
370
 
337
371
  ### 17. Line Break Field
372
+
338
373
  Add visual spacing between sections.
339
374
 
340
375
  ```javascript
341
376
  {
342
- type: 'linebreak'
377
+ type: "linebreak";
343
378
  }
344
379
  ```
345
380
 
@@ -354,11 +389,11 @@ Apply consistent styling to all fields (except header, html, linebreak, hidden,
354
389
  name: 'email',
355
390
  label: 'Email',
356
391
  type: 'email',
357
-
392
+
358
393
  // Card container
359
394
  containerStyle: 'card',
360
395
  color: 'blue', // Card border/accent color
361
-
396
+
362
397
  // Layout for checkbox/radio
363
398
  layout: 'inline', // or 'stacked' | 'default'
364
399
  inline: true, // For radio groups
@@ -370,6 +405,7 @@ Apply consistent styling to all fields (except header, html, linebreak, hidden,
370
405
  ## Advanced Features
371
406
 
372
407
  ### Conditional Display
408
+
373
409
  Show/hide fields based on other values:
374
410
 
375
411
  ```javascript
@@ -383,6 +419,7 @@ Show/hide fields based on other values:
383
419
  ```
384
420
 
385
421
  ### Conditional Disable
422
+
386
423
  Disable fields based on conditions:
387
424
 
388
425
  ```javascript
@@ -395,6 +432,7 @@ Disable fields based on conditions:
395
432
  ```
396
433
 
397
434
  ### Custom Validation
435
+
398
436
  Field-level validation functions:
399
437
 
400
438
  ```javascript
@@ -412,6 +450,7 @@ Field-level validation functions:
412
450
  ```
413
451
 
414
452
  ### Dynamic Options
453
+
415
454
  Load options from API:
416
455
 
417
456
  ```javascript
@@ -433,142 +472,143 @@ const formDefinition = {
433
472
  fields: [
434
473
  // Section Header
435
474
  {
436
- type: 'header',
437
- label: 'Personal Information',
438
- size: 'xl',
439
- underline: true
475
+ type: "header",
476
+ label: "Personal Information",
477
+ size: "xl",
478
+ underline: true,
440
479
  },
441
-
480
+
442
481
  // Alert Message
443
482
  {
444
- type: 'alert',
445
- variant: 'info',
446
- message: 'Please provide accurate information. All fields marked with * are required.'
483
+ type: "alert",
484
+ variant: "info",
485
+ message:
486
+ "Please provide accurate information. All fields marked with * are required.",
447
487
  },
448
-
488
+
449
489
  // Input Field
450
490
  {
451
- name: 'fullName',
452
- label: 'Full Name',
453
- type: 'input',
491
+ name: "fullName",
492
+ label: "Full Name",
493
+ type: "input",
454
494
  required: true,
455
- placeholder: 'John Doe',
456
- containerStyle: 'card',
457
- color: 'blue'
495
+ placeholder: "John Doe",
496
+ containerStyle: "card",
497
+ color: "blue",
458
498
  },
459
-
499
+
460
500
  // Email Field
461
501
  {
462
- name: 'email',
463
- label: 'Email',
464
- type: 'email',
502
+ name: "email",
503
+ label: "Email",
504
+ type: "email",
465
505
  required: true,
466
- placeholder: 'you@example.com'
506
+ placeholder: "you@example.com",
467
507
  },
468
-
508
+
469
509
  // Date Picker
470
510
  {
471
- name: 'birthDate',
472
- label: 'Birth Date',
473
- type: 'date',
511
+ name: "birthDate",
512
+ label: "Birth Date",
513
+ type: "date",
474
514
  required: true,
475
- placeholder: 'Select your birth date'
515
+ placeholder: "Select your birth date",
476
516
  },
477
-
517
+
478
518
  // Time Picker
479
519
  {
480
- name: 'preferredTime',
481
- label: 'Preferred Contact Time',
482
- type: 'time',
483
- placeholder: 'Select time'
520
+ name: "preferredTime",
521
+ label: "Preferred Contact Time",
522
+ type: "time",
523
+ placeholder: "Select time",
484
524
  },
485
-
525
+
486
526
  // Section Header
487
527
  {
488
- type: 'header',
489
- label: 'Preferences',
490
- size: 'lg',
491
- underline: true
528
+ type: "header",
529
+ label: "Preferences",
530
+ size: "lg",
531
+ underline: true,
492
532
  },
493
-
533
+
494
534
  // Radio Group
495
535
  {
496
- name: 'contactMethod',
497
- label: 'Preferred Contact Method',
498
- type: 'radiogroup',
536
+ name: "contactMethod",
537
+ label: "Preferred Contact Method",
538
+ type: "radiogroup",
499
539
  required: true,
500
- value: 'email',
540
+ value: "email",
501
541
  inline: true,
502
- color: 'green',
542
+ color: "green",
503
543
  options: [
504
- { value: 'email', label: 'Email' },
505
- { value: 'phone', label: 'Phone' },
506
- { value: 'sms', label: 'SMS' }
507
- ]
544
+ { value: "email", label: "Email" },
545
+ { value: "phone", label: "Phone" },
546
+ { value: "sms", label: "SMS" },
547
+ ],
508
548
  },
509
-
549
+
510
550
  // MultiSelect
511
551
  {
512
- name: 'interests',
513
- label: 'Areas of Interest',
514
- type: 'multiselect',
552
+ name: "interests",
553
+ label: "Areas of Interest",
554
+ type: "multiselect",
515
555
  value: [],
516
556
  options: [
517
- { value: 'sports', label: 'Sports' },
518
- { value: 'tech', label: 'Technology' },
519
- { value: 'travel', label: 'Travel' },
520
- { value: 'food', label: 'Food & Dining' }
521
- ]
557
+ { value: "sports", label: "Sports" },
558
+ { value: "tech", label: "Technology" },
559
+ { value: "travel", label: "Travel" },
560
+ { value: "food", label: "Food & Dining" },
561
+ ],
522
562
  },
523
-
563
+
524
564
  // Checkbox
525
565
  {
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'
566
+ name: "newsletter",
567
+ label: "Subscribe to newsletter",
568
+ type: "checkbox",
569
+ layout: "inline",
570
+ description: "Get weekly updates and special offers",
571
+ containerStyle: "card",
572
+ color: "purple",
533
573
  },
534
-
574
+
535
575
  // TextArea
536
576
  {
537
- name: 'comments',
538
- label: 'Additional Comments',
539
- type: 'textarea',
577
+ name: "comments",
578
+ label: "Additional Comments",
579
+ type: "textarea",
540
580
  rows: 4,
541
581
  maxLength: 500,
542
582
  showCharCount: true,
543
- placeholder: 'Any additional information...'
583
+ placeholder: "Any additional information...",
544
584
  },
545
-
585
+
546
586
  // File Upload
547
587
  {
548
- name: 'documents',
549
- label: 'Upload Documents',
550
- type: 'file',
551
- accept: '.pdf,.doc,.docx',
552
- maxSize: 5 * 1024 * 1024
553
- }
554
- ]
588
+ name: "documents",
589
+ label: "Upload Documents",
590
+ type: "file",
591
+ accept: ".pdf,.doc,.docx",
592
+ maxSize: 5 * 1024 * 1024,
593
+ },
594
+ ],
555
595
  };
556
596
 
557
597
  // Usage
558
598
  <DynamicForm
559
599
  formDefinition={formDefinition}
560
600
  defaultValues={{
561
- fullName: 'John Doe',
562
- email: 'john@example.com',
563
- contactMethod: 'email'
601
+ fullName: "John Doe",
602
+ email: "john@example.com",
603
+ contactMethod: "email",
564
604
  }}
565
605
  sendFormValues={(values) => {
566
- console.log('Form submitted:', values);
606
+ console.log("Form submitted:", values);
567
607
  }}
568
608
  onFieldsChange={(values) => {
569
- console.log('Form changed:', values);
609
+ console.log("Form changed:", values);
570
610
  }}
571
- />
611
+ />;
572
612
  ```
573
613
 
574
614
  ---
@@ -576,7 +616,9 @@ const formDefinition = {
576
616
  ## Styling Reference
577
617
 
578
618
  ### Card Container Colors
619
+
579
620
  Available for `containerStyle='card'`:
621
+
580
622
  - `green` - Green border and accent
581
623
  - `blue` - Blue border and accent
582
624
  - `red` - Red border and accent
@@ -588,6 +630,7 @@ Available for `containerStyle='card'`:
588
630
  - `orange` - Orange border and accent
589
631
 
590
632
  ### Header Sizes
633
+
591
634
  - `sm` - Small header
592
635
  - `md` - Medium header
593
636
  - `lg` - Large header
@@ -597,6 +640,7 @@ Available for `containerStyle='card'`:
597
640
  - `4xl` - 4X large
598
641
 
599
642
  ### Layout Options (Checkbox/Radio)
643
+
600
644
  - `default` - Standard vertical layout
601
645
  - `inline` - Horizontal with label beside control
602
646
  - `stacked` - Vertical with description below
@@ -606,6 +650,7 @@ Available for `containerStyle='card'`:
606
650
  ## Props
607
651
 
608
652
  ### DynamicForm Props
653
+
609
654
  - `formDefinition` - Object containing field definitions
610
655
  - `defaultValues` - Initial form values
611
656
  - `sendFormValues` - Callback when form is submitted
@@ -615,6 +660,7 @@ Available for `containerStyle='card'`:
615
660
  ---
616
661
 
617
662
  ## Notes
663
+
618
664
  - All fields support `required`, `disabled`, `showIf` properties
619
665
  - Fields are automatically validated on blur and submit
620
666
  - Error messages display below invalid fields