@leonardaustin/ui 0.27.0 → 0.29.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 (56) hide show
  1. package/dist/components/charts/AreaChart.js +113 -114
  2. package/dist/components/charts/BarChart.d.ts +4 -2
  3. package/dist/components/charts/BarChart.js +69 -49
  4. package/dist/components/charts/Heatmap.d.ts +20 -0
  5. package/dist/components/charts/Heatmap.js +46 -0
  6. package/dist/components/charts/StackedBarChart.d.ts +3 -1
  7. package/dist/components/charts/StackedBarChart.js +103 -95
  8. package/dist/components/charts/VerticalBarChart.d.ts +3 -1
  9. package/dist/components/charts/VerticalBarChart.js +94 -83
  10. package/dist/components/charts/barChartUtils.d.ts +16 -0
  11. package/dist/components/charts/barChartUtils.js +24 -0
  12. package/dist/components/charts/chartUtils.d.ts +2 -0
  13. package/dist/components/charts/chartUtils.js +14 -9
  14. package/dist/components/charts/useChartSize.d.ts +13 -0
  15. package/dist/components/charts/useChartSize.js +27 -0
  16. package/dist/components/tables/Pagination.d.ts +3 -1
  17. package/dist/components/tables/Pagination.js +12 -12
  18. package/dist/components/tables/ResourceTable.d.ts +5 -0
  19. package/dist/components/tables/ResourceTable.js +11 -9
  20. package/dist/components/tables/Table.d.ts +22 -3
  21. package/dist/components/tables/Table.js +41 -35
  22. package/dist/components/ui/ActionLink.d.ts +14 -0
  23. package/dist/components/ui/ActionLink.js +12 -0
  24. package/dist/components/ui/DateRangePicker.js +107 -76
  25. package/dist/components/ui/EmptyState.d.ts +8 -6
  26. package/dist/components/ui/EmptyState.js +11 -10
  27. package/dist/components/ui/ErrorBoundary.d.ts +6 -0
  28. package/dist/components/ui/ErrorBoundary.js +11 -5
  29. package/dist/components/ui/Grid.d.ts +1 -1
  30. package/dist/components/ui/Icon.d.ts +91 -0
  31. package/dist/components/ui/Icon.js +98 -0
  32. package/dist/components/ui/Inline.d.ts +1 -1
  33. package/dist/components/ui/LoadingSpinner.d.ts +7 -3
  34. package/dist/components/ui/LoadingSpinner.js +19 -11
  35. package/dist/components/ui/MainAsideLayout.d.ts +10 -0
  36. package/dist/components/ui/MainAsideLayout.js +18 -0
  37. package/dist/components/ui/Meter.d.ts +11 -0
  38. package/dist/components/ui/Meter.js +7 -0
  39. package/dist/components/ui/MetricCard.d.ts +11 -8
  40. package/dist/components/ui/MetricCard.js +18 -15
  41. package/dist/components/ui/PaginationBar.d.ts +3 -3
  42. package/dist/components/ui/PaginationBar.js +35 -33
  43. package/dist/components/ui/SideSheet.d.ts +4 -2
  44. package/dist/components/ui/SideSheet.js +64 -52
  45. package/dist/components/ui/Stack.d.ts +1 -1
  46. package/dist/components/ui/Tabs.d.ts +5 -1
  47. package/dist/components/ui/Tabs.js +23 -21
  48. package/dist/components/ui/Text.d.ts +19 -0
  49. package/dist/components/ui/Text.js +20 -0
  50. package/dist/components/ui/Toolbar.js +13 -13
  51. package/dist/core.css +122 -0
  52. package/dist/hooks/useFocusTrap.js +1 -1
  53. package/dist/index.d.ts +6 -0
  54. package/dist/index.js +135 -129
  55. package/dist/styles.css +123 -0
  56. package/package.json +1 -1
@@ -1,211 +1,210 @@
1
1
  import { cn as e } from "../../lib/cn.js";
2
2
  import { mergeRefs as t } from "../../lib/mergeRefs.js";
3
- import { estimateTooltipWidth as n, formatCompactValue as r, getLabelIndices as i, getSvgTooltipPosition as a } from "./chartUtils.js";
4
- import { useId as o, useMemo as s, useRef as c, useState as l } from "react";
5
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
3
+ import { estimateTextWidth as n, estimateTooltipWidth as r, formatCompactValue as i, getFittingLabelCount as a, getLabelIndices as o, getSvgTooltipPosition as ee } from "./chartUtils.js";
4
+ import { useChartSize as s } from "./useChartSize.js";
5
+ import { useId as c, useMemo as l, useRef as u, useState as d } from "react";
6
+ import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
6
7
  //#region src/components/charts/AreaChart.tsx
7
- var p = {
8
+ var h = {
8
9
  top: 16,
9
10
  right: 12,
10
11
  bottom: 28,
11
12
  left: 48
12
- }, m = 600;
13
- function h(e) {
13
+ }, te = 600;
14
+ function g(e) {
14
15
  return e === 0 ? 1 : Math.max(Math.abs(e) * .02, 1);
15
16
  }
16
- function g({ data: g, height: _ = 240, minValue: v, maxValue: y, startAtZero: b = !1, valueFormatter: x, tooltipValueFormatter: S, xLabelCount: C = 5, "aria-label": w = "Area chart", className: T, onPointerMove: E, onPointerLeave: D, ref: O, ...k }) {
17
- let A = o(), j = c(null), M = s(() => t(j, O), [O]), [N, P] = l(null), F = Math.max(p.top + p.bottom + 1, _), I = m - p.left - p.right, L = Math.max(1, F - p.top - p.bottom), R = g.length > 0, z = g[0]?.value ?? 0, B = g[0]?.value ?? 0;
18
- for (let e of g) e.value < z && (z = e.value), e.value > B && (B = e.value);
19
- let V = v ?? z, H = y ?? B;
20
- if (b && v === void 0 && z >= 0 && (V = 0), V === H) {
17
+ function _({ data: _, height: ne = 240, minValue: v, maxValue: y, startAtZero: b = !1, valueFormatter: x, tooltipValueFormatter: re, xLabelCount: S = 5, "aria-label": C = "Area chart", className: w, onPointerMove: ie, onPointerLeave: ae, ref: T, ...oe }) {
18
+ let E = c(), D = u(null), O = l(() => t(D, T), [T]), [k, A] = d(null), j = s(D), M = j?.width ?? te, N = Math.max(h.top + h.bottom + 1, ne), P = j?.height ?? N, F = (e, t) => j && e && S > 0 ? Math.max(t, n(e) / 2 + 4) : t, I = F(_[0]?.date, h.left), L = F(_.at(-1)?.date, h.right), R = Math.max(1, M - I - L), z = Math.max(1, P - h.top - h.bottom), B = _.length > 0, V = _[0]?.value ?? 0, H = _[0]?.value ?? 0;
19
+ for (let e of _) e.value < V && (V = e.value), e.value > H && (H = e.value);
20
+ let U = v ?? V, W = y ?? H;
21
+ if (b && v === void 0 && V >= 0 && (U = 0), U === W) {
21
22
  if (b || v !== void 0 || y !== void 0) {
22
- let e = h(B);
23
- v === void 0 && (V = b && z >= 0 ? 0 : z >= 0 ? Math.max(0, z - e) : z - e), y === void 0 && (H = B + e);
23
+ let e = g(H);
24
+ v === void 0 && (U = b && V >= 0 ? 0 : V >= 0 ? Math.max(0, V - e) : V - e), y === void 0 && (W = H + e);
24
25
  }
25
- V === H && (H = V + 1);
26
+ U === W && (W = U + 1);
26
27
  }
27
- let U = H - V, W = x ?? r, G = S ?? x ?? ((e) => e.toLocaleString());
28
- function K(e) {
29
- return p.left + e / Math.max(g.length - 1, 1) * I;
28
+ let G = W - U, K = x ?? i, q = re ?? x ?? ((e) => e.toLocaleString());
29
+ function J(e) {
30
+ return I + e / Math.max(_.length - 1, 1) * R;
30
31
  }
31
- function q(e) {
32
- return p.top + L - (e - V) / U * L;
32
+ function Y(e) {
33
+ return h.top + z - (e - U) / G * z;
33
34
  }
34
- let J = g.map((e, t) => `${K(t)},${q(e.value)}`).join(" "), Y = R ? [
35
- `${K(0)},${p.top + L}`,
36
- ...g.map((e, t) => `${K(t)},${q(e.value)}`),
37
- `${K(g.length - 1)},${p.top + L}`
38
- ].join(" ") : "", X = i(g.length, C);
39
- function Z(e) {
40
- let t = j.current;
41
- if (!t || g.length === 0) return;
42
- let n = t.getBoundingClientRect();
43
- if (n.width <= 0) return;
44
- let r = ((e.clientX - n.left) / n.width * m - p.left) / I, i = Math.round(r * (g.length - 1)), a = Math.max(0, Math.min(g.length - 1, i));
45
- P({
46
- x: K(a),
47
- y: q(g[a].value),
48
- index: a
49
- });
50
- }
51
- function Q(e) {
52
- P({
53
- x: K(e),
54
- y: q(g[e].value),
55
- index: e
56
- });
35
+ let se = _.map((e, t) => `${J(t)},${Y(e.value)}`).join(" "), ce = B ? [
36
+ `${J(0)},${h.top + z}`,
37
+ ..._.map((e, t) => `${J(t)},${Y(e.value)}`),
38
+ `${J(_.length - 1)},${h.top + z}`
39
+ ].join(" ") : "", X = l(() => _.reduce((e, { date: t }) => Math.max(e, n(t)), 0), [_]), le = j ? Math.min(S, a(_.length, R, X)) : S, ue = o(_.length, le), Z = k === null ? void 0 : _[k], Q = Z && k !== null ? {
40
+ x: J(k),
41
+ y: Y(Z.value)
42
+ } : null;
43
+ function de(e) {
44
+ let t = D.current;
45
+ if (!t || _.length === 0) return;
46
+ let n = t.getScreenCTM(), r;
47
+ if (n) {
48
+ let i = t.createSVGPoint();
49
+ i.x = e.clientX, i.y = e.clientY, r = i.matrixTransform(n.inverse()).x;
50
+ } else {
51
+ let n = t.getBoundingClientRect();
52
+ if (n.width <= 0) return;
53
+ r = (e.clientX - n.left) / n.width * M;
54
+ }
55
+ let i = (r - I) / R, a = Math.round(i * (_.length - 1));
56
+ A(Math.max(0, Math.min(_.length - 1, a)));
57
57
  }
58
58
  function $() {
59
- P(null);
59
+ A(null);
60
60
  }
61
- return /* @__PURE__ */ f("svg", {
62
- ...k,
63
- ref: M,
61
+ return /* @__PURE__ */ m("svg", {
62
+ ...oe,
63
+ ref: O,
64
64
  width: "100%",
65
- viewBox: `0 0 ${m} ${F}`,
65
+ height: N,
66
+ viewBox: `0 0 ${M} ${P}`,
66
67
  onPointerMove: (e) => {
67
- E?.(e), !e.defaultPrevented && Z(e);
68
+ ie?.(e), !e.defaultPrevented && de(e);
68
69
  },
69
70
  onPointerLeave: (e) => {
70
- D?.(e), !e.defaultPrevented && $();
71
+ ae?.(e), !e.defaultPrevented && $();
71
72
  },
72
- className: e("select-none", T),
73
+ className: e("select-none", w),
73
74
  role: "img",
74
- "aria-label": w,
75
+ "aria-label": C,
75
76
  children: [
76
- /* @__PURE__ */ d("defs", { children: /* @__PURE__ */ f("linearGradient", {
77
- id: A,
77
+ /* @__PURE__ */ p("defs", { children: /* @__PURE__ */ m("linearGradient", {
78
+ id: E,
78
79
  x1: "0",
79
80
  y1: "0",
80
81
  x2: "0",
81
82
  y2: "1",
82
- children: [/* @__PURE__ */ d("stop", {
83
+ children: [/* @__PURE__ */ p("stop", {
83
84
  offset: "0%",
84
85
  stopColor: "var(--accent)",
85
86
  stopOpacity: .3
86
- }), /* @__PURE__ */ d("stop", {
87
+ }), /* @__PURE__ */ p("stop", {
87
88
  offset: "100%",
88
89
  stopColor: "var(--accent)",
89
90
  stopOpacity: 0
90
91
  })]
91
92
  }) }),
92
- /* @__PURE__ */ d("text", {
93
- x: p.left - 8,
94
- y: p.top,
93
+ /* @__PURE__ */ p("text", {
94
+ x: I - 8,
95
+ y: h.top,
95
96
  textAnchor: "end",
96
97
  dominantBaseline: "central",
97
98
  fill: "var(--text-tertiary)",
98
99
  fontSize: 10,
99
- children: W(H)
100
+ children: K(W)
100
101
  }),
101
- /* @__PURE__ */ d("text", {
102
- x: p.left - 8,
103
- y: p.top + L,
102
+ /* @__PURE__ */ p("text", {
103
+ x: I - 8,
104
+ y: h.top + z,
104
105
  textAnchor: "end",
105
106
  dominantBaseline: "central",
106
107
  fill: "var(--text-tertiary)",
107
108
  fontSize: 10,
108
- children: W(V)
109
+ children: K(U)
109
110
  }),
110
- /* @__PURE__ */ d("line", {
111
- x1: p.left,
112
- y1: p.top + L,
113
- x2: p.left + I,
114
- y2: p.top + L,
111
+ /* @__PURE__ */ p("line", {
112
+ x1: I,
113
+ y1: h.top + z,
114
+ x2: I + R,
115
+ y2: h.top + z,
115
116
  stroke: "var(--border)",
116
117
  strokeWidth: 1
117
118
  }),
118
- R && /* @__PURE__ */ d("polygon", {
119
- points: Y,
120
- fill: `url(#${A})`
119
+ B && /* @__PURE__ */ p("polygon", {
120
+ points: ce,
121
+ fill: `url(#${E})`
121
122
  }),
122
- R && /* @__PURE__ */ d("polyline", {
123
- points: J,
123
+ B && /* @__PURE__ */ p("polyline", {
124
+ points: se,
124
125
  fill: "none",
125
126
  stroke: "var(--accent)",
126
127
  strokeWidth: 2,
127
128
  strokeLinecap: "round",
128
129
  strokeLinejoin: "round"
129
130
  }),
130
- g.map((e, t) => /* @__PURE__ */ d("circle", {
131
- cx: K(t),
132
- cy: q(e.value),
131
+ _.map((e, t) => /* @__PURE__ */ p("circle", {
132
+ cx: J(t),
133
+ cy: Y(e.value),
133
134
  r: 8,
134
135
  fill: "transparent",
135
136
  tabIndex: 0,
136
137
  role: "button",
137
- "aria-label": `${e.date}: ${G(e.value)}`,
138
- onFocus: () => Q(t),
138
+ "aria-label": `${e.date}: ${q(e.value)}`,
139
+ onFocus: () => A(t),
139
140
  onBlur: $
140
141
  }, `${e.date}-${t}-hit`)),
141
- X.map((e) => /* @__PURE__ */ d("text", {
142
- x: K(e),
143
- y: F - 4,
142
+ ue.map((e) => /* @__PURE__ */ p("text", {
143
+ x: J(e),
144
+ y: P - 4,
144
145
  textAnchor: "middle",
145
146
  fill: "var(--text-tertiary)",
146
147
  fontSize: 10,
147
- children: g[e].date
148
- }, `${g[e].date}-${e}`)),
149
- N && /* @__PURE__ */ f(u, { children: [
150
- /* @__PURE__ */ d("line", {
151
- x1: N.x,
152
- y1: p.top,
153
- x2: N.x,
154
- y2: p.top + L,
148
+ children: _[e].date
149
+ }, `${_[e].date}-${e}`)),
150
+ Q && Z && /* @__PURE__ */ m(f, { children: [
151
+ /* @__PURE__ */ p("line", {
152
+ x1: Q.x,
153
+ y1: h.top,
154
+ x2: Q.x,
155
+ y2: h.top + z,
155
156
  stroke: "var(--border-strong)",
156
157
  strokeWidth: 1,
157
158
  strokeDasharray: "3 3"
158
159
  }),
159
- /* @__PURE__ */ d("circle", {
160
- cx: N.x,
161
- cy: N.y,
160
+ /* @__PURE__ */ p("circle", {
161
+ cx: Q.x,
162
+ cy: Q.y,
162
163
  r: 4,
163
164
  fill: "var(--accent)",
164
165
  stroke: "var(--bg-secondary)",
165
166
  strokeWidth: 2
166
167
  }),
167
168
  (() => {
168
- let e = g[N.index];
169
- if (!e) return null;
170
- let t = e.date, r = G(e.value), i = a(N.x, N.y, {
171
- boundsHeight: F,
172
- boundsWidth: m,
169
+ let e = Z.date, t = q(Z.value), n = ee(Q.x, Q.y, {
170
+ boundsHeight: P,
171
+ boundsWidth: M,
173
172
  height: 28,
174
173
  offset: 10,
175
- width: n([t, r], {
174
+ width: r([e, t], {
176
175
  maxWidth: 180,
177
176
  minWidth: 90
178
177
  })
179
- }), o = i.x + i.width / 2;
180
- return /* @__PURE__ */ f(u, { children: [
181
- /* @__PURE__ */ d("rect", {
182
- x: i.x,
183
- y: i.y,
184
- width: i.width,
185
- height: i.height,
178
+ }), i = n.x + n.width / 2;
179
+ return /* @__PURE__ */ m(f, { children: [
180
+ /* @__PURE__ */ p("rect", {
181
+ x: n.x,
182
+ y: n.y,
183
+ width: n.width,
184
+ height: n.height,
186
185
  rx: 4,
187
186
  fill: "var(--bg-tooltip, var(--bg-tertiary))",
188
187
  stroke: "var(--border)",
189
188
  strokeWidth: 1
190
189
  }),
191
- /* @__PURE__ */ d("text", {
192
- x: o,
193
- y: i.y + 10,
190
+ /* @__PURE__ */ p("text", {
191
+ x: i,
192
+ y: n.y + 10,
194
193
  textAnchor: "middle",
195
194
  dominantBaseline: "central",
196
195
  fill: "var(--text-secondary)",
197
196
  fontSize: 9,
198
- children: t
197
+ children: e
199
198
  }),
200
- /* @__PURE__ */ d("text", {
201
- x: o,
202
- y: i.y + 22,
199
+ /* @__PURE__ */ p("text", {
200
+ x: i,
201
+ y: n.y + 22,
203
202
  textAnchor: "middle",
204
203
  dominantBaseline: "central",
205
204
  fill: "var(--text-primary)",
206
205
  fontSize: 11,
207
206
  fontWeight: 600,
208
- children: r
207
+ children: t
209
208
  })
210
209
  ] });
211
210
  })()
@@ -214,4 +213,4 @@ function g({ data: g, height: _ = 240, minValue: v, maxValue: y, startAtZero: b
214
213
  });
215
214
  }
216
215
  //#endregion
217
- export { g as AreaChart };
216
+ export { _ as AreaChart };
@@ -6,6 +6,8 @@ export interface BarChartDatum {
6
6
  export interface BarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
7
7
  /** Bars to draw top to bottom, each with a `label` and numeric `value`. */
8
8
  data: BarChartDatum[];
9
+ /** Activate a bar by click, Enter or Space. Receives the original datum and its index in data. */
10
+ onDatumActivate?: (datum: BarChartDatum, index: number) => void;
9
11
  /** Total chart height in SVG units; rows scale to fit. Defaults to the natural height from `barHeight` and `gap`. */
10
12
  height?: number;
11
13
  /** Explicit domain maximum. Defaults to the largest positive value. */
@@ -14,7 +16,7 @@ export interface BarChartProps extends Omit<ComponentPropsWithRef<"svg">, "child
14
16
  valueFormatter?: (value: number) => string;
15
17
  /** Format left-side labels before optional truncation. */
16
18
  labelFormatter?: (label: string, datum: BarChartDatum, index: number) => string;
17
- /** Maximum rendered label length. Omit to render the full formatted label. */
19
+ /** Maximum label length before fitting the text to a scaled label column. */
18
20
  maxLabelLength?: number;
19
21
  /** Width reserved for left-side labels in the SVG viewBox. */
20
22
  labelWidth?: number;
@@ -29,4 +31,4 @@ export interface BarChartProps extends Omit<ComponentPropsWithRef<"svg">, "child
29
31
  /** Extra classes for the `<svg>`. */
30
32
  className?: string;
31
33
  }
32
- export declare function BarChart({ data, height, maxValue, valueFormatter, labelFormatter, maxLabelLength, labelWidth, valueWidth, barHeight, gap, "aria-label": ariaLabel, className, ref, ...rest }: BarChartProps): import("react/jsx-runtime").JSX.Element;
34
+ export declare function BarChart({ data, onDatumActivate, height, maxValue, valueFormatter, labelFormatter, maxLabelLength, labelWidth, valueWidth, barHeight, gap, "aria-label": ariaLabel, className, ref, ...rest }: BarChartProps): import("react/jsx-runtime").JSX.Element;
@@ -1,86 +1,106 @@
1
1
  import { cn as e } from "../../lib/cn.js";
2
2
  import { clamp as t } from "../../lib/math.js";
3
3
  import { getPositiveValue as n, truncateChartLabel as r } from "./chartUtils.js";
4
- import { useState as i } from "react";
5
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
4
+ import { useBarChartSize as i } from "./useChartSize.js";
5
+ import { getBarActivationProps as a } from "./barChartUtils.js";
6
+ import { useState as o } from "react";
7
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
6
8
  //#region src/components/charts/BarChart.tsx
7
- var s = [
9
+ var u = [
8
10
  1,
9
11
  .85,
10
12
  .7,
11
13
  .55,
12
14
  .45
13
- ], c = 600;
14
- function l({ data: l, height: u, maxValue: d, valueFormatter: f, labelFormatter: p, maxLabelLength: m, labelWidth: h = 160, valueWidth: g = 60, barHeight: _ = 28, gap: v = 10, "aria-label": y = "Horizontal bar chart", className: b, ref: x, ...S }) {
15
- let [C, w] = i(null), T = l.length, E = Math.max(1, _), D = Math.max(0, v), O = T > 0 ? T * E + Math.max(0, T - 1) * D : E, k = Math.max(1, u ?? O), A = u === void 0 ? 1 : k / O, j = E * A, M = D * A, N = Math.min(3, j / 3), P = Math.max(0, j - N * 2), F = d === void 0 ? Math.max(...l.map((e) => n(e.value)), 1) : Math.max(n(d), 1), I = Math.max(0, h), L = Math.max(0, g), R = Math.max(0, c - I - L), z = f ?? ((e) => e.toLocaleString());
16
- return /* @__PURE__ */ a("svg", {
17
- ref: x,
18
- ...S,
15
+ ];
16
+ function d(e, t, n, r) {
17
+ if (e) {
18
+ if (e.textContent = t, e.getComputedTextLength() > r) {
19
+ let n = Array.from(t.replace(/\.\.\.$/, "")), i = 0, a = n.length;
20
+ for (; i < a;) {
21
+ let t = Math.ceil((i + a) / 2);
22
+ e.textContent = n.slice(0, t).join("") + "…", e.getComputedTextLength() <= r ? i = t : a = t - 1;
23
+ }
24
+ e.textContent = n.slice(0, i).join("") + "…", i === 0 && e.getComputedTextLength() > r && (e.textContent = "");
25
+ }
26
+ if (e.textContent !== n) {
27
+ let t = document.createElementNS(e.namespaceURI, "title");
28
+ t.textContent = n, e.prepend(t);
29
+ }
30
+ }
31
+ }
32
+ function f({ data: f, onDatumActivate: p, height: m, maxValue: h, valueFormatter: g, labelFormatter: _, maxLabelLength: v, labelWidth: y = 160, valueWidth: b = 60, barHeight: x = 28, gap: S = 10, "aria-label": C = "Horizontal bar chart", className: w, ref: T, ...E }) {
33
+ let { rootRef: D, size: O, viewBoxWidth: k } = i(T), [A, j] = o(null), M = f.length, N = Math.max(1, x), P = Math.max(0, S), F = M > 0 ? M * N + Math.max(0, M - 1) * P : N, I = Math.max(1, m ?? F), L = O?.height ?? I, R = L / F, z = N * R, B = P * R, V = Math.min(3, z / 3), H = Math.max(0, z - V * 2), U = h === void 0 ? Math.max(...f.map((e) => n(e.value)), 1) : Math.max(n(h), 1), W = Math.max(0, y), G = W + Math.max(0, b), K = Math.min(G, k * .6), q = G > 0 ? W / G * K : 0, J = k - K, Y = g ?? ((e) => e.toLocaleString());
34
+ return /* @__PURE__ */ c("svg", {
35
+ ref: D,
36
+ ...E,
19
37
  width: "100%",
20
- viewBox: `0 0 ${c} ${k}`,
21
- className: e("select-none", b),
22
- role: "img",
23
- "aria-label": y,
24
- children: l.map((e, i) => {
25
- let l = i * (j + M), u = F > 0 ? t(n(e.value), 0, F) / F * R : 0, d = C === i, f = p?.(e.label, e, i) ?? e.label, h = r(f, m), g = h !== f, _ = z(e.value);
26
- return /* @__PURE__ */ o("g", {
27
- onMouseEnter: () => w(i),
28
- onMouseLeave: () => w(null),
29
- onPointerEnter: () => w(i),
30
- onPointerDown: () => w(i),
31
- onPointerLeave: () => w(null),
32
- onFocus: () => w(i),
33
- onBlur: () => w(null),
38
+ height: O && I,
39
+ viewBox: `0 0 ${k} ${L}`,
40
+ className: e("select-none", w),
41
+ role: p ? "group" : "img",
42
+ "aria-label": C,
43
+ children: f.map((e, i) => {
44
+ let o = i * (z + B), f = U > 0 ? t(n(e.value), 0, U) / U * J : 0, m = A === i, h = _?.(e.label, e, i) ?? e.label, g = r(h, v), y = g !== h, b = Y(e.value);
45
+ return /* @__PURE__ */ l("g", {
46
+ ...a(p, e, i),
47
+ onMouseEnter: () => j(i),
48
+ onMouseLeave: () => j(null),
49
+ onPointerEnter: () => j(i),
50
+ onPointerDown: () => j(i),
51
+ onPointerLeave: () => j(null),
52
+ onFocus: () => j(i),
53
+ onBlur: () => j(null),
34
54
  className: "cursor-pointer",
35
55
  tabIndex: 0,
36
56
  role: "button",
37
- "aria-label": `${f}: ${_}`,
57
+ "aria-label": `${h}: ${b}`,
38
58
  children: [
39
- /* @__PURE__ */ a("rect", {
59
+ /* @__PURE__ */ c("rect", {
40
60
  x: 0,
41
- y: l,
42
- width: c,
43
- height: j,
61
+ y: o,
62
+ width: k,
63
+ height: z,
44
64
  fill: "transparent"
45
65
  }),
46
- /* @__PURE__ */ o("text", {
66
+ /* @__PURE__ */ c("text", {
47
67
  x: 0,
48
- y: l + j / 2,
68
+ y: o + z / 2,
49
69
  dominantBaseline: "central",
50
- fill: d ? "var(--text-primary)" : "var(--text-secondary)",
70
+ fill: m ? "var(--text-primary)" : "var(--text-secondary)",
51
71
  fontSize: 11,
52
- fontWeight: d ? 600 : 400,
72
+ fontWeight: m ? 600 : 400,
53
73
  style: { transition: "all 150ms" },
54
- children: [g && /* @__PURE__ */ a("title", { children: f }), h]
74
+ children: O && K < G ? /* @__PURE__ */ c("tspan", { ref: (e) => d(e, g, h, q - 4) }) : /* @__PURE__ */ l(s, { children: [y && /* @__PURE__ */ c("title", { children: h }), g] })
55
75
  }),
56
- /* @__PURE__ */ a("rect", {
57
- x: I,
58
- y: l + N,
59
- width: R,
60
- height: P,
76
+ /* @__PURE__ */ c("rect", {
77
+ x: q,
78
+ y: o + V,
79
+ width: J,
80
+ height: H,
61
81
  fill: "var(--border)",
62
82
  rx: 6,
63
83
  opacity: .5
64
84
  }),
65
- /* @__PURE__ */ a("rect", {
66
- x: I,
67
- y: l + N,
68
- width: u,
69
- height: P,
85
+ /* @__PURE__ */ c("rect", {
86
+ x: q,
87
+ y: o + V,
88
+ width: f,
89
+ height: H,
70
90
  fill: "var(--accent)",
71
91
  rx: 6,
72
- opacity: d ? 1 : s[i % s.length],
92
+ opacity: m ? 1 : u[i % u.length],
73
93
  style: { transition: "all 150ms" }
74
94
  }),
75
- /* @__PURE__ */ a("text", {
76
- x: c,
77
- y: l + j / 2,
95
+ /* @__PURE__ */ c("text", {
96
+ x: k,
97
+ y: o + z / 2,
78
98
  dominantBaseline: "central",
79
99
  textAnchor: "end",
80
100
  fill: "var(--text-primary)",
81
101
  fontSize: 11,
82
102
  fontWeight: 600,
83
- children: _
103
+ children: b
84
104
  })
85
105
  ]
86
106
  }, e.label);
@@ -88,4 +108,4 @@ function l({ data: l, height: u, maxValue: d, valueFormatter: f, labelFormatter:
88
108
  });
89
109
  }
90
110
  //#endregion
91
- export { l as BarChart };
111
+ export { f as BarChart };
@@ -0,0 +1,20 @@
1
+ import type { ComponentPropsWithRef } from "react";
2
+ export interface HeatmapProps extends Omit<ComponentPropsWithRef<"figure">, "children"> {
3
+ /** Visible table caption and accessible name of the scrolling region. */
4
+ caption: string;
5
+ /** Labels down the left edge, in matrix order. */
6
+ rowLabels: readonly string[];
7
+ /** Labels across the top, in matrix order. */
8
+ columnLabels: readonly string[];
9
+ /** Non-negative readings by row and column. Missing rows, short rows and null readings display a dash for each absent value. */
10
+ values: readonly (readonly (number | null | undefined)[] | undefined)[];
11
+ /** Optional heading above the row labels. */
12
+ rowHeading?: string;
13
+ /** Positive upper bound for the four colour bands; higher readings use the top band. Defaults to the largest reading. */
14
+ max?: number;
15
+ /** Tooltip and accessible name for a numeric cell. Defaults to the displayed number. */
16
+ valueLabel?: (value: number, row: string, column: string) => string;
17
+ /** Tooltip and accessible name for an absent reading. */
18
+ missingLabel?: string;
19
+ }
20
+ export declare function Heatmap({ caption, rowLabels, columnLabels, values, rowHeading, max, valueLabel, missingLabel, className, ...props }: HeatmapProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import { cn as e } from "../../lib/cn.js";
2
+ import { Table as t, TableBody as n, TableCell as r, TableHead as i, TableHeaderCell as a, TableRow as o } from "../tables/Table.js";
3
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
4
+ //#region src/components/charts/Heatmap.tsx
5
+ function l(e) {
6
+ let t = 0;
7
+ for (let n of e) if (n !== void 0) for (let e of n) t = Math.max(t, e ?? 0);
8
+ return t;
9
+ }
10
+ function u({ caption: u, rowLabels: d, columnLabels: f, values: p, rowHeading: m, max: h, valueLabel: g, missingLabel: _ = "Unavailable", className: v, ...y }) {
11
+ let b = h ?? l(p);
12
+ return /* @__PURE__ */ c("figure", {
13
+ ...y,
14
+ className: e("min-w-0", v),
15
+ children: [/* @__PURE__ */ c(t, {
16
+ caption: u,
17
+ className: "ui-heatmap",
18
+ wrapperProps: {
19
+ role: "region",
20
+ tabIndex: 0,
21
+ "aria-label": u
22
+ },
23
+ children: [/* @__PURE__ */ s(i, { children: /* @__PURE__ */ c(o, { children: [m ? /* @__PURE__ */ s(a, { children: m }) : /* @__PURE__ */ s("td", {}), f.map((e, t) => /* @__PURE__ */ s(a, { children: e }, t))] }) }), /* @__PURE__ */ s(n, { children: d.map((e, t) => /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s(a, {
24
+ scope: "row",
25
+ children: e
26
+ }), f.map((n, i) => {
27
+ let a = p[t]?.[i], o = a == null ? _ : g?.(a, e, n) ?? String(a);
28
+ return /* @__PURE__ */ s(r, {
29
+ "data-intensity": a == null ? "missing" : a <= 0 ? 0 : Math.min(4, Math.ceil(4 * a / b)),
30
+ "aria-label": o,
31
+ title: o,
32
+ children: a ?? "—"
33
+ }, i);
34
+ })] }, t)) })]
35
+ }), /* @__PURE__ */ c("figcaption", {
36
+ className: "text-xs text-text-secondary",
37
+ children: [
38
+ "Colour scale from 0 to ",
39
+ b,
40
+ "."
41
+ ]
42
+ })]
43
+ });
44
+ }
45
+ //#endregion
46
+ export { u as Heatmap };
@@ -17,6 +17,8 @@ export interface StackedBarChartTooltipRow {
17
17
  export interface StackedBarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
18
18
  /** One entry per bar, with a `date` label and a numeric value for each segment `key`. */
19
19
  data: StackedBarChartDatum[];
20
+ /** Activate a bar by click, Enter or Space. Receives the original datum and its index in data. */
21
+ onDatumActivate?: (datum: StackedBarChartDatum, index: number) => void;
20
22
  /** Stack layers in order; each maps a `key` in `data` to a `label`, `color`, and optional `opacity`. */
21
23
  segments: StackedBarChartSegment[];
22
24
  /** Chart height in SVG units; the width scales to the container. Defaults to 220. */
@@ -38,4 +40,4 @@ export interface StackedBarChartProps extends Omit<ComponentPropsWithRef<"svg">,
38
40
  /** Extra classes for the `<svg>`. */
39
41
  className?: string;
40
42
  }
41
- export declare function StackedBarChart({ data, segments, height, "aria-label": ariaLabel, tooltipRows, valueFormatter, tooltipValueFormatter, xLabelCount, barGap, minBarWidth, className, ref, ...rest }: StackedBarChartProps): import("react/jsx-runtime").JSX.Element;
43
+ export declare function StackedBarChart({ data, onDatumActivate, segments, height, "aria-label": ariaLabel, tooltipRows, valueFormatter, tooltipValueFormatter, xLabelCount, barGap, minBarWidth, className, ref, ...rest }: StackedBarChartProps): import("react/jsx-runtime").JSX.Element;