@overdoser/react-toolkit 0.15.0 → 0.17.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/AGENTS.md +2 -0
- package/CHANGELOG.md +87 -0
- package/components/Chart/AreaChart.d.ts +5 -1
- package/components/Chart/AreaChart.js +155 -144
- package/components/Chart/BarChart.js +5 -5
- package/components/Chart/PieChart.js +2 -5
- package/components/Chart/RadarChart.js +2 -5
- package/components/Chart/TradingChart.js +258 -257
- package/components/Drawer/Drawer.js +69 -70
- package/components/Dropdown/Dropdown.js +51 -56
- package/components/Modal/Modal.js +42 -47
- package/components/Popover/Popover.js +52 -55
- package/components/SplitButton/SplitButton.js +50 -55
- package/components/inputs/DatePicker/CalendarPanel.d.ts +40 -0
- package/components/inputs/DatePicker/CalendarPanel.js +287 -0
- package/components/inputs/DatePicker/CalendarPanel.module.scss.js +41 -0
- package/components/inputs/DatePicker/DatePicker.d.ts +3 -1
- package/components/inputs/DatePicker/DatePicker.js +105 -192
- package/components/inputs/DatePicker/DatePicker.module.scss.js +20 -40
- package/components/inputs/DateTimePicker/DateTimePicker.d.ts +141 -0
- package/components/inputs/DateTimePicker/DateTimePicker.js +232 -0
- package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +37 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.d.ts +48 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.js +252 -0
- package/components/inputs/DateTimePicker/TimeField.d.ts +18 -0
- package/components/inputs/DateTimePicker/TimeField.js +135 -0
- package/components/inputs/DateTimePicker/index.d.ts +3 -0
- package/components/inputs/DateTimePicker/timeZoneUtils.d.ts +44 -0
- package/components/inputs/DateTimePicker/timeZoneUtils.js +102 -0
- package/components/inputs/NumberInput/NumberInput.js +79 -81
- package/components/inputs/Select/Select.d.ts +5 -0
- package/components/inputs/Select/Select.js +340 -285
- package/hooks/useEscapeLayer.d.ts +36 -0
- package/hooks/useEscapeLayer.js +33 -0
- package/index.css +1 -1
- package/index.d.ts +2 -0
- package/index.js +108 -106
- package/index.layered.css +1 -1
- package/llms.txt +29 -4
- package/manifest.json +127 -1
- package/package.json +1 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { jsxs as w, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Pe, useState as E, useMemo as a, useCallback as r, useRef as H } from "react";
|
|
3
|
+
import { createPortal as Me } from "react-dom";
|
|
4
|
+
import l from "clsx";
|
|
5
|
+
import { useClickOutside as Ze } from "../../../hooks/useClickOutside.js";
|
|
6
|
+
import { usePortalPosition as xe } from "../../../hooks/usePortalPosition.js";
|
|
7
|
+
import { CalendarPanel as Ee } from "../DatePicker/CalendarPanel.js";
|
|
8
|
+
import { startOfMonth as ie } from "../DatePicker/dateUtils.js";
|
|
9
|
+
import p from "../DatePicker/DatePicker.module.scss.js";
|
|
10
|
+
import d from "./DateTimePicker.module.scss.js";
|
|
11
|
+
import { TimeField as Oe } from "./TimeField.js";
|
|
12
|
+
import { DateTimeSegments as Re } from "./DateTimeSegments.js";
|
|
13
|
+
import { isValidTimeZone as Ue, localeHourCycle as ze, getWallClock as O, wallClockDay as b, timeZoneName as We, localTimeZone as Ie, fromWallClock as Ke } from "./timeZoneUtils.js";
|
|
14
|
+
import { Button as Se } from "../../Button/Button.js";
|
|
15
|
+
const Ve = { hour: 0, minute: 0, second: 0 }, Le = Pe(
|
|
16
|
+
({
|
|
17
|
+
value: A,
|
|
18
|
+
defaultValue: ae,
|
|
19
|
+
onChange: B,
|
|
20
|
+
min: c,
|
|
21
|
+
max: s,
|
|
22
|
+
disabledDate: Y,
|
|
23
|
+
weekStartsOn: le = 0,
|
|
24
|
+
locale: y,
|
|
25
|
+
timeZone: ce,
|
|
26
|
+
showTimeZone: _ = !0,
|
|
27
|
+
timeZoneStyle: $ = "longOffset",
|
|
28
|
+
fieldFormat: R = "iso",
|
|
29
|
+
hourCycle: G,
|
|
30
|
+
minuteStep: se = 5,
|
|
31
|
+
showSeconds: J = !0,
|
|
32
|
+
format: U,
|
|
33
|
+
placeholder: ue = "Select date and time",
|
|
34
|
+
doneLabel: fe = "Done",
|
|
35
|
+
inputSize: me = "md",
|
|
36
|
+
error: z = !1,
|
|
37
|
+
disabled: u = !1,
|
|
38
|
+
portal: N = !0,
|
|
39
|
+
classes: n,
|
|
40
|
+
className: pe,
|
|
41
|
+
style: de,
|
|
42
|
+
"aria-label": Q,
|
|
43
|
+
"aria-describedby": X
|
|
44
|
+
}, P) => {
|
|
45
|
+
const W = A !== void 0, [ye, he] = E(ae ?? null), i = W ? A ?? null : ye, k = ce ?? "UTC", t = a(() => {
|
|
46
|
+
if (k !== "system")
|
|
47
|
+
return Ue(k) ? k : (console.warn(`[DateTimePicker] Unknown time zone "${k}" — falling back to UTC.`), "UTC");
|
|
48
|
+
}, [k]), ee = a(
|
|
49
|
+
() => G ?? (R === "locale" ? ze(y) : 24),
|
|
50
|
+
[G, R, y]
|
|
51
|
+
), f = a(() => i ? O(i, t) : null, [i, t]), m = a(() => f ? b(f) : null, [f]), I = f ? { hour: f.hour, minute: f.minute, second: f.second } : Ve, h = r(() => b(O(/* @__PURE__ */ new Date(), t)), [t]), ve = a(() => h(), [h]), [v, C] = E(!1), [De, te] = E(() => ie(m ?? h())), [K, S] = E(() => m ?? h()), V = H(null), L = H(null), oe = H(null), ne = xe(V, v && N), g = a(() => _ ? t === "UTC" || t === "Etc/UTC" ? "UTC" : We(i ?? /* @__PURE__ */ new Date(), t, y, $) : null, [_, i, t, y, $]), j = t ?? Ie(), M = a(() => c ? b(O(c, t)) : void 0, [c, t]), Z = a(() => s ? b(O(s, t)) : void 0, [s, t]), ke = r(
|
|
52
|
+
(e) => M && e < M || Z && e > Z ? !0 : Y?.(e) ?? !1,
|
|
53
|
+
[M, Z, Y]
|
|
54
|
+
), q = r(
|
|
55
|
+
(e) => {
|
|
56
|
+
W || he(e), B?.(e);
|
|
57
|
+
},
|
|
58
|
+
[W, B]
|
|
59
|
+
), D = r(
|
|
60
|
+
(e, Ne) => {
|
|
61
|
+
let T = Ke(
|
|
62
|
+
{ year: e.getFullYear(), month: e.getMonth(), day: e.getDate(), ...Ne },
|
|
63
|
+
t
|
|
64
|
+
);
|
|
65
|
+
c && T < c && (T = new Date(c.getTime())), s && T > s && (T = new Date(s.getTime())), q(T);
|
|
66
|
+
},
|
|
67
|
+
[t, c, s, q]
|
|
68
|
+
), x = r(() => {
|
|
69
|
+
if (u) return;
|
|
70
|
+
const e = m ?? h();
|
|
71
|
+
te(ie(e)), S(e), C(!0);
|
|
72
|
+
}, [u, m, h]), F = r((e = !0) => {
|
|
73
|
+
C(!1), e && (L.current ? L.current.focus() : V.current?.querySelector("input")?.focus());
|
|
74
|
+
}, []), Ce = r(
|
|
75
|
+
(e) => {
|
|
76
|
+
S(e), D(e, I);
|
|
77
|
+
},
|
|
78
|
+
[D, I]
|
|
79
|
+
), ge = r(
|
|
80
|
+
(e) => D(m ?? K, e),
|
|
81
|
+
[D, m, K]
|
|
82
|
+
), Te = r(
|
|
83
|
+
(e) => D(b(e), { hour: e.hour, minute: e.minute, second: e.second }),
|
|
84
|
+
[D]
|
|
85
|
+
);
|
|
86
|
+
Ze(oe, () => C(!1), v);
|
|
87
|
+
const we = (e) => {
|
|
88
|
+
e.key === "ArrowDown" || e.key === "Enter" ? (e.preventDefault(), x()) : e.key === "Escape" && v && (e.preventDefault(), C(!1));
|
|
89
|
+
}, be = (e) => {
|
|
90
|
+
e.key === "Escape" && !e.defaultPrevented && (e.preventDefault(), F());
|
|
91
|
+
}, re = (
|
|
92
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
93
|
+
/* @__PURE__ */ w(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
ref: oe,
|
|
97
|
+
className: l(d.popover, N && d.portalled, n?.popover),
|
|
98
|
+
style: N ? { position: "fixed", top: ne.top + 4, left: ne.left } : void 0,
|
|
99
|
+
role: "dialog",
|
|
100
|
+
"aria-modal": "false",
|
|
101
|
+
"aria-label": "Choose date and time",
|
|
102
|
+
onKeyDown: be,
|
|
103
|
+
children: [
|
|
104
|
+
/* @__PURE__ */ w("div", { className: d.body, children: [
|
|
105
|
+
/* @__PURE__ */ o("div", { className: d.calendar, children: /* @__PURE__ */ o(
|
|
106
|
+
Ee,
|
|
107
|
+
{
|
|
108
|
+
viewDate: De,
|
|
109
|
+
focusedDate: K,
|
|
110
|
+
selected: m,
|
|
111
|
+
today: ve,
|
|
112
|
+
minDay: M,
|
|
113
|
+
maxDay: Z,
|
|
114
|
+
locale: y,
|
|
115
|
+
weekStartsOn: le,
|
|
116
|
+
isDisabledDay: ke,
|
|
117
|
+
onSelect: Ce,
|
|
118
|
+
onViewDateChange: te,
|
|
119
|
+
onFocusedDateChange: S,
|
|
120
|
+
onEscape: F,
|
|
121
|
+
classes: n
|
|
122
|
+
}
|
|
123
|
+
) }),
|
|
124
|
+
/* @__PURE__ */ o(
|
|
125
|
+
Oe,
|
|
126
|
+
{
|
|
127
|
+
...I,
|
|
128
|
+
onChange: ge,
|
|
129
|
+
hourCycle: ee,
|
|
130
|
+
showSeconds: J,
|
|
131
|
+
minuteStep: se,
|
|
132
|
+
disabled: u,
|
|
133
|
+
classes: n
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
] }),
|
|
137
|
+
/* @__PURE__ */ w("div", { className: l(d.footer, n?.footer), children: [
|
|
138
|
+
g && /* @__PURE__ */ o("span", { className: l(d.zone, n?.timeZone), title: j, children: g }),
|
|
139
|
+
/* @__PURE__ */ o(Se, { type: "button", size: "sm", onClick: () => F(), children: fe })
|
|
140
|
+
] })
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
return /* @__PURE__ */ w(
|
|
146
|
+
"div",
|
|
147
|
+
{
|
|
148
|
+
ref: (e) => {
|
|
149
|
+
V.current = e, typeof P == "function" ? P(e) : P && (P.current = e);
|
|
150
|
+
},
|
|
151
|
+
className: l(
|
|
152
|
+
p.root,
|
|
153
|
+
p[me],
|
|
154
|
+
z && p.error,
|
|
155
|
+
u && p.disabled,
|
|
156
|
+
n?.root,
|
|
157
|
+
pe
|
|
158
|
+
),
|
|
159
|
+
style: de,
|
|
160
|
+
children: [
|
|
161
|
+
U ? /* @__PURE__ */ o(
|
|
162
|
+
"input",
|
|
163
|
+
{
|
|
164
|
+
type: "text",
|
|
165
|
+
readOnly: !0,
|
|
166
|
+
className: l(p.input, n?.input),
|
|
167
|
+
value: i ? U(i) : "",
|
|
168
|
+
placeholder: ue,
|
|
169
|
+
disabled: u,
|
|
170
|
+
"aria-label": Q,
|
|
171
|
+
"aria-describedby": X,
|
|
172
|
+
"aria-haspopup": "dialog",
|
|
173
|
+
"aria-expanded": v,
|
|
174
|
+
"aria-invalid": z || void 0,
|
|
175
|
+
onClick: x,
|
|
176
|
+
onKeyDown: we
|
|
177
|
+
}
|
|
178
|
+
) : /* @__PURE__ */ o(
|
|
179
|
+
Re,
|
|
180
|
+
{
|
|
181
|
+
ref: L,
|
|
182
|
+
value: i,
|
|
183
|
+
timeZone: t,
|
|
184
|
+
locale: y,
|
|
185
|
+
layout: R,
|
|
186
|
+
hourCycle: ee,
|
|
187
|
+
showSeconds: J,
|
|
188
|
+
onChange: Te,
|
|
189
|
+
onClear: () => q(null),
|
|
190
|
+
onOpenRequest: x,
|
|
191
|
+
onEscape: (e) => {
|
|
192
|
+
v && (e.preventDefault(), C(!1));
|
|
193
|
+
},
|
|
194
|
+
suffix: g,
|
|
195
|
+
suffixTitle: j,
|
|
196
|
+
suffixClassName: n?.timeZone,
|
|
197
|
+
disabled: u,
|
|
198
|
+
className: l(p.input, n?.input),
|
|
199
|
+
classes: { segment: n?.segment },
|
|
200
|
+
"aria-label": Q,
|
|
201
|
+
"aria-describedby": X,
|
|
202
|
+
"aria-invalid": z
|
|
203
|
+
}
|
|
204
|
+
),
|
|
205
|
+
U && g && /* @__PURE__ */ o("span", { className: l(d.timeZone, n?.timeZone), title: j, children: g }),
|
|
206
|
+
/* @__PURE__ */ o(
|
|
207
|
+
"button",
|
|
208
|
+
{
|
|
209
|
+
type: "button",
|
|
210
|
+
tabIndex: -1,
|
|
211
|
+
className: l(p.icon, n?.icon),
|
|
212
|
+
onClick: x,
|
|
213
|
+
disabled: u,
|
|
214
|
+
"aria-label": "Open date and time picker",
|
|
215
|
+
children: /* @__PURE__ */ w("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.5", "aria-hidden": "true", children: [
|
|
216
|
+
/* @__PURE__ */ o("path", { d: "M3 8h14M7 2v3M13 2v3", strokeLinecap: "round" }),
|
|
217
|
+
/* @__PURE__ */ o("path", { d: "M17 10V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h4", strokeLinecap: "round" }),
|
|
218
|
+
/* @__PURE__ */ o("circle", { cx: "14.5", cy: "14.5", r: "3.5" }),
|
|
219
|
+
/* @__PURE__ */ o("path", { d: "M14.5 12.75v1.75l1.25 1", strokeLinecap: "round" })
|
|
220
|
+
] })
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
v && (N ? typeof document < "u" && Me(re, document.body) : re)
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
Le.displayName = "DateTimePicker";
|
|
230
|
+
export {
|
|
231
|
+
Le as DateTimePicker
|
|
232
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const e = "crk-popover-RmMhf", o = "crk-portalled-Yh6Wl", t = "crk-segments-BIpWS", n = "crk-segment-ETxcK", c = "crk-segmentEmpty-OjqG3", s = "crk-literal-iZcwW", r = "crk-suffix-l1MSH", l = "crk-timeZone-27ID1", m = "crk-body-5FqOt", p = "crk-calendar-EjUxD", i = "crk-time-F5Zb0", k = "crk-column-bRLrD", a = "crk-option-JF-Fj", d = "crk-optionSelected-nlh39", f = "crk-footer-q3V1M", g = "crk-zone-QFZBW", u = {
|
|
2
|
+
popover: e,
|
|
3
|
+
portalled: o,
|
|
4
|
+
segments: t,
|
|
5
|
+
segment: n,
|
|
6
|
+
segmentEmpty: c,
|
|
7
|
+
literal: s,
|
|
8
|
+
suffix: r,
|
|
9
|
+
timeZone: l,
|
|
10
|
+
body: m,
|
|
11
|
+
calendar: p,
|
|
12
|
+
time: i,
|
|
13
|
+
column: k,
|
|
14
|
+
option: a,
|
|
15
|
+
optionSelected: d,
|
|
16
|
+
footer: f,
|
|
17
|
+
zone: g
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
m as body,
|
|
21
|
+
p as calendar,
|
|
22
|
+
k as column,
|
|
23
|
+
u as default,
|
|
24
|
+
f as footer,
|
|
25
|
+
s as literal,
|
|
26
|
+
a as option,
|
|
27
|
+
d as optionSelected,
|
|
28
|
+
e as popover,
|
|
29
|
+
o as portalled,
|
|
30
|
+
n as segment,
|
|
31
|
+
c as segmentEmpty,
|
|
32
|
+
t as segments,
|
|
33
|
+
r as suffix,
|
|
34
|
+
i as time,
|
|
35
|
+
l as timeZone,
|
|
36
|
+
g as zone
|
|
37
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KeyboardEvent } from 'react';
|
|
2
|
+
import { WallClock } from './timeZoneUtils';
|
|
3
|
+
export type SegmentType = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'dayPeriod';
|
|
4
|
+
export interface DateTimeSegmentsClasses {
|
|
5
|
+
/** The row of segments (sits where the read-only input would). */
|
|
6
|
+
segments: string;
|
|
7
|
+
/** Each editable segment. */
|
|
8
|
+
segment: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DateTimeSegmentsHandle {
|
|
11
|
+
/** Focus the segment that currently holds roving focus. */
|
|
12
|
+
focus: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface DateTimeSegmentsProps {
|
|
15
|
+
value: Date | null;
|
|
16
|
+
timeZone?: string;
|
|
17
|
+
locale?: string;
|
|
18
|
+
/** `'iso'` → `YYYY-MM-DD HH:mm:ss`; `'locale'` → the locale's numeric order. */
|
|
19
|
+
layout: 'iso' | 'locale';
|
|
20
|
+
hourCycle: 12 | 24;
|
|
21
|
+
showSeconds: boolean;
|
|
22
|
+
/** An edited wall clock; the parent converts, clamps and commits it. */
|
|
23
|
+
onChange: (wc: WallClock) => void;
|
|
24
|
+
/** Backspace / Delete on any segment. */
|
|
25
|
+
onClear: () => void;
|
|
26
|
+
/** Alt+ArrowDown — the user asked for the popover. */
|
|
27
|
+
onOpenRequest: () => void;
|
|
28
|
+
onEscape: (e: KeyboardEvent<HTMLElement>) => void;
|
|
29
|
+
/** Plain trailing label (the zone name) rendered after the last segment. */
|
|
30
|
+
suffix?: string | null;
|
|
31
|
+
suffixTitle?: string;
|
|
32
|
+
suffixClassName?: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
classes?: Partial<DateTimeSegmentsClasses>;
|
|
35
|
+
className?: string;
|
|
36
|
+
'aria-label'?: string;
|
|
37
|
+
'aria-describedby'?: string;
|
|
38
|
+
'aria-invalid'?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Keyboard-editable date/time field made of locale-ordered segments — the
|
|
42
|
+
* "type it or arrow it" half of `DateTimePicker`. Every segment is a
|
|
43
|
+
* `spinbutton`: Up/Down step and wrap, Left/Right (and Tab-less roving focus)
|
|
44
|
+
* move between segments, digits type with auto-advance, A/P set the period,
|
|
45
|
+
* Backspace/Delete clear the field. With no value, the first arrow press
|
|
46
|
+
* fills in the current date and time (then steps), and typing starts from it.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DateTimeSegments: import('react').ForwardRefExoticComponent<DateTimeSegmentsProps & import('react').RefAttributes<DateTimeSegmentsHandle>>;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { jsxs as $, jsx as R, Fragment as oe } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as se, useRef as j, useState as U, useMemo as A, useCallback as ie, useImperativeHandle as ue, useEffect as ce } from "react";
|
|
3
|
+
import T from "clsx";
|
|
4
|
+
import D from "./DateTimePicker.module.scss.js";
|
|
5
|
+
import { getWallClock as W } from "./timeZoneUtils.js";
|
|
6
|
+
const de = /* @__PURE__ */ new Set(["year", "month", "day", "hour", "minute", "second", "dayPeriod"]), le = {
|
|
7
|
+
year: "YYYY",
|
|
8
|
+
month: "MM",
|
|
9
|
+
day: "DD",
|
|
10
|
+
hour: "HH",
|
|
11
|
+
minute: "mm",
|
|
12
|
+
second: "ss",
|
|
13
|
+
dayPeriod: "AM"
|
|
14
|
+
}, me = {
|
|
15
|
+
year: "Year",
|
|
16
|
+
month: "Month",
|
|
17
|
+
day: "Day",
|
|
18
|
+
hour: "Hour",
|
|
19
|
+
minute: "Minute",
|
|
20
|
+
second: "Second",
|
|
21
|
+
dayPeriod: "AM/PM"
|
|
22
|
+
}, z = (s, a) => new Date(s, a + 1, 0).getDate(), v = (s, a, g) => {
|
|
23
|
+
const m = g - a + 1;
|
|
24
|
+
return ((s - a) % m + m) % m + a;
|
|
25
|
+
}, ye = se(
|
|
26
|
+
({
|
|
27
|
+
value: s,
|
|
28
|
+
timeZone: a,
|
|
29
|
+
locale: g,
|
|
30
|
+
layout: m,
|
|
31
|
+
hourCycle: y,
|
|
32
|
+
showSeconds: b,
|
|
33
|
+
onChange: p,
|
|
34
|
+
onClear: G,
|
|
35
|
+
onOpenRequest: J,
|
|
36
|
+
onEscape: Q,
|
|
37
|
+
suffix: Y,
|
|
38
|
+
suffixTitle: V,
|
|
39
|
+
suffixClassName: X,
|
|
40
|
+
disabled: h = !1,
|
|
41
|
+
classes: B,
|
|
42
|
+
className: _,
|
|
43
|
+
"aria-label": C,
|
|
44
|
+
"aria-describedby": Z,
|
|
45
|
+
"aria-invalid": ee
|
|
46
|
+
}, te) => {
|
|
47
|
+
const M = j(null), [f, F] = U(0), [E, c] = U(""), L = j(!1), q = A(
|
|
48
|
+
() => new Intl.DateTimeFormat(g, {
|
|
49
|
+
year: "numeric",
|
|
50
|
+
month: "2-digit",
|
|
51
|
+
day: "2-digit",
|
|
52
|
+
hour: "2-digit",
|
|
53
|
+
minute: "2-digit",
|
|
54
|
+
second: b ? "2-digit" : void 0,
|
|
55
|
+
hourCycle: y === 12 ? "h12" : "h23",
|
|
56
|
+
timeZone: a
|
|
57
|
+
}),
|
|
58
|
+
[g, b, y, a]
|
|
59
|
+
), i = A(() => s ? W(s, a) : null, [s, a]), N = A(() => {
|
|
60
|
+
if (m === "locale")
|
|
61
|
+
return q.formatToParts(s ?? new Date(2001, 11, 21, 15, 45, 30)).filter((n) => de.has(n.type) || n.type === "literal").map((n) => ({ type: n.type, text: n.value }));
|
|
62
|
+
const e = (l, n = 2) => String(l).padStart(n, "0"), t = i ?? { year: 0, month: 0, day: 0, hour: 0, minute: 0, second: 0 }, r = y === 12 ? t.hour % 12 || 12 : t.hour, o = [
|
|
63
|
+
{ type: "year", text: e(t.year, 4) },
|
|
64
|
+
{ type: "literal", text: "-" },
|
|
65
|
+
{ type: "month", text: e(t.month + 1) },
|
|
66
|
+
{ type: "literal", text: "-" },
|
|
67
|
+
{ type: "day", text: e(t.day) },
|
|
68
|
+
{ type: "literal", text: " " },
|
|
69
|
+
{ type: "hour", text: e(r) },
|
|
70
|
+
{ type: "literal", text: ":" },
|
|
71
|
+
{ type: "minute", text: e(t.minute) }
|
|
72
|
+
];
|
|
73
|
+
return b && o.push({ type: "literal", text: ":" }, { type: "second", text: e(t.second) }), y === 12 && o.push({ type: "literal", text: " " }, { type: "dayPeriod", text: t.hour >= 12 ? "PM" : "AM" }), o;
|
|
74
|
+
}, [m, q, s, i, y, b]), u = A(
|
|
75
|
+
() => N.map((e, t) => e.type === "literal" ? -1 : t).filter((e) => e >= 0),
|
|
76
|
+
[N]
|
|
77
|
+
), S = ie(() => i ? { ...i } : { ...W(/* @__PURE__ */ new Date(), a), second: 0 }, [i, a]);
|
|
78
|
+
ue(
|
|
79
|
+
te,
|
|
80
|
+
() => ({
|
|
81
|
+
focus: () => {
|
|
82
|
+
M.current?.querySelector('[role="spinbutton"][tabindex="0"]')?.focus();
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
[]
|
|
86
|
+
), ce(() => {
|
|
87
|
+
L.current && (L.current = !1, M.current?.querySelector(`[data-segment="${f}"]`)?.focus());
|
|
88
|
+
}, [f]);
|
|
89
|
+
const w = (e) => {
|
|
90
|
+
const t = u.indexOf(e), r = u[Math.max(0, Math.min(u.length - 1, t))];
|
|
91
|
+
c(""), L.current = !0, F(r);
|
|
92
|
+
}, H = (e) => {
|
|
93
|
+
const t = u.indexOf(f), r = u[Math.max(0, Math.min(u.length - 1, t + e))];
|
|
94
|
+
r !== f && w(r);
|
|
95
|
+
}, k = (e, t, r) => {
|
|
96
|
+
switch (e) {
|
|
97
|
+
case "year":
|
|
98
|
+
t.year = Math.max(1, Math.min(9999, r));
|
|
99
|
+
break;
|
|
100
|
+
case "month":
|
|
101
|
+
t.month = v(r, 0, 11);
|
|
102
|
+
break;
|
|
103
|
+
case "day":
|
|
104
|
+
t.day = v(r, 1, z(t.year, t.month));
|
|
105
|
+
break;
|
|
106
|
+
case "hour":
|
|
107
|
+
t.hour = v(r, 0, 23);
|
|
108
|
+
break;
|
|
109
|
+
case "minute":
|
|
110
|
+
t.minute = v(r, 0, 59);
|
|
111
|
+
break;
|
|
112
|
+
case "second":
|
|
113
|
+
t.second = v(r, 0, 59);
|
|
114
|
+
break;
|
|
115
|
+
case "dayPeriod":
|
|
116
|
+
t.hour = r >= 12 ? t.hour % 12 + 12 : t.hour % 12;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
return t.day = Math.min(t.day, z(t.year, t.month)), t;
|
|
120
|
+
}, K = (e, t) => {
|
|
121
|
+
switch (e) {
|
|
122
|
+
case "year":
|
|
123
|
+
return t.year;
|
|
124
|
+
case "month":
|
|
125
|
+
return t.month;
|
|
126
|
+
case "day":
|
|
127
|
+
return t.day;
|
|
128
|
+
case "hour":
|
|
129
|
+
return t.hour;
|
|
130
|
+
case "minute":
|
|
131
|
+
return t.minute;
|
|
132
|
+
case "second":
|
|
133
|
+
return t.second;
|
|
134
|
+
case "dayPeriod":
|
|
135
|
+
return t.hour >= 12 ? 12 : 0;
|
|
136
|
+
}
|
|
137
|
+
}, O = (e, t) => {
|
|
138
|
+
const r = S();
|
|
139
|
+
if (!i) {
|
|
140
|
+
p(r);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const o = e === "dayPeriod" ? r.hour >= 12 ? 0 : 12 : K(e, r) + t;
|
|
144
|
+
p(k(e, r, o));
|
|
145
|
+
}, re = (e, t) => {
|
|
146
|
+
const r = y === 12, o = { year: 9999, month: 12, day: 31, hour: r ? 12 : 23, minute: 59, second: 59, dayPeriod: 0 }[e], l = e === "year" ? 4 : 2;
|
|
147
|
+
let n = E + t;
|
|
148
|
+
Number(n) > o && (n = t);
|
|
149
|
+
const d = Number(n), P = n.length === l || d * 10 > o, x = S();
|
|
150
|
+
if (e === "year")
|
|
151
|
+
P && p(k(e, x, d));
|
|
152
|
+
else if (d > 0 || e === "hour" || e === "minute" || e === "second") {
|
|
153
|
+
let I = d;
|
|
154
|
+
e === "month" && (I = d - 1), e === "hour" && r && (I = d % 12 + (x.hour >= 12 ? 12 : 0)), p(k(e, x, I));
|
|
155
|
+
}
|
|
156
|
+
P ? (c(""), H(1)) : c(n);
|
|
157
|
+
}, ne = (e, t) => {
|
|
158
|
+
if (!h) {
|
|
159
|
+
if (e.altKey && e.key === "ArrowDown") {
|
|
160
|
+
e.preventDefault(), J();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
switch (e.key) {
|
|
164
|
+
case "ArrowUp":
|
|
165
|
+
e.preventDefault(), c(""), O(t, 1);
|
|
166
|
+
return;
|
|
167
|
+
case "ArrowDown":
|
|
168
|
+
e.preventDefault(), c(""), O(t, -1);
|
|
169
|
+
return;
|
|
170
|
+
case "ArrowLeft":
|
|
171
|
+
e.preventDefault(), H(-1);
|
|
172
|
+
return;
|
|
173
|
+
case "ArrowRight":
|
|
174
|
+
e.preventDefault(), H(1);
|
|
175
|
+
return;
|
|
176
|
+
case "Home":
|
|
177
|
+
e.preventDefault(), w(u[0]);
|
|
178
|
+
return;
|
|
179
|
+
case "End":
|
|
180
|
+
e.preventDefault(), w(u[u.length - 1]);
|
|
181
|
+
return;
|
|
182
|
+
case "Backspace":
|
|
183
|
+
case "Delete":
|
|
184
|
+
e.preventDefault(), c(""), G();
|
|
185
|
+
return;
|
|
186
|
+
case "Escape":
|
|
187
|
+
Q(e);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (t === "dayPeriod") {
|
|
191
|
+
const r = e.key.toLowerCase();
|
|
192
|
+
(r === "a" || r === "p") && (e.preventDefault(), p(k(t, S(), r === "p" ? 12 : 0)));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
/^\d$/.test(e.key) && (e.preventDefault(), re(t, e.key));
|
|
196
|
+
}
|
|
197
|
+
}, ae = (e) => {
|
|
198
|
+
h || e.target.closest('[role="spinbutton"]') || (e.preventDefault(), M.current?.querySelector(`[data-segment="${f}"]`)?.focus());
|
|
199
|
+
};
|
|
200
|
+
return (
|
|
201
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
202
|
+
/* @__PURE__ */ $(
|
|
203
|
+
"div",
|
|
204
|
+
{
|
|
205
|
+
ref: M,
|
|
206
|
+
role: "group",
|
|
207
|
+
"aria-label": C,
|
|
208
|
+
"aria-describedby": Z,
|
|
209
|
+
"aria-invalid": ee || void 0,
|
|
210
|
+
"aria-disabled": h || void 0,
|
|
211
|
+
className: T(D.segments, B?.segments, _),
|
|
212
|
+
onMouseDown: ae,
|
|
213
|
+
children: [
|
|
214
|
+
N.map((e, t) => {
|
|
215
|
+
if (e.type === "literal")
|
|
216
|
+
return /* @__PURE__ */ R("span", { className: D.literal, "aria-hidden": "true", children: e.text }, t);
|
|
217
|
+
const r = e.type, o = t === f, l = o && E !== "", n = !i && !l, d = l ? E : n ? le[r] : e.text, P = i ? K(r, i) + (r === "month" ? 1 : 0) : void 0;
|
|
218
|
+
return /* @__PURE__ */ R(
|
|
219
|
+
"span",
|
|
220
|
+
{
|
|
221
|
+
role: "spinbutton",
|
|
222
|
+
tabIndex: h ? -1 : o ? 0 : -1,
|
|
223
|
+
"data-segment": t,
|
|
224
|
+
"aria-label": me[r],
|
|
225
|
+
"aria-valuenow": P,
|
|
226
|
+
"aria-valuetext": n ? "Empty" : r === "dayPeriod" ? e.text : void 0,
|
|
227
|
+
"aria-disabled": h || void 0,
|
|
228
|
+
className: T(D.segment, n && D.segmentEmpty, B?.segment),
|
|
229
|
+
onFocus: () => {
|
|
230
|
+
c(""), F(t);
|
|
231
|
+
},
|
|
232
|
+
onBlur: () => c(""),
|
|
233
|
+
onKeyDown: (x) => ne(x, r),
|
|
234
|
+
children: d
|
|
235
|
+
},
|
|
236
|
+
t
|
|
237
|
+
);
|
|
238
|
+
}),
|
|
239
|
+
Y && /* @__PURE__ */ $(oe, { children: [
|
|
240
|
+
" ",
|
|
241
|
+
/* @__PURE__ */ R("span", { className: T(D.suffix, X), title: V, children: Y })
|
|
242
|
+
] })
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
ye.displayName = "DateTimeSegments";
|
|
250
|
+
export {
|
|
251
|
+
ye as DateTimeSegments
|
|
252
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TimeParts } from './timeZoneUtils';
|
|
2
|
+
export interface TimeFieldClasses {
|
|
3
|
+
time: string;
|
|
4
|
+
column: string;
|
|
5
|
+
option: string;
|
|
6
|
+
optionSelected: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TimeFieldProps extends TimeParts {
|
|
9
|
+
onChange: (time: TimeParts) => void;
|
|
10
|
+
hourCycle: 12 | 24;
|
|
11
|
+
showSeconds: boolean;
|
|
12
|
+
/** Spacing of the minute options. */
|
|
13
|
+
minuteStep: number;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
classes?: Partial<TimeFieldClasses>;
|
|
16
|
+
}
|
|
17
|
+
/** Internal hours / minutes (/ seconds) (/ AM-PM) columns used by `DateTimePicker`. */
|
|
18
|
+
export declare function TimeField({ hour, minute, second, onChange, hourCycle, showSeconds, minuteStep, disabled, classes, }: TimeFieldProps): import("react/jsx-runtime").JSX.Element;
|