-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
1275 lines (1239 loc) · 67.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'raf/polyfill';
import 'babel-polyfill';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import Markdown from 'react-markdown';
import prefixAll from 'inline-style-prefix-all';
import Prism from 'prismjs';
import 'prismjs/themes/prism-tomorrow.css';
import CSS from '../src/css/example.css';
import { Textbox, Textarea, Radiobox, Checkbox, Select } from '../src/js/Inputs/index.ts';
const markdownTextboxEmptyExample = `
\`\`\`javascript
import { Textbox } from 'react-inputs-validation';
<Textbox
attributesInput={{ // Optional.
id: 'Name',
name: 'Name',
type: 'text',
placeholder: 'Place your name here ^-^',
}}
value={name} // Optional.[String].Default: "".
onChange={(name, e) => {
this.setState({ name });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={(e) => {console.log(e)}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
name: 'Name', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your {name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
\`\`\`
`;
const markdownTextboxRegexExample = `
\`\`\`javascript
import { Textbox } from 'react-inputs-validation';
<Textbox
attributesInput={{ // Optional.
id: 'Name',
name: 'Name',
type: 'text',
placeholder: 'Place your name here ^-^',
}}
value={nameRg} // Optional.[String].Default: "".
placeholder="Place your name here ^-^" // Optional.[String].Default: "".
onChange={(name, e) => {
this.setState({ nameRg });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={(e) => {console.log(e)}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
reg: /^\d{5}$/, // Optional.[Bool].Default: "" Custom regex.
regMsg: 'failed in reg.test(value)' // Optional.[String].Default: "" Custom regex error message.
}}
/>
\`\`\`
`;
const markdownTextboxNumberExample = `
\`\`\`javascript
import { Textbox } from 'react-inputs-validation';
<Textbox
attributesInput={{ // Optional.
id: 'Number',
name: 'Number',
type: 'text', // Input type [text, password, number]. NOTE: provide "text" for better performance since different browsers run differently with "number".
placeholder: 'Place your number here ^-^',
}}
value={number} // Optional.[String].Default: "".
onChange={(number, e) => {
this.setState({ number });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={() => {}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
type: 'number', // Optional.[String].Default: "string". Validation type, options are ['string', 'number', 'alphanumeric', 'alpha'].
min: 10, // Optional.[Number].Default: 0. Validation of min length when validationOption['type'] is string, min amount when validationOption['type'] is number.
max: 100 // Optional.[Number].Default: 0. Validation of max length when validationOption['type'] is string, max amount when validationOption['type'] is number.
// mantissa: 2, // Optional.[Number].Default: -1. Number precision.
}}
/>
\`\`\`
`;
const markdownRadioboxEmptyExample = `
\`\`\`javascript
import { Radiobox } from 'react-inputs-validation';
<Radiobox
attributesInput={{ // Optional.
id: 'job',
name: 'job',
}}
value={job} // Optional.[String].Default: "".
optionList={[
{ id: 'engineer', name: 'engineer' },
{ id: 'teacher', name: 'teacher' },
{ id: 'student', name: 'student' }
]}
customStyleContainer={{
display: 'flex',
justifyContent: 'flex-start'
}} // Optional.[Object].Default: {}.
customStyleOptionListItem={{ marginRight: '20px' }} // Optional.[Object].Default: {}.
onChange={(job, e) =>{
this.setState({ job });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={(e) => {console.log(e)}} // Optional.[Func].Default: none.
validationOption={{
name: 'job', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
\`\`\`
`;
const markdownCheckboxEmptyExample = `
\`\`\`javascript
import { Checkbox } from 'react-inputs-validation';
<Checkbox
attributesInput={{ // Optional.
id: 'agreement',
name: 'agreement',
}}
value={agreement} // Required.[String].Default: "".
onBlur={() => {}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
checked={isAgreementChecked} // Required.[Bool].Default: false.
onChange={(isAgreementChecked, e) => {
this.setState({ isAgreementChecked });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
labelHtml={
<div style={{ color: '#4a4a4a', marginTop: '2px' }}>
agree?
</div>
} // Required.[Html].Default: none.
validationOption={{
name: 'agreement', // Optional.[String].Default: "". To display in the Error message. i.e Please check the ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
\`\`\`
`;
const markdownSelectEmptyExample = `
\`\`\`javascript
import { Select } from 'react-inputs-validation';
<Select
attributesInput={{ // Optional.
id: 'country',
name: 'country',
}}
value={country} // Optional.[String].Default: "".
optionList={[
{ id: '', name: 'Please Select a country' },
{ id: 'US', name: 'United States' },
{ id: 'CN', name: 'China' },
{ id: 'JP', name: 'Japan' }
]} // Required.[Array of Object(s)].Default: [].
onChange={(res, e) => {
this.setState({ country: res.id });
console.log(e);
}} // Optional.[Func].Default: () => {}. Will return the value.
onBlur={() => {}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
customStyleOptionListContainer={{ maxHeight: '200px', overflow: 'auto', fontSize: '14px' }} // Optional.[Object].Default: {}.
validationOption={{
name: 'country', // Optional.[String].Default: "". To display in the Error message. i.e Please select a ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
\`\`\`
`;
const markdownTextareaEmptyExample = `
\`\`\`javascript
import { Textarea } from 'react-inputs-validation';
<Textarea
attributesInput={{ // Optional.
id: 'description',
name: 'description',
type: 'text',
placeholder: 'Place your description here ^-^',
}}
value={description} // Optional.[String].Default: "".
onChange={(description, e) => {
this.setState({ description });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={(e) => {console.log(e)}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
name: 'Description', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your {name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
\`\`\`
`;
const CodeBlock = ({ literal, language }) => {
var html = Prism.highlight(literal, Prism.languages[language]);
var cls = 'language-' + language;
return (
<pre className={cls}>
<code dangerouslySetInnerHTML={{ __html: html }} className={cls} />
</pre>
);
};
CodeBlock.propTypes = {
literal: PropTypes.string,
language: PropTypes.string,
};
// import { Textbox, Radiobox, Checkbox, Select } from '../index.js';
const JOB_OPTIONS_LIST = [
{ id: 'engineer', name: 'engineer' },
{ id: 'teacher', name: 'teacher' },
{ id: 'student', name: 'student' },
];
const COUNTRY_OPTIONS_LIST = [
{ id: '', name: 'Please Select a country', icon: '' },
{ name: 'Afghanistan', id: 'AF', icon: '' },
{ name: 'Åland Islands', id: 'AX', icon: '' },
{ name: 'Albania', id: 'AL', icon: '' },
{ name: 'Algeria', id: 'DZ', icon: '' },
{ name: 'American Samoa', id: 'AS', icon: '' },
{ name: 'AndorrA', id: 'AD', icon: '' },
{ name: 'Angola', id: 'AO', icon: '' },
{ name: 'Anguilla', id: 'AI', icon: '' },
{ name: 'Antarctica', id: 'AQ', icon: '' },
{ name: 'Antigua and Barbuda', id: 'AG', icon: '' },
{ name: 'Argentina', id: 'AR', icon: '' },
{ name: 'Armenia', id: 'AM', icon: '' },
{ name: 'Aruba', id: 'AW', icon: '' },
{ name: 'Australia', id: 'AU', icon: '' },
{ name: 'Austria', id: 'AT', icon: '' },
{ name: 'Azerbaijan', id: 'AZ', icon: '' },
{ name: 'Bahamas', id: 'BS', icon: '' },
{ name: 'Bahrain', id: 'BH', icon: '' },
{ name: 'Bangladesh', id: 'BD', icon: '' },
{ name: 'Barbados', id: 'BB', icon: '' },
{ name: 'Belarus', id: 'BY', icon: '' },
{ name: 'Belgium', id: 'BE', icon: '' },
{ name: 'Belize', id: 'BZ', icon: '' },
{ name: 'Benin', id: 'BJ', icon: '' },
{ name: 'Bermuda', id: 'BM', icon: '' },
{ name: 'Bhutan', id: 'BT', icon: '' },
{ name: 'Bolivia', id: 'BO', icon: '' },
{ name: 'Bosnia and Herzegovina', id: 'BA', icon: '' },
{ name: 'Botswana', id: 'BW', icon: '' },
{ name: 'Bouvet Island', id: 'BV', icon: '' },
{ name: 'Brazil', id: 'BR', icon: '' },
{ name: 'British Indian Ocean Territory', id: 'IO', icon: '' },
{ name: 'Brunei Darussalam', id: 'BN', icon: '' },
{ name: 'Bulgaria', id: 'BG', icon: '' },
{ name: 'Burkina Faso', id: 'BF', icon: '' },
{ name: 'Burundi', id: 'BI', icon: '' },
{ name: 'Cambodia', id: 'KH', icon: '' },
{ name: 'Cameroon', id: 'CM', icon: '' },
{ name: 'Canada', id: 'CA', icon: '' },
{ name: 'Cape Verde', id: 'CV', icon: '' },
{ name: 'Cayman Islands', id: 'KY', icon: '' },
{ name: 'Central African Republic', id: 'CF', icon: '' },
{ name: 'Chad', id: 'TD', icon: '' },
{ name: 'Chile', id: 'CL', icon: '' },
{ name: 'China', id: 'CN', icon: '' },
{ name: 'Christmas Island', id: 'CX', icon: '' },
{ name: 'Cocos (Keeling) Islands', id: 'CC', icon: '' },
{ name: 'Colombia', id: 'CO', icon: '' },
{ name: 'Comoros', id: 'KM', icon: '' },
{ name: 'Congo', id: 'CG', icon: '' },
{ name: 'Congo, The Democratic Republic of the', id: 'CD', icon: '' },
{ name: 'Cook Islands', id: 'CK', icon: '' },
{ name: 'Costa Rica', id: 'CR', icon: '' },
{ name: 'Croatia', id: 'HR', icon: '' },
{ name: 'Cuba', id: 'CU', icon: '' },
{ name: 'Cyprus', id: 'CY', icon: '' },
{ name: 'Czech Republic', id: 'CZ', icon: '' },
{ name: 'Denmark', id: 'DK', icon: '' },
{ name: 'Djibouti', id: 'DJ', icon: '' },
{ name: 'Dominica', id: 'DM', icon: '' },
{ name: 'Dominican Republic', id: 'DO', icon: '' },
{ name: 'Ecuador', id: 'EC', icon: '' },
{ name: 'Egypt', id: 'EG', icon: '' },
{ name: 'El Salvador', id: 'SV', icon: '' },
{ name: 'Equatorial Guinea', id: 'GQ', icon: '' },
{ name: 'Eritrea', id: 'ER', icon: '' },
{ name: 'Estonia', id: 'EE', icon: '' },
{ name: 'Ethiopia', id: 'ET', icon: '' },
{ name: 'Falkland Islands (Malvinas)', id: 'FK', icon: '' },
{ name: 'Faroe Islands', id: 'FO', icon: '' },
{ name: 'Fiji', id: 'FJ', icon: '' },
{ name: 'Finland', id: 'FI', icon: '' },
{ name: 'France', id: 'FR', icon: '' },
{ name: 'French Guiana', id: 'GF', icon: '' },
{ name: 'French Polynesia', id: 'PF', icon: '' },
{ name: 'French Southern Territories', id: 'TF', icon: '' },
{ name: 'Gabon', id: 'GA', icon: '' },
{ name: 'Gambia', id: 'GM', icon: '' },
{ name: 'Georgia', id: 'GE', icon: '' },
{ name: 'Germany', id: 'DE', icon: '' },
{ name: 'Ghana', id: 'GH', icon: '' },
{ name: 'Gibraltar', id: 'GI', icon: '' },
{ name: 'Greece', id: 'GR', icon: '' },
{ name: 'Greenland', id: 'GL', icon: '' },
{ name: 'Grenada', id: 'GD', icon: '' },
{ name: 'Guadeloupe', id: 'GP', icon: '' },
{ name: 'Guam', id: 'GU', icon: '' },
{ name: 'Guatemala', id: 'GT', icon: '' },
{ name: 'Guernsey', id: 'GG', icon: '' },
{ name: 'Guinea', id: 'GN', icon: '' },
{ name: 'Guinea-Bissau', id: 'GW', icon: '' },
{ name: 'Guyana', id: 'GY', icon: '' },
{ name: 'Haiti', id: 'HT', icon: '' },
{ name: 'Heard Island and Mcdonald Islands', id: 'HM', icon: '' },
{ name: 'Holy See (Vatican City State)', id: 'VA', icon: '' },
{ name: 'Honduras', id: 'HN', icon: '' },
{ name: 'Hong Kong, SAR of China', id: 'HK', icon: '' },
{ name: 'Hungary', id: 'HU', icon: '' },
{ name: 'Iceland', id: 'IS', icon: '' },
{ name: 'India', id: 'IN', icon: '' },
{ name: 'Indonesia', id: 'ID', icon: '' },
{ name: 'Iran, Islamic Republic Of', id: 'IR', icon: '' },
{ name: 'Iraq', id: 'IQ', icon: '' },
{ name: 'Ireland', id: 'IE', icon: '' },
{ name: 'Isle of Man', id: 'IM', icon: '' },
{ name: 'Israel', id: 'IL', icon: '' },
{ name: 'Italy', id: 'IT', icon: '' },
{ name: 'Jamaica', id: 'JM', icon: '' },
{ name: 'Japan', id: 'JP', icon: '' },
{ name: 'Jersey', id: 'JE', icon: '' },
{ name: 'Jordan', id: 'JO', icon: '' },
{ name: 'Kazakhstan', id: 'KZ', icon: '' },
{ name: 'Kenya', id: 'KE', icon: '' },
{ name: 'Kiribati', id: 'KI', icon: '' },
{ name: 'Korea, Republic of', id: 'KR', icon: '' },
{ name: 'Kuwait', id: 'KW', icon: '' },
{ name: 'Kyrgyzstan', id: 'KG', icon: '' },
{ name: 'Latvia', id: 'LV', icon: '' },
{ name: 'Lebanon', id: 'LB', icon: '' },
{ name: 'Lesotho', id: 'LS', icon: '' },
{ name: 'Liberia', id: 'LR', icon: '' },
{ name: 'Libyan Arab Jamahiriya', id: 'LY', icon: '' },
{ name: 'Liechtenstein', id: 'LI', icon: '' },
{ name: 'Lithuania', id: 'LT', icon: '' },
{ name: 'Luxembourg', id: 'LU', icon: '' },
{ name: 'Macao, SAR of China', id: 'MO', icon: '' },
{ name: 'Macedonia, The Former Yugoslav Republic of', id: 'MK', icon: '' },
{ name: 'Madagascar', id: 'MG', icon: '' },
{ name: 'Malawi', id: 'MW', icon: '' },
{ name: 'Malaysia', id: 'MY', icon: '' },
{ name: 'Maldives', id: 'MV', icon: '' },
{ name: 'Mali', id: 'ML', icon: '' },
{ name: 'Malta', id: 'MT', icon: '' },
{ name: 'Marshall Islands', id: 'MH', icon: '' },
{ name: 'Martinique', id: 'MQ', icon: '' },
{ name: 'Mauritania', id: 'MR', icon: '' },
{ name: 'Mauritius', id: 'MU', icon: '' },
{ name: 'Mayotte', id: 'YT', icon: '' },
{ name: 'Mexico', id: 'MX', icon: '' },
{ name: 'Micronesia, Federated States of', id: 'FM', icon: '' },
{ name: 'Moldova, Republic of', id: 'MD', icon: '' },
{ name: 'Monaco', id: 'MC', icon: '' },
{ name: 'Mongolia', id: 'MN', icon: '' },
{ name: 'Montserrat', id: 'MS', icon: '' },
{ name: 'Morocco', id: 'MA', icon: '' },
{ name: 'Mozambique', id: 'MZ', icon: '' },
{ name: 'Myanmar', id: 'MM', icon: '' },
{ name: 'Namibia', id: 'NA', icon: '' },
{ name: 'Nauru', id: 'NR', icon: '' },
{ name: 'Nepal', id: 'NP', icon: '' },
{ name: 'Netherlands', id: 'NL', icon: '' },
{ name: 'Netherlands Antilles', id: 'AN', icon: '' },
{ name: 'New Caledonia', id: 'NC', icon: '' },
{ name: 'New Zealand', id: 'NZ', icon: '' },
{ name: 'Nicaragua', id: 'NI', icon: '' },
{ name: 'Niger', id: 'NE', icon: '' },
{ name: 'Nigeria', id: 'NG', icon: '' },
{ name: 'Niue', id: 'NU', icon: '' },
{ name: 'Norfolk Island', id: 'NF', icon: '' },
{ name: 'Northern Mariana Islands', id: 'MP', icon: '' },
{ name: 'Norway', id: 'NO', icon: '' },
{ name: 'Oman', id: 'OM', icon: '' },
{ name: 'Pakistan', id: 'PK', icon: '' },
{ name: 'Palau', id: 'PW', icon: '' },
{ name: 'Palestinian Territory, Occupied', id: 'PS', icon: '' },
{ name: 'Panama', id: 'PA', icon: '' },
{ name: 'Papua New Guinea', id: 'PG', icon: '' },
{ name: 'Paraguay', id: 'PY', icon: '' },
{ name: 'Peru', id: 'PE', icon: '' },
{ name: 'Philippines', id: 'PH', icon: '' },
{ name: 'Pitcairn', id: 'PN', icon: '' },
{ name: 'Poland', id: 'PL', icon: '' },
{ name: 'Portugal', id: 'PT', icon: '' },
{ name: 'Puerto Rico', id: 'PR', icon: '' },
{ name: 'Qatar', id: 'QA', icon: '' },
{ name: 'Reunion', id: 'RE', icon: '' },
{ name: 'Romania', id: 'RO', icon: '' },
{ name: 'Russian Federation', id: 'RU', icon: '' },
{ name: 'RWANDA', id: 'RW', icon: '' },
{ name: 'Saint Helena', id: 'SH', icon: '' },
{ name: 'Saint Kitts and Nevis', id: 'KN', icon: '' },
{ name: 'Saint Lucia', id: 'LC', icon: '' },
{ name: 'Saint Pierre and Miquelon', id: 'PM', icon: '' },
{ name: 'Saint Vincent and the Grenadines', id: 'VC', icon: '' },
{ name: 'Samoa', id: 'WS', icon: '' },
{ name: 'San Marino', id: 'SM', icon: '' },
{ name: 'Sao Tome and Principe', id: 'ST', icon: '' },
{ name: 'Saudi Arabia', id: 'SA', icon: '' },
{ name: 'Senegal', id: 'SN', icon: '' },
{ name: 'Serbia and Montenegro', id: 'CS', icon: '' },
{ name: 'Seychelles', id: 'SC', icon: '' },
{ name: 'Sierra Leone', id: 'SL', icon: '' },
{ name: 'Singapore', id: 'SG', icon: '' },
{ name: 'Slovakia', id: 'SK', icon: '' },
{ name: 'Slovenia', id: 'SI', icon: '' },
{ name: 'Solomon Islands', id: 'SB', icon: '' },
{ name: 'Somalia', id: 'SO', icon: '' },
{ name: 'South Africa', id: 'ZA', icon: '' },
{ name: 'South Georgia and the South Sandwich Islands', id: 'GS', icon: '' },
{ name: 'Spain', id: 'ES', icon: '' },
{ name: 'Sri Lanka', id: 'LK', icon: '' },
{ name: 'Sudan', id: 'SD', icon: '' },
{ name: 'Suriname', id: 'SR', icon: '' },
{ name: 'Svalbard and Jan Mayen', id: 'SJ', icon: '' },
{ name: 'Swaziland', id: 'SZ', icon: '' },
{ name: 'Sweden', id: 'SE', icon: '' },
{ name: 'Switzerland', id: 'CH', icon: '' },
{ name: 'Syrian Arab Republic', id: 'SY', icon: '' },
{ name: 'Taiwan, Province of China', id: 'TW', icon: '' },
{ name: 'Tajikistan', id: 'TJ', icon: '' },
{ name: 'Tanzania, United Republic of', id: 'TZ', icon: '' },
{ name: 'Thailand', id: 'TH', icon: '' },
{ name: 'Timor-Leste', id: 'TL', icon: '' },
{ name: 'Togo', id: 'TG', icon: '' },
{ name: 'Tokelau', id: 'TK', icon: '' },
{ name: 'Tonga', id: 'TO', icon: '' },
{ name: 'Trinidad and Tobago', id: 'TT', icon: '' },
{ name: 'Tunisia', id: 'TN', icon: '' },
{ name: 'Turkey', id: 'TR', icon: '' },
{ name: 'Turkmenistan', id: 'TM', icon: '' },
{ name: 'Turks and Caicos Islands', id: 'TC', icon: '' },
{ name: 'Tuvalu', id: 'TV', icon: '' },
{ name: 'Uganda', id: 'UG', icon: '' },
{ name: 'Ukraine', id: 'UA', icon: '' },
{ name: 'United Arab Emirates', id: 'AE', icon: '' },
{ name: 'United Kingdom', id: 'GB', icon: '' },
{ name: 'United States', id: 'US', icon: '' },
{ name: 'United States Minor Outlying Islands', id: 'UM', icon: '' },
{ name: 'Uruguay', id: 'UY', icon: '' },
{ name: 'Uzbekistan', id: 'UZ', icon: '' },
{ name: 'Vanuatu', id: 'VU', icon: '' },
{ name: 'Venezuela', id: 'VE', icon: '' },
{ name: 'Viet Nam', id: 'VN', icon: '' },
{ name: 'Virgin Islands, British', id: 'VG', icon: '' },
{ name: 'Virgin Islands, U.S.', id: 'VI', icon: '' },
{ name: 'Wallis and Futuna', id: 'WF', icon: '' },
{ name: 'Western Sahara', id: 'EH', icon: '' },
{ name: 'Yemen', id: 'YE', icon: '' },
{ name: 'Zambia', id: 'ZM', icon: '' },
{ name: 'Zimbabwe', id: 'ZW', icon: '' },
];
class Index extends Component {
constructor(props) {
super(props);
this.state = {
name: '',
nameRg: '',
number: '',
description: '',
job: '',
country: '',
agreement: false,
isAgreementChecked: false,
hasNameError: true,
hasDescriptionError: true,
hasMovieError: true,
hasJobError: true,
hasAgreementError: true,
validate: false,
};
this.validateForm = this.validateForm.bind(this);
}
toggleValidating(validate) {
this.setState({ validate });
}
validateForm(e) {
e.preventDefault();
this.toggleValidating(true);
const {
// name,
// job,
// country,
// agreement,
// description,
hasNameError,
hasDescriptionError,
hasMovieError,
hasJobError,
hasAgreementError,
} = this.state;
if (!hasNameError && !hasDescriptionError && !hasMovieError && !hasJobError && !hasAgreementError) {
alert('All validated!');
}
}
render() {
const { name, nameRg, number, description, job, agreement, isAgreementChecked, country, validate } = this.state;
const rowStyle = {
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'space-between',
padding: '2%',
fontSize: '14px',
};
const rowWrapperStyle = {
display: 'table',
width: '100%',
};
const rowContainerStyle = {
display: 'table-cell',
verticalAlign: 'middle',
borderBottom: '1px solid #e5e5e5',
};
const labelStyle = {
display: 'inline-block',
};
const labelContentStyle = {
verticalAlign: 'middle',
};
let countryItem;
COUNTRY_OPTIONS_LIST.filter(i => {
if (String(i.id) == String(country)) {
countryItem = i;
}
});
return (
<div className={CSS['wrapper']}>
<div style={{ padding: '10px', border: '1px solid #e5e5e5' }}>
<div>
<h1>Basic Usage</h1>
</div>
<div>
<div className={CSS['sub-section-title-wrapper']}>
<div className={CSS['sub-section-title']}>Textbox</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Textbox Empty by onBlur Example:</h1>
<Textbox
attributesInput={{
// Optional.
id: 'Name',
name: 'Name',
type: 'text',
placeholder: 'Place your name here ^-^',
}}
value={name} // Optional.[String].Default: "".
onChange={(name, e) => {
this.setState({ name });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={e => {
console.log(e);
}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
name: 'Name', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your {name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownTextboxEmptyExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Textbox Regex by onBlur Example:</h1>
<Textbox
attributesInput={{
// Optional.
id: 'Name',
name: 'Name',
type: 'text',
placeholder: 'Place your name here ^-^',
}}
value={nameRg} // Optional.[String].Default: "".
placeholder="Place your name here ^-^" // Optional.[String].Default: "".
onChange={(name, e) => {
this.setState({ nameRg });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={e => {
console.log(e);
}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
reg: /^\d{5}$/, // Optional.[Bool].Default: "" Custom regex.
regMsg: 'failed in reg.test(value)', // Optional.[String].Default: "" Custom regex error message.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownTextboxRegexExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Textbox Number by onBlur Example:</h1>
<Textbox
attributesInput={{
// Optional.
id: 'Number',
name: 'Number',
type: 'text', // Input type [text, password, number]. NOTE: provide "text" for better performance since different browsers run differently with "number".
placeholder: 'Place your number here ^-^',
}}
value={number} // Optional.[String].Default: "".
onChange={(number, e) => {
this.setState({ number });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={() => {}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
type: 'number', // Optional.[String].Default: "string". Validation type, options are ['string', 'number', 'alphanumeric', 'alpha'].
min: 10, // Optional.[Number].Default: 0. Validation of min length when validationOption['type'] is string, min amount when validationOption['type'] is number.
max: 100, // Optional.[Number].Default: 0. Validation of max length when validationOption['type'] is string, max amount when validationOption['type'] is number.
// mantissa: 2, // Optional.[Number].Default: -1. Number precision.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownTextboxNumberExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
</div>
<div>
<div className={CSS['sub-section-title-wrapper']}>
<div className={CSS['sub-section-title']}>Radiobox</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Radiobox Empty by onBlur Example:</h1>
<Radiobox
attributesInput={{
// Optional.
id: 'job',
name: 'job',
}}
value={job} // Optional.[String].Default: "".
optionList={[
{ id: 'engineer', name: 'engineer' },
{ id: 'teacher', name: 'teacher' },
{ id: 'student', name: 'student' },
]}
customStyleContainer={{
display: 'flex',
justifyContent: 'flex-start',
}} // Optional.[Object].Default: {}.
customStyleOptionListItem={{ marginRight: '20px' }} // Optional.[Object].Default: {}.
onChange={(job, e) => {
this.setState({ job });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={e => {
console.log(e);
}} // Optional.[Func].Default: none.
validationOption={{
name: 'job', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownRadioboxEmptyExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
</div>
<div>
<div className={CSS['sub-section-title-wrapper']}>
<div className={CSS['sub-section-title']}>Checkbox</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Checkbox Empty by onBlur Example:</h1>
<Checkbox
attributesInput={{
// Optional.
id: 'agreement',
name: 'agreement',
}}
value={agreement} // Required.[String].Default: "".
onBlur={() => {}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
checked={isAgreementChecked} // Required.[Bool].Default: false.
onChange={(isAgreementChecked, e) => {
this.setState({ isAgreementChecked });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
labelHtml={<div style={{ color: '#4a4a4a', marginTop: '2px' }}>agree?</div>} // Required.[Html].Default: none.
validationOption={{
name: 'agreement', // Optional.[String].Default: "". To display in the Error message. i.e Please check the ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownCheckboxEmptyExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
</div>
<div>
<div className={CSS['sub-section-title-wrapper']}>
<div className={CSS['sub-section-title']}>Select</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Select Empty by onBlur Example:</h1>
<Select
attributesInput={{
// Optional.
id: 'country',
name: 'country',
}}
value={country} // Optional.[String].Default: "".
optionList={[
{ id: '', name: 'Please Select a country' },
{ id: 'US', name: 'United States' },
{ id: 'CN', name: 'China' },
{ id: 'JP', name: 'Japan' },
]} // Required.[Array of Object(s)].Default: [].
onChange={(res, e) => {
this.setState({ country: res.id });
console.log(e);
}} // Optional.[Func].Default: () => {}. Will return the value.
onBlur={() => {}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
customStyleOptionListContainer={{ maxHeight: '200px', overflow: 'auto', fontSize: '14px' }} // Optional.[Object].Default: {}.
validationOption={{
name: 'country', // Optional.[String].Default: "". To display in the Error message. i.e Please select a ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownSelectEmptyExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
</div>
<div>
<div className={CSS['sub-section-title-wrapper']}>
<div className={CSS['sub-section-title']}>Textarea</div>
</div>
<div style={{ overflow: 'auto', padding: '2%' }}>
<div className={CSS['block']}>
<div>
<h1>Validate Textarea Empty by onBlur Example:</h1>
<Textarea
attributesInput={{
// Optional.
id: 'description',
name: 'description',
type: 'text',
placeholder: 'Place your description here ^-^',
}}
value={description} // Optional.[String].Default: "".
onChange={(description, e) => {
this.setState({ description });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={e => {
console.log(e);
}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
validationOption={{
name: 'Description', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your {name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
}}
/>
<br />
</div>
<div>
<Markdown source={markdownTextareaEmptyExample} renderers={{ CodeBlock }} />
</div>
</div>
</div>
</div>
</div>
<br />
<div style={{ minHeight: '1000px', padding: '10px', border: '1px solid #e5e5e5' }}>
<h1>Example form</h1>
<form onSubmit={this.validateForm}>
<div style={rowWrapperStyle}>
<div style={rowContainerStyle}>
<div style={rowStyle}>
<div style={prefixAll({ ...labelStyle, flex: '3 3 0px', marginTop: '3px' })}>
<span className="icon icon-person" style={{ ...labelContentStyle, fontSize: '20px' }} />
<span style={labelContentStyle}>Name</span>
</div>
<div style={prefixAll({ flex: '6 6 0px' })}>
<Textbox
attributesWrapper={{}}
attributesInput={{
id: 'Name',
name: 'Name',
maxLength: 10,
type: 'text',
placeholder: 'Place your name here ^-^',
}}
value={name} // Optional.[String].Default: "".
label="" // Optional.[String].Default: "". The content of label. NOTE: must provide attributesInput.id
disabled={false} // Optional.[Bool].Default: false.
validate={validate} // Optional.[Bool].Default: false. If you have a submit button and trying to validate all the inputs of your form at onece, toggle it to true, then it will validate the field and pass the result via the "validationCallback" you provide.
validationCallback={res => this.setState({ hasNameError: res, validate: false })} // Optional.[Func].Default: none. Return the validation result.
classNameInput="" // Optional.[String].Default: "".
classNameWrapper="" // Optional.[String].Default: "".
classNameContainer="" // Optional.[String].Default: "".
customStyleInput={{}} // Optional.[Object].Default: {}.
customStyleWrapper={{}} // Optional.[Object].Default: {}.
customStyleContainer={{}} // Optional.[Object].Default: {}.
onChange={(name, e) => {
this.setState({ name });
console.log(e);
}} // Required.[Func].Default: () => {}. Will return the value.
onBlur={e => {
console.log(e);
}} // Optional.[Func].Default: none. In order to validate the value on blur, you MUST provide a function, even if it is an empty function. Missing this, the validation on blur will not work.
// onFocus={(e) => {console.log(e);}} // Optional.[Func].Default: none.
// onClick={(e) => {console.log(e);}} // Optional.[Func].Default: none.
validationOption={{
name: 'Name', // Optional.[String].Default: "". To display in the Error message. i.e Please enter your ${name}.
check: true, // Optional.[Bool].Default: true. To determin if you need to validate.
required: true, // Optional.[Bool].Default: true. To determin if it is a required field.
type: 'number',
// type: 'string', // Optional.[String].Default: "string". Validation type, options are ['string', 'number', 'alphanumeric', 'alpha'].
// numberType: 'decimal', // Optional.[String].Default: "decimal". Validation number type, options are ['decimal', 'int', 'price']. Handy when the validation type is number.
// mantissa: 2, // Optional.[Number].Default: -1. Number precision.
// showMsg: true, // Optional.[Bool].Default: true. To determin display the error message or not.
// min: 2, // Optional.[Number].Default: 0. Validation of min length when validationOption['type'] is string, min amount when validationOption['type'] is number.
// max: 10, // Optional.[Number].Default: 0. Validation of max length when validationOption['type'] is string, max amount when validationOption['type'] is number.
// length: 2, // Optional.[Number].Default: 0. Validation of exact length of the value.
// compare: '3', // Optional.[String].Default: "" Compare this value to 3 to see if they are equal.
// reg: /^\d{18}|\d{15}$/, // Optional.[Bool].Default: "" Custom regex.
// regMsg: 'failed in reg.test(${value})', // Optional.[String].Default: "" Custom regex error message.
// locale: 'en-US', // Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'.
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", // Optional.[String].Default: "" Show your custom error message no matter what(except the message from customFunc) when it has error if it is provied.
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border.", // Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
// customFunc: res => { // Optional.[Func].Default: none. Custom function. Returns true or err message
// if (res != 'milk') {
// return 'Name cannot be other things but milk';
// }
// return true;
// }
// customFunc: async v => {
// if (v === '') {
// this.setState({ hasError: true });
// return 'Name is required.';
// }
// if (v.length < 4) {
// this.setState({ hasError: true });
// return 'Name needs at least 4 length.';
// }
// let usernameRes = null;
// await fetch('https://jsonplaceholder.typicode.com/todos/1')
// .then(response => {
// return response.json();
// })
// .then(json => {
// console.log('parsed json', json);
// usernameRes = true;
// })
// .catch(ex => {
// console.log('parsing failed', ex);
// });
// if (usernameRes === false) {
// this.setState({ hasError: true });
// return {
// error: true,
// message: 'Username already exist.',
// };
// }
// if (usernameRes === true) {
// this.setState({ hasError: false });
// return {
// error: false,
// message: 'Username does not already exist.',
// showOnSuccess: true,
// };
// }
// },
// msgOnError: '<a href="google.com">google</a>',
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
}}
// asyncMsgObj={this.state.nameAsyncMsgObj}
// asyncMsgObj={{
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
// message: '', // Optional.[String].Default: "". (Server response) Your AJAX message. For instance, provide it when backend returns 'USERNAME ALREADY EXIST'
// showOnError: true, // Optional.[Bool].Default: true. (Server response) Show AJAX error message or not.
// showOnSuccess: false, // Optional.[Bool].Default: false. (Server response) Show AJAX success message or not.
// }}
/>
{/*<div>
<input
id="textOutsideController"
onChange={() => {
this.setState({ name: document.getElementById('textOutsideController').value });
}}
/>
</div>*/}
</div>
</div>
</div>
</div>
<div style={rowWrapperStyle}>
<div style={rowContainerStyle}>
<div style={rowStyle}>
<div style={prefixAll({ ...labelStyle, flex: '3 3 0px', marginTop: '3px' })}>
{/*<div style={(labelStyle, { flex: '3 3 0px' })}>*/}
<span className="icon icon-info" style={{ ...labelContentStyle, fontSize: '20px' }} />
<span style={labelContentStyle}>job</span>
</div>
<div style={prefixAll({ flex: '6 6 0px', display: 'flex' })}>
<Radiobox
attributesWrapper={{}}
attributesInputs={[
{ id: 'job-0', name: 'job-0' },
{ id: 'job-1', name: 'job-1' },
{ id: 'job-2', name: 'job-2' },
]}
disabled={false} // Optional.[Bool].Default: false.
value={job} // Optional.[String].Default: "".
validate={validate} // Optional.[Bool].Default: false. If you have a submit button and trying to validate all the inputs of your form at onece, toggle it to true, then it will validate the field and pass the result via the "validationCallback" you provide.
validationCallback={res => this.setState({ hasJobError: res, validate: false })} // Optional.[Func].Default: none. Return the validation result.
optionList={JOB_OPTIONS_LIST}
classNameInput="" // Optional.[String].Default: "".
classNameWrapper="" // Optional.[String].Default: "".
classNameContainer="" // Optional.[String].Default: "".
classNameOptionListItem="" // Optional.[String].Default: "".
customStyleInput={{}} // Optional.[Object].Default: {}.
customStyleWrapper={{}} // Optional.[Object].Default: {}.
customStyleContainer={{
display: 'flex',
justifyContent: 'flex-start',
}} // Optional.[Object].Default: {}.
customStyleOptionListItem={{ marginRight: '20px' }} // Optional.[Object].Default: {}.
onChange={(job, e) => {