@leonardaustin/ui 0.28.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.
- package/dist/components/charts/BarChart.d.ts +4 -2
- package/dist/components/charts/BarChart.js +69 -49
- package/dist/components/charts/StackedBarChart.d.ts +3 -1
- package/dist/components/charts/StackedBarChart.js +103 -95
- package/dist/components/charts/VerticalBarChart.d.ts +3 -1
- package/dist/components/charts/VerticalBarChart.js +94 -83
- package/dist/components/charts/barChartUtils.d.ts +16 -0
- package/dist/components/charts/barChartUtils.js +24 -0
- package/dist/components/charts/useChartSize.d.ts +9 -1
- package/dist/components/charts/useChartSize.js +19 -10
- package/dist/components/ui/MainAsideLayout.d.ts +10 -0
- package/dist/components/ui/MainAsideLayout.js +18 -0
- package/dist/core.css +17 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -5
- package/dist/styles.css +17 -0
- package/package.json +1 -1
|
@@ -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
|
|
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 {
|
|
5
|
-
import {
|
|
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
|
|
9
|
+
var u = [
|
|
8
10
|
1,
|
|
9
11
|
.85,
|
|
10
12
|
.7,
|
|
11
13
|
.55,
|
|
12
14
|
.45
|
|
13
|
-
]
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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": `${
|
|
57
|
+
"aria-label": `${h}: ${b}`,
|
|
38
58
|
children: [
|
|
39
|
-
/* @__PURE__ */
|
|
59
|
+
/* @__PURE__ */ c("rect", {
|
|
40
60
|
x: 0,
|
|
41
|
-
y:
|
|
42
|
-
width:
|
|
43
|
-
height:
|
|
61
|
+
y: o,
|
|
62
|
+
width: k,
|
|
63
|
+
height: z,
|
|
44
64
|
fill: "transparent"
|
|
45
65
|
}),
|
|
46
|
-
/* @__PURE__ */
|
|
66
|
+
/* @__PURE__ */ c("text", {
|
|
47
67
|
x: 0,
|
|
48
|
-
y:
|
|
68
|
+
y: o + z / 2,
|
|
49
69
|
dominantBaseline: "central",
|
|
50
|
-
fill:
|
|
70
|
+
fill: m ? "var(--text-primary)" : "var(--text-secondary)",
|
|
51
71
|
fontSize: 11,
|
|
52
|
-
fontWeight:
|
|
72
|
+
fontWeight: m ? 600 : 400,
|
|
53
73
|
style: { transition: "all 150ms" },
|
|
54
|
-
children:
|
|
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__ */
|
|
57
|
-
x:
|
|
58
|
-
y:
|
|
59
|
-
width:
|
|
60
|
-
height:
|
|
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__ */
|
|
66
|
-
x:
|
|
67
|
-
y:
|
|
68
|
-
width:
|
|
69
|
-
height:
|
|
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:
|
|
92
|
+
opacity: m ? 1 : u[i % u.length],
|
|
73
93
|
style: { transition: "all 150ms" }
|
|
74
94
|
}),
|
|
75
|
-
/* @__PURE__ */
|
|
76
|
-
x:
|
|
77
|
-
y:
|
|
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 {
|
|
111
|
+
export { f as BarChart };
|
|
@@ -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;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
|
-
import { estimateTooltipWidth as t, formatCompactValue as n,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { estimateTooltipWidth as t, formatCompactValue as n, getSvgTooltipPosition as r } from "./chartUtils.js";
|
|
3
|
+
import { useBarChartSize as i } from "./useChartSize.js";
|
|
4
|
+
import { getBarActivationProps as a, getBarAxisLayout as o } from "./barChartUtils.js";
|
|
5
|
+
import { useMemo as s, useState as c } from "react";
|
|
6
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
5
7
|
//#region src/components/charts/StackedBarChart.tsx
|
|
6
|
-
var
|
|
8
|
+
var f = {
|
|
7
9
|
top: 20,
|
|
8
10
|
right: 12,
|
|
9
11
|
bottom: 30,
|
|
10
12
|
left: 48
|
|
11
|
-
},
|
|
12
|
-
function
|
|
13
|
+
}, p = 4;
|
|
14
|
+
function m(e) {
|
|
13
15
|
let t = /^(\d{4})-(\d{2})-(\d{2})T(\d{2})/.exec(e);
|
|
14
16
|
if (t) {
|
|
15
17
|
let [, e, n, r, i] = t;
|
|
@@ -29,7 +31,7 @@ function f(e) {
|
|
|
29
31
|
timeZone: "UTC"
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
function
|
|
34
|
+
function h(e, t) {
|
|
33
35
|
let n = e[t];
|
|
34
36
|
if (typeof n == "number") return Number.isFinite(n) ? n : 0;
|
|
35
37
|
if (typeof n == "string") {
|
|
@@ -38,10 +40,10 @@ function p(e, t) {
|
|
|
38
40
|
}
|
|
39
41
|
return 0;
|
|
40
42
|
}
|
|
41
|
-
function
|
|
42
|
-
return t.reduce((t, n) => t + Math.max(0,
|
|
43
|
+
function g(e, t) {
|
|
44
|
+
return t.reduce((t, n) => t + Math.max(0, h(e, n.key)), 0);
|
|
43
45
|
}
|
|
44
|
-
function
|
|
46
|
+
function ee(e, t, n, r, i) {
|
|
45
47
|
let a = Math.min(i, Math.max(0, n / 2), Math.max(0, r));
|
|
46
48
|
return a <= 0 ? `M ${e} ${t} H ${e + n} V ${t + r} H ${e} Z` : [
|
|
47
49
|
`M ${e} ${t + r}`,
|
|
@@ -53,146 +55,152 @@ function h(e, t, n, r, i) {
|
|
|
53
55
|
"Z"
|
|
54
56
|
].join(" ");
|
|
55
57
|
}
|
|
56
|
-
function
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
function _({ data: _, onDatumActivate: v, segments: y, height: b = 220, "aria-label": x = "Stacked bar chart", tooltipRows: S, valueFormatter: te, tooltipValueFormatter: ne, xLabelCount: C = 6, barGap: w, minBarWidth: T = 1, className: E, ref: D, ...O }) {
|
|
59
|
+
let { rootRef: k, size: A, viewBoxWidth: j } = i(D), [M, N] = c(null), P = Math.max(f.top + f.bottom + 1, b), F = A?.height ?? P, I = s(() => _.map((e) => m(e.date)), [_]), { left: L, plotWidth: R, indices: z } = s(() => o(I, C, A?.width, f), [
|
|
60
|
+
I,
|
|
61
|
+
C,
|
|
62
|
+
A?.width
|
|
63
|
+
]), B = Math.max(1, F - f.top - f.bottom), V = _.reduce((e, t) => Math.max(e, g(t, y)), 1), H = Math.ceil(V / 2), U = H > 0 && H < V, W = w ?? (_.length > 60 ? 2 : _.length > 30 ? 3 : 6), G = Math.max(1, T), K = _.length > 1 ? Math.max(0, (R - _.length * G) / Math.max(_.length - 1, 1)) : 0, q = _.length > 1 ? Math.min(Math.max(0, W), K) : 0, J = _.length > 0 ? (R - q * Math.max(_.length - 1, 0)) / _.length : 0, Y = M === null ? null : _[M], X = te ?? n, Z = ne ?? ((e) => e.toLocaleString());
|
|
64
|
+
function Q(e) {
|
|
65
|
+
return L + e * (J + q);
|
|
60
66
|
}
|
|
61
|
-
function
|
|
62
|
-
return e /
|
|
67
|
+
function $(e) {
|
|
68
|
+
return e / V * B;
|
|
63
69
|
}
|
|
64
|
-
return /* @__PURE__ */
|
|
65
|
-
ref:
|
|
70
|
+
return /* @__PURE__ */ d("svg", {
|
|
71
|
+
ref: k,
|
|
66
72
|
...O,
|
|
67
73
|
width: "100%",
|
|
68
|
-
|
|
74
|
+
height: A && P,
|
|
75
|
+
viewBox: `0 0 ${j} ${F}`,
|
|
69
76
|
className: e("select-none", E),
|
|
70
|
-
role: "img",
|
|
71
|
-
"aria-label":
|
|
77
|
+
role: v ? "group" : "img",
|
|
78
|
+
"aria-label": x,
|
|
72
79
|
children: [
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
x:
|
|
75
|
-
y:
|
|
80
|
+
/* @__PURE__ */ u("text", {
|
|
81
|
+
x: L - 8,
|
|
82
|
+
y: f.top,
|
|
76
83
|
textAnchor: "end",
|
|
77
84
|
dominantBaseline: "central",
|
|
78
85
|
fill: "var(--text-tertiary)",
|
|
79
86
|
fontSize: 10,
|
|
80
|
-
children:
|
|
87
|
+
children: X(V)
|
|
81
88
|
}),
|
|
82
|
-
|
|
83
|
-
x:
|
|
84
|
-
y:
|
|
89
|
+
U && /* @__PURE__ */ u("text", {
|
|
90
|
+
x: L - 8,
|
|
91
|
+
y: f.top + B / 2,
|
|
85
92
|
textAnchor: "end",
|
|
86
93
|
dominantBaseline: "central",
|
|
87
94
|
fill: "var(--text-tertiary)",
|
|
88
95
|
fontSize: 10,
|
|
89
|
-
children:
|
|
96
|
+
children: X(H)
|
|
90
97
|
}),
|
|
91
|
-
/* @__PURE__ */
|
|
92
|
-
x:
|
|
93
|
-
y:
|
|
98
|
+
/* @__PURE__ */ u("text", {
|
|
99
|
+
x: L - 8,
|
|
100
|
+
y: f.top + B,
|
|
94
101
|
textAnchor: "end",
|
|
95
102
|
dominantBaseline: "central",
|
|
96
103
|
fill: "var(--text-tertiary)",
|
|
97
104
|
fontSize: 10,
|
|
98
105
|
children: "0"
|
|
99
106
|
}),
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
x1:
|
|
102
|
-
y1:
|
|
103
|
-
x2:
|
|
104
|
-
y2:
|
|
107
|
+
/* @__PURE__ */ u("line", {
|
|
108
|
+
x1: L,
|
|
109
|
+
y1: f.top + B,
|
|
110
|
+
x2: L + R,
|
|
111
|
+
y2: f.top + B,
|
|
105
112
|
stroke: "var(--border)",
|
|
106
113
|
strokeWidth: 1
|
|
107
114
|
}),
|
|
108
|
-
/* @__PURE__ */
|
|
109
|
-
x1:
|
|
110
|
-
y1:
|
|
111
|
-
x2:
|
|
112
|
-
y2:
|
|
115
|
+
/* @__PURE__ */ u("line", {
|
|
116
|
+
x1: L,
|
|
117
|
+
y1: f.top + B / 2,
|
|
118
|
+
x2: L + R,
|
|
119
|
+
y2: f.top + B / 2,
|
|
113
120
|
stroke: "var(--border)",
|
|
114
121
|
strokeWidth: 1,
|
|
115
122
|
strokeDasharray: "3 3",
|
|
116
123
|
opacity: .5
|
|
117
124
|
}),
|
|
118
|
-
|
|
119
|
-
let n =
|
|
125
|
+
_.map((e, t) => {
|
|
126
|
+
let n = Q(t), r = M === t, i = 0, o = y.map((t) => ({
|
|
120
127
|
segment: t,
|
|
121
|
-
value: Math.max(0,
|
|
128
|
+
value: Math.max(0, h(e, t.key))
|
|
122
129
|
})).filter(({ value: e }) => e > 0);
|
|
123
|
-
return /* @__PURE__ */
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
return /* @__PURE__ */ d("g", {
|
|
131
|
+
...a(v, e, t),
|
|
132
|
+
onMouseEnter: () => N(t),
|
|
133
|
+
onMouseLeave: () => N(null),
|
|
134
|
+
onPointerEnter: () => N(t),
|
|
135
|
+
onPointerDown: () => N(t),
|
|
136
|
+
onPointerLeave: () => N(null),
|
|
137
|
+
onFocus: () => N(t),
|
|
138
|
+
onBlur: () => N(null),
|
|
131
139
|
tabIndex: 0,
|
|
132
140
|
role: "button",
|
|
133
|
-
"aria-label": `${
|
|
141
|
+
"aria-label": `${I[t]}: ${Z(g(e, y))}`,
|
|
134
142
|
children: [
|
|
135
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ u("rect", {
|
|
136
144
|
x: n,
|
|
137
|
-
y:
|
|
138
|
-
width:
|
|
139
|
-
height:
|
|
145
|
+
y: f.top,
|
|
146
|
+
width: J,
|
|
147
|
+
height: B,
|
|
140
148
|
fill: "transparent"
|
|
141
149
|
}),
|
|
142
|
-
|
|
143
|
-
let
|
|
144
|
-
return i +=
|
|
145
|
-
d:
|
|
150
|
+
o.map(({ segment: e, value: t }, a) => {
|
|
151
|
+
let s = $(t), c = f.top + B - i - s, l = a === o.length - 1;
|
|
152
|
+
return i += s, l ? /* @__PURE__ */ u("path", {
|
|
153
|
+
d: ee(n, c, J, s, p),
|
|
146
154
|
fill: e.color,
|
|
147
155
|
opacity: r ? 1 : e.opacity ?? .9
|
|
148
|
-
}, e.key) : /* @__PURE__ */
|
|
156
|
+
}, e.key) : /* @__PURE__ */ u("rect", {
|
|
149
157
|
x: n,
|
|
150
|
-
y:
|
|
151
|
-
width:
|
|
152
|
-
height:
|
|
158
|
+
y: c,
|
|
159
|
+
width: J,
|
|
160
|
+
height: s,
|
|
153
161
|
fill: e.color,
|
|
154
162
|
opacity: r ? 1 : e.opacity ?? .9
|
|
155
163
|
}, e.key);
|
|
156
164
|
}),
|
|
157
|
-
|
|
158
|
-
x: n +
|
|
159
|
-
y:
|
|
165
|
+
z.has(t) && /* @__PURE__ */ u("text", {
|
|
166
|
+
x: n + J / 2,
|
|
167
|
+
y: F - 5,
|
|
160
168
|
textAnchor: "middle",
|
|
161
169
|
fill: "var(--text-tertiary)",
|
|
162
170
|
fontSize: 10,
|
|
163
|
-
children:
|
|
171
|
+
children: I[t]
|
|
164
172
|
})
|
|
165
173
|
]
|
|
166
174
|
}, `${e.date}-${t}`);
|
|
167
175
|
}),
|
|
168
|
-
|
|
176
|
+
Y && M !== null && /* @__PURE__ */ u("g", {
|
|
169
177
|
pointerEvents: "none",
|
|
170
178
|
children: (() => {
|
|
171
|
-
let e =
|
|
179
|
+
let e = Q(M) + J / 2, n = S?.(Y) ?? y.map((e) => ({
|
|
172
180
|
color: e.color,
|
|
173
181
|
label: e.label,
|
|
174
|
-
value:
|
|
175
|
-
})),
|
|
176
|
-
boundsHeight:
|
|
177
|
-
boundsWidth:
|
|
182
|
+
value: h(Y, e.key)
|
|
183
|
+
})), i = g(Y, y), a = r(e, f.top + B - $(i), {
|
|
184
|
+
boundsHeight: F,
|
|
185
|
+
boundsWidth: j,
|
|
178
186
|
height: 28 + n.length * 15,
|
|
179
187
|
offset: 8,
|
|
180
|
-
width: t([
|
|
188
|
+
width: t([m(Y.date), ...n.map((e) => `${e.label} ${Z(e.value)}`)], {
|
|
181
189
|
maxWidth: 240,
|
|
182
190
|
minWidth: 150
|
|
183
191
|
})
|
|
184
|
-
}),
|
|
185
|
-
return /* @__PURE__ */
|
|
186
|
-
/* @__PURE__ */
|
|
192
|
+
}), o = a.x + 10, s = a.x + a.width - 10;
|
|
193
|
+
return /* @__PURE__ */ d(l, { children: [
|
|
194
|
+
/* @__PURE__ */ u("line", {
|
|
187
195
|
x1: e,
|
|
188
|
-
y1:
|
|
196
|
+
y1: f.top,
|
|
189
197
|
x2: e,
|
|
190
|
-
y2:
|
|
198
|
+
y2: f.top + B,
|
|
191
199
|
stroke: "var(--border-strong)",
|
|
192
200
|
strokeWidth: 1,
|
|
193
201
|
strokeDasharray: "3 3"
|
|
194
202
|
}),
|
|
195
|
-
/* @__PURE__ */
|
|
203
|
+
/* @__PURE__ */ u("rect", {
|
|
196
204
|
x: a.x,
|
|
197
205
|
y: a.y,
|
|
198
206
|
width: a.width,
|
|
@@ -202,40 +210,40 @@ function g({ data: g, segments: _, height: v = 220, "aria-label": y = "Stacked b
|
|
|
202
210
|
stroke: "var(--border)",
|
|
203
211
|
strokeWidth: 1
|
|
204
212
|
}),
|
|
205
|
-
/* @__PURE__ */
|
|
206
|
-
x:
|
|
213
|
+
/* @__PURE__ */ u("text", {
|
|
214
|
+
x: o,
|
|
207
215
|
y: a.y + 14,
|
|
208
216
|
fill: "var(--text-primary)",
|
|
209
217
|
fontSize: 10,
|
|
210
218
|
fontWeight: 600,
|
|
211
|
-
children:
|
|
219
|
+
children: m(Y.date)
|
|
212
220
|
}),
|
|
213
221
|
n.map((e, t) => {
|
|
214
222
|
let n = a.y + 30 + t * 15;
|
|
215
|
-
return /* @__PURE__ */
|
|
216
|
-
e.color && /* @__PURE__ */
|
|
217
|
-
x:
|
|
223
|
+
return /* @__PURE__ */ d("g", { children: [
|
|
224
|
+
e.color && /* @__PURE__ */ u("rect", {
|
|
225
|
+
x: o,
|
|
218
226
|
y: n - 6,
|
|
219
227
|
width: 6,
|
|
220
228
|
height: 6,
|
|
221
229
|
rx: 1,
|
|
222
230
|
fill: e.color
|
|
223
231
|
}),
|
|
224
|
-
/* @__PURE__ */
|
|
225
|
-
x: e.color ?
|
|
232
|
+
/* @__PURE__ */ u("text", {
|
|
233
|
+
x: e.color ? o + 12 : o,
|
|
226
234
|
y: n,
|
|
227
235
|
fill: "var(--text-secondary)",
|
|
228
236
|
fontSize: 10,
|
|
229
237
|
children: e.label
|
|
230
238
|
}),
|
|
231
|
-
/* @__PURE__ */
|
|
232
|
-
x:
|
|
239
|
+
/* @__PURE__ */ u("text", {
|
|
240
|
+
x: s,
|
|
233
241
|
y: n,
|
|
234
242
|
textAnchor: "end",
|
|
235
243
|
fill: "var(--text-primary)",
|
|
236
244
|
fontSize: 10,
|
|
237
245
|
fontWeight: 600,
|
|
238
|
-
children:
|
|
246
|
+
children: Z(e.value)
|
|
239
247
|
})
|
|
240
248
|
] }, e.label);
|
|
241
249
|
})
|
|
@@ -246,4 +254,4 @@ function g({ data: g, segments: _, height: v = 220, "aria-label": y = "Stacked b
|
|
|
246
254
|
});
|
|
247
255
|
}
|
|
248
256
|
//#endregion
|
|
249
|
-
export {
|
|
257
|
+
export { _ as StackedBarChart };
|
|
@@ -7,6 +7,8 @@ export interface VerticalBarChartDatum {
|
|
|
7
7
|
export interface VerticalBarChartProps extends Omit<ComponentPropsWithRef<"svg">, "children" | "viewBox" | "width"> {
|
|
8
8
|
/** Bars to draw left to right, each with a `label`, numeric `value`, and optional `color`. */
|
|
9
9
|
data: VerticalBarChartDatum[];
|
|
10
|
+
/** Activate a bar by click, Enter or Space. Receives the original datum and its index in data. */
|
|
11
|
+
onDatumActivate?: (datum: VerticalBarChartDatum, index: number) => void;
|
|
10
12
|
/** Chart height in SVG units; the width scales to the container. Defaults to 180. */
|
|
11
13
|
height?: number;
|
|
12
14
|
/** Explicit domain maximum. Defaults to the largest positive value. */
|
|
@@ -30,4 +32,4 @@ export interface VerticalBarChartProps extends Omit<ComponentPropsWithRef<"svg">
|
|
|
30
32
|
/** Extra classes for the `<svg>`. */
|
|
31
33
|
className?: string;
|
|
32
34
|
}
|
|
33
|
-
export declare function VerticalBarChart({ data, height, maxValue, valueFormatter, tooltipValueFormatter, labelFormatter, maxLabelLength, xLabelCount, barGap, minBarWidth, "aria-label": ariaLabel, className, ref, ...rest }: VerticalBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare function VerticalBarChart({ data, onDatumActivate, height, maxValue, valueFormatter, tooltipValueFormatter, labelFormatter, maxLabelLength, xLabelCount, barGap, minBarWidth, "aria-label": ariaLabel, className, ref, ...rest }: VerticalBarChartProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { cn as e } from "../../lib/cn.js";
|
|
2
2
|
import { clamp as t } from "../../lib/math.js";
|
|
3
|
-
import { estimateTooltipWidth as n, formatCompactValue as r,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { estimateTooltipWidth as n, formatCompactValue as r, getPositiveValue as i, getSvgTooltipPosition as a, resolveChartColor as o, truncateChartLabel as s } from "./chartUtils.js";
|
|
4
|
+
import { useBarChartSize as c } from "./useChartSize.js";
|
|
5
|
+
import { getBarActivationProps as l, getBarAxisLayout as u } from "./barChartUtils.js";
|
|
6
|
+
import { useMemo as d, useState as f } from "react";
|
|
7
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
6
8
|
//#region src/components/charts/VerticalBarChart.tsx
|
|
7
|
-
var
|
|
9
|
+
var h = [
|
|
8
10
|
1,
|
|
9
11
|
.85,
|
|
10
12
|
.7,
|
|
@@ -12,126 +14,135 @@ var p = [
|
|
|
12
14
|
.45,
|
|
13
15
|
.35,
|
|
14
16
|
.25
|
|
15
|
-
],
|
|
17
|
+
], g = {
|
|
16
18
|
top: 20,
|
|
17
19
|
right: 8,
|
|
18
20
|
bottom: 24,
|
|
19
21
|
left: 40
|
|
20
|
-
}
|
|
21
|
-
function
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
};
|
|
23
|
+
function _({ data: _, onDatumActivate: v, height: y = 180, maxValue: b, valueFormatter: x, tooltipValueFormatter: S, labelFormatter: C, maxLabelLength: w, xLabelCount: T = 7, barGap: E = 6, minBarWidth: D = 4, "aria-label": O = "Vertical bar chart", className: k, ref: A, ...j }) {
|
|
24
|
+
let { rootRef: M, size: N, viewBoxWidth: P } = c(A), [F, I] = f(null), L = Math.max(g.top + g.bottom + 1, y), R = N?.height ?? L, z = d(() => _.map((e, t) => C?.(e.label, e, t) ?? e.label), [_, C]), B = d(() => z.map((e) => s(e, w)), [z, w]), { left: V, plotWidth: H, indices: U } = d(() => u(B, T, N?.width, g), [
|
|
25
|
+
B,
|
|
26
|
+
T,
|
|
27
|
+
N?.width
|
|
28
|
+
]), W = Math.max(1, R - g.top - g.bottom), G = b === void 0 ? Math.max(..._.map((e) => i(e.value)), 1) : Math.max(i(b), 1), K = Math.max(0, E), q = Math.max(1, D), J = _.length > 1 ? Math.max(0, (H - _.length * q) / Math.max(_.length - 1, 1)) : 0, Y = _.length > 1 ? Math.min(K, J) : 0, X = _.length > 0 ? Math.max(0, (H - Y * Math.max(_.length - 1, 0)) / _.length) : 0, Z = x ?? r, Q = S ?? ((e) => e.toLocaleString());
|
|
29
|
+
return /* @__PURE__ */ m("svg", {
|
|
30
|
+
ref: M,
|
|
31
|
+
...j,
|
|
26
32
|
width: "100%",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
33
|
+
height: N && L,
|
|
34
|
+
viewBox: `0 0 ${P} ${R}`,
|
|
35
|
+
className: e("select-none", k),
|
|
36
|
+
role: v ? "group" : "img",
|
|
37
|
+
"aria-label": O,
|
|
31
38
|
children: [
|
|
32
|
-
/* @__PURE__ */
|
|
33
|
-
x:
|
|
34
|
-
y:
|
|
39
|
+
/* @__PURE__ */ p("text", {
|
|
40
|
+
x: V - 6,
|
|
41
|
+
y: g.top + 4,
|
|
35
42
|
textAnchor: "end",
|
|
36
43
|
fill: "var(--text-tertiary)",
|
|
37
44
|
fontSize: 10,
|
|
38
|
-
children:
|
|
45
|
+
children: Z(G)
|
|
39
46
|
}),
|
|
40
|
-
/* @__PURE__ */
|
|
41
|
-
x:
|
|
42
|
-
y:
|
|
47
|
+
/* @__PURE__ */ p("text", {
|
|
48
|
+
x: V - 6,
|
|
49
|
+
y: g.top + W,
|
|
43
50
|
textAnchor: "end",
|
|
44
51
|
dominantBaseline: "central",
|
|
45
52
|
fill: "var(--text-tertiary)",
|
|
46
53
|
fontSize: 10,
|
|
47
54
|
children: "0"
|
|
48
55
|
}),
|
|
49
|
-
/* @__PURE__ */
|
|
50
|
-
x1:
|
|
51
|
-
y1:
|
|
52
|
-
x2:
|
|
53
|
-
y2:
|
|
56
|
+
/* @__PURE__ */ p("line", {
|
|
57
|
+
x1: V,
|
|
58
|
+
y1: g.top + W,
|
|
59
|
+
x2: V + H,
|
|
60
|
+
y2: g.top + W,
|
|
54
61
|
stroke: "var(--border)",
|
|
55
62
|
strokeWidth: 1
|
|
56
63
|
}),
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
x1:
|
|
59
|
-
y1:
|
|
60
|
-
x2:
|
|
61
|
-
y2:
|
|
64
|
+
/* @__PURE__ */ p("line", {
|
|
65
|
+
x1: V,
|
|
66
|
+
y1: g.top + W / 2,
|
|
67
|
+
x2: V + H,
|
|
68
|
+
y2: g.top + W / 2,
|
|
62
69
|
stroke: "var(--border)",
|
|
63
70
|
strokeWidth: 1,
|
|
64
71
|
strokeDasharray: "3 3",
|
|
65
72
|
opacity: .5
|
|
66
73
|
}),
|
|
67
|
-
|
|
68
|
-
let
|
|
69
|
-
return /* @__PURE__ */
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
_.map((e, r) => {
|
|
75
|
+
let s = V + r * (X + Y), c = t(i(e.value), 0, G) / G * W, u = g.top + W - c, d = F === r, f = z[r], _ = B[r], y = _ !== f, b = Q(e.value);
|
|
76
|
+
return /* @__PURE__ */ m("g", {
|
|
77
|
+
...l(v, e, r),
|
|
78
|
+
onMouseEnter: () => I(r),
|
|
79
|
+
onMouseLeave: () => I(null),
|
|
80
|
+
onPointerEnter: () => I(r),
|
|
81
|
+
onPointerDown: () => I(r),
|
|
82
|
+
onPointerLeave: () => I(null),
|
|
83
|
+
onFocus: () => I(r),
|
|
84
|
+
onBlur: () => I(null),
|
|
77
85
|
tabIndex: 0,
|
|
78
86
|
role: "button",
|
|
79
|
-
"aria-label": `${
|
|
87
|
+
"aria-label": `${f}: ${b}`,
|
|
80
88
|
children: [
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
x:
|
|
83
|
-
y:
|
|
84
|
-
width:
|
|
85
|
-
height:
|
|
89
|
+
/* @__PURE__ */ p("rect", {
|
|
90
|
+
x: s,
|
|
91
|
+
y: g.top,
|
|
92
|
+
width: X,
|
|
93
|
+
height: W,
|
|
86
94
|
fill: "transparent"
|
|
87
95
|
}),
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
x:
|
|
90
|
-
y:
|
|
91
|
-
width:
|
|
92
|
-
height:
|
|
93
|
-
fill:
|
|
96
|
+
/* @__PURE__ */ p("rect", {
|
|
97
|
+
x: s,
|
|
98
|
+
y: u,
|
|
99
|
+
width: X,
|
|
100
|
+
height: c,
|
|
101
|
+
fill: o(e.color),
|
|
94
102
|
rx: 6,
|
|
95
|
-
opacity:
|
|
103
|
+
opacity: d ? 1 : h[r % h.length],
|
|
96
104
|
style: { transition: "all 150ms" }
|
|
97
105
|
}),
|
|
98
|
-
U.has(r) && /* @__PURE__ */
|
|
99
|
-
x:
|
|
100
|
-
y:
|
|
106
|
+
U.has(r) && /* @__PURE__ */ m("text", {
|
|
107
|
+
x: s + X / 2,
|
|
108
|
+
y: R - 4,
|
|
101
109
|
textAnchor: "middle",
|
|
102
110
|
fill: "var(--text-tertiary)",
|
|
103
111
|
fontSize: 10,
|
|
104
|
-
children: [
|
|
112
|
+
children: [y && /* @__PURE__ */ p("title", { children: f }), _]
|
|
105
113
|
}),
|
|
106
|
-
|
|
107
|
-
let e =
|
|
108
|
-
boundsHeight:
|
|
109
|
-
boundsWidth:
|
|
114
|
+
d && (() => {
|
|
115
|
+
let e = a(s + X / 2, u, {
|
|
116
|
+
boundsHeight: R,
|
|
117
|
+
boundsWidth: P,
|
|
110
118
|
height: 24,
|
|
111
119
|
offset: 8,
|
|
112
|
-
width: n([
|
|
120
|
+
width: n([f, b], {
|
|
113
121
|
maxWidth: 180,
|
|
114
122
|
minWidth: 72
|
|
115
123
|
})
|
|
116
124
|
}), t = e.x + e.width / 2;
|
|
117
|
-
return /* @__PURE__ */
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
return /* @__PURE__ */ m("g", {
|
|
126
|
+
pointerEvents: "none",
|
|
127
|
+
children: [/* @__PURE__ */ p("rect", {
|
|
128
|
+
x: e.x,
|
|
129
|
+
y: e.y,
|
|
130
|
+
width: e.width,
|
|
131
|
+
height: e.height,
|
|
132
|
+
rx: 4,
|
|
133
|
+
fill: "var(--bg-tooltip, var(--bg-tertiary))",
|
|
134
|
+
stroke: "var(--border)",
|
|
135
|
+
strokeWidth: 1
|
|
136
|
+
}), /* @__PURE__ */ p("text", {
|
|
137
|
+
x: t,
|
|
138
|
+
y: e.y + 15,
|
|
139
|
+
textAnchor: "middle",
|
|
140
|
+
fill: "var(--text-primary)",
|
|
141
|
+
fontSize: 10,
|
|
142
|
+
fontWeight: 600,
|
|
143
|
+
children: b
|
|
144
|
+
})]
|
|
145
|
+
});
|
|
135
146
|
})()
|
|
136
147
|
]
|
|
137
148
|
}, e.label);
|
|
@@ -140,4 +151,4 @@ function g({ data: g, height: _ = 180, maxValue: v, valueFormatter: y, tooltipVa
|
|
|
140
151
|
});
|
|
141
152
|
}
|
|
142
153
|
//#endregion
|
|
143
|
-
export {
|
|
154
|
+
export { _ as VerticalBarChart };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { KeyboardEvent } from "react";
|
|
2
|
+
export declare function getBarActivationProps<T>(activate: ((datum: T, index: number) => void) | undefined, datum: T, index: number): {
|
|
3
|
+
onClick?: undefined;
|
|
4
|
+
onKeyDown?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
onKeyDown(event: KeyboardEvent<SVGGElement>): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function getBarAxisLayout(labels: string[], cap: number, measuredWidth: number | undefined, padding: {
|
|
10
|
+
left: number;
|
|
11
|
+
right: number;
|
|
12
|
+
}): {
|
|
13
|
+
left: number;
|
|
14
|
+
plotWidth: number;
|
|
15
|
+
indices: Set<number>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { estimateTextWidth as e, getFittingLabelCount as t, getLabelIndices as n } from "./chartUtils.js";
|
|
2
|
+
//#region src/components/charts/barChartUtils.ts
|
|
3
|
+
function r(e, t, n) {
|
|
4
|
+
return e ? {
|
|
5
|
+
onClick: () => e(t, n),
|
|
6
|
+
onKeyDown(r) {
|
|
7
|
+
r.key !== "Enter" && r.key !== " " || (r.preventDefault(), r.repeat || e(t, n));
|
|
8
|
+
}
|
|
9
|
+
} : {};
|
|
10
|
+
}
|
|
11
|
+
function i(r, i, a, o) {
|
|
12
|
+
let s = a ?? 600, c = (t, n) => a && i > 0 && t ? Math.max(n, Math.min(s / 4, e(t) / 2 + 4)) : n, l = c(r[0], o.left), u = Math.max(0, s - l - c(r.at(-1), o.right)), d = i;
|
|
13
|
+
if (a && r.length > 1 && i > 1) {
|
|
14
|
+
let n = r.reduce((t, n) => Math.max(t, e(n)), 0), a = u * (1 - 1 / r.length);
|
|
15
|
+
d = Math.min(i, t(r.length, a, n));
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
left: l,
|
|
19
|
+
plotWidth: u,
|
|
20
|
+
indices: new Set(n(r.length, d))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { r as getBarActivationProps, i as getBarAxisLayout };
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { type RefObject } from "react";
|
|
1
|
+
import { type Ref, type RefCallback, type RefObject } from "react";
|
|
2
2
|
export declare function useChartSize(ref: RefObject<SVGSVGElement | null>): {
|
|
3
3
|
width: number;
|
|
4
4
|
height: number;
|
|
5
5
|
} | undefined;
|
|
6
|
+
export declare function useBarChartSize(ref: Ref<SVGSVGElement> | undefined): {
|
|
7
|
+
rootRef: RefCallback<SVGSVGElement>;
|
|
8
|
+
size: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
} | undefined;
|
|
12
|
+
viewBoxWidth: number;
|
|
13
|
+
};
|
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mergeRefs as e } from "../../lib/mergeRefs.js";
|
|
2
|
+
import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
|
|
2
3
|
//#region src/components/charts/useChartSize.ts
|
|
3
|
-
function
|
|
4
|
-
let [
|
|
5
|
-
return
|
|
6
|
-
if (!
|
|
7
|
-
let
|
|
4
|
+
function a(e) {
|
|
5
|
+
let [t, r] = i();
|
|
6
|
+
return n(() => {
|
|
7
|
+
if (!e.current || typeof ResizeObserver > "u") return;
|
|
8
|
+
let t = new ResizeObserver(([e]) => {
|
|
8
9
|
let { width: t, height: n } = e.contentRect;
|
|
9
|
-
t > 0 && n > 0 &&
|
|
10
|
+
t > 0 && n > 0 && r({
|
|
10
11
|
width: t,
|
|
11
12
|
height: n
|
|
12
13
|
});
|
|
13
14
|
});
|
|
14
|
-
return
|
|
15
|
-
}, [
|
|
15
|
+
return t.observe(e.current), () => t.disconnect();
|
|
16
|
+
}, [e]), t;
|
|
17
|
+
}
|
|
18
|
+
function o(n) {
|
|
19
|
+
let i = r(null), o = t((t) => e(i, n)(t), [n]), s = a(i);
|
|
20
|
+
return {
|
|
21
|
+
rootRef: o,
|
|
22
|
+
size: s,
|
|
23
|
+
viewBoxWidth: s?.width ?? 600
|
|
24
|
+
};
|
|
16
25
|
}
|
|
17
26
|
//#endregion
|
|
18
|
-
export {
|
|
27
|
+
export { o as useBarChartSize, a as useChartSize };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
export interface MainAsideLayoutProps extends ComponentPropsWithRef<"div"> {
|
|
3
|
+
/** Primary content, displayed first at every width. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** Supporting content, rendered in an aside. */
|
|
6
|
+
aside: ReactNode;
|
|
7
|
+
/** Show a divider between the columns when side by side. */
|
|
8
|
+
divider?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function MainAsideLayout({ children, aside, divider, className, ...props }: MainAsideLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cn as e } from "../../lib/cn.js";
|
|
2
|
+
import { jsx as t, jsxs as n } from "react/jsx-runtime";
|
|
3
|
+
//#region src/components/ui/MainAsideLayout.tsx
|
|
4
|
+
function r({ children: r, aside: i, divider: a = !1, className: o, ...s }) {
|
|
5
|
+
return /* @__PURE__ */ t("div", {
|
|
6
|
+
...s,
|
|
7
|
+
className: e("ui-main-aside", o),
|
|
8
|
+
children: /* @__PURE__ */ n("div", {
|
|
9
|
+
className: "ui-main-aside-grid",
|
|
10
|
+
children: [/* @__PURE__ */ t("div", { children: r }), /* @__PURE__ */ t("aside", {
|
|
11
|
+
className: a ? "ui-main-aside-divider" : void 0,
|
|
12
|
+
children: i
|
|
13
|
+
})]
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { r as MainAsideLayout };
|
package/dist/core.css
CHANGED
|
@@ -2246,6 +2246,23 @@ select:disabled + .ui-select-placeholder {
|
|
|
2246
2246
|
grid-template-columns: var(--ui-columns-base, repeat(1, minmax(0, 1fr)));
|
|
2247
2247
|
justify-items: var(--ui-justify, stretch);
|
|
2248
2248
|
}
|
|
2249
|
+
.ui-main-aside {
|
|
2250
|
+
container: ui-main-aside / inline-size;
|
|
2251
|
+
}
|
|
2252
|
+
.ui-main-aside-grid {
|
|
2253
|
+
display: grid;
|
|
2254
|
+
grid-template-columns: minmax(0, 1fr);
|
|
2255
|
+
gap: calc(4 * var(--spacing));
|
|
2256
|
+
}
|
|
2257
|
+
@container ui-main-aside (min-width: 56rem) {
|
|
2258
|
+
.ui-main-aside-grid {
|
|
2259
|
+
grid-template-columns: minmax(0, 2fr) minmax(20rem, 1fr);
|
|
2260
|
+
}
|
|
2261
|
+
.ui-main-aside-grid > .ui-main-aside-divider {
|
|
2262
|
+
border-inline-start: var(--ui-border-width) solid var(--border);
|
|
2263
|
+
padding-inline-start: calc(4 * var(--spacing));
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2249
2266
|
.ui-grid-item {
|
|
2250
2267
|
grid-column: var(--ui-span-base, span 1 / span 1);
|
|
2251
2268
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -133,6 +133,7 @@ export * from "./components/ui/Stack";
|
|
|
133
133
|
export * from "./components/ui/Inline";
|
|
134
134
|
export * from "./components/ui/Grid";
|
|
135
135
|
export * from "./components/ui/GridItem";
|
|
136
|
+
export * from "./components/ui/MainAsideLayout";
|
|
136
137
|
export * from "./components/tables/Table";
|
|
137
138
|
export * from "./components/ui/ActionLink";
|
|
138
139
|
export * from "./components/ui/Icon";
|
package/dist/index.js
CHANGED
|
@@ -131,8 +131,9 @@ import { Stack as An } from "./components/ui/Stack.js";
|
|
|
131
131
|
import { Inline as jn } from "./components/ui/Inline.js";
|
|
132
132
|
import { Grid as Mn } from "./components/ui/Grid.js";
|
|
133
133
|
import { GridItem as Nn } from "./components/ui/GridItem.js";
|
|
134
|
-
import {
|
|
135
|
-
import {
|
|
136
|
-
import {
|
|
137
|
-
import {
|
|
138
|
-
|
|
134
|
+
import { MainAsideLayout as Pn } from "./components/ui/MainAsideLayout.js";
|
|
135
|
+
import { ActionLink as Fn } from "./components/ui/ActionLink.js";
|
|
136
|
+
import { Icon as In } from "./components/ui/Icon.js";
|
|
137
|
+
import { Text as Ln } from "./components/ui/Text.js";
|
|
138
|
+
import { Meter as Rn } from "./components/ui/Meter.js";
|
|
139
|
+
export { xe as Accordion, Fn as ActionLink, Se as Alert, de as AppShell, t as AreaChart, Sn as AttachmentItem, Cn as AttachmentList, Ce as AudioPlayer, we as AuthCard, fe as AuthLayout, Te as AuthorByline, H as Avatar, pe as BackLink, Ee as Badge, n as BarChart, x as BottomNav, Z as Breadcrumbs, ee as Button, C as COMMAND_PALETTE_EVENT, st as Calendar, ct as CalendarGrid, lt as Card, Dn as CharacterCount, me as Checkbox, ut as CodeInput, ge as ColumnPicker, dt as Combobox, D as CommandPalette, On as ControlSizeProvider, ft as CopyButton, at as DEFAULT_CALENDAR_LABELS, w as DEFAULT_COMMAND_PALETTE_SHORTCUT, pt as DangerZone, wn as DatePartsInput, mt as DatePicker, ht as DateRangePicker, gt as DateTimePicker, _t as DetailPanel, vt as Dialog, yt as DialogActions, be as Disclosure, bt as DividerLabel, r as DonutChart, xt as DropdownMenu, St as EmptyState, Ct as ErrorBoundary, _n as FieldError, vn as FieldHint, bn as Fieldset, he as FilterButton, wt as FilterDropdown, yn as FormField, Mn as Grid, Nn as GridItem, f as Heatmap, In as Icon, jn as Inline, Tt as Kbd, Dt as ListItemLink, Et as LoadingSpinner, Pn as MainAsideLayout, Ot as MessageBubble, kt as MetadataGrid, Rn as Meter, At as MetricCard, A as MobileDrawer, En as NavTabs, jt as OAuthButton, Mt as OverlineLabel, Nt as PageHeader, Pt as PageSection, _e as Pagination, Ft as PaginationBar, It as PasswordInput, zt as PasswordRequirements, Bt as Popover, O as PortalContainerContext, Vt as ProfileHeader, kn as ProgressBar, Ht as ProseContent, Ut as QrCapacityError, Gt as QrCode, p as RadarChart, m as RadialBarChart, xn as Radio, ot as RadioPill, Kt as ReorderList, ye as ResourceTable, qt as SearchInput, te as SectionHeader, Jt as Select, re as SelectDropdown, Yt as SettingRow, B as SettingsContext, hn as SettingsProvider, Xt as SideSheet, X as Sidebar, Tn as Skeleton, ie as Slider, h as SparkLine, Zt as SplitPaneLayout, An as Stack, g as StackedBarChart, Qt as StatusDot, $t as StepProgress, se as THEME_MENU_EVENT, i as Table, a as TableBody, o as TableCell, s as TableEmptyRow, c as TableFoot, l as TableHead, u as TableHeaderCell, d as TableRow, en as Tabs, Ln as Text, nn as TextInput, tn as Textarea, un as ThemeContext, le as ThemeMenu, ae as ThemePreview, gn as ThemeProvider, rn as TimeInput, an as Timeline, J as ToastProvider, oe as Toggle, cn as Toolbar, sn as Tooltip, ue as TopBar, on as TranscriptLine, ln as UploadDropzone, _ as VerticalBarChart, j as accentItems, Oe as addDays, ke as addMinutes, Ae as addMonths, De as badgeColors, je as calendarDateFromParts, Me as calendarDateParts, e as cn, Ne as createCalendarDateMath, M as darkThemes, Pe as dateAtMinutes, Lt as defaultPasswordRequirements, Fe as differenceInDays, Wt as encodeQrCode, Ie as expandAvailabilityRules, N as fontOptions, fn as formatDateLong, pn as formatDateShort, Le as formatRangeTitle, mn as formatRelative, Re as formatTime, ze as formatTimeOfDay, Be as formatTimeRange, Ve as fromDateKey, He as getActiveResourceIds, Ue as getViewRange, We as getVisibleDays, v as handleAppShellNavigate, Ge as isAllDayLike, y as isAppShellPathActive, P as isLightTheme, Ke as isSameDay, qe as isTimeGridView, U as isTone, Je as layoutOverlaps, F as lightThemes, T as matchesCommandPaletteShortcut, Rt as meetsPasswordRequirements, Ye as minutesOfDay, b as navigateToPath, E as openCommandPalette, ce as openThemeMenu, Xe as parseTime, Ze as rangesOverlap, W as semanticTones, Qe as shiftDate, $e as snapDate, et as snapMinutes, ve as sortRows, tt as startOfDay, nt as startOfMonth, rt as startOfWeek, I as themeDefaults, L as themeItems, it as toDateKey, G as toneClasses, K as toneColor, q as tones, R as useAnchoredPopup, Q as useApplyTheme, $ as useControlSize, z as useDismiss, S as useFocusTrap, ne as usePopover, k as usePortalContainer, V as useSettings, dn as useTheme, Y as useToast };
|
package/dist/styles.css
CHANGED
|
@@ -2936,6 +2936,23 @@ select:disabled + .ui-select-placeholder {
|
|
|
2936
2936
|
grid-template-columns: var(--ui-columns-base, repeat(1, minmax(0, 1fr)));
|
|
2937
2937
|
justify-items: var(--ui-justify, stretch);
|
|
2938
2938
|
}
|
|
2939
|
+
.ui-main-aside {
|
|
2940
|
+
container: ui-main-aside / inline-size;
|
|
2941
|
+
}
|
|
2942
|
+
.ui-main-aside-grid {
|
|
2943
|
+
display: grid;
|
|
2944
|
+
grid-template-columns: minmax(0, 1fr);
|
|
2945
|
+
gap: calc(4 * var(--spacing));
|
|
2946
|
+
}
|
|
2947
|
+
@container ui-main-aside (min-width: 56rem) {
|
|
2948
|
+
.ui-main-aside-grid {
|
|
2949
|
+
grid-template-columns: minmax(0, 2fr) minmax(20rem, 1fr);
|
|
2950
|
+
}
|
|
2951
|
+
.ui-main-aside-grid > .ui-main-aside-divider {
|
|
2952
|
+
border-inline-start: var(--ui-border-width) solid var(--border);
|
|
2953
|
+
padding-inline-start: calc(4 * var(--spacing));
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2939
2956
|
.ui-grid-item {
|
|
2940
2957
|
grid-column: var(--ui-span-base, span 1 / span 1);
|
|
2941
2958
|
}
|