@loykin/datetime-range 0.0.1-dev.3 → 0.0.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/README.md +42 -0
- package/dist/UIAdapterContext-Bm35TZtL.d.cts +96 -0
- package/dist/UIAdapterContext-Bm35TZtL.d.ts +96 -0
- package/dist/adapters/shadcn.cjs +117 -0
- package/dist/adapters/shadcn.cjs.map +1 -0
- package/dist/adapters/shadcn.d.cts +41 -0
- package/dist/adapters/shadcn.d.ts +41 -0
- package/dist/adapters/shadcn.js +115 -0
- package/dist/adapters/shadcn.js.map +1 -0
- package/dist/index.cjs +412 -303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -3
- package/dist/index.d.ts +36 -3
- package/dist/index.js +344 -237
- package/dist/index.js.map +1 -1
- package/dist/styles.css +226 -211
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var lucideReact = require('lucide-react');
|
|
4
4
|
var clsx = require('clsx');
|
|
5
|
+
var React2 = require('react');
|
|
5
6
|
var button = require('@base-ui/react/button');
|
|
6
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
8
|
var popover = require('@base-ui/react/popover');
|
|
8
|
-
var React = require('react');
|
|
9
|
-
var tabs = require('@base-ui/react/tabs');
|
|
10
|
-
var input = require('@base-ui/react/input');
|
|
11
9
|
var select = require('@base-ui/react/select');
|
|
12
10
|
var react = require('@hugeicons/react');
|
|
13
11
|
var coreFreeIcons = require('@hugeicons/core-free-icons');
|
|
12
|
+
var tabs = require('@base-ui/react/tabs');
|
|
13
|
+
var input = require('@base-ui/react/input');
|
|
14
14
|
var _switch = require('@base-ui/react/switch');
|
|
15
|
+
var scrollArea = require('@base-ui/react/scroll-area');
|
|
15
16
|
var dateFns = require('date-fns');
|
|
16
17
|
var reactDayPicker = require('react-day-picker');
|
|
17
18
|
var setMonth = require('date-fns/setMonth');
|
|
18
|
-
var scrollArea = require('@base-ui/react/scroll-area');
|
|
19
19
|
var chrono = require('chrono-node');
|
|
20
20
|
|
|
21
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -38,7 +38,7 @@ function _interopNamespace(e) {
|
|
|
38
38
|
return Object.freeze(n);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
var
|
|
41
|
+
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
42
42
|
var chrono__namespace = /*#__PURE__*/_interopNamespace(chrono);
|
|
43
43
|
|
|
44
44
|
// src/DatetimeRange.tsx
|
|
@@ -50,7 +50,7 @@ function buttonVariants({
|
|
|
50
50
|
size = "default",
|
|
51
51
|
className
|
|
52
52
|
} = {}) {
|
|
53
|
-
return cn("
|
|
53
|
+
return cn("datetime-range-btn", className, variant && `datetime-range-btn--${variant}`, size && `datetime-range-btn--${size}`);
|
|
54
54
|
}
|
|
55
55
|
function Button({
|
|
56
56
|
className,
|
|
@@ -95,89 +95,25 @@ function PopoverContent({
|
|
|
95
95
|
sideOffset,
|
|
96
96
|
disableAnchorTracking,
|
|
97
97
|
collisionAvoidance,
|
|
98
|
-
className: "
|
|
98
|
+
className: "datetime-range-positioner",
|
|
99
99
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
100
100
|
popover.Popover.Popup,
|
|
101
101
|
{
|
|
102
102
|
"data-slot": "popover-content",
|
|
103
|
-
className: cn("
|
|
103
|
+
className: cn("datetime-range-popover-content", className),
|
|
104
104
|
...props
|
|
105
105
|
}
|
|
106
106
|
)
|
|
107
107
|
}
|
|
108
108
|
) });
|
|
109
109
|
}
|
|
110
|
-
function Tabs({
|
|
111
|
-
className,
|
|
112
|
-
orientation = "horizontal",
|
|
113
|
-
...props
|
|
114
|
-
}) {
|
|
115
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
116
|
-
tabs.Tabs.Root,
|
|
117
|
-
{
|
|
118
|
-
"data-slot": "tabs",
|
|
119
|
-
"data-orientation": orientation,
|
|
120
|
-
className: cn("dr-tabs", className),
|
|
121
|
-
...props
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
function TabsList({
|
|
126
|
-
className,
|
|
127
|
-
variant = "default",
|
|
128
|
-
...props
|
|
129
|
-
}) {
|
|
130
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
131
|
-
tabs.Tabs.List,
|
|
132
|
-
{
|
|
133
|
-
"data-slot": "tabs-list",
|
|
134
|
-
"data-variant": variant,
|
|
135
|
-
className: cn("dr-tabs-list", className),
|
|
136
|
-
...props
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
function TabsTrigger({ className, ...props }) {
|
|
141
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
142
|
-
tabs.Tabs.Tab,
|
|
143
|
-
{
|
|
144
|
-
"data-slot": "tabs-trigger",
|
|
145
|
-
className: cn("dr-tabs-trigger", className),
|
|
146
|
-
...props
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
function TabsContent({ className, ...props }) {
|
|
151
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
152
|
-
tabs.Tabs.Panel,
|
|
153
|
-
{
|
|
154
|
-
"data-slot": "tabs-content",
|
|
155
|
-
className: cn("dr-tabs-content", className),
|
|
156
|
-
...props
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
function Input({ className, type, ...props }) {
|
|
161
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
162
|
-
input.Input,
|
|
163
|
-
{
|
|
164
|
-
type,
|
|
165
|
-
"data-slot": "input",
|
|
166
|
-
className: cn(
|
|
167
|
-
"dr-input",
|
|
168
|
-
className
|
|
169
|
-
),
|
|
170
|
-
...props
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
110
|
var Select = select.Select.Root;
|
|
175
111
|
function SelectValue({ className, ...props }) {
|
|
176
112
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
177
113
|
select.Select.Value,
|
|
178
114
|
{
|
|
179
115
|
"data-slot": "select-value",
|
|
180
|
-
className: cn("
|
|
116
|
+
className: cn("datetime-range-select-value", className),
|
|
181
117
|
...props
|
|
182
118
|
}
|
|
183
119
|
);
|
|
@@ -193,7 +129,7 @@ function SelectTrigger({
|
|
|
193
129
|
{
|
|
194
130
|
"data-slot": "select-trigger",
|
|
195
131
|
"data-size": size,
|
|
196
|
-
className: cn("
|
|
132
|
+
className: cn("datetime-range-select-trigger", className),
|
|
197
133
|
...props,
|
|
198
134
|
children: [
|
|
199
135
|
children,
|
|
@@ -205,7 +141,7 @@ function SelectTrigger({
|
|
|
205
141
|
{
|
|
206
142
|
icon: coreFreeIcons.UnfoldMoreIcon,
|
|
207
143
|
strokeWidth: 2,
|
|
208
|
-
className: "
|
|
144
|
+
className: "datetime-range-select-icon"
|
|
209
145
|
}
|
|
210
146
|
)
|
|
211
147
|
}
|
|
@@ -232,13 +168,13 @@ function SelectContent({
|
|
|
232
168
|
align,
|
|
233
169
|
alignOffset,
|
|
234
170
|
alignItemWithTrigger,
|
|
235
|
-
className: "
|
|
171
|
+
className: "datetime-range-positioner",
|
|
236
172
|
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
237
173
|
select.Select.Popup,
|
|
238
174
|
{
|
|
239
175
|
"data-slot": "select-content",
|
|
240
176
|
"data-align-trigger": alignItemWithTrigger,
|
|
241
|
-
className: cn("
|
|
177
|
+
className: cn("datetime-range-select-content", className),
|
|
242
178
|
...props,
|
|
243
179
|
children: [
|
|
244
180
|
/* @__PURE__ */ jsxRuntime.jsx(SelectScrollUpButton, {}),
|
|
@@ -259,14 +195,14 @@ function SelectItem({
|
|
|
259
195
|
select.Select.Item,
|
|
260
196
|
{
|
|
261
197
|
"data-slot": "select-item",
|
|
262
|
-
className: cn("
|
|
198
|
+
className: cn("datetime-range-select-item", className),
|
|
263
199
|
...props,
|
|
264
200
|
children: [
|
|
265
|
-
/* @__PURE__ */ jsxRuntime.jsx(select.Select.ItemText, { className: "
|
|
201
|
+
/* @__PURE__ */ jsxRuntime.jsx(select.Select.ItemText, { className: "datetime-range-select-item-text", children }),
|
|
266
202
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
267
203
|
select.Select.ItemIndicator,
|
|
268
204
|
{
|
|
269
|
-
render: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "
|
|
205
|
+
render: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "datetime-range-select-item-indicator" }),
|
|
270
206
|
children: /* @__PURE__ */ jsxRuntime.jsx(react.HugeiconsIcon, { icon: coreFreeIcons.Tick02Icon, strokeWidth: 2, style: { pointerEvents: "none" } })
|
|
271
207
|
}
|
|
272
208
|
)
|
|
@@ -282,7 +218,7 @@ function SelectScrollUpButton({
|
|
|
282
218
|
select.Select.ScrollUpArrow,
|
|
283
219
|
{
|
|
284
220
|
"data-slot": "select-scroll-up-button",
|
|
285
|
-
className: cn("
|
|
221
|
+
className: cn("datetime-range-select-scroll-btn datetime-range-select-scroll-btn--up", className),
|
|
286
222
|
...props,
|
|
287
223
|
children: /* @__PURE__ */ jsxRuntime.jsx(react.HugeiconsIcon, { icon: coreFreeIcons.ArrowUp01Icon, strokeWidth: 2 })
|
|
288
224
|
}
|
|
@@ -296,12 +232,76 @@ function SelectScrollDownButton({
|
|
|
296
232
|
select.Select.ScrollDownArrow,
|
|
297
233
|
{
|
|
298
234
|
"data-slot": "select-scroll-down-button",
|
|
299
|
-
className: cn("
|
|
235
|
+
className: cn("datetime-range-select-scroll-btn datetime-range-select-scroll-btn--down", className),
|
|
300
236
|
...props,
|
|
301
237
|
children: /* @__PURE__ */ jsxRuntime.jsx(react.HugeiconsIcon, { icon: coreFreeIcons.ArrowDown01Icon, strokeWidth: 2 })
|
|
302
238
|
}
|
|
303
239
|
);
|
|
304
240
|
}
|
|
241
|
+
function Tabs({
|
|
242
|
+
className,
|
|
243
|
+
orientation = "horizontal",
|
|
244
|
+
...props
|
|
245
|
+
}) {
|
|
246
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
247
|
+
tabs.Tabs.Root,
|
|
248
|
+
{
|
|
249
|
+
"data-slot": "tabs",
|
|
250
|
+
"data-orientation": orientation,
|
|
251
|
+
className: cn("datetime-range-tabs", className),
|
|
252
|
+
...props
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
function TabsList({
|
|
257
|
+
className,
|
|
258
|
+
variant = "default",
|
|
259
|
+
...props
|
|
260
|
+
}) {
|
|
261
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
262
|
+
tabs.Tabs.List,
|
|
263
|
+
{
|
|
264
|
+
"data-slot": "tabs-list",
|
|
265
|
+
"data-variant": variant,
|
|
266
|
+
className: cn("datetime-range-tabs-list", className),
|
|
267
|
+
...props
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
function TabsTrigger({ className, ...props }) {
|
|
272
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
273
|
+
tabs.Tabs.Tab,
|
|
274
|
+
{
|
|
275
|
+
"data-slot": "tabs-trigger",
|
|
276
|
+
className: cn("datetime-range-tabs-trigger", className),
|
|
277
|
+
...props
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
function TabsContent({ className, ...props }) {
|
|
282
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
283
|
+
tabs.Tabs.Panel,
|
|
284
|
+
{
|
|
285
|
+
"data-slot": "tabs-content",
|
|
286
|
+
className: cn("datetime-range-tabs-content", className),
|
|
287
|
+
...props
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
function Input({ className, type, ...props }) {
|
|
292
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
293
|
+
input.Input,
|
|
294
|
+
{
|
|
295
|
+
type,
|
|
296
|
+
"data-slot": "input",
|
|
297
|
+
className: cn(
|
|
298
|
+
"datetime-range-input",
|
|
299
|
+
className
|
|
300
|
+
),
|
|
301
|
+
...props
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
305
|
function Switch({
|
|
306
306
|
className,
|
|
307
307
|
size = "default",
|
|
@@ -312,13 +312,13 @@ function Switch({
|
|
|
312
312
|
{
|
|
313
313
|
"data-slot": "switch",
|
|
314
314
|
"data-size": size,
|
|
315
|
-
className: cn("
|
|
315
|
+
className: cn("datetime-range-switch", className),
|
|
316
316
|
...props,
|
|
317
317
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
318
318
|
_switch.Switch.Thumb,
|
|
319
319
|
{
|
|
320
320
|
"data-slot": "switch-thumb",
|
|
321
|
-
className: "
|
|
321
|
+
className: "datetime-range-switch-thumb"
|
|
322
322
|
}
|
|
323
323
|
)
|
|
324
324
|
}
|
|
@@ -336,7 +336,7 @@ function ScrollArea({
|
|
|
336
336
|
{
|
|
337
337
|
"data-slot": "scroll-area",
|
|
338
338
|
style: { position: "relative", ...style },
|
|
339
|
-
className: cn("
|
|
339
|
+
className: cn("datetime-range-scroll-area", className),
|
|
340
340
|
...props,
|
|
341
341
|
children: [
|
|
342
342
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -344,7 +344,7 @@ function ScrollArea({
|
|
|
344
344
|
{
|
|
345
345
|
ref: viewportRef,
|
|
346
346
|
"data-slot": "scroll-area-viewport",
|
|
347
|
-
className: "
|
|
347
|
+
className: "datetime-range-scroll-area-viewport",
|
|
348
348
|
children
|
|
349
349
|
}
|
|
350
350
|
),
|
|
@@ -365,23 +365,117 @@ function ScrollBar({
|
|
|
365
365
|
{
|
|
366
366
|
"data-slot": "scroll-area-scrollbar",
|
|
367
367
|
orientation,
|
|
368
|
-
className: cn("
|
|
368
|
+
className: cn("datetime-range-scrollbar", className),
|
|
369
369
|
...props,
|
|
370
370
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
371
371
|
scrollArea.ScrollArea.Thumb,
|
|
372
372
|
{
|
|
373
373
|
"data-slot": "scroll-area-thumb",
|
|
374
|
-
className: "
|
|
374
|
+
className: "datetime-range-scrollbar-thumb"
|
|
375
375
|
}
|
|
376
376
|
)
|
|
377
377
|
}
|
|
378
378
|
);
|
|
379
379
|
}
|
|
380
|
+
var defaultUIAdapter = {
|
|
381
|
+
Button,
|
|
382
|
+
Popover,
|
|
383
|
+
PopoverTrigger,
|
|
384
|
+
PopoverContent,
|
|
385
|
+
Select,
|
|
386
|
+
SelectTrigger,
|
|
387
|
+
SelectValue,
|
|
388
|
+
SelectContent,
|
|
389
|
+
SelectItem,
|
|
390
|
+
Tabs,
|
|
391
|
+
TabsList,
|
|
392
|
+
TabsTrigger,
|
|
393
|
+
TabsContent,
|
|
394
|
+
Input,
|
|
395
|
+
Switch,
|
|
396
|
+
ScrollArea
|
|
397
|
+
};
|
|
398
|
+
var DatetimeRangeUIContext = React2.createContext(defaultUIAdapter);
|
|
399
|
+
function useResolvedDatetimeRangeUI(adapter) {
|
|
400
|
+
const parent = React2.useContext(DatetimeRangeUIContext);
|
|
401
|
+
return React2.useMemo(() => adapter ? { ...parent, ...adapter } : parent, [parent, adapter]);
|
|
402
|
+
}
|
|
403
|
+
function DatetimeRangeProvider({ adapter, children }) {
|
|
404
|
+
const value = useResolvedDatetimeRangeUI(adapter);
|
|
405
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DatetimeRangeUIContext.Provider, { value, children });
|
|
406
|
+
}
|
|
407
|
+
function useDatetimeRangeUI() {
|
|
408
|
+
return React2.useContext(DatetimeRangeUIContext);
|
|
409
|
+
}
|
|
410
|
+
function Button2(props) {
|
|
411
|
+
const { Button: Component } = useDatetimeRangeUI();
|
|
412
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
413
|
+
}
|
|
414
|
+
function Popover2(props) {
|
|
415
|
+
const { Popover: Component } = useDatetimeRangeUI();
|
|
416
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
417
|
+
}
|
|
418
|
+
function PopoverTrigger2(props) {
|
|
419
|
+
const { PopoverTrigger: Component } = useDatetimeRangeUI();
|
|
420
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
421
|
+
}
|
|
422
|
+
function PopoverContent2(props) {
|
|
423
|
+
const { PopoverContent: Component } = useDatetimeRangeUI();
|
|
424
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
425
|
+
}
|
|
426
|
+
function Select2(props) {
|
|
427
|
+
const { Select: Component } = useDatetimeRangeUI();
|
|
428
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
429
|
+
}
|
|
430
|
+
function SelectTrigger2(props) {
|
|
431
|
+
const { SelectTrigger: Component } = useDatetimeRangeUI();
|
|
432
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
433
|
+
}
|
|
434
|
+
function SelectValue2(props) {
|
|
435
|
+
const { SelectValue: Component } = useDatetimeRangeUI();
|
|
436
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
437
|
+
}
|
|
438
|
+
function SelectContent2(props) {
|
|
439
|
+
const { SelectContent: Component } = useDatetimeRangeUI();
|
|
440
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
441
|
+
}
|
|
442
|
+
function SelectItem2(props) {
|
|
443
|
+
const { SelectItem: Component } = useDatetimeRangeUI();
|
|
444
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
445
|
+
}
|
|
446
|
+
function Tabs2(props) {
|
|
447
|
+
const { Tabs: Component } = useDatetimeRangeUI();
|
|
448
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
449
|
+
}
|
|
450
|
+
function TabsList2(props) {
|
|
451
|
+
const { TabsList: Component } = useDatetimeRangeUI();
|
|
452
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
453
|
+
}
|
|
454
|
+
function TabsTrigger2(props) {
|
|
455
|
+
const { TabsTrigger: Component } = useDatetimeRangeUI();
|
|
456
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
457
|
+
}
|
|
458
|
+
function TabsContent2(props) {
|
|
459
|
+
const { TabsContent: Component } = useDatetimeRangeUI();
|
|
460
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
461
|
+
}
|
|
462
|
+
function Input2(props) {
|
|
463
|
+
const { Input: Component } = useDatetimeRangeUI();
|
|
464
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
465
|
+
}
|
|
466
|
+
function Switch2(props) {
|
|
467
|
+
const { Switch: Component } = useDatetimeRangeUI();
|
|
468
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
469
|
+
}
|
|
470
|
+
function ScrollArea2(props) {
|
|
471
|
+
const { ScrollArea: Component } = useDatetimeRangeUI();
|
|
472
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
473
|
+
}
|
|
380
474
|
var AM_VALUE = 0;
|
|
381
475
|
var PM_VALUE = 1;
|
|
382
476
|
function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, className }) {
|
|
383
|
-
const yearRef =
|
|
384
|
-
const years =
|
|
477
|
+
const yearRef = React2.useRef(null);
|
|
478
|
+
const years = React2.useMemo(() => {
|
|
385
479
|
const result = [];
|
|
386
480
|
for (let i = 1912; i < 2100; i++) {
|
|
387
481
|
let disabled = false;
|
|
@@ -393,7 +487,7 @@ function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, cl
|
|
|
393
487
|
}
|
|
394
488
|
return result;
|
|
395
489
|
}, [value, minDate, maxDate]);
|
|
396
|
-
const months =
|
|
490
|
+
const months = React2.useMemo(() => {
|
|
397
491
|
const result = [];
|
|
398
492
|
for (let i = 0; i < 12; i++) {
|
|
399
493
|
let disabled = false;
|
|
@@ -405,7 +499,7 @@ function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, cl
|
|
|
405
499
|
}
|
|
406
500
|
return result;
|
|
407
501
|
}, [value, minDate, maxDate]);
|
|
408
|
-
const onYearChange =
|
|
502
|
+
const onYearChange = React2.useCallback(
|
|
409
503
|
(v) => {
|
|
410
504
|
let newDate = dateFns.setYear(value, v.value);
|
|
411
505
|
if (minDate && newDate < minDate) newDate = setMonth.setMonth(newDate, dateFns.getMonth(minDate));
|
|
@@ -414,14 +508,14 @@ function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, cl
|
|
|
414
508
|
},
|
|
415
509
|
[onChange, value, minDate, maxDate]
|
|
416
510
|
);
|
|
417
|
-
|
|
511
|
+
React2.useEffect(() => {
|
|
418
512
|
if (mode === "year") {
|
|
419
513
|
yearRef.current?.scrollIntoView({ behavior: "auto", block: "center" });
|
|
420
514
|
}
|
|
421
515
|
}, [mode, value]);
|
|
422
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(className), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
516
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(className), children: /* @__PURE__ */ jsxRuntime.jsxs(ScrollArea2, { className: "h-full", children: [
|
|
423
517
|
mode === "year" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-4", children: years.map((year) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref: year.value === dateFns.getYear(value) ? yearRef : void 0, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
424
|
-
|
|
518
|
+
Button2,
|
|
425
519
|
{
|
|
426
520
|
disabled: year.disabled,
|
|
427
521
|
variant: dateFns.getYear(value) === year.value ? "default" : "ghost",
|
|
@@ -431,7 +525,7 @@ function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, cl
|
|
|
431
525
|
}
|
|
432
526
|
) }, year.value)) }),
|
|
433
527
|
mode === "month" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-3 gap-4 mt-7", children: months.map((month) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
434
|
-
|
|
528
|
+
Button2,
|
|
435
529
|
{
|
|
436
530
|
size: "lg",
|
|
437
531
|
disabled: month.disabled,
|
|
@@ -446,7 +540,7 @@ function MonthYearPicker({ value, minDate, maxDate, mode = "month", onChange, cl
|
|
|
446
540
|
}
|
|
447
541
|
function TimeItem({ option, selected, onSelect, className, disabled }) {
|
|
448
542
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
449
|
-
|
|
543
|
+
Button2,
|
|
450
544
|
{
|
|
451
545
|
variant: "ghost",
|
|
452
546
|
className: cn("flex justify-center px-1 pe-2 ps-1", className),
|
|
@@ -471,22 +565,22 @@ function buildTime({ use12HourFormat, value, formatStr, hour, minute, second, am
|
|
|
471
565
|
return dateFns.setHours(dateFns.setMinutes(dateFns.setSeconds(value, second), minute), hour);
|
|
472
566
|
}
|
|
473
567
|
function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker }) {
|
|
474
|
-
const formatStr =
|
|
568
|
+
const formatStr = React2.useMemo(
|
|
475
569
|
() => use12HourFormat ? "yyyy-MM-dd hh:mm:ss.SSS a xxxx" : "yyyy-MM-dd HH:mm:ss.SSS xxxx",
|
|
476
570
|
[use12HourFormat]
|
|
477
571
|
);
|
|
478
|
-
const [ampm, setAmpm] =
|
|
479
|
-
const [hour, setHour] =
|
|
480
|
-
const [minute, setMinute] =
|
|
481
|
-
const [second, setSecond] =
|
|
482
|
-
|
|
572
|
+
const [ampm, setAmpm] = React2.useState(dateFns.format(value, "a") === "AM" ? AM_VALUE : PM_VALUE);
|
|
573
|
+
const [hour, setHour] = React2.useState(use12HourFormat ? +dateFns.format(value, "hh") : value.getHours());
|
|
574
|
+
const [minute, setMinute] = React2.useState(value.getMinutes());
|
|
575
|
+
const [second, setSecond] = React2.useState(value.getSeconds());
|
|
576
|
+
React2.useEffect(() => {
|
|
483
577
|
onChange(buildTime({ use12HourFormat, value, formatStr, hour, minute, second, ampm }));
|
|
484
578
|
}, [hour, minute, second, ampm, formatStr, use12HourFormat]);
|
|
485
|
-
const hourIn24h =
|
|
579
|
+
const hourIn24h = React2.useMemo(
|
|
486
580
|
() => use12HourFormat ? hour % 12 + ampm * 12 : hour,
|
|
487
581
|
[hour, use12HourFormat, ampm]
|
|
488
582
|
);
|
|
489
|
-
const hours =
|
|
583
|
+
const hours = React2.useMemo(
|
|
490
584
|
() => Array.from({ length: use12HourFormat ? 12 : 24 }, (_, i) => {
|
|
491
585
|
const hourValue = use12HourFormat ? i === 0 ? 12 : i : i;
|
|
492
586
|
const hDate = dateFns.setHours(value, use12HourFormat ? i + ampm * 12 : i);
|
|
@@ -497,7 +591,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
497
591
|
}),
|
|
498
592
|
[value, min, max, use12HourFormat, ampm]
|
|
499
593
|
);
|
|
500
|
-
const minutes =
|
|
594
|
+
const minutes = React2.useMemo(() => {
|
|
501
595
|
const anchor = dateFns.setHours(value, hourIn24h);
|
|
502
596
|
return Array.from({ length: 60 }, (_, i) => {
|
|
503
597
|
const mDate = dateFns.setMinutes(anchor, i);
|
|
@@ -507,7 +601,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
507
601
|
return { value: i, label: i.toString().padStart(2, "0"), disabled };
|
|
508
602
|
});
|
|
509
603
|
}, [value, min, max, hourIn24h]);
|
|
510
|
-
const seconds =
|
|
604
|
+
const seconds = React2.useMemo(() => {
|
|
511
605
|
const anchor = dateFns.setMilliseconds(dateFns.setMinutes(dateFns.setHours(value, hourIn24h), minute), 0);
|
|
512
606
|
const _min = min ? dateFns.setMilliseconds(min, 0) : void 0;
|
|
513
607
|
const _max = max ? dateFns.setMilliseconds(max, 0) : void 0;
|
|
@@ -519,7 +613,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
519
613
|
return { value: i, label: i.toString().padStart(2, "0"), disabled };
|
|
520
614
|
});
|
|
521
615
|
}, [value, minute, min, max, hourIn24h]);
|
|
522
|
-
const ampmOptions =
|
|
616
|
+
const ampmOptions = React2.useMemo(() => {
|
|
523
617
|
const startD = dateFns.startOfDay(value);
|
|
524
618
|
const endD = dateFns.endOfDay(value);
|
|
525
619
|
return [
|
|
@@ -534,11 +628,11 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
534
628
|
return { ...v, disabled };
|
|
535
629
|
});
|
|
536
630
|
}, [value, min, max]);
|
|
537
|
-
const [open, setOpen] =
|
|
538
|
-
const hourViewportRef =
|
|
539
|
-
const minuteViewportRef =
|
|
540
|
-
const secondViewportRef =
|
|
541
|
-
|
|
631
|
+
const [open, setOpen] = React2.useState(false);
|
|
632
|
+
const hourViewportRef = React2.useRef(null);
|
|
633
|
+
const minuteViewportRef = React2.useRef(null);
|
|
634
|
+
const secondViewportRef = React2.useRef(null);
|
|
635
|
+
React2.useEffect(() => {
|
|
542
636
|
const id = setTimeout(() => {
|
|
543
637
|
if (open) {
|
|
544
638
|
const ITEM_H = 32;
|
|
@@ -550,7 +644,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
550
644
|
}, 1);
|
|
551
645
|
return () => clearTimeout(id);
|
|
552
646
|
}, [open, hours, hour, minute, second]);
|
|
553
|
-
const onHourChange =
|
|
647
|
+
const onHourChange = React2.useCallback(
|
|
554
648
|
(v) => {
|
|
555
649
|
if (min) {
|
|
556
650
|
const t = buildTime({ use12HourFormat, value, formatStr, hour: v.value, minute, second, ampm });
|
|
@@ -570,7 +664,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
570
664
|
},
|
|
571
665
|
[use12HourFormat, value, formatStr, minute, second, ampm, min, max]
|
|
572
666
|
);
|
|
573
|
-
const onMinuteChange =
|
|
667
|
+
const onMinuteChange = React2.useCallback(
|
|
574
668
|
(v) => {
|
|
575
669
|
if (min) {
|
|
576
670
|
const t = buildTime({ use12HourFormat, value, formatStr, hour, minute: v.value, second, ampm });
|
|
@@ -584,7 +678,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
584
678
|
},
|
|
585
679
|
[use12HourFormat, value, formatStr, hour, second, ampm, min, max]
|
|
586
680
|
);
|
|
587
|
-
const onAmpmChange =
|
|
681
|
+
const onAmpmChange = React2.useCallback(
|
|
588
682
|
(v) => {
|
|
589
683
|
if (min) {
|
|
590
684
|
const t = buildTime({ use12HourFormat, value, formatStr, hour, minute, second, ampm: v.value });
|
|
@@ -608,7 +702,7 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
608
702
|
},
|
|
609
703
|
[use12HourFormat, value, formatStr, hour, minute, second, min, max]
|
|
610
704
|
);
|
|
611
|
-
const display =
|
|
705
|
+
const display = React2.useMemo(() => {
|
|
612
706
|
const parts = [];
|
|
613
707
|
for (const el of ["hour", "minute", "second"]) {
|
|
614
708
|
if (!timePicker || timePicker[el]) {
|
|
@@ -617,12 +711,12 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
617
711
|
}
|
|
618
712
|
return dateFns.format(value, parts.join(":") + (use12HourFormat ? " a" : ""));
|
|
619
713
|
}, [value, use12HourFormat, timePicker]);
|
|
620
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
714
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover2, { open, onOpenChange: setOpen, children: [
|
|
621
715
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
622
|
-
|
|
716
|
+
PopoverTrigger2,
|
|
623
717
|
{
|
|
624
718
|
render: (props) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
625
|
-
|
|
719
|
+
Button2,
|
|
626
720
|
{
|
|
627
721
|
...props,
|
|
628
722
|
variant: "ghost",
|
|
@@ -639,11 +733,11 @@ function TimePicker({ value, onChange, use12HourFormat, min, max, timePicker })
|
|
|
639
733
|
)
|
|
640
734
|
}
|
|
641
735
|
),
|
|
642
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
643
|
-
(!timePicker || timePicker.hour) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
644
|
-
(!timePicker || timePicker.minute) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
645
|
-
(!timePicker || timePicker.second) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
646
|
-
use12HourFormat && /* @__PURE__ */ jsxRuntime.jsx(
|
|
736
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent2, { className: "p-0", side: "top", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-col gap-2 p-2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-56 grow", children: [
|
|
737
|
+
(!timePicker || timePicker.hour) && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea2, { className: "h-full grow", viewportRef: hourViewportRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2 pb-48", children: hours.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === hour, onSelect: onHourChange, className: "h-8", disabled: v.disabled }, v.value)) }) }),
|
|
738
|
+
(!timePicker || timePicker.minute) && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea2, { className: "h-full grow", viewportRef: minuteViewportRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2 pb-48", children: minutes.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === minute, onSelect: onMinuteChange, className: "h-8", disabled: v.disabled }, v.value)) }) }),
|
|
739
|
+
(!timePicker || timePicker.second) && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea2, { className: "h-full grow", viewportRef: secondViewportRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2 pb-48", children: seconds.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === second, onSelect: (v2) => setSecond(v2.value), className: "h-8", disabled: v.disabled }, v.value)) }) }),
|
|
740
|
+
use12HourFormat && /* @__PURE__ */ jsxRuntime.jsx(ScrollArea2, { className: "h-full grow", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex grow flex-col items-stretch overflow-y-auto pe-2", children: ampmOptions.map((v) => /* @__PURE__ */ jsxRuntime.jsx(TimeItem, { option: v, selected: v.value === ampm, onSelect: onAmpmChange, className: "h-8", disabled: v.disabled }, v.value)) }) })
|
|
647
741
|
] }) }) })
|
|
648
742
|
] });
|
|
649
743
|
}
|
|
@@ -671,16 +765,16 @@ function DateTimePanel({
|
|
|
671
765
|
getRangeErrorMessage,
|
|
672
766
|
...props
|
|
673
767
|
}) {
|
|
674
|
-
const [monthYearPicker, setMonthYearPicker] =
|
|
675
|
-
const initDate =
|
|
676
|
-
const [month, setMonth] =
|
|
677
|
-
const [date, setDate] =
|
|
678
|
-
const [errorType, setErrorType] =
|
|
679
|
-
const [previousDate, setPreviousDate] =
|
|
680
|
-
const endMonth =
|
|
681
|
-
const minDate =
|
|
682
|
-
const maxDate =
|
|
683
|
-
const validate =
|
|
768
|
+
const [monthYearPicker, setMonthYearPicker] = React2.useState(false);
|
|
769
|
+
const initDate = React2.useMemo(() => new reactDayPicker.TZDate(value || /* @__PURE__ */ new Date(), timezone), [value, timezone]);
|
|
770
|
+
const [month, setMonth] = React2.useState(initDate);
|
|
771
|
+
const [date, setDate] = React2.useState(initDate);
|
|
772
|
+
const [errorType, setErrorType] = React2.useState(null);
|
|
773
|
+
const [previousDate, setPreviousDate] = React2.useState(initDate);
|
|
774
|
+
const endMonth = React2.useMemo(() => dateFns.setYear(month, dateFns.getYear(month) + 1), [month]);
|
|
775
|
+
const minDate = React2.useMemo(() => min ? new reactDayPicker.TZDate(min, timezone) : void 0, [min, timezone]);
|
|
776
|
+
const maxDate = React2.useMemo(() => max ? new reactDayPicker.TZDate(max, timezone) : void 0, [max, timezone]);
|
|
777
|
+
const validate = React2.useCallback(
|
|
684
778
|
(cur, cmp) => {
|
|
685
779
|
if (validateDateRange) return validateDateRange(cur, cmp);
|
|
686
780
|
if (!cmp) return { isValid: true, errorType: null };
|
|
@@ -690,7 +784,7 @@ function DateTimePanel({
|
|
|
690
784
|
},
|
|
691
785
|
[validateDateRange, title]
|
|
692
786
|
);
|
|
693
|
-
const onDayChanged =
|
|
787
|
+
const onDayChanged = React2.useCallback(
|
|
694
788
|
(d) => {
|
|
695
789
|
d.setHours(date.getHours(), date.getMinutes(), date.getSeconds());
|
|
696
790
|
if (min && d < min) d.setHours(min.getHours(), min.getMinutes(), min.getSeconds());
|
|
@@ -700,14 +794,14 @@ function DateTimePanel({
|
|
|
700
794
|
},
|
|
701
795
|
[date, immediate, onChangeAction, min, max]
|
|
702
796
|
);
|
|
703
|
-
const onTimeChanged =
|
|
797
|
+
const onTimeChanged = React2.useCallback(
|
|
704
798
|
(d) => {
|
|
705
799
|
setDate(d);
|
|
706
800
|
if (immediate) onChangeAction(new Date(d), true);
|
|
707
801
|
},
|
|
708
802
|
[immediate, onChangeAction]
|
|
709
803
|
);
|
|
710
|
-
const onSubmit =
|
|
804
|
+
const onSubmit = React2.useCallback(() => {
|
|
711
805
|
const result = validate(date, compareValue);
|
|
712
806
|
setErrorType(result.isValid ? null : result.errorType);
|
|
713
807
|
if (result.isValid) {
|
|
@@ -715,39 +809,39 @@ function DateTimePanel({
|
|
|
715
809
|
setPreviousDate(new Date(date));
|
|
716
810
|
}
|
|
717
811
|
}, [date, onChangeAction, compareValue, validate]);
|
|
718
|
-
const onCancel =
|
|
812
|
+
const onCancel = React2.useCallback(() => {
|
|
719
813
|
setDate(previousDate);
|
|
720
814
|
setMonth(previousDate);
|
|
721
815
|
setErrorType(null);
|
|
722
816
|
onChangeAction(void 0, false);
|
|
723
817
|
}, [previousDate, onChangeAction]);
|
|
724
|
-
const onMonthYearChanged =
|
|
818
|
+
const onMonthYearChanged = React2.useCallback((d, mode) => {
|
|
725
819
|
setMonth(d);
|
|
726
820
|
setMonthYearPicker(mode === "year" ? "month" : false);
|
|
727
821
|
}, []);
|
|
728
|
-
const onNextMonth =
|
|
729
|
-
const onPrevMonth =
|
|
730
|
-
|
|
822
|
+
const onNextMonth = React2.useCallback(() => setMonth(dateFns.addMonths(month, 1)), [month]);
|
|
823
|
+
const onPrevMonth = React2.useCallback(() => setMonth(dateFns.subMonths(month, 1)), [month]);
|
|
824
|
+
React2.useEffect(() => {
|
|
731
825
|
setDate(initDate);
|
|
732
826
|
setMonth(initDate);
|
|
733
827
|
setMonthYearPicker(false);
|
|
734
828
|
setPreviousDate(initDate);
|
|
735
829
|
}, [initDate]);
|
|
736
830
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
737
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
738
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
831
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-panel-header", children: [
|
|
832
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-panel-nav-label", children: [
|
|
739
833
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
740
834
|
/* @__PURE__ */ jsxRuntime.jsx("span", { onClick: () => setMonthYearPicker(monthYearPicker === "month" ? false : "month"), children: dateFns.format(month, "MMMM") }),
|
|
741
835
|
/* @__PURE__ */ jsxRuntime.jsx("span", { onClick: () => setMonthYearPicker(monthYearPicker === "year" ? false : "year"), children: dateFns.format(month, "yyyy") })
|
|
742
836
|
] }),
|
|
743
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
837
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { variant: "ghost", size: "icon", onClick: () => setMonthYearPicker(monthYearPicker ? false : "year"), children: monthYearPicker ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUpIcon, { style: { width: 16, height: 16 } }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDownIcon, { style: { width: 16, height: 16 } }) })
|
|
744
838
|
] }),
|
|
745
|
-
!monthYearPicker && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
746
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
747
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
839
|
+
!monthYearPicker && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-panel-nav-btn", children: [
|
|
840
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { variant: "ghost", size: "icon", "aria-label": "Previous month", onClick: onPrevMonth, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeftIcon, { style: { width: 16, height: 16 } }) }),
|
|
841
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { variant: "ghost", size: "icon", "aria-label": "Next month", onClick: onNextMonth, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRightIcon, { style: { width: 16, height: 16 } }) })
|
|
748
842
|
] })
|
|
749
843
|
] }),
|
|
750
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
844
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-panel-calendar", children: [
|
|
751
845
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
752
846
|
reactDayPicker.DayPicker,
|
|
753
847
|
{
|
|
@@ -772,31 +866,31 @@ function DateTimePanel({
|
|
|
772
866
|
disabled: [max ? { after: max } : null, min ? { before: min } : null].filter(Boolean),
|
|
773
867
|
onMonthChange: setMonth,
|
|
774
868
|
classNames: {
|
|
775
|
-
dropdowns: "
|
|
776
|
-
months: "
|
|
777
|
-
month: "
|
|
869
|
+
dropdowns: "datetime-range-cal-dropdowns",
|
|
870
|
+
months: "datetime-range-cal-months",
|
|
871
|
+
month: "datetime-range-cal-month",
|
|
778
872
|
month_caption: "hidden",
|
|
779
873
|
button_previous: "hidden",
|
|
780
874
|
button_next: "hidden",
|
|
781
|
-
month_grid: "
|
|
782
|
-
weekdays: "
|
|
783
|
-
weekday: "
|
|
784
|
-
week: "
|
|
785
|
-
day: "
|
|
786
|
-
day_button: "
|
|
787
|
-
range_end: "
|
|
788
|
-
selected: "
|
|
789
|
-
today: "
|
|
790
|
-
outside: "
|
|
791
|
-
disabled: "
|
|
792
|
-
range_middle: "
|
|
793
|
-
hidden: "
|
|
875
|
+
month_grid: "datetime-range-cal-month-grid",
|
|
876
|
+
weekdays: "datetime-range-cal-weekdays",
|
|
877
|
+
weekday: "datetime-range-cal-weekday",
|
|
878
|
+
week: "datetime-range-cal-week",
|
|
879
|
+
day: "datetime-range-cal-day",
|
|
880
|
+
day_button: "datetime-range-cal-day-btn",
|
|
881
|
+
range_end: "datetime-range-cal-day-range-end",
|
|
882
|
+
selected: "datetime-range-cal-day-selected",
|
|
883
|
+
today: "datetime-range-cal-day-today",
|
|
884
|
+
outside: "datetime-range-cal-day-outside",
|
|
885
|
+
disabled: "datetime-range-cal-day-disabled",
|
|
886
|
+
range_middle: "datetime-range-cal-day-range-middle",
|
|
887
|
+
hidden: "datetime-range-cal-day-hidden"
|
|
794
888
|
},
|
|
795
889
|
showOutsideDays: true,
|
|
796
890
|
...props
|
|
797
891
|
}
|
|
798
892
|
),
|
|
799
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("
|
|
893
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("datetime-range-panel-overlay", !monthYearPicker && "datetime-range-panel-overlay--hidden") }),
|
|
800
894
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
801
895
|
MonthYearPicker,
|
|
802
896
|
{
|
|
@@ -805,12 +899,12 @@ function DateTimePanel({
|
|
|
805
899
|
onChange: onMonthYearChanged,
|
|
806
900
|
minDate,
|
|
807
901
|
maxDate,
|
|
808
|
-
className: cn("
|
|
902
|
+
className: cn("datetime-range-panel-monthyear", !monthYearPicker && "datetime-range-panel-monthyear--hidden")
|
|
809
903
|
}
|
|
810
904
|
)
|
|
811
905
|
] }),
|
|
812
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
813
|
-
precision !== "date" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
906
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-panel-footer", children: [
|
|
907
|
+
precision !== "date" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-panel-time", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
814
908
|
TimePicker,
|
|
815
909
|
{
|
|
816
910
|
timePicker: precisionToTimePicker(precision),
|
|
@@ -821,10 +915,10 @@ function DateTimePanel({
|
|
|
821
915
|
max: maxDate
|
|
822
916
|
}
|
|
823
917
|
) }),
|
|
824
|
-
(isError || errorType !== null) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
825
|
-
!immediate && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
826
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
827
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
918
|
+
(isError || errorType !== null) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-panel-error", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "datetime-range-panel-error-msg", children: getRangeErrorMessage?.(errorType, title) ?? "Invalid date range." }) }),
|
|
919
|
+
!immediate && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-panel-buttons", children: [
|
|
920
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { variant: "outline", size: "sm", onClick: onCancel, children: "Cancel" }),
|
|
921
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { size: "sm", onClick: onSubmit, children: "Done" })
|
|
828
922
|
] })
|
|
829
923
|
] })
|
|
830
924
|
] });
|
|
@@ -888,8 +982,8 @@ function DatetimeSegmentInput({
|
|
|
888
982
|
isError = false,
|
|
889
983
|
precision = "second"
|
|
890
984
|
}) {
|
|
891
|
-
const containerRef =
|
|
892
|
-
const spanRefs =
|
|
985
|
+
const containerRef = React2.useRef(null);
|
|
986
|
+
const spanRefs = React2.useRef({
|
|
893
987
|
year: null,
|
|
894
988
|
month: null,
|
|
895
989
|
day: null,
|
|
@@ -897,7 +991,7 @@ function DatetimeSegmentInput({
|
|
|
897
991
|
minute: null,
|
|
898
992
|
second: null
|
|
899
993
|
});
|
|
900
|
-
const [typing, setTyping] =
|
|
994
|
+
const [typing, setTyping] = React2.useState({
|
|
901
995
|
year: null,
|
|
902
996
|
month: null,
|
|
903
997
|
day: null,
|
|
@@ -905,14 +999,14 @@ function DatetimeSegmentInput({
|
|
|
905
999
|
minute: null,
|
|
906
1000
|
second: null
|
|
907
1001
|
});
|
|
908
|
-
const date =
|
|
1002
|
+
const date = React2.useMemo(
|
|
909
1003
|
() => !Number.isNaN(value.getTime()) ? value : /* @__PURE__ */ new Date(),
|
|
910
1004
|
[value]
|
|
911
1005
|
);
|
|
912
|
-
const focusSegment =
|
|
1006
|
+
const focusSegment = React2.useCallback((key) => {
|
|
913
1007
|
spanRefs.current[key]?.focus();
|
|
914
1008
|
}, []);
|
|
915
|
-
const commitTyping =
|
|
1009
|
+
const commitTyping = React2.useCallback((key, buf) => {
|
|
916
1010
|
const num = parseInt(buf, 10);
|
|
917
1011
|
const seg = SEGMENTS.find((s) => s.key === key);
|
|
918
1012
|
if (!Number.isNaN(num)) {
|
|
@@ -921,11 +1015,11 @@ function DatetimeSegmentInput({
|
|
|
921
1015
|
}
|
|
922
1016
|
setTyping((prev) => ({ ...prev, [key]: null }));
|
|
923
1017
|
}, [date, onChange]);
|
|
924
|
-
const activeSegments =
|
|
1018
|
+
const activeSegments = React2.useMemo(() => {
|
|
925
1019
|
const count = precision === "date" ? 3 : precision === "hour" ? 4 : precision === "minute" ? 5 : 6;
|
|
926
1020
|
return SEGMENTS.slice(0, count);
|
|
927
1021
|
}, [precision]);
|
|
928
|
-
const handleKeyDown =
|
|
1022
|
+
const handleKeyDown = React2.useCallback((e, seg) => {
|
|
929
1023
|
if (disabled) return;
|
|
930
1024
|
const { key } = seg;
|
|
931
1025
|
const idx = activeSegments.findIndex((s) => s.key === key);
|
|
@@ -970,7 +1064,7 @@ function DatetimeSegmentInput({
|
|
|
970
1064
|
return;
|
|
971
1065
|
}
|
|
972
1066
|
}, [disabled, typing, date, onChange, commitTyping, focusSegment, activeSegments]);
|
|
973
|
-
const handleBlur =
|
|
1067
|
+
const handleBlur = React2.useCallback((key) => {
|
|
974
1068
|
const buf = typing[key];
|
|
975
1069
|
if (buf !== null) commitTyping(key, buf);
|
|
976
1070
|
}, [typing, commitTyping]);
|
|
@@ -984,7 +1078,7 @@ function DatetimeSegmentInput({
|
|
|
984
1078
|
"div",
|
|
985
1079
|
{
|
|
986
1080
|
ref: containerRef,
|
|
987
|
-
className: cn("
|
|
1081
|
+
className: cn("datetime-range-segment-input", className),
|
|
988
1082
|
"data-error": isError || void 0,
|
|
989
1083
|
"data-disabled": disabled || void 0,
|
|
990
1084
|
onMouseDown: (e) => {
|
|
@@ -997,8 +1091,8 @@ function DatetimeSegmentInput({
|
|
|
997
1091
|
children: activeSegments.map((seg, idx) => {
|
|
998
1092
|
const sep = idx === 0 ? null : idx === 3 ? "\xA0" : idx < 3 ? "-" : ":";
|
|
999
1093
|
const isFocused = typing[seg.key] !== null;
|
|
1000
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1001
|
-
sep !== null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "
|
|
1094
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(React2__default.default.Fragment, { children: [
|
|
1095
|
+
sep !== null && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "datetime-range-segment-sep", "aria-hidden": true, children: sep }),
|
|
1002
1096
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1003
1097
|
"div",
|
|
1004
1098
|
{
|
|
@@ -1011,7 +1105,7 @@ function DatetimeSegmentInput({
|
|
|
1011
1105
|
"aria-valuemin": seg.min,
|
|
1012
1106
|
"aria-valuemax": seg.max,
|
|
1013
1107
|
tabIndex: disabled ? -1 : 0,
|
|
1014
|
-
className: "
|
|
1108
|
+
className: "datetime-range-segment",
|
|
1015
1109
|
"data-focused": isFocused || void 0,
|
|
1016
1110
|
style: { height: "24px", lineHeight: "24px" },
|
|
1017
1111
|
onKeyDown: (e) => handleKeyDown(e, seg),
|
|
@@ -1162,14 +1256,14 @@ function validateRange(start, end) {
|
|
|
1162
1256
|
return null;
|
|
1163
1257
|
}
|
|
1164
1258
|
function RelativeSidePanel({ value, onChange, relativeFormats, showNow, labels }) {
|
|
1165
|
-
const [numValue, setNumValue] =
|
|
1259
|
+
const [numValue, setNumValue] = React2.useState(
|
|
1166
1260
|
value.relativeValue !== void 0 ? String(value.relativeValue) : "5"
|
|
1167
1261
|
);
|
|
1168
|
-
const [format3, setFormat] =
|
|
1262
|
+
const [format3, setFormat] = React2.useState(
|
|
1169
1263
|
value.relativeFormat ?? relativeFormats[0] ?? "Minutes ago"
|
|
1170
1264
|
);
|
|
1171
|
-
const [isNow, setIsNow] =
|
|
1172
|
-
|
|
1265
|
+
const [isNow, setIsNow] = React2.useState(value.relativeNow ?? false);
|
|
1266
|
+
React2.useEffect(() => {
|
|
1173
1267
|
if (value.relativeNow) {
|
|
1174
1268
|
setIsNow(true);
|
|
1175
1269
|
} else {
|
|
@@ -1190,17 +1284,17 @@ function RelativeSidePanel({ value, onChange, relativeFormats, showNow, labels }
|
|
|
1190
1284
|
});
|
|
1191
1285
|
}
|
|
1192
1286
|
};
|
|
1193
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1287
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-relative", children: [
|
|
1194
1288
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1195
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "
|
|
1196
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1289
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "datetime-range-relative-label", children: labels.amount }),
|
|
1290
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-relative-row", children: [
|
|
1197
1291
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1198
|
-
|
|
1292
|
+
Input2,
|
|
1199
1293
|
{
|
|
1200
1294
|
type: "text",
|
|
1201
1295
|
inputMode: "numeric",
|
|
1202
1296
|
pattern: "[0-9]*",
|
|
1203
|
-
className: "
|
|
1297
|
+
className: "datetime-range-relative-input",
|
|
1204
1298
|
disabled: isNow,
|
|
1205
1299
|
value: numValue,
|
|
1206
1300
|
onChange: (e) => {
|
|
@@ -1217,7 +1311,7 @@ function RelativeSidePanel({ value, onChange, relativeFormats, showNow, labels }
|
|
|
1217
1311
|
}
|
|
1218
1312
|
),
|
|
1219
1313
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1220
|
-
|
|
1314
|
+
Select2,
|
|
1221
1315
|
{
|
|
1222
1316
|
disabled: isNow,
|
|
1223
1317
|
value: format3,
|
|
@@ -1227,16 +1321,16 @@ function RelativeSidePanel({ value, onChange, relativeFormats, showNow, labels }
|
|
|
1227
1321
|
emit({ numValue, format: f, isNow });
|
|
1228
1322
|
},
|
|
1229
1323
|
children: [
|
|
1230
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1231
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1324
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectTrigger2, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue2, { children: format3 }) }),
|
|
1325
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent2, { children: relativeFormats.map((f) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem2, { value: f, children: f }, f)) })
|
|
1232
1326
|
]
|
|
1233
1327
|
}
|
|
1234
1328
|
)
|
|
1235
1329
|
] })
|
|
1236
1330
|
] }),
|
|
1237
|
-
showNow && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1331
|
+
showNow && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-relative-now-row", children: [
|
|
1238
1332
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1239
|
-
|
|
1333
|
+
Switch2,
|
|
1240
1334
|
{
|
|
1241
1335
|
checked: isNow,
|
|
1242
1336
|
onCheckedChange: (checked) => {
|
|
@@ -1245,9 +1339,9 @@ function RelativeSidePanel({ value, onChange, relativeFormats, showNow, labels }
|
|
|
1245
1339
|
}
|
|
1246
1340
|
}
|
|
1247
1341
|
),
|
|
1248
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1249
|
-
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "
|
|
1250
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "
|
|
1342
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-relative-now-labels", children: [
|
|
1343
|
+
/* @__PURE__ */ jsxRuntime.jsx("label", { className: "datetime-range-relative-now-label", children: labels.now }),
|
|
1344
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "datetime-range-relative-now-desc", children: labels.nowDescription })
|
|
1251
1345
|
] })
|
|
1252
1346
|
] })
|
|
1253
1347
|
] });
|
|
@@ -1261,67 +1355,72 @@ function AbsoluteContent({
|
|
|
1261
1355
|
min,
|
|
1262
1356
|
max,
|
|
1263
1357
|
timezone,
|
|
1264
|
-
use12HourFormat
|
|
1358
|
+
use12HourFormat,
|
|
1359
|
+
calendarMode = "popover"
|
|
1265
1360
|
}) {
|
|
1266
1361
|
const compareDate = compareValue ? toDate(compareValue) : void 0;
|
|
1267
1362
|
const currentDate = value.type === "absolute" ? toDate(value) : /* @__PURE__ */ new Date();
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1363
|
+
const calendarPanel = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1364
|
+
DateTimePanel,
|
|
1365
|
+
{
|
|
1366
|
+
value: value.type === "absolute" ? currentDate : void 0,
|
|
1367
|
+
compareValue: compareDate,
|
|
1368
|
+
title,
|
|
1369
|
+
immediate: true,
|
|
1370
|
+
precision,
|
|
1371
|
+
min,
|
|
1372
|
+
max,
|
|
1373
|
+
timezone,
|
|
1374
|
+
use12HourFormat,
|
|
1375
|
+
onChangeAction: (d) => {
|
|
1376
|
+
if (!d) return;
|
|
1377
|
+
onChange(absoluteDate(d));
|
|
1276
1378
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1379
|
+
}
|
|
1380
|
+
);
|
|
1381
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1382
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-absolute-row", children: [
|
|
1279
1383
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1280
|
-
|
|
1384
|
+
DatetimeSegmentInput,
|
|
1281
1385
|
{
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
type: "button",
|
|
1287
|
-
variant: "outline",
|
|
1288
|
-
size: "icon",
|
|
1289
|
-
className: "dr-absolute-btn",
|
|
1290
|
-
title: "Pick from calendar",
|
|
1291
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { size: 14 })
|
|
1292
|
-
}
|
|
1293
|
-
)
|
|
1386
|
+
value: currentDate,
|
|
1387
|
+
onChange: (d) => onChange(absoluteDate(d)),
|
|
1388
|
+
className: "datetime-range-absolute-input",
|
|
1389
|
+
precision
|
|
1294
1390
|
}
|
|
1295
1391
|
),
|
|
1296
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
immediate: true,
|
|
1311
|
-
precision,
|
|
1312
|
-
min,
|
|
1313
|
-
max,
|
|
1314
|
-
timezone,
|
|
1315
|
-
use12HourFormat,
|
|
1316
|
-
onChangeAction: (d) => {
|
|
1317
|
-
if (!d) return;
|
|
1318
|
-
onChange(absoluteDate(d));
|
|
1392
|
+
calendarMode === "popover" && /* @__PURE__ */ jsxRuntime.jsxs(Popover2, { children: [
|
|
1393
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1394
|
+
PopoverTrigger2,
|
|
1395
|
+
{
|
|
1396
|
+
render: (triggerProps) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1397
|
+
Button2,
|
|
1398
|
+
{
|
|
1399
|
+
...triggerProps,
|
|
1400
|
+
type: "button",
|
|
1401
|
+
variant: "outline",
|
|
1402
|
+
size: "icon",
|
|
1403
|
+
className: "datetime-range-absolute-btn",
|
|
1404
|
+
title: "Pick from calendar",
|
|
1405
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { size: 14 })
|
|
1319
1406
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1407
|
+
)
|
|
1408
|
+
}
|
|
1409
|
+
),
|
|
1410
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1411
|
+
PopoverContent2,
|
|
1412
|
+
{
|
|
1413
|
+
className: "p-0 w-auto",
|
|
1414
|
+
side: "bottom",
|
|
1415
|
+
align: "start",
|
|
1416
|
+
sideOffset: 6,
|
|
1417
|
+
disableAnchorTracking: true,
|
|
1418
|
+
children: calendarPanel
|
|
1419
|
+
}
|
|
1420
|
+
)
|
|
1421
|
+
] })
|
|
1422
|
+
] }),
|
|
1423
|
+
calendarMode === "inline" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-absolute-inline-calendar", children: calendarPanel })
|
|
1325
1424
|
] });
|
|
1326
1425
|
}
|
|
1327
1426
|
function SidePanel({
|
|
@@ -1338,10 +1437,12 @@ function SidePanel({
|
|
|
1338
1437
|
max,
|
|
1339
1438
|
timezone,
|
|
1340
1439
|
use12HourFormat,
|
|
1341
|
-
labels: labelsProp
|
|
1440
|
+
labels: labelsProp,
|
|
1441
|
+
calendarMode,
|
|
1442
|
+
uiAdapter
|
|
1342
1443
|
}) {
|
|
1343
1444
|
const labels = { ...DEFAULT_LABELS, ...labelsProp };
|
|
1344
|
-
|
|
1445
|
+
React2.useEffect(() => {
|
|
1345
1446
|
if (!showRelative && value.type === "relative") {
|
|
1346
1447
|
onChange(absoluteDate(/* @__PURE__ */ new Date()));
|
|
1347
1448
|
} else if (!showAbsolute && value.type === "absolute") {
|
|
@@ -1360,7 +1461,8 @@ function SidePanel({
|
|
|
1360
1461
|
min,
|
|
1361
1462
|
max,
|
|
1362
1463
|
timezone,
|
|
1363
|
-
use12HourFormat
|
|
1464
|
+
use12HourFormat,
|
|
1465
|
+
calendarMode
|
|
1364
1466
|
}
|
|
1365
1467
|
);
|
|
1366
1468
|
const relativeContent = /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1373,13 +1475,13 @@ function SidePanel({
|
|
|
1373
1475
|
labels
|
|
1374
1476
|
}
|
|
1375
1477
|
);
|
|
1376
|
-
|
|
1377
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "
|
|
1478
|
+
const content = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-side-panel", children: [
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "datetime-range-side-panel-title", children: title }),
|
|
1378
1480
|
hasBothModes ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1379
|
-
|
|
1481
|
+
Tabs2,
|
|
1380
1482
|
{
|
|
1381
1483
|
value: value.type,
|
|
1382
|
-
className: "
|
|
1484
|
+
className: "datetime-range-side-panel-tabs",
|
|
1383
1485
|
onValueChange: (t) => {
|
|
1384
1486
|
if (t === "absolute") {
|
|
1385
1487
|
onChange(absoluteDate(value.type === "absolute" ? toDate(value) : /* @__PURE__ */ new Date()));
|
|
@@ -1388,28 +1490,29 @@ function SidePanel({
|
|
|
1388
1490
|
}
|
|
1389
1491
|
},
|
|
1390
1492
|
children: [
|
|
1391
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1392
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1393
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1493
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TabsList2, { className: "datetime-range-tabs-list--grid datetime-range-tabs-list--grid-2", children: [
|
|
1494
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger2, { value: "absolute", children: labels.absolute }),
|
|
1495
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger2, { value: "relative", children: labels.relative })
|
|
1394
1496
|
] }),
|
|
1395
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1396
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1497
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent2, { value: "absolute", children: absoluteContent }),
|
|
1498
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent2, { value: "relative", children: relativeContent })
|
|
1397
1499
|
]
|
|
1398
1500
|
}
|
|
1399
1501
|
) : showAbsolute ? absoluteContent : relativeContent
|
|
1400
1502
|
] });
|
|
1503
|
+
return uiAdapter ? /* @__PURE__ */ jsxRuntime.jsx(DatetimeRangeProvider, { adapter: uiAdapter, children: content }) : content;
|
|
1401
1504
|
}
|
|
1402
1505
|
function useDatetimeRange({
|
|
1403
1506
|
startTime,
|
|
1404
1507
|
endTime,
|
|
1405
1508
|
onChange
|
|
1406
1509
|
}) {
|
|
1407
|
-
const [isOpen, setIsOpen] =
|
|
1408
|
-
const [draftStart, setDraftStart] =
|
|
1409
|
-
const [draftEnd, setDraftEnd] =
|
|
1410
|
-
const [error, setError] =
|
|
1411
|
-
const wasOpen =
|
|
1412
|
-
|
|
1510
|
+
const [isOpen, setIsOpen] = React2.useState(false);
|
|
1511
|
+
const [draftStart, setDraftStart] = React2.useState(startTime);
|
|
1512
|
+
const [draftEnd, setDraftEnd] = React2.useState(endTime);
|
|
1513
|
+
const [error, setError] = React2.useState(null);
|
|
1514
|
+
const wasOpen = React2.useRef(false);
|
|
1515
|
+
React2.useEffect(() => {
|
|
1413
1516
|
const justOpened = isOpen && !wasOpen.current;
|
|
1414
1517
|
wasOpen.current = isOpen;
|
|
1415
1518
|
if (justOpened) {
|
|
@@ -1418,8 +1521,8 @@ function useDatetimeRange({
|
|
|
1418
1521
|
setError(null);
|
|
1419
1522
|
}
|
|
1420
1523
|
}, [isOpen, startTime, endTime]);
|
|
1421
|
-
const clearError =
|
|
1422
|
-
const onApply =
|
|
1524
|
+
const clearError = React2.useCallback(() => setError(null), []);
|
|
1525
|
+
const onApply = React2.useCallback(() => {
|
|
1423
1526
|
const err = validateRange(draftStart, draftEnd);
|
|
1424
1527
|
if (err) {
|
|
1425
1528
|
setError(err);
|
|
@@ -1428,13 +1531,13 @@ function useDatetimeRange({
|
|
|
1428
1531
|
onChange(draftStart, draftEnd);
|
|
1429
1532
|
setIsOpen(false);
|
|
1430
1533
|
}, [draftStart, draftEnd, onChange]);
|
|
1431
|
-
const onCancel =
|
|
1534
|
+
const onCancel = React2.useCallback(() => {
|
|
1432
1535
|
setDraftStart(startTime);
|
|
1433
1536
|
setDraftEnd(endTime);
|
|
1434
1537
|
setError(null);
|
|
1435
1538
|
setIsOpen(false);
|
|
1436
1539
|
}, [startTime, endTime]);
|
|
1437
|
-
const onPreset =
|
|
1540
|
+
const onPreset = React2.useCallback((preset) => {
|
|
1438
1541
|
onChange(preset.start, preset.end);
|
|
1439
1542
|
setIsOpen(false);
|
|
1440
1543
|
}, [onChange]);
|
|
@@ -1467,13 +1570,15 @@ function DatetimeRange({
|
|
|
1467
1570
|
timezone,
|
|
1468
1571
|
use12HourFormat = false,
|
|
1469
1572
|
showNow = true,
|
|
1573
|
+
calendarMode = "popover",
|
|
1470
1574
|
disabled = false,
|
|
1471
1575
|
labels: labelsProp,
|
|
1472
1576
|
popoverAlign = "start",
|
|
1473
1577
|
popoverSide = "bottom",
|
|
1474
1578
|
renderTrigger,
|
|
1475
1579
|
portalContainer,
|
|
1476
|
-
className
|
|
1580
|
+
className,
|
|
1581
|
+
uiAdapter
|
|
1477
1582
|
}) {
|
|
1478
1583
|
const labels = { ...DEFAULT_LABELS, ...labelsProp };
|
|
1479
1584
|
const {
|
|
@@ -1499,24 +1604,25 @@ function DatetimeRange({
|
|
|
1499
1604
|
max,
|
|
1500
1605
|
timezone,
|
|
1501
1606
|
use12HourFormat,
|
|
1502
|
-
labels
|
|
1607
|
+
labels,
|
|
1608
|
+
calendarMode
|
|
1503
1609
|
};
|
|
1504
|
-
|
|
1610
|
+
const content = /* @__PURE__ */ jsxRuntime.jsxs(Popover2, { open: isOpen, onOpenChange: disabled ? void 0 : setIsOpen, children: [
|
|
1505
1611
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1506
|
-
|
|
1612
|
+
PopoverTrigger2,
|
|
1507
1613
|
{
|
|
1508
1614
|
disabled,
|
|
1509
1615
|
render: (triggerProps) => renderTrigger ? renderTrigger(triggerProps, { open: isOpen, startTime, endTime }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1510
|
-
|
|
1616
|
+
Button2,
|
|
1511
1617
|
{
|
|
1512
1618
|
...triggerProps,
|
|
1513
1619
|
variant: "outline",
|
|
1514
1620
|
disabled,
|
|
1515
|
-
className: cn("
|
|
1621
|
+
className: cn("datetime-range-range-trigger", isOpen && "datetime-range-range-trigger--open", className),
|
|
1516
1622
|
children: [
|
|
1517
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { size: 14, className: "
|
|
1623
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { size: 14, className: "datetime-range-range-trigger-icon" }),
|
|
1518
1624
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: toDisplayString(startTime, { precision }) }),
|
|
1519
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "
|
|
1625
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "datetime-range-range-trigger-arrow", children: "\u2192" }),
|
|
1520
1626
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: toDisplayString(endTime, { precision }) })
|
|
1521
1627
|
]
|
|
1522
1628
|
}
|
|
@@ -1524,31 +1630,31 @@ function DatetimeRange({
|
|
|
1524
1630
|
}
|
|
1525
1631
|
),
|
|
1526
1632
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1527
|
-
|
|
1633
|
+
PopoverContent2,
|
|
1528
1634
|
{
|
|
1529
|
-
className: "
|
|
1635
|
+
className: "datetime-range-range-popup-content",
|
|
1530
1636
|
align: popoverAlign,
|
|
1531
1637
|
side: popoverSide,
|
|
1532
1638
|
sideOffset: 4,
|
|
1533
1639
|
container: portalContainer,
|
|
1534
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1535
|
-
showQuickRanges && quickPresets.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
1536
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
1537
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
1640
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-range-popup", children: [
|
|
1641
|
+
showQuickRanges && quickPresets.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-range-quick", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-range-quick-inner", children: [
|
|
1642
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-range-quick-label", children: labels.quickRanges }),
|
|
1643
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-range-quick-list", children: quickPresets.map((preset) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1538
1644
|
"button",
|
|
1539
1645
|
{
|
|
1540
1646
|
type: "button",
|
|
1541
|
-
className: "
|
|
1647
|
+
className: "datetime-range-range-quick-item",
|
|
1542
1648
|
onClick: () => handlePreset(preset),
|
|
1543
1649
|
children: preset.label
|
|
1544
1650
|
},
|
|
1545
1651
|
preset.label
|
|
1546
1652
|
)) })
|
|
1547
1653
|
] }) }),
|
|
1548
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1549
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
1550
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1551
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
1654
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-range-pickers", children: [
|
|
1655
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-range-divider" }),
|
|
1656
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-range-panels", children: [
|
|
1657
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-range-panel-slot", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1552
1658
|
SidePanel,
|
|
1553
1659
|
{
|
|
1554
1660
|
title: labels.start,
|
|
@@ -1561,7 +1667,7 @@ function DatetimeRange({
|
|
|
1561
1667
|
...sidePanelProps
|
|
1562
1668
|
}
|
|
1563
1669
|
) }),
|
|
1564
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "
|
|
1670
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "datetime-range-range-panel-slot", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1565
1671
|
SidePanel,
|
|
1566
1672
|
{
|
|
1567
1673
|
title: labels.end,
|
|
@@ -1575,11 +1681,11 @@ function DatetimeRange({
|
|
|
1575
1681
|
}
|
|
1576
1682
|
) })
|
|
1577
1683
|
] }),
|
|
1578
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1579
|
-
error === "validation" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "
|
|
1580
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "
|
|
1581
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1582
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1684
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-range-footer", children: [
|
|
1685
|
+
error === "validation" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "datetime-range-range-error-text", children: "Start must be earlier than end." }) : /* @__PURE__ */ jsxRuntime.jsx("span", {}),
|
|
1686
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "datetime-range-range-actions", children: [
|
|
1687
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { variant: "outline", size: "sm", onClick: handleCancel, children: labels.cancel }),
|
|
1688
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button2, { size: "sm", onClick: handleApply, children: labels.apply })
|
|
1583
1689
|
] })
|
|
1584
1690
|
] })
|
|
1585
1691
|
] })
|
|
@@ -1587,10 +1693,12 @@ function DatetimeRange({
|
|
|
1587
1693
|
}
|
|
1588
1694
|
)
|
|
1589
1695
|
] });
|
|
1696
|
+
return uiAdapter ? /* @__PURE__ */ jsxRuntime.jsx(DatetimeRangeProvider, { adapter: uiAdapter, children: content }) : content;
|
|
1590
1697
|
}
|
|
1591
1698
|
|
|
1592
1699
|
exports.DateTimePanel = DateTimePanel;
|
|
1593
1700
|
exports.DatetimeRange = DatetimeRange;
|
|
1701
|
+
exports.DatetimeRangeProvider = DatetimeRangeProvider;
|
|
1594
1702
|
exports.DatetimeSegmentInput = DatetimeSegmentInput;
|
|
1595
1703
|
exports.QUICK_PRESETS = QUICK_PRESETS;
|
|
1596
1704
|
exports.RELATIVE_FORMATS = RELATIVE_FORMATS;
|
|
@@ -1605,6 +1713,7 @@ exports.toTimestamp = toTimestamp;
|
|
|
1605
1713
|
exports.toTimestampMs = toTimestampMs;
|
|
1606
1714
|
exports.toUrlString = toUrlString;
|
|
1607
1715
|
exports.useDatetimeRange = useDatetimeRange;
|
|
1716
|
+
exports.useDatetimeRangeUI = useDatetimeRangeUI;
|
|
1608
1717
|
exports.validateRange = validateRange;
|
|
1609
1718
|
//# sourceMappingURL=index.cjs.map
|
|
1610
1719
|
//# sourceMappingURL=index.cjs.map
|