@cognite/aura 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -3
- package/dist/colors.css +30 -0
- package/dist/components/index.d.ts +6 -36
- package/dist/components/index.js +311 -347
- package/dist/components/ui/core/accordion/accordion.d.ts +7 -7
- package/dist/components/ui/core/accordion/accordion.js +49 -47
- package/dist/components/ui/core/action-toolbar/action-toolbar.d.ts +41 -0
- package/dist/components/ui/core/action-toolbar/action-toolbar.js +176 -0
- package/dist/components/ui/core/alert/alert.d.ts +23 -12
- package/dist/components/ui/core/alert/alert.js +123 -120
- package/dist/components/ui/core/avatar/avatar.d.ts +12 -8
- package/dist/components/ui/core/badge/badge.d.ts +11 -8
- package/dist/components/ui/core/banner/banner.d.ts +18 -28
- package/dist/components/ui/core/banner/banner.js +6 -6
- package/dist/components/ui/core/breadcrumb/breadcrumb.d.ts +10 -9
- package/dist/components/ui/core/breadcrumb/breadcrumb.js +98 -88
- package/dist/components/ui/core/button/button.d.ts +8 -5
- package/dist/components/ui/core/button/button.js +22 -19
- package/dist/components/ui/core/button-group/button-group.d.ts +7 -6
- package/dist/components/ui/core/card/card.d.ts +17 -16
- package/dist/components/ui/core/chart/chart.d.ts +69 -0
- package/dist/components/ui/core/chart/chart.js +215 -0
- package/dist/components/ui/core/chart/index.d.ts +2 -0
- package/dist/components/ui/core/chart/index.js +8 -0
- package/dist/components/ui/core/checkbox/checkbox.d.ts +13 -9
- package/dist/components/ui/core/checkbox/checkbox.js +38 -34
- package/dist/components/ui/core/code-block/code-block.d.ts +6 -9
- package/dist/components/ui/core/code-block/code-block.js +52 -48
- package/dist/components/ui/core/collapsible/collapsible.d.ts +5 -3
- package/dist/components/ui/core/combobox/combobox.d.ts +2 -2
- package/dist/components/ui/core/command/command.d.ts +11 -78
- package/dist/components/ui/core/command/command.js +53 -52
- package/dist/components/ui/core/count/count.d.ts +7 -6
- package/dist/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.d.ts +15 -0
- package/dist/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.js +99 -0
- package/dist/components/ui/core/date-time-pickers/date-range-picker/index.d.ts +3 -0
- package/dist/components/ui/core/date-time-pickers/date-range-picker/types.d.ts +25 -0
- package/dist/components/ui/core/date-time-pickers/date-range-picker/use-date-range-picker.d.ts +4 -0
- package/dist/components/ui/core/date-time-pickers/date-range-picker/use-date-range-picker.js +82 -0
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.d.ts +17 -0
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.js +190 -0
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/index.d.ts +3 -0
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/types.d.ts +42 -0
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/use-date-time-range-picker.d.ts +3 -0
- package/dist/components/ui/core/date-time-pickers/date-time-range-picker/use-date-time-range-picker.js +161 -0
- package/dist/components/ui/core/date-time-pickers/index.d.ts +6 -0
- package/dist/components/ui/core/date-time-pickers/shared/am-pm-scroll/am-pm-scroll.d.ts +7 -0
- package/dist/components/ui/core/date-time-pickers/shared/am-pm-scroll/am-pm-scroll.js +57 -0
- package/dist/components/ui/core/date-time-pickers/shared/calendar/calendar.d.ts +13 -0
- package/dist/components/ui/core/date-time-pickers/shared/calendar/calendar.js +119 -0
- package/dist/components/ui/core/date-time-pickers/shared/calendar-header/calendar-header.d.ts +10 -0
- package/dist/components/ui/core/date-time-pickers/shared/calendar-header/calendar-header.js +93 -0
- package/dist/components/ui/core/date-time-pickers/shared/constants.d.ts +20 -0
- package/dist/components/ui/core/date-time-pickers/shared/constants.js +14 -0
- package/dist/components/ui/core/date-time-pickers/shared/date-time-input/date-time-input.d.ts +19 -0
- package/dist/components/ui/core/date-time-pickers/shared/date-time-input/date-time-input.js +99 -0
- package/dist/components/ui/core/date-time-pickers/shared/date-time-input/range-input-display.d.ts +12 -0
- package/dist/components/ui/core/date-time-pickers/shared/date-time-input/range-input-display.js +68 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-popover-state.d.ts +12 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-popover-state.js +40 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-range-date-state.d.ts +29 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-range-date-state.js +63 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-range-step-manager.d.ts +8 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-range-step-manager.js +19 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-time-state.d.ts +17 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-time-state.js +34 -0
- package/dist/components/ui/core/date-time-pickers/shared/scroll-cell-classes.d.ts +8 -0
- package/dist/components/ui/core/date-time-pickers/shared/scroll-cell-classes.js +7 -0
- package/dist/components/ui/core/date-time-pickers/shared/shortcuts-panel/shortcuts-panel.d.ts +13 -0
- package/dist/components/ui/core/date-time-pickers/shared/shortcuts-panel/shortcuts-panel.js +31 -0
- package/dist/components/ui/core/date-time-pickers/shared/time-picker-scroll/time-picker-scroll.d.ts +10 -0
- package/dist/components/ui/core/date-time-pickers/shared/time-picker-scroll/time-picker-scroll.js +52 -0
- package/dist/components/ui/core/date-time-pickers/utils/calendar-utils.d.ts +48 -0
- package/dist/components/ui/core/date-time-pickers/utils/calendar-utils.js +52 -0
- package/dist/components/ui/core/date-time-pickers/utils/date-range-utils.d.ts +26 -0
- package/dist/components/ui/core/date-time-pickers/utils/format-utils.d.ts +37 -0
- package/dist/components/ui/core/date-time-pickers/utils/segment-utils.d.ts +34 -0
- package/dist/components/ui/core/date-time-pickers/utils/time-utils.d.ts +43 -0
- package/dist/components/ui/core/date-time-pickers/utils/time-utils.js +15 -0
- package/dist/components/ui/core/date-time-pickers/utils/time-validation.d.ts +23 -0
- package/dist/components/ui/core/dialog/dialog.d.ts +10 -10
- package/dist/components/ui/core/dialog/dialog.js +12 -3
- package/dist/components/ui/core/dropdown-menu/dropdown-menu.d.ts +24 -47
- package/dist/components/ui/core/dropdown-menu/dropdown-menu.js +125 -123
- package/dist/components/ui/core/empty-state/empty-state.context.d.ts +10 -0
- package/dist/components/ui/core/empty-state/empty-state.context.js +8 -0
- package/dist/components/ui/core/empty-state/empty-state.d.ts +18 -0
- package/dist/components/ui/core/empty-state/empty-state.js +139 -0
- package/dist/components/ui/core/helper-text/helper-text.d.ts +7 -5
- package/dist/components/ui/core/hover-card/hover-card.d.ts +5 -7
- package/dist/components/ui/core/hover-card/hover-card.js +26 -25
- package/dist/components/ui/core/inline-citation/inline-citation.d.ts +10 -10
- package/dist/components/ui/core/inline-citation/inline-citation.js +57 -49
- package/dist/components/ui/core/input/input.d.ts +2 -1
- package/dist/components/ui/core/input-group/input-group.d.ts +17 -13
- package/dist/components/ui/core/input-group/input-group.js +35 -36
- package/dist/components/ui/core/kbd/kbd.d.ts +3 -2
- package/dist/components/ui/core/label/label.d.ts +3 -2
- package/dist/components/ui/core/loader/loader.d.ts +2 -2
- package/dist/components/ui/core/message/message.d.ts +18 -17
- package/dist/components/ui/core/message/message.js +15 -13
- package/dist/components/ui/core/pagination/pagination-size-context.d.ts +5 -0
- package/dist/components/ui/core/pagination/pagination-size-context.js +6 -0
- package/dist/components/ui/core/pagination/pagination-teleport.d.ts +11 -0
- package/dist/components/ui/core/pagination/pagination-teleport.js +108 -0
- package/dist/components/ui/core/pagination/pagination-teleport.utils.d.ts +1 -0
- package/dist/components/ui/core/pagination/pagination-teleport.utils.js +7 -0
- package/dist/components/ui/core/pagination/pagination.d.ts +41 -0
- package/dist/components/ui/core/pagination/pagination.js +335 -0
- package/dist/components/ui/core/popover/popover.d.ts +12 -16
- package/dist/components/ui/core/popover/popover.js +52 -51
- package/dist/components/ui/core/progress/progress.d.ts +7 -4
- package/dist/components/ui/core/prompt-input/prompt-input.d.ts +36 -103
- package/dist/components/ui/core/prompt-input/prompt-input.js +193 -180
- package/dist/components/ui/core/radio-group/radio-group.d.ts +12 -8
- package/dist/components/ui/core/radio-group/radio-group.js +58 -55
- package/dist/components/ui/core/reasoning/reasoning.d.ts +5 -5
- package/dist/components/ui/core/reasoning/reasoning.js +1 -1
- package/dist/components/ui/core/scroll-area/scroll-area.d.ts +4 -2
- package/dist/components/ui/core/search/search.d.ts +10 -0
- package/dist/components/ui/core/search/search.js +99 -0
- package/dist/components/ui/core/segmented-control/segmented-control.d.ts +15 -11
- package/dist/components/ui/core/segmented-control/segmented-control.js +7 -4
- package/dist/components/ui/core/select/select.d.ts +13 -13
- package/dist/components/ui/core/select/select.js +13 -10
- package/dist/components/ui/core/separator/separator.d.ts +2 -4
- package/dist/components/ui/core/separator/separator.js +4 -5
- package/dist/components/ui/core/shimmer/shimmer.d.ts +3 -5
- package/dist/components/ui/core/shimmer/shimmer.js +25 -26
- package/dist/components/ui/core/skeleton/skeleton.d.ts +2 -1
- package/dist/components/ui/core/sonner-toast/sonner-toast.d.ts +2 -1
- package/dist/components/ui/core/sources/sources.d.ts +3 -3
- package/dist/components/ui/core/sources/sources.js +6 -1
- package/dist/components/ui/core/switch/switch.d.ts +11 -0
- package/dist/components/ui/core/{button/button.metadata.d.ts → switch/switch.metadata.d.ts} +1 -1
- package/dist/components/ui/core/tabs/tabs.d.ts +21 -17
- package/dist/components/ui/core/tabs/tabs.js +14 -12
- package/dist/components/ui/core/textarea/textarea.d.ts +2 -1
- package/dist/components/ui/core/textarea/textarea.js +20 -18
- package/dist/components/ui/core/tool/tool.d.ts +7 -6
- package/dist/components/ui/core/tool/tool.js +48 -44
- package/dist/components/ui/core/tooltip/tooltip.d.ts +6 -5
- package/dist/components/ui/core/tooltip/tooltip.js +10 -8
- package/dist/components/ui/core/topbar/topbar.d.ts +11 -13
- package/dist/eslint/index.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +302 -336
- package/dist/lib/portal-container-context.d.ts +2 -1
- package/dist/lib/portal-container-context.js +1 -3
- package/dist/styles.css +1 -1
- package/dist/styles.source.css +9 -1
- package/package.json +22 -1
- package/dist/components/ui/core/accordion/accordion.metadata.d.ts +0 -2
- package/dist/components/ui/core/accordion/accordion.metadata.js +0 -9
- package/dist/components/ui/core/alert/alert.metadata.d.ts +0 -2
- package/dist/components/ui/core/alert/alert.metadata.js +0 -9
- package/dist/components/ui/core/avatar/avatar.metadata.d.ts +0 -8
- package/dist/components/ui/core/avatar/avatar.metadata.js +0 -9
- package/dist/components/ui/core/badge/badge.metadata.d.ts +0 -2
- package/dist/components/ui/core/badge/badge.metadata.js +0 -8
- package/dist/components/ui/core/banner/banner.metadata.d.ts +0 -2
- package/dist/components/ui/core/banner/banner.metadata.js +0 -9
- package/dist/components/ui/core/breadcrumb/breadcrumb.metadata.d.ts +0 -2
- package/dist/components/ui/core/breadcrumb/breadcrumb.metadata.js +0 -9
- package/dist/components/ui/core/button/button.metadata.js +0 -9
- package/dist/components/ui/core/button-group/button-group.metadata.d.ts +0 -2
- package/dist/components/ui/core/button-group/button-group.metadata.js +0 -8
- package/dist/components/ui/core/card/card.metadata.d.ts +0 -8
- package/dist/components/ui/core/card/card.metadata.js +0 -9
- package/dist/components/ui/core/code-block/code-block.metadata.d.ts +0 -2
- package/dist/components/ui/core/code-block/code-block.metadata.js +0 -8
- package/dist/components/ui/core/collapsible/collapsible.metadata.d.ts +0 -2
- package/dist/components/ui/core/collapsible/collapsible.metadata.js +0 -9
- package/dist/components/ui/core/combobox/combobox.metadata.d.ts +0 -2
- package/dist/components/ui/core/command/command.metadata.d.ts +0 -2
- package/dist/components/ui/core/command/command.metadata.js +0 -9
- package/dist/components/ui/core/dialog/dialog.metadata.d.ts +0 -2
- package/dist/components/ui/core/dialog/dialog.metadata.js +0 -9
- package/dist/components/ui/core/dropdown-menu/dropdown-menu.metadata.d.ts +0 -2
- package/dist/components/ui/core/dropdown-menu/dropdown-menu.metadata.js +0 -9
- package/dist/components/ui/core/helper-text/helper-text.metadata.d.ts +0 -2
- package/dist/components/ui/core/helper-text/helper-text.metadata.js +0 -9
- package/dist/components/ui/core/hover-card/hover-card.metadata.d.ts +0 -2
- package/dist/components/ui/core/hover-card/hover-card.metadata.js +0 -8
- package/dist/components/ui/core/inline-citation/inline-citation.metadata.d.ts +0 -2
- package/dist/components/ui/core/inline-citation/inline-citation.metadata.js +0 -8
- package/dist/components/ui/core/input/input.metadata.d.ts +0 -2
- package/dist/components/ui/core/input/input.metadata.js +0 -9
- package/dist/components/ui/core/input-group/input-group.metadata.d.ts +0 -2
- package/dist/components/ui/core/input-group/input-group.metadata.js +0 -9
- package/dist/components/ui/core/kbd/kbd.metadata.d.ts +0 -2
- package/dist/components/ui/core/kbd/kbd.metadata.js +0 -9
- package/dist/components/ui/core/label/label.metadata.d.ts +0 -2
- package/dist/components/ui/core/label/label.metadata.js +0 -9
- package/dist/components/ui/core/loader/loader.metadata.d.ts +0 -2
- package/dist/components/ui/core/loader/loader.metadata.js +0 -9
- package/dist/components/ui/core/message/message.metadata.d.ts +0 -2
- package/dist/components/ui/core/popover/popover.metadata.d.ts +0 -2
- package/dist/components/ui/core/popover/popover.metadata.js +0 -9
- package/dist/components/ui/core/progress/progress.metadata.d.ts +0 -2
- package/dist/components/ui/core/progress/progress.metadata.js +0 -9
- package/dist/components/ui/core/prompt-input/prompt-input.metadata.d.ts +0 -2
- package/dist/components/ui/core/prompt-input/prompt-input.metadata.js +0 -9
- package/dist/components/ui/core/radio-group/radio-group.metadata.d.ts +0 -2
- package/dist/components/ui/core/radio-group/radio-group.metadata.js +0 -9
- package/dist/components/ui/core/reasoning/reasoning.metadata.d.ts +0 -2
- package/dist/components/ui/core/reasoning/reasoning.metadata.js +0 -8
- package/dist/components/ui/core/scroll-area/scroll-area.metadata.d.ts +0 -2
- package/dist/components/ui/core/scroll-area/scroll-area.metadata.js +0 -9
- package/dist/components/ui/core/select/select.metadata.d.ts +0 -2
- package/dist/components/ui/core/select/select.metadata.js +0 -9
- package/dist/components/ui/core/separator/separator.metadata.d.ts +0 -2
- package/dist/components/ui/core/separator/separator.metadata.js +0 -8
- package/dist/components/ui/core/shimmer/shimmer.metadata.d.ts +0 -2
- package/dist/components/ui/core/shimmer/shimmer.metadata.js +0 -9
- package/dist/components/ui/core/skeleton/skeleton.metadata.d.ts +0 -2
- package/dist/components/ui/core/skeleton/skeleton.metadata.js +0 -9
- package/dist/components/ui/core/sonner-toast/sonner-toast.metadata.d.ts +0 -2
- package/dist/components/ui/core/sonner-toast/sonner-toast.metadata.js +0 -9
- package/dist/components/ui/core/sources/sources.metadata.d.ts +0 -2
- package/dist/components/ui/core/textarea/textarea.metadata.d.ts +0 -2
- package/dist/components/ui/core/textarea/textarea.metadata.js +0 -9
- package/dist/components/ui/core/tool/tool.metadata.d.ts +0 -2
- package/dist/components/ui/core/tool/tool.metadata.js +0 -8
- package/dist/components/ui/core/tooltip/tooltip.metadata.d.ts +0 -8
- package/dist/components/ui/core/tooltip/tooltip.metadata.js +0 -9
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useEffect as L } from "react";
|
|
3
|
+
import { cn as l } from "../../../../../../lib/utils.js";
|
|
4
|
+
import { SCROLL_ITEM_SELECTED_CLASSES as _, SCROLL_ITEM_UNSELECTED_CLASSES as C, SCROLL_ITEM_BASE_CLASSES as a, SCROLL_CONTAINER_CLASSES as d } from "../scroll-cell-classes.js";
|
|
5
|
+
const A = ["AM", "PM"], p = ({
|
|
6
|
+
value: e,
|
|
7
|
+
onChange: c,
|
|
8
|
+
className: S
|
|
9
|
+
}) => {
|
|
10
|
+
const r = s(null), n = s(null);
|
|
11
|
+
L(() => {
|
|
12
|
+
if (e !== null && n.current && r.current) {
|
|
13
|
+
const o = r.current, t = n.current;
|
|
14
|
+
o.scrollTo({
|
|
15
|
+
top: t.offsetTop - o.offsetHeight / 2 + t.offsetHeight / 2,
|
|
16
|
+
behavior: "smooth"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}, [e]);
|
|
20
|
+
const f = (o, t) => {
|
|
21
|
+
(o.key === "Enter" || o.key === " ") && (o.preventDefault(), c(t));
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ i(
|
|
24
|
+
"div",
|
|
25
|
+
{
|
|
26
|
+
"data-slot": "am-pm-scroll",
|
|
27
|
+
ref: r,
|
|
28
|
+
role: "listbox",
|
|
29
|
+
"aria-label": "AM/PM",
|
|
30
|
+
"aria-orientation": "vertical",
|
|
31
|
+
className: l(d, S),
|
|
32
|
+
children: A.map((o) => {
|
|
33
|
+
const t = e !== null && o === e;
|
|
34
|
+
return /* @__PURE__ */ i(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
ref: t ? n : void 0,
|
|
38
|
+
tabIndex: 0,
|
|
39
|
+
className: l(
|
|
40
|
+
a,
|
|
41
|
+
t ? _ : C
|
|
42
|
+
),
|
|
43
|
+
onClick: () => c(o),
|
|
44
|
+
onKeyDown: (E) => f(E, o),
|
|
45
|
+
role: "option",
|
|
46
|
+
"aria-selected": t,
|
|
47
|
+
children: o
|
|
48
|
+
},
|
|
49
|
+
o
|
|
50
|
+
);
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
p as AmPmScroll
|
|
57
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
export interface CalendarProps {
|
|
4
|
+
displayedMonth: Dayjs;
|
|
5
|
+
selectedRange: [Dayjs | null, Dayjs | null];
|
|
6
|
+
hoverDate: Dayjs | null;
|
|
7
|
+
displayWeekNumber?: boolean;
|
|
8
|
+
onDateClick: (date: Dayjs) => void;
|
|
9
|
+
onMonthChange: (month: Dayjs) => void;
|
|
10
|
+
onDateHover?: (date: Dayjs | null) => void;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const Calendar: FC<CalendarProps>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsxs as x, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import C from "react";
|
|
3
|
+
import { cn as b } from "../../../../../../lib/utils.js";
|
|
4
|
+
import { getCalendarDays as _, getWeekdayNames as E, getWeekNumbers as O, isDateInRange as v, isSameDay as f, isToday as T, isOutsideMonth as B } from "../../utils/calendar-utils.js";
|
|
5
|
+
import { CalendarHeader as K } from "../calendar-header/calendar-header.js";
|
|
6
|
+
import { DAYS_IN_WEEK as p } from "../constants.js";
|
|
7
|
+
function P({
|
|
8
|
+
isOutsideMonth: r,
|
|
9
|
+
isSelected: t,
|
|
10
|
+
isToday: s,
|
|
11
|
+
isRangeStart: o,
|
|
12
|
+
isRangeEnd: c,
|
|
13
|
+
isInRange: a,
|
|
14
|
+
isInHoverRange: i
|
|
15
|
+
}) {
|
|
16
|
+
return b(
|
|
17
|
+
"w-9 h-9 flex items-center justify-center text-sm font-medium cursor-pointer select-none relative transition-colors",
|
|
18
|
+
"focus-visible:ring-2 focus-visible:ring-border focus-visible:outline-none",
|
|
19
|
+
// border-radius for range endpoints
|
|
20
|
+
o && c && "rounded-lg",
|
|
21
|
+
o && !c && "rounded-l-lg",
|
|
22
|
+
c && !o && "rounded-r-lg",
|
|
23
|
+
// selected day
|
|
24
|
+
t && "bg-primary-background text-foreground-on-primary hover:bg-primary-background",
|
|
25
|
+
// unselected text
|
|
26
|
+
!t && r && "text-muted-foreground/50",
|
|
27
|
+
!t && !r && (a || i) ? "text-foreground" : !t && !r && "text-secondary-foreground",
|
|
28
|
+
// range highlight
|
|
29
|
+
!t && (a || i) && "bg-accent-background",
|
|
30
|
+
!t && "hover:bg-accent-background hover:rounded-lg hover:text-foreground",
|
|
31
|
+
// today outline
|
|
32
|
+
s && !t && "border border-border rounded-lg"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const W = ({
|
|
36
|
+
displayedMonth: r,
|
|
37
|
+
selectedRange: t,
|
|
38
|
+
hoverDate: s,
|
|
39
|
+
displayWeekNumber: o = !1,
|
|
40
|
+
onDateClick: c,
|
|
41
|
+
onMonthChange: a,
|
|
42
|
+
onDateHover: i,
|
|
43
|
+
className: N
|
|
44
|
+
}) => {
|
|
45
|
+
const [n, m] = t, h = _(r), M = E(), k = o ? O(h) : [], Y = () => {
|
|
46
|
+
a(r.subtract(1, "month"));
|
|
47
|
+
}, D = () => {
|
|
48
|
+
a(r.add(1, "month"));
|
|
49
|
+
}, w = (e) => {
|
|
50
|
+
const d = {
|
|
51
|
+
isOutsideMonth: B(e, r),
|
|
52
|
+
isToday: T(e),
|
|
53
|
+
isSelected: f(e, n) || f(e, m),
|
|
54
|
+
isRangeStart: f(e, n),
|
|
55
|
+
isRangeEnd: f(e, m),
|
|
56
|
+
isInRange: v(e, n, m),
|
|
57
|
+
isInHoverRange: !1
|
|
58
|
+
};
|
|
59
|
+
if (s && n && !m) {
|
|
60
|
+
const u = n.isBefore(s) ? n : s, g = n.isBefore(s) ? s : n;
|
|
61
|
+
d.isInHoverRange = v(e, u, g);
|
|
62
|
+
}
|
|
63
|
+
return d;
|
|
64
|
+
};
|
|
65
|
+
return /* @__PURE__ */ x("div", { "data-slot": "calendar", className: b("flex flex-col gap-4", N), children: [
|
|
66
|
+
/* @__PURE__ */ l(
|
|
67
|
+
K,
|
|
68
|
+
{
|
|
69
|
+
displayedMonth: r,
|
|
70
|
+
onPrevMonth: Y,
|
|
71
|
+
onNextMonth: D,
|
|
72
|
+
onMonthChange: a
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
/* @__PURE__ */ x(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
className: b(
|
|
79
|
+
"grid gap-0",
|
|
80
|
+
o ? "grid-cols-calendar-weeks" : "grid-cols-calendar"
|
|
81
|
+
),
|
|
82
|
+
children: [
|
|
83
|
+
o && /* @__PURE__ */ l("div", { className: "text-xs font-semibold text-muted-foreground text-center py-2 px-1", children: "#" }),
|
|
84
|
+
M.map((e) => /* @__PURE__ */ l(
|
|
85
|
+
"div",
|
|
86
|
+
{
|
|
87
|
+
className: "text-xs font-medium text-muted-foreground text-center py-2 px-1 tracking-tighter",
|
|
88
|
+
children: e
|
|
89
|
+
},
|
|
90
|
+
e
|
|
91
|
+
)),
|
|
92
|
+
h.map((e, d) => {
|
|
93
|
+
const u = w(e), g = Math.floor(d / p), I = o && d % p === 0, j = `day-${e.format("YYYY-MM-DD")}`;
|
|
94
|
+
return /* @__PURE__ */ x(C.Fragment, { children: [
|
|
95
|
+
I && /* @__PURE__ */ l("div", { className: "text-xs text-muted-foreground text-center flex items-center justify-center h-9", children: k[g] }),
|
|
96
|
+
/* @__PURE__ */ l(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
className: P(u),
|
|
100
|
+
onClick: () => c(e),
|
|
101
|
+
onMouseEnter: () => i?.(e),
|
|
102
|
+
onMouseLeave: () => i?.(null),
|
|
103
|
+
role: "gridcell",
|
|
104
|
+
tabIndex: 0,
|
|
105
|
+
"aria-label": e.format("DD MMMM YYYY"),
|
|
106
|
+
"aria-selected": u.isSelected,
|
|
107
|
+
children: e.date()
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
] }, j);
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
] });
|
|
116
|
+
};
|
|
117
|
+
export {
|
|
118
|
+
W as Calendar
|
|
119
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
export interface CalendarHeaderProps {
|
|
4
|
+
displayedMonth: Dayjs;
|
|
5
|
+
onPrevMonth: () => void;
|
|
6
|
+
onNextMonth: () => void;
|
|
7
|
+
onMonthChange: (month: Dayjs) => void;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const CalendarHeader: FC<CalendarHeaderProps>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsxs as t, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { IconChevronLeft as h, IconChevronRight as u, IconChevronDown as p } from "@tabler/icons-react";
|
|
3
|
+
import i from "dayjs";
|
|
4
|
+
import { cn as N } from "../../../../../../lib/utils.js";
|
|
5
|
+
import { Button as l } from "../../../button/button.js";
|
|
6
|
+
import { DropdownMenu as g, DropdownMenuTrigger as v, DropdownMenuContent as x, DropdownMenuItem as w } from "../../../dropdown-menu/dropdown-menu.js";
|
|
7
|
+
const M = Array.from(
|
|
8
|
+
{ length: 12 },
|
|
9
|
+
(r, a) => i().month(a).format("MMMM")
|
|
10
|
+
), c = i().year() - 50, b = i().year() + 10, z = Array.from(
|
|
11
|
+
{ length: b - c + 1 },
|
|
12
|
+
(r, a) => c + a
|
|
13
|
+
), d = ({
|
|
14
|
+
label: r,
|
|
15
|
+
items: a,
|
|
16
|
+
onSelect: s
|
|
17
|
+
}) => /* @__PURE__ */ t(g, { modal: !1, children: [
|
|
18
|
+
/* @__PURE__ */ e(
|
|
19
|
+
v,
|
|
20
|
+
{
|
|
21
|
+
render: /* @__PURE__ */ t(
|
|
22
|
+
l,
|
|
23
|
+
{
|
|
24
|
+
variant: "ghost",
|
|
25
|
+
size: "sm",
|
|
26
|
+
className: "h-7 px-2 gap-1 text-sm font-medium text-secondary-foreground",
|
|
27
|
+
children: [
|
|
28
|
+
r,
|
|
29
|
+
/* @__PURE__ */ e(p, { className: "size-4" })
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
/* @__PURE__ */ e(x, { className: "max-h-60 overflow-y-auto", children: a.map(({ value: n, label: m }) => /* @__PURE__ */ e(w, { onClick: () => s(n), children: m }, n)) })
|
|
36
|
+
] }), E = ({
|
|
37
|
+
displayedMonth: r,
|
|
38
|
+
onPrevMonth: a,
|
|
39
|
+
onNextMonth: s,
|
|
40
|
+
onMonthChange: n,
|
|
41
|
+
className: m
|
|
42
|
+
}) => /* @__PURE__ */ t(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
"data-slot": "calendar-header",
|
|
46
|
+
className: N("flex items-center justify-between pt-1 w-full", m),
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ e(
|
|
49
|
+
l,
|
|
50
|
+
{
|
|
51
|
+
variant: "ghost",
|
|
52
|
+
size: "icon-sm",
|
|
53
|
+
className: "size-7 rounded-md text-secondary-foreground",
|
|
54
|
+
onClick: a,
|
|
55
|
+
"aria-label": "Previous month",
|
|
56
|
+
children: /* @__PURE__ */ e(h, { className: "size-4" })
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
/* @__PURE__ */ t("div", { className: "flex items-center gap-0.5", children: [
|
|
60
|
+
/* @__PURE__ */ e(
|
|
61
|
+
d,
|
|
62
|
+
{
|
|
63
|
+
label: r.format("MMMM"),
|
|
64
|
+
items: M.map((o, f) => ({ value: f, label: o })),
|
|
65
|
+
onSelect: (o) => n(r.date(1).month(o))
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
/* @__PURE__ */ e(
|
|
69
|
+
d,
|
|
70
|
+
{
|
|
71
|
+
label: r.format("YYYY"),
|
|
72
|
+
items: z.map((o) => ({ value: o, label: String(o) })),
|
|
73
|
+
onSelect: (o) => n(r.date(1).year(o))
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ e(
|
|
78
|
+
l,
|
|
79
|
+
{
|
|
80
|
+
variant: "ghost",
|
|
81
|
+
size: "icon-sm",
|
|
82
|
+
className: "size-7 rounded-md text-secondary-foreground",
|
|
83
|
+
onClick: s,
|
|
84
|
+
"aria-label": "Next month",
|
|
85
|
+
children: /* @__PURE__ */ e(u, { className: "size-4" })
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
export {
|
|
92
|
+
E as CalendarHeader
|
|
93
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared numeric constants for date/time picker components.
|
|
3
|
+
* Colors and typography are applied via Tailwind utility classes — no CSS
|
|
4
|
+
* variable strings are exported from here.
|
|
5
|
+
*/
|
|
6
|
+
export declare const HOURS_IN_DAY = 24;
|
|
7
|
+
export declare const HOURS_IN_12H = 12;
|
|
8
|
+
export declare const MINUTES_IN_HOUR = 60;
|
|
9
|
+
export declare const MINUTE_INCREMENT = 1;
|
|
10
|
+
export declare const DAYS_IN_WEEK = 7;
|
|
11
|
+
export declare const DEFAULT_START_HOUR = 9;
|
|
12
|
+
export declare const DEFAULT_END_HOUR = 17;
|
|
13
|
+
export declare const DEFAULT_MINUTE = 0;
|
|
14
|
+
export declare const START_OF_DAY_HOUR = 0;
|
|
15
|
+
export declare const END_OF_DAY_HOUR = 23;
|
|
16
|
+
export declare const END_OF_DAY_MINUTE = 59;
|
|
17
|
+
export declare const DEFAULT_START_AMPM: 'AM' | 'PM';
|
|
18
|
+
export declare const DEFAULT_END_AMPM: 'AM' | 'PM';
|
|
19
|
+
export declare const NOON_HOUR = 12;
|
|
20
|
+
export declare const MIDNIGHT_HOUR = 0;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const _ = 24, N = 12, U = 60, o = 1, t = 7, E = 9, T = 0, c = 0, n = 23, s = 59, I = 0;
|
|
2
|
+
export {
|
|
3
|
+
t as DAYS_IN_WEEK,
|
|
4
|
+
T as DEFAULT_MINUTE,
|
|
5
|
+
E as DEFAULT_START_HOUR,
|
|
6
|
+
n as END_OF_DAY_HOUR,
|
|
7
|
+
s as END_OF_DAY_MINUTE,
|
|
8
|
+
N as HOURS_IN_12H,
|
|
9
|
+
_ as HOURS_IN_DAY,
|
|
10
|
+
I as MIDNIGHT_HOUR,
|
|
11
|
+
U as MINUTES_IN_HOUR,
|
|
12
|
+
o as MINUTE_INCREMENT,
|
|
13
|
+
c as START_OF_DAY_HOUR
|
|
14
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
export declare const DEFAULT_ARIA_LABEL = "Date picker";
|
|
4
|
+
export type DateTimeInputVariant = 'date' | 'time' | 'datetime';
|
|
5
|
+
export type RangePart = 'start' | 'end';
|
|
6
|
+
export interface DateTimeInputProps {
|
|
7
|
+
value: [Dayjs | null, Dayjs | null] | Dayjs | null;
|
|
8
|
+
format: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
ariaLabel?: string;
|
|
14
|
+
variant?: DateTimeInputVariant;
|
|
15
|
+
activeRangePart?: RangePart;
|
|
16
|
+
onRangePartClick?: (part: RangePart) => void;
|
|
17
|
+
popoverId?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const DateTimeInput: FC<DateTimeInputProps>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsxs as u, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { IconCalendarClock as A, IconClock as I, IconCalendar as y } from "@tabler/icons-react";
|
|
3
|
+
import { cn as a } from "../../../../../../lib/utils.js";
|
|
4
|
+
import { Input as D } from "../../../input/input.js";
|
|
5
|
+
import { RangeInputDisplay as R } from "./range-input-display.js";
|
|
6
|
+
const v = "Date picker", C = () => {
|
|
7
|
+
}, p = {
|
|
8
|
+
date: /* @__PURE__ */ r(y, { "aria-label": "date-icon", className: "size-4" }),
|
|
9
|
+
time: /* @__PURE__ */ r(I, { "aria-label": "time-icon", className: "size-4" }),
|
|
10
|
+
datetime: /* @__PURE__ */ r(A, { "aria-label": "datetime-icon", className: "size-4" })
|
|
11
|
+
}, g = (e, o) => a(
|
|
12
|
+
"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none",
|
|
13
|
+
"flex items-center justify-center",
|
|
14
|
+
"transition-colors duration-150",
|
|
15
|
+
o || e ? "text-foreground" : "text-muted-foreground",
|
|
16
|
+
"group-hover:text-foreground"
|
|
17
|
+
), _ = ({
|
|
18
|
+
value: e,
|
|
19
|
+
format: o,
|
|
20
|
+
placeholder: b,
|
|
21
|
+
onClick: n,
|
|
22
|
+
isOpen: t,
|
|
23
|
+
className: i,
|
|
24
|
+
ariaLabel: l = v,
|
|
25
|
+
variant: s = "date",
|
|
26
|
+
activeRangePart: f,
|
|
27
|
+
onRangePartClick: x,
|
|
28
|
+
popoverId: c
|
|
29
|
+
}) => {
|
|
30
|
+
if (Array.isArray(e)) {
|
|
31
|
+
const N = e[0] !== null || e[1] !== null;
|
|
32
|
+
return /* @__PURE__ */ u(
|
|
33
|
+
"div",
|
|
34
|
+
{
|
|
35
|
+
"data-slot": "date-time-input",
|
|
36
|
+
className: a(
|
|
37
|
+
"relative flex items-center cursor-pointer w-full group",
|
|
38
|
+
i
|
|
39
|
+
),
|
|
40
|
+
onClick: n,
|
|
41
|
+
role: "combobox",
|
|
42
|
+
"aria-label": l,
|
|
43
|
+
"aria-expanded": t,
|
|
44
|
+
"aria-controls": c,
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ r(
|
|
47
|
+
R,
|
|
48
|
+
{
|
|
49
|
+
startDate: e[0],
|
|
50
|
+
endDate: e[1],
|
|
51
|
+
format: o,
|
|
52
|
+
activeRangePart: f,
|
|
53
|
+
onRangePartClick: x,
|
|
54
|
+
isOpen: t
|
|
55
|
+
}
|
|
56
|
+
),
|
|
57
|
+
/* @__PURE__ */ r("div", { className: g(t, N), children: p[s] })
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const d = e?.format(o) ?? "", m = d.length > 0, h = b ?? o;
|
|
63
|
+
return /* @__PURE__ */ u(
|
|
64
|
+
"div",
|
|
65
|
+
{
|
|
66
|
+
"data-slot": "date-time-input",
|
|
67
|
+
className: a(
|
|
68
|
+
"relative flex items-center cursor-pointer w-full group",
|
|
69
|
+
i
|
|
70
|
+
),
|
|
71
|
+
onClick: n,
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ r(
|
|
74
|
+
D,
|
|
75
|
+
{
|
|
76
|
+
value: d,
|
|
77
|
+
placeholder: h,
|
|
78
|
+
onChange: C,
|
|
79
|
+
"aria-label": l,
|
|
80
|
+
"aria-expanded": t,
|
|
81
|
+
"aria-controls": c,
|
|
82
|
+
role: "combobox",
|
|
83
|
+
className: a(
|
|
84
|
+
"border-transparent bg-muted-background cursor-pointer caret-transparent pr-9",
|
|
85
|
+
m ? "text-foreground" : "text-muted-foreground",
|
|
86
|
+
"hover:border-border-emphasized",
|
|
87
|
+
t && "!bg-background !text-foreground !border-border"
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ r("div", { className: g(t, m), children: p[s] })
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
export {
|
|
97
|
+
v as DEFAULT_ARIA_LABEL,
|
|
98
|
+
_ as DateTimeInput
|
|
99
|
+
};
|
package/dist/components/ui/core/date-time-pickers/shared/date-time-input/range-input-display.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
import { RangePart } from './date-time-input';
|
|
4
|
+
export interface RangeInputDisplayProps {
|
|
5
|
+
startDate: Dayjs | null;
|
|
6
|
+
endDate: Dayjs | null;
|
|
7
|
+
format: string;
|
|
8
|
+
activeRangePart?: RangePart;
|
|
9
|
+
onRangePartClick?: (part: RangePart) => void;
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const RangeInputDisplay: FC<RangeInputDisplayProps>;
|
package/dist/components/ui/core/date-time-pickers/shared/date-time-input/range-input-display.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsxs as p, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { cn as n } from "../../../../../../lib/utils.js";
|
|
3
|
+
const a = "px-1 py-0.5 rounded-sm transition-colors duration-150", i = "text-muted-foreground group-hover:text-foreground transition-colors duration-150", x = ({
|
|
4
|
+
startDate: d,
|
|
5
|
+
endDate: t,
|
|
6
|
+
format: e,
|
|
7
|
+
activeRangePart: s,
|
|
8
|
+
onRangePartClick: r,
|
|
9
|
+
isOpen: l
|
|
10
|
+
}) => {
|
|
11
|
+
const u = d !== null || t !== null, c = (b) => (g) => {
|
|
12
|
+
r && (g.stopPropagation(), r(b));
|
|
13
|
+
};
|
|
14
|
+
return /* @__PURE__ */ p(
|
|
15
|
+
"div",
|
|
16
|
+
{
|
|
17
|
+
className: n(
|
|
18
|
+
"flex items-center w-full py-1 px-3 pr-9 border rounded-lg",
|
|
19
|
+
"text-sm leading-5 h-9 box-border whitespace-nowrap overflow-hidden",
|
|
20
|
+
"transition-[background,border-color,color,box-shadow] duration-150",
|
|
21
|
+
l ? "bg-background text-foreground border-border shadow-focus-ring" : [
|
|
22
|
+
"bg-muted-background border-transparent",
|
|
23
|
+
"hover:bg-accent-background hover:text-foreground hover:border-border-emphasized",
|
|
24
|
+
u ? "text-foreground" : "text-muted-foreground"
|
|
25
|
+
]
|
|
26
|
+
),
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ o(
|
|
29
|
+
"span",
|
|
30
|
+
{
|
|
31
|
+
className: n(
|
|
32
|
+
a,
|
|
33
|
+
r ? "cursor-pointer" : "cursor-default",
|
|
34
|
+
s === "start" ? "bg-active-muted-background" : r && "hover:bg-active-muted-background-hover"
|
|
35
|
+
),
|
|
36
|
+
onClick: c("start"),
|
|
37
|
+
children: d ? d.format(e) : /* @__PURE__ */ o("span", { className: i, children: e })
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
/* @__PURE__ */ o(
|
|
41
|
+
"span",
|
|
42
|
+
{
|
|
43
|
+
className: n(
|
|
44
|
+
"select-none transition-colors duration-150",
|
|
45
|
+
u ? "text-foreground" : "text-muted-foreground group-hover:text-foreground"
|
|
46
|
+
),
|
|
47
|
+
children: " – "
|
|
48
|
+
}
|
|
49
|
+
),
|
|
50
|
+
/* @__PURE__ */ o(
|
|
51
|
+
"span",
|
|
52
|
+
{
|
|
53
|
+
className: n(
|
|
54
|
+
a,
|
|
55
|
+
r ? "cursor-pointer" : "cursor-default",
|
|
56
|
+
s === "end" ? "bg-active-muted-background" : r && "hover:bg-active-muted-background-hover"
|
|
57
|
+
),
|
|
58
|
+
onClick: c("end"),
|
|
59
|
+
children: t ? t.format(e) : /* @__PURE__ */ o("span", { className: i, children: e })
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
x as RangeInputDisplay
|
|
68
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface UsePopoverStateOptions {
|
|
2
|
+
onClose?: () => void;
|
|
3
|
+
onBackspace?: () => void;
|
|
4
|
+
}
|
|
5
|
+
export interface UsePopoverStateReturn {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
8
|
+
popoverRef: React.RefObject<HTMLDivElement>;
|
|
9
|
+
inputRef: React.RefObject<HTMLDivElement>;
|
|
10
|
+
handleTogglePopover: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const usePopoverState: (options?: UsePopoverStateOptions) => UsePopoverStateReturn;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useState as I, useRef as f, useCallback as L, useEffect as T } from "react";
|
|
2
|
+
const g = (p = {}) => {
|
|
3
|
+
const { onClose: s, onBackspace: c } = p, [a, n] = I(!1), i = f(null), r = f(null), m = L(() => {
|
|
4
|
+
n((o) => !o);
|
|
5
|
+
}, []);
|
|
6
|
+
return T(() => {
|
|
7
|
+
if (!a) return;
|
|
8
|
+
const o = (t) => {
|
|
9
|
+
const e = t.target;
|
|
10
|
+
if (!(e instanceof Node)) return;
|
|
11
|
+
const l = i.current?.contains(e) ?? !1, k = r.current?.contains(e) ?? !1, v = t.composedPath().some(
|
|
12
|
+
(d) => d instanceof HTMLElement && d.hasAttribute("data-picker-overlay")
|
|
13
|
+
);
|
|
14
|
+
!l && !k && !v && (n(!1), s?.());
|
|
15
|
+
}, u = (t) => {
|
|
16
|
+
if (t.key === "Escape") {
|
|
17
|
+
n(!1), s?.();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (t.key === "Backspace" && c) {
|
|
21
|
+
const { target: e } = t;
|
|
22
|
+
e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLElement && e.isContentEditable || (t.preventDefault(), c());
|
|
23
|
+
}
|
|
24
|
+
}, E = setTimeout(() => {
|
|
25
|
+
document.addEventListener("mousedown", o);
|
|
26
|
+
}, 0);
|
|
27
|
+
return document.addEventListener("keydown", u), () => {
|
|
28
|
+
clearTimeout(E), document.removeEventListener("mousedown", o), document.removeEventListener("keydown", u);
|
|
29
|
+
};
|
|
30
|
+
}, [a, s, c]), {
|
|
31
|
+
isOpen: a,
|
|
32
|
+
setIsOpen: n,
|
|
33
|
+
popoverRef: i,
|
|
34
|
+
inputRef: r,
|
|
35
|
+
handleTogglePopover: m
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
g as usePopoverState
|
|
40
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { RangeSelectionStep } from './use-range-step-manager';
|
|
3
|
+
export interface DateStateSnapshot {
|
|
4
|
+
tempStart: Dayjs | null;
|
|
5
|
+
tempEnd: Dayjs | null;
|
|
6
|
+
}
|
|
7
|
+
export interface UseRangeDateStateOptions {
|
|
8
|
+
value: [Dayjs | null, Dayjs | null];
|
|
9
|
+
defaultDate: Dayjs;
|
|
10
|
+
/** Transforms a clicked date before storing; pass time-of-day defaults for datetime variants. */
|
|
11
|
+
mapDate?: (date: Dayjs, role: 'start' | 'end') => Dayjs;
|
|
12
|
+
/** Called when the end date is selected; used for auto-apply in date-only variants. */
|
|
13
|
+
onEndDateSelected?: (start: Dayjs | null, end: Dayjs) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface UseRangeDateStateReturn {
|
|
16
|
+
tempStart: Dayjs | null;
|
|
17
|
+
tempEnd: Dayjs | null;
|
|
18
|
+
displayedMonth: Dayjs;
|
|
19
|
+
hoverDate: Dayjs | null;
|
|
20
|
+
/** Synchronous ref — use inside callbacks to avoid stale closures. */
|
|
21
|
+
stateRef: React.MutableRefObject<DateStateSnapshot>;
|
|
22
|
+
handleDateClick: (date: Dayjs, step: RangeSelectionStep) => void;
|
|
23
|
+
handleDateHover: (date: Dayjs | null) => void;
|
|
24
|
+
handleMonthChange: (month: Dayjs) => void;
|
|
25
|
+
/** Returns the new [start, end] tuple, or null if the segment was already empty (signals caller to move focus to start). */
|
|
26
|
+
clearActiveSegment: (step: RangeSelectionStep) => [Dayjs | null, Dayjs | null] | null;
|
|
27
|
+
resetDates: (value: [Dayjs | null, Dayjs | null]) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare const useRangeDateState: ({ value, defaultDate, mapDate, onEndDateSelected, }: UseRangeDateStateOptions) => UseRangeDateStateReturn;
|