@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 CHANGED
@@ -75,6 +75,8 @@ For exhaustive component reference (every prop, every variant, every signature),
75
75
 
76
76
  - **Need a date input?** → `<DatePicker value onChange min max disabledDate />` — pop-up calendar, single date, binds in `FormField` (`value: Date | null`).
77
77
 
78
+ - **Need a date *and* time?** → `<DateTimePicker value onChange />` — editable segments in the field (click a part, arrows step, digits type) plus a calendar-icon popover with the calendar beside scrollable hour/minute columns (MUI-style); `hourCycle={12|24}`, `showSeconds`, `minuteStep` (default 5). Defaults: `YYYY-MM-DD HH:mm:ss UTC`, 24h, UTC, zone labelled inline after the time. The value is an absolute instant; `timeZone="system"` (or any IANA zone) edits in another wall clock (`… 17:30:00 GMT+03:00`), `fieldFormat="locale"` follows the locale order, `showTimeZone={false}` drops the label. Don't build a time picker from `DatePicker` + `NumberInput`s.
79
+
78
80
  - **Need file upload?** → `<Dropzone onFiles accept maxSize multiple />` — drag-drop or click; it emits accepted/rejected files but leaves the file-list UI to you.
79
81
 
80
82
  - **Need a countdown / stopwatch / elapsed display?** → `<Timer mode="countdown|stopwatch" duration={…} variant="digital|ring" label="…" />`. Drive it with `autoStart` + an imperative ref (`start`/`pause`/`reset`/`restart`), or make it display-only with `value`.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,39 @@ All notable changes to `@overdoser/react-toolkit` are documented here.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.16.0]
8
+
9
+ A date + time picker, and month/year jumping in the calendar header.
10
+
11
+ ### Added
12
+
13
+ - **`DateTimePicker`** — date and time in one field, binding in `FormField`
14
+ like `DatePicker` (`value: Date | null`). The field is a row of editable
15
+ segments: click one, Up/Down steps it (wrapping inside the segment),
16
+ Left/Right moves between segments, digits type with auto-advance,
17
+ Backspace clears; on an empty field the first arrow press fills in "now".
18
+ The calendar icon (or Alt+ArrowDown) opens a popover with the `DatePicker`
19
+ calendar beside scrollable hours / minutes / seconds / AM-PM columns;
20
+ picking a day keeps the time and leaves the popover open, every change
21
+ commits immediately. Defaults: `YYYY-MM-DD HH:mm:ss UTC`, 24-hour clock,
22
+ seconds on, zone badge right after the time. Props: `timeZone` (IANA name,
23
+ `'UTC'`, or `'system'` for the local zone — the value is always an absolute
24
+ instant, only the wall clock shown changes), `showTimeZone`,
25
+ `timeZoneStyle` (`GMT+03:00` by default), `fieldFormat: 'iso' | 'locale'`,
26
+ `hourCycle: 12 | 24`, `showSeconds`, `minuteStep`, `doneLabel`, plus
27
+ `min`/`max` as instants (days outside are disabled, boundary-day times
28
+ clamp). Forwards its ref to the root `<div>`. Exports `DateTimePickerProps`,
29
+ `DateTimePickerClasses`, `TimeZoneNameStyle`.
30
+
31
+ ### Changed
32
+
33
+ - **`DatePicker`** — the month and year in the calendar header are now
34
+ buttons: month opens a 12-month grid, year opens a scrollable year list
35
+ (keyboard-navigable, gated and clipped by `min`/`max`). Props, value
36
+ semantics, and the `DatePickerClasses` shape are unchanged; the month
37
+ label became a visually-hidden live region so month changes are still
38
+ announced.
39
+
7
40
  ## [0.15.0]
8
41
 
9
42
  A split button for grouped row actions, and a Dropdown positioning fix.
@@ -0,0 +1,40 @@
1
+ export interface CalendarPanelClasses {
2
+ header: string;
3
+ nav: string;
4
+ grid: string;
5
+ day: string;
6
+ daySelected: string;
7
+ dayToday: string;
8
+ dayOutside: string;
9
+ }
10
+ export interface CalendarPanelProps {
11
+ /** Month currently shown (any day within it). */
12
+ viewDate: Date;
13
+ /** Day holding roving focus; receives DOM focus on mount and whenever it changes. */
14
+ focusedDate: Date;
15
+ /** Selected day (day granularity, local midnight). */
16
+ selected: Date | null;
17
+ /** The day to mark as "today". */
18
+ today: Date;
19
+ /** Earliest / latest selectable day — gates the month and year pickers. */
20
+ minDay?: Date;
21
+ maxDay?: Date;
22
+ locale?: string;
23
+ weekStartsOn: number;
24
+ isDisabledDay: (date: Date) => boolean;
25
+ onSelect: (date: Date) => void;
26
+ onViewDateChange: (date: Date) => void;
27
+ onFocusedDateChange: (date: Date) => void;
28
+ /** Escape pressed while in the day grid. */
29
+ onEscape: () => void;
30
+ classes?: Partial<CalendarPanelClasses>;
31
+ }
32
+ /**
33
+ * Internal calendar shared by `DatePicker` and `DateTimePicker`. Owns the
34
+ * header (month / year buttons that open a month grid or a scrollable year
35
+ * grid), the weekday row, and the roving-focus keyboard model; the selected /
36
+ * focused / view dates live in the parent. Days are plain local-midnight
37
+ * `Date`s, so a parent that renders another time zone passes wall-clock
38
+ * proxies.
39
+ */
40
+ export declare function CalendarPanel({ viewDate, focusedDate, selected, today, minDay, maxDay, locale, weekStartsOn, isDisabledDay, onSelect, onViewDateChange, onFocusedDateChange, onEscape, classes, }: CalendarPanelProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,287 @@
1
+ import { jsxs as I, Fragment as U, jsx as o } from "react/jsx-runtime";
2
+ import { useRef as $, useState as q, useMemo as b, useEffect as le } from "react";
3
+ import m from "clsx";
4
+ import r from "./CalendarPanel.module.scss.js";
5
+ import { weekdayLabels as de, buildCalendarDays as ce, toISODate as x, isSameMonth as W, isSameDay as C, addMonths as F, startOfMonth as G, addDays as g } from "./dateUtils.js";
6
+ const z = 100, he = 3, me = 4;
7
+ function ve({
8
+ viewDate: l,
9
+ focusedDate: i,
10
+ selected: J,
11
+ today: Q,
12
+ minDay: p,
13
+ maxDay: f,
14
+ locale: d,
15
+ weekStartsOn: y,
16
+ isDisabledDay: S,
17
+ onSelect: V,
18
+ onViewDateChange: L,
19
+ onFocusedDateChange: E,
20
+ onEscape: X,
21
+ classes: u
22
+ }) {
23
+ const H = $(null), T = $(null), [c, N] = q("day"), [s, R] = q(0), h = l.getFullYear(), k = l.getMonth(), Z = b(
24
+ () => new Intl.DateTimeFormat(d, { month: "long", year: "numeric" }).format(l),
25
+ [d, l]
26
+ ), D = b(() => new Intl.DateTimeFormat(d, { month: "long" }).format(l), [d, l]), ee = b(() => new Intl.DateTimeFormat(d, { year: "numeric" }).format(l), [d, l]), te = b(() => {
27
+ const e = new Intl.DateTimeFormat(d, { month: "short" }), t = new Intl.DateTimeFormat(d, { month: "long" });
28
+ return Array.from({ length: 12 }, (a, n) => {
29
+ const A = new Date(2023, n, 1);
30
+ return { short: e.format(A), long: t.format(A) };
31
+ });
32
+ }, [d]), w = b(() => {
33
+ let e = p ? p.getFullYear() : h - z, t = f ? f.getFullYear() : h + z;
34
+ return e = Math.min(e, h), t = Math.max(t, h), Array.from({ length: t - e + 1 }, (a, n) => e + n);
35
+ }, [p, f, h]), ne = b(() => de(d, y), [d, y]), re = b(() => ce(l, y), [l, y]), ae = b(() => new Intl.DateTimeFormat(d, { dateStyle: "full" }), [d]), Y = (e) => {
36
+ const t = new Date(h, e, 1), a = new Date(h, e + 1, 0);
37
+ return !!f && t > f || !!p && a < p;
38
+ }, K = (e) => !!f && new Date(e, 0, 1) > f || !!p && new Date(e, 11, 31) < p;
39
+ le(() => {
40
+ if (c === "day") {
41
+ H.current?.querySelector(`[data-date="${x(i)}"]`)?.focus();
42
+ return;
43
+ }
44
+ const e = T.current, t = e?.querySelector("[data-active]");
45
+ e && t && (e.scrollTop = t.offsetTop - e.clientHeight / 2 + t.offsetHeight / 2, t.focus());
46
+ }, [c, i, s]);
47
+ const oe = (e) => {
48
+ E(e), W(e, l) || L(G(e));
49
+ }, P = (e) => {
50
+ S(e) || V(e);
51
+ }, _ = (e) => {
52
+ if (c === e) {
53
+ N("day");
54
+ return;
55
+ }
56
+ R(e === "month" ? k : w.indexOf(h)), N(e);
57
+ }, M = (e, t) => {
58
+ const a = new Date(e, t + 1, 0).getDate(), n = new Date(e, t, Math.min(i.getDate(), a));
59
+ E(n), L(G(n)), N("day");
60
+ }, ie = (e) => {
61
+ let t = null;
62
+ switch (e.key) {
63
+ case "ArrowLeft":
64
+ t = g(i, -1);
65
+ break;
66
+ case "ArrowRight":
67
+ t = g(i, 1);
68
+ break;
69
+ case "ArrowUp":
70
+ t = g(i, -7);
71
+ break;
72
+ case "ArrowDown":
73
+ t = g(i, 7);
74
+ break;
75
+ case "Home":
76
+ t = g(i, -((i.getDay() - y + 7) % 7));
77
+ break;
78
+ case "End":
79
+ t = g(i, 6 - (i.getDay() - y + 7) % 7);
80
+ break;
81
+ case "PageUp":
82
+ t = F(i, -1);
83
+ break;
84
+ case "PageDown":
85
+ t = F(i, 1);
86
+ break;
87
+ case "Enter":
88
+ case " ":
89
+ e.preventDefault(), P(i);
90
+ return;
91
+ case "Escape":
92
+ e.preventDefault(), X();
93
+ return;
94
+ default:
95
+ return;
96
+ }
97
+ e.preventDefault(), oe(t);
98
+ }, j = (e, t, a) => {
99
+ let n = s;
100
+ switch (e.key) {
101
+ case "ArrowLeft":
102
+ n = s - 1;
103
+ break;
104
+ case "ArrowRight":
105
+ n = s + 1;
106
+ break;
107
+ case "ArrowUp":
108
+ n = s - a;
109
+ break;
110
+ case "ArrowDown":
111
+ n = s + a;
112
+ break;
113
+ case "Home":
114
+ n = 0;
115
+ break;
116
+ case "End":
117
+ n = t - 1;
118
+ break;
119
+ case "Enter":
120
+ case " ":
121
+ e.preventDefault(), c === "month" ? Y(s) || M(h, s) : K(w[s]) || M(w[s], k);
122
+ return;
123
+ case "Escape":
124
+ e.preventDefault(), N("day");
125
+ return;
126
+ default:
127
+ return;
128
+ }
129
+ e.preventDefault(), R(Math.max(0, Math.min(t - 1, n)));
130
+ }, v = c === "year", B = c === "day" ? "month" : "year", O = (e) => L(c === "day" ? F(l, e) : new Date(h + e, k, 1));
131
+ return /* @__PURE__ */ I(U, { children: [
132
+ /* @__PURE__ */ I("div", { className: m(r.header, u?.header), children: [
133
+ /* @__PURE__ */ o(
134
+ "button",
135
+ {
136
+ type: "button",
137
+ className: m(r.nav, v && r.navHidden, u?.nav),
138
+ onClick: () => O(-1),
139
+ "aria-label": `Previous ${B}`,
140
+ "aria-hidden": v || void 0,
141
+ tabIndex: v ? -1 : void 0,
142
+ children: /* @__PURE__ */ o("svg", { viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { d: "M7 2L3 6l4 4" }) })
143
+ }
144
+ ),
145
+ /* @__PURE__ */ I("div", { className: r.title, children: [
146
+ /* @__PURE__ */ o(
147
+ "button",
148
+ {
149
+ type: "button",
150
+ className: r.titleButton,
151
+ "aria-label": "Choose month",
152
+ "aria-expanded": c === "month",
153
+ onClick: () => _("month"),
154
+ children: D
155
+ }
156
+ ),
157
+ /* @__PURE__ */ o(
158
+ "button",
159
+ {
160
+ type: "button",
161
+ className: r.titleButton,
162
+ "aria-label": "Choose year",
163
+ "aria-expanded": c === "year",
164
+ onClick: () => _("year"),
165
+ children: ee
166
+ }
167
+ ),
168
+ /* @__PURE__ */ o("span", { className: r.srOnly, "aria-live": "polite", children: Z })
169
+ ] }),
170
+ /* @__PURE__ */ o(
171
+ "button",
172
+ {
173
+ type: "button",
174
+ className: m(r.nav, v && r.navHidden, u?.nav),
175
+ onClick: () => O(1),
176
+ "aria-label": `Next ${B}`,
177
+ "aria-hidden": v || void 0,
178
+ tabIndex: v ? -1 : void 0,
179
+ children: /* @__PURE__ */ o("svg", { viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { d: "M5 2l4 4-4 4" }) })
180
+ }
181
+ )
182
+ ] }),
183
+ c === "month" && // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
184
+ /* @__PURE__ */ o(
185
+ "div",
186
+ {
187
+ ref: T,
188
+ role: "listbox",
189
+ "aria-label": "Month",
190
+ className: m(r.options, r.months),
191
+ onKeyDown: (e) => j(e, 12, he),
192
+ children: te.map((e, t) => {
193
+ const a = Y(t), n = t === k;
194
+ return /* @__PURE__ */ o(
195
+ "button",
196
+ {
197
+ type: "button",
198
+ role: "option",
199
+ "aria-selected": n,
200
+ "aria-disabled": a || void 0,
201
+ "aria-label": e.long,
202
+ tabIndex: t === s ? 0 : -1,
203
+ "data-active": t === s || void 0,
204
+ className: m(r.option, n && r.optionSelected),
205
+ onClick: () => !a && M(h, t),
206
+ children: e.short
207
+ },
208
+ t
209
+ );
210
+ })
211
+ }
212
+ ),
213
+ c === "year" && // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
214
+ /* @__PURE__ */ o(
215
+ "div",
216
+ {
217
+ ref: T,
218
+ role: "listbox",
219
+ "aria-label": "Year",
220
+ className: m(r.options, r.years),
221
+ onKeyDown: (e) => j(e, w.length, me),
222
+ children: w.map((e, t) => {
223
+ const a = K(e), n = e === h;
224
+ return /* @__PURE__ */ o(
225
+ "button",
226
+ {
227
+ type: "button",
228
+ role: "option",
229
+ "aria-selected": n,
230
+ "aria-disabled": a || void 0,
231
+ tabIndex: t === s ? 0 : -1,
232
+ "data-active": t === s || void 0,
233
+ className: m(r.option, n && r.optionSelected),
234
+ onClick: () => !a && M(e, k),
235
+ children: e
236
+ },
237
+ e
238
+ );
239
+ })
240
+ }
241
+ ),
242
+ c === "day" && /* @__PURE__ */ I(U, { children: [
243
+ /* @__PURE__ */ o("div", { className: r.weekdays, "aria-hidden": "true", children: ne.map((e, t) => /* @__PURE__ */ o("span", { className: r.weekday, children: e }, t)) }),
244
+ /* @__PURE__ */ o(
245
+ "div",
246
+ {
247
+ ref: H,
248
+ role: "grid",
249
+ className: m(r.grid, u?.grid),
250
+ onKeyDown: ie,
251
+ children: re.map((e) => {
252
+ const t = !W(e, l), a = C(e, J), n = C(e, Q), A = S(e), se = C(e, i);
253
+ return /* @__PURE__ */ o(
254
+ "button",
255
+ {
256
+ type: "button",
257
+ role: "gridcell",
258
+ "data-date": x(e),
259
+ tabIndex: se ? 0 : -1,
260
+ className: m(
261
+ r.day,
262
+ t && r.dayOutside,
263
+ n && r.dayToday,
264
+ a && r.daySelected,
265
+ t && u?.dayOutside,
266
+ n && u?.dayToday,
267
+ a && u?.daySelected,
268
+ u?.day
269
+ ),
270
+ "aria-selected": a,
271
+ "aria-disabled": A || void 0,
272
+ "aria-current": n ? "date" : void 0,
273
+ "aria-label": ae.format(e),
274
+ onClick: () => P(e),
275
+ children: e.getDate()
276
+ },
277
+ x(e)
278
+ );
279
+ })
280
+ }
281
+ )
282
+ ] })
283
+ ] });
284
+ }
285
+ export {
286
+ ve as CalendarPanel
287
+ };
@@ -0,0 +1,41 @@
1
+ const t = "crk-header-T9XMb", e = "crk-nav-iAxYo", o = "crk-weekdays-TV4PD", n = "crk-grid--96pQ", c = "crk-weekday--syM1", d = "crk-day-m-HUr", s = "crk-dayOutside-x2kQk", a = "crk-dayToday-qIjS-", r = "crk-daySelected-iA4S4", y = "crk-title-68NVZ", i = "crk-titleButton-9V2YZ", k = "crk-srOnly-4nytm", l = "crk-navHidden-QhiL0", p = "crk-options-b8L5n", S = "crk-months-b-CoG", h = "crk-years-QGvpU", u = "crk-option-kbY30", v = "crk-optionSelected-as-xo", w = {
2
+ header: t,
3
+ nav: e,
4
+ weekdays: o,
5
+ grid: n,
6
+ weekday: c,
7
+ day: d,
8
+ dayOutside: s,
9
+ dayToday: a,
10
+ daySelected: r,
11
+ title: y,
12
+ titleButton: i,
13
+ srOnly: k,
14
+ navHidden: l,
15
+ options: p,
16
+ months: S,
17
+ years: h,
18
+ option: u,
19
+ optionSelected: v
20
+ };
21
+ export {
22
+ d as day,
23
+ s as dayOutside,
24
+ r as daySelected,
25
+ a as dayToday,
26
+ w as default,
27
+ n as grid,
28
+ t as header,
29
+ S as months,
30
+ e as nav,
31
+ l as navHidden,
32
+ u as option,
33
+ v as optionSelected,
34
+ p as options,
35
+ k as srOnly,
36
+ y as title,
37
+ i as titleButton,
38
+ c as weekday,
39
+ o as weekdays,
40
+ h as years
41
+ };
@@ -50,7 +50,9 @@ export interface DatePickerProps {
50
50
  /**
51
51
  * Date input with a pop-up calendar. Single date selection with full keyboard
52
52
  * support (arrows move days, PageUp/Down change month, Enter selects, Esc
53
- * closes). Binds inside `FormField` (`value: Date | null` / `onChange`).
53
+ * closes); the month and year in the header open a month grid / year list
54
+ * for long jumps. Binds inside `FormField` (`value: Date | null` / `onChange`).
55
+ * Need a time as well? Use `DateTimePicker`.
54
56
  *
55
57
  * @example
56
58
  * <DatePicker value={date} onChange={setDate} min={new Date()} />