@jirawatpyk/aura-react 4.5.0 → 4.6.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 +19 -4
- package/dist/aura.bundle.js +2644 -2043
- package/dist/cjs/index.cjs +2642 -2043
- package/dist/esm/Button.js +9 -9
- package/dist/esm/Checkbox.js +41 -33
- package/dist/esm/Combobox.js +143 -125
- package/dist/esm/DataTable.js +629 -495
- package/dist/esm/DatePicker.js +378 -305
- package/dist/esm/Dialog.js +48 -59
- package/dist/esm/DropdownMenu.js +9 -12
- package/dist/esm/FileUpload.js +91 -73
- package/dist/esm/Icon.js +27 -22
- package/dist/esm/IconButton.js +13 -9
- package/dist/esm/Menu.js +78 -66
- package/dist/esm/Stat.js +9 -26
- package/dist/esm/StatusPill.js +12 -13
- package/dist/esm/Surface.js +17 -13
- package/dist/esm/ThemeStyle.js +9 -5
- package/dist/esm/TimePicker.js +155 -127
- package/dist/esm/colorScheme.js +106 -0
- package/dist/esm/extra.js +270 -186
- package/dist/esm/feedback.js +112 -84
- package/dist/esm/forms.js +144 -113
- package/dist/esm/index.js +5 -0
- package/dist/esm/internal.js +33 -23
- package/dist/esm/layout.js +113 -128
- package/dist/esm/layout2.js +67 -45
- package/dist/esm/locale.js +23 -9
- package/dist/esm/overlay.js +21 -18
- package/dist/esm/theme.js +103 -50
- package/dist/index.d.ts +37 -7
- package/package.json +6 -3
package/dist/esm/DatePicker.js
CHANGED
|
@@ -6,9 +6,8 @@ import { cx, uid, useMaybeControlled, useMounted, useIsoLayoutEffect, trapTab, u
|
|
|
6
6
|
import { Icon } from "./Icon.js";
|
|
7
7
|
import { IconButton } from "./IconButton.js";
|
|
8
8
|
import { Field } from "./forms.js";
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
var pad = function(n) {
|
|
9
|
+
const ERA = /^พ\.ศ\.\s?|\s?(BE|พ\.ศ\.)$/g;
|
|
10
|
+
const pad = function(n) {
|
|
12
11
|
return (n < 10 ? "0" : "") + n;
|
|
13
12
|
};
|
|
14
13
|
function toISO(d) {
|
|
@@ -16,15 +15,15 @@ function toISO(d) {
|
|
|
16
15
|
}
|
|
17
16
|
function fromISO(s) {
|
|
18
17
|
if (!s) return null;
|
|
19
|
-
|
|
18
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
20
19
|
return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null;
|
|
21
20
|
}
|
|
22
21
|
function addDays(d, n) {
|
|
23
22
|
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
|
|
24
23
|
}
|
|
25
24
|
function addMonths(d, n) {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const t = new Date(d.getFullYear(), d.getMonth() + n, 1);
|
|
26
|
+
const last = new Date(t.getFullYear(), t.getMonth() + 1, 0).getDate();
|
|
28
27
|
return new Date(t.getFullYear(), t.getMonth(), Math.min(d.getDate(), last));
|
|
29
28
|
}
|
|
30
29
|
function same(a, b) {
|
|
@@ -33,39 +32,43 @@ function same(a, b) {
|
|
|
33
32
|
function localeTag(locale, calendar) {
|
|
34
33
|
return (locale === "en" ? "en-GB" : "th-TH") + "-u-ca-" + (calendar === "gregory" ? "gregory" : "buddhist");
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const fmtCache = {};
|
|
36
|
+
const PRESETS = {
|
|
37
|
+
short: { day: "numeric", month: "short", year: "numeric" },
|
|
38
|
+
long: { day: "numeric", month: "long", year: "numeric" },
|
|
39
|
+
numeric: { day: "2-digit", month: "2-digit", year: "numeric" }
|
|
40
|
+
};
|
|
38
41
|
function fmt(tag, opts, d) {
|
|
39
|
-
|
|
42
|
+
const k = tag + JSON.stringify(opts);
|
|
40
43
|
if (!fmtCache[k]) fmtCache[k] = new Intl.DateTimeFormat(tag, opts);
|
|
41
44
|
return fmtCache[k].format(d);
|
|
42
45
|
}
|
|
43
46
|
function formatDate(iso, opts) {
|
|
44
|
-
|
|
47
|
+
const o = opts || {}, d = fromISO(iso);
|
|
45
48
|
if (!d) return "";
|
|
46
|
-
|
|
49
|
+
const f = typeof o.format === "object" ? o.format : PRESETS[o.format || "short"];
|
|
47
50
|
return fmt(localeTag(o.locale, o.calendar), f, d).replace(ERA, "");
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
let MONTHS = null;
|
|
50
53
|
function monthIndex(word) {
|
|
51
54
|
if (!MONTHS) {
|
|
52
55
|
MONTHS = {};
|
|
53
56
|
["th-TH", "en-GB"].forEach(function(tag) {
|
|
54
57
|
["short", "long"].forEach(function(w) {
|
|
55
|
-
for (
|
|
56
|
-
|
|
58
|
+
for (let i = 0; i < 12; i++) {
|
|
59
|
+
const n = new Intl.DateTimeFormat(tag, { month: w }).format(new Date(2020, i, 1)).toLowerCase().replace(/\.$/, "");
|
|
57
60
|
MONTHS[n] = i;
|
|
58
61
|
if (/^[a-z]/.test(n)) MONTHS[n.slice(0, 3)] = i;
|
|
59
62
|
}
|
|
60
63
|
});
|
|
61
64
|
});
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
const k = word.toLowerCase().replace(/\.$/, "");
|
|
64
67
|
return MONTHS[k] != null ? MONTHS[k] : -1;
|
|
65
68
|
}
|
|
66
69
|
function parseDate(text) {
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
const s = String(text || "").trim();
|
|
71
|
+
let m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(s), y, mo, d;
|
|
69
72
|
if (m) {
|
|
70
73
|
y = +m[1];
|
|
71
74
|
mo = +m[2];
|
|
@@ -80,50 +83,50 @@ function parseDate(text) {
|
|
|
80
83
|
y = +m[3];
|
|
81
84
|
} else return null;
|
|
82
85
|
if (y >= 2400) y -= 543;
|
|
83
|
-
|
|
86
|
+
const dt = new Date(y, mo - 1, d);
|
|
84
87
|
return dt.getMonth() === mo - 1 && dt.getDate() === d ? toISO(dt) : null;
|
|
85
88
|
}
|
|
86
89
|
const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", tag = localeTag(locale, calendar);
|
|
91
|
+
const weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
|
|
92
|
+
let today = /* @__PURE__ */ new Date();
|
|
90
93
|
today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
const min = fromISO(props.min), max = fromISO(props.max);
|
|
95
|
+
const start = fromISO(props.start), end = fromISO(props.end);
|
|
96
|
+
const focusState = React.useState(fromISO(props.focus) || start || today);
|
|
97
|
+
const focusDate = focusState[0], setFocus = focusState[1];
|
|
98
|
+
const viewState = React.useState("days"), view = viewState[0], setView = viewState[1];
|
|
99
|
+
const hoverState = React.useState(null);
|
|
100
|
+
const gridRef = React.useRef(null), gridMerged = useMergedRef(ref, gridRef), moved = React.useRef(false);
|
|
101
|
+
const th = locale !== "en";
|
|
99
102
|
function disabled(d) {
|
|
100
103
|
return !!(min && d < min || max && d > max || props.isDateDisabled && props.isDateDisabled(toISO(d)));
|
|
101
104
|
}
|
|
102
105
|
React.useEffect(function() {
|
|
103
106
|
if (!moved.current) return;
|
|
104
107
|
moved.current = false;
|
|
105
|
-
|
|
108
|
+
const el = gridRef.current && gridRef.current.querySelector('[data-date="' + toISO(focusDate) + '"]');
|
|
106
109
|
if (el) el.focus();
|
|
107
110
|
});
|
|
108
111
|
React.useEffect(function() {
|
|
109
112
|
if (props.autoFocus === false) return;
|
|
110
|
-
|
|
113
|
+
const el = gridRef.current && gridRef.current.querySelector('[tabindex="0"]');
|
|
111
114
|
if (el) el.focus();
|
|
112
115
|
}, []);
|
|
113
116
|
function move(d) {
|
|
114
117
|
moved.current = true;
|
|
115
118
|
setFocus(d);
|
|
116
119
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
for (
|
|
122
|
-
|
|
123
|
-
for (
|
|
120
|
+
const first = new Date(focusDate.getFullYear(), focusDate.getMonth(), 1);
|
|
121
|
+
const lead = (first.getDay() - weekStart + 7) % 7;
|
|
122
|
+
const gridStart = addDays(first, -lead);
|
|
123
|
+
const days = [];
|
|
124
|
+
for (let i = 0; i < 42; i++) days.push(addDays(gridStart, i));
|
|
125
|
+
const weeks = [];
|
|
126
|
+
for (let w = 0; w < 6; w++) weeks.push(days.slice(w * 7, w * 7 + 7));
|
|
124
127
|
if (weeks[5][0].getMonth() !== focusDate.getMonth()) weeks.pop();
|
|
125
128
|
function onKey(e, d) {
|
|
126
|
-
|
|
129
|
+
let k = e.key, n = null;
|
|
127
130
|
if (k === "ArrowLeft") n = addDays(d, -1);
|
|
128
131
|
else if (k === "ArrowRight") n = addDays(d, 1);
|
|
129
132
|
else if (k === "ArrowUp") n = addDays(d, -7);
|
|
@@ -142,104 +145,127 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
142
145
|
move(n);
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
const hover = hoverState[0];
|
|
149
|
+
const rangeEnd = end || (props.range && start && hover ? hover : null);
|
|
147
150
|
function inRange(d) {
|
|
148
151
|
if (!props.range || !start || !rangeEnd) return false;
|
|
149
|
-
|
|
152
|
+
const a = start < rangeEnd ? start : rangeEnd, b = start < rangeEnd ? rangeEnd : start;
|
|
150
153
|
return d > a && d < b;
|
|
151
154
|
}
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
const monthTitle = fmt(tag, { month: "long", year: "numeric" }, focusDate).replace(ERA, "");
|
|
156
|
+
const weekdayNames = weeks[0].map(function(d) {
|
|
154
157
|
return { short: fmt(tag, { weekday: th ? "narrow" : "short" }, d), long: fmt(tag, { weekday: "long" }, d) };
|
|
155
158
|
});
|
|
156
159
|
if (view === "years") {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
for (
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
{
|
|
163
|
-
|
|
164
|
-
"
|
|
165
|
-
|
|
166
|
-
h(IconButton, { icon: "chevron-left", label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous years", onClick: function() {
|
|
160
|
+
const yr = focusDate.getFullYear(), base = yr - yr % 12;
|
|
161
|
+
const years = [];
|
|
162
|
+
for (let y = base; y < base + 12; y++) years.push(y);
|
|
163
|
+
return /* @__PURE__ */ React.createElement("div", { className: "aura-cal", ref: gridMerged }, /* @__PURE__ */ React.createElement("div", { className: "aura-cal__head" }, /* @__PURE__ */ React.createElement(
|
|
164
|
+
IconButton,
|
|
165
|
+
{
|
|
166
|
+
icon: "chevron-left",
|
|
167
|
+
label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous years",
|
|
168
|
+
onClick: function() {
|
|
167
169
|
setFocus(new Date(yr - 12, focusDate.getMonth(), 1));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
176
|
-
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
), /* @__PURE__ */ React.createElement(
|
|
173
|
+
"button",
|
|
174
|
+
{
|
|
175
|
+
type: "button",
|
|
176
|
+
className: "aura-cal__title",
|
|
177
|
+
onClick: function() {
|
|
178
|
+
setView("days");
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
fmt(tag, { year: "numeric" }, new Date(base, 0, 1)).replace(ERA, "") + " \u2013 " + fmt(tag, { year: "numeric" }, new Date(base + 11, 0, 1)).replace(ERA, "")
|
|
182
|
+
), /* @__PURE__ */ React.createElement(
|
|
183
|
+
IconButton,
|
|
184
|
+
{
|
|
185
|
+
icon: "chevron-right",
|
|
186
|
+
label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E16\u0E31\u0E14\u0E44\u0E1B" : "Next years",
|
|
187
|
+
onClick: function() {
|
|
177
188
|
setFocus(new Date(yr + 12, focusDate.getMonth(), 1));
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
)), /* @__PURE__ */ React.createElement("div", { className: "aura-cal__years" }, years.map(function(y) {
|
|
192
|
+
const d = new Date(y, focusDate.getMonth(), 1);
|
|
193
|
+
return /* @__PURE__ */ React.createElement(
|
|
194
|
+
"button",
|
|
195
|
+
{
|
|
196
|
+
key: y,
|
|
197
|
+
type: "button",
|
|
198
|
+
tabIndex: y === yr ? 0 : -1,
|
|
199
|
+
className: cx("aura-cal__year", y === yr && "is-selected"),
|
|
200
|
+
onClick: function() {
|
|
201
|
+
setFocus(new Date(y, focusDate.getMonth(), Math.min(focusDate.getDate(), 28)));
|
|
202
|
+
setView("days");
|
|
203
|
+
moved.current = true;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
fmt(tag, { year: "numeric" }, d).replace(ERA, "")
|
|
207
|
+
);
|
|
208
|
+
})));
|
|
199
209
|
}
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
{
|
|
203
|
-
|
|
204
|
-
"
|
|
205
|
-
|
|
206
|
-
h(IconButton, { icon: "chevron-left", label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous month", onClick: function() {
|
|
210
|
+
return /* @__PURE__ */ React.createElement("div", { className: "aura-cal", ref: gridMerged }, /* @__PURE__ */ React.createElement("div", { className: "aura-cal__head" }, /* @__PURE__ */ React.createElement(
|
|
211
|
+
IconButton,
|
|
212
|
+
{
|
|
213
|
+
icon: "chevron-left",
|
|
214
|
+
label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous month",
|
|
215
|
+
onClick: function() {
|
|
207
216
|
setFocus(addMonths(focusDate, -1));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
)
|
|
217
|
-
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
), /* @__PURE__ */ React.createElement(
|
|
220
|
+
"button",
|
|
221
|
+
{
|
|
222
|
+
type: "button",
|
|
223
|
+
className: "aura-cal__title",
|
|
224
|
+
"aria-live": "polite",
|
|
225
|
+
onClick: function() {
|
|
226
|
+
setView("years");
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
monthTitle,
|
|
230
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "chevron-down", size: 14 })
|
|
231
|
+
), /* @__PURE__ */ React.createElement(
|
|
232
|
+
IconButton,
|
|
233
|
+
{
|
|
234
|
+
icon: "chevron-right",
|
|
235
|
+
label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B" : "Next month",
|
|
236
|
+
onClick: function() {
|
|
218
237
|
setFocus(addMonths(focusDate, 1));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
h("tbody", { onMouseLeave: function() {
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
)), /* @__PURE__ */ React.createElement("table", { role: "grid", className: "aura-cal__grid", "aria-label": monthTitle }, /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement("tr", null, weekdayNames.map(function(n, i) {
|
|
241
|
+
return /* @__PURE__ */ React.createElement("th", { key: i, scope: "col", abbr: n.long }, /* @__PURE__ */ React.createElement("span", { "aria-hidden": true }, n.short));
|
|
242
|
+
}))), /* @__PURE__ */ React.createElement(
|
|
243
|
+
"tbody",
|
|
244
|
+
{
|
|
245
|
+
onMouseLeave: function() {
|
|
228
246
|
hoverState[1](null);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
weeks.map(function(wk, wi) {
|
|
250
|
+
return /* @__PURE__ */ React.createElement("tr", { key: wi }, wk.map(function(d) {
|
|
251
|
+
const iso = toISO(d), out = d.getMonth() !== focusDate.getMonth(), dis = disabled(d);
|
|
252
|
+
const isStart = same(d, start), isEnd = same(d, end) || !end && props.range && same(d, hover) && start;
|
|
253
|
+
const sel = isStart || same(d, end);
|
|
254
|
+
return /* @__PURE__ */ React.createElement(
|
|
255
|
+
"td",
|
|
256
|
+
{
|
|
257
|
+
key: iso,
|
|
258
|
+
role: "gridcell",
|
|
259
|
+
"aria-selected": sel || void 0,
|
|
260
|
+
className: cx(
|
|
261
|
+
inRange(d) && "is-in-range",
|
|
262
|
+
props.range && isStart && rangeEnd && "is-range-start",
|
|
263
|
+
props.range && isEnd && start && "is-range-end"
|
|
264
|
+
)
|
|
265
|
+
},
|
|
266
|
+
/* @__PURE__ */ React.createElement(
|
|
267
|
+
"button",
|
|
236
268
|
{
|
|
237
|
-
key: iso,
|
|
238
|
-
role: "gridcell",
|
|
239
|
-
"aria-selected": sel || void 0,
|
|
240
|
-
className: cx(inRange(d) && "is-in-range", props.range && isStart && rangeEnd && "is-range-start", props.range && isEnd && start && "is-range-end")
|
|
241
|
-
},
|
|
242
|
-
h("button", {
|
|
243
269
|
type: "button",
|
|
244
270
|
"data-date": iso,
|
|
245
271
|
tabIndex: same(d, focusDate) ? 0 : -1,
|
|
@@ -247,7 +273,12 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
247
273
|
"aria-label": fmt(tag, { weekday: "long", day: "numeric", month: "long", year: "numeric" }, d),
|
|
248
274
|
"aria-current": same(d, today) ? "date" : void 0,
|
|
249
275
|
"aria-pressed": sel || void 0,
|
|
250
|
-
className: cx(
|
|
276
|
+
className: cx(
|
|
277
|
+
"aura-cal__day",
|
|
278
|
+
out && "is-outside",
|
|
279
|
+
sel && "is-selected",
|
|
280
|
+
same(d, today) && "is-today"
|
|
281
|
+
),
|
|
251
282
|
onClick: function() {
|
|
252
283
|
setFocus(d);
|
|
253
284
|
props.onSelect(iso);
|
|
@@ -258,62 +289,80 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
|
|
|
258
289
|
onMouseEnter: function() {
|
|
259
290
|
if (props.range) hoverState[1](d);
|
|
260
291
|
}
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
292
|
+
},
|
|
293
|
+
d.getDate()
|
|
294
|
+
)
|
|
295
|
+
);
|
|
296
|
+
}));
|
|
297
|
+
})
|
|
298
|
+
)), props.footer === false ? null : /* @__PURE__ */ React.createElement("div", { className: "aura-cal__foot" }, /* @__PURE__ */ React.createElement(
|
|
299
|
+
"button",
|
|
300
|
+
{
|
|
301
|
+
type: "button",
|
|
302
|
+
className: "aura-cal__link",
|
|
303
|
+
disabled: disabled(today),
|
|
304
|
+
onClick: function() {
|
|
270
305
|
move(today);
|
|
271
306
|
props.onSelect(toISO(today));
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
th ? "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49" : "Today"
|
|
310
|
+
), props.onClear ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "aura-cal__link", onClick: props.onClear }, th ? "\u0E25\u0E49\u0E32\u0E07" : "Clear") : null));
|
|
276
311
|
});
|
|
277
312
|
function useCalendarPopover(boxRef) {
|
|
278
|
-
|
|
279
|
-
|
|
313
|
+
const openState = React.useState(false), open = openState[0], setOpen = openState[1];
|
|
314
|
+
const pos = React.useState(null), popRef = React.useRef(null), mounted = useMounted();
|
|
280
315
|
function place() {
|
|
281
316
|
if (!boxRef.current) return;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
317
|
+
const r = boxRef.current.getBoundingClientRect(), H = 380;
|
|
318
|
+
const up = window.innerHeight - r.bottom < H && r.top > H;
|
|
319
|
+
const left = Math.max(8, Math.min(r.left, window.innerWidth - 320 - 8));
|
|
285
320
|
pos[1](up ? { left, bottom: window.innerHeight - r.top + 4 } : { left, top: r.bottom + 4 });
|
|
286
321
|
}
|
|
287
|
-
useIsoLayoutEffect(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
document.
|
|
302
|
-
window.
|
|
303
|
-
window.
|
|
304
|
-
|
|
305
|
-
|
|
322
|
+
useIsoLayoutEffect(
|
|
323
|
+
function() {
|
|
324
|
+
if (open) place();
|
|
325
|
+
},
|
|
326
|
+
[open]
|
|
327
|
+
);
|
|
328
|
+
React.useEffect(
|
|
329
|
+
function() {
|
|
330
|
+
if (!open) return;
|
|
331
|
+
function outside(e) {
|
|
332
|
+
if (boxRef.current && boxRef.current.contains(e.target)) return;
|
|
333
|
+
if (popRef.current && popRef.current.contains(e.target)) return;
|
|
334
|
+
setOpen(false);
|
|
335
|
+
}
|
|
336
|
+
document.addEventListener("pointerdown", outside, true);
|
|
337
|
+
window.addEventListener("resize", place);
|
|
338
|
+
window.addEventListener("scroll", place, true);
|
|
339
|
+
return function() {
|
|
340
|
+
document.removeEventListener("pointerdown", outside, true);
|
|
341
|
+
window.removeEventListener("resize", place);
|
|
342
|
+
window.removeEventListener("scroll", place, true);
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
[open]
|
|
346
|
+
);
|
|
306
347
|
return { open, setOpen, pos: pos[0], popRef, mounted };
|
|
307
348
|
}
|
|
308
349
|
function DateField(props) {
|
|
309
|
-
|
|
310
|
-
return
|
|
350
|
+
const editState = React.useState(null), editing = editState[0], setEditing = editState[1];
|
|
351
|
+
return /* @__PURE__ */ React.createElement(
|
|
311
352
|
Field,
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
353
|
+
{
|
|
354
|
+
id: props.id,
|
|
355
|
+
label: props.label,
|
|
356
|
+
hint: props.hint,
|
|
357
|
+
error: props.error,
|
|
358
|
+
required: props.required,
|
|
359
|
+
optional: props.optional,
|
|
360
|
+
disabled: props.disabled,
|
|
361
|
+
className: props.className
|
|
362
|
+
},
|
|
363
|
+
/* @__PURE__ */ React.createElement("div", { ref: props.boxRef, className: cx("aura-input aura-date", props.open && "is-open") }, /* @__PURE__ */ React.createElement(
|
|
364
|
+
"input",
|
|
365
|
+
{
|
|
317
366
|
ref: props.inputRef,
|
|
318
367
|
id: props.id,
|
|
319
368
|
type: "text",
|
|
@@ -349,9 +398,20 @@ function DateField(props) {
|
|
|
349
398
|
props.onToggle(false);
|
|
350
399
|
}
|
|
351
400
|
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
401
|
+
}
|
|
402
|
+
), props.clearable !== false && props.hasValue && !props.disabled ? /* @__PURE__ */ React.createElement(
|
|
403
|
+
"button",
|
|
404
|
+
{
|
|
405
|
+
type: "button",
|
|
406
|
+
tabIndex: -1,
|
|
407
|
+
className: "aura-combo__clear",
|
|
408
|
+
"aria-label": props.clearLabel,
|
|
409
|
+
onClick: props.onClear
|
|
410
|
+
},
|
|
411
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "x" })
|
|
412
|
+
) : null, /* @__PURE__ */ React.createElement(
|
|
413
|
+
"button",
|
|
414
|
+
{
|
|
355
415
|
type: "button",
|
|
356
416
|
className: "aura-date__toggle",
|
|
357
417
|
disabled: props.disabled,
|
|
@@ -362,30 +422,35 @@ function DateField(props) {
|
|
|
362
422
|
onClick: function() {
|
|
363
423
|
props.onToggle(!props.open);
|
|
364
424
|
}
|
|
365
|
-
},
|
|
366
|
-
|
|
425
|
+
},
|
|
426
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "calendar" })
|
|
427
|
+
))
|
|
367
428
|
);
|
|
368
429
|
}
|
|
369
430
|
const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
431
|
+
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 || "buddhist", th = locale !== "en";
|
|
433
|
+
const st = useMaybeControlled(
|
|
434
|
+
props.value,
|
|
435
|
+
props.defaultValue == null ? null : props.defaultValue,
|
|
436
|
+
props.onChange
|
|
437
|
+
);
|
|
438
|
+
const boxRef = React.useRef(null), inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef);
|
|
439
|
+
const pop = useCalendarPopover(boxRef);
|
|
375
440
|
function commit(text) {
|
|
376
441
|
if (!text.trim()) {
|
|
377
442
|
st[1](null);
|
|
378
443
|
return;
|
|
379
444
|
}
|
|
380
|
-
|
|
445
|
+
const iso = parseDate(text);
|
|
381
446
|
if (iso) st[1](iso);
|
|
382
447
|
}
|
|
383
448
|
function close() {
|
|
384
449
|
pop.setOpen(false);
|
|
385
450
|
if (inputRef.current) inputRef.current.focus();
|
|
386
451
|
}
|
|
387
|
-
|
|
388
|
-
|
|
452
|
+
const cal = pop.open && pop.mounted && pop.pos ? createPortal(
|
|
453
|
+
/* @__PURE__ */ React.createElement(
|
|
389
454
|
"div",
|
|
390
455
|
{
|
|
391
456
|
ref: pop.popRef,
|
|
@@ -402,27 +467,29 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
|
402
467
|
} else trapTab(e, pop.popRef.current);
|
|
403
468
|
}
|
|
404
469
|
},
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
st[
|
|
416
|
-
|
|
470
|
+
/* @__PURE__ */ React.createElement(
|
|
471
|
+
Calendar,
|
|
472
|
+
{
|
|
473
|
+
locale,
|
|
474
|
+
calendar,
|
|
475
|
+
weekStartsOn: props.weekStartsOn,
|
|
476
|
+
min: props.min,
|
|
477
|
+
max: props.max,
|
|
478
|
+
isDateDisabled: props.isDateDisabled,
|
|
479
|
+
start: st[0],
|
|
480
|
+
focus: st[0],
|
|
481
|
+
onSelect: function(iso) {
|
|
482
|
+
st[1](iso);
|
|
483
|
+
close();
|
|
484
|
+
}
|
|
417
485
|
}
|
|
418
|
-
|
|
486
|
+
)
|
|
419
487
|
),
|
|
420
488
|
document.body
|
|
421
489
|
) : null;
|
|
422
|
-
return
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
h(DateField, {
|
|
490
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
491
|
+
DateField,
|
|
492
|
+
{
|
|
426
493
|
id,
|
|
427
494
|
dialogId,
|
|
428
495
|
label: props.label,
|
|
@@ -451,119 +518,125 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
|
|
|
451
518
|
pop.setOpen(o);
|
|
452
519
|
if (!o && inputRef.current) inputRef.current.focus();
|
|
453
520
|
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
);
|
|
521
|
+
}
|
|
522
|
+
), cal);
|
|
457
523
|
});
|
|
458
|
-
const DateRangePicker = React.forwardRef(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
return;
|
|
524
|
+
const DateRangePicker = React.forwardRef(
|
|
525
|
+
function DateRangePicker2(props, ref) {
|
|
526
|
+
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 || "buddhist", th = locale !== "en";
|
|
528
|
+
const st = useMaybeControlled(
|
|
529
|
+
props.value,
|
|
530
|
+
props.defaultValue || { start: null, end: null },
|
|
531
|
+
props.onChange
|
|
532
|
+
);
|
|
533
|
+
const v = st[0] || { start: null, end: null };
|
|
534
|
+
const draft = React.useState(null);
|
|
535
|
+
const boxRef = React.useRef(null), inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef);
|
|
536
|
+
const pop = useCalendarPopover(boxRef);
|
|
537
|
+
const o = { locale, calendar };
|
|
538
|
+
function show(r) {
|
|
539
|
+
if (!r.start) return "";
|
|
540
|
+
if (!r.end) return formatDate(r.start, o) + " \u2013";
|
|
541
|
+
return formatDate(r.start, o) + " \u2013 " + formatDate(r.end, o);
|
|
477
542
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
function pick(iso) {
|
|
487
|
-
if (!draft[0]) {
|
|
488
|
-
draft[1](iso);
|
|
489
|
-
return;
|
|
543
|
+
function commit(text) {
|
|
544
|
+
const parts = String(text).split(/\s[–-]\s|\s*–\s*/);
|
|
545
|
+
if (!text.trim()) {
|
|
546
|
+
st[1]({ start: null, end: null });
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const a = parseDate(parts[0]), b = parseDate(parts[1] || "");
|
|
550
|
+
if (a && b) st[1](a <= b ? { start: a, end: b } : { start: b, end: a });
|
|
490
551
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
552
|
+
function close() {
|
|
553
|
+
pop.setOpen(false);
|
|
554
|
+
draft[1](null);
|
|
555
|
+
if (inputRef.current) inputRef.current.focus();
|
|
556
|
+
}
|
|
557
|
+
function pick(iso) {
|
|
558
|
+
if (!draft[0]) {
|
|
559
|
+
draft[1](iso);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const a = draft[0], b = iso;
|
|
563
|
+
st[1](a <= b ? { start: a, end: b } : { start: b, end: a });
|
|
564
|
+
close();
|
|
565
|
+
}
|
|
566
|
+
const cal = pop.open && pop.mounted && pop.pos ? createPortal(
|
|
567
|
+
/* @__PURE__ */ React.createElement(
|
|
568
|
+
"div",
|
|
569
|
+
{
|
|
570
|
+
ref: pop.popRef,
|
|
571
|
+
id: dialogId,
|
|
572
|
+
role: "dialog",
|
|
573
|
+
"aria-modal": false,
|
|
574
|
+
"aria-label": props.label || (th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Choose dates"),
|
|
575
|
+
className: "aura-cal__popover",
|
|
576
|
+
style: pop.pos,
|
|
577
|
+
onKeyDown: function(e) {
|
|
578
|
+
if (e.key === "Escape") {
|
|
579
|
+
e.stopPropagation();
|
|
580
|
+
close();
|
|
581
|
+
} else trapTab(e, pop.popRef.current);
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
/* @__PURE__ */ React.createElement("p", { className: "aura-cal__hint", "aria-live": "polite" }, draft[0] ? th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14" : "Choose the end date" : th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" : "Choose the start date"),
|
|
585
|
+
/* @__PURE__ */ React.createElement(
|
|
586
|
+
Calendar,
|
|
587
|
+
{
|
|
588
|
+
range: true,
|
|
589
|
+
locale,
|
|
590
|
+
calendar,
|
|
591
|
+
weekStartsOn: props.weekStartsOn,
|
|
592
|
+
min: props.min,
|
|
593
|
+
max: props.max,
|
|
594
|
+
isDateDisabled: props.isDateDisabled,
|
|
595
|
+
start: draft[0] || v.start,
|
|
596
|
+
end: draft[0] ? null : v.end,
|
|
597
|
+
focus: draft[0] || v.start,
|
|
598
|
+
onSelect: pick
|
|
599
|
+
}
|
|
600
|
+
)
|
|
601
|
+
),
|
|
602
|
+
document.body
|
|
603
|
+
) : null;
|
|
604
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
605
|
+
DateField,
|
|
498
606
|
{
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
607
|
+
id,
|
|
608
|
+
dialogId,
|
|
609
|
+
label: props.label,
|
|
610
|
+
hint: props.hint,
|
|
611
|
+
error: props.error,
|
|
612
|
+
required: props.required,
|
|
613
|
+
optional: props.optional,
|
|
614
|
+
disabled: props.disabled,
|
|
615
|
+
className: props.className,
|
|
616
|
+
name: props.name,
|
|
617
|
+
boxRef,
|
|
618
|
+
inputRef: inputMerged,
|
|
619
|
+
open: pop.open,
|
|
620
|
+
display: show(v),
|
|
621
|
+
placeholder: props.placeholder || (th ? "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B \u2013 \u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B" : "dd/mm/yyyy \u2013 dd/mm/yyyy"),
|
|
622
|
+
hasValue: v.start != null,
|
|
623
|
+
clearable: props.clearable,
|
|
624
|
+
onClear: function() {
|
|
625
|
+
st[1]({ start: null, end: null });
|
|
626
|
+
inputRef.current && inputRef.current.focus();
|
|
627
|
+
},
|
|
628
|
+
clearLabel: th ? "\u0E25\u0E49\u0E32\u0E07\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Clear dates",
|
|
629
|
+
toggleLabel: th ? "\u0E40\u0E1B\u0E34\u0E14\u0E1B\u0E0F\u0E34\u0E17\u0E34\u0E19" : "Open calendar",
|
|
630
|
+
onCommit: commit,
|
|
631
|
+
onToggle: function(op) {
|
|
632
|
+
pop.setOpen(op);
|
|
633
|
+
draft[1](null);
|
|
634
|
+
if (!op && inputRef.current) inputRef.current.focus();
|
|
511
635
|
}
|
|
512
|
-
},
|
|
513
|
-
h("p", { className: "aura-cal__hint", "aria-live": "polite" }, draft[0] ? th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14" : "Choose the end date" : th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" : "Choose the start date"),
|
|
514
|
-
h(Calendar, {
|
|
515
|
-
range: true,
|
|
516
|
-
locale,
|
|
517
|
-
calendar,
|
|
518
|
-
weekStartsOn: props.weekStartsOn,
|
|
519
|
-
min: props.min,
|
|
520
|
-
max: props.max,
|
|
521
|
-
isDateDisabled: props.isDateDisabled,
|
|
522
|
-
start: draft[0] || v.start,
|
|
523
|
-
end: draft[0] ? null : v.end,
|
|
524
|
-
focus: draft[0] || v.start,
|
|
525
|
-
onSelect: pick
|
|
526
|
-
})
|
|
527
|
-
),
|
|
528
|
-
document.body
|
|
529
|
-
) : null;
|
|
530
|
-
return h(
|
|
531
|
-
React.Fragment,
|
|
532
|
-
null,
|
|
533
|
-
h(DateField, {
|
|
534
|
-
id,
|
|
535
|
-
dialogId,
|
|
536
|
-
label: props.label,
|
|
537
|
-
hint: props.hint,
|
|
538
|
-
error: props.error,
|
|
539
|
-
required: props.required,
|
|
540
|
-
optional: props.optional,
|
|
541
|
-
disabled: props.disabled,
|
|
542
|
-
className: props.className,
|
|
543
|
-
name: props.name,
|
|
544
|
-
boxRef,
|
|
545
|
-
inputRef: inputMerged,
|
|
546
|
-
open: pop.open,
|
|
547
|
-
display: show(v),
|
|
548
|
-
placeholder: props.placeholder || (th ? "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B \u2013 \u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B" : "dd/mm/yyyy \u2013 dd/mm/yyyy"),
|
|
549
|
-
hasValue: v.start != null,
|
|
550
|
-
clearable: props.clearable,
|
|
551
|
-
onClear: function() {
|
|
552
|
-
st[1]({ start: null, end: null });
|
|
553
|
-
inputRef.current && inputRef.current.focus();
|
|
554
|
-
},
|
|
555
|
-
clearLabel: th ? "\u0E25\u0E49\u0E32\u0E07\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Clear dates",
|
|
556
|
-
toggleLabel: th ? "\u0E40\u0E1B\u0E34\u0E14\u0E1B\u0E0F\u0E34\u0E17\u0E34\u0E19" : "Open calendar",
|
|
557
|
-
onCommit: commit,
|
|
558
|
-
onToggle: function(op) {
|
|
559
|
-
pop.setOpen(op);
|
|
560
|
-
draft[1](null);
|
|
561
|
-
if (!op && inputRef.current) inputRef.current.focus();
|
|
562
636
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
});
|
|
637
|
+
), cal);
|
|
638
|
+
}
|
|
639
|
+
);
|
|
567
640
|
export {
|
|
568
641
|
Calendar,
|
|
569
642
|
DatePicker,
|