@nepdatejs/react 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +74 -2
- package/dist/date-text-BX3Uag0O.cjs +84 -0
- package/dist/date-text-BX3Uag0O.cjs.map +1 -0
- package/dist/date-text-DLwhBmYj.js +61 -0
- package/dist/date-text-DLwhBmYj.js.map +1 -0
- package/dist/date-text-Dipetpbp.d.cts +37 -0
- package/dist/date-text-Dipetpbp.d.ts +37 -0
- package/dist/headless-AEI6dxTJ.cjs +619 -0
- package/dist/headless-AEI6dxTJ.cjs.map +1 -0
- package/dist/headless-CVj0DhD4.js +560 -0
- package/dist/headless-CVj0DhD4.js.map +1 -0
- package/dist/headless-ChE3zuYj.d.ts +195 -0
- package/dist/headless-CrIIPnOF.d.cts +195 -0
- package/dist/headless.cjs +11 -0
- package/dist/headless.d.cts +2 -0
- package/dist/headless.d.ts +2 -0
- package/dist/headless.js +2 -0
- package/dist/index.cjs +915 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +245 -0
- package/dist/index.d.ts +245 -0
- package/dist/index.js +895 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +6 -0
- package/dist/server.d.cts +2 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +1 -0
- package/package.json +110 -3
- package/src/bindings.ts +247 -0
- package/src/calendar-body.tsx +133 -0
- package/src/calendar.tsx +34 -0
- package/src/date-picker.tsx +343 -0
- package/src/date-range-picker.tsx +225 -0
- package/src/date-text.tsx +110 -0
- package/src/date-time-picker.tsx +289 -0
- package/src/headless.ts +21 -0
- package/src/hooks.ts +476 -0
- package/src/icons.tsx +35 -0
- package/src/index.ts +21 -0
- package/src/multi-date-picker.tsx +245 -0
- package/src/page-locale.ts +23 -0
- package/src/panel.ts +67 -0
- package/src/presets.tsx +44 -0
- package/src/server.ts +8 -0
- package/src/time-columns.tsx +60 -0
- package/src/use-store.ts +196 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,895 @@
|
|
|
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-CVj0DhD4.js";
|
|
3
|
+
import { i as shortDate, n as ShortDate, r as bothDates, t as DateText } from "./date-text-DLwhBmYj.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
6
|
+
import { getConfig, 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/page-locale.ts
|
|
155
|
+
const neverChanges = () => () => void 0;
|
|
156
|
+
/** Used on the server and while hydrating, so both render the same text. */
|
|
157
|
+
function defaultLocale() {
|
|
158
|
+
return getConfig().defaultLocale;
|
|
159
|
+
}
|
|
160
|
+
/** Nepali names and digits when the page language is Nepali. Browser only. */
|
|
161
|
+
function pageLocale() {
|
|
162
|
+
return document.documentElement.lang.toLowerCase().startsWith("ne") ? "ne" : defaultLocale();
|
|
163
|
+
}
|
|
164
|
+
/** The given locale, or else the page's language. */
|
|
165
|
+
function usePageLocale(given) {
|
|
166
|
+
const page = useSyncExternalStore(neverChanges, pageLocale, defaultLocale);
|
|
167
|
+
return given ?? page;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/panel.ts
|
|
171
|
+
/**
|
|
172
|
+
* While `open`: show the panel in the top layer beside the anchor, close on an
|
|
173
|
+
* outside pointer, a tap on a bottom sheet's backdrop, or Escape (returning focus to `returnFocus`), and move focus
|
|
174
|
+
* into the calendar.
|
|
175
|
+
*/
|
|
176
|
+
function usePanel(open, refs, close, focusGrid, width = 320, layout = "auto") {
|
|
177
|
+
const closeRef = useRef(close);
|
|
178
|
+
closeRef.current = close;
|
|
179
|
+
useIsomorphicLayoutEffect(() => {
|
|
180
|
+
const anchor = refs.anchor.current;
|
|
181
|
+
const panel = refs.panel.current;
|
|
182
|
+
if (!open || !anchor || !panel) return;
|
|
183
|
+
const stopTracking = trackPosition(anchor, panel, {
|
|
184
|
+
width,
|
|
185
|
+
layout
|
|
186
|
+
});
|
|
187
|
+
const stopOutside = onOutsidePointer(() => [refs.field.current, refs.panel.current], () => {
|
|
188
|
+
closeRef.current();
|
|
189
|
+
});
|
|
190
|
+
const stopBackdrop = onBackdropPointer(panel, () => {
|
|
191
|
+
closeRef.current();
|
|
192
|
+
});
|
|
193
|
+
const stopEscape = onEscape(() => {
|
|
194
|
+
closeRef.current();
|
|
195
|
+
restoreFocus(refs.returnFocus.current);
|
|
196
|
+
});
|
|
197
|
+
return () => {
|
|
198
|
+
stopTracking();
|
|
199
|
+
stopOutside();
|
|
200
|
+
stopBackdrop();
|
|
201
|
+
stopEscape();
|
|
202
|
+
};
|
|
203
|
+
}, [
|
|
204
|
+
open,
|
|
205
|
+
width,
|
|
206
|
+
layout
|
|
207
|
+
]);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (open) focusGrid();
|
|
210
|
+
}, [open]);
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/presets.tsx
|
|
214
|
+
/** The panel body: the shortcut list (when there are presets), then the calendar and anything else. */
|
|
215
|
+
function PanelBody({ presets, label, onPreset, children }) {
|
|
216
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
217
|
+
className: "ndp-panel__body",
|
|
218
|
+
children: [presets.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
219
|
+
className: "ndp-presets",
|
|
220
|
+
role: "group",
|
|
221
|
+
"aria-label": label,
|
|
222
|
+
children: presets.map((preset) => /* @__PURE__ */ jsx("button", {
|
|
223
|
+
type: "button",
|
|
224
|
+
className: "ndp-preset",
|
|
225
|
+
"aria-pressed": preset.isActive,
|
|
226
|
+
disabled: preset.isDisabled,
|
|
227
|
+
onClick: () => {
|
|
228
|
+
onPreset(preset.id);
|
|
229
|
+
},
|
|
230
|
+
children: preset.label
|
|
231
|
+
}, preset.id))
|
|
232
|
+
}), children]
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/date-picker.tsx
|
|
237
|
+
/**
|
|
238
|
+
* A BS/AD date field: type a date or pick it from a calendar. The value is
|
|
239
|
+
* always the AD day as "YYYY-MM-DD", so forms, validation and storage are
|
|
240
|
+
* unchanged and a BS date can never be sent as if it were AD.
|
|
241
|
+
*/
|
|
242
|
+
function DatePicker(props) {
|
|
243
|
+
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;
|
|
244
|
+
const locale = usePageLocale(localeProp);
|
|
245
|
+
const picker = useDatePicker({
|
|
246
|
+
...options,
|
|
247
|
+
locale,
|
|
248
|
+
onCalendarChange: (calendar) => {
|
|
249
|
+
remember(persistCalendar, calendar);
|
|
250
|
+
onCalendarChange?.(calendar);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const { state, store, calendar } = picker;
|
|
254
|
+
const labels = getLocale(locale);
|
|
255
|
+
const field = useRef(null);
|
|
256
|
+
const box = useRef(null);
|
|
257
|
+
const panel = useRef(null);
|
|
258
|
+
const input = useRef(null);
|
|
259
|
+
const hidden = useRef(null);
|
|
260
|
+
const panelWidth = state.presets.length > 0 ? 492 : 320;
|
|
261
|
+
usePanel(state.open && !state.inline, {
|
|
262
|
+
anchor: box,
|
|
263
|
+
panel,
|
|
264
|
+
field,
|
|
265
|
+
returnFocus: input
|
|
266
|
+
}, () => {
|
|
267
|
+
store.actions.close();
|
|
268
|
+
}, calendar.focusGrid, panelWidth, panelLayout);
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
const stored = read(persistCalendar);
|
|
271
|
+
if (stored) store.actions.switchCalendar(stored);
|
|
272
|
+
}, [persistCalendar, store]);
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
const form = hidden.current?.form ?? input.current?.form;
|
|
275
|
+
if (!form) return;
|
|
276
|
+
const reset = () => {
|
|
277
|
+
store.actions.reset();
|
|
278
|
+
};
|
|
279
|
+
form.addEventListener("reset", reset);
|
|
280
|
+
return () => {
|
|
281
|
+
form.removeEventListener("reset", reset);
|
|
282
|
+
};
|
|
283
|
+
}, [store]);
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
input.current?.setCustomValidity(state.error?.message ?? "");
|
|
286
|
+
}, [state.error]);
|
|
287
|
+
const hint = state.error?.message ?? (showEquivalent ? state.equivalentText : null);
|
|
288
|
+
const inputProps = picker.getInputProps();
|
|
289
|
+
const describedBy = [ariaDescribedBy, hint ? picker.ids.hint : void 0].filter(Boolean).join(" ") || void 0;
|
|
290
|
+
const invalid = ariaInvalid === true || state.error !== null;
|
|
291
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
292
|
+
ref: field,
|
|
293
|
+
className: className ? `ndp-field ${className}` : "ndp-field",
|
|
294
|
+
"data-ndp-theme": theme,
|
|
295
|
+
children: [
|
|
296
|
+
/* @__PURE__ */ jsxs("div", {
|
|
297
|
+
ref: box,
|
|
298
|
+
className: "ndp-input",
|
|
299
|
+
"data-invalid": invalid || void 0,
|
|
300
|
+
"data-disabled": disabled || void 0,
|
|
301
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
302
|
+
ref: input,
|
|
303
|
+
className: "ndp-input__control",
|
|
304
|
+
...inputProps,
|
|
305
|
+
"aria-describedby": describedBy,
|
|
306
|
+
"aria-invalid": invalid || void 0,
|
|
307
|
+
"aria-label": ariaLabel,
|
|
308
|
+
placeholder: placeholder ?? state.placeholder,
|
|
309
|
+
required,
|
|
310
|
+
disabled
|
|
311
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
312
|
+
className: "ndp-input__actions",
|
|
313
|
+
children: [
|
|
314
|
+
clearable && state.text !== "" && !disabled && /* @__PURE__ */ jsx("button", {
|
|
315
|
+
className: "ndp-icon-button",
|
|
316
|
+
...picker.getClearProps(),
|
|
317
|
+
onClick: () => {
|
|
318
|
+
store.actions.clear();
|
|
319
|
+
input.current?.focus();
|
|
320
|
+
},
|
|
321
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "close" })
|
|
322
|
+
}),
|
|
323
|
+
state.canSwitchCalendar && /* @__PURE__ */ jsx("button", {
|
|
324
|
+
className: "ndp-input__switch",
|
|
325
|
+
disabled,
|
|
326
|
+
...picker.getSwitchProps(),
|
|
327
|
+
children: labels.calendarNames[state.calendar]
|
|
328
|
+
}),
|
|
329
|
+
!state.inline && /* @__PURE__ */ jsx("button", {
|
|
330
|
+
className: "ndp-icon-button",
|
|
331
|
+
disabled,
|
|
332
|
+
...picker.getToggleProps(),
|
|
333
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
|
|
334
|
+
})
|
|
335
|
+
]
|
|
336
|
+
})]
|
|
337
|
+
}),
|
|
338
|
+
hint !== null && /* @__PURE__ */ jsx("p", {
|
|
339
|
+
id: picker.ids.hint,
|
|
340
|
+
className: "ndp-hint",
|
|
341
|
+
"data-error": state.error ? true : void 0,
|
|
342
|
+
"aria-live": "polite",
|
|
343
|
+
children: hint
|
|
344
|
+
}),
|
|
345
|
+
name !== void 0 && /* @__PURE__ */ jsx("input", {
|
|
346
|
+
ref: hidden,
|
|
347
|
+
type: "hidden",
|
|
348
|
+
name,
|
|
349
|
+
value: state.value,
|
|
350
|
+
disabled
|
|
351
|
+
}),
|
|
352
|
+
state.open && /* @__PURE__ */ jsxs("div", {
|
|
353
|
+
ref: panel,
|
|
354
|
+
className: "ndp-panel",
|
|
355
|
+
popover: state.inline ? void 0 : "manual",
|
|
356
|
+
"data-layout": state.inline ? "inline" : void 0,
|
|
357
|
+
style: state.inline ? { "--ndp-panel-width": `${String(panelWidth)}px` } : void 0,
|
|
358
|
+
"data-ndp-theme": theme,
|
|
359
|
+
...picker.getPanelProps(),
|
|
360
|
+
"aria-label": ariaLabel ? `${ariaLabel}: ${labels.labels.calendar}` : labels.labels.chooseDate,
|
|
361
|
+
children: [/* @__PURE__ */ jsx(PanelBody, {
|
|
362
|
+
presets: state.presets,
|
|
363
|
+
label: labels.labels.presets,
|
|
364
|
+
onPreset: (id) => {
|
|
365
|
+
if (store.actions.applyPreset(id) && !store.getState().open) restoreFocus(input.current);
|
|
366
|
+
},
|
|
367
|
+
children: /* @__PURE__ */ jsx(CalendarBody, { bindings: {
|
|
368
|
+
...calendar,
|
|
369
|
+
getDayProps: (cell) => ({
|
|
370
|
+
...calendar.getDayProps(cell),
|
|
371
|
+
onClick: () => {
|
|
372
|
+
if (!cell.isDisabled && store.actions.select(cell.date) && !store.getState().open) restoreFocus(input.current);
|
|
373
|
+
}
|
|
374
|
+
})
|
|
375
|
+
} })
|
|
376
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
377
|
+
className: "ndp-panel__footer",
|
|
378
|
+
children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
|
|
379
|
+
className: "ndp-segment",
|
|
380
|
+
role: "group",
|
|
381
|
+
"aria-label": labels.labels.calendar,
|
|
382
|
+
children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
|
|
383
|
+
className: "ndp-segment__item",
|
|
384
|
+
...picker.getCalendarOptionProps(option),
|
|
385
|
+
children: labels.calendarNames[option]
|
|
386
|
+
}, option))
|
|
387
|
+
}) : /* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsx("button", {
|
|
388
|
+
className: "ndp-button",
|
|
389
|
+
...picker.getTodayProps(),
|
|
390
|
+
onClick: () => {
|
|
391
|
+
if (store.actions.selectToday()) restoreFocus(input.current);
|
|
392
|
+
},
|
|
393
|
+
children: labels.labels.today
|
|
394
|
+
})]
|
|
395
|
+
})]
|
|
396
|
+
})
|
|
397
|
+
]
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
function read(key) {
|
|
401
|
+
if (!key) return null;
|
|
402
|
+
try {
|
|
403
|
+
const stored = window.localStorage.getItem(key);
|
|
404
|
+
return stored === "AD" || stored === "BS" ? stored : null;
|
|
405
|
+
} catch {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function remember(key, calendar) {
|
|
410
|
+
if (!key) return;
|
|
411
|
+
try {
|
|
412
|
+
window.localStorage.setItem(key, calendar);
|
|
413
|
+
} catch {}
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/date-range-picker.tsx
|
|
417
|
+
/** Two BS/AD date fields sharing one calendar panel in range mode. */
|
|
418
|
+
function DateRangePicker({ startName, endName, startLabel, endLabel, fiscalYearView = false, disabled = false, panelLayout, theme, className, ...options }) {
|
|
419
|
+
const locale = usePageLocale(options.locale);
|
|
420
|
+
const picker = useDateRangePicker({
|
|
421
|
+
...options,
|
|
422
|
+
locale
|
|
423
|
+
});
|
|
424
|
+
const { state, store, calendar } = picker;
|
|
425
|
+
const labels = getLocale(locale);
|
|
426
|
+
const field = useRef(null);
|
|
427
|
+
const row = useRef(null);
|
|
428
|
+
const panel = useRef(null);
|
|
429
|
+
const start = useRef(null);
|
|
430
|
+
const panelWidth = state.presets.length > 0 ? 492 : 320;
|
|
431
|
+
usePanel(state.open && !state.inline, {
|
|
432
|
+
anchor: row,
|
|
433
|
+
panel,
|
|
434
|
+
field,
|
|
435
|
+
returnFocus: start
|
|
436
|
+
}, () => {
|
|
437
|
+
store.actions.close();
|
|
438
|
+
}, calendar.focusGrid, panelWidth, panelLayout);
|
|
439
|
+
const invalid = (which) => state.error !== null && (state.error.field === which || state.error.field === "range");
|
|
440
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
441
|
+
ref: field,
|
|
442
|
+
className: className ? `ndp-field ${className}` : "ndp-field",
|
|
443
|
+
"data-ndp-theme": theme,
|
|
444
|
+
children: [
|
|
445
|
+
/* @__PURE__ */ jsxs("div", {
|
|
446
|
+
ref: row,
|
|
447
|
+
className: "ndp-range",
|
|
448
|
+
children: [
|
|
449
|
+
/* @__PURE__ */ jsx("div", {
|
|
450
|
+
className: "ndp-input",
|
|
451
|
+
"data-invalid": invalid("start") || void 0,
|
|
452
|
+
"data-disabled": disabled || void 0,
|
|
453
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
454
|
+
ref: start,
|
|
455
|
+
className: "ndp-input__control",
|
|
456
|
+
...picker.getInputProps("start"),
|
|
457
|
+
"aria-label": startLabel,
|
|
458
|
+
disabled
|
|
459
|
+
})
|
|
460
|
+
}),
|
|
461
|
+
/* @__PURE__ */ jsx("span", {
|
|
462
|
+
className: "ndp-range__separator",
|
|
463
|
+
"aria-hidden": "true",
|
|
464
|
+
children: "→"
|
|
465
|
+
}),
|
|
466
|
+
/* @__PURE__ */ jsxs("div", {
|
|
467
|
+
className: "ndp-input",
|
|
468
|
+
"data-invalid": invalid("end") || void 0,
|
|
469
|
+
"data-disabled": disabled || void 0,
|
|
470
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
471
|
+
className: "ndp-input__control",
|
|
472
|
+
...picker.getInputProps("end"),
|
|
473
|
+
"aria-label": endLabel,
|
|
474
|
+
disabled
|
|
475
|
+
}), !state.inline && /* @__PURE__ */ jsx("span", {
|
|
476
|
+
className: "ndp-input__actions",
|
|
477
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
478
|
+
className: "ndp-icon-button",
|
|
479
|
+
disabled,
|
|
480
|
+
...picker.getToggleProps(),
|
|
481
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
|
|
482
|
+
})
|
|
483
|
+
})]
|
|
484
|
+
})
|
|
485
|
+
]
|
|
486
|
+
}),
|
|
487
|
+
state.error && /* @__PURE__ */ jsx("p", {
|
|
488
|
+
id: picker.ids.hint,
|
|
489
|
+
className: "ndp-hint",
|
|
490
|
+
"data-error": true,
|
|
491
|
+
"aria-live": "polite",
|
|
492
|
+
children: state.error.message
|
|
493
|
+
}),
|
|
494
|
+
startName !== void 0 && /* @__PURE__ */ jsx("input", {
|
|
495
|
+
type: "hidden",
|
|
496
|
+
name: startName,
|
|
497
|
+
value: state.value.start,
|
|
498
|
+
disabled
|
|
499
|
+
}),
|
|
500
|
+
endName !== void 0 && /* @__PURE__ */ jsx("input", {
|
|
501
|
+
type: "hidden",
|
|
502
|
+
name: endName,
|
|
503
|
+
value: state.value.end,
|
|
504
|
+
disabled
|
|
505
|
+
}),
|
|
506
|
+
state.open && /* @__PURE__ */ jsxs("div", {
|
|
507
|
+
ref: panel,
|
|
508
|
+
className: "ndp-panel",
|
|
509
|
+
popover: state.inline ? void 0 : "manual",
|
|
510
|
+
"data-layout": state.inline ? "inline" : void 0,
|
|
511
|
+
style: state.inline ? { "--ndp-panel-width": `${String(panelWidth)}px` } : void 0,
|
|
512
|
+
"data-ndp-theme": theme,
|
|
513
|
+
...picker.getPanelProps(),
|
|
514
|
+
children: [/* @__PURE__ */ jsx(PanelBody, {
|
|
515
|
+
presets: state.presets,
|
|
516
|
+
label: labels.labels.presets,
|
|
517
|
+
onPreset: (id) => {
|
|
518
|
+
if (store.actions.applyPreset(id) && !store.getState().open) restoreFocus(start.current);
|
|
519
|
+
},
|
|
520
|
+
children: /* @__PURE__ */ jsx(CalendarBody, { bindings: calendar })
|
|
521
|
+
}), (state.canSwitchCalendar || fiscalYearView) && /* @__PURE__ */ jsxs("div", {
|
|
522
|
+
className: "ndp-panel__footer",
|
|
523
|
+
children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
|
|
524
|
+
className: "ndp-segment",
|
|
525
|
+
role: "group",
|
|
526
|
+
"aria-label": labels.labels.calendar,
|
|
527
|
+
children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
|
|
528
|
+
className: "ndp-segment__item",
|
|
529
|
+
...picker.getCalendarOptionProps(option),
|
|
530
|
+
children: labels.calendarNames[option]
|
|
531
|
+
}, option))
|
|
532
|
+
}) : /* @__PURE__ */ jsx("span", {}), fiscalYearView && /* @__PURE__ */ jsx("button", {
|
|
533
|
+
type: "button",
|
|
534
|
+
className: "ndp-button",
|
|
535
|
+
"aria-pressed": state.calendarState.view === "fiscal",
|
|
536
|
+
onClick: () => {
|
|
537
|
+
store.calendar.actions.setView(state.calendarState.view === "fiscal" ? "day" : "fiscal");
|
|
538
|
+
calendar.focusGrid();
|
|
539
|
+
},
|
|
540
|
+
children: labels.labels.fiscalYear
|
|
541
|
+
})]
|
|
542
|
+
})]
|
|
543
|
+
})
|
|
544
|
+
]
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/time-columns.tsx
|
|
549
|
+
/** Hour and minute columns (Figma "Time Item"); the selected items scroll into view. */
|
|
550
|
+
function TimeColumns({ hours, minutes, locale, onHour, onMinute }) {
|
|
551
|
+
const root = useRef(null);
|
|
552
|
+
const labels = getLocale(locale).labels;
|
|
553
|
+
useEffect(() => {
|
|
554
|
+
for (const item of root.current?.querySelectorAll("[aria-pressed=\"true\"]") ?? []) if (typeof item.scrollIntoView === "function") item.scrollIntoView({ block: "nearest" });
|
|
555
|
+
}, []);
|
|
556
|
+
const column = (label, cells, pick) => /* @__PURE__ */ jsx("div", {
|
|
557
|
+
className: "ndp-time__column",
|
|
558
|
+
role: "group",
|
|
559
|
+
"aria-label": label,
|
|
560
|
+
children: cells.map((cell) => /* @__PURE__ */ jsx("button", {
|
|
561
|
+
type: "button",
|
|
562
|
+
className: "ndp-time-item",
|
|
563
|
+
"aria-pressed": cell.isSelected,
|
|
564
|
+
onClick: () => {
|
|
565
|
+
pick(cell.value);
|
|
566
|
+
},
|
|
567
|
+
children: cell.label
|
|
568
|
+
}, cell.value))
|
|
569
|
+
});
|
|
570
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
571
|
+
ref: root,
|
|
572
|
+
className: "ndp-time",
|
|
573
|
+
role: "group",
|
|
574
|
+
"aria-label": labels.time,
|
|
575
|
+
children: [column(labels.hour, hours, onHour), column(labels.minute, minutes, onMinute)]
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region src/date-time-picker.tsx
|
|
580
|
+
/** A BS/AD date and time field. The value is one instant, with the zone's offset. */
|
|
581
|
+
function DateTimePicker({ name, required, disabled = false, panelLayout, theme, className, "aria-label": ariaLabel, timeLabel, ...options }) {
|
|
582
|
+
const locale = usePageLocale(options.locale);
|
|
583
|
+
const { state, store, calendar, ids } = useDateTimePicker({
|
|
584
|
+
...options,
|
|
585
|
+
locale
|
|
586
|
+
});
|
|
587
|
+
const labels = getLocale(locale);
|
|
588
|
+
const field = useRef(null);
|
|
589
|
+
const row = useRef(null);
|
|
590
|
+
const panel = useRef(null);
|
|
591
|
+
const dateInput = useRef(null);
|
|
592
|
+
const panelWidth = (state.presets.length > 0 ? 492 : 320) + 136;
|
|
593
|
+
usePanel(state.open && !state.inline, {
|
|
594
|
+
anchor: row,
|
|
595
|
+
panel,
|
|
596
|
+
field,
|
|
597
|
+
returnFocus: dateInput
|
|
598
|
+
}, () => {
|
|
599
|
+
store.actions.close();
|
|
600
|
+
}, calendar.focusGrid, panelWidth, panelLayout);
|
|
601
|
+
const hint = state.error?.message ?? state.equivalentText;
|
|
602
|
+
const invalid = (which) => state.error?.field === which;
|
|
603
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
604
|
+
ref: field,
|
|
605
|
+
className: className ? `ndp-field ${className}` : "ndp-field",
|
|
606
|
+
"data-ndp-theme": theme,
|
|
607
|
+
children: [
|
|
608
|
+
/* @__PURE__ */ jsxs("div", {
|
|
609
|
+
ref: row,
|
|
610
|
+
className: "ndp-datetime",
|
|
611
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
612
|
+
className: "ndp-input",
|
|
613
|
+
"data-invalid": invalid("date") || void 0,
|
|
614
|
+
"data-disabled": disabled || void 0,
|
|
615
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
616
|
+
ref: dateInput,
|
|
617
|
+
id: ids.date,
|
|
618
|
+
className: "ndp-input__control",
|
|
619
|
+
...popupProps(state),
|
|
620
|
+
type: "text",
|
|
621
|
+
inputMode: "numeric",
|
|
622
|
+
autoComplete: "off",
|
|
623
|
+
value: state.dateText,
|
|
624
|
+
placeholder: state.placeholder,
|
|
625
|
+
"aria-label": ariaLabel,
|
|
626
|
+
"aria-controls": ids.panel,
|
|
627
|
+
"aria-invalid": invalid("date") || void 0,
|
|
628
|
+
"aria-describedby": hint ? ids.hint : void 0,
|
|
629
|
+
required,
|
|
630
|
+
disabled,
|
|
631
|
+
onChange: (event) => {
|
|
632
|
+
store.actions.typeDate(event.target.value);
|
|
633
|
+
},
|
|
634
|
+
onBlur: () => {
|
|
635
|
+
store.actions.blurDate();
|
|
636
|
+
},
|
|
637
|
+
onKeyDown: (event) => {
|
|
638
|
+
if (event.key === "ArrowDown" && (event.altKey || state.dateText === "")) {
|
|
639
|
+
event.preventDefault();
|
|
640
|
+
store.actions.open();
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}), !state.inline && /* @__PURE__ */ jsx("span", {
|
|
644
|
+
className: "ndp-input__actions",
|
|
645
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
646
|
+
type: "button",
|
|
647
|
+
className: "ndp-icon-button",
|
|
648
|
+
disabled,
|
|
649
|
+
"aria-label": labels.labels.openCalendar,
|
|
650
|
+
"aria-expanded": state.open,
|
|
651
|
+
"aria-controls": ids.panel,
|
|
652
|
+
onClick: () => {
|
|
653
|
+
store.actions.toggle();
|
|
654
|
+
},
|
|
655
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
|
|
656
|
+
})
|
|
657
|
+
})]
|
|
658
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
659
|
+
className: "ndp-input ndp-input--time",
|
|
660
|
+
"data-invalid": invalid("time") || void 0,
|
|
661
|
+
"data-disabled": disabled || void 0,
|
|
662
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
663
|
+
id: ids.time,
|
|
664
|
+
className: "ndp-input__control",
|
|
665
|
+
type: "text",
|
|
666
|
+
inputMode: "text",
|
|
667
|
+
autoComplete: "off",
|
|
668
|
+
value: state.timeText,
|
|
669
|
+
placeholder: state.timePlaceholder,
|
|
670
|
+
"aria-label": timeLabel ?? labels.labels.time,
|
|
671
|
+
"aria-invalid": invalid("time") || void 0,
|
|
672
|
+
"aria-describedby": hint ? ids.hint : void 0,
|
|
673
|
+
disabled,
|
|
674
|
+
onChange: (event) => {
|
|
675
|
+
store.actions.typeTime(event.target.value);
|
|
676
|
+
},
|
|
677
|
+
onBlur: () => {
|
|
678
|
+
store.actions.blurTime();
|
|
679
|
+
}
|
|
680
|
+
})
|
|
681
|
+
})]
|
|
682
|
+
}),
|
|
683
|
+
hint !== null && /* @__PURE__ */ jsx("p", {
|
|
684
|
+
id: ids.hint,
|
|
685
|
+
className: "ndp-hint",
|
|
686
|
+
"data-error": state.error ? true : void 0,
|
|
687
|
+
"aria-live": "polite",
|
|
688
|
+
children: hint
|
|
689
|
+
}),
|
|
690
|
+
name !== void 0 && /* @__PURE__ */ jsx("input", {
|
|
691
|
+
type: "hidden",
|
|
692
|
+
name,
|
|
693
|
+
value: state.value,
|
|
694
|
+
disabled
|
|
695
|
+
}),
|
|
696
|
+
state.open && /* @__PURE__ */ jsxs("div", {
|
|
697
|
+
ref: panel,
|
|
698
|
+
id: ids.panel,
|
|
699
|
+
className: "ndp-panel",
|
|
700
|
+
popover: state.inline ? void 0 : "manual",
|
|
701
|
+
"data-layout": state.inline ? "inline" : void 0,
|
|
702
|
+
style: state.inline ? { "--ndp-panel-width": `${String(panelWidth)}px` } : void 0,
|
|
703
|
+
role: state.inline ? "group" : "dialog",
|
|
704
|
+
"aria-label": labels.labels.chooseDate,
|
|
705
|
+
"data-ndp-theme": theme,
|
|
706
|
+
children: [/* @__PURE__ */ jsxs(PanelBody, {
|
|
707
|
+
presets: state.presets,
|
|
708
|
+
label: labels.labels.presets,
|
|
709
|
+
onPreset: (presetId) => {
|
|
710
|
+
store.actions.applyPreset(presetId);
|
|
711
|
+
},
|
|
712
|
+
children: [/* @__PURE__ */ jsx(CalendarBody, { bindings: calendar }), /* @__PURE__ */ jsx(TimeColumns, {
|
|
713
|
+
hours: state.hours,
|
|
714
|
+
minutes: state.minutes,
|
|
715
|
+
locale: options.locale,
|
|
716
|
+
onHour: (hour) => {
|
|
717
|
+
store.actions.selectHour(hour);
|
|
718
|
+
},
|
|
719
|
+
onMinute: (minute) => {
|
|
720
|
+
store.actions.selectMinute(minute);
|
|
721
|
+
}
|
|
722
|
+
})]
|
|
723
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
724
|
+
className: "ndp-panel__footer",
|
|
725
|
+
children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
|
|
726
|
+
className: "ndp-segment",
|
|
727
|
+
role: "group",
|
|
728
|
+
"aria-label": labels.labels.calendar,
|
|
729
|
+
children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
|
|
730
|
+
type: "button",
|
|
731
|
+
className: "ndp-segment__item",
|
|
732
|
+
"aria-pressed": state.calendar === option,
|
|
733
|
+
onClick: () => {
|
|
734
|
+
store.actions.switchCalendar(option);
|
|
735
|
+
},
|
|
736
|
+
children: labels.calendarNames[option]
|
|
737
|
+
}, option))
|
|
738
|
+
}) : /* @__PURE__ */ jsx("span", {}), /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("button", {
|
|
739
|
+
type: "button",
|
|
740
|
+
className: "ndp-button",
|
|
741
|
+
onClick: () => {
|
|
742
|
+
store.actions.selectNow();
|
|
743
|
+
},
|
|
744
|
+
children: labels.labels.now
|
|
745
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
746
|
+
type: "button",
|
|
747
|
+
className: "ndp-button",
|
|
748
|
+
"data-variant": "primary",
|
|
749
|
+
onClick: () => {
|
|
750
|
+
store.actions.close();
|
|
751
|
+
dateInput.current?.focus();
|
|
752
|
+
},
|
|
753
|
+
children: labels.labels.done
|
|
754
|
+
})] })]
|
|
755
|
+
})]
|
|
756
|
+
})
|
|
757
|
+
]
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region src/multi-date-picker.tsx
|
|
762
|
+
/**
|
|
763
|
+
* Several separate BS/AD days in one field (PICK-001): click days in the
|
|
764
|
+
* panel to add or remove them, or type them separated by commas. The value is
|
|
765
|
+
* the sorted AD days as "YYYY-MM-DD" strings.
|
|
766
|
+
*/
|
|
767
|
+
function MultiDatePicker({ name, placeholder, required, disabled = false, clearable = true, panelLayout, theme, className, "aria-label": ariaLabel, ...options }) {
|
|
768
|
+
const locale = usePageLocale(options.locale);
|
|
769
|
+
const picker = useMultiDatePicker({
|
|
770
|
+
...options,
|
|
771
|
+
locale
|
|
772
|
+
});
|
|
773
|
+
const { state, store, calendar } = picker;
|
|
774
|
+
const labels = getLocale(locale);
|
|
775
|
+
const field = useRef(null);
|
|
776
|
+
const box = useRef(null);
|
|
777
|
+
const panel = useRef(null);
|
|
778
|
+
const input = useRef(null);
|
|
779
|
+
usePanel(state.open && !state.inline, {
|
|
780
|
+
anchor: box,
|
|
781
|
+
panel,
|
|
782
|
+
field,
|
|
783
|
+
returnFocus: input
|
|
784
|
+
}, () => {
|
|
785
|
+
store.actions.close();
|
|
786
|
+
}, calendar.focusGrid, 320, panelLayout);
|
|
787
|
+
useEffect(() => {
|
|
788
|
+
const form = input.current?.form;
|
|
789
|
+
if (!form) return;
|
|
790
|
+
const reset = () => {
|
|
791
|
+
store.actions.reset();
|
|
792
|
+
};
|
|
793
|
+
form.addEventListener("reset", reset);
|
|
794
|
+
return () => {
|
|
795
|
+
form.removeEventListener("reset", reset);
|
|
796
|
+
};
|
|
797
|
+
}, [store]);
|
|
798
|
+
useEffect(() => {
|
|
799
|
+
input.current?.setCustomValidity(state.error?.message ?? "");
|
|
800
|
+
}, [state.error]);
|
|
801
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
802
|
+
ref: field,
|
|
803
|
+
className: className ? `ndp-field ${className}` : "ndp-field",
|
|
804
|
+
"data-ndp-theme": theme,
|
|
805
|
+
children: [
|
|
806
|
+
/* @__PURE__ */ jsxs("div", {
|
|
807
|
+
ref: box,
|
|
808
|
+
className: "ndp-input",
|
|
809
|
+
"data-invalid": state.error !== null || void 0,
|
|
810
|
+
"data-disabled": disabled || void 0,
|
|
811
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
812
|
+
ref: input,
|
|
813
|
+
className: "ndp-input__control",
|
|
814
|
+
...picker.getInputProps(),
|
|
815
|
+
"aria-label": ariaLabel,
|
|
816
|
+
placeholder: placeholder ?? state.placeholder,
|
|
817
|
+
required,
|
|
818
|
+
disabled
|
|
819
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
820
|
+
className: "ndp-input__actions",
|
|
821
|
+
children: [clearable && state.text !== "" && !disabled && /* @__PURE__ */ jsx("button", {
|
|
822
|
+
className: "ndp-icon-button",
|
|
823
|
+
...picker.getClearProps(),
|
|
824
|
+
onClick: () => {
|
|
825
|
+
store.actions.clear();
|
|
826
|
+
input.current?.focus();
|
|
827
|
+
},
|
|
828
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "close" })
|
|
829
|
+
}), !state.inline && /* @__PURE__ */ jsx("button", {
|
|
830
|
+
className: "ndp-icon-button",
|
|
831
|
+
disabled,
|
|
832
|
+
...picker.getToggleProps(),
|
|
833
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "calendar" })
|
|
834
|
+
})]
|
|
835
|
+
})]
|
|
836
|
+
}),
|
|
837
|
+
state.error && /* @__PURE__ */ jsx("p", {
|
|
838
|
+
id: picker.ids.hint,
|
|
839
|
+
className: "ndp-hint",
|
|
840
|
+
"data-error": true,
|
|
841
|
+
"aria-live": "polite",
|
|
842
|
+
children: state.error.message
|
|
843
|
+
}),
|
|
844
|
+
name !== void 0 && state.value.map((day) => /* @__PURE__ */ jsx("input", {
|
|
845
|
+
type: "hidden",
|
|
846
|
+
name,
|
|
847
|
+
value: day,
|
|
848
|
+
disabled
|
|
849
|
+
}, day)),
|
|
850
|
+
state.open && /* @__PURE__ */ jsxs("div", {
|
|
851
|
+
ref: panel,
|
|
852
|
+
className: "ndp-panel",
|
|
853
|
+
popover: state.inline ? void 0 : "manual",
|
|
854
|
+
"data-layout": state.inline ? "inline" : void 0,
|
|
855
|
+
style: state.inline ? { "--ndp-panel-width": `${String(320)}px` } : void 0,
|
|
856
|
+
"data-ndp-theme": theme,
|
|
857
|
+
...picker.getPanelProps(),
|
|
858
|
+
"aria-label": ariaLabel ? `${ariaLabel}: ${labels.labels.calendar}` : labels.labels.chooseDate,
|
|
859
|
+
children: [/* @__PURE__ */ jsx(CalendarBody, { bindings: {
|
|
860
|
+
...calendar,
|
|
861
|
+
getDayProps: (cell) => ({
|
|
862
|
+
...calendar.getDayProps(cell),
|
|
863
|
+
onClick: () => {
|
|
864
|
+
if (!cell.isDisabled && store.actions.select(cell.date) && !store.getState().open) restoreFocus(input.current);
|
|
865
|
+
}
|
|
866
|
+
})
|
|
867
|
+
} }), /* @__PURE__ */ jsxs("div", {
|
|
868
|
+
className: "ndp-panel__footer",
|
|
869
|
+
children: [state.canSwitchCalendar ? /* @__PURE__ */ jsx("div", {
|
|
870
|
+
className: "ndp-segment",
|
|
871
|
+
role: "group",
|
|
872
|
+
"aria-label": labels.labels.calendar,
|
|
873
|
+
children: ["BS", "AD"].map((option) => /* @__PURE__ */ jsx("button", {
|
|
874
|
+
className: "ndp-segment__item",
|
|
875
|
+
...picker.getCalendarOptionProps(option),
|
|
876
|
+
children: labels.calendarNames[option]
|
|
877
|
+
}, option))
|
|
878
|
+
}) : /* @__PURE__ */ jsx("span", {}), !state.inline && /* @__PURE__ */ jsx("button", {
|
|
879
|
+
type: "button",
|
|
880
|
+
className: "ndp-button",
|
|
881
|
+
onClick: () => {
|
|
882
|
+
store.actions.close();
|
|
883
|
+
restoreFocus(input.current);
|
|
884
|
+
},
|
|
885
|
+
children: labels.labels.done
|
|
886
|
+
})]
|
|
887
|
+
})]
|
|
888
|
+
})
|
|
889
|
+
]
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
//#endregion
|
|
893
|
+
export { Calendar, CalendarBody, DatePicker, DateRangePicker, DateText, DateTimePicker, Icon, MultiDatePicker, ShortDate, TimeColumns, bothDates, deepEqual, shortDate, useCalendar, useCalendarBindings, useDatePicker, useDateRangePicker, useDateTimePicker, useMultiDatePicker, useStore };
|
|
894
|
+
|
|
895
|
+
//# sourceMappingURL=index.js.map
|