@jirawatpyk/aura-react 4.8.0 → 4.10.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/README.md +14 -3
- package/dist/aura.bundle.js +1457 -634
- package/dist/cjs/index.cjs +1456 -633
- package/dist/esm/Breadcrumb.js +3 -2
- package/dist/esm/Button.js +5 -3
- package/dist/esm/Combobox.js +310 -235
- package/dist/esm/DataTable.js +176 -94
- package/dist/esm/DatePicker.js +85 -23
- package/dist/esm/Icon.js +12 -1
- package/dist/esm/IconButton.js +2 -2
- package/dist/esm/NumberField.js +175 -0
- package/dist/esm/Pagination.js +3 -2
- package/dist/esm/SegmentedControl.js +104 -0
- package/dist/esm/SideNav.js +116 -10
- package/dist/esm/Stat.js +7 -3
- package/dist/esm/Stepper.js +54 -0
- package/dist/esm/colorScheme.js +8 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/locale.js +121 -2
- package/dist/esm/theme.js +35 -0
- package/dist/index.d.ts +171 -34
- package/dist/styles.css +150 -2
- package/package.json +1 -1
package/dist/esm/DatePicker.js
CHANGED
|
@@ -29,8 +29,69 @@ function addMonths(d, n) {
|
|
|
29
29
|
function same(a, b) {
|
|
30
30
|
return !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
31
31
|
}
|
|
32
|
+
const TAGS = { th: "th-TH", en: "en-GB", sv: "sv-SE" };
|
|
33
|
+
function defaultCalendar(locale) {
|
|
34
|
+
return locale === "sv" ? "gregory" : "buddhist";
|
|
35
|
+
}
|
|
32
36
|
function localeTag(locale, calendar) {
|
|
33
|
-
|
|
37
|
+
const cal = calendar || defaultCalendar(locale);
|
|
38
|
+
return (TAGS[locale || "th"] || "th-TH") + "-u-ca-" + (cal === "gregory" ? "gregory" : "buddhist");
|
|
39
|
+
}
|
|
40
|
+
const DATE_TEXT = {
|
|
41
|
+
th: {
|
|
42
|
+
prevYears: "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32",
|
|
43
|
+
nextYears: "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E16\u0E31\u0E14\u0E44\u0E1B",
|
|
44
|
+
prevMonth: "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32",
|
|
45
|
+
nextMonth: "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B",
|
|
46
|
+
today: "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49",
|
|
47
|
+
clear: "\u0E25\u0E49\u0E32\u0E07",
|
|
48
|
+
chooseDate: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
|
|
49
|
+
datePlaceholder: "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B",
|
|
50
|
+
clearDate: "\u0E25\u0E49\u0E32\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
|
|
51
|
+
openCalendar: "\u0E40\u0E1B\u0E34\u0E14\u0E1B\u0E0F\u0E34\u0E17\u0E34\u0E19",
|
|
52
|
+
chooseDates: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
|
|
53
|
+
rangePlaceholder: "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B \u2013 \u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B",
|
|
54
|
+
clearDates: "\u0E25\u0E49\u0E32\u0E07\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
|
|
55
|
+
chooseStart: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19",
|
|
56
|
+
chooseEnd: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14"
|
|
57
|
+
},
|
|
58
|
+
en: {
|
|
59
|
+
prevYears: "Previous years",
|
|
60
|
+
nextYears: "Next years",
|
|
61
|
+
prevMonth: "Previous month",
|
|
62
|
+
nextMonth: "Next month",
|
|
63
|
+
today: "Today",
|
|
64
|
+
clear: "Clear",
|
|
65
|
+
chooseDate: "Choose date",
|
|
66
|
+
datePlaceholder: "dd/mm/yyyy",
|
|
67
|
+
clearDate: "Clear date",
|
|
68
|
+
openCalendar: "Open calendar",
|
|
69
|
+
chooseDates: "Choose dates",
|
|
70
|
+
rangePlaceholder: "dd/mm/yyyy \u2013 dd/mm/yyyy",
|
|
71
|
+
clearDates: "Clear dates",
|
|
72
|
+
chooseStart: "Choose the start date",
|
|
73
|
+
chooseEnd: "Choose the end date"
|
|
74
|
+
},
|
|
75
|
+
sv: {
|
|
76
|
+
prevYears: "Tidigare \xE5r",
|
|
77
|
+
nextYears: "Senare \xE5r",
|
|
78
|
+
prevMonth: "F\xF6reg\xE5ende m\xE5nad",
|
|
79
|
+
nextMonth: "N\xE4sta m\xE5nad",
|
|
80
|
+
today: "Idag",
|
|
81
|
+
clear: "Rensa",
|
|
82
|
+
chooseDate: "V\xE4lj datum",
|
|
83
|
+
datePlaceholder: "\xE5\xE5\xE5\xE5-mm-dd",
|
|
84
|
+
clearDate: "Rensa datum",
|
|
85
|
+
openCalendar: "\xD6ppna kalendern",
|
|
86
|
+
chooseDates: "V\xE4lj datum",
|
|
87
|
+
rangePlaceholder: "\xE5\xE5\xE5\xE5-mm-dd \u2013 \xE5\xE5\xE5\xE5-mm-dd",
|
|
88
|
+
clearDates: "Rensa datumen",
|
|
89
|
+
chooseStart: "V\xE4lj startdatum",
|
|
90
|
+
chooseEnd: "V\xE4lj slutdatum"
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
function dateText(locale) {
|
|
94
|
+
return DATE_TEXT[locale || "th"] || DATE_TEXT.th;
|
|
34
95
|
}
|
|
35
96
|
const fmtCache = {};
|
|
36
97
|
const PRESETS = {
|
|
@@ -53,12 +114,12 @@ let MONTHS = null;
|
|
|
53
114
|
function monthIndex(word) {
|
|
54
115
|
if (!MONTHS) {
|
|
55
116
|
MONTHS = {};
|
|
56
|
-
["th-TH", "en-GB"].forEach(function(tag) {
|
|
117
|
+
["th-TH", "en-GB", "sv-SE"].forEach(function(tag) {
|
|
57
118
|
["short", "long"].forEach(function(w) {
|
|
58
119
|
for (let i = 0; i < 12; i++) {
|
|
59
120
|
const n = new Intl.DateTimeFormat(tag, { month: w }).format(new Date(2020, i, 1)).toLowerCase().replace(/\.$/, "");
|
|
60
121
|
MONTHS[n] = i;
|
|
61
|
-
if (/^[a-
|
|
122
|
+
if (/^[a-zåäö]/.test(n)) MONTHS[n.slice(0, 3)] = i;
|
|
62
123
|
}
|
|
63
124
|
});
|
|
64
125
|
});
|
|
@@ -87,8 +148,8 @@ function parseDate(text) {
|
|
|
87
148
|
return dt.getMonth() === mo - 1 && dt.getDate() === d ? toISO(dt) : null;
|
|
88
149
|
}
|
|
89
150
|
const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
90
|
-
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar ||
|
|
91
|
-
const weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
|
|
151
|
+
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || defaultCalendar(locale), tag = localeTag(locale, calendar);
|
|
152
|
+
const weekStart = props.weekStartsOn == null ? locale === "sv" ? 1 : 0 : props.weekStartsOn;
|
|
92
153
|
let today = /* @__PURE__ */ new Date();
|
|
93
154
|
today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
94
155
|
const min = fromISO(props.min), max = fromISO(props.max);
|
|
@@ -98,7 +159,8 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
98
159
|
const viewState = React.useState("days"), view = viewState[0], setView = viewState[1];
|
|
99
160
|
const hoverState = React.useState(null);
|
|
100
161
|
const gridRef = React.useRef(null), gridMerged = useMergedRef(ref, gridRef), moved = React.useRef(false);
|
|
101
|
-
const th = locale
|
|
162
|
+
const th = locale === "th";
|
|
163
|
+
const dt = dateText(locale);
|
|
102
164
|
function disabled(d) {
|
|
103
165
|
return !!(min && d < min || max && d > max || props.isDateDisabled && props.isDateDisabled(toISO(d)));
|
|
104
166
|
}
|
|
@@ -164,7 +226,7 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
164
226
|
IconButton,
|
|
165
227
|
{
|
|
166
228
|
icon: "chevron-left",
|
|
167
|
-
label:
|
|
229
|
+
label: dt.prevYears,
|
|
168
230
|
onClick: function() {
|
|
169
231
|
setFocus(new Date(yr - 12, focusDate.getMonth(), 1));
|
|
170
232
|
}
|
|
@@ -183,7 +245,7 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
183
245
|
IconButton,
|
|
184
246
|
{
|
|
185
247
|
icon: "chevron-right",
|
|
186
|
-
label:
|
|
248
|
+
label: dt.nextYears,
|
|
187
249
|
onClick: function() {
|
|
188
250
|
setFocus(new Date(yr + 12, focusDate.getMonth(), 1));
|
|
189
251
|
}
|
|
@@ -211,7 +273,7 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
211
273
|
IconButton,
|
|
212
274
|
{
|
|
213
275
|
icon: "chevron-left",
|
|
214
|
-
label:
|
|
276
|
+
label: dt.prevMonth,
|
|
215
277
|
onClick: function() {
|
|
216
278
|
setFocus(addMonths(focusDate, -1));
|
|
217
279
|
}
|
|
@@ -232,7 +294,7 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
232
294
|
IconButton,
|
|
233
295
|
{
|
|
234
296
|
icon: "chevron-right",
|
|
235
|
-
label:
|
|
297
|
+
label: dt.nextMonth,
|
|
236
298
|
onClick: function() {
|
|
237
299
|
setFocus(addMonths(focusDate, 1));
|
|
238
300
|
}
|
|
@@ -306,8 +368,8 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
306
368
|
props.onSelect(toISO(today));
|
|
307
369
|
}
|
|
308
370
|
},
|
|
309
|
-
|
|
310
|
-
), props.onClear ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "aura-cal__link", onClick: props.onClear },
|
|
371
|
+
dt.today
|
|
372
|
+
), props.onClear ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "aura-cal__link", onClick: props.onClear }, dt.clear) : null));
|
|
311
373
|
});
|
|
312
374
|
function useCalendarPopover(boxRef) {
|
|
313
375
|
const openState = React.useState(false), open = openState[0], setOpen = openState[1];
|
|
@@ -429,7 +491,7 @@ function DateField(props) {
|
|
|
429
491
|
}
|
|
430
492
|
const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
431
493
|
const auto = uid(), id = props.id || auto, dialogId = id + "-cal";
|
|
432
|
-
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar ||
|
|
494
|
+
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || defaultCalendar(locale), dt = dateText(locale);
|
|
433
495
|
const st = useMaybeControlled(
|
|
434
496
|
props.value,
|
|
435
497
|
props.defaultValue == null ? null : props.defaultValue,
|
|
@@ -457,7 +519,7 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
|
457
519
|
id: dialogId,
|
|
458
520
|
role: "dialog",
|
|
459
521
|
"aria-modal": false,
|
|
460
|
-
"aria-label": props.label ||
|
|
522
|
+
"aria-label": props.label || dt.chooseDate,
|
|
461
523
|
className: "aura-cal__popover",
|
|
462
524
|
style: pop.pos,
|
|
463
525
|
onKeyDown: function(e) {
|
|
@@ -504,15 +566,15 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
|
504
566
|
inputRef: inputMerged,
|
|
505
567
|
open: pop.open,
|
|
506
568
|
display: formatDate(st[0], { locale, calendar }),
|
|
507
|
-
placeholder: props.placeholder ||
|
|
569
|
+
placeholder: props.placeholder || dt.datePlaceholder,
|
|
508
570
|
hasValue: st[0] != null,
|
|
509
571
|
clearable: props.clearable,
|
|
510
572
|
onClear: function() {
|
|
511
573
|
st[1](null);
|
|
512
574
|
inputRef.current && inputRef.current.focus();
|
|
513
575
|
},
|
|
514
|
-
clearLabel:
|
|
515
|
-
toggleLabel:
|
|
576
|
+
clearLabel: dt.clearDate,
|
|
577
|
+
toggleLabel: dt.openCalendar,
|
|
516
578
|
onCommit: commit,
|
|
517
579
|
onToggle: function(o) {
|
|
518
580
|
pop.setOpen(o);
|
|
@@ -524,7 +586,7 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
|
524
586
|
const DateRangePicker = React.forwardRef(
|
|
525
587
|
function DateRangePicker2(props, ref) {
|
|
526
588
|
const auto = uid(), id = props.id || auto, dialogId = id + "-cal";
|
|
527
|
-
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar ||
|
|
589
|
+
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || defaultCalendar(locale), dt = dateText(locale);
|
|
528
590
|
const st = useMaybeControlled(
|
|
529
591
|
props.value,
|
|
530
592
|
props.defaultValue || { start: null, end: null },
|
|
@@ -571,7 +633,7 @@ const DateRangePicker = React.forwardRef(
|
|
|
571
633
|
id: dialogId,
|
|
572
634
|
role: "dialog",
|
|
573
635
|
"aria-modal": false,
|
|
574
|
-
"aria-label": props.label ||
|
|
636
|
+
"aria-label": props.label || dt.chooseDates,
|
|
575
637
|
className: "aura-cal__popover",
|
|
576
638
|
style: pop.pos,
|
|
577
639
|
onKeyDown: function(e) {
|
|
@@ -581,7 +643,7 @@ const DateRangePicker = React.forwardRef(
|
|
|
581
643
|
} else trapTab(e, pop.popRef.current);
|
|
582
644
|
}
|
|
583
645
|
},
|
|
584
|
-
/* @__PURE__ */ React.createElement("p", { className: "aura-cal__hint", "aria-live": "polite" }, draft[0] ?
|
|
646
|
+
/* @__PURE__ */ React.createElement("p", { className: "aura-cal__hint", "aria-live": "polite" }, draft[0] ? dt.chooseEnd : dt.chooseStart),
|
|
585
647
|
/* @__PURE__ */ React.createElement(
|
|
586
648
|
Calendar,
|
|
587
649
|
{
|
|
@@ -618,15 +680,15 @@ const DateRangePicker = React.forwardRef(
|
|
|
618
680
|
inputRef: inputMerged,
|
|
619
681
|
open: pop.open,
|
|
620
682
|
display: show(v),
|
|
621
|
-
placeholder: props.placeholder ||
|
|
683
|
+
placeholder: props.placeholder || dt.rangePlaceholder,
|
|
622
684
|
hasValue: v.start != null,
|
|
623
685
|
clearable: props.clearable,
|
|
624
686
|
onClear: function() {
|
|
625
687
|
st[1]({ start: null, end: null });
|
|
626
688
|
inputRef.current && inputRef.current.focus();
|
|
627
689
|
},
|
|
628
|
-
clearLabel:
|
|
629
|
-
toggleLabel:
|
|
690
|
+
clearLabel: dt.clearDates,
|
|
691
|
+
toggleLabel: dt.openCalendar,
|
|
630
692
|
onCommit: commit,
|
|
631
693
|
onToggle: function(op) {
|
|
632
694
|
pop.setOpen(op);
|
package/dist/esm/Icon.js
CHANGED
|
@@ -5,9 +5,20 @@ const h = React.createElement;
|
|
|
5
5
|
const ICONS = { "check": [["path", { "d": "M20 6 9 17l-5-5" }]], "x": [["path", { "d": "M18 6 6 18" }], ["path", { "d": "m6 6 12 12" }]], "plus": [["path", { "d": "M5 12h14" }], ["path", { "d": "M12 5v14" }]], "minus": [["path", { "d": "M5 12h14" }]], "search": [["path", { "d": "m21 21-4.34-4.34" }], ["circle", { "cx": "11", "cy": "11", "r": "8" }]], "chevron-down": [["path", { "d": "m6 9 6 6 6-6" }]], "chevron-up": [["path", { "d": "m18 15-6-6-6 6" }]], "chevron-left": [["path", { "d": "m15 18-6-6 6-6" }]], "chevron-right": [["path", { "d": "m9 18 6-6-6-6" }]], "arrow-right": [["path", { "d": "M5 12h14" }], ["path", { "d": "m12 5 7 7-7 7" }]], "arrow-up-right": [["path", { "d": "M7 7h10v10" }], ["path", { "d": "M7 17 17 7" }]], "arrow-up-down": [["path", { "d": "m21 16-4 4-4-4" }], ["path", { "d": "M17 20V4" }], ["path", { "d": "m3 8 4-4 4 4" }], ["path", { "d": "M7 4v16" }]], "loader-circle": [["path", { "d": "M21 12a9 9 0 1 1-6.219-8.56" }]], "circle-alert": [["circle", { "cx": "12", "cy": "12", "r": "10" }], ["line", { "x1": "12", "x2": "12", "y1": "8", "y2": "12" }], ["line", { "x1": "12", "x2": "12.01", "y1": "16", "y2": "16" }]], "circle-check": [["circle", { "cx": "12", "cy": "12", "r": "10" }], ["path", { "d": "m16 9-5.5 5.5L8 12" }]], "info": [["circle", { "cx": "12", "cy": "12", "r": "10" }], ["path", { "d": "M12 16v-4" }], ["path", { "d": "M12 8h.01" }]], "triangle-alert": [["path", { "d": "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" }], ["path", { "d": "M12 9v4" }], ["path", { "d": "M12 17h.01" }]], "settings": [["path", { "d": "M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" }], ["circle", { "cx": "12", "cy": "12", "r": "3" }]], "user": [["path", { "d": "M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" }], ["circle", { "cx": "12", "cy": "7", "r": "4" }]], "users": [["path", { "d": "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" }], ["path", { "d": "M16 3.128a4 4 0 0 1 0 7.744" }], ["path", { "d": "M22 21v-2a4 4 0 0 0-3-3.87" }], ["circle", { "cx": "9", "cy": "7", "r": "4" }]], "filter": [["path", { "d": "M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z" }]], "ellipsis": [["circle", { "cx": "12", "cy": "12", "r": "1" }], ["circle", { "cx": "19", "cy": "12", "r": "1" }], ["circle", { "cx": "5", "cy": "12", "r": "1" }]], "external-link": [["path", { "d": "M15 3h6v6" }], ["path", { "d": "M10 14 21 3" }], ["path", { "d": "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }]], "copy": [["rect", { "width": "14", "height": "14", "x": "8", "y": "8", "rx": "2", "ry": "2" }], ["path", { "d": "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" }]], "trash-2": [["path", { "d": "M10 11v6" }], ["path", { "d": "M14 11v6" }], ["path", { "d": "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" }], ["path", { "d": "M3 6h18" }], ["path", { "d": "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" }]], "pencil": [["path", { "d": "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" }], ["path", { "d": "m15 5 4 4" }]], "download": [["path", { "d": "M12 15V3" }], ["path", { "d": "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }], ["path", { "d": "m7 10 5 5 5-5" }]], "upload": [["path", { "d": "M12 3v12" }], ["path", { "d": "m17 8-5-5-5 5" }], ["path", { "d": "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }]], "calendar": [["path", { "d": "M8 2v3" }], ["path", { "d": "M16 2v3" }], ["rect", { "x": "3", "y": "3", "width": "18", "height": "18", "rx": "2" }], ["path", { "d": "M3 9h18" }]], "bell": [["path", { "d": "M10.268 21a2 2 0 0 0 3.464 0" }], ["path", { "d": "M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326" }]], "menu": [["path", { "d": "M4 5h16" }], ["path", { "d": "M4 12h16" }], ["path", { "d": "M4 19h16" }]], "eye": [["path", { "d": "M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0" }], ["circle", { "cx": "12", "cy": "12", "r": "3" }]], "log-out": [["path", { "d": "m16 17 5-5-5-5" }], ["path", { "d": "M21 12H9" }], ["path", { "d": "M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" }]], "circle": [["circle", { "cx": "12", "cy": "12", "r": "10" }]], "circle-dot-dashed": [["path", { "d": "M10.1 2.18a9.93 9.93 0 0 1 3.8 0" }], ["path", { "d": "M17.6 3.71a9.95 9.95 0 0 1 2.69 2.7" }], ["path", { "d": "M21.82 10.1a9.93 9.93 0 0 1 0 3.8" }], ["path", { "d": "M20.29 17.6a9.95 9.95 0 0 1-2.7 2.69" }], ["path", { "d": "M13.9 21.82a9.94 9.94 0 0 1-3.8 0" }], ["path", { "d": "M6.4 20.29a9.95 9.95 0 0 1-2.69-2.7" }], ["path", { "d": "M2.18 13.9a9.93 9.93 0 0 1 0-3.8" }], ["path", { "d": "M3.71 6.4a9.95 9.95 0 0 1 2.7-2.69" }], ["circle", { "cx": "12", "cy": "12", "r": "1" }]], "ban": [["circle", { "cx": "12", "cy": "12", "r": "10" }], ["path", { "d": "M4.929 4.929 19.07 19.071" }]], "arrow-up": [["path", { "d": "m5 12 7-7 7 7" }], ["path", { "d": "M12 19V5" }]], "arrow-down": [["path", { "d": "M12 5v14" }], ["path", { "d": "m19 12-7 7-7-7" }]], "inbox": [["polyline", { "points": "22 12 16 12 14 15 10 15 8 12 2 12" }], ["path", { "d": "M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" }]], "pin": [["path", { "d": "M12 17v5" }], ["path", { "d": "M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z" }]], "pin-off": [["path", { "d": "M12 17v5" }], ["path", { "d": "M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89" }], ["path", { "d": "m2 2 20 20" }], ["path", { "d": "M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11" }]], "eye-off": [["path", { "d": "M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49" }], ["path", { "d": "M14.084 14.158a3 3 0 0 1-4.242-4.242" }], ["path", { "d": "M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143" }], ["path", { "d": "m2 2 20 20" }]], "columns-3": [["rect", { "width": "18", "height": "18", "x": "3", "y": "3", "rx": "2" }], ["path", { "d": "M9 3v18" }], ["path", { "d": "M15 3v18" }]], "arrow-left": [["path", { "d": "m12 19-7-7 7-7" }], ["path", { "d": "M19 12H5" }]], "rotate-ccw": [["path", { "d": "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }], ["path", { "d": "M3 3v5h5" }]], "house": [["path", { "d": "M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8" }], ["path", { "d": "M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" }]], "layout-dashboard": [["rect", { "width": "7", "height": "9", "x": "3", "y": "3", "rx": "1" }], ["rect", { "width": "7", "height": "5", "x": "14", "y": "3", "rx": "1" }], ["rect", { "width": "7", "height": "9", "x": "14", "y": "12", "rx": "1" }], ["rect", { "width": "7", "height": "5", "x": "3", "y": "16", "rx": "1" }]], "folder": [["path", { "d": "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" }]], "chart-column": [["path", { "d": "M3 3v16a2 2 0 0 0 2 2h16" }], ["path", { "d": "M18 17V9" }], ["path", { "d": "M13 17V5" }], ["path", { "d": "M8 17v-3" }]], "file-text": [["path", { "d": "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" }], ["path", { "d": "M14 2v5a1 1 0 0 0 1 1h5" }], ["path", { "d": "M10 9H8" }], ["path", { "d": "M16 13H8" }], ["path", { "d": "M16 17H8" }]], "mail": [["path", { "d": "m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7" }], ["rect", { "x": "2", "y": "4", "width": "20", "height": "16", "rx": "2" }]], "lock": [["rect", { "width": "18", "height": "11", "x": "3", "y": "11", "rx": "2", "ry": "2" }], ["path", { "d": "M7 11V7a5 5 0 0 1 10 0v4" }]], "clock": [["circle", { "cx": "12", "cy": "12", "r": "10" }], ["path", { "d": "M12 6v6l4 2" }]], "trending-up": [["path", { "d": "M16 7h6v6" }], ["path", { "d": "m22 7-8.5 8.5-5-5L2 17" }]], "trending-down": [["path", { "d": "M16 17h6v-6" }], ["path", { "d": "m22 17-8.5-8.5-5 5L2 7" }]], "image": [["rect", { "width": "18", "height": "18", "x": "3", "y": "3", "rx": "2", "ry": "2" }], ["circle", { "cx": "9", "cy": "9", "r": "2" }], ["path", { "d": "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" }]], "paperclip": [["path", { "d": "m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551" }]], "cloud-upload": [["path", { "d": "M12 13v8" }], ["path", { "d": "M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242" }], ["path", { "d": "m8 17 4-4 4 4" }]], "file": [["path", { "d": "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z" }], ["path", { "d": "M14 2v5a1 1 0 0 0 1 1h5" }]], "sun": [["circle", { "cx": "12", "cy": "12", "r": "4" }], ["path", { "d": "M12 2v2" }], ["path", { "d": "M12 20v2" }], ["path", { "d": "m4.93 4.93 1.41 1.41" }], ["path", { "d": "m17.66 17.66 1.41 1.41" }], ["path", { "d": "M2 12h2" }], ["path", { "d": "M20 12h2" }], ["path", { "d": "m6.34 17.66-1.41 1.41" }], ["path", { "d": "m19.07 4.93-1.41 1.41" }]], "moon": [["path", { "d": "M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401" }]], "monitor": [["rect", { "width": "20", "height": "14", "x": "2", "y": "3", "rx": "2" }], ["line", { "x1": "8", "x2": "16", "y1": "21", "y2": "21" }], ["line", { "x1": "12", "x2": "12", "y1": "17", "y2": "21" }]] };
|
|
6
6
|
const SIZES = { sm: 16, md: 20, lg: 24 };
|
|
7
7
|
const Icon = React.forwardRef(function Icon2(props, ref) {
|
|
8
|
+
const size = SIZES[props.size] || props.size || 16;
|
|
9
|
+
if (React.isValidElement(props.name)) {
|
|
10
|
+
return /* @__PURE__ */ React.createElement(
|
|
11
|
+
"span",
|
|
12
|
+
{
|
|
13
|
+
className: cx("aura-icon", "aura-icon--custom", props.className),
|
|
14
|
+
style: { width: size, height: size, ["--aura-icon-stroke"]: props.strokeWidth || 2 },
|
|
15
|
+
...props.label ? { role: "img", "aria-label": props.label } : { "aria-hidden": true }
|
|
16
|
+
},
|
|
17
|
+
props.name
|
|
18
|
+
);
|
|
19
|
+
}
|
|
8
20
|
const shapes = ICONS[props.name];
|
|
9
21
|
if (!shapes) return null;
|
|
10
|
-
const size = SIZES[props.size] || props.size || 16;
|
|
11
22
|
const a11y = props.label ? { role: "img", "aria-label": props.label } : { "aria-hidden": true, focusable: "false" };
|
|
12
23
|
return /* @__PURE__ */ React.createElement(
|
|
13
24
|
"svg",
|
package/dist/esm/IconButton.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { cx, omit } from "./internal.js";
|
|
4
4
|
import { Icon } from "./Icon.js";
|
|
5
5
|
const IconButton = React.forwardRef(function IconButton2(props, ref) {
|
|
6
|
-
const rest = omit(props, ["icon", "label", "className", "size"]);
|
|
6
|
+
const rest = omit(props, ["icon", "label", "className", "size", "tone"]);
|
|
7
7
|
return /* @__PURE__ */ React.createElement(
|
|
8
8
|
"button",
|
|
9
9
|
{
|
|
@@ -12,7 +12,7 @@ const IconButton = React.forwardRef(function IconButton2(props, ref) {
|
|
|
12
12
|
type: props.type || "button",
|
|
13
13
|
"aria-label": props.label,
|
|
14
14
|
title: props.label,
|
|
15
|
-
className: cx("aura-icon-btn", props.className)
|
|
15
|
+
className: cx("aura-icon-btn", props.tone === "danger" && "aura-icon-btn--danger", props.className)
|
|
16
16
|
},
|
|
17
17
|
/* @__PURE__ */ React.createElement(Icon, { name: props.icon, size: props.size || "sm" })
|
|
18
18
|
);
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Field, describedBy } from "./Field.js";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
import { cx, uid, useMaybeControlled } from "./internal.js";
|
|
6
|
+
import { useStrings } from "./locale.js";
|
|
7
|
+
function decimalsOf(n) {
|
|
8
|
+
const s = String(n);
|
|
9
|
+
const i = s.indexOf(".");
|
|
10
|
+
return i < 0 ? 0 : s.length - i - 1;
|
|
11
|
+
}
|
|
12
|
+
function parse(text) {
|
|
13
|
+
const s = text.replace(/[,\s ]/g, "");
|
|
14
|
+
if (!/^-?(\d+\.?\d*|\.\d+)$/.test(s)) return NaN;
|
|
15
|
+
return Number(s);
|
|
16
|
+
}
|
|
17
|
+
const NumberField = React.forwardRef(function NumberField2(props, ref) {
|
|
18
|
+
const t = useStrings();
|
|
19
|
+
const auto = uid(), id = props.id || auto;
|
|
20
|
+
const step = props.step || 1;
|
|
21
|
+
const decimals = props.decimals != null ? props.decimals : decimalsOf(step);
|
|
22
|
+
const st = useMaybeControlled(
|
|
23
|
+
props.value,
|
|
24
|
+
props.defaultValue == null ? null : props.defaultValue,
|
|
25
|
+
props.onChange
|
|
26
|
+
);
|
|
27
|
+
const value = st[0], setValue = st[1];
|
|
28
|
+
const draftState = React.useState(null), draft = draftState[0], setDraft = draftState[1];
|
|
29
|
+
function fmt(n) {
|
|
30
|
+
if (n == null || isNaN(n)) return "";
|
|
31
|
+
return n.toLocaleString("en", { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
|
|
32
|
+
}
|
|
33
|
+
function fit(n) {
|
|
34
|
+
let v = n;
|
|
35
|
+
if (props.min != null && v < props.min) v = props.min;
|
|
36
|
+
if (props.max != null && v > props.max) v = props.max;
|
|
37
|
+
const f = Math.pow(10, decimals);
|
|
38
|
+
return Math.round(v * f) / f;
|
|
39
|
+
}
|
|
40
|
+
function nudge(by) {
|
|
41
|
+
if (props.disabled || props.readOnly) return;
|
|
42
|
+
const base = value == null ? props.min != null && props.min > 0 ? props.min - by : 0 : value;
|
|
43
|
+
const next = fit(base + by);
|
|
44
|
+
setValue(next);
|
|
45
|
+
setDraft(null);
|
|
46
|
+
}
|
|
47
|
+
function onKeyDown(e) {
|
|
48
|
+
const k = e.key;
|
|
49
|
+
let by = 0;
|
|
50
|
+
if (k === "ArrowUp") by = step;
|
|
51
|
+
else if (k === "ArrowDown") by = -step;
|
|
52
|
+
else if (k === "PageUp") by = step * 10;
|
|
53
|
+
else if (k === "PageDown") by = -step * 10;
|
|
54
|
+
else if (k === "Home" && props.min != null) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
setValue(props.min);
|
|
57
|
+
setDraft(null);
|
|
58
|
+
return;
|
|
59
|
+
} else if (k === "End" && props.max != null) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
setValue(props.max);
|
|
62
|
+
setDraft(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (by) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
nudge(by);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const atMin = value != null && props.min != null && value <= props.min;
|
|
71
|
+
const atMax = value != null && props.max != null && value >= props.max;
|
|
72
|
+
const affixText = function(x) {
|
|
73
|
+
return typeof x === "string" || typeof x === "number" ? String(x) : "";
|
|
74
|
+
};
|
|
75
|
+
const valueText = value == null ? void 0 : [affixText(props.prefix), fmt(value), affixText(props.suffix)].join(" ").trim();
|
|
76
|
+
const stepper = props.stepper !== false && !props.readOnly;
|
|
77
|
+
return /* @__PURE__ */ React.createElement(
|
|
78
|
+
Field,
|
|
79
|
+
{
|
|
80
|
+
id,
|
|
81
|
+
label: props.label,
|
|
82
|
+
hint: props.hint,
|
|
83
|
+
error: props.error,
|
|
84
|
+
required: props.required,
|
|
85
|
+
optional: props.optional,
|
|
86
|
+
disabled: props.disabled,
|
|
87
|
+
className: props.className
|
|
88
|
+
},
|
|
89
|
+
/* @__PURE__ */ React.createElement("div", { className: cx("aura-input aura-number", stepper && "has-stepper") }, props.prefix != null ? /* @__PURE__ */ React.createElement("span", { className: "aura-number__affix", "aria-hidden": true }, props.prefix) : null, /* @__PURE__ */ React.createElement(
|
|
90
|
+
"input",
|
|
91
|
+
{
|
|
92
|
+
ref,
|
|
93
|
+
id,
|
|
94
|
+
type: "text",
|
|
95
|
+
role: "spinbutton",
|
|
96
|
+
inputMode: decimals > 0 || props.min != null && props.min < 0 ? "decimal" : "numeric",
|
|
97
|
+
autoComplete: "off",
|
|
98
|
+
className: "aura-input__control",
|
|
99
|
+
name: props.name,
|
|
100
|
+
placeholder: props.placeholder,
|
|
101
|
+
disabled: props.disabled,
|
|
102
|
+
readOnly: props.readOnly,
|
|
103
|
+
required: props.required,
|
|
104
|
+
"aria-valuenow": value == null ? void 0 : value,
|
|
105
|
+
"aria-valuemin": props.min,
|
|
106
|
+
"aria-valuemax": props.max,
|
|
107
|
+
"aria-valuetext": valueText,
|
|
108
|
+
"aria-invalid": props.error ? true : void 0,
|
|
109
|
+
"aria-describedby": describedBy(id, props),
|
|
110
|
+
value: draft != null ? draft : fmt(value),
|
|
111
|
+
onFocus: function() {
|
|
112
|
+
setDraft(fmt(value));
|
|
113
|
+
},
|
|
114
|
+
onChange: function(e) {
|
|
115
|
+
const text = e.target.value;
|
|
116
|
+
setDraft(text);
|
|
117
|
+
if (!text.trim()) setValue(null);
|
|
118
|
+
else {
|
|
119
|
+
const n = parse(text);
|
|
120
|
+
if (!isNaN(n)) setValue(n);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onBlur: function(e) {
|
|
124
|
+
const n = draft == null ? value : !draft.trim() ? null : parse(draft);
|
|
125
|
+
if (n == null) {
|
|
126
|
+
if (value != null) setValue(null);
|
|
127
|
+
} else if (!isNaN(n)) {
|
|
128
|
+
const f = fit(n);
|
|
129
|
+
if (f !== value) setValue(f);
|
|
130
|
+
}
|
|
131
|
+
setDraft(null);
|
|
132
|
+
if (props.onBlur) props.onBlur(e);
|
|
133
|
+
},
|
|
134
|
+
onKeyDown
|
|
135
|
+
}
|
|
136
|
+
), props.suffix != null ? /* @__PURE__ */ React.createElement("span", { className: "aura-number__affix", "aria-hidden": true }, props.suffix) : null, stepper ? /* @__PURE__ */ React.createElement("span", { className: "aura-number__steps" }, /* @__PURE__ */ React.createElement(
|
|
137
|
+
"button",
|
|
138
|
+
{
|
|
139
|
+
type: "button",
|
|
140
|
+
tabIndex: -1,
|
|
141
|
+
className: "aura-number__step",
|
|
142
|
+
"aria-label": t.decrease,
|
|
143
|
+
"aria-controls": id,
|
|
144
|
+
disabled: props.disabled || atMin,
|
|
145
|
+
onPointerDown: function(e) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
},
|
|
148
|
+
onClick: function() {
|
|
149
|
+
nudge(-step);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "minus" })
|
|
153
|
+
), /* @__PURE__ */ React.createElement(
|
|
154
|
+
"button",
|
|
155
|
+
{
|
|
156
|
+
type: "button",
|
|
157
|
+
tabIndex: -1,
|
|
158
|
+
className: "aura-number__step",
|
|
159
|
+
"aria-label": t.increase,
|
|
160
|
+
"aria-controls": id,
|
|
161
|
+
disabled: props.disabled || atMax,
|
|
162
|
+
onPointerDown: function(e) {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
},
|
|
165
|
+
onClick: function() {
|
|
166
|
+
nudge(step);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "plus" })
|
|
170
|
+
)) : null)
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
export {
|
|
174
|
+
NumberField
|
|
175
|
+
};
|
package/dist/esm/Pagination.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { IconButton } from "./IconButton.js";
|
|
4
4
|
import { cx, useMaybeControlled } from "./internal.js";
|
|
5
|
-
import { useStrings } from "./locale.js";
|
|
5
|
+
import { useLinkComponent, useStrings } from "./locale.js";
|
|
6
6
|
function pageList(page, count, sib) {
|
|
7
7
|
let out = [], lo = Math.max(2, page - sib), hi = Math.min(count - 1, page + sib);
|
|
8
8
|
if (page - sib <= 3) {
|
|
@@ -31,6 +31,7 @@ const Pagination = React.forwardRef(function Pagination2(props, ref) {
|
|
|
31
31
|
if (p >= 1 && p <= count && p !== page) st[1](p);
|
|
32
32
|
}
|
|
33
33
|
const link = props.getHref;
|
|
34
|
+
const Link = useLinkComponent();
|
|
34
35
|
function item(p, label, extra) {
|
|
35
36
|
const common = Object.assign(
|
|
36
37
|
{
|
|
@@ -41,7 +42,7 @@ const Pagination = React.forwardRef(function Pagination2(props, ref) {
|
|
|
41
42
|
extra
|
|
42
43
|
);
|
|
43
44
|
return link ? /* @__PURE__ */ React.createElement(
|
|
44
|
-
|
|
45
|
+
Link,
|
|
45
46
|
{
|
|
46
47
|
href: link(p),
|
|
47
48
|
onClick: function(e) {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { cx, uid, useMaybeControlled } from "./internal.js";
|
|
5
|
+
function toOpt(o) {
|
|
6
|
+
return typeof o === "object" ? o : { value: o, label: o };
|
|
7
|
+
}
|
|
8
|
+
const SegmentedControl = React.forwardRef(
|
|
9
|
+
function SegmentedControl2(props, ref) {
|
|
10
|
+
const options = (props.options || []).map(toOpt);
|
|
11
|
+
const firstEnabled = options.filter(function(o) {
|
|
12
|
+
return !o.disabled;
|
|
13
|
+
})[0];
|
|
14
|
+
const st = useMaybeControlled(
|
|
15
|
+
props.value,
|
|
16
|
+
props.defaultValue != null ? props.defaultValue : firstEnabled ? firstEnabled.value : void 0,
|
|
17
|
+
props.onChange
|
|
18
|
+
);
|
|
19
|
+
const value = st[0], setValue = st[1];
|
|
20
|
+
const auto = uid(), id = props.id || auto;
|
|
21
|
+
const refs = React.useRef([]);
|
|
22
|
+
const selIdx = options.findIndex(function(o) {
|
|
23
|
+
return o.value === value;
|
|
24
|
+
});
|
|
25
|
+
const tabIdx = selIdx >= 0 && !options[selIdx].disabled ? selIdx : options.indexOf(firstEnabled);
|
|
26
|
+
function move(from, dir) {
|
|
27
|
+
const n = options.length;
|
|
28
|
+
for (let k = 1; k <= n; k++) {
|
|
29
|
+
const i = ((from + dir * k) % n + n) % n;
|
|
30
|
+
if (!options[i].disabled) {
|
|
31
|
+
setValue(options[i].value);
|
|
32
|
+
const el = refs.current[i];
|
|
33
|
+
if (el) el.focus();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function onKeyDown(e, i) {
|
|
39
|
+
const k = e.key;
|
|
40
|
+
if (k === "ArrowRight" || k === "ArrowDown") {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
move(i, 1);
|
|
43
|
+
} else if (k === "ArrowLeft" || k === "ArrowUp") {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
move(i, -1);
|
|
46
|
+
} else if (k === "Home") {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
move(-1, 1);
|
|
49
|
+
} else if (k === "End") {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
move(options.length, -1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return /* @__PURE__ */ React.createElement(
|
|
55
|
+
"div",
|
|
56
|
+
{
|
|
57
|
+
ref,
|
|
58
|
+
id,
|
|
59
|
+
role: "radiogroup",
|
|
60
|
+
"aria-label": props.label,
|
|
61
|
+
"aria-disabled": props.disabled || void 0,
|
|
62
|
+
className: cx(
|
|
63
|
+
"aura-segmented",
|
|
64
|
+
props.size === "sm" && "aura-segmented--sm",
|
|
65
|
+
props.fullWidth && "is-full",
|
|
66
|
+
props.disabled && "is-disabled",
|
|
67
|
+
props.className
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
options.map(function(o, i) {
|
|
71
|
+
const on = o.value === value;
|
|
72
|
+
const off = props.disabled || o.disabled;
|
|
73
|
+
return /* @__PURE__ */ React.createElement(
|
|
74
|
+
"button",
|
|
75
|
+
{
|
|
76
|
+
key: o.value,
|
|
77
|
+
ref: function(el) {
|
|
78
|
+
refs.current[i] = el;
|
|
79
|
+
},
|
|
80
|
+
type: "button",
|
|
81
|
+
role: "radio",
|
|
82
|
+
"aria-checked": on,
|
|
83
|
+
"aria-label": o.iconOnly ? o.label : void 0,
|
|
84
|
+
title: o.iconOnly ? o.label : void 0,
|
|
85
|
+
tabIndex: i === tabIdx && !props.disabled ? 0 : -1,
|
|
86
|
+
disabled: off,
|
|
87
|
+
className: cx("aura-segmented__option", on && "is-selected", o.iconOnly && "is-icon"),
|
|
88
|
+
onClick: function() {
|
|
89
|
+
setValue(o.value);
|
|
90
|
+
},
|
|
91
|
+
onKeyDown: function(e) {
|
|
92
|
+
onKeyDown(e, i);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
o.icon ? /* @__PURE__ */ React.createElement(Icon, { name: o.icon }) : null,
|
|
96
|
+
o.iconOnly ? null : /* @__PURE__ */ React.createElement("span", null, o.label)
|
|
97
|
+
);
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
export {
|
|
103
|
+
SegmentedControl
|
|
104
|
+
};
|