@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
@@ -0,0 +1,10 @@
1
+ import { DatePicker as o } from "./date-picker/date-picker.js";
2
+ import { DateRangePicker as i } from "./date-range-picker/date-range-picker.js";
3
+ import { DateTimeRangePicker as a } from "./date-time-range-picker/date-time-range-picker.js";
4
+ import { TimePicker as f } from "./time-picker/time-picker.js";
5
+ export {
6
+ o as DatePicker,
7
+ i as DateRangePicker,
8
+ a as DateTimeRangePicker,
9
+ f as TimePicker
10
+ };
@@ -1,10 +1,10 @@
1
1
  import { jsxs as x, jsx as l } from "react/jsx-runtime";
2
2
  import C from "react";
3
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";
4
+ import { getCalendarDays as E, getWeekdayNames as O, getWeekNumbers as T, isDateInRange as v, isSameDay as f, isToday as B, isOutsideMonth as K } from "../../utils/calendar-utils.js";
5
+ import { CalendarHeader as P } from "../calendar-header/calendar-header.js";
6
6
  import { DAYS_IN_WEEK as p } from "../constants.js";
7
- function P({
7
+ function _({
8
8
  isOutsideMonth: r,
9
9
  isSelected: t,
10
10
  isToday: s,
@@ -42,14 +42,14 @@ const W = ({
42
42
  onDateHover: i,
43
43
  className: N
44
44
  }) => {
45
- const [n, m] = t, h = _(r), M = E(), k = o ? O(h) : [], Y = () => {
45
+ const [n, m] = t, h = E(r), M = O(), k = o ? T(h) : [], Y = () => {
46
46
  a(r.subtract(1, "month"));
47
47
  }, D = () => {
48
48
  a(r.add(1, "month"));
49
49
  }, w = (e) => {
50
50
  const d = {
51
- isOutsideMonth: B(e, r),
52
- isToday: T(e),
51
+ isOutsideMonth: K(e, r),
52
+ isToday: B(e),
53
53
  isSelected: f(e, n) || f(e, m),
54
54
  isRangeStart: f(e, n),
55
55
  isRangeEnd: f(e, m),
@@ -64,7 +64,7 @@ const W = ({
64
64
  };
65
65
  return /* @__PURE__ */ x("div", { "data-slot": "calendar", className: b("flex flex-col gap-4", N), children: [
66
66
  /* @__PURE__ */ l(
67
- K,
67
+ P,
68
68
  {
69
69
  displayedMonth: r,
70
70
  onPrevMonth: Y,
@@ -96,7 +96,7 @@ const W = ({
96
96
  /* @__PURE__ */ l(
97
97
  "div",
98
98
  {
99
- className: P(u),
99
+ className: _(u),
100
100
  onClick: () => c(e),
101
101
  onMouseEnter: () => i?.(e),
102
102
  onMouseLeave: () => i?.(null),
@@ -7,7 +7,7 @@ export interface DateTimeInputProps {
7
7
  value: [Dayjs | null, Dayjs | null] | Dayjs | null;
8
8
  format: string;
9
9
  placeholder?: string;
10
- onClick: () => void;
10
+ onClick?: () => void;
11
11
  isOpen: boolean;
12
12
  className?: string;
13
13
  ariaLabel?: string;
@@ -37,11 +37,11 @@ const v = "Date picker", C = () => {
37
37
  "relative flex items-center cursor-pointer w-full group",
38
38
  i
39
39
  ),
40
- onClick: n,
41
40
  role: "combobox",
42
41
  "aria-label": l,
43
42
  "aria-expanded": t,
44
43
  "aria-controls": c,
44
+ onClick: n,
45
45
  children: [
46
46
  /* @__PURE__ */ r(
47
47
  R,
@@ -1,5 +1,4 @@
1
1
  export interface UsePopoverStateOptions {
2
- onClose?: () => void;
3
2
  onBackspace?: () => void;
4
3
  }
5
4
  export interface UsePopoverStateReturn {
@@ -7,6 +6,5 @@ export interface UsePopoverStateReturn {
7
6
  setIsOpen: (isOpen: boolean) => void;
8
7
  popoverRef: React.RefObject<HTMLDivElement>;
9
8
  inputRef: React.RefObject<HTMLDivElement>;
10
- handleTogglePopover: () => void;
11
9
  }
12
10
  export declare const usePopoverState: (options?: UsePopoverStateOptions) => UsePopoverStateReturn;
@@ -1,40 +1,24 @@
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;
1
+ import { useState as f, useRef as c, useEffect as p } from "react";
2
+ const m = (r = {}) => {
3
+ const { onBackspace: t } = r, [n, a] = f(!1), u = c(null), i = c(null);
4
+ return p(() => {
5
+ if (!n) return;
6
+ const s = (o) => {
7
+ if (o.key === "Backspace" && t) {
8
+ const { target: e } = o;
9
+ e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLElement && e.isContentEditable || (o.preventDefault(), t());
19
10
  }
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
11
  };
30
- }, [a, s, c]), {
31
- isOpen: a,
32
- setIsOpen: n,
33
- popoverRef: i,
34
- inputRef: r,
35
- handleTogglePopover: m
12
+ return document.addEventListener("keydown", s), () => {
13
+ document.removeEventListener("keydown", s);
14
+ };
15
+ }, [n, t]), {
16
+ isOpen: n,
17
+ setIsOpen: a,
18
+ popoverRef: u,
19
+ inputRef: i
36
20
  };
37
21
  };
38
22
  export {
39
- g as usePopoverState
23
+ m as usePopoverState
40
24
  };
@@ -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,2 @@
1
+ export { TimePickerPanel } from './time-picker-panel';
2
+ export type { TimePickerPanelProps } from './time-picker-panel';
@@ -0,0 +1,19 @@
1
+ import { FC } from 'react';
2
+ type TimePickerPanelBaseProps = {
3
+ hour: number;
4
+ minute: number;
5
+ onHourChange: (hour: number) => void;
6
+ onMinuteChange: (minute: number) => void;
7
+ className?: string;
8
+ };
9
+ export type TimePickerPanelProps = TimePickerPanelBaseProps & ({
10
+ timeFormat: '12h';
11
+ amPm: 'AM' | 'PM';
12
+ onAmPmChange: (amPm: 'AM' | 'PM') => void;
13
+ } | {
14
+ timeFormat?: '24h';
15
+ amPm?: undefined;
16
+ onAmPmChange?: undefined;
17
+ });
18
+ export declare const TimePickerPanel: FC<TimePickerPanelProps>;
19
+ export {};
@@ -0,0 +1,41 @@
1
+ import { jsxs as r, jsx as e, Fragment as c } from "react/jsx-runtime";
2
+ import { cn as h } from "../../../../../../lib/utils.js";
3
+ import { AmPmScroll as d } from "../am-pm-scroll/am-pm-scroll.js";
4
+ import { TimePickerScroll as a } from "../time-picker-scroll/time-picker-scroll.js";
5
+ const f = (m) => {
6
+ const { hour: t, minute: i, onHourChange: n, onMinuteChange: l, className: o } = m, s = m.timeFormat ?? "24h";
7
+ return /* @__PURE__ */ r(
8
+ "div",
9
+ {
10
+ "data-slot": "time-picker-panel",
11
+ className: h("flex items-stretch", o),
12
+ children: [
13
+ /* @__PURE__ */ e("div", { className: "px-3", children: /* @__PURE__ */ e(
14
+ a,
15
+ {
16
+ value: t,
17
+ onChange: n,
18
+ type: "hour",
19
+ timeFormat: s
20
+ }
21
+ ) }),
22
+ /* @__PURE__ */ e("div", { className: "w-px bg-border shrink-0 self-stretch" }),
23
+ /* @__PURE__ */ e("div", { className: "px-3", children: /* @__PURE__ */ e(
24
+ a,
25
+ {
26
+ value: i,
27
+ onChange: l,
28
+ type: "minute"
29
+ }
30
+ ) }),
31
+ m.timeFormat === "12h" && /* @__PURE__ */ r(c, { children: [
32
+ /* @__PURE__ */ e("div", { className: "w-px bg-border shrink-0 self-stretch" }),
33
+ /* @__PURE__ */ e("div", { className: "px-3", children: /* @__PURE__ */ e(d, { value: m.amPm, onChange: m.onAmPmChange }) })
34
+ ] })
35
+ ]
36
+ }
37
+ );
38
+ };
39
+ export {
40
+ f as TimePickerPanel
41
+ };
@@ -0,0 +1,3 @@
1
+ export { TimePicker } from './time-picker';
2
+ export type { TimePickerProps, ShortcutItem } from './time-picker';
3
+ export type { UseTimePickerProps, UseTimePickerReturn } from './types';
@@ -0,0 +1,16 @@
1
+ import { FC } from 'react';
2
+ import { Dayjs } from 'dayjs';
3
+ import { ShortcutItem } from '../shared/shortcuts-panel/shortcuts-panel';
4
+ import { TimeFormat } from '../utils/format-utils';
5
+ export type { ShortcutItem };
6
+ export interface TimePickerProps {
7
+ value: Dayjs | null;
8
+ onChange: (time: Dayjs | null) => void;
9
+ timeFormat?: TimeFormat;
10
+ format?: string;
11
+ placeholder?: string;
12
+ shortcuts?: ShortcutItem[];
13
+ defaultDate?: Dayjs;
14
+ className?: string;
15
+ }
16
+ export declare const TimePicker: FC<TimePickerProps>;
@@ -0,0 +1,100 @@
1
+ import { jsx as e, jsxs as o } from "react/jsx-runtime";
2
+ import { cn as T } from "../../../../../lib/utils.js";
3
+ import { Button as b } from "../../button/button.js";
4
+ import { Popover as w, PopoverTrigger as H, PopoverContent as M } from "../../popover/popover.js";
5
+ import { DateTimeInput as O } from "../shared/date-time-input/date-time-input.js";
6
+ import { ShortcutsPanel as S } from "../shared/shortcuts-panel/shortcuts-panel.js";
7
+ import { TimePickerPanel as h } from "../shared/time-picker-panel/time-picker-panel.js";
8
+ import { useTimePicker as j } from "./use-time-picker.js";
9
+ const z = ({
10
+ value: p,
11
+ onChange: c,
12
+ timeFormat: r = "24h",
13
+ format: d,
14
+ placeholder: s,
15
+ shortcuts: n,
16
+ defaultDate: f,
17
+ className: u
18
+ }) => {
19
+ const g = d ?? (r === "12h" ? "h:mm A" : "HH:mm"), {
20
+ isOpen: a,
21
+ hour: i,
22
+ minute: l,
23
+ amPm: v,
24
+ displayValue: C,
25
+ handleOpenChange: P,
26
+ handleApply: x,
27
+ handleHourChange: t,
28
+ handleMinuteChange: m,
29
+ handleAmPmChange: k,
30
+ handleApplyShortcut: N,
31
+ inputRef: y,
32
+ popoverRef: A
33
+ } = j({ value: p, onChange: c, timeFormat: r, defaultDate: f });
34
+ return /* @__PURE__ */ e("div", { "data-slot": "time-picker", className: T("relative w-full", u), children: /* @__PURE__ */ o(w, { open: a, onOpenChange: P, children: [
35
+ /* @__PURE__ */ e(H, { render: /* @__PURE__ */ e("div", { ref: y, className: "w-full" }), children: /* @__PURE__ */ e(
36
+ O,
37
+ {
38
+ value: C,
39
+ format: g,
40
+ placeholder: s,
41
+ isOpen: a,
42
+ variant: "time",
43
+ ariaLabel: "Time picker"
44
+ }
45
+ ) }),
46
+ /* @__PURE__ */ e(
47
+ M,
48
+ {
49
+ ref: A,
50
+ className: "rounded-xl w-auto p-0",
51
+ side: "bottom",
52
+ align: "start",
53
+ children: /* @__PURE__ */ o("div", { "data-slot": "time-picker-content", className: "flex flex-col", children: [
54
+ /* @__PURE__ */ o("div", { className: "flex flex-row", children: [
55
+ n && n.length > 0 && /* @__PURE__ */ e(
56
+ S,
57
+ {
58
+ shortcuts: n,
59
+ onShortcutClick: N
60
+ }
61
+ ),
62
+ r === "12h" ? /* @__PURE__ */ e(
63
+ h,
64
+ {
65
+ hour: i,
66
+ minute: l,
67
+ amPm: v,
68
+ timeFormat: "12h",
69
+ onHourChange: t,
70
+ onMinuteChange: m,
71
+ onAmPmChange: k
72
+ }
73
+ ) : /* @__PURE__ */ e(
74
+ h,
75
+ {
76
+ hour: i,
77
+ minute: l,
78
+ timeFormat: "24h",
79
+ onHourChange: t,
80
+ onMinuteChange: m
81
+ }
82
+ )
83
+ ] }),
84
+ /* @__PURE__ */ e("div", { className: "flex p-2 border-t border-border", children: /* @__PURE__ */ e(
85
+ b,
86
+ {
87
+ variant: "secondary",
88
+ className: "w-full",
89
+ onClick: x,
90
+ children: "Apply"
91
+ }
92
+ ) })
93
+ ] })
94
+ }
95
+ )
96
+ ] }) });
97
+ };
98
+ export {
99
+ z as TimePicker
100
+ };
@@ -0,0 +1,23 @@
1
+ import { Dayjs } from 'dayjs';
2
+ import { TimeFormat } from '../utils/format-utils';
3
+ export interface UseTimePickerProps {
4
+ value: Dayjs | null;
5
+ onChange: (time: Dayjs | null) => void;
6
+ timeFormat?: TimeFormat;
7
+ defaultDate?: Dayjs;
8
+ }
9
+ export interface UseTimePickerReturn {
10
+ isOpen: boolean;
11
+ hour: number;
12
+ minute: number;
13
+ amPm: 'AM' | 'PM';
14
+ displayValue: Dayjs | null;
15
+ handleOpenChange: (open: boolean) => void;
16
+ handleApply: () => void;
17
+ handleHourChange: (hour: number) => void;
18
+ handleMinuteChange: (minute: number) => void;
19
+ handleAmPmChange: (amPm: 'AM' | 'PM') => void;
20
+ handleApplyShortcut: (shortcutValue: Dayjs | [Dayjs, Dayjs] | [Dayjs | null, Dayjs | null]) => void;
21
+ inputRef: React.RefObject<HTMLDivElement>;
22
+ popoverRef: React.RefObject<HTMLDivElement>;
23
+ }
@@ -0,0 +1,3 @@
1
+ import { UseTimePickerProps, UseTimePickerReturn } from './types';
2
+ export type { UseTimePickerProps, UseTimePickerReturn };
3
+ export declare const useTimePicker: ({ value, onChange, timeFormat, defaultDate, }: UseTimePickerProps) => UseTimePickerReturn;
@@ -0,0 +1,64 @@
1
+ import { useRef as g, useCallback as B, useEffect as D } from "react";
2
+ import H from "dayjs";
3
+ import { DEFAULT_MINUTE as p, DEFAULT_START_HOUR as u } from "../shared/constants.js";
4
+ import { usePopoverState as M } from "../shared/hooks/use-popover-state.js";
5
+ import { useTimeState as _ } from "../shared/hooks/use-time-state.js";
6
+ const z = ({
7
+ value: n,
8
+ onChange: t,
9
+ timeFormat: h = "24h",
10
+ defaultDate: d = H()
11
+ }) => {
12
+ const s = g(() => {
13
+ }), { isOpen: r, setIsOpen: o, popoverRef: f, inputRef: A } = M({
14
+ onBackspace: B(() => s.current(), [])
15
+ }), T = _({
16
+ initialHour: n?.hour() ?? u,
17
+ initialMinute: n?.minute() ?? p,
18
+ timeFormat: h
19
+ }), {
20
+ hour: y,
21
+ minute: c,
22
+ amPm: O,
23
+ hour24: R,
24
+ handleHourChange: S,
25
+ handleMinuteChange: k,
26
+ handleAmPmChange: C,
27
+ resetTime: E
28
+ } = T, i = n ?? d, l = (e) => e.hour(R).minute(c).second(0).millisecond(0), P = (e) => i.hour(e.hour()).minute(e.minute()).second(0).millisecond(0), U = r ? l(i) : n, a = () => {
29
+ E(
30
+ n?.hour() ?? u,
31
+ n?.minute() ?? p
32
+ );
33
+ }, b = () => {
34
+ n !== null && (t(null), a());
35
+ };
36
+ return D(() => {
37
+ s.current = b;
38
+ }), {
39
+ isOpen: r,
40
+ hour: y,
41
+ minute: c,
42
+ amPm: O,
43
+ displayValue: U,
44
+ handleOpenChange: (e) => {
45
+ a(), o(e);
46
+ },
47
+ handleApply: () => {
48
+ const e = l(i);
49
+ t(e), o(!1);
50
+ },
51
+ handleHourChange: S,
52
+ handleMinuteChange: k,
53
+ handleAmPmChange: C,
54
+ handleApplyShortcut: (e) => {
55
+ const m = Array.isArray(e) ? e[0] : e;
56
+ t(m ? P(m) : null), o(!1);
57
+ },
58
+ inputRef: A,
59
+ popoverRef: f
60
+ };
61
+ };
62
+ export {
63
+ z as useTimePicker
64
+ };
@@ -1,7 +1,7 @@
1
1
  import r from "dayjs";
2
- import c from "dayjs/plugin/isBetween";
3
- import d from "dayjs/plugin/isSameOrBefore";
4
- import m from "dayjs/plugin/weekOfYear";
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
5
  import { DAYS_IN_WEEK as u } from "../shared/constants.js";
6
6
  r.extend(c);
7
7
  r.extend(d);
@@ -1,5 +1,5 @@
1
1
  import m from "dayjs";
2
- import u from "dayjs/plugin/customParseFormat";
2
+ import u from "dayjs/plugin/customParseFormat.js";
3
3
  import { HOURS_IN_12H as t, HOURS_IN_DAY as f, MINUTES_IN_HOUR as s, MINUTE_INCREMENT as o } from "../shared/constants.js";
4
4
  m.extend(u);
5
5
  const c = (r = "24h") => r === "12h" ? Array.from({ length: t }, (e, n) => n + 1) : Array.from({ length: f }, (e, n) => n), M = () => Array.from(
@@ -1,6 +1,5 @@
1
- import { ForwardRefExoticComponent, RefAttributes, ComponentProps, ReactNode } from 'react';
2
- import { SeparatorProps } from '@base-ui/react';
3
- import { MenuCheckboxItemProps, MenuGroupLabelProps, MenuItemProps, MenuRadioItemProps, MenuSubmenuTriggerProps, Menu as MenuPrimitive } from '@base-ui/react/menu';
1
+ import { ComponentProps, ComponentRef, ForwardRefExoticComponent, HTMLAttributes, ReactNode, RefAttributes } from 'react';
2
+ import { Menu as MenuPrimitive } from '@base-ui/react/menu';
4
3
  declare function DropdownMenu({ ...props }: MenuPrimitive.Root.Props): ReactNode;
5
4
  declare function DropdownMenuPortal({ container, ...props }: MenuPrimitive.Portal.Props): ReactNode;
6
5
  declare function DropdownMenuTrigger({ children, ...props }: MenuPrimitive.Trigger.Props): ReactNode;
@@ -8,23 +7,26 @@ declare function DropdownMenuContent({ align, alignOffset, side, sideOffset, cla
8
7
  container?: MenuPrimitive.Portal.Props['container'];
9
8
  }): ReactNode;
10
9
  declare function DropdownMenuGroup({ ...props }: MenuPrimitive.Group.Props): ReactNode;
11
- declare const DropdownMenuItem: ForwardRefExoticComponent<Omit<MenuItemProps & {
10
+ type DropdownMenuItemProps = MenuPrimitive.Item.Props & {
12
11
  inset?: boolean;
13
12
  variant?: 'default' | 'destructive';
14
- }, 'ref'> & RefAttributes<HTMLElement>>;
15
- declare const DropdownMenuCheckboxItem: ForwardRefExoticComponent<Omit<MenuCheckboxItemProps, 'ref'> & RefAttributes<HTMLElement>>;
13
+ };
14
+ declare const DropdownMenuItem: ForwardRefExoticComponent<Omit<DropdownMenuItemProps, 'ref'> & RefAttributes<ComponentRef<typeof MenuPrimitive.Item>>>;
15
+ declare const DropdownMenuCheckboxItem: ForwardRefExoticComponent<Omit<MenuPrimitive.CheckboxItem.Props, 'ref'> & RefAttributes<ComponentRef<typeof MenuPrimitive.CheckboxItem>>>;
16
16
  declare function DropdownMenuRadioGroup({ ...props }: MenuPrimitive.RadioGroup.Props): ReactNode;
17
- declare const DropdownMenuRadioItem: ForwardRefExoticComponent<Omit<MenuRadioItemProps, 'ref'> & RefAttributes<HTMLElement>>;
18
- declare const DropdownMenuLabel: ForwardRefExoticComponent<Omit<MenuGroupLabelProps & {
17
+ declare const DropdownMenuRadioItem: ForwardRefExoticComponent<Omit<MenuPrimitive.RadioItem.Props, 'ref'> & RefAttributes<ComponentRef<typeof MenuPrimitive.RadioItem>>>;
18
+ type DropdownMenuLabelProps = MenuPrimitive.GroupLabel.Props & {
19
19
  inset?: boolean;
20
- }, 'ref'> & RefAttributes<HTMLDivElement>>;
21
- declare const DropdownMenuHeader: ForwardRefExoticComponent<ComponentProps<'div'> & RefAttributes<HTMLDivElement>>;
22
- declare const DropdownMenuSeparator: ForwardRefExoticComponent<Omit<SeparatorProps, 'ref'> & RefAttributes<HTMLDivElement>>;
23
- declare const DropdownMenuShortcut: ForwardRefExoticComponent<ComponentProps<'span'> & RefAttributes<HTMLSpanElement>>;
20
+ };
21
+ declare const DropdownMenuLabel: ForwardRefExoticComponent<Omit<DropdownMenuLabelProps, 'ref'> & RefAttributes<ComponentRef<typeof MenuPrimitive.GroupLabel>>>;
22
+ declare const DropdownMenuHeader: ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, 'ref'> & RefAttributes<HTMLDivElement>>;
23
+ declare const DropdownMenuSeparator: ForwardRefExoticComponent<Omit<MenuPrimitive.Separator.Props, 'ref'> & RefAttributes<ComponentRef<typeof MenuPrimitive.Separator>>>;
24
+ declare const DropdownMenuShortcut: ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLSpanElement>, 'ref'> & RefAttributes<HTMLSpanElement>>;
24
25
  declare function DropdownMenuSub({ ...props }: MenuPrimitive.SubmenuRoot.Props): ReactNode;
25
- declare const DropdownMenuSubTrigger: ForwardRefExoticComponent<Omit<MenuSubmenuTriggerProps & {
26
+ type DropdownMenuSubTriggerProps = MenuPrimitive.SubmenuTrigger.Props & {
26
27
  inset?: boolean;
27
- }, 'ref'> & RefAttributes<HTMLElement>>;
28
+ };
29
+ declare const DropdownMenuSubTrigger: ForwardRefExoticComponent<Omit<DropdownMenuSubTriggerProps, 'ref'> & RefAttributes<ComponentRef<typeof MenuPrimitive.SubmenuTrigger>>>;
28
30
  declare function DropdownMenuSubContent({ align, alignOffset, side, sideOffset, className, ...props }: ComponentProps<typeof DropdownMenuContent>): ReactNode;
29
- declare const DropdownMenuSectionLabel: ForwardRefExoticComponent<ComponentProps<'div'> & RefAttributes<HTMLDivElement>>;
31
+ declare const DropdownMenuSectionLabel: ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>, 'ref'> & RefAttributes<HTMLDivElement>>;
30
32
  export { DropdownMenu, DropdownMenuPortal, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuHeader, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, DropdownMenuSectionLabel, };