@cognite/aura 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/DESIGN.md +2243 -729
  2. package/README.md +133 -11
  3. package/dist/components/index.d.ts +3 -2
  4. package/dist/components/index.js +183 -176
  5. package/dist/components/ui/core/action-toolbar/action-toolbar.js +4 -4
  6. package/dist/components/ui/core/alert/alert.js +3 -3
  7. package/dist/components/ui/core/banner/banner.js +6 -6
  8. package/dist/components/ui/core/button/button.js +4 -4
  9. package/dist/components/ui/core/checkbox/checkbox.js +8 -8
  10. package/dist/components/ui/core/code-block/code-block.js +6 -6
  11. package/dist/components/ui/core/date-time-pickers/date-picker/date-picker.d.ts +15 -0
  12. package/dist/components/ui/core/date-time-pickers/date-picker/date-picker.js +73 -0
  13. package/dist/components/ui/core/date-time-pickers/date-picker/index.d.ts +3 -0
  14. package/dist/components/ui/core/date-time-pickers/date-picker/types.d.ts +17 -0
  15. package/dist/components/ui/core/date-time-pickers/date-picker/use-date-picker.d.ts +3 -0
  16. package/dist/components/ui/core/date-time-pickers/date-picker/use-date-picker.js +52 -0
  17. package/dist/components/ui/core/date-time-pickers/date-range-picker/date-range-picker.js +64 -75
  18. package/dist/components/ui/core/date-time-pickers/date-range-picker/types.d.ts +1 -2
  19. package/dist/components/ui/core/date-time-pickers/date-range-picker/use-date-range-picker.js +51 -64
  20. package/dist/components/ui/core/date-time-pickers/date-time-range-picker/date-time-range-picker.js +146 -161
  21. package/dist/components/ui/core/date-time-pickers/date-time-range-picker/types.d.ts +1 -2
  22. package/dist/components/ui/core/date-time-pickers/date-time-range-picker/use-date-time-range-picker.js +124 -137
  23. package/dist/components/ui/core/date-time-pickers/index.d.ts +4 -0
  24. package/dist/components/ui/core/date-time-pickers/index.js +10 -0
  25. package/dist/components/ui/core/date-time-pickers/shared/calendar/calendar.js +8 -8
  26. package/dist/components/ui/core/date-time-pickers/shared/date-time-input/date-time-input.d.ts +1 -1
  27. package/dist/components/ui/core/date-time-pickers/shared/date-time-input/date-time-input.js +1 -1
  28. package/dist/components/ui/core/date-time-pickers/shared/hooks/use-popover-state.d.ts +0 -2
  29. package/dist/components/ui/core/date-time-pickers/shared/hooks/use-popover-state.js +18 -34
  30. package/dist/components/ui/core/date-time-pickers/shared/hooks/use-single-date-state.d.ts +23 -0
  31. package/dist/components/ui/core/date-time-pickers/shared/hooks/use-single-date-state.js +32 -0
  32. package/dist/components/ui/core/date-time-pickers/shared/time-picker-panel/index.d.ts +2 -0
  33. package/dist/components/ui/core/date-time-pickers/shared/time-picker-panel/time-picker-panel.d.ts +19 -0
  34. package/dist/components/ui/core/date-time-pickers/shared/time-picker-panel/time-picker-panel.js +41 -0
  35. package/dist/components/ui/core/date-time-pickers/time-picker/index.d.ts +3 -0
  36. package/dist/components/ui/core/date-time-pickers/time-picker/time-picker.d.ts +16 -0
  37. package/dist/components/ui/core/date-time-pickers/time-picker/time-picker.js +100 -0
  38. package/dist/components/ui/core/date-time-pickers/time-picker/types.d.ts +23 -0
  39. package/dist/components/ui/core/date-time-pickers/time-picker/use-time-picker.d.ts +3 -0
  40. package/dist/components/ui/core/date-time-pickers/time-picker/use-time-picker.js +64 -0
  41. package/dist/components/ui/core/date-time-pickers/utils/calendar-utils.js +3 -3
  42. package/dist/components/ui/core/date-time-pickers/utils/time-utils.js +1 -1
  43. package/dist/components/ui/core/dropdown-menu/dropdown-menu.d.ts +17 -15
  44. package/dist/components/ui/core/dropdown-menu/dropdown-menu.js +83 -85
  45. package/dist/components/ui/core/hover-card/hover-card.js +3 -3
  46. package/dist/components/ui/core/input/input.js +1 -1
  47. package/dist/components/ui/core/message/message.js +387 -101
  48. package/dist/components/ui/core/pagination/pagination.js +9 -7
  49. package/dist/components/ui/core/prompt-input/prompt-input.js +16 -16
  50. package/dist/components/ui/core/radio-group/radio-group.js +7 -7
  51. package/dist/components/ui/core/reasoning/reasoning.js +1 -1
  52. package/dist/components/ui/core/segmented-control/segmented-control.js +3 -3
  53. package/dist/components/ui/core/select/select.d.ts +2 -1
  54. package/dist/components/ui/core/select/select.js +134 -110
  55. package/dist/components/ui/core/shimmer/shimmer.d.ts +3 -1
  56. package/dist/components/ui/core/shimmer/shimmer.js +89 -49
  57. package/dist/components/ui/core/tabs/tabs.js +3 -3
  58. package/dist/components/ui/core/textarea/textarea.js +1 -1
  59. package/dist/components/ui/core/toggle/toggle.d.ts +15 -0
  60. package/dist/components/ui/core/toggle/toggle.js +74 -0
  61. package/dist/components/ui/core/tool/tool.js +3 -3
  62. package/dist/index.d.ts +1 -1
  63. package/dist/lib/portal-container-context.js +3 -3
  64. package/dist/lib/use-controllable-state.js +17 -17
  65. package/dist/lib/utils.d.ts +1 -1
  66. package/dist/lib/utils.js +7 -7
  67. package/dist/styles.css +1 -1
  68. package/dist/styles.source.css +3 -0
  69. package/package.json +200 -18
  70. package/dist/index.js +0 -308
@@ -3,7 +3,7 @@ import { forwardRef as r } from "react";
3
3
  import { Checkbox as i } from "@base-ui/react/checkbox";
4
4
  import { IconCheck as l, IconMinus as b } from "@tabler/icons-react";
5
5
  import { cva as m } from "class-variance-authority";
6
- import { cn as d, invalidState as h, focusState as k, selectionItemDescription as u, selectionItemLabel as x, selectionItemBase as p, selectionItemCard as g, selectionItemDefault as f } from "../../../../lib/utils.js";
6
+ import { cn as d, selectionItemBase as h, selectionItemCard as k, selectionItemDefault as u, invalidState as x, focusState as p, selectionItemLabel as g, selectionItemDescription as f } from "../../../../lib/utils.js";
7
7
  const I = r(
8
8
  ({ className: a, orientation: e = "vertical", role: t = "group", ...c }, n) => /* @__PURE__ */ o(
9
9
  "div",
@@ -21,11 +21,11 @@ const I = r(
21
21
  )
22
22
  );
23
23
  I.displayName = "CheckboxGroup";
24
- const C = m(d("group/checkbox-item", p), {
24
+ const C = m(d("group/checkbox-item", h), {
25
25
  variants: {
26
26
  variant: {
27
- default: f,
28
- card: g
27
+ default: u,
28
+ card: k
29
29
  }
30
30
  },
31
31
  defaultVariants: {
@@ -55,8 +55,8 @@ const N = r(({ className: a, ...e }, t) => /* @__PURE__ */ o(
55
55
  "data-unchecked:not-data-disabled:hover:border-secondary-foreground group-hover/checkbox-item:data-unchecked:not-data-disabled:border-secondary-foreground",
56
56
  "data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:border-transparent data-disabled:bg-disabled-background data-disabled:text-disabled-foreground data-disabled:data-unchecked:border-border",
57
57
  "[&[data-checked]_[data-slot=checkbox-check]]:block [&[data-indeterminate]_[data-slot=checkbox-dash]]:block",
58
- k,
59
- h,
58
+ p,
59
+ x,
60
60
  a
61
61
  ),
62
62
  ...e,
@@ -97,7 +97,7 @@ const y = r(
97
97
  ref: t,
98
98
  "data-slot": "checkbox-item-label",
99
99
  className: d(
100
- x,
100
+ g,
101
101
  "group-has-[[data-checked]]/checkbox-item:text-foreground",
102
102
  "group-has-[[data-indeterminate]]/checkbox-item:text-foreground",
103
103
  "group-has-[[data-disabled]]/checkbox-item:text-disabled-foreground",
@@ -115,7 +115,7 @@ const z = r(
115
115
  ref: t,
116
116
  "data-slot": "checkbox-item-description",
117
117
  className: d(
118
- u,
118
+ f,
119
119
  "group-has-[[data-disabled]]/checkbox-item:text-disabled-foreground",
120
120
  a
121
121
  ),
@@ -1,9 +1,9 @@
1
1
  import { jsxs as L, jsx as r } from "react/jsx-runtime";
2
- import { forwardRef as w, useState as x, useMemo as D, useEffect as F, useContext as H, createContext as O } from "react";
3
- import { IconSelector as K, IconCheck as V, IconCopy as $, IconDownload as q } from "@tabler/icons-react";
2
+ import { createContext as F, forwardRef as w, useState as x, useMemo as D, useEffect as O, useContext as H } from "react";
3
+ import { IconCheck as K, IconCopy as V, IconSelector as $, IconDownload as q } from "@tabler/icons-react";
4
4
  import { isStorybookTestEnv as v, highlightCode as M, cn as f } from "../../../../lib/utils.js";
5
5
  import { Button as S } from "../button/button.js";
6
- const I = O({
6
+ const I = F({
7
7
  code: "",
8
8
  copyText: "",
9
9
  isCollapsed: !1,
@@ -48,7 +48,7 @@ const ee = "min(60vh, 32rem)", oe = "dark:hidden [&>pre]:m-0 [&>pre]:min-h-10 [&
48
48
  () => v ? `<pre><code>${P(s)}</code></pre>` : "",
49
49
  [s]
50
50
  );
51
- F(() => {
51
+ O(() => {
52
52
  if (v) return;
53
53
  let g = !1;
54
54
  const B = (u) => {
@@ -183,7 +183,7 @@ const re = w(
183
183
  c instanceof Error ? c : new Error("Clipboard write failed")
184
184
  );
185
185
  }
186
- }, p = C ? V : $;
186
+ }, p = C ? K : V;
187
187
  return /* @__PURE__ */ r(
188
188
  S,
189
189
  {
@@ -213,7 +213,7 @@ const le = w(
213
213
  size: "icon-sm",
214
214
  variant: "secondary",
215
215
  ...n,
216
- children: e ?? /* @__PURE__ */ r(K, { size: 14 })
216
+ children: e ?? /* @__PURE__ */ r($, { size: 14 })
217
217
  }
218
218
  );
219
219
  }
@@ -0,0 +1,15 @@
1
+ import { FC } from 'react';
2
+ import { Dayjs } from 'dayjs';
3
+ import { ShortcutItem } from '../shared/shortcuts-panel/shortcuts-panel';
4
+ export type { ShortcutItem };
5
+ export interface DatePickerProps {
6
+ value: Dayjs | null;
7
+ onChange: (date: Dayjs | null) => void;
8
+ format?: string;
9
+ placeholder?: string;
10
+ displayWeekNumber?: boolean;
11
+ shortcuts?: ShortcutItem[];
12
+ defaultDate?: Dayjs;
13
+ className?: string;
14
+ }
15
+ export declare const DatePicker: FC<DatePickerProps>;
@@ -0,0 +1,73 @@
1
+ import { jsx as e, jsxs as l } from "react/jsx-runtime";
2
+ import { cn as k } from "../../../../../lib/utils.js";
3
+ import { Popover as x, PopoverTrigger as P, PopoverContent as M } from "../../popover/popover.js";
4
+ import { Calendar as N } from "../shared/calendar/calendar.js";
5
+ import { DateTimeInput as w } from "../shared/date-time-input/date-time-input.js";
6
+ import { ShortcutsPanel as R } from "../shared/shortcuts-panel/shortcuts-panel.js";
7
+ import { useDatePicker as S } from "./use-date-picker.js";
8
+ const Y = (n) => n ? [n, n] : [null, null], V = ({
9
+ value: n,
10
+ onChange: r,
11
+ format: i = "DD/MM/YYYY",
12
+ placeholder: p,
13
+ displayWeekNumber: c = !1,
14
+ shortcuts: t,
15
+ defaultDate: d,
16
+ className: s
17
+ }) => {
18
+ const {
19
+ isOpen: o,
20
+ displayedMonth: m,
21
+ tempDate: a,
22
+ handleOpenChange: h,
23
+ handleDateClick: f,
24
+ handleMonthChange: u,
25
+ handleApplyShortcut: v,
26
+ inputRef: g,
27
+ popoverRef: C
28
+ } = S({ value: n, onChange: r, defaultDate: d }), D = o ? a : n;
29
+ return /* @__PURE__ */ e("div", { "data-slot": "date-picker", className: k("relative w-full", s), children: /* @__PURE__ */ l(x, { open: o, onOpenChange: h, children: [
30
+ /* @__PURE__ */ e(P, { render: /* @__PURE__ */ e("div", { ref: g, className: "w-full" }), children: /* @__PURE__ */ e(
31
+ w,
32
+ {
33
+ value: D,
34
+ format: i,
35
+ placeholder: p,
36
+ isOpen: o,
37
+ variant: "date"
38
+ }
39
+ ) }),
40
+ /* @__PURE__ */ e(
41
+ M,
42
+ {
43
+ ref: C,
44
+ className: "rounded-xl w-auto p-0",
45
+ side: "bottom",
46
+ align: "start",
47
+ children: /* @__PURE__ */ l("div", { "data-slot": "date-picker-content", className: "flex flex-row", children: [
48
+ t && t.length > 0 && /* @__PURE__ */ e(
49
+ R,
50
+ {
51
+ shortcuts: t,
52
+ onShortcutClick: v
53
+ }
54
+ ),
55
+ /* @__PURE__ */ e("div", { className: "p-3", children: /* @__PURE__ */ e(
56
+ N,
57
+ {
58
+ displayedMonth: m,
59
+ selectedRange: Y(a),
60
+ hoverDate: null,
61
+ displayWeekNumber: c,
62
+ onDateClick: f,
63
+ onMonthChange: u
64
+ }
65
+ ) })
66
+ ] })
67
+ }
68
+ )
69
+ ] }) });
70
+ };
71
+ export {
72
+ V as DatePicker
73
+ };
@@ -0,0 +1,3 @@
1
+ export { DatePicker } from './date-picker';
2
+ export type { DatePickerProps, ShortcutItem } from './date-picker';
3
+ export type { UseDatePickerProps, UseDatePickerReturn } from './types';
@@ -0,0 +1,17 @@
1
+ import { Dayjs } from 'dayjs';
2
+ export interface UseDatePickerProps {
3
+ value: Dayjs | null;
4
+ onChange: (date: Dayjs | null) => void;
5
+ defaultDate?: Dayjs;
6
+ }
7
+ export interface UseDatePickerReturn {
8
+ isOpen: boolean;
9
+ displayedMonth: Dayjs;
10
+ tempDate: Dayjs | null;
11
+ handleOpenChange: (open: boolean) => void;
12
+ handleDateClick: (date: Dayjs) => void;
13
+ handleMonthChange: (month: Dayjs) => void;
14
+ handleApplyShortcut: (shortcutValue: Dayjs | [Dayjs, Dayjs] | [Dayjs | null, Dayjs | null]) => void;
15
+ inputRef: React.RefObject<HTMLDivElement>;
16
+ popoverRef: React.RefObject<HTMLDivElement>;
17
+ }
@@ -0,0 +1,3 @@
1
+ import { UseDatePickerProps, UseDatePickerReturn } from './types';
2
+ export type { UseDatePickerProps, UseDatePickerReturn };
3
+ export declare const useDatePicker: ({ value, onChange, defaultDate, }: UseDatePickerProps) => UseDatePickerReturn;
@@ -0,0 +1,52 @@
1
+ import { useRef as y, useCallback as A, useEffect as O } from "react";
2
+ import R from "dayjs";
3
+ import { usePopoverState as B } from "../shared/hooks/use-popover-state.js";
4
+ import { useSingleDateState as C } from "../shared/hooks/use-single-date-state.js";
5
+ const x = ({
6
+ value: n,
7
+ onChange: t,
8
+ defaultDate: o = R()
9
+ }) => {
10
+ const s = y(() => {
11
+ }), { isOpen: r, setIsOpen: a, popoverRef: c, inputRef: p } = B({
12
+ onBackspace: A(() => s.current(), [])
13
+ }), l = C({
14
+ value: n,
15
+ defaultDate: o,
16
+ onDateSelected: (e) => {
17
+ t(e), a(!1);
18
+ }
19
+ }), {
20
+ tempDate: d,
21
+ displayedMonth: f,
22
+ handleDateClick: i,
23
+ handleMonthChange: h,
24
+ clearDate: m,
25
+ resetDate: u
26
+ } = l, D = () => {
27
+ u(n);
28
+ }, S = () => {
29
+ m() && t(null);
30
+ };
31
+ return O(() => {
32
+ s.current = S;
33
+ }), {
34
+ isOpen: r,
35
+ displayedMonth: f,
36
+ tempDate: d,
37
+ handleOpenChange: (e) => {
38
+ D(), a(e);
39
+ },
40
+ handleDateClick: i,
41
+ handleMonthChange: h,
42
+ handleApplyShortcut: (e) => {
43
+ const k = Array.isArray(e) ? e[0] : e;
44
+ t(k), a(!1);
45
+ },
46
+ inputRef: p,
47
+ popoverRef: c
48
+ };
49
+ };
50
+ export {
51
+ x as useDatePicker
52
+ };
@@ -1,99 +1,88 @@
1
1
  import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
- import { cn as N } from "../../../../../lib/utils.js";
3
- import { Popover as w, PopoverTrigger as Y, PopoverContent as T } from "../../popover/popover.js";
4
- import { Calendar as j } from "../shared/calendar/calendar.js";
5
- import { DateTimeInput as y } from "../shared/date-time-input/date-time-input.js";
6
- import { ShortcutsPanel as H } from "../shared/shortcuts-panel/shortcuts-panel.js";
7
- import { useDateRangePicker as O } from "./use-date-range-picker.js";
8
- const F = ({
9
- value: t,
2
+ import { cn as S } from "../../../../../lib/utils.js";
3
+ import { Popover as M, PopoverTrigger as N, PopoverContent as w } from "../../popover/popover.js";
4
+ import { Calendar as Y } from "../shared/calendar/calendar.js";
5
+ import { DateTimeInput as O } from "../shared/date-time-input/date-time-input.js";
6
+ import { ShortcutsPanel as j } from "../shared/shortcuts-panel/shortcuts-panel.js";
7
+ import { useDateRangePicker as y } from "./use-date-range-picker.js";
8
+ const z = ({
9
+ value: n,
10
10
  onChange: d,
11
11
  format: p = "DD/MM/YYYY",
12
12
  placeholder: c,
13
13
  displayWeekNumber: h = !1,
14
- shortcuts: n,
14
+ shortcuts: t,
15
15
  defaultDate: m,
16
16
  className: s
17
17
  }) => {
18
18
  const {
19
19
  isOpen: a,
20
- step: o,
20
+ step: r,
21
21
  displayedMonth: v,
22
- tempStart: r,
22
+ tempStart: o,
23
23
  tempEnd: l,
24
24
  hoverDate: f,
25
- handleTogglePopover: g,
26
- handleCancel: C,
25
+ handleOpenChange: g,
27
26
  handleDateClick: D,
28
27
  handleMonthChange: u,
29
- handleDateHover: k,
30
- handleSetStep: P,
31
- handleApplyShortcut: R,
32
- inputRef: x,
33
- popoverRef: S
34
- } = O({ value: t, onChange: d, defaultDate: m });
28
+ handleDateHover: C,
29
+ handleSetStep: k,
30
+ handleApplyShortcut: P,
31
+ inputRef: R,
32
+ popoverRef: x
33
+ } = y({ value: n, onChange: d, defaultDate: m });
35
34
  return /* @__PURE__ */ e(
36
35
  "div",
37
36
  {
38
37
  "data-slot": "date-range-picker",
39
- className: N("relative w-full", s),
40
- children: /* @__PURE__ */ i(
41
- w,
42
- {
43
- open: a,
44
- onOpenChange: (M) => {
45
- M || C();
46
- },
47
- children: [
48
- /* @__PURE__ */ e(Y, { render: /* @__PURE__ */ e("div", { ref: x, className: "w-full" }), children: /* @__PURE__ */ e(
49
- y,
50
- {
51
- value: a ? [r, l] : t,
52
- format: p,
53
- placeholder: c,
54
- onClick: g,
55
- isOpen: a,
56
- variant: "date",
57
- activeRangePart: a ? o : void 0,
58
- onRangePartClick: a ? P : void 0
59
- }
60
- ) }),
61
- /* @__PURE__ */ e(
62
- T,
63
- {
64
- ref: S,
65
- className: "rounded-xl w-auto p-0",
66
- side: "bottom",
67
- align: "start",
68
- children: /* @__PURE__ */ i("div", { "data-slot": "date-range-picker-content", className: "flex flex-row", children: [
69
- n && n.length > 0 && /* @__PURE__ */ e(
70
- H,
71
- {
72
- shortcuts: n,
73
- onShortcutClick: R
74
- }
75
- ),
76
- /* @__PURE__ */ e("div", { className: "p-3", children: /* @__PURE__ */ e(
77
- j,
78
- {
79
- displayedMonth: v,
80
- selectedRange: [r, l],
81
- hoverDate: o === "end" ? f : null,
82
- displayWeekNumber: h,
83
- onDateClick: D,
84
- onMonthChange: u,
85
- onDateHover: k
86
- }
87
- ) })
88
- ] })
89
- }
90
- )
91
- ]
92
- }
93
- )
38
+ className: S("relative w-full", s),
39
+ children: /* @__PURE__ */ i(M, { open: a, onOpenChange: g, children: [
40
+ /* @__PURE__ */ e(N, { render: /* @__PURE__ */ e("div", { ref: R, className: "w-full" }), children: /* @__PURE__ */ e(
41
+ O,
42
+ {
43
+ value: a ? [o, l] : n,
44
+ format: p,
45
+ placeholder: c,
46
+ isOpen: a,
47
+ variant: "date",
48
+ activeRangePart: a ? r : void 0,
49
+ onRangePartClick: a ? k : void 0
50
+ }
51
+ ) }),
52
+ /* @__PURE__ */ e(
53
+ w,
54
+ {
55
+ ref: x,
56
+ className: "rounded-xl w-auto p-0",
57
+ side: "bottom",
58
+ align: "start",
59
+ children: /* @__PURE__ */ i("div", { "data-slot": "date-range-picker-content", className: "flex flex-row", children: [
60
+ t && t.length > 0 && /* @__PURE__ */ e(
61
+ j,
62
+ {
63
+ shortcuts: t,
64
+ onShortcutClick: P
65
+ }
66
+ ),
67
+ /* @__PURE__ */ e("div", { className: "p-3", children: /* @__PURE__ */ e(
68
+ Y,
69
+ {
70
+ displayedMonth: v,
71
+ selectedRange: [o, l],
72
+ hoverDate: r === "end" ? f : null,
73
+ displayWeekNumber: h,
74
+ onDateClick: D,
75
+ onMonthChange: u,
76
+ onDateHover: C
77
+ }
78
+ ) })
79
+ ] })
80
+ }
81
+ )
82
+ ] })
94
83
  }
95
84
  );
96
85
  };
97
86
  export {
98
- F as DateRangePicker
87
+ z as DateRangePicker
99
88
  };
@@ -13,8 +13,7 @@ export interface UseDateRangePickerReturn {
13
13
  tempStart: Dayjs | null;
14
14
  tempEnd: Dayjs | null;
15
15
  hoverDate: Dayjs | null;
16
- handleTogglePopover: () => void;
17
- handleCancel: () => void;
16
+ handleOpenChange: (open: boolean) => void;
18
17
  handleDateClick: (date: Dayjs) => void;
19
18
  handleMonthChange: (month: Dayjs) => void;
20
19
  handleDateHover: (date: Dayjs | null) => void;
@@ -1,82 +1,69 @@
1
- import { useRef as k, useCallback as s, useEffect as g } from "react";
2
- import b from "dayjs";
3
- import { usePopoverState as j } from "../shared/hooks/use-popover-state.js";
4
- import { useRangeDateState as H } from "../shared/hooks/use-range-date-state.js";
5
- import { useRangeStepManager as I } from "../shared/hooks/use-range-step-manager.js";
6
- const U = ({
1
+ import { useRef as E, useCallback as c, useEffect as x } from "react";
2
+ import P from "dayjs";
3
+ import { usePopoverState as b } from "../shared/hooks/use-popover-state.js";
4
+ import { useRangeDateState as j } from "../shared/hooks/use-range-date-state.js";
5
+ import { useRangeStepManager as H } from "../shared/hooks/use-range-step-manager.js";
6
+ const L = ({
7
7
  value: r,
8
8
  onChange: t,
9
- defaultDate: D = b()
9
+ defaultDate: S = P()
10
10
  }) => {
11
- const d = k(() => {
12
- }), f = k(() => {
13
- }), {
14
- isOpen: i,
15
- setIsOpen: a,
16
- popoverRef: R,
17
- inputRef: v,
18
- handleTogglePopover: y
19
- } = j({
20
- onClose: s(() => d.current(), []),
21
- onBackspace: s(() => f.current(), [])
22
- }), A = I(), { step: o, handleBack: c, handleNext: h, resetStep: n } = A, C = H({
11
+ const p = E(() => {
12
+ }), { isOpen: m, setIsOpen: s, popoverRef: u, inputRef: k } = b({
13
+ onBackspace: c(() => p.current(), [])
14
+ }), D = H(), { step: n, handleBack: o, handleNext: d, resetStep: a } = D, R = j({
23
15
  value: r,
24
- defaultDate: D,
25
- onEndDateSelected: s(
26
- (e, p) => {
27
- t([e, p]), a(!1), n();
16
+ defaultDate: S,
17
+ onEndDateSelected: c(
18
+ (e, l) => {
19
+ t([e, l]), s(!1), a();
28
20
  },
29
- [t, a, n]
21
+ [t, s, a]
30
22
  )
31
23
  }), {
32
- tempStart: P,
33
- tempEnd: B,
34
- displayedMonth: M,
35
- hoverDate: E,
36
- handleDateClick: T,
37
- handleDateHover: x,
38
- handleMonthChange: O,
39
- clearActiveSegment: u,
40
- resetDates: S
41
- } = C, l = s(() => {
42
- S(r), n();
43
- }, [S, n, r]), m = s(() => {
44
- const e = u(o);
45
- e === null ? c() : e[0] === null && e[1] === null && t(e);
46
- }, [u, o, c, t]);
47
- return g(() => {
48
- d.current = l;
49
- }, [l]), g(() => {
50
- f.current = m;
51
- }, [m]), {
52
- isOpen: i,
53
- step: o,
54
- displayedMonth: M,
55
- tempStart: P,
56
- tempEnd: B,
57
- hoverDate: E,
58
- handleTogglePopover: () => {
59
- i || l(), y();
60
- },
61
- handleCancel: () => {
62
- l(), a(!1);
24
+ tempStart: y,
25
+ tempEnd: A,
26
+ displayedMonth: B,
27
+ hoverDate: C,
28
+ handleDateClick: M,
29
+ handleDateHover: O,
30
+ handleMonthChange: g,
31
+ clearActiveSegment: i,
32
+ resetDates: h
33
+ } = R, v = c(() => {
34
+ h(r), a();
35
+ }, [h, a, r]), f = c(() => {
36
+ const e = i(n);
37
+ e === null ? o() : e[0] === null && e[1] === null && t(e);
38
+ }, [i, n, o, t]);
39
+ return x(() => {
40
+ p.current = f;
41
+ }, [f]), {
42
+ isOpen: m,
43
+ step: n,
44
+ displayedMonth: B,
45
+ tempStart: y,
46
+ tempEnd: A,
47
+ hoverDate: C,
48
+ handleOpenChange: (e) => {
49
+ v(), s(e);
63
50
  },
64
51
  handleDateClick: (e) => {
65
- T(e, o), o === "start" && h();
52
+ M(e, n), n === "start" && d();
66
53
  },
67
- handleMonthChange: O,
68
- handleDateHover: x,
54
+ handleMonthChange: g,
55
+ handleDateHover: O,
69
56
  handleSetStep: (e) => {
70
- e === "start" ? c() : h();
57
+ e === "start" ? o() : d();
71
58
  },
72
59
  handleApplyShortcut: (e) => {
73
- const p = Array.isArray(e) ? e : [e, e];
74
- t(p), a(!1), n();
60
+ const l = Array.isArray(e) ? e : [e, e];
61
+ t(l), s(!1), a();
75
62
  },
76
- inputRef: v,
77
- popoverRef: R
63
+ inputRef: k,
64
+ popoverRef: u
78
65
  };
79
66
  };
80
67
  export {
81
- U as useDateRangePicker
68
+ L as useDateRangePicker
82
69
  };