@leonardaustin/ui 0.26.2 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/components/charts/AreaChart.js +113 -114
  2. package/dist/components/charts/Heatmap.d.ts +20 -0
  3. package/dist/components/charts/Heatmap.js +46 -0
  4. package/dist/components/charts/chartUtils.d.ts +2 -0
  5. package/dist/components/charts/chartUtils.js +14 -9
  6. package/dist/components/charts/useChartSize.d.ts +5 -0
  7. package/dist/components/charts/useChartSize.js +18 -0
  8. package/dist/components/tables/Pagination.d.ts +3 -1
  9. package/dist/components/tables/Pagination.js +12 -12
  10. package/dist/components/tables/ResourceTable.d.ts +5 -0
  11. package/dist/components/tables/ResourceTable.js +11 -9
  12. package/dist/components/tables/Table.d.ts +22 -3
  13. package/dist/components/tables/Table.js +41 -35
  14. package/dist/components/ui/ActionLink.d.ts +14 -0
  15. package/dist/components/ui/ActionLink.js +12 -0
  16. package/dist/components/ui/CalendarGrid.js +10 -10
  17. package/dist/components/ui/DatePicker.d.ts +1 -1
  18. package/dist/components/ui/DatePicker.js +5 -10
  19. package/dist/components/ui/DateRangePicker.d.ts +3 -1
  20. package/dist/components/ui/DateRangePicker.js +105 -80
  21. package/dist/components/ui/DateTimePicker.js +20 -20
  22. package/dist/components/ui/EmptyState.d.ts +8 -6
  23. package/dist/components/ui/EmptyState.js +11 -10
  24. package/dist/components/ui/ErrorBoundary.d.ts +6 -0
  25. package/dist/components/ui/ErrorBoundary.js +11 -5
  26. package/dist/components/ui/Grid.d.ts +1 -1
  27. package/dist/components/ui/Icon.d.ts +91 -0
  28. package/dist/components/ui/Icon.js +98 -0
  29. package/dist/components/ui/Inline.d.ts +1 -1
  30. package/dist/components/ui/LoadingSpinner.d.ts +7 -3
  31. package/dist/components/ui/LoadingSpinner.js +19 -11
  32. package/dist/components/ui/Meter.d.ts +11 -0
  33. package/dist/components/ui/Meter.js +7 -0
  34. package/dist/components/ui/MetricCard.d.ts +11 -8
  35. package/dist/components/ui/MetricCard.js +18 -15
  36. package/dist/components/ui/PaginationBar.d.ts +3 -3
  37. package/dist/components/ui/PaginationBar.js +35 -33
  38. package/dist/components/ui/SideSheet.d.ts +4 -2
  39. package/dist/components/ui/SideSheet.js +64 -52
  40. package/dist/components/ui/Stack.d.ts +1 -1
  41. package/dist/components/ui/Tabs.d.ts +5 -1
  42. package/dist/components/ui/Tabs.js +23 -21
  43. package/dist/components/ui/Text.d.ts +19 -0
  44. package/dist/components/ui/Text.js +20 -0
  45. package/dist/components/ui/Toolbar.js +13 -13
  46. package/dist/core.css +105 -0
  47. package/dist/hooks/useFocusTrap.js +1 -1
  48. package/dist/index.d.ts +5 -0
  49. package/dist/index.js +134 -129
  50. package/dist/lib/calendar.d.ts +2 -0
  51. package/dist/lib/calendar.js +234 -229
  52. package/dist/styles.css +106 -0
  53. package/package.json +1 -1
@@ -1,5 +1,13 @@
1
1
  import type { ComponentPropsWithRef, CSSProperties, ReactNode } from "react";
2
2
  export interface TableProps extends ComponentPropsWithRef<"table"> {
3
+ /** Use a borderless table inside an existing card. Defaults to "framed". */
4
+ appearance?: "framed" | "embedded";
5
+ /** Reduce horizontal and vertical cell padding. Defaults to false. */
6
+ compact?: boolean;
7
+ /** Tint alternating body rows. Defaults to false. */
8
+ striped?: boolean;
9
+ /** Use a tinted header with body-sized labels in their original case. */
10
+ headerAppearance?: "default" | "band";
3
11
  /** Table caption, rendered as a `<caption>`. */
4
12
  caption?: ReactNode;
5
13
  /** Visually hide the caption while keeping it available to screen readers. Defaults to `false`. */
@@ -17,9 +25,10 @@ export interface TableProps extends ComponentPropsWithRef<"table"> {
17
25
  /** Content rendered inside the wrapper `<div>` before the `<table>`, for example a visually hidden `role="status"` loading message. */
18
26
  beforeTable?: ReactNode;
19
27
  }
20
- export declare function Table({ caption, captionHidden, captionClassName, stickyHeader, maxHeight, wrapperClassName, wrapperProps, beforeTable, className, children, ...props }: TableProps): import("react/jsx-runtime").JSX.Element;
28
+ export declare function Table({ appearance, compact, striped, headerAppearance, caption, captionHidden, captionClassName, stickyHeader, maxHeight, wrapperClassName, wrapperProps, beforeTable, className, children, ...props }: TableProps): import("react/jsx-runtime").JSX.Element;
21
29
  export declare function TableHead({ className, ...props }: ComponentPropsWithRef<"thead">): import("react/jsx-runtime").JSX.Element;
22
30
  export declare function TableBody({ className, ...props }: ComponentPropsWithRef<"tbody">): import("react/jsx-runtime").JSX.Element;
31
+ export declare function TableFoot({ className, ...props }: ComponentPropsWithRef<"tfoot">): import("react/jsx-runtime").JSX.Element;
23
32
  export interface TableRowProps extends ComponentPropsWithRef<"tr"> {
24
33
  /** Marks the row selected via `data-selected`, which applies the selected background. `aria-selected` is not set; pass it yourself only where it is valid (grid/treegrid rows). */
25
34
  selected?: boolean;
@@ -28,6 +37,11 @@ export interface TableRowProps extends ComponentPropsWithRef<"tr"> {
28
37
  }
29
38
  export declare function TableRow({ selected, interactive, className, ...props }: TableRowProps): import("react/jsx-runtime").JSX.Element;
30
39
  export interface TableHeaderCellProps extends Omit<ComponentPropsWithRef<"th">, "align"> {
40
+ /**
41
+ * Hide at wrapper widths of 32rem or less.
42
+ * Hiding uses a container query, so place the table in a block-level parent; shrink-to-fit parents such as inline-block collapse it.
43
+ */
44
+ lowPriority?: boolean;
31
45
  /** Horizontal text alignment of the cell. */
32
46
  align?: CSSProperties["textAlign"];
33
47
  /** Right-align with tabular figures for numeric columns. Defaults to `false`. */
@@ -37,8 +51,13 @@ export interface TableHeaderCellProps extends Omit<ComponentPropsWithRef<"th">,
37
51
  /** Reports the requested next direction. Sorting and state updates belong to the caller. */
38
52
  onSort?: (direction: "ascending" | "descending") => void;
39
53
  }
40
- export declare function TableHeaderCell({ numeric, align, sort, onSort, scope, className, style, children, ...props }: TableHeaderCellProps): import("react/jsx-runtime").JSX.Element;
54
+ export declare function TableHeaderCell({ lowPriority, numeric, align, sort, onSort, scope, className, style, children, ...props }: TableHeaderCellProps): import("react/jsx-runtime").JSX.Element;
41
55
  export interface TableCellProps extends Omit<ComponentPropsWithRef<"td">, "align"> {
56
+ /**
57
+ * Hide at wrapper widths of 32rem or less.
58
+ * Hiding uses a container query, so place the table in a block-level parent; shrink-to-fit parents such as inline-block collapse it.
59
+ */
60
+ lowPriority?: boolean;
42
61
  /** Horizontal text alignment of the cell. */
43
62
  align?: CSSProperties["textAlign"];
44
63
  /** Right-align with tabular figures for numeric columns. Defaults to `false`. */
@@ -46,7 +65,7 @@ export interface TableCellProps extends Omit<ComponentPropsWithRef<"td">, "align
46
65
  /** Prevent the cell content from wrapping. Defaults to `false`. */
47
66
  nowrap?: boolean;
48
67
  }
49
- export declare function TableCell({ numeric, align, nowrap, className, style, ...props }: TableCellProps): import("react/jsx-runtime").JSX.Element;
68
+ export declare function TableCell({ lowPriority, numeric, align, nowrap, className, style, ...props }: TableCellProps): import("react/jsx-runtime").JSX.Element;
50
69
  export interface TableEmptyRowProps extends ComponentPropsWithRef<"tr"> {
51
70
  /** Number of columns the empty-state cell spans; set to the table's column count. */
52
71
  colSpan: number;
@@ -2,22 +2,22 @@ import { cn as e } from "../../lib/cn.js";
2
2
  import { jsx as t, jsxs as n } from "react/jsx-runtime";
3
3
  import { ArrowDown as r, ArrowUp as i, ArrowUpDown as a } from "lucide-react";
4
4
  //#region src/components/tables/Table.tsx
5
- function o({ caption: r, captionHidden: i = !1, captionClassName: a, stickyHeader: o = !1, maxHeight: s, wrapperClassName: c, wrapperProps: l, beforeTable: u, className: d, children: f, ...p }) {
5
+ function o({ appearance: r = "framed", compact: i = !1, striped: a = !1, headerAppearance: o = "default", caption: s, captionHidden: c = !1, captionClassName: l, stickyHeader: u = !1, maxHeight: d, wrapperClassName: f, wrapperProps: p, beforeTable: m, className: h, children: g, ..._ }) {
6
6
  return /* @__PURE__ */ n("div", {
7
- ...l,
8
- className: e("ui-table-wrap", l?.className, c),
7
+ ...p,
8
+ className: e("ui-table-wrap", r === "embedded" && "ui-table-wrap-embedded", p?.className, f),
9
9
  style: {
10
- maxHeight: s,
11
- ...s ? { overflow: "auto" } : {},
12
- ...l?.style
10
+ maxHeight: d,
11
+ ...d ? { overflow: "auto" } : {},
12
+ ...p?.style
13
13
  },
14
- children: [u, /* @__PURE__ */ n("table", {
15
- ...p,
16
- className: e("ui-table", o && "ui-table-sticky", d),
17
- children: [r != null && /* @__PURE__ */ t("caption", {
18
- className: e(i && "sr-only", a),
19
- children: r
20
- }), f]
14
+ children: [m, /* @__PURE__ */ n("table", {
15
+ ..._,
16
+ className: e("ui-table", i && "ui-table-compact", a && "ui-table-striped", o === "band" && "ui-table-header-band", u && "ui-table-sticky", h),
17
+ children: [s != null && /* @__PURE__ */ t("caption", {
18
+ className: e(c && "sr-only", l),
19
+ children: s
20
+ }), g]
21
21
  })]
22
22
  });
23
23
  }
@@ -33,54 +33,60 @@ function c({ className: n, ...r }) {
33
33
  className: e("ui-table-body", n)
34
34
  });
35
35
  }
36
- function l({ selected: n, interactive: r = !1, className: i, ...a }) {
36
+ function l({ className: n, ...r }) {
37
+ return /* @__PURE__ */ t("tfoot", {
38
+ ...r,
39
+ className: e("ui-table-foot", n)
40
+ });
41
+ }
42
+ function u({ selected: n, interactive: r = !1, className: i, ...a }) {
37
43
  return /* @__PURE__ */ t("tr", {
38
44
  ...a,
39
45
  "data-selected": n ? "" : void 0,
40
46
  className: e("ui-table-row", r && "ui-table-interactive", i)
41
47
  });
42
48
  }
43
- function u({ numeric: o = !1, align: s, sort: c, onSort: l, scope: u = "col", className: d, style: f, children: p, ...m }) {
44
- let h = c ?? m["aria-sort"], g = h === "ascending" ? "descending" : "ascending";
49
+ function d({ lowPriority: o = !1, numeric: s = !1, align: c, sort: l, onSort: u, scope: d = "col", className: f, style: p, children: m, ...h }) {
50
+ let g = l ?? h["aria-sort"], _ = g === "ascending" ? "descending" : "ascending";
45
51
  return /* @__PURE__ */ t("th", {
46
- ...m,
47
- scope: u,
48
- "aria-sort": h ?? (l ? "none" : void 0),
49
- className: e("ui-table-header-cell", o && "ui-table-numeric", d),
52
+ ...h,
53
+ scope: d,
54
+ "aria-sort": g ?? (u ? "none" : void 0),
55
+ className: e("ui-table-header-cell", o && "ui-table-low-priority", s && "ui-table-numeric", f),
50
56
  style: {
51
- ...s ? { textAlign: s } : {},
52
- ...f
57
+ ...c ? { textAlign: c } : {},
58
+ ...p
53
59
  },
54
- children: l ? /* @__PURE__ */ n("button", {
60
+ children: u ? /* @__PURE__ */ n("button", {
55
61
  type: "button",
56
62
  className: "ui-table-sort-button",
57
- onClick: () => l(g),
63
+ onClick: () => u(_),
58
64
  children: [
59
- p,
65
+ m,
60
66
  /* @__PURE__ */ n("span", {
61
67
  className: "sr-only",
62
- children: [" Sort ", g]
68
+ children: [" Sort ", _]
63
69
  }),
64
70
  /* @__PURE__ */ t("span", {
65
71
  className: "ui-table-sort-indicator",
66
72
  "aria-hidden": "true",
67
- children: t(h === "ascending" ? i : h === "descending" ? r : a, {})
73
+ children: t(g === "ascending" ? i : g === "descending" ? r : a, {})
68
74
  })
69
75
  ]
70
- }) : p
76
+ }) : m
71
77
  });
72
78
  }
73
- function d({ numeric: n = !1, align: r, nowrap: i = !1, className: a, style: o, ...s }) {
79
+ function f({ lowPriority: n = !1, numeric: r = !1, align: i, nowrap: a = !1, className: o, style: s, ...c }) {
74
80
  return /* @__PURE__ */ t("td", {
75
- ...s,
76
- className: e("ui-table-cell", n && "ui-table-numeric", i && "ui-table-nowrap", a),
81
+ ...c,
82
+ className: e("ui-table-cell", n && "ui-table-low-priority", r && "ui-table-numeric", a && "ui-table-nowrap", o),
77
83
  style: {
78
- ...r ? { textAlign: r } : {},
79
- ...o
84
+ ...i ? { textAlign: i } : {},
85
+ ...s
80
86
  }
81
87
  });
82
88
  }
83
- function f({ colSpan: n, cellClassName: r, children: i, className: a, ...o }) {
89
+ function p({ colSpan: n, cellClassName: r, children: i, className: a, ...o }) {
84
90
  return /* @__PURE__ */ t("tr", {
85
91
  ...o,
86
92
  className: e("ui-table-empty-row", a),
@@ -92,4 +98,4 @@ function f({ colSpan: n, cellClassName: r, children: i, className: a, ...o }) {
92
98
  });
93
99
  }
94
100
  //#endregion
95
- export { o as Table, c as TableBody, d as TableCell, f as TableEmptyRow, s as TableHead, u as TableHeaderCell, l as TableRow };
101
+ export { o as Table, c as TableBody, f as TableCell, p as TableEmptyRow, l as TableFoot, s as TableHead, d as TableHeaderCell, u as TableRow };
@@ -0,0 +1,14 @@
1
+ import type { ComponentPropsWithRef, ReactNode } from "react";
2
+ type AnchorProps = ComponentPropsWithRef<"a"> & {
3
+ href: string;
4
+ };
5
+ export interface ActionLinkProps extends AnchorProps {
6
+ /** Destination for native navigation, including opening in a new tab. */
7
+ href: string;
8
+ /** Inline text link or bordered secondary action. */
9
+ appearance?: "inline" | "secondary";
10
+ /** Render a router anchor, forwarding the supplied attributes, children and ref. */
11
+ renderLink?: (props: AnchorProps) => ReactNode;
12
+ }
13
+ export declare function ActionLink({ appearance, renderLink, className, ...props }: ActionLinkProps): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
14
+ export {};
@@ -0,0 +1,12 @@
1
+ import { cn as e } from "../../lib/cn.js";
2
+ import { jsx as t } from "react/jsx-runtime";
3
+ //#region src/components/ui/ActionLink.tsx
4
+ function n({ appearance: n = "inline", renderLink: r, className: i, ...a }) {
5
+ let o = {
6
+ ...a,
7
+ className: e("focus-visible:outline-accent focus-visible:outline-2 focus-visible:outline-offset-2", n === "secondary" ? "bg-bg-secondary text-text-primary border-border hover:bg-bg-hover inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs font-medium transition-colors duration-[100ms]" : "text-accent-fg underline underline-offset-2", i)
8
+ };
9
+ return r ? r(o) : /* @__PURE__ */ t("a", { ...o });
10
+ }
11
+ //#endregion
12
+ export { n as ActionLink };
@@ -1,7 +1,7 @@
1
1
  import { cn as e } from "../../lib/cn.js";
2
2
  import { mergeRefs as t } from "../../lib/mergeRefs.js";
3
- import { calendarDateFromParts as n, calendarDateParts as r } from "../../lib/calendar.js";
4
- import { MONTHS_LONG as i } from "../../lib/months.js";
3
+ import { MONTHS_LONG as n } from "../../lib/months.js";
4
+ import { calendarDateFromParts as r, calendarDateParts as i } from "../../lib/calendar.js";
5
5
  import { useRef as a, useState as o } from "react";
6
6
  import { jsx as s, jsxs as c } from "react/jsx-runtime";
7
7
  import { ChevronLeft as l, ChevronRight as u } from "lucide-react";
@@ -16,8 +16,8 @@ var d = [
16
16
  "Su"
17
17
  ];
18
18
  function f(e, t, n) {
19
- let i = r(e, n), a = r(t, n);
20
- return i.year === a.year && i.month === a.month && i.day === a.day;
19
+ let r = i(e, n), a = i(t, n);
20
+ return r.year === a.year && r.month === a.month && r.day === a.day;
21
21
  }
22
22
  function p(e, t, n) {
23
23
  if (!t || !n) return !1;
@@ -34,7 +34,7 @@ function h(e, t) {
34
34
  function g({ year: g, month: _, timeZone: v, selected: y, rangeStart: b, rangeEnd: x, hoverDate: S, onSelect: C, onMonthChange: w, onHover: T, minDate: E, maxDate: D, className: O, ref: k, ...A }) {
35
35
  let j = m(g, _), M = h(g, _), N = /* @__PURE__ */ new Date(), P = a(null), [F, I] = o(null);
36
36
  function L() {
37
- return F !== null && F >= 1 && F <= j ? F : y && r(y, v).year === g && r(y, v).month - 1 === _ ? r(y, v).day : b && r(b, v).year === g && r(b, v).month - 1 === _ ? r(b, v).day : r(N, v).year === g && r(N, v).month - 1 === _ ? r(N, v).day : 1;
37
+ return F !== null && F >= 1 && F <= j ? F : y && i(y, v).year === g && i(y, v).month - 1 === _ ? i(y, v).day : b && i(b, v).year === g && i(b, v).month - 1 === _ ? i(b, v).day : i(N, v).year === g && i(N, v).month - 1 === _ ? i(N, v).day : 1;
38
38
  }
39
39
  let R = L();
40
40
  function z(e, t) {
@@ -85,7 +85,7 @@ function g({ year: g, month: _, timeZone: v, selected: y, rangeStart: b, rangeEn
85
85
  className: "text-text-primary text-xs font-semibold",
86
86
  "aria-live": "polite",
87
87
  children: [
88
- i[_],
88
+ n[_],
89
89
  " ",
90
90
  g
91
91
  ]
@@ -103,9 +103,9 @@ function g({ year: g, month: _, timeZone: v, selected: y, rangeStart: b, rangeEn
103
103
  children: [d.map((e) => /* @__PURE__ */ s("div", {
104
104
  className: "text-text-tertiary text-2xs flex h-8 items-center justify-center font-medium",
105
105
  children: e
106
- }, e)), H.map((t, r) => {
107
- if (t === null) return /* @__PURE__ */ s("div", { className: "h-8" }, `empty-${r}`);
108
- let a = n({
106
+ }, e)), H.map((t, i) => {
107
+ if (t === null) return /* @__PURE__ */ s("div", { className: "h-8" }, `empty-${i}`);
108
+ let a = r({
109
109
  year: g,
110
110
  month: _ + 1,
111
111
  day: t,
@@ -119,7 +119,7 @@ function g({ year: g, month: _, timeZone: v, selected: y, rangeStart: b, rangeEn
119
119
  "data-day": t,
120
120
  disabled: !!m,
121
121
  tabIndex: t === R ? 0 : -1,
122
- "aria-label": `${i[_]} ${t}, ${g}`,
122
+ "aria-label": `${n[_]} ${t}, ${g}`,
123
123
  "aria-current": o ? "date" : void 0,
124
124
  onClick: () => C(a),
125
125
  onKeyDown: (e) => z(e, t),
@@ -13,7 +13,7 @@ export interface DatePickerProps extends Omit<ComponentPropsWithRef<"div">, "chi
13
13
  /** Called with the chosen date. */
14
14
  onValueChange?: (date: Date | null) => void;
15
15
  placeholder?: string;
16
- /** Format function for display. Defaults to "MMM D, YYYY". */
16
+ /** Formats the trigger date. Defaults to en-GB, e.g. "25 Oct 2026". */
17
17
  format?: (date: Date) => string;
18
18
  }
19
19
  export declare function DatePicker({ controlSize, label, timeZone, value: valueProp, defaultValue, onValueChange, placeholder, format, ref, ...rest }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
@@ -3,19 +3,14 @@ import { mergeRefs as t } from "../../lib/mergeRefs.js";
3
3
  import { useControlSize as n } from "../../providers/ControlSizeContext.js";
4
4
  import { useControllableState as r } from "../../hooks/useControllableState.js";
5
5
  import { usePopover as i } from "../../hooks/usePopover.js";
6
- import { calendarDateParts as a } from "../../lib/calendar.js";
7
- import { MONTHS_SHORT as o } from "../../lib/months.js";
6
+ import { calendarDateParts as a, formatPickerDate as o } from "../../lib/calendar.js";
8
7
  import { CalendarGrid as s } from "./CalendarGrid.js";
9
8
  import { useMemo as c, useState as l } from "react";
10
9
  import { jsx as u, jsxs as d } from "react/jsx-runtime";
11
10
  import { Calendar as f } from "lucide-react";
12
11
  //#region src/components/ui/DatePicker.tsx
13
- function p(e, t) {
14
- let { year: n, month: r, day: i } = a(e, t);
15
- return `${o[r - 1]} ${i}, ${n}`;
16
- }
17
- function m({ controlSize: o, label: m, timeZone: h, value: g, defaultValue: _ = null, onValueChange: v, placeholder: y = "Select date...", format: b, ref: x, ...S }) {
18
- let C = n(o), [w, T] = r({
12
+ function p({ controlSize: p, label: m, timeZone: h, value: g, defaultValue: _ = null, onValueChange: v, placeholder: y = "Select date...", format: b, ref: x, ...S }) {
13
+ let C = n(p), [w, T] = r({
19
14
  value: g,
20
15
  defaultValue: _,
21
16
  onChange: v
@@ -53,7 +48,7 @@ function m({ controlSize: o, label: m, timeZone: h, value: g, defaultValue: _ =
53
48
  onClick: H,
54
49
  "data-control-size": C,
55
50
  className: e("ui-sized-control flex h-7 w-full cursor-pointer items-center rounded-md text-xs", "bg-bg-secondary border-border text-text-primary border", "hover:bg-bg-hover hover:border-border-strong", "transition-colors duration-[100ms]", "px-2 pr-7"),
56
- children: w ? b ? b(w) : p(w, h) : /* @__PURE__ */ u("span", {
51
+ children: w ? b ? b(w) : o(w, h) : /* @__PURE__ */ u("span", {
57
52
  className: "text-text-placeholder",
58
53
  children: y
59
54
  })
@@ -81,4 +76,4 @@ function m({ controlSize: o, label: m, timeZone: h, value: g, defaultValue: _ =
81
76
  });
82
77
  }
83
78
  //#endregion
84
- export { m as DatePicker };
79
+ export { p as DatePicker };
@@ -17,5 +17,7 @@ export interface DateRangePickerProps extends Omit<ComponentPropsWithRef<"div">,
17
17
  onValueChange?: (range: DateRange) => void;
18
18
  /** Text shown when no range is selected. Defaults to "Select date range...". */
19
19
  placeholder?: string;
20
+ /** Formats each date in the trigger. Defaults to en-GB, e.g. "25 Oct 2026". */
21
+ format?: (date: Date) => string;
20
22
  }
21
- export declare function DateRangePicker({ controlSize, label, value: valueProp, defaultValue, onValueChange, placeholder, ref, className, ...rest }: DateRangePickerProps): import("react/jsx-runtime").JSX.Element;
23
+ export declare function DateRangePicker({ controlSize, label, value: valueProp, defaultValue, onValueChange, placeholder, format, ref, className, ...rest }: DateRangePickerProps): import("react/jsx-runtime").JSX.Element;
@@ -3,135 +3,160 @@ import { mergeRefs as t } from "../../lib/mergeRefs.js";
3
3
  import { useControlSize as n } from "../../providers/ControlSizeContext.js";
4
4
  import { useControllableState as r } from "../../hooks/useControllableState.js";
5
5
  import { usePopover as i } from "../../hooks/usePopover.js";
6
- import { MONTHS_SHORT as a } from "../../lib/months.js";
6
+ import { formatPickerDate as a } from "../../lib/calendar.js";
7
7
  import { CalendarGrid as o } from "./CalendarGrid.js";
8
- import { useMemo as s, useState as c } from "react";
9
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
10
- import { Calendar as d } from "lucide-react";
8
+ import { useLayoutEffect as s, useMemo as c, useRef as l, useState as u } from "react";
9
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
10
+ import { Calendar as p } from "lucide-react";
11
11
  //#region src/components/ui/DateRangePicker.tsx
12
- function f(e) {
13
- return `${a[e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`;
14
- }
15
- function p(e) {
16
- return e.start && e.end ? `${f(e.start)} – ${f(e.end)}` : e.start ? f(e.start) : "";
17
- }
18
- var m = {
12
+ var ee = {
19
13
  start: null,
20
14
  end: null
21
15
  };
22
- function h({ controlSize: a, label: f, value: h, defaultValue: g = m, onValueChange: _, placeholder: v = "Select date range...", ref: y, className: b, ...x }) {
23
- let S = n(a), [C, w] = r({
24
- value: h,
25
- defaultValue: g,
26
- onChange: _
27
- }), { open: T, show: E, close: D, rootRef: O, anchorRef: k, triggerRef: A, popupRef: j, labelId: M, popupId: N, triggerAria: P } = i({
16
+ function m({ controlSize: m, label: h, value: g, defaultValue: _ = ee, onValueChange: v, placeholder: y = "Select date range...", format: b = a, ref: x, className: te, ...ne }) {
17
+ let re = n(m), [S, ie] = r({
18
+ value: g,
19
+ defaultValue: _,
20
+ onChange: v
21
+ }), { open: C, show: ae, close: w, rootRef: T, anchorRef: oe, triggerRef: E, popupRef: D, labelId: O, popupId: k, triggerAria: A } = i({
28
22
  haspopup: "dialog",
29
- labelled: !!f
30
- }), F = s(() => t(y, O), [y, O]), I = /* @__PURE__ */ new Date(), [L, R] = c(C.start?.getFullYear() ?? I.getFullYear()), [z, B] = c(C.start?.getMonth() ?? I.getMonth()), [V, H] = c(null), [U, W] = c("start"), [G, K] = c(C.start), [q, J] = c(C.end), Y = z === 11 ? L + 1 : L, X = z === 11 ? 0 : z + 1;
31
- function Z() {
32
- if (T) {
33
- D("toggle");
23
+ labelled: !!h
24
+ }), j = c(() => t(x, T), [x, T]), M = l(null), N = l(null), [P, F] = u(!0), I = /* @__PURE__ */ new Date(), [L, R] = u(S.start?.getFullYear() ?? I.getFullYear()), [z, B] = u(S.start?.getMonth() ?? I.getMonth()), V = z === 11 ? L + 1 : L, H = z === 11 ? 0 : z + 1;
25
+ s(() => {
26
+ let e = D.current, t = M.current, n = t?.parentElement, r = e?.ownerDocument.defaultView;
27
+ if (!C || !e || !t || !n || !r) return;
28
+ let i = e.ownerDocument, a = () => {
29
+ let a = parseFloat(r.getComputedStyle(n).columnGap), o = e.offsetWidth - n.offsetWidth, s = 2 * t.offsetWidth + a + o + 16 > i.documentElement.clientWidth, c = i.activeElement;
30
+ if (s && e.contains(c) && !t.contains(c)) {
31
+ let e = c?.getAttribute("data-day");
32
+ if (e) N.current = e, R(V), B(H);
33
+ else {
34
+ let e = c?.getAttribute("aria-label");
35
+ Array.from(t.querySelectorAll("button")).find((t) => t.getAttribute("aria-label") === e)?.focus({ preventScroll: !0 });
36
+ }
37
+ }
38
+ F(s);
39
+ }, o = typeof ResizeObserver > "u" ? null : new ResizeObserver(a);
40
+ o?.observe(e);
41
+ let s = o ? 0 : r.requestAnimationFrame(a);
42
+ return r.addEventListener("resize", a), () => {
43
+ o?.disconnect(), r.cancelAnimationFrame(s), r.removeEventListener("resize", a);
44
+ };
45
+ }, [
46
+ C,
47
+ D,
48
+ H,
49
+ V
50
+ ]), s(() => {
51
+ let e = N.current;
52
+ !P || !e || (N.current = null, M.current?.querySelector(`[data-day="${e}"]`)?.focus({ preventScroll: !0 }));
53
+ }, [P]);
54
+ let [U, W] = u(null), [G, K] = u("start"), [q, J] = u(S.start), [Y, X] = u(S.end);
55
+ function se() {
56
+ if (C) {
57
+ w("toggle");
34
58
  return;
35
59
  }
36
- K(C.start), J(C.end), W("start"), C.start && (R(C.start.getFullYear()), B(C.start.getMonth())), E();
60
+ J(S.start), X(S.end), K("start"), F(!0), S.start && (R(S.start.getFullYear()), B(S.start.getMonth())), ae();
37
61
  }
38
- function Q(e) {
39
- U === "start" ? (K(e), J(null), W("end")) : (G && e < G ? (J(G), K(e)) : J(e), W("start"), w({
40
- start: G && e < G ? e : G,
41
- end: G && e < G ? G : e
42
- }), D("select"));
62
+ function Z(e) {
63
+ G === "start" ? (J(e), X(null), K("end")) : (q && e < q ? (X(q), J(e)) : X(e), K("start"), ie({
64
+ start: q && e < q ? e : q,
65
+ end: q && e < q ? q : e
66
+ }), w("select"));
43
67
  }
44
- function $() {
68
+ function ce() {
45
69
  z === 0 ? (R(L - 1), B(11)) : B(z - 1);
46
70
  }
47
- function ee() {
71
+ function le() {
48
72
  z === 11 ? (R(L + 1), B(0)) : B(z + 1);
49
73
  }
50
- let te = C.start || C.end ? p(C) : "";
51
- return /* @__PURE__ */ u("div", {
52
- ...x,
53
- ref: F,
54
- className: e("flex flex-col gap-1.5", b),
55
- children: [f && /* @__PURE__ */ l("span", {
56
- id: M,
74
+ let { start: Q, end: $ } = S;
75
+ return /* @__PURE__ */ f("div", {
76
+ ...ne,
77
+ ref: j,
78
+ className: e("flex flex-col gap-1.5", te),
79
+ children: [h && /* @__PURE__ */ d("span", {
80
+ id: O,
57
81
  className: "ui-field-label text-xs font-medium",
58
- children: f
59
- }), /* @__PURE__ */ u("div", {
82
+ children: h
83
+ }), /* @__PURE__ */ f("div", {
60
84
  className: "relative",
61
- ref: k,
85
+ ref: oe,
62
86
  children: [
63
- /* @__PURE__ */ l("button", {
87
+ /* @__PURE__ */ d("button", {
64
88
  type: "button",
65
- ref: A,
66
- ...P,
67
- onClick: Z,
68
- "data-control-size": S,
89
+ ref: E,
90
+ ...A,
91
+ onClick: se,
92
+ "data-control-size": re,
69
93
  className: e("ui-sized-control flex h-7 w-full cursor-pointer items-center rounded-md text-xs", "bg-bg-secondary border-border text-text-primary border", "hover:bg-bg-hover hover:border-border-strong", "transition-colors duration-[100ms]", "px-2 pr-7"),
70
- children: te || /* @__PURE__ */ l("span", {
94
+ children: Q ? $ ? `${b(Q)} – ${b($)}` : b(Q) : /* @__PURE__ */ d("span", {
71
95
  className: "text-text-placeholder",
72
- children: v
96
+ children: y
73
97
  })
74
98
  }),
75
- /* @__PURE__ */ l(d, { className: "text-text-tertiary pointer-events-none absolute top-1/2 right-2 h-3 w-3 -translate-y-1/2" }),
76
- T && /* @__PURE__ */ u("div", {
77
- ref: j,
78
- id: N,
99
+ /* @__PURE__ */ d(p, { className: "text-text-tertiary pointer-events-none absolute top-1/2 right-2 h-3 w-3 -translate-y-1/2" }),
100
+ C && /* @__PURE__ */ f("div", {
101
+ ref: D,
102
+ id: k,
79
103
  role: "dialog",
80
104
  "aria-label": "Choose date range",
81
105
  className: e("ui-glass ui-glass-popover bg-bg-tertiary border-border-strong animate-scale-in fixed top-0 left-0 z-[100] rounded-md border shadow-lg", "p-3"),
82
- children: [/* @__PURE__ */ u("div", {
106
+ children: [/* @__PURE__ */ f("div", {
83
107
  className: "mb-2 flex items-center justify-between",
84
108
  children: [
85
- /* @__PURE__ */ l("button", {
109
+ /* @__PURE__ */ d("button", {
86
110
  type: "button",
87
- onClick: $,
111
+ onClick: ce,
88
112
  "aria-label": "Previous month",
89
- className: "text-text-tertiary hover:text-text-primary hover:bg-bg-hover flex h-6 w-6 cursor-pointer items-center justify-center rounded-md transition-colors duration-[100ms]",
90
- children: /* @__PURE__ */ l("span", {
113
+ className: e("text-text-tertiary hover:text-text-primary hover:bg-bg-hover h-6 w-6 cursor-pointer items-center justify-center rounded-md transition-colors duration-[100ms]", P ? "hidden" : "flex"),
114
+ children: /* @__PURE__ */ d("span", {
91
115
  className: "text-xs",
92
116
  children: "‹"
93
117
  })
94
118
  }),
95
- /* @__PURE__ */ l("span", {
96
- className: "text-text-tertiary text-2xs",
119
+ /* @__PURE__ */ d("span", {
120
+ className: "text-text-tertiary text-2xs flex-1 text-center",
97
121
  "aria-live": "polite",
98
- children: U === "start" ? "Select start date" : "Select end date"
122
+ children: G === "start" ? "Select start date" : "Select end date"
99
123
  }),
100
- /* @__PURE__ */ l("button", {
124
+ /* @__PURE__ */ d("button", {
101
125
  type: "button",
102
- onClick: ee,
126
+ onClick: le,
103
127
  "aria-label": "Next month",
104
- className: "text-text-tertiary hover:text-text-primary hover:bg-bg-hover flex h-6 w-6 cursor-pointer items-center justify-center rounded-md transition-colors duration-[100ms]",
105
- children: /* @__PURE__ */ l("span", {
128
+ className: e("text-text-tertiary hover:text-text-primary hover:bg-bg-hover h-6 w-6 cursor-pointer items-center justify-center rounded-md transition-colors duration-[100ms]", P ? "hidden" : "flex"),
129
+ children: /* @__PURE__ */ d("span", {
106
130
  className: "text-xs",
107
131
  children: "›"
108
132
  })
109
133
  })
110
134
  ]
111
- }), /* @__PURE__ */ u("div", {
112
- className: "flex gap-4",
113
- children: [/* @__PURE__ */ l(o, {
135
+ }), /* @__PURE__ */ f("div", {
136
+ className: "flex w-max gap-4",
137
+ children: [/* @__PURE__ */ d(o, {
138
+ ref: M,
114
139
  year: L,
115
140
  month: z,
116
- rangeStart: G,
117
- rangeEnd: q,
118
- hoverDate: U === "end" ? V : null,
119
- onSelect: Q,
141
+ rangeStart: q,
142
+ rangeEnd: Y,
143
+ hoverDate: G === "end" ? U : null,
144
+ onSelect: Z,
120
145
  onMonthChange: (e, t) => {
121
146
  R(e), B(t);
122
147
  },
123
- onHover: H
124
- }), /* @__PURE__ */ l(o, {
125
- year: Y,
126
- month: X,
127
- rangeStart: G,
128
- rangeEnd: q,
129
- hoverDate: U === "end" ? V : null,
130
- onSelect: Q,
148
+ onHover: W
149
+ }), !P && /* @__PURE__ */ d(o, {
150
+ year: V,
151
+ month: H,
152
+ rangeStart: q,
153
+ rangeEnd: Y,
154
+ hoverDate: G === "end" ? U : null,
155
+ onSelect: Z,
131
156
  onMonthChange: (e, t) => {
132
157
  t === 0 ? (R(e - 1), B(11)) : (R(e), B(t - 1));
133
158
  },
134
- onHover: H
159
+ onHover: W
135
160
  })]
136
161
  })]
137
162
  })
@@ -140,4 +165,4 @@ function h({ controlSize: a, label: f, value: h, defaultValue: g = m, onValueCha
140
165
  });
141
166
  }
142
167
  //#endregion
143
- export { h as DateRangePicker };
168
+ export { m as DateRangePicker };