-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
1538 lines (1454 loc) · 36.4 KB
/
example.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
'use strict';
var stream = m.stream;
uiWidgets.updateConfig({
signFont: "Caveat",
// currencySymbol: "£"
// requiredLblPost: "*",
// optionalLblPost: " (optional)"
});
uiWidgets.updateClasses({
invalidInputWrapper: "b--red ba",
floatLabelPlaceholder: "o-40",
requiredLabel: "bb b--red",
});
uiWidgets.updateButtonContext({
invert: "bg-dark-gray light-blue b--light-blue",
warn: "bg-orange black ph3 pv2 ba br-pill b--black b--dashed"
});
// Simple props
var textVal = stream();
var currencyVal = stream(-500);
var currencyValidationVal = stream(100);
var percentageVal = stream(-5000);
var dateVal = stream();
var dateFormat = stream("default");
var enableDatePicker = stream(false)
var dateFormatUiClass = { inputWrapper: "pa1 ma0", input: "f6", merge: false };
var timeVal = stream();
var colVal = stream("#cc0011");
var cardVal = stream();
var labVal = stream("Label");
var checkVal = stream();
var optVal = stream();
var multiVal = stream();
var multiValOpts = [{
value: "A", label: "Apple",
}, {
value: "B", label: "Banana"
}, {
value: "C", label: "Cherry"
}, {
value: 1, label: "One"
}, {
value: true, label: "True"
}];
var faceVal = stream();
var faceValUiClass = {
wrapper: "flex-auto bg-near-white br-pill ma1",
input: "flex justify-center"
};
var toggleVal = stream();
var passVal = stream();
// Transform
var xformValIn = stream("");
var xformValOut = xformValIn.map((val) => val.toUpperCase());
// Custom
var value = stream("");
var label = stream("Custom Input");
var type = stream("text");
var placeholder = stream("Placeholder");
var required = stream(false);
var readonly = stream(false);
var disabled = stream(false);
var displayFileList = stream(false);
// Files
var fileButtonList = stream([]);
var fileList = stream([]);
var imgList = stream([]);
var imgInputList = stream([]);
var signList = stream([]);
var omniInputList = stream([]);
var multiOmniInputList = stream([]);
var readonlyOrDisabled = stream(false);
// Layout
var layoutVal = stream("floatLabel");
layoutVal.map((newVal) => uiWidgets.updateConfig({ layoutType: newVal }));
// Theme
var themeWrapper = stream(uiWidgets.theme.wrapper);
themeWrapper.map((newCls) => uiWidgets.updateClasses({ wrapper: newCls }));
var themeLabel = stream(uiWidgets.theme.label);
themeLabel.map((newCls) => uiWidgets.updateClasses({ label: newCls }));
var themeInputWrapper = stream(uiWidgets.theme.inputWrapper);
themeInputWrapper.map((newCls) => uiWidgets.updateClasses({ inputWrapper: newCls }));
var themeInput = stream(uiWidgets.theme.input);
themeInput.map((newCls) => uiWidgets.updateClasses({ input: newCls }));
var themeRequired = stream(uiWidgets.theme.requiredLabel);
themeRequired.map((newCls) => uiWidgets.updateClasses({ requiredLabel: newCls }));
var themeDisabled = stream(uiWidgets.theme.disabledWrapper);
themeDisabled.map((newCls) => uiWidgets.updateClasses({ disabledWrapper: newCls }));
var themeBtn = stream(uiWidgets.theme.button);
themeBtn.map((newCls) => uiWidgets.updateClasses({ button: newCls }));
var themeNavBtn = stream(uiWidgets.theme.navButton);
themeNavBtn.map((newCls) => uiWidgets.updateClasses({ navButton: newCls }));
uiWidgets.registerFunction("svgCircle", (data, classes) => m("svg[xmlns=http://www.w3.org/2000/svg]", {
class: classes,
viewBox: `0 0 ${data.radius * 2} ${data.radius * 2}`,
width: data.radius * 2, height: data.radius * 2,
class: uiWidgets.joinClasses([classes, data.classes])
},
m("circle", {
cx: data.radius, cy: data.radius, r: data.radius - 1,
style: {
fill: data.fill,
stroke: data.stroke,
strokeWidth: 2
}
})
));
// List debug mode
var debug = stream(false);
// List dummy data generator
var words = ["lorem", "ipsum", "dolor", "sit", "amet"];
function generate(offset, limit) {
var data = [];
var end = offset + limit;
// var end = Math.min(offset + limit, 256);
for (var i = offset; i < end; i++) {
var random = Math.random();
data.push({
id: i,
name: `${i}: ${words[Math.floor(random * words.length)]}`,
random: random.toFixed(3),
upper: random > 0.5,
even: i % 2 === 0
});
}
return new Promise((resolve) => {
setTimeout(() => resolve(data), 500 + Math.random() * 500);
});
}
// Fetch 128 rows
var single = uiWidgets.ListController.single(() => generate(0, 128));
// Basic sort
var orderAsc = true;
single.setSort((input) => orderAsc ? input : _.sortBy(input, ({ id }) => id * -1));
// Basic filter
var singleFilter = stream();
single.setFilter((input) => {
const val = singleFilter();
if (val) {
const filter = val.toLowerCase();
return input.filter(({ name }) => name.toLowerCase().includes(filter))
} else {
return input;
}
});
// Don't filter until data is loaded and handle streams that have not started
singleFilter.map(() => single.applyFilter());
// Fetch rows from range
var paging = uiWidgets.ListController.paging(generate);
// var paginated = uiWidgets.PageController.single(() => generate(0, 128));
var paginated = uiWidgets.PageController.paging(generate);
// List row component
var rowComponent = {
view: ({ attrs: { id, name, random, upper, even } }) => m(".pa1",
m(".flex.items-center.justify-around.pa1.ba.b--moon-gray.br2", {
class: even ? "bg-near-white" : ""
}, [
m("span.w-20.i", id),
m("span.w-30", name),
m("span.w-20.code.f6", {
class: upper ? "dark-green" : "dark-red"
}, random),
m(uiWidgets.Button, {
label: "Log Name",
onclick: () => console.log(name)
})
])
)
};
m.mount(document.getElementById("page"), {
view: () => m(".mw8.ph4.mv5.center", [
// Navbar
m(".flex.flex-column.flex-row-l.items-center-l.fixed.top-0.right-0.bg-near-white.z-max", [
m(uiWidgets.NavLink, {
label: "Basic Usage",
icon: "fas fa-home",
href: "#basic"
}),
m(uiWidgets.NavLink, {
label: "Buttons",
icon: "fas fa-arrow-circle-right",
href: "#button"
}),
m(uiWidgets.NavLink, {
label: "Customise",
icon: "fas fa-edit",
href: "#custom"
}),
m(uiWidgets.NavLink, {
label: "File Inputs",
icon: "fas fa-file-alt",
href: "#files"
}),
m(uiWidgets.NavLink, {
label: "List",
icon: "fas fa-list",
href: "#list"
}),
m(uiWidgets.NavLink, {
label: "Theme",
icon: "fas fa-paint-roller",
href: "#theme"
}),
m(".mh2.flex.items-center", [
m("i.fa.fa-tags.mh2"),
m("span", "Type"),
m(uiWidgets.SelectInput, {
field: {
id: "layout-in",
options: [{
label: "Basic",
value: "default"
}, {
label: "Animated",
value: "floatLabel"
}, {
label: "Fixed",
value: "floatAlways"
}],
uiClass: {
inputWrapper: "bn",
}
},
value: layoutVal
})
])
]),
m("h2.flex.items-center", [
"ui-widgets",
m(uiWidgets.Tooltip, { message: ["Now with tooltip", "with the option for multiple lines"] })
]),
m("h3", m("a#basic.link[href=#basic]", "Basic Usage")),
m("p", "Display components reflect changes made to the stream by input components. A value stream can be used by multiple input components, values stay in sync with no additional code."),
m("p", "Inputs can apply additional classes if they fail validation."),
// Text
m(".flex.mb2.items-center.ba.b--silver", [
m(".flex.flex-column.w-50.pa2", [
m(uiWidgets.BaseInput, {
field: {
id: "text-in-input",
label: {
text: "Text Input",
alt: "(updates on input)"
},
required: true,
// pattern: "([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\\s?[0-9][A-Za-z]{2})",
instant: true,
uiClass: { invalidInputWrapper: "b--dashed" }
},
value: textVal
}),
m(uiWidgets.TextareaInput, {
field: {
id: "text-area-input",
label: {
text: "Text Area",
alt: "(updates on change)"
},
type: "textarea"
},
value: textVal
}),
]),
m(".w-50.pa2", m(uiWidgets.BaseText, {
field: {
id: "text-out",
label: "Text Output"
},
value: textVal
}))
]),
// Date
m(".flex.mb2.items-center.ba.b--silver", [
m(".flex.flex-column.w-50.pa2", [
m(uiWidgets.BaseInput, {
field: {
id: "date-in",
label: {
text: "Date Input",
alt: "(Browser Default)"
},
type: "date",
uiClass: { wrapper: "mb2" }
},
value: dateVal
}),
m(uiWidgets.DateInput, {
field: {
id: "date-in-widget",
label: {
text: "Date Input",
alt: "(ui-widgets Bespoke)"
},
required: true,
disabled: !enableDatePicker(),
uiClass: { wrapper: "mb2" },
config: {
dateLocale: dateFormat()
}
},
value: dateVal
}),
m(uiWidgets.ToggleInput, {
field: {
id: "toggle-Flatpickr",
label: "Enabled",
config: {
toggleOnIcn: "bg-white br-pill fa-solid fa-check green",
toggleOffIcn: "bg-white br-pill fa-solid fa-xmark"
}
},
value: enableDatePicker
}),
// Date locale
m(".flex.flex-wrap.mb2", [
m(uiWidgets.RadioInput, {
field: {
id: "date-format-default",
label: "Default", value: "default",
uiClass: dateFormatUiClass
},
value: dateFormat
}),
m(uiWidgets.RadioInput, {
field: {
id: "date-format-gb",
label: "GB", value: "en-GB",
uiClass: dateFormatUiClass
},
value: dateFormat
}),
m(uiWidgets.RadioInput, {
field: {
id: "date-format-us",
label: "US", value: "en-US",
uiClass: dateFormatUiClass
},
value: dateFormat
}),
m(uiWidgets.RadioInput, {
field: {
id: "date-format-ch",
label: "Switzerland", value: "fr-CH",
uiClass: dateFormatUiClass
},
value: dateFormat
}),
m(uiWidgets.RadioInput, {
field: {
id: "date-format-eg",
label: "Egypt", value: "ar-EG",
uiClass: dateFormatUiClass
},
value: dateFormat
}),
m(uiWidgets.RadioInput, {
field: {
id: "date-format-kr",
label: "Korea", value: "ko-KR",
uiClass: dateFormatUiClass
},
value: dateFormat
}),
m(uiWidgets.RadioInput, {
field: {
id: "date-format-jp",
label: "Japan", value: "ja-JP",
uiClass: dateFormatUiClass
},
value: dateFormat
})
]),
m(uiWidgets.BaseInput, {
field: {
id: "date-in-text",
label: {
text: "Date Input",
alt: "(text input)"
}
},
value: dateVal
})
]),
m(".w-50.pa2", m(uiWidgets.DateText, {
field: {
id: "date-out",
label: "Date Output"
},
value: dateVal
}))
]),
// Time
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", [
m(uiWidgets.BaseInput, {
field: {
id: "time-in",
label: "Time Input",
type: "time"
},
value: timeVal
}),
m(uiWidgets.TimeInput, {
field: {
id: "time-in-widget",
label: {
text: "Time Input",
alt: "(ui-widgets Bespoke)"
},
required: true,
step: 5
},
value: timeVal
})
]),
m(".w-50.pa2", m(uiWidgets.BaseText, {
field: {
id: "time-out",
label: "Time Output",
},
value: timeVal
}))
]),
// Colour
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.BaseInput, {
field: {
id: "color-in",
label: "Colour Input",
type: "color"
},
value: colVal
})),
m(".w-50.pa2", m(uiWidgets.BaseText, {
field: {
id: "color-out",
label: "Colour Output",
},
value: colVal
}))
]),
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.Label, {
field: {
id: "label",
label: "Label"
},
value: labVal
})),
m(".w-50.pa2", m(uiWidgets.BaseText, {
field: {
id: "label-out",
label: "Label Output",
},
value: labVal
}))
]),
// Password
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.PasswordInput, {
field: {
id: "password-in",
label: "Password Input",
required: true,
instant: true
},
value: passVal
})),
m(".w-50.pa2", m(uiWidgets.PasswordStrength, {
field: {
id: "password-in-strength",
label: "Password Strength"
},
value: passVal
}))
]),
m("p", "Checkbox, Toggle, and Radio inputs support conditional labels and classes based on their state."),
// Checkbox
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.CheckboxInput, {
field: {
id: "check-in",
label: "Checkbox Input",
config: {
selectionLayout: ["label", "icon", "on"],
selectionOnLabel: "Checked",
}
},
value: checkVal
})),
m(".w-50.pa2", m(uiWidgets.Checkbox, {
field: {
id: "check-out",
label: "Checkbox Output",
config: {
selectionLayout: ["label", "icon", "off"],
selectionOffLabel: "Unchecked"
}
},
value: checkVal
}))
]),
// Toggle
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.ToggleInput, {
field: {
id: "toggle-in",
label: "Toggle Input",
required: true
},
value: toggleVal
})),
m(".w-50.pa2", m(uiWidgets.Toggle, {
field: {
id: "toggle-out",
label: "Toggle Output",
config: {
selectionLayout: ["icon", "on", "off"],
selectionOnLabel: "Toggle Input On",
selectionOffLabel: "Toggle Input Off",
toggleOnIcn: "fas fa-toggle-off",
toggleOffIcn: "fas fa-toggle-on"
}
},
value: toggleVal
}))
]),
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.ToggleInput, {
field: {
id: "toggle-in",
label: "Toggle Input",
config: {
toggleOnWrapper: "bg-dark-gray",
toggleOffWrapper: "bg-dark-gray",
toggleOnIcn: "bg-near-white",
toggleOffIcn: "bg-gray"
},
layout: "floatAlways"
},
value: toggleVal
})),
m(".w-50.pa2", m(uiWidgets.Toggle, {
field: {
id: "toggle-out",
label: "Toggle Output",
config: {
selectionLayout: ["off", "icon", "on", "label"],
selectionOnLabel: "On",
selectionOffLabel: "Off",
selectionOnInactive: "o-40",
selectionOffInactive: "o-40",
toggleOnIcn: "fas fa-toggle-off",
toggleOffIcn: "fas fa-toggle-on fa-flip-horizontal"
}
},
value: toggleVal
}))
]),
// Select/Radio
m(".flex.mb2.items-center.ba.b--silver", [
m(".flex.flex-column.w-50.pa2", [
m(uiWidgets.SelectInput, {
field: {
id: "select-in",
label: "Select Input",
required: true,
options: [{
label: "Not Set",
value: ""
}, {
label: "Yes",
value: "yes"
}, {
label: "No",
value: "no"
}, {
label: "Maybe",
value: "maybe"
}],
uiClass: { wrapper: "mb2" }
},
value: optVal
}),
m(uiWidgets.RadioInput, {
field: {
id: "radio-in",
label: "Yes",
type: "radio",
name: "radio-group-1",
value: "yes",
required: true
},
value: optVal
}),
m(uiWidgets.RadioInput, {
field: {
id: "radio-in2",
label: "No",
type: "radio",
name: "radio-group-1",
value: "no",
required: true
},
value: optVal
}),
m(uiWidgets.RadioInput, {
field: {
id: "radio-in3",
label: "Maybe",
type: "radio",
name: "radio-group-1",
value: "maybe",
required: true,
config: {
selectionLayout: ["icon", "label", "on"],
selectionOnActive: "fas fa-question",
radioOnIcn: {
name: "svgCircle",
data: {
radius: 10,
fill: "green",
stroke: "#333333"
}
},
// radioOffIcn: {
// name: "svgCircle",
// data: {
// radius: 10,
// fill: "red",
// stroke: "#333333"
// }
// }
}
},
value: optVal
})
]),
m(".w-50.pa2", m(uiWidgets.BaseText, {
field: {
id: "select-radio-out",
label: "Select/Radio Output"
},
value: optVal
}))
]),
m("p", "The CheckList input behaves like a select input, but displays options similar to the Checkbox widget. The list stays open when in focus and can help simplify multiple selection."),
// Multi-Select
m(".flex.mb2.items-center.ba.b--silver", [
m(".w-50.pa2", [
m(uiWidgets.CheckList, {
field: {
id: "single-checklist-in",
label: "Single CheckList Input",
required: true,
placeholder: "Single",
options: multiValOpts,
config: {
checkListIcn: "fas fa-chevron-up",
checkListDropUp: true
}
},
value: multiVal
}),
m(uiWidgets.CheckList, {
field: {
id: "multi-checklist-in",
label: "Multi CheckList Input",
required: true,
multiple: true,
placeholder: "Multiple",
options: multiValOpts
},
value: multiVal
})
]),
m(".w-50.pa2", [
m(uiWidgets.BaseText, {
field: {
id: "checklist-out",
label: "CheckList Output"
},
value: multiVal
})
])
]),
m("p.mt1.f6.orange", "Note: Take care mixing strings, numbers, and booleans in option values. The values are compared as strings and may not behave as expected."),
m("p", "The currency input stores values as the smallest monetary unit"),
// Currency/Number
m(".flex.mb2.ba.b--silver.flex-wrap", [
m(".w-50.pa2", m(uiWidgets.CurrencyInput, {
field: {
id: "currency-in-currency",
label: {
text: "Currency Input",
alt: "(Symbol on Right)"
},
config: { badgePosition: "right" }
},
value: currencyVal
})),
m(".w-50.pa2", m(uiWidgets.CurrencyInput, {
field: {
id: "currency-in-currency-parentheses",
label: {
text: "Currency Input",
alt: "(Red negative)"
},
config: { negativeStyle: "red" }
},
value: currencyVal
})),
m(".w-50.pa2", m(uiWidgets.CurrencyInput, {
field: {
id: "currency-in-currency-parentheses",
label: {
text: "Currency Input",
alt: "(Parentheses negative)"
},
config: { negativeStyle: "parentheses" }
},
value: currencyVal
})),
m(".w-50.pa2", m(uiWidgets.CurrencyInput, {
field: {
id: "currency-in-currency-red-parentheses",
label: {
text: "Currency Input",
alt: "(Red Parentheses negative)"
},
config: { negativeStyle: "redParentheses" }
},
value: currencyVal
})),
m(".w-50.pa2", m(uiWidgets.BaseInput, {
field: {
id: "currency-in-number",
label: "Smallest Monetary Unit",
type: "number"
},
value: currencyVal
}))
]),
m("p", "Currency inputs also support number validation, these rules are applied against the currency in the smallest monetary unit"),
// Currency/Number
m("form.flex.mb2.ba.b--silver.flex-wrap", {
onsubmit: () => {
console.debug("Submit success");
return false;
}
}, [
m(".w-50.pa2", m(uiWidgets.CurrencyInput, {
field: {
id: "currency-in-currency",
label: {
text: "Currency Input",
alt: "(Min 0, Max 1000)"
},
min: 0,
max: 1000,
},
value: currencyValidationVal
})),
m(".w-50.pa2.flex.items-end", m(uiWidgets.Button, {
label: "Submit",
type: "submit",
icon: "fas fa-paper-plane"
}))
]),
m("p.mt1.f6.orange", "Note: Values beyond Number.MAX_SAFE_INTEGER have undefined behaviour and display/input values will have their absolute value taken"),
m("p.mt1.f6.orange", "Note: Take care with CSS specificity between input class and red negative class"),
// Percentage
m(".flex.mb2.ba.b--silver.flex-wrap", [
m(".w-50.pa2", m(uiWidgets.PercentageInput, {
field: {
id: "percentage",
label: {
text: "Percentage Input",
alt: "(Symbol on right)"
},
max: 100,
config: { badgePosition: "right" }
},
value: percentageVal
})),
]),
// Card Date
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.CardDateInput, {
field: {
id: "card-in-date",
label: "Card Expiry MM/YY",
required: true
},
value: cardVal
})),
m(".w-50.pa2", m(uiWidgets.BaseInput, {
field: {
id: "card-in-text",
label: "Card Expiry Plain Text",
type: "text"
},
value: cardVal
}))
]),
m("p", "Perform custom transforms by mapping the input stream to a new value"),
m("p", "Note that a transform stream value is fed back into the initial value on each update"),
// xform
m(".flex.mb2.ba.b--silver", [
m(".w-50.pa2", m(uiWidgets.BaseInput, {
field: {
id: "xform-in-simple",
label: "Input Stream",
instant: true
},
value: xformValIn
})),
m(".w-50.pa2", m(uiWidgets.BaseInput, {
field: {
id: "xform-in-xform",
label: "Input Stream + Transform Stream (toUpperCase)",
instant: true
},
value: xformValIn,
xform: xformValOut
}))
]),
m("h3", m("a#button.link[href=#button]", "Buttons")),
m("p", "Buttons are available in standard and hyperlink variants"),
m(".flex.flex-wrap.mb1.nl1.nt1.nr1", [
m(uiWidgets.Button, {
label: "Simple Button",
icon: "fas fa-arrow-circle-down mr1",
// rightIcon: "fas fa-arrow-circle-down ml1",
rightIcon: {
name: "svgCircle",
data: {
radius: 10,
fill: "silver",
stroke: "#333333",
classes: "ml1"
}
},
classes: "ma1",
onclick: () => console.debug("Button Click")
}),
m(uiWidgets.Button, {
label: "Disabled Button",
classes: "ma1",
disabled: true
// onclick event will not fire on a disabled button
}),
m(uiWidgets.ButtonLink, {
label: "Link Button",
icon: "fas fa-link mr1",
classes: "ma1",
href: "#button"
}),
m(uiWidgets.NavButton, {
label: "Nav Button",
icon: "fas fa-arrow-circle-up mr1",
classes: "ma1",
onclick: () => console.debug("Nav Button Click")
}),
m(uiWidgets.NavLink, {
label: "Nav Link",
rightIcon: "fas fa-link ml1",
classes: "ma1",
href: "#button"
})
]),
m("p", "Additional button themes can also be registered"),
m(".flex.flex-wrap.mb1.nl1.nt1.nr1", [
m(uiWidgets.Button, {
label: "Inverted",
rightIcon: "fas fa-recycle ml1",
context: "invert",
classes: "ma1"
}),
m(uiWidgets.Button, {
label: "Warning",
icon: "fas fa-exclamation-triangle mr1",
context: "warn",
classes: "ma1"
}),
m(uiWidgets.ButtonLink, {
label: "Link Inverted",
icon: "fas fa-link mr1",
classes: "ma1",
context: "invert",
href: "#button"
}),
]),
m("h3", m("a#custom.link[href=#custom]", "Customise")),
m("p", "Widget options are simple to update"),
// Custom BaseInput
m(".flex.mb2.items-center.ba.b--silver", [
m(".flex.flex-column.w-50.pa2", [
m(uiWidgets.BaseInput, {
field: {
id: "custom-label",
label: "Label",
instant: true,
uiClass: { wrapper: "mb2" }
},
value: label
}),
m(uiWidgets.SelectInput, {
field: {
id: "custom-type",
label: "Type",
options: [{
label: "Text",
value: "text"
}, {
label: "Password",
value: "password"
}, {
label: "Date",
value: "date"
}, {
label: "Date Time",
value: "datetime-local"
}, {
label: "Number",
value: "number"
}, {
label: "Email",
value: "email"
}, {
label: "Telephone",
value: "tel"
}, {
label: "Color",
value: "color"
}, {
label: "Range",
value: "range"
}, {
label: "Hidden",
value: "hidden"
}],
uiClass: { wrapper: "mb2" }
},
value: type
}),