@overdoser/react-toolkit 0.15.0 → 0.16.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 +33 -0
- 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 +93 -186
- 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 +230 -0
- package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +37 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.d.ts +47 -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/index.css +1 -1
- package/index.d.ts +2 -0
- package/index.js +108 -106
- package/index.layered.css +1 -1
- package/llms.txt +26 -2
- package/manifest.json +127 -1
- package/package.json +1 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsxs as H, jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as b, useRef as g, useEffect as w } from "react";
|
|
3
|
+
import x from "clsx";
|
|
4
|
+
import S from "./DateTimePicker.module.scss.js";
|
|
5
|
+
const y = (n) => String(n).padStart(2, "0");
|
|
6
|
+
function A(n, r, l) {
|
|
7
|
+
const a = /* @__PURE__ */ new Set();
|
|
8
|
+
for (let o = 0; o <= n; o += Math.max(1, Math.floor(r))) a.add(o);
|
|
9
|
+
return a.add(l), Array.from(a).sort((o, f) => o - f).map((o) => ({ value: o, label: y(o) }));
|
|
10
|
+
}
|
|
11
|
+
function v({ label: n, items: r, selected: l, onSelect: a, disabled: o, classes: f }) {
|
|
12
|
+
const m = g(null), u = g(!1);
|
|
13
|
+
w(() => {
|
|
14
|
+
const e = m.current, t = e?.querySelector('[aria-selected="true"]');
|
|
15
|
+
e && t && (e.scrollTop = t.offsetTop - e.clientHeight / 2 + t.offsetHeight / 2);
|
|
16
|
+
}, []), w(() => {
|
|
17
|
+
if (!u.current) return;
|
|
18
|
+
u.current = !1;
|
|
19
|
+
const e = m.current?.querySelector('[aria-selected="true"]');
|
|
20
|
+
e?.focus(), e?.scrollIntoView?.({ block: "nearest" });
|
|
21
|
+
}, [l]);
|
|
22
|
+
const i = (e) => {
|
|
23
|
+
const t = r.findIndex((h) => h.value === l);
|
|
24
|
+
let s = t;
|
|
25
|
+
switch (e.key) {
|
|
26
|
+
case "ArrowDown":
|
|
27
|
+
s = (t + 1) % r.length;
|
|
28
|
+
break;
|
|
29
|
+
case "ArrowUp":
|
|
30
|
+
s = (t - 1 + r.length) % r.length;
|
|
31
|
+
break;
|
|
32
|
+
case "Home":
|
|
33
|
+
s = 0;
|
|
34
|
+
break;
|
|
35
|
+
case "End":
|
|
36
|
+
s = r.length - 1;
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
e.preventDefault(), s !== t && (u.current = !0, a(r[s].value));
|
|
42
|
+
};
|
|
43
|
+
return (
|
|
44
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
45
|
+
/* @__PURE__ */ d(
|
|
46
|
+
"div",
|
|
47
|
+
{
|
|
48
|
+
ref: m,
|
|
49
|
+
role: "listbox",
|
|
50
|
+
"aria-label": n,
|
|
51
|
+
className: x(S.column, f?.column),
|
|
52
|
+
onKeyDown: i,
|
|
53
|
+
children: r.map((e) => {
|
|
54
|
+
const t = e.value === l;
|
|
55
|
+
return /* @__PURE__ */ d(
|
|
56
|
+
"button",
|
|
57
|
+
{
|
|
58
|
+
type: "button",
|
|
59
|
+
role: "option",
|
|
60
|
+
"aria-selected": t,
|
|
61
|
+
tabIndex: t ? 0 : -1,
|
|
62
|
+
disabled: o,
|
|
63
|
+
className: x(S.option, t && S.optionSelected, f?.option, t && f?.optionSelected),
|
|
64
|
+
onClick: () => a(e.value),
|
|
65
|
+
children: e.label
|
|
66
|
+
},
|
|
67
|
+
e.value
|
|
68
|
+
);
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function j({
|
|
75
|
+
hour: n,
|
|
76
|
+
minute: r,
|
|
77
|
+
second: l,
|
|
78
|
+
onChange: a,
|
|
79
|
+
hourCycle: o,
|
|
80
|
+
showSeconds: f,
|
|
81
|
+
minuteStep: m,
|
|
82
|
+
disabled: u,
|
|
83
|
+
classes: i
|
|
84
|
+
}) {
|
|
85
|
+
const e = o === 12, t = n >= 12, s = b(() => e ? Array.from({ length: 12 }, (c, p) => ({ value: p + (t ? 12 : 0), label: y(p === 0 ? 12 : p) })) : Array.from({ length: 24 }, (c, p) => ({ value: p, label: y(p) })), [e, t]), h = b(() => A(59, m, r), [m, r]), M = b(() => A(59, 1, l), [l]), k = b(() => [{ value: 0, label: "AM" }, { value: 1, label: "PM" }], []);
|
|
86
|
+
return /* @__PURE__ */ H("div", { className: x(S.time, i?.time), role: "group", "aria-label": "Time", children: [
|
|
87
|
+
/* @__PURE__ */ d(
|
|
88
|
+
v,
|
|
89
|
+
{
|
|
90
|
+
label: "Hours",
|
|
91
|
+
items: s,
|
|
92
|
+
selected: n,
|
|
93
|
+
onSelect: (c) => a({ hour: c, minute: r, second: l }),
|
|
94
|
+
disabled: u,
|
|
95
|
+
classes: i
|
|
96
|
+
}
|
|
97
|
+
),
|
|
98
|
+
/* @__PURE__ */ d(
|
|
99
|
+
v,
|
|
100
|
+
{
|
|
101
|
+
label: "Minutes",
|
|
102
|
+
items: h,
|
|
103
|
+
selected: r,
|
|
104
|
+
onSelect: (c) => a({ hour: n, minute: c, second: l }),
|
|
105
|
+
disabled: u,
|
|
106
|
+
classes: i
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
f && /* @__PURE__ */ d(
|
|
110
|
+
v,
|
|
111
|
+
{
|
|
112
|
+
label: "Seconds",
|
|
113
|
+
items: M,
|
|
114
|
+
selected: l,
|
|
115
|
+
onSelect: (c) => a({ hour: n, minute: r, second: c }),
|
|
116
|
+
disabled: u,
|
|
117
|
+
classes: i
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
e && /* @__PURE__ */ d(
|
|
121
|
+
v,
|
|
122
|
+
{
|
|
123
|
+
label: "AM/PM",
|
|
124
|
+
items: k,
|
|
125
|
+
selected: t ? 1 : 0,
|
|
126
|
+
onSelect: (c) => a({ hour: n % 12 + (c ? 12 : 0), minute: r, second: l }),
|
|
127
|
+
disabled: u,
|
|
128
|
+
classes: i
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
] });
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
j as TimeField
|
|
135
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wall-clock ⇄ instant conversion for an arbitrary IANA time zone, built on
|
|
3
|
+
* `Intl.DateTimeFormat` only (no date library). When `timeZone` is undefined
|
|
4
|
+
* every helper falls back to the plain local `Date` getters/constructor, so
|
|
5
|
+
* the default path is byte-for-byte what `DatePicker` does.
|
|
6
|
+
*/
|
|
7
|
+
export interface WallClock {
|
|
8
|
+
year: number;
|
|
9
|
+
/** 0-based, like `Date#getMonth`. */
|
|
10
|
+
month: number;
|
|
11
|
+
day: number;
|
|
12
|
+
hour: number;
|
|
13
|
+
minute: number;
|
|
14
|
+
second: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TimeParts {
|
|
17
|
+
hour: number;
|
|
18
|
+
minute: number;
|
|
19
|
+
second: number;
|
|
20
|
+
}
|
|
21
|
+
/** `true` when `Intl` accepts `timeZone` (IANA name, `'UTC'`, or an alias). */
|
|
22
|
+
export declare function isValidTimeZone(timeZone: string): boolean;
|
|
23
|
+
/** The runtime's local IANA zone (e.g. `'Europe/Bucharest'`). */
|
|
24
|
+
export declare function localTimeZone(): string;
|
|
25
|
+
/** Wall-clock fields of `date` as seen in `timeZone` (local zone when omitted). */
|
|
26
|
+
export declare function getWallClock(date: Date, timeZone?: string): WallClock;
|
|
27
|
+
/**
|
|
28
|
+
* The instant whose wall clock in `timeZone` reads `wc` (local zone when
|
|
29
|
+
* omitted). In a DST overlap (a wall-clock time that happens twice) the
|
|
30
|
+
* earlier instant wins; in a gap (a time that never happens) the result is
|
|
31
|
+
* shifted forward by the gap — the resolution most date libraries use.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fromWallClock(wc: WallClock, timeZone?: string): Date;
|
|
34
|
+
/** Local-midnight `Date` for the wall-clock day — the key the calendar grid works with. */
|
|
35
|
+
export declare function wallClockDay(wc: WallClock): Date;
|
|
36
|
+
export type TimeZoneNameStyle = 'short' | 'long' | 'shortOffset' | 'longOffset';
|
|
37
|
+
/**
|
|
38
|
+
* Localized zone name for `timeZone` at `date` (e.g. `'EDT'`, `'GMT+3'`,
|
|
39
|
+
* `'Coordinated Universal Time'`). Offset styles fall back to `'short'` on
|
|
40
|
+
* older ICU builds that don't support them.
|
|
41
|
+
*/
|
|
42
|
+
export declare function timeZoneName(date: Date, timeZone: string | undefined, locale?: string, style?: TimeZoneNameStyle): string;
|
|
43
|
+
/** Default hour cycle for `locale` (12 for en-US, 24 for most of Europe). */
|
|
44
|
+
export declare function localeHourCycle(locale?: string): 12 | 24;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const i = /* @__PURE__ */ new Map();
|
|
2
|
+
function c(e) {
|
|
3
|
+
let t = i.get(e);
|
|
4
|
+
return t || (t = new Intl.DateTimeFormat("en-US", {
|
|
5
|
+
timeZone: e,
|
|
6
|
+
hourCycle: "h23",
|
|
7
|
+
year: "numeric",
|
|
8
|
+
month: "numeric",
|
|
9
|
+
day: "numeric",
|
|
10
|
+
hour: "numeric",
|
|
11
|
+
minute: "numeric",
|
|
12
|
+
second: "numeric"
|
|
13
|
+
}), i.set(e, t)), t;
|
|
14
|
+
}
|
|
15
|
+
function h(e) {
|
|
16
|
+
try {
|
|
17
|
+
return c(e), !0;
|
|
18
|
+
} catch {
|
|
19
|
+
return !1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function y() {
|
|
23
|
+
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24
|
+
}
|
|
25
|
+
function f(e, t) {
|
|
26
|
+
if (!t)
|
|
27
|
+
return {
|
|
28
|
+
year: e.getFullYear(),
|
|
29
|
+
month: e.getMonth(),
|
|
30
|
+
day: e.getDate(),
|
|
31
|
+
hour: e.getHours(),
|
|
32
|
+
minute: e.getMinutes(),
|
|
33
|
+
second: e.getSeconds()
|
|
34
|
+
};
|
|
35
|
+
const n = { year: 0, month: 0, day: 1, hour: 0, minute: 0, second: 0 };
|
|
36
|
+
for (const r of c(t).formatToParts(e))
|
|
37
|
+
switch (r.type) {
|
|
38
|
+
case "year":
|
|
39
|
+
n.year = Number(r.value);
|
|
40
|
+
break;
|
|
41
|
+
case "month":
|
|
42
|
+
n.month = Number(r.value) - 1;
|
|
43
|
+
break;
|
|
44
|
+
case "day":
|
|
45
|
+
n.day = Number(r.value);
|
|
46
|
+
break;
|
|
47
|
+
case "hour":
|
|
48
|
+
n.hour = Number(r.value) % 24;
|
|
49
|
+
break;
|
|
50
|
+
case "minute":
|
|
51
|
+
n.minute = Number(r.value);
|
|
52
|
+
break;
|
|
53
|
+
case "second":
|
|
54
|
+
n.second = Number(r.value);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
return n;
|
|
58
|
+
}
|
|
59
|
+
function l(e) {
|
|
60
|
+
const t = /* @__PURE__ */ new Date(0);
|
|
61
|
+
return t.setUTCFullYear(e.year, e.month, e.day), t.setUTCHours(e.hour, e.minute, e.second, 0), t.getTime();
|
|
62
|
+
}
|
|
63
|
+
function s(e, t) {
|
|
64
|
+
return l(f(e, t)) - Math.floor(e.getTime() / 1e3) * 1e3;
|
|
65
|
+
}
|
|
66
|
+
function d(e, t) {
|
|
67
|
+
if (!t) {
|
|
68
|
+
const a = new Date(e.year, e.month, e.day, e.hour, e.minute, e.second, 0);
|
|
69
|
+
return e.year >= 0 && e.year < 100 && a.setFullYear(e.year), a;
|
|
70
|
+
}
|
|
71
|
+
const n = l(e), r = 864e5, u = new Set([n - r, n, n + r].map((a) => s(new Date(a), t))), o = [];
|
|
72
|
+
for (const a of u) {
|
|
73
|
+
const m = n - a;
|
|
74
|
+
s(new Date(m), t) === a && o.push(m);
|
|
75
|
+
}
|
|
76
|
+
return o.length > 0 ? new Date(Math.min(...o)) : new Date(n - s(new Date(n - r), t));
|
|
77
|
+
}
|
|
78
|
+
function D(e) {
|
|
79
|
+
const t = new Date(e.year, e.month, e.day);
|
|
80
|
+
return e.year >= 0 && e.year < 100 && t.setFullYear(e.year), t;
|
|
81
|
+
}
|
|
82
|
+
function b(e, t, n, r = "short") {
|
|
83
|
+
const u = (o) => new Intl.DateTimeFormat(n, { timeZone: t, timeZoneName: o }).formatToParts(e).find((a) => a.type === "timeZoneName")?.value ?? "";
|
|
84
|
+
try {
|
|
85
|
+
return u(r);
|
|
86
|
+
} catch {
|
|
87
|
+
return u("short");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function T(e) {
|
|
91
|
+
const t = new Intl.DateTimeFormat(e, { hour: "numeric" }).resolvedOptions().hourCycle;
|
|
92
|
+
return t === "h11" || t === "h12" ? 12 : 24;
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
d as fromWallClock,
|
|
96
|
+
f as getWallClock,
|
|
97
|
+
h as isValidTimeZone,
|
|
98
|
+
y as localTimeZone,
|
|
99
|
+
T as localeHourCycle,
|
|
100
|
+
b as timeZoneName,
|
|
101
|
+
D as wallClockDay
|
|
102
|
+
};
|