@reactfast/forms 0.1.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.
package/index.d.ts ADDED
@@ -0,0 +1,780 @@
1
+ import { SignatureInputProps } from "@/formFields/Signature";
2
+ import { TimeInputProps } from "@/formFields/Time";
3
+ import { CSSProperties } from "react";
4
+
5
+ type CSSColor = CSSProperties["color"];
6
+ type CSSBorderColor = CSSProperties["borderColor"];
7
+ type CSSBackgroundColor = CSSProperties["backgroundColor"];
8
+
9
+ /**
10
+ * NOTE: Might use `React.ChangeEventHandler` as alias so this is here for now. -Josh
11
+ */
12
+ type OnChangeCallback = () => void;
13
+
14
+ declare module NovaForms {
15
+ // #region - Types
16
+
17
+ type FormFieldCondition =
18
+ | "true"
19
+ | "false"
20
+ | "empty"
21
+ | "not empty"
22
+ | "null"
23
+ | "not null"
24
+ | "less than"
25
+ | "greater than"
26
+ | "equal"
27
+ | "not equal"
28
+ | "between"
29
+ | "matches";
30
+
31
+ // #endregion
32
+
33
+ // #region - Enums
34
+
35
+ type SocialMediaOptions =
36
+ | "Facebook"
37
+ | "Instagram"
38
+ | "Twitter"
39
+ | "LinkedIn"
40
+ | "YouTube"
41
+ | "TikTok"
42
+ | "GitHub";
43
+
44
+ type SocialMediaDictionary = { [id: SocialMediaOptions]: string };
45
+
46
+ // #endregion
47
+
48
+ // #region - Structs
49
+
50
+ interface NovaFormsTheme {
51
+ error: CSSColor;
52
+ inputFocusBorder: CSSBorderColor;
53
+ inputBorder: CSSBorderColor;
54
+ label: CSSColor;
55
+ description: CSSColor;
56
+ requiredAsterisk: CSSColor;
57
+ inputText: CSSColor;
58
+ inputBackground: CSSBackgroundColor;
59
+ }
60
+
61
+ interface FormField {
62
+ name: string;
63
+ title: string;
64
+ type: string;
65
+ width: number;
66
+ }
67
+
68
+ interface FormRule {
69
+ name: string;
70
+ effects: any[];
71
+ }
72
+
73
+ interface FormRuleEffect {
74
+ /**
75
+ * Default: `value`
76
+ */
77
+ prop?: string;
78
+
79
+ /**
80
+ * TODO: Resolve type.
81
+ */
82
+ targetField: any;
83
+
84
+ /**
85
+ * Default: `number`
86
+ */
87
+ kind: string;
88
+
89
+ /**
90
+ * ? Not sure if value is always passed as string but is transformed.
91
+ */
92
+ value: string | number;
93
+
94
+ /**
95
+ * Default: `false`
96
+ */
97
+ strictString: boolean;
98
+
99
+ /**
100
+ * TODO: Resolve type.
101
+ */
102
+ sourceFields: any[];
103
+ }
104
+
105
+ // #endregion
106
+ // #region - Global
107
+
108
+ /**
109
+ * Generic onChange handler for dynamic forms Applies modifiers automatically.
110
+ *
111
+ * @param setState React setState function
112
+ * @param fields array of field definitions (JSON schema)
113
+ */
114
+ function createFormHandler(
115
+ setState: function,
116
+ fields: FormField[],
117
+ rules
118
+ ): (eOrValue: any, fieldName: string) => void;
119
+
120
+ /**
121
+ * Checks if the modifier should apply.
122
+ *
123
+ * @param triggerValue
124
+ * @param when The condition type.
125
+ * @param value value to compare (or array for "between", regex for "matches")
126
+ */
127
+ function evaluateCondition(
128
+ triggerValue: any,
129
+ when: FormFieldCondition,
130
+ value: Array | RegExp | string | number
131
+ ): boolean;
132
+
133
+ // #endregion
134
+
135
+ // #region - React
136
+
137
+ function AutoComplete(): JSX.Element;
138
+
139
+ // MARK: SocialMediaLinks
140
+
141
+ interface SocialMediaLinksProps {
142
+ value?: SocialMediaDictionary;
143
+ onChange?: OnChangeCallback;
144
+ }
145
+
146
+ function SocialMediaLinks(props: SocialMediaLinksProps): JSX.Element;
147
+
148
+ // MARK: CaptchaField
149
+
150
+ interface CaptchaFieldObject {
151
+ name: string;
152
+ title: string;
153
+ required: boolean;
154
+ }
155
+
156
+ interface CaptchaFieldProps {
157
+ onChange?: OnChangeCallback;
158
+ field: CaptchaFieldObject;
159
+ theme: NovaFormsTheme;
160
+ value: any;
161
+ }
162
+
163
+ function CaptchaField(props: CaptchaFieldProps): JSX.Element;
164
+
165
+ // MARK: DateTime
166
+
167
+ interface DateTimeField {
168
+ name: string;
169
+ error?: string;
170
+ title?: string;
171
+ helper?: string;
172
+ description?: string;
173
+ required?: boolean;
174
+ optional?: boolean;
175
+ }
176
+
177
+ interface DateTimeProps {
178
+ field: DateTimeField;
179
+ theme: NovaFormsTheme;
180
+ value: string;
181
+ onChange?: OnChangeCallback;
182
+ }
183
+
184
+ // MARK: DynamicSubForm
185
+
186
+ interface DynamicSubFormField {
187
+ name: string;
188
+ type: string;
189
+ title: string;
190
+ }
191
+
192
+ interface DynamicSubFormProps {
193
+ fields: DynamicSubFormField[];
194
+ onSave?: (values: any[]) => void;
195
+
196
+ /**
197
+ * Default: `Item`
198
+ */
199
+ title?: string;
200
+
201
+ value?: any[];
202
+ }
203
+
204
+ function DynamicSubForm(props: DynamicSubFormProps): JSX.Element;
205
+
206
+ // MARK: EmailInput
207
+
208
+ interface EmailInputField {
209
+ name: string;
210
+ title?: string;
211
+
212
+ /**
213
+ * Default: `you@example.com`
214
+ */
215
+ placeholder?: string;
216
+
217
+ description?: string;
218
+ required?: boolean;
219
+ helper?: string;
220
+ leadingIcon?: JSX.Element;
221
+ trailingIcon?: JSX.Element;
222
+ }
223
+
224
+ interface EmailInputProps {
225
+ field: EmailInputField;
226
+ value: string;
227
+ theme: NovaFormsTheme;
228
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
229
+ required?: boolean;
230
+ helper?: string;
231
+ description?: string;
232
+ placeholder?: string;
233
+ }
234
+
235
+ function EmailInput(props: EmailInputProps): JSX.Element;
236
+
237
+ // MARK: FormHeader
238
+
239
+ type FormHeaderSize = "sm" | "md" | "lg";
240
+
241
+ interface FormHeaderField {
242
+ title: string;
243
+
244
+ /**
245
+ * Default: `md`
246
+ */
247
+ size?: FormHeaderSize;
248
+
249
+ /**
250
+ * Default: `false`
251
+ */
252
+ dividerAbove?: boolean;
253
+
254
+ /**
255
+ * Default: `false`
256
+ */
257
+ dividerBelow?: boolean;
258
+ }
259
+
260
+ interface FormHeaderProps {
261
+ field: FormHeaderField;
262
+ }
263
+
264
+ function FormHeader(props: FormHeaderProps): JSX.Element;
265
+
266
+ // MARK: InputCheckbox
267
+
268
+ interface InputCheckboxField {
269
+ name: string;
270
+ label?: string;
271
+ optional?: boolean;
272
+ description?: string;
273
+ error?: string;
274
+ }
275
+
276
+ interface InputCheckboxProps {
277
+ field: InputCheckboxField;
278
+ value: any;
279
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
280
+ }
281
+
282
+ function InputCheckbox(props: InputCheckboxProps): JSX.Element;
283
+
284
+ // MARK: InputColor
285
+
286
+ interface InputColorField {
287
+ name: string;
288
+ title?: string;
289
+ description?: string;
290
+ optional?: boolean;
291
+ error?: string;
292
+ }
293
+
294
+ interface InputColorProps {
295
+ field: InputColorField;
296
+ value: any;
297
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
298
+ }
299
+
300
+ function InputColor(props: InputColorProps): JSX.Element;
301
+
302
+ // MARK: InputDate
303
+
304
+ interface InputDateField {
305
+ name: string;
306
+ title?: string;
307
+ description?: string;
308
+ optional?: boolean;
309
+ required?: boolean;
310
+ error?: string;
311
+ }
312
+
313
+ interface InputDateProps {
314
+ field: InputDateField;
315
+ value: any;
316
+ theme: NovaFormsTheme;
317
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
318
+ }
319
+
320
+ function InputDate(props: InputDateProps): JSX.Element;
321
+
322
+ // MARK: InputDefault
323
+
324
+ interface InputDefaultField {
325
+ name: string;
326
+ title?: string;
327
+
328
+ /**
329
+ * Default: `text`
330
+ */
331
+ type?: string;
332
+
333
+ /**
334
+ * Default: `Enter text`
335
+ */
336
+ placeholder?: string;
337
+
338
+ description?: string;
339
+ required?: boolean;
340
+ error?: string;
341
+ helper?: string;
342
+ leadingIcon?: JSX.Element;
343
+ trailingIcon?: JSX.Element;
344
+ }
345
+
346
+ interface InputDefaultProps {
347
+ field: InputDefaultField;
348
+ value: any;
349
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
350
+ theme: NovaFormsTheme;
351
+ }
352
+
353
+ function InputDefault(props: InputDefaultProps): JSX.Element;
354
+
355
+ // MARK: InputNumber
356
+
357
+ interface InputNumberField {
358
+ name: string;
359
+ label?: string;
360
+
361
+ /**
362
+ * Default: `Enter a number`
363
+ */
364
+ placeholder?: string;
365
+
366
+ description?: string;
367
+ optional?: boolean;
368
+ error?: string;
369
+
370
+ // TODO: Are strings okay here? The technical input is `string | number`. -Josh
371
+ min: number;
372
+ max: number;
373
+ step: number;
374
+ }
375
+
376
+ interface InputNumberProps {
377
+ field: InputNumberField;
378
+ value: any;
379
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
380
+ }
381
+
382
+ function InputNumber(props: InputNumberProps): JSX.Element;
383
+
384
+ // MARK: InputTextArea
385
+
386
+ interface InputTextAreaField {
387
+ name: string;
388
+ title?: string;
389
+
390
+ /**
391
+ * Default: `4`
392
+ */
393
+ rows: number;
394
+
395
+ /**
396
+ * Default: `Enter text`
397
+ */
398
+ placeholder?: string;
399
+
400
+ description?: string;
401
+ optional?: boolean;
402
+ error?: string;
403
+ }
404
+
405
+ interface InputTextAreaProps {
406
+ field: InputTextAreaField;
407
+ value: any;
408
+ theme: NovaFormsTheme;
409
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
410
+ }
411
+
412
+ function InputTextArea(props: InputTextAreaProps): JSX.Element;
413
+
414
+ // MARK: InputToggle
415
+
416
+ interface InputToggleField {
417
+ name: string;
418
+ title?: string;
419
+ description?: string;
420
+ error?: string;
421
+ }
422
+
423
+ interface InputToggleProps {
424
+ field: InputToggleField;
425
+ value: any;
426
+ onChange: React.ChangeEventHandler<HTMLInputElement>;
427
+ }
428
+
429
+ function InputToggle(props: InputToggleProps): JSX.Element;
430
+
431
+ // MARK: MediaSelectorModal
432
+
433
+ interface MediaSelectorModalProps {
434
+ onSelect: (url: string) => void;
435
+
436
+ value: any;
437
+
438
+ /**
439
+ * Default: `Select Media`
440
+ */
441
+ label?: string;
442
+ }
443
+
444
+ function MediaSelectorModal(props: MediaSelectorModalProps): JSX.Element;
445
+
446
+ // MARK: MultiSelect
447
+
448
+ // TODO: Verify & Validate optional and required field(s). -Josh
449
+ interface MultiSelectOption {
450
+ label: string;
451
+
452
+ /**
453
+ * For the dynamic `optionLabel` passed via `MultiSelectField` prop.
454
+ */
455
+ [optionLabel: string]: string;
456
+ }
457
+
458
+ type MultiSelectOptions = MultiSelectOption[];
459
+
460
+ interface MultiSelectField {
461
+ name: string;
462
+ title?: string;
463
+
464
+ /**
465
+ * Default: `"Select options"`
466
+ */
467
+ placeholder?: string;
468
+
469
+ /**
470
+ * Default: `[]`
471
+ */
472
+ options?: MultiSelectOptions;
473
+
474
+ /**
475
+ * Default: `id`
476
+ */
477
+ optionId?: string;
478
+
479
+ /**
480
+ * Default: `name`
481
+ */
482
+ optionLabel?: string;
483
+
484
+ error?: string;
485
+ }
486
+
487
+ interface MultiSelectProps {
488
+ field: MultiSelectField;
489
+ theme: NovaFormsTheme;
490
+ onChange: (labels: any[]) => void;
491
+
492
+ /**
493
+ * Default: `[]`
494
+ */
495
+ value?: any[];
496
+ }
497
+
498
+ function MultiSelect(props: MultiSelectProps): JSX.Element;
499
+
500
+ // MARK: Phone
501
+
502
+ interface PhoneField {
503
+ name: string;
504
+ title?: string;
505
+
506
+ /**
507
+ * Default: `(123) 456-7890`
508
+ */
509
+ placeholder?: string;
510
+
511
+ description?: string;
512
+ required?: boolean;
513
+ helper?: string;
514
+ leadingIcon?: JSX.Element;
515
+ trailingIcon?: JSX.Element;
516
+ }
517
+
518
+ interface PhoneProps {
519
+ field: PhoneField;
520
+ value: number | string;
521
+ onChange: (arg: { name: string; value: string }) => void;
522
+ theme: NovaFormsTheme;
523
+ }
524
+
525
+ function Phone(props: PhoneProps): JSX.Element;
526
+
527
+ // #MARK: RadioGroup
528
+
529
+ interface RadioGroupOption {
530
+ label: string;
531
+ value: React.Key;
532
+ }
533
+
534
+ interface RadioGroupField {
535
+ name: string;
536
+ title?: string;
537
+ description?: string;
538
+ required?: boolean;
539
+ error?: string;
540
+ helper?: string;
541
+
542
+ /**
543
+ * Default: `[]`
544
+ */
545
+ options?: any[];
546
+ }
547
+
548
+ interface RadioGroupProps {
549
+ field: RadioGroupField;
550
+ value: any;
551
+ onChange: (value: string) => void;
552
+ theme: NovaFormsTheme;
553
+ }
554
+
555
+ function RadioGroup(props: RadioGroupProps): JSX.Element;
556
+
557
+ // MARK: RatingInput
558
+
559
+ interface RatingInputField {
560
+ name: string;
561
+ title?: string;
562
+ description?: string;
563
+ required?: boolean;
564
+ helper?: string;
565
+
566
+ /**
567
+ * Default: `5`
568
+ */
569
+ max?: number;
570
+
571
+ /**
572
+ * An icon from:
573
+ * ```js
574
+ * import ReturnIcon from "../utils/returnHeroIcon.jsx";
575
+ * ```
576
+ *
577
+ * Default: `StarIcon`
578
+ */
579
+ icon?: string;
580
+ }
581
+
582
+ interface RatingInputProps {
583
+ field: RatingInputField;
584
+ value: any;
585
+ onChange: (arg: { target: { name: string; value: number } }) => void;
586
+ theme: NovaFormsTheme;
587
+ }
588
+
589
+ function RatingInput(props: RatingInputProps): JSX.Element;
590
+
591
+ // MARK: ScaleInput
592
+
593
+ interface ScaleInputField {
594
+ name: string;
595
+ title?: string;
596
+ description?: string;
597
+ required?: boolean;
598
+ helper?: string;
599
+
600
+ /**
601
+ * Default: `1`
602
+ */
603
+ min?: number;
604
+
605
+ /**
606
+ * Default: `10`
607
+ */
608
+ max?: number;
609
+
610
+ /**
611
+ * Default: `1`
612
+ */
613
+ step?: number;
614
+ }
615
+
616
+ interface ScaleInputProps {
617
+ field: ScaleInputField;
618
+ value: any;
619
+ onChange: (arg: { name: string; value: number }) => void;
620
+ }
621
+
622
+ function ScaleInput(props: ScaleInputProps): JSX.Element;
623
+
624
+ // MARK: SignatureInput
625
+
626
+ interface SignatureInputField {
627
+ name: string;
628
+ title?: string;
629
+ description?: string;
630
+ required?: boolean;
631
+ helper?: string;
632
+ }
633
+
634
+ interface SignatureInputProps {
635
+ field: SignatureInputField;
636
+ value: any;
637
+ onChange: (arg: { name: string; value: string }) => void;
638
+ theme: NovaFormsTheme;
639
+ }
640
+
641
+ function SignatureInput(props: SignatureInputProps): JSX.Element;
642
+
643
+ // MARK: SingleSelect
644
+
645
+ // TODO: Verify & Validate optional and required field(s). -Josh
646
+ interface SingleSelectOption {
647
+ name: string;
648
+ value: any;
649
+ label: string;
650
+
651
+ /**
652
+ * For the dynamic `optionLabel` passed via `SingleSelectField` prop.
653
+ */
654
+ [optionLabel: string]: string;
655
+ }
656
+
657
+ interface SingleSelectField {
658
+ name: string;
659
+ title?: string;
660
+ helper?: string;
661
+ description?: string;
662
+
663
+ /**
664
+ * Default: `Select an option`
665
+ */
666
+ placeholder?: string;
667
+
668
+ required?: boolean;
669
+ error?: string;
670
+
671
+ /**
672
+ * Default: `[]`
673
+ */
674
+ options?: (SingleSelectOption | string)[];
675
+
676
+ /**
677
+ * Default: `id`
678
+ */
679
+ optionId?: string;
680
+
681
+ /**
682
+ * Default: `name`
683
+ */
684
+ optionLabel?: string;
685
+ }
686
+
687
+ interface SingleSelectProps {
688
+ field: SingleSelectField;
689
+ value: any;
690
+
691
+ /**
692
+ * TODO: Not sure if the type is broad or constrained to strings or casted strings. -Josh
693
+ */
694
+ onChange: (value: any) => void;
695
+
696
+ theme: NovaFormsTheme;
697
+ }
698
+
699
+ function SingleSelect(props: SingleSelectProps): JSX.Element;
700
+
701
+ // MARK: TimeInput
702
+
703
+ interface TimeInputField {
704
+ name: string;
705
+ title?: string;
706
+
707
+ /**
708
+ * Default: `HH:MM`
709
+ */
710
+ placeholder?: string;
711
+
712
+ description?: string;
713
+ required?: boolean;
714
+ error?: string;
715
+ helper?: string;
716
+ leadingIcon?: JSX.Element;
717
+ trailingIcon?: JSX.Element;
718
+ min?: string | number;
719
+ max?: string | number;
720
+ step?: string | number;
721
+ }
722
+
723
+ interface TimeInputProps {
724
+ field: TimeInputField;
725
+ value: any;
726
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
727
+ theme: NovaFormsTheme;
728
+ }
729
+
730
+ function TimeINput(props: TimeInputProps): JSX.Element;
731
+
732
+ // MARK: ImageUploadBase64
733
+
734
+ interface ImageUploadBase64Props {
735
+ value: Base64URLString;
736
+ onChange?: (base64String: Base64URLString) => void;
737
+
738
+ /**
739
+ * TODO: Maybe use `png` to simplify API without needing the `.`, unless this is a pattern selector format. -Josh
740
+ * Default: `['.png', '.jpg', '.jpeg', '.gif']
741
+ */
742
+ accept?: string[];
743
+
744
+ /**
745
+ * Default: `10 * 1024 * 1024` (10 MB)
746
+ */
747
+ maxSize?: number;
748
+ }
749
+
750
+ function ImageUploadBase64(props: ImageUploadBase64Props): JSX.Element;
751
+
752
+ // MARK: UrlInput
753
+
754
+ interface UrlInputField {
755
+ name: string;
756
+ title?: string;
757
+
758
+ /**
759
+ * Default: `https://example.com`
760
+ */
761
+ placeholder?: string;
762
+
763
+ description?: string;
764
+ required?: boolean;
765
+ helper?: string;
766
+ leadingIcon?: JSX.Element;
767
+ trailingIcon?: JSX.Element;
768
+ }
769
+
770
+ interface UrlInputProps {
771
+ field: UrlInputField;
772
+ value: any;
773
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
774
+ theme: NovaFormsTheme;
775
+ }
776
+
777
+ function UrlInput(props: UrlInputProps): JSX.Element;
778
+
779
+ // #endregion
780
+ }