@nepdatejs/react 0.0.0-bootstrap → 0.1.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -1
  3. package/dist/date-text-BT82cZ7i.cjs +84 -0
  4. package/dist/date-text-BT82cZ7i.cjs.map +1 -0
  5. package/dist/date-text-Df1gFksR.js +61 -0
  6. package/dist/date-text-Df1gFksR.js.map +1 -0
  7. package/dist/date-text-Dipetpbp.d.cts +37 -0
  8. package/dist/date-text-Dipetpbp.d.ts +37 -0
  9. package/dist/headless-6BuUOtOR.d.cts +194 -0
  10. package/dist/headless-BK0XRHKb.js +513 -0
  11. package/dist/headless-BK0XRHKb.js.map +1 -0
  12. package/dist/headless-CFZ06zLn.d.ts +194 -0
  13. package/dist/headless-HxTkvgbz.cjs +572 -0
  14. package/dist/headless-HxTkvgbz.cjs.map +1 -0
  15. package/dist/headless.cjs +11 -0
  16. package/dist/headless.d.cts +2 -0
  17. package/dist/headless.d.ts +2 -0
  18. package/dist/headless.js +2 -0
  19. package/dist/index.cjs +891 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +245 -0
  22. package/dist/index.d.ts +245 -0
  23. package/dist/index.js +871 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/server.cjs +6 -0
  26. package/dist/server.d.cts +2 -0
  27. package/dist/server.d.ts +2 -0
  28. package/dist/server.js +1 -0
  29. package/package.json +107 -4
  30. package/src/bindings.ts +247 -0
  31. package/src/calendar-body.tsx +133 -0
  32. package/src/calendar.tsx +34 -0
  33. package/src/date-picker.tsx +350 -0
  34. package/src/date-range-picker.tsx +223 -0
  35. package/src/date-text.tsx +110 -0
  36. package/src/date-time-picker.tsx +287 -0
  37. package/src/headless.ts +21 -0
  38. package/src/hooks.ts +474 -0
  39. package/src/icons.tsx +35 -0
  40. package/src/index.ts +21 -0
  41. package/src/multi-date-picker.tsx +243 -0
  42. package/src/panel.ts +67 -0
  43. package/src/presets.tsx +44 -0
  44. package/src/server.ts +8 -0
  45. package/src/time-columns.tsx +60 -0
  46. package/src/use-store.ts +113 -0
package/dist/index.js ADDED
@@ -0,0 +1,871 @@
1
+ "use client";
2
+ import { a as useDateTimePicker, c as useIsomorphicLayoutEffect, i as useDateRangePicker, l as useStore, n as useCalendar, o as useMultiDatePicker, r as useDatePicker, s as deepEqual, t as popupProps, u as useCalendarBindings } from "./headless-BK0XRHKb.js";
3
+ import { i as shortDate, n as ShortDate, r as bothDates, t as DateText } from "./date-text-Df1gFksR.js";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { useEffect, useRef } from "react";
6
+ import { getLocale } from "@nepdatejs/core";
7
+ import { onBackdropPointer, onEscape, onOutsidePointer, restoreFocus, trackPosition } from "@nepdatejs/dom";
8
+ //#region src/icons.tsx
9
+ const PATHS = {
10
+ "chevron-left": ["M10 3.5 5.5 8l4.5 4.5"],
11
+ "chevron-right": ["M6 3.5 10.5 8 6 12.5"],
12
+ calendar: [
13
+ "M2 6.5h12",
14
+ "M5.5 1.5v3",
15
+ "M10.5 1.5v3",
16
+ "M4 3h8a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2Z"
17
+ ],
18
+ close: ["M4 4l8 8", "M12 4l-8 8"]
19
+ };
20
+ /** The Figma icon set, 16px, stroked with currentColor. */
21
+ function Icon({ name }) {
22
+ return /* @__PURE__ */ jsx("svg", {
23
+ viewBox: "0 0 16 16",
24
+ fill: "none",
25
+ stroke: "currentColor",
26
+ strokeWidth: 1.5,
27
+ strokeLinecap: "round",
28
+ strokeLinejoin: "round",
29
+ "aria-hidden": "true",
30
+ focusable: "false",
31
+ children: PATHS[name].map((d) => /* @__PURE__ */ jsx("path", { d }, d))
32
+ });
33
+ }
34
+ //#endregion
35
+ //#region src/calendar-body.tsx
36
+ /** The calendar markup (@nepdatejs/styles contract) for any set of bindings. */
37
+ function CalendarBody({ bindings, className, theme }) {
38
+ const { state } = bindings;
39
+ const tiles = state.view === "month" ? state.months : state.view === "year" ? state.years : state.fiscalYears;
40
+ return /* @__PURE__ */ jsxs("div", {
41
+ className: className ? `ndp-calendar ${className}` : "ndp-calendar",
42
+ "data-ndp-theme": theme,
43
+ children: [/* @__PURE__ */ jsxs("div", {
44
+ className: "ndp-calendar__header",
45
+ children: [
46
+ /* @__PURE__ */ jsx("button", {
47
+ className: "ndp-icon-button",
48
+ ...bindings.getPrevProps(),
49
+ children: /* @__PURE__ */ jsx(Icon, { name: "chevron-left" })
50
+ }),
51
+ /* @__PURE__ */ jsx("div", {
52
+ className: "ndp-calendar__title",
53
+ "aria-live": "polite",
54
+ children: bindings.getTitleButtons().map((button) => /* @__PURE__ */ jsx("button", {
55
+ className: "ndp-calendar__title-button",
56
+ ...button.props,
57
+ children: button.label
58
+ }, button.key))
59
+ }),
60
+ /* @__PURE__ */ jsx("button", {
61
+ className: "ndp-icon-button",
62
+ ...bindings.getNextProps(),
63
+ children: /* @__PURE__ */ jsx(Icon, { name: "chevron-right" })
64
+ })
65
+ ]
66
+ }), state.view === "day" ? /* @__PURE__ */ jsxs("table", {
67
+ className: "ndp-grid",
68
+ ...bindings.getGridProps(),
69
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", {
70
+ role: "row",
71
+ children: state.weekdays.map((weekday) => /* @__PURE__ */ jsx("th", {
72
+ className: "ndp-weekday",
73
+ scope: "col",
74
+ role: "columnheader",
75
+ abbr: weekday.longLabel,
76
+ "data-weekend": weekday.isWeekend || void 0,
77
+ children: weekday.label
78
+ }, weekday.index))
79
+ }) }), /* @__PURE__ */ jsx("tbody", { children: state.weeks.map((week, row) => /* @__PURE__ */ jsx("tr", {
80
+ role: "row",
81
+ children: week.map((cell, column) => cell ? /* @__PURE__ */ jsx("td", {
82
+ role: "gridcell",
83
+ "aria-selected": cell.isSelected || void 0,
84
+ children: /* @__PURE__ */ jsxs("button", {
85
+ className: "ndp-day",
86
+ ...bindings.getDayProps(cell),
87
+ children: [
88
+ /* @__PURE__ */ jsx("span", {
89
+ className: "ndp-sr-only",
90
+ children: cell.ariaLabel
91
+ }),
92
+ /* @__PURE__ */ jsx("span", {
93
+ className: "ndp-day__label",
94
+ "aria-hidden": "true",
95
+ children: cell.label
96
+ }),
97
+ cell.subLabel !== null && /* @__PURE__ */ jsx("span", {
98
+ className: "ndp-day__sub",
99
+ "aria-hidden": "true",
100
+ children: cell.subLabel
101
+ }),
102
+ cell.events[0] && /* @__PURE__ */ jsx("span", {
103
+ className: "ndp-day__dot",
104
+ "aria-hidden": "true",
105
+ style: cell.events[0].color ? { "--ndp-dot-color": cell.events[0].color } : void 0
106
+ })
107
+ ]
108
+ })
109
+ }, cell.key) : /* @__PURE__ */ jsx("td", { role: "gridcell" }, `empty-${column}`))
110
+ }, row)) })]
111
+ }) : /* @__PURE__ */ jsx("div", {
112
+ className: "ndp-options",
113
+ role: "group",
114
+ "aria-label": state.title,
115
+ children: tiles.map((tile, index) => /* @__PURE__ */ jsxs("button", {
116
+ className: "ndp-option",
117
+ ...bindings.getOptionProps(tile, index, tiles),
118
+ children: [
119
+ /* @__PURE__ */ jsx("span", {
120
+ className: "ndp-sr-only",
121
+ children: tile.subLabel ? `${tile.label} (${tile.subLabel})` : tile.label
122
+ }),
123
+ /* @__PURE__ */ jsx("span", {
124
+ className: "ndp-option__label",
125
+ "aria-hidden": "true",
126
+ children: tile.label
127
+ }),
128
+ tile.subLabel !== null && /* @__PURE__ */ jsx("span", {
129
+ className: "ndp-option__sub",
130
+ "aria-hidden": "true",
131
+ children: tile.subLabel
132
+ })
133
+ ]
134
+ }, tile.value))
135
+ })]
136
+ });
137
+ }
138
+ //#endregion
139
+ //#region src/calendar.tsx
140
+ /** A standalone BS/AD month view with keyboard support. */
141
+ function Calendar({ month, onMonthChange, className, theme, ...options }) {
142
+ const bindings = useCalendar({
143
+ ...options,
144
+ visibleMonth: month,
145
+ onVisibleMonthChange: onMonthChange
146
+ });
147
+ return /* @__PURE__ */ jsx(CalendarBody, {
148
+ bindings,
149
+ className,
150
+ theme
151
+ });
152
+ }
153
+ //#endregion
154
+ //#region src/panel.ts
155
+ /**
156
+ * While `open`: show the panel in the top layer beside the anchor, close on an
157
+ * outside pointer, a tap on a bottom sheet's backdrop, or Escape (returning focus to `returnFocus`), and move focus
158
+ * into the calendar.
159
+ */
160
+ function usePanel(open, refs, close, focusGrid, width = 320, layout = "auto") {
161
+ const closeRef = useRef(close);
162
+ closeRef.current = close;
163
+ useIsomorphicLayoutEffect(() => {
164
+ const anchor = refs.anchor.current;
165
+ const panel = refs.panel.current;
166
+ if (!open || !anchor || !panel) return;
167
+ const stopTracking = trackPosition(anchor, panel, {
168
+ width,
169
+ layout
170
+ });
171
+ const stopOutside = onOutsidePointer(() => [refs.field.current, refs.panel.current], () => {
172
+ closeRef.current();
173
+ });
174
+ const stopBackdrop = onBackdropPointer(panel, () => {
175
+ closeRef.current();
176
+ });
177
+ const stopEscape = onEscape(() => {
178
+ closeRef.current();
179
+ restoreFocus(refs.returnFocus.current);
180
+ });
181
+ return () => {
182
+ stopTracking();
183
+ stopOutside();
184
+ stopBackdrop();
185
+ stopEscape();
186
+ };
187
+ }, [
188
+ open,
189
+ width,
190
+ layout
191
+ ]);
192
+ useEffect(() => {
193
+ if (open) focusGrid();
194
+ }, [open]);
195
+ }
196
+ //#endregion
197
+ //#region src/presets.tsx
198
+ /** The panel body: the shortcut list (when there are presets), then the calendar and anything else. */
199
+ function PanelBody({ presets, label, onPreset, children }) {
200
+ return /* @__PURE__ */ jsxs("div", {
201
+ className: "ndp-panel__body",
202
+ children: [presets.length > 0 && /* @__PURE__ */ jsx("div", {
203
+ className: "ndp-presets",
204
+ role: "group",
205
+ "aria-label": label,
206
+ children: presets.map((preset) => /* @__PURE__ */ jsx("button", {
207
+ type: "button",
208
+ className: "ndp-preset",
209
+ "aria-pressed": preset.isActive,
210
+ disabled: preset.isDisabled,
211
+ onClick: () => {
212
+ onPreset(preset.id);
213
+ },
214
+ children: preset.label
215
+ }, preset.id))
216
+ }), children]
217
+ });
218
+ }
219
+ //#endregion
220
+ //#region src/date-picker.tsx
221
+ /**
222
+ * A BS/AD date field: type a date or pick it from a calendar. The value is
223
+ * always the AD day as "YYYY-MM-DD", so forms, validation and storage are
224
+ * unchanged and a BS date can never be sent as if it were AD.
225
+ */
226
+ function DatePicker(props) {
227
+ const { name, placeholder, required, disabled = false, clearable = true, showEquivalent = true, persistCalendar, panelLayout, theme, className, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, locale: localeProp, onCalendarChange, ...options } = props;
228
+ const locale = localeProp ?? pageLocale();
229
+ const picker = useDatePicker({
230
+ ...options,
231
+ locale,
232
+ onCalendarChange: (calendar) => {
233
+ remember(persistCalendar, calendar);
234
+ onCalendarChange?.(calendar);
235
+ }
236
+ });
237
+ const { state, store, calendar } = picker;
238
+ const labels = getLocale(locale);
239
+ const field = useRef(null);
240
+ const box = useRef(null);
241
+ const panel = useRef(null);
242
+ const input = useRef(null);
243
+ const hidden = useRef(null);
244
+ const panelWidth = state.presets.length > 0 ? 492 : 320;
245
+ usePanel(state.open && !state.inline, {
246
+ anchor: box,
247
+ panel,
248
+ field,
249
+ returnFocus: input
250
+ }, () => {
251
+ store.actions.close();
252
+ }, calendar.focusGrid, panelWidth, panelLayout);
253
+ useEffect(() => {
254
+ const stored = read(persistCalendar);
255
+ if (stored) store.actions.switchCalendar(stored);
256
+ }, [persistCalendar, store]);
257
+ useEffect(() => {
258
+ const form = hidden.current?.form ?? input.current?.form;
259
+ if (!form) return;
260
+ const reset = () => {
261
+ store.actions.reset();
262
+ };
263
+ form.addEventListener("reset", reset);
264
+ return () => {
265
+ form.removeEventListener("reset", reset);
266
+ };
267
+ }, [store]);
268
+ useEffect(() => {
269
+ input.current?.setCustomValidity(state.error?.message ?? "");
270
+ }, [state.error]);
271
+ const hint = state.error?.message ?? (showEquivalent ? state.equivalentText : null);
272
+ const inputProps = picker.getInputProps();
273
+ const describedBy = [ariaDescribedBy, hint ? picker.ids.hint : void 0].filter(Boolean).join(" ") || void 0;
274
+ const invalid = ariaInvalid === true || state.error !== null;
275
+ return /* @__PURE__ */ jsxs("div", {
276
+ ref: field,
277
+ className: className ? `ndp-field ${className}` : "ndp-field",
278
+ "data-ndp-theme": theme,
279
+ children: [
280
+ /* @__PURE__ */ jsxs("div", {
281
+ ref: box,
282
+ className: "ndp-input",
283
+ "data-invalid": invalid || void 0,
284
+ "data-disabled": disabled || void 0,
285
+ children: [/* @__PURE__ */ jsx("input", {
286
+ ref: input,
287
+ className: "ndp-input__control",
288
+ ...inputProps,
289
+ "aria-describedby": describedBy,
290
+ "aria-invalid": invalid || void 0,
291
+ "aria-label": ariaLabel,
292
+ placeholder: placeholder ?? state.placeholder,
293
+ required,
294
+ disabled
295
+ }), /* @__PURE__ */ jsxs("span", {
296
+ className: "ndp-input__actions",
297
+ children: [
298
+ clearable && state.text !== "" && !disabled && /* @__PURE__ */ jsx("button", {
299
+ className: "ndp-icon-button",
300
+ ...picker.getClearProps(),
301
+ onClick: () => {
302
+ store.actions.clear();
303
+ input.current?.focus();
304
+ },
305
+ children: /* @__PURE__ */ jsx(Icon, { name: "close" })
306
+ }),
307
+ state.canSwitchCalendar && /* @__PURE__ */ jsx("button", {
308
+ className: "ndp-input__switch",
309
+ disabled,
310
+ ...picker.getSwitchProps(),
311
+ children: labels.calendarNames[state.calendar]
312
+ }),
313
+ !state.inline && /* @__PURE__ */ jsx("button", {
314
+ className: "ndp-icon-button",
315
+ disabled,
316
+ ...picker.getToggleProps(),
317
+ children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
318
+ })
319
+ ]
320
+ })]
321
+ }),
322
+ hint !== null && /* @__PURE__ */ jsx("p", {
323
+ id: picker.ids.hint,
324
+ className: "ndp-hint",
325
+ "data-error": state.error ? true : void 0,
326
+ "aria-live": "polite",
327
+ children: hint
328
+ }),
329
+ name !== void 0 && /* @__PURE__ */ jsx("input", {
330
+ ref: hidden,
331
+ type: "hidden",
332
+ name,
333
+ value: state.value,
334
+ disabled
335
+ }),
336
+ state.open && /* @__PURE__ */ jsxs("div", {
337
+ ref: panel,
338
+ className: "ndp-panel",
339
+ popover: state.inline ? void 0 : "manual",
340
+ "data-layout": state.inline ? "inline" : void 0,
341
+ style: state.inline ? { "--ndp-panel-width": `${String(panelWidth)}px` } : void 0,
342
+ "data-ndp-theme": theme,
343
+ ...picker.getPanelProps(),
344
+ "aria-label": ariaLabel ? `${ariaLabel}: ${labels.labels.calendar}` : labels.labels.chooseDate,
345
+ children: [/* @__PURE__ */ jsx(PanelBody, {
346
+ presets: state.presets,
347
+ label: labels.labels.presets,
348
+ onPreset: (id) => {
349
+ if (store.actions.applyPreset(id) && !store.getState().open) restoreFocus(input.current);
350
+ },
351
+ children: /* @__PURE__ */ jsx(CalendarBody, { bindings: {
352
+ ...calendar,
353
+ getDayProps: (cell) => ({
354
+ ...calendar.getDayProps(cell),
355
+ onClick: () => {
356
+ if (!cell.isDisabled && store.actions.select(cell.date) && !store.getState().open) restoreFocus(input.current);
357
+ }
358
+ })
359
+ } })
360
+ }), /* @__PURE__ */ jsxs("div", {
361
+ className: "ndp-panel__footer",
362
+ children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
363
+ className: "ndp-segment",
364
+ role: "group",
365
+ "aria-label": labels.labels.calendar,
366
+ children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
367
+ className: "ndp-segment__item",
368
+ ...picker.getCalendarOptionProps(option),
369
+ children: labels.calendarNames[option]
370
+ }, option))
371
+ }) : /* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsx("button", {
372
+ className: "ndp-button",
373
+ ...picker.getTodayProps(),
374
+ onClick: () => {
375
+ if (store.actions.selectToday()) restoreFocus(input.current);
376
+ },
377
+ children: labels.labels.today
378
+ })]
379
+ })]
380
+ })
381
+ ]
382
+ });
383
+ }
384
+ /** Nepali names and digits when the page language is Nepali. */
385
+ function pageLocale() {
386
+ return typeof document !== "undefined" && document.documentElement.lang.toLowerCase().startsWith("ne") ? "ne" : "en";
387
+ }
388
+ function read(key) {
389
+ if (!key) return null;
390
+ try {
391
+ const stored = window.localStorage.getItem(key);
392
+ return stored === "AD" || stored === "BS" ? stored : null;
393
+ } catch {
394
+ return null;
395
+ }
396
+ }
397
+ function remember(key, calendar) {
398
+ if (!key) return;
399
+ try {
400
+ window.localStorage.setItem(key, calendar);
401
+ } catch {}
402
+ }
403
+ //#endregion
404
+ //#region src/date-range-picker.tsx
405
+ /** Two BS/AD date fields sharing one calendar panel in range mode. */
406
+ function DateRangePicker({ startName, endName, startLabel, endLabel, fiscalYearView = false, disabled = false, panelLayout, theme, className, ...options }) {
407
+ const picker = useDateRangePicker(options);
408
+ const { state, store, calendar } = picker;
409
+ const labels = getLocale(options.locale);
410
+ const field = useRef(null);
411
+ const row = useRef(null);
412
+ const panel = useRef(null);
413
+ const start = useRef(null);
414
+ const panelWidth = state.presets.length > 0 ? 492 : 320;
415
+ usePanel(state.open && !state.inline, {
416
+ anchor: row,
417
+ panel,
418
+ field,
419
+ returnFocus: start
420
+ }, () => {
421
+ store.actions.close();
422
+ }, calendar.focusGrid, panelWidth, panelLayout);
423
+ const invalid = (which) => state.error !== null && (state.error.field === which || state.error.field === "range");
424
+ return /* @__PURE__ */ jsxs("div", {
425
+ ref: field,
426
+ className: className ? `ndp-field ${className}` : "ndp-field",
427
+ "data-ndp-theme": theme,
428
+ children: [
429
+ /* @__PURE__ */ jsxs("div", {
430
+ ref: row,
431
+ className: "ndp-range",
432
+ children: [
433
+ /* @__PURE__ */ jsx("div", {
434
+ className: "ndp-input",
435
+ "data-invalid": invalid("start") || void 0,
436
+ "data-disabled": disabled || void 0,
437
+ children: /* @__PURE__ */ jsx("input", {
438
+ ref: start,
439
+ className: "ndp-input__control",
440
+ ...picker.getInputProps("start"),
441
+ "aria-label": startLabel,
442
+ disabled
443
+ })
444
+ }),
445
+ /* @__PURE__ */ jsx("span", {
446
+ className: "ndp-range__separator",
447
+ "aria-hidden": "true",
448
+ children: "→"
449
+ }),
450
+ /* @__PURE__ */ jsxs("div", {
451
+ className: "ndp-input",
452
+ "data-invalid": invalid("end") || void 0,
453
+ "data-disabled": disabled || void 0,
454
+ children: [/* @__PURE__ */ jsx("input", {
455
+ className: "ndp-input__control",
456
+ ...picker.getInputProps("end"),
457
+ "aria-label": endLabel,
458
+ disabled
459
+ }), !state.inline && /* @__PURE__ */ jsx("span", {
460
+ className: "ndp-input__actions",
461
+ children: /* @__PURE__ */ jsx("button", {
462
+ className: "ndp-icon-button",
463
+ disabled,
464
+ ...picker.getToggleProps(),
465
+ children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
466
+ })
467
+ })]
468
+ })
469
+ ]
470
+ }),
471
+ state.error && /* @__PURE__ */ jsx("p", {
472
+ id: picker.ids.hint,
473
+ className: "ndp-hint",
474
+ "data-error": true,
475
+ "aria-live": "polite",
476
+ children: state.error.message
477
+ }),
478
+ startName !== void 0 && /* @__PURE__ */ jsx("input", {
479
+ type: "hidden",
480
+ name: startName,
481
+ value: state.value.start,
482
+ disabled
483
+ }),
484
+ endName !== void 0 && /* @__PURE__ */ jsx("input", {
485
+ type: "hidden",
486
+ name: endName,
487
+ value: state.value.end,
488
+ disabled
489
+ }),
490
+ state.open && /* @__PURE__ */ jsxs("div", {
491
+ ref: panel,
492
+ className: "ndp-panel",
493
+ popover: state.inline ? void 0 : "manual",
494
+ "data-layout": state.inline ? "inline" : void 0,
495
+ style: state.inline ? { "--ndp-panel-width": `${String(panelWidth)}px` } : void 0,
496
+ "data-ndp-theme": theme,
497
+ ...picker.getPanelProps(),
498
+ children: [/* @__PURE__ */ jsx(PanelBody, {
499
+ presets: state.presets,
500
+ label: labels.labels.presets,
501
+ onPreset: (id) => {
502
+ if (store.actions.applyPreset(id) && !store.getState().open) restoreFocus(start.current);
503
+ },
504
+ children: /* @__PURE__ */ jsx(CalendarBody, { bindings: calendar })
505
+ }), (state.canSwitchCalendar || fiscalYearView) && /* @__PURE__ */ jsxs("div", {
506
+ className: "ndp-panel__footer",
507
+ children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
508
+ className: "ndp-segment",
509
+ role: "group",
510
+ "aria-label": labels.labels.calendar,
511
+ children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
512
+ className: "ndp-segment__item",
513
+ ...picker.getCalendarOptionProps(option),
514
+ children: labels.calendarNames[option]
515
+ }, option))
516
+ }) : /* @__PURE__ */ jsx("span", {}), fiscalYearView && /* @__PURE__ */ jsx("button", {
517
+ type: "button",
518
+ className: "ndp-button",
519
+ "aria-pressed": state.calendarState.view === "fiscal",
520
+ onClick: () => {
521
+ store.calendar.actions.setView(state.calendarState.view === "fiscal" ? "day" : "fiscal");
522
+ calendar.focusGrid();
523
+ },
524
+ children: labels.labels.fiscalYear
525
+ })]
526
+ })]
527
+ })
528
+ ]
529
+ });
530
+ }
531
+ //#endregion
532
+ //#region src/time-columns.tsx
533
+ /** Hour and minute columns (Figma "Time Item"); the selected items scroll into view. */
534
+ function TimeColumns({ hours, minutes, locale, onHour, onMinute }) {
535
+ const root = useRef(null);
536
+ const labels = getLocale(locale).labels;
537
+ useEffect(() => {
538
+ for (const item of root.current?.querySelectorAll("[aria-pressed=\"true\"]") ?? []) if (typeof item.scrollIntoView === "function") item.scrollIntoView({ block: "nearest" });
539
+ }, []);
540
+ const column = (label, cells, pick) => /* @__PURE__ */ jsx("div", {
541
+ className: "ndp-time__column",
542
+ role: "group",
543
+ "aria-label": label,
544
+ children: cells.map((cell) => /* @__PURE__ */ jsx("button", {
545
+ type: "button",
546
+ className: "ndp-time-item",
547
+ "aria-pressed": cell.isSelected,
548
+ onClick: () => {
549
+ pick(cell.value);
550
+ },
551
+ children: cell.label
552
+ }, cell.value))
553
+ });
554
+ return /* @__PURE__ */ jsxs("div", {
555
+ ref: root,
556
+ className: "ndp-time",
557
+ role: "group",
558
+ "aria-label": labels.time,
559
+ children: [column(labels.hour, hours, onHour), column(labels.minute, minutes, onMinute)]
560
+ });
561
+ }
562
+ //#endregion
563
+ //#region src/date-time-picker.tsx
564
+ /** A BS/AD date and time field. The value is one instant, with the zone's offset. */
565
+ function DateTimePicker({ name, required, disabled = false, panelLayout, theme, className, "aria-label": ariaLabel, timeLabel, ...options }) {
566
+ const { state, store, calendar, ids } = useDateTimePicker(options);
567
+ const labels = getLocale(options.locale);
568
+ const field = useRef(null);
569
+ const row = useRef(null);
570
+ const panel = useRef(null);
571
+ const dateInput = useRef(null);
572
+ const panelWidth = (state.presets.length > 0 ? 492 : 320) + 136;
573
+ usePanel(state.open && !state.inline, {
574
+ anchor: row,
575
+ panel,
576
+ field,
577
+ returnFocus: dateInput
578
+ }, () => {
579
+ store.actions.close();
580
+ }, calendar.focusGrid, panelWidth, panelLayout);
581
+ const hint = state.error?.message ?? state.equivalentText;
582
+ const invalid = (which) => state.error?.field === which;
583
+ return /* @__PURE__ */ jsxs("div", {
584
+ ref: field,
585
+ className: className ? `ndp-field ${className}` : "ndp-field",
586
+ "data-ndp-theme": theme,
587
+ children: [
588
+ /* @__PURE__ */ jsxs("div", {
589
+ ref: row,
590
+ className: "ndp-datetime",
591
+ children: [/* @__PURE__ */ jsxs("div", {
592
+ className: "ndp-input",
593
+ "data-invalid": invalid("date") || void 0,
594
+ "data-disabled": disabled || void 0,
595
+ children: [/* @__PURE__ */ jsx("input", {
596
+ ref: dateInput,
597
+ id: ids.date,
598
+ className: "ndp-input__control",
599
+ ...popupProps(state),
600
+ type: "text",
601
+ inputMode: "numeric",
602
+ autoComplete: "off",
603
+ value: state.dateText,
604
+ placeholder: state.placeholder,
605
+ "aria-label": ariaLabel,
606
+ "aria-controls": ids.panel,
607
+ "aria-invalid": invalid("date") || void 0,
608
+ "aria-describedby": hint ? ids.hint : void 0,
609
+ required,
610
+ disabled,
611
+ onChange: (event) => {
612
+ store.actions.typeDate(event.target.value);
613
+ },
614
+ onBlur: () => {
615
+ store.actions.blurDate();
616
+ },
617
+ onKeyDown: (event) => {
618
+ if (event.key === "ArrowDown" && (event.altKey || state.dateText === "")) {
619
+ event.preventDefault();
620
+ store.actions.open();
621
+ }
622
+ }
623
+ }), !state.inline && /* @__PURE__ */ jsx("span", {
624
+ className: "ndp-input__actions",
625
+ children: /* @__PURE__ */ jsx("button", {
626
+ type: "button",
627
+ className: "ndp-icon-button",
628
+ disabled,
629
+ "aria-label": labels.labels.openCalendar,
630
+ "aria-expanded": state.open,
631
+ "aria-controls": ids.panel,
632
+ onClick: () => {
633
+ store.actions.toggle();
634
+ },
635
+ children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
636
+ })
637
+ })]
638
+ }), /* @__PURE__ */ jsx("div", {
639
+ className: "ndp-input ndp-input--time",
640
+ "data-invalid": invalid("time") || void 0,
641
+ "data-disabled": disabled || void 0,
642
+ children: /* @__PURE__ */ jsx("input", {
643
+ id: ids.time,
644
+ className: "ndp-input__control",
645
+ type: "text",
646
+ inputMode: "text",
647
+ autoComplete: "off",
648
+ value: state.timeText,
649
+ placeholder: state.timePlaceholder,
650
+ "aria-label": timeLabel ?? labels.labels.time,
651
+ "aria-invalid": invalid("time") || void 0,
652
+ "aria-describedby": hint ? ids.hint : void 0,
653
+ disabled,
654
+ onChange: (event) => {
655
+ store.actions.typeTime(event.target.value);
656
+ },
657
+ onBlur: () => {
658
+ store.actions.blurTime();
659
+ }
660
+ })
661
+ })]
662
+ }),
663
+ hint !== null && /* @__PURE__ */ jsx("p", {
664
+ id: ids.hint,
665
+ className: "ndp-hint",
666
+ "data-error": state.error ? true : void 0,
667
+ "aria-live": "polite",
668
+ children: hint
669
+ }),
670
+ name !== void 0 && /* @__PURE__ */ jsx("input", {
671
+ type: "hidden",
672
+ name,
673
+ value: state.value,
674
+ disabled
675
+ }),
676
+ state.open && /* @__PURE__ */ jsxs("div", {
677
+ ref: panel,
678
+ id: ids.panel,
679
+ className: "ndp-panel",
680
+ popover: state.inline ? void 0 : "manual",
681
+ "data-layout": state.inline ? "inline" : void 0,
682
+ style: state.inline ? { "--ndp-panel-width": `${String(panelWidth)}px` } : void 0,
683
+ role: state.inline ? "group" : "dialog",
684
+ "aria-label": labels.labels.chooseDate,
685
+ "data-ndp-theme": theme,
686
+ children: [/* @__PURE__ */ jsxs(PanelBody, {
687
+ presets: state.presets,
688
+ label: labels.labels.presets,
689
+ onPreset: (presetId) => {
690
+ store.actions.applyPreset(presetId);
691
+ },
692
+ children: [/* @__PURE__ */ jsx(CalendarBody, { bindings: calendar }), /* @__PURE__ */ jsx(TimeColumns, {
693
+ hours: state.hours,
694
+ minutes: state.minutes,
695
+ locale: options.locale,
696
+ onHour: (hour) => {
697
+ store.actions.selectHour(hour);
698
+ },
699
+ onMinute: (minute) => {
700
+ store.actions.selectMinute(minute);
701
+ }
702
+ })]
703
+ }), /* @__PURE__ */ jsxs("div", {
704
+ className: "ndp-panel__footer",
705
+ children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
706
+ className: "ndp-segment",
707
+ role: "group",
708
+ "aria-label": labels.labels.calendar,
709
+ children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
710
+ type: "button",
711
+ className: "ndp-segment__item",
712
+ "aria-pressed": state.calendar === option,
713
+ onClick: () => {
714
+ store.actions.switchCalendar(option);
715
+ },
716
+ children: labels.calendarNames[option]
717
+ }, option))
718
+ }) : /* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("button", {
719
+ type: "button",
720
+ className: "ndp-button",
721
+ onClick: () => {
722
+ store.actions.selectNow();
723
+ },
724
+ children: labels.labels.now
725
+ }), /* @__PURE__ */ jsx("button", {
726
+ type: "button",
727
+ className: "ndp-button",
728
+ "data-variant": "primary",
729
+ onClick: () => {
730
+ store.actions.close();
731
+ dateInput.current?.focus();
732
+ },
733
+ children: labels.labels.done
734
+ })] })]
735
+ })]
736
+ })
737
+ ]
738
+ });
739
+ }
740
+ //#endregion
741
+ //#region src/multi-date-picker.tsx
742
+ /**
743
+ * Several separate BS/AD days in one field (PICK-001): click days in the
744
+ * panel to add or remove them, or type them separated by commas. The value is
745
+ * the sorted AD days as "YYYY-MM-DD" strings.
746
+ */
747
+ function MultiDatePicker({ name, placeholder, required, disabled = false, clearable = true, panelLayout, theme, className, "aria-label": ariaLabel, ...options }) {
748
+ const picker = useMultiDatePicker(options);
749
+ const { state, store, calendar } = picker;
750
+ const labels = getLocale(options.locale);
751
+ const field = useRef(null);
752
+ const box = useRef(null);
753
+ const panel = useRef(null);
754
+ const input = useRef(null);
755
+ usePanel(state.open && !state.inline, {
756
+ anchor: box,
757
+ panel,
758
+ field,
759
+ returnFocus: input
760
+ }, () => {
761
+ store.actions.close();
762
+ }, calendar.focusGrid, 320, panelLayout);
763
+ useEffect(() => {
764
+ const form = input.current?.form;
765
+ if (!form) return;
766
+ const reset = () => {
767
+ store.actions.reset();
768
+ };
769
+ form.addEventListener("reset", reset);
770
+ return () => {
771
+ form.removeEventListener("reset", reset);
772
+ };
773
+ }, [store]);
774
+ useEffect(() => {
775
+ input.current?.setCustomValidity(state.error?.message ?? "");
776
+ }, [state.error]);
777
+ return /* @__PURE__ */ jsxs("div", {
778
+ ref: field,
779
+ className: className ? `ndp-field ${className}` : "ndp-field",
780
+ "data-ndp-theme": theme,
781
+ children: [
782
+ /* @__PURE__ */ jsxs("div", {
783
+ ref: box,
784
+ className: "ndp-input",
785
+ "data-invalid": state.error !== null || void 0,
786
+ "data-disabled": disabled || void 0,
787
+ children: [/* @__PURE__ */ jsx("input", {
788
+ ref: input,
789
+ className: "ndp-input__control",
790
+ ...picker.getInputProps(),
791
+ "aria-label": ariaLabel,
792
+ placeholder: placeholder ?? state.placeholder,
793
+ required,
794
+ disabled
795
+ }), /* @__PURE__ */ jsxs("span", {
796
+ className: "ndp-input__actions",
797
+ children: [clearable && state.text !== "" && !disabled && /* @__PURE__ */ jsx("button", {
798
+ className: "ndp-icon-button",
799
+ ...picker.getClearProps(),
800
+ onClick: () => {
801
+ store.actions.clear();
802
+ input.current?.focus();
803
+ },
804
+ children: /* @__PURE__ */ jsx(Icon, { name: "close" })
805
+ }), !state.inline && /* @__PURE__ */ jsx("button", {
806
+ className: "ndp-icon-button",
807
+ disabled,
808
+ ...picker.getToggleProps(),
809
+ children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
810
+ })]
811
+ })]
812
+ }),
813
+ state.error && /* @__PURE__ */ jsx("p", {
814
+ id: picker.ids.hint,
815
+ className: "ndp-hint",
816
+ "data-error": true,
817
+ "aria-live": "polite",
818
+ children: state.error.message
819
+ }),
820
+ name !== void 0 && state.value.map((day) => /* @__PURE__ */ jsx("input", {
821
+ type: "hidden",
822
+ name,
823
+ value: day,
824
+ disabled
825
+ }, day)),
826
+ state.open && /* @__PURE__ */ jsxs("div", {
827
+ ref: panel,
828
+ className: "ndp-panel",
829
+ popover: state.inline ? void 0 : "manual",
830
+ "data-layout": state.inline ? "inline" : void 0,
831
+ style: state.inline ? { "--ndp-panel-width": `${String(320)}px` } : void 0,
832
+ "data-ndp-theme": theme,
833
+ ...picker.getPanelProps(),
834
+ "aria-label": ariaLabel ? `${ariaLabel}: ${labels.labels.calendar}` : labels.labels.chooseDate,
835
+ children: [/* @__PURE__ */ jsx(CalendarBody, { bindings: {
836
+ ...calendar,
837
+ getDayProps: (cell) => ({
838
+ ...calendar.getDayProps(cell),
839
+ onClick: () => {
840
+ if (!cell.isDisabled && store.actions.select(cell.date) && !store.getState().open) restoreFocus(input.current);
841
+ }
842
+ })
843
+ } }), /* @__PURE__ */ jsxs("div", {
844
+ className: "ndp-panel__footer",
845
+ children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
846
+ className: "ndp-segment",
847
+ role: "group",
848
+ "aria-label": labels.labels.calendar,
849
+ children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
850
+ className: "ndp-segment__item",
851
+ ...picker.getCalendarOptionProps(option),
852
+ children: labels.calendarNames[option]
853
+ }, option))
854
+ }) : /* @__PURE__ */ jsx("span", {}), !state.inline && /* @__PURE__ */ jsx("button", {
855
+ type: "button",
856
+ className: "ndp-button",
857
+ onClick: () => {
858
+ store.actions.close();
859
+ restoreFocus(input.current);
860
+ },
861
+ children: labels.labels.done
862
+ })]
863
+ })]
864
+ })
865
+ ]
866
+ });
867
+ }
868
+ //#endregion
869
+ export { Calendar, CalendarBody, DatePicker, DateRangePicker, DateText, DateTimePicker, Icon, MultiDatePicker, ShortDate, TimeColumns, bothDates, deepEqual, shortDate, useCalendar, useCalendarBindings, useDatePicker, useDateRangePicker, useDateTimePicker, useMultiDatePicker, useStore };
870
+
871
+ //# sourceMappingURL=index.js.map