@cognite/aura 0.2.0 → 0.3.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/DESIGN.md +869 -870
- package/README.md +143 -9
- package/dist/colors.css +30 -0
- package/dist/components/index.d.ts +7 -36
- package/dist/components/index.js +319 -350
- 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/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 +32 -28
- package/dist/components/ui/core/code-block/code-block.d.ts +6 -9
- package/dist/components/ui/core/code-block/code-block.js +48 -44
- 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-picker/date-picker.d.ts +15 -0
- package/dist/components/ui/core/date-time-pickers/date-picker/date-picker.js +84 -0
- package/dist/components/ui/core/date-time-pickers/date-picker/index.d.ts +3 -0
- package/dist/components/ui/core/date-time-pickers/date-picker/types.d.ts +18 -0
- package/dist/components/ui/core/date-time-pickers/date-picker/use-date-picker.d.ts +3 -0
- package/dist/components/ui/core/date-time-pickers/date-picker/use-date-picker.js +63 -0
- 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 +8 -0
- package/dist/components/ui/core/date-time-pickers/index.js +8 -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-single-date-state.d.ts +23 -0
- package/dist/components/ui/core/date-time-pickers/shared/hooks/use-single-date-state.js +32 -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 +23 -22
- 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/input.js +1 -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 +387 -99
- 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 +337 -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 +180 -167
- package/dist/components/ui/core/radio-group/radio-group.d.ts +12 -8
- package/dist/components/ui/core/radio-group/radio-group.js +56 -53
- package/dist/components/ui/core/reasoning/reasoning.d.ts +5 -5
- 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 +4 -1
- package/dist/components/ui/core/select/select.d.ts +15 -14
- package/dist/components/ui/core/select/select.js +135 -108
- 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 +5 -5
- package/dist/components/ui/core/shimmer/shimmer.js +91 -52
- 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 +11 -9
- 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/toggle/toggle.d.ts +15 -0
- package/dist/components/ui/core/toggle/toggle.js +74 -0
- package/dist/components/ui/core/tool/tool.d.ts +7 -6
- package/dist/components/ui/core/tool/tool.js +47 -43
- 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/lib/portal-container-context.d.ts +2 -1
- package/dist/lib/portal-container-context.js +3 -5
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +7 -7
- package/dist/styles.css +1 -1
- package/dist/styles.source.css +12 -1
- package/package.json +217 -14
- 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
- package/dist/index.js +0 -342
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;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback as e, useState as u, useRef as b } from "react";
|
|
2
|
+
const A = ({
|
|
3
|
+
value: c,
|
|
4
|
+
defaultDate: p,
|
|
5
|
+
mapDate: a,
|
|
6
|
+
onEndDateSelected: S
|
|
7
|
+
}) => {
|
|
8
|
+
const o = e(
|
|
9
|
+
(t, m) => a ? a(t, m) : t,
|
|
10
|
+
[a]
|
|
11
|
+
), [E, f] = u(c[0]), [y, M] = u(c[1]), [g, i] = u(
|
|
12
|
+
() => c[0] ?? p
|
|
13
|
+
), [C, l] = u(null), n = b({
|
|
14
|
+
tempStart: c[0],
|
|
15
|
+
tempEnd: c[1]
|
|
16
|
+
}), s = e((t) => {
|
|
17
|
+
n.current.tempStart = t, f(t);
|
|
18
|
+
}, []), r = e((t) => {
|
|
19
|
+
n.current.tempEnd = t, M(t);
|
|
20
|
+
}, []), R = e(
|
|
21
|
+
(t, m) => {
|
|
22
|
+
if (m === "start") {
|
|
23
|
+
s(o(t, "start")), r(null), l(null);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const d = n.current.tempStart;
|
|
27
|
+
if (d && t.isBefore(d, "day")) {
|
|
28
|
+
s(o(t, "start")), r(null), l(null);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const h = o(t, "end");
|
|
32
|
+
r(h), l(null), S?.(n.current.tempStart, h);
|
|
33
|
+
},
|
|
34
|
+
[o, s, r, S]
|
|
35
|
+
), k = e((t) => {
|
|
36
|
+
l(t);
|
|
37
|
+
}, []), D = e((t) => {
|
|
38
|
+
i(t);
|
|
39
|
+
}, []), H = e(
|
|
40
|
+
(t) => t === "start" ? (s(null), [null, n.current.tempEnd]) : n.current.tempEnd === null ? null : (r(null), [n.current.tempStart, null]),
|
|
41
|
+
[s, r]
|
|
42
|
+
), T = e(
|
|
43
|
+
(t) => {
|
|
44
|
+
s(t[0]), r(t[1]), l(null), i(t[0] ?? p);
|
|
45
|
+
},
|
|
46
|
+
[s, r, p]
|
|
47
|
+
);
|
|
48
|
+
return {
|
|
49
|
+
tempStart: E,
|
|
50
|
+
tempEnd: y,
|
|
51
|
+
displayedMonth: g,
|
|
52
|
+
hoverDate: C,
|
|
53
|
+
stateRef: n,
|
|
54
|
+
handleDateClick: R,
|
|
55
|
+
handleDateHover: k,
|
|
56
|
+
handleMonthChange: D,
|
|
57
|
+
clearActiveSegment: H,
|
|
58
|
+
resetDates: T
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
A as useRangeDateState
|
|
63
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type RangeSelectionStep = 'start' | 'end';
|
|
2
|
+
export interface UseRangeStepManagerReturn {
|
|
3
|
+
step: RangeSelectionStep;
|
|
4
|
+
handleNext: () => void;
|
|
5
|
+
handleBack: () => void;
|
|
6
|
+
resetStep: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const useRangeStepManager: () => UseRangeStepManagerReturn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState as o, useCallback as e } from "react";
|
|
2
|
+
const p = () => {
|
|
3
|
+
const [s, t] = o("start"), a = e(() => {
|
|
4
|
+
t("end");
|
|
5
|
+
}, []), n = e(() => {
|
|
6
|
+
t("start");
|
|
7
|
+
}, []), r = e(() => {
|
|
8
|
+
t("start");
|
|
9
|
+
}, []);
|
|
10
|
+
return {
|
|
11
|
+
step: s,
|
|
12
|
+
handleNext: a,
|
|
13
|
+
handleBack: n,
|
|
14
|
+
resetStep: r
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
p as useRangeStepManager
|
|
19
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
export interface UseSingleDateStateOptions {
|
|
3
|
+
value: Dayjs | null;
|
|
4
|
+
defaultDate: Dayjs;
|
|
5
|
+
/** Transforms a clicked date before storing; pass time-of-day defaults for datetime variants. */
|
|
6
|
+
mapDate?: (date: Dayjs) => Dayjs;
|
|
7
|
+
/** Called when a date is selected; used for auto-apply in date-only variants. */
|
|
8
|
+
onDateSelected?: (date: Dayjs) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface UseSingleDateStateReturn {
|
|
11
|
+
tempDate: Dayjs | null;
|
|
12
|
+
displayedMonth: Dayjs;
|
|
13
|
+
/** Synchronous ref — use inside callbacks to avoid stale closures. */
|
|
14
|
+
stateRef: React.MutableRefObject<{
|
|
15
|
+
tempDate: Dayjs | null;
|
|
16
|
+
}>;
|
|
17
|
+
handleDateClick: (date: Dayjs) => void;
|
|
18
|
+
handleMonthChange: (month: Dayjs) => void;
|
|
19
|
+
/** Returns true when a date was cleared, false when already empty. */
|
|
20
|
+
clearDate: () => boolean;
|
|
21
|
+
resetDate: (value: Dayjs | null) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare const useSingleDateState: ({ value, defaultDate, mapDate, onDateSelected, }: UseSingleDateStateOptions) => UseSingleDateStateReturn;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState as l, useRef as i } from "react";
|
|
2
|
+
const g = ({
|
|
3
|
+
value: e,
|
|
4
|
+
defaultDate: a,
|
|
5
|
+
mapDate: r,
|
|
6
|
+
onDateSelected: D
|
|
7
|
+
}) => {
|
|
8
|
+
const [p, h] = l(e), [u, o] = l(
|
|
9
|
+
() => e ?? a
|
|
10
|
+
), n = i({ tempDate: e }), s = (t) => {
|
|
11
|
+
n.current.tempDate = t, h(t);
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
tempDate: p,
|
|
15
|
+
displayedMonth: u,
|
|
16
|
+
stateRef: n,
|
|
17
|
+
handleDateClick: (t) => {
|
|
18
|
+
const c = r ? r(t) : t;
|
|
19
|
+
s(c), D?.(c);
|
|
20
|
+
},
|
|
21
|
+
handleMonthChange: (t) => {
|
|
22
|
+
o(t);
|
|
23
|
+
},
|
|
24
|
+
clearDate: () => n.current.tempDate === null ? !1 : (s(null), !0),
|
|
25
|
+
resetDate: (t) => {
|
|
26
|
+
s(t), o(t ?? a);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
g as useSingleDateState
|
|
32
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TimeFormat } from '../../utils/format-utils';
|
|
2
|
+
export interface UseTimeStateOptions {
|
|
3
|
+
initialHour?: number;
|
|
4
|
+
initialMinute?: number;
|
|
5
|
+
timeFormat?: TimeFormat;
|
|
6
|
+
}
|
|
7
|
+
export interface UseTimeStateReturn {
|
|
8
|
+
hour: number;
|
|
9
|
+
minute: number;
|
|
10
|
+
amPm: 'AM' | 'PM';
|
|
11
|
+
hour24: number;
|
|
12
|
+
handleHourChange: (hour: number) => void;
|
|
13
|
+
handleMinuteChange: (minute: number) => void;
|
|
14
|
+
handleAmPmChange: (amPm: 'AM' | 'PM') => void;
|
|
15
|
+
resetTime: (hour: number, minute: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const useTimeState: ({ initialHour, initialMinute, timeFormat, }?: UseTimeStateOptions) => UseTimeStateReturn;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState as r, useMemo as C, useCallback as M } from "react";
|
|
2
|
+
import { getAmPmFromHour as m, convert12HourTo24Hour as P, convert24HourTo12Hour as T } from "../../utils/time-utils.js";
|
|
3
|
+
import { DEFAULT_START_HOUR as U, DEFAULT_MINUTE as f } from "../constants.js";
|
|
4
|
+
const S = ({
|
|
5
|
+
initialHour: s = U,
|
|
6
|
+
initialMinute: a = f,
|
|
7
|
+
timeFormat: o = "24h"
|
|
8
|
+
} = {}) => {
|
|
9
|
+
const l = o === "12h" ? T(s) : s, [e, u] = r(l), [p, h] = r(a), [t, c] = r(
|
|
10
|
+
() => m(s)
|
|
11
|
+
), A = C(
|
|
12
|
+
() => o === "12h" ? P(e, t) : e,
|
|
13
|
+
[e, t, o]
|
|
14
|
+
), H = M(
|
|
15
|
+
(n, d) => {
|
|
16
|
+
const g = o === "12h" ? T(n) : n;
|
|
17
|
+
u(g), h(d), c(m(n));
|
|
18
|
+
},
|
|
19
|
+
[o]
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
hour: e,
|
|
23
|
+
minute: p,
|
|
24
|
+
amPm: t,
|
|
25
|
+
hour24: A,
|
|
26
|
+
handleHourChange: u,
|
|
27
|
+
handleMinuteChange: h,
|
|
28
|
+
handleAmPmChange: c,
|
|
29
|
+
resetTime: H
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
S as useTimeState
|
|
34
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Tailwind class strings for TimePickerScroll and AmPmScroll.
|
|
3
|
+
* Both components render the same scroll container and cell styles.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SCROLL_CONTAINER_CLASSES = "overflow-y-auto flex flex-col items-center py-2 w-9 h-72 shrink-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden";
|
|
6
|
+
export declare const SCROLL_ITEM_BASE_CLASSES = "w-9 h-9 flex items-center justify-center rounded-lg cursor-pointer text-sm font-medium leading-[18px] tracking-normal select-none transition-colors duration-150 shrink-0";
|
|
7
|
+
export declare const SCROLL_ITEM_SELECTED_CLASSES = "bg-primary-background text-foreground-on-primary hover:bg-primary-background";
|
|
8
|
+
export declare const SCROLL_ITEM_UNSELECTED_CLASSES = "text-secondary-foreground hover:bg-accent-background";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const r = "overflow-y-auto flex flex-col items-center py-2 w-9 h-72 shrink-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden", o = "w-9 h-9 flex items-center justify-center rounded-lg cursor-pointer text-sm font-medium leading-[18px] tracking-normal select-none transition-colors duration-150 shrink-0", e = "bg-primary-background text-foreground-on-primary hover:bg-primary-background", n = "text-secondary-foreground hover:bg-accent-background";
|
|
2
|
+
export {
|
|
3
|
+
r as SCROLL_CONTAINER_CLASSES,
|
|
4
|
+
o as SCROLL_ITEM_BASE_CLASSES,
|
|
5
|
+
e as SCROLL_ITEM_SELECTED_CLASSES,
|
|
6
|
+
n as SCROLL_ITEM_UNSELECTED_CLASSES
|
|
7
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Dayjs } from 'dayjs';
|
|
3
|
+
export interface ShortcutItem {
|
|
4
|
+
id?: string;
|
|
5
|
+
label: string;
|
|
6
|
+
getValue: () => [Dayjs, Dayjs] | Dayjs | [Dayjs | null, Dayjs | null];
|
|
7
|
+
}
|
|
8
|
+
export interface ShortcutsPanelProps {
|
|
9
|
+
shortcuts?: ShortcutItem[];
|
|
10
|
+
onShortcutClick: (value: [Dayjs, Dayjs] | Dayjs | [Dayjs | null, Dayjs | null]) => void;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const ShortcutsPanel: FC<ShortcutsPanelProps>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { cn as t } from "../../../../../../lib/utils.js";
|
|
3
|
+
import { Button as n } from "../../../button/button.js";
|
|
4
|
+
const i = [], m = ({
|
|
5
|
+
shortcuts: r = i,
|
|
6
|
+
onShortcutClick: a,
|
|
7
|
+
className: o
|
|
8
|
+
}) => r.length === 0 ? null : /* @__PURE__ */ l(
|
|
9
|
+
"div",
|
|
10
|
+
{
|
|
11
|
+
"data-slot": "shortcuts-panel",
|
|
12
|
+
className: t(
|
|
13
|
+
"flex flex-col gap-1 p-3 border-r border-border min-w-[150px]",
|
|
14
|
+
o
|
|
15
|
+
),
|
|
16
|
+
children: r.map((e) => /* @__PURE__ */ l(
|
|
17
|
+
n,
|
|
18
|
+
{
|
|
19
|
+
variant: "ghost",
|
|
20
|
+
size: "default",
|
|
21
|
+
className: "w-full justify-start text-secondary-foreground",
|
|
22
|
+
onClick: () => a(e.getValue()),
|
|
23
|
+
children: e.label
|
|
24
|
+
},
|
|
25
|
+
e.id ?? e.label
|
|
26
|
+
))
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
export {
|
|
30
|
+
m as ShortcutsPanel
|
|
31
|
+
};
|
package/dist/components/ui/core/date-time-pickers/shared/time-picker-scroll/time-picker-scroll.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { TimeFormat } from '../../utils/format-utils';
|
|
3
|
+
export type TimePickerScrollProps = {
|
|
4
|
+
value: number | null;
|
|
5
|
+
onChange: (value: number) => void;
|
|
6
|
+
type: 'hour' | 'minute';
|
|
7
|
+
timeFormat?: TimeFormat;
|
|
8
|
+
className?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const TimePickerScroll: FC<TimePickerScrollProps>;
|
package/dist/components/ui/core/date-time-pickers/shared/time-picker-scroll/time-picker-scroll.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as f, useEffect as p } from "react";
|
|
3
|
+
import { cn as E } from "../../../../../../lib/utils.js";
|
|
4
|
+
import { generateHours as C, generateMinutes as d } from "../../utils/time-utils.js";
|
|
5
|
+
import { MIDNIGHT_HOUR as h, HOURS_IN_12H as s } from "../constants.js";
|
|
6
|
+
import { SCROLL_ITEM_SELECTED_CLASSES as u, SCROLL_ITEM_UNSELECTED_CLASSES as R, SCROLL_ITEM_BASE_CLASSES as T, SCROLL_CONTAINER_CLASSES as a } from "../scroll-cell-classes.js";
|
|
7
|
+
const M = ({
|
|
8
|
+
value: r,
|
|
9
|
+
onChange: m,
|
|
10
|
+
type: c,
|
|
11
|
+
timeFormat: i = "24h",
|
|
12
|
+
className: L
|
|
13
|
+
}) => {
|
|
14
|
+
const e = f(null), n = f(null), _ = c === "hour" ? C(i) : d(), S = r === null ? null : c === "hour" && i === "12h" ? r === h ? s : r > s ? r - s : r : r;
|
|
15
|
+
return p(() => {
|
|
16
|
+
if (r !== null && n.current && e.current) {
|
|
17
|
+
const o = e.current, t = n.current;
|
|
18
|
+
o.scrollTo({
|
|
19
|
+
top: t.offsetTop - o.offsetHeight / 2 + t.offsetHeight / 2,
|
|
20
|
+
behavior: "smooth"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}, [r]), /* @__PURE__ */ l(
|
|
24
|
+
"div",
|
|
25
|
+
{
|
|
26
|
+
"data-slot": "time-picker-scroll",
|
|
27
|
+
ref: e,
|
|
28
|
+
className: E(a, L),
|
|
29
|
+
children: _.map((o) => {
|
|
30
|
+
const t = S !== null && o === S;
|
|
31
|
+
return /* @__PURE__ */ l(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
ref: t ? n : void 0,
|
|
35
|
+
className: E(
|
|
36
|
+
T,
|
|
37
|
+
t ? u : R
|
|
38
|
+
),
|
|
39
|
+
onClick: () => m(o),
|
|
40
|
+
role: "option",
|
|
41
|
+
"aria-selected": t,
|
|
42
|
+
children: o.toString().padStart(2, "0")
|
|
43
|
+
},
|
|
44
|
+
o
|
|
45
|
+
);
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
M as TimePickerScroll
|
|
52
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
/**
|
|
3
|
+
* Get all days to display in a calendar month grid (including padding days from prev/next months)
|
|
4
|
+
* @param month - The month to display
|
|
5
|
+
* @param locale - Optional locale for week start day (e.g., 'en', 'nb', 'de')
|
|
6
|
+
*/
|
|
7
|
+
export declare function getCalendarDays(month: Dayjs, locale?: string): Dayjs[];
|
|
8
|
+
/**
|
|
9
|
+
* Check if a date is within a given range (inclusive)
|
|
10
|
+
* Uses dayjs isBetween plugin with '[]' for inclusive start and end
|
|
11
|
+
* @see https://day.js.org/docs/en/plugin/is-between
|
|
12
|
+
*/
|
|
13
|
+
export declare function isDateInRange(date: Dayjs, startDate: Dayjs | null, endDate: Dayjs | null): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a date is outside the current display month
|
|
16
|
+
*/
|
|
17
|
+
export declare function isOutsideMonth(date: Dayjs, displayMonth: Dayjs): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a date is today
|
|
20
|
+
* Note: Uses local timezone. Both the input date and current time are compared
|
|
21
|
+
* using the user's local timezone, which is the expected behavior for calendar UIs.
|
|
22
|
+
* @param date - The date to check
|
|
23
|
+
* @param now - Optional current date for testing (defaults to dayjs())
|
|
24
|
+
*/
|
|
25
|
+
export declare function isToday(date: Dayjs, now?: Dayjs): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Get an array of weekday names (short form)
|
|
28
|
+
* @param locale - Optional locale for localized weekday names (e.g., 'en', 'nb', 'de')
|
|
29
|
+
* @param baseDate - Optional base date for testing (defaults to dayjs())
|
|
30
|
+
*/
|
|
31
|
+
export declare function getWeekdayNames(locale?: string, baseDate?: Dayjs): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Get the week number for a given date
|
|
34
|
+
*/
|
|
35
|
+
export declare function getWeekNumber(date: Dayjs): number;
|
|
36
|
+
/**
|
|
37
|
+
* Get all week numbers for days in a calendar month grid
|
|
38
|
+
*/
|
|
39
|
+
export declare function getWeekNumbers(days: Dayjs[]): number[];
|
|
40
|
+
/**
|
|
41
|
+
* Check if two dates are the same day
|
|
42
|
+
*/
|
|
43
|
+
export declare function isSameDay(date1: Dayjs | null, date2: Dayjs | null): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Format a date range for display
|
|
46
|
+
* When one date is missing, shows the format placeholder for the missing date
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatDateRange(startDate: Dayjs | null, endDate: Dayjs | null, format: string): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import r from "dayjs";
|
|
2
|
+
import c from "dayjs/plugin/isBetween.js";
|
|
3
|
+
import d from "dayjs/plugin/isSameOrBefore.js";
|
|
4
|
+
import m from "dayjs/plugin/weekOfYear.js";
|
|
5
|
+
import { DAYS_IN_WEEK as u } from "../shared/constants.js";
|
|
6
|
+
r.extend(c);
|
|
7
|
+
r.extend(d);
|
|
8
|
+
r.extend(m);
|
|
9
|
+
function p(e, t) {
|
|
10
|
+
const n = e, a = n.startOf("month").startOf("week"), i = n.endOf("month").endOf("week"), f = [];
|
|
11
|
+
let s = a;
|
|
12
|
+
for (; s.isSameOrBefore(i, "day"); )
|
|
13
|
+
f.push(s), s = s.add(1, "day");
|
|
14
|
+
return f;
|
|
15
|
+
}
|
|
16
|
+
function g(e, t, n) {
|
|
17
|
+
return !t || !n || !e.isValid() || !t.isValid() || !n.isValid() || t.isAfter(n, "day") ? !1 : e.isBetween(t, n, "day", "[]");
|
|
18
|
+
}
|
|
19
|
+
function b(e, t) {
|
|
20
|
+
return e.month() !== t.month();
|
|
21
|
+
}
|
|
22
|
+
function M(e, t) {
|
|
23
|
+
return e.isSame(r(), "day");
|
|
24
|
+
}
|
|
25
|
+
function S(e, t) {
|
|
26
|
+
const a = r().startOf("week");
|
|
27
|
+
return Array.from({ length: u }, (l, i) => a.add(i, "day").format("dd"));
|
|
28
|
+
}
|
|
29
|
+
function y(e) {
|
|
30
|
+
return e.week();
|
|
31
|
+
}
|
|
32
|
+
function W(e) {
|
|
33
|
+
const t = [];
|
|
34
|
+
for (let n = 0; n < e.length; n += u) {
|
|
35
|
+
const o = e[n];
|
|
36
|
+
o && t.push(y(o));
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
40
|
+
function N(e, t) {
|
|
41
|
+
return !e || !t ? !1 : e.isSame(t, "day");
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
p as getCalendarDays,
|
|
45
|
+
y as getWeekNumber,
|
|
46
|
+
W as getWeekNumbers,
|
|
47
|
+
S as getWeekdayNames,
|
|
48
|
+
g as isDateInRange,
|
|
49
|
+
b as isOutsideMonth,
|
|
50
|
+
N as isSameDay,
|
|
51
|
+
M as isToday
|
|
52
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
/**
|
|
3
|
+
* Applies start of day (00:00:00.000) to a given date
|
|
4
|
+
* @param date - Dayjs object
|
|
5
|
+
* @returns Dayjs object with time set to 00:00:00.000
|
|
6
|
+
*/
|
|
7
|
+
export declare const applyStartOfDay: (date: Dayjs) => Dayjs;
|
|
8
|
+
/**
|
|
9
|
+
* Applies end of day (23:59:59.999) to a given date
|
|
10
|
+
* @param date - Dayjs object
|
|
11
|
+
* @returns Dayjs object with time set to 23:59:59.999
|
|
12
|
+
*/
|
|
13
|
+
export declare const applyEndOfDay: (date: Dayjs) => Dayjs;
|
|
14
|
+
/**
|
|
15
|
+
* Validates that a date range is valid (start is before or equal to end)
|
|
16
|
+
* @param start - Start date (Dayjs or null)
|
|
17
|
+
* @param end - End date (Dayjs or null)
|
|
18
|
+
* @returns True if the range is valid, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
export declare const validateDateRange: (start: Dayjs | null, end: Dayjs | null) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a timestamp (milliseconds) to a Dayjs object
|
|
23
|
+
* @param timestamp - Timestamp in milliseconds
|
|
24
|
+
* @returns Dayjs object or null if timestamp is null or undefined
|
|
25
|
+
*/
|
|
26
|
+
export declare const timestampToDayjs: (timestamp: number | undefined | null) => Dayjs | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
export type TimeFormat = '12h' | '24h';
|
|
3
|
+
/**
|
|
4
|
+
* Formats a date for display
|
|
5
|
+
* @param date - Dayjs date object
|
|
6
|
+
* @param format - Date format string (e.g., 'DD/MM/YYYY')
|
|
7
|
+
* @returns Formatted date string
|
|
8
|
+
*/
|
|
9
|
+
export declare const formatDateDisplay: (date: Dayjs, format: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Formats time for display using dayjs formatting
|
|
12
|
+
* @param time - Time object with hour and minute
|
|
13
|
+
* @param timeFormat - '12h' or '24h' format
|
|
14
|
+
* @returns Formatted time string (e.g., "9:05 AM" or "09:05")
|
|
15
|
+
*/
|
|
16
|
+
export declare const formatTimeDisplay: (time: {
|
|
17
|
+
hour: number;
|
|
18
|
+
minute: number;
|
|
19
|
+
}, timeFormat?: TimeFormat) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Formats a date range for display
|
|
22
|
+
* @param start - Start date
|
|
23
|
+
* @param end - End date
|
|
24
|
+
* @param format - Date format string
|
|
25
|
+
* @returns Formatted date range string (e.g., "10/05/2024 – 20/05/2024")
|
|
26
|
+
*/
|
|
27
|
+
export declare const formatRangeDisplay: (start: Dayjs | null, end: Dayjs | null, format: string) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Formats a date-time range for display
|
|
30
|
+
* @param start - Start date
|
|
31
|
+
* @param end - End date
|
|
32
|
+
* @param dateFormat - Date format string
|
|
33
|
+
* @param includeTime - Whether to include time in the format
|
|
34
|
+
* @param timeFormat - '12h' or '24h' format
|
|
35
|
+
* @returns Formatted date-time range string
|
|
36
|
+
*/
|
|
37
|
+
export declare const formatDateTimeRangeDisplay: (start: Dayjs | null, end: Dayjs | null, dateFormat: string, includeTime?: boolean, timeFormat?: TimeFormat) => string;
|