@sincpro/web-ui 1.9.0 → 1.11.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 (95) hide show
  1. package/dist/components/board/Board.d.ts +51 -0
  2. package/dist/components/board/Board.js +15 -0
  3. package/dist/components/board/index.d.ts +1 -0
  4. package/dist/components/board/index.js +2 -0
  5. package/dist/components/canvas/Canvas.d.ts +14 -0
  6. package/dist/components/canvas/Canvas.js +9 -0
  7. package/dist/components/canvas/canvas.css +19 -0
  8. package/dist/components/canvas/index.d.ts +1 -0
  9. package/dist/components/canvas/index.js +2 -0
  10. package/dist/components/chat/ChatComposer.d.ts +10 -0
  11. package/dist/components/chat/ChatComposer.js +29 -0
  12. package/dist/components/chat/ChatThread.d.ts +13 -0
  13. package/dist/components/chat/ChatThread.js +76 -0
  14. package/dist/components/chat/ConversationList.d.ts +22 -0
  15. package/dist/components/chat/ConversationList.js +22 -0
  16. package/dist/components/chat/index.d.ts +4 -0
  17. package/dist/components/chat/index.js +5 -0
  18. package/dist/components/chat/model.d.ts +30 -0
  19. package/dist/components/chat/model.js +53 -0
  20. package/dist/components/frame/Chart.d.ts +12 -7
  21. package/dist/components/frame/Chart.js +17 -17
  22. package/dist/components/frame/FrameView.d.ts +3 -3
  23. package/dist/components/frame/FrameView.js +79 -26
  24. package/dist/components/frame/model.d.ts +12 -3
  25. package/dist/components/frame/model.js +53 -19
  26. package/dist/components/index.d.ts +4 -0
  27. package/dist/components/index.js +4 -0
  28. package/dist/components/listing/AxisLevels.d.ts +24 -0
  29. package/dist/components/listing/AxisLevels.js +58 -0
  30. package/dist/components/listing/ChartExplorer.d.ts +79 -0
  31. package/dist/components/listing/ChartExplorer.js +114 -0
  32. package/dist/components/listing/ColumnsMenu.d.ts +7 -1
  33. package/dist/components/listing/ColumnsMenu.js +16 -5
  34. package/dist/components/listing/GroupingLevels.d.ts +5 -1
  35. package/dist/components/listing/GroupingLevels.js +7 -4
  36. package/dist/components/listing/ListingBar.js +2 -2
  37. package/dist/components/listing/PivotExplorer.js +5 -36
  38. package/dist/components/listing/index.d.ts +2 -0
  39. package/dist/components/listing/index.js +2 -0
  40. package/dist/components/listing/set.d.ts +3 -1
  41. package/dist/components/preview/FilePreview.d.ts +19 -0
  42. package/dist/components/preview/FilePreview.js +112 -0
  43. package/dist/components/preview/PdfPreview.d.ts +7 -0
  44. package/dist/components/preview/PdfPreview.js +47 -0
  45. package/dist/components/preview/index.d.ts +1 -0
  46. package/dist/components/preview/index.js +2 -0
  47. package/dist/components/record/SmartButtons.js +1 -1
  48. package/dist/components/search/FieldPath.d.ts +54 -0
  49. package/dist/components/search/FieldPath.js +159 -0
  50. package/dist/components/search/FilterBuilder.d.ts +38 -5
  51. package/dist/components/search/FilterBuilder.js +129 -25
  52. package/dist/components/search/SearchBar.js +7 -2
  53. package/dist/components/search/criteria.d.ts +23 -1
  54. package/dist/components/search/index.d.ts +4 -2
  55. package/dist/components/search/index.js +4 -0
  56. package/dist/components/search/paths.d.ts +49 -0
  57. package/dist/components/search/paths.js +75 -0
  58. package/dist/components/shell/TopBar.js +1 -1
  59. package/dist/foundations/calendar.d.ts +15 -0
  60. package/dist/foundations/calendar.js +59 -1
  61. package/dist/foundations/chart.d.ts +126 -0
  62. package/dist/foundations/chart.js +297 -0
  63. package/dist/foundations/copy.d.ts +125 -0
  64. package/dist/foundations/copy.es.js +90 -0
  65. package/dist/foundations/copy.js +84 -0
  66. package/dist/foundations/index.d.ts +2 -1
  67. package/dist/foundations/index.js +4 -1
  68. package/dist/foundations/pivot.d.ts +9 -0
  69. package/dist/foundations/pivot.js +1 -0
  70. package/dist/primitives/chart/Chart.d.ts +39 -0
  71. package/dist/primitives/chart/Chart.js +235 -0
  72. package/dist/primitives/chart/index.d.ts +1 -0
  73. package/dist/primitives/chart/index.js +1 -0
  74. package/dist/primitives/field/Field.js +2 -1
  75. package/dist/primitives/index.d.ts +1 -0
  76. package/dist/primitives/index.js +1 -0
  77. package/dist/primitives/notice/Callout.d.ts +4 -1
  78. package/dist/primitives/notice/Callout.js +12 -2
  79. package/dist/primitives/notice/Notice.d.ts +26 -2
  80. package/dist/primitives/notice/Notice.js +64 -4
  81. package/dist/primitives/notice/Toast.js +10 -1
  82. package/dist/primitives/value/Markdown.d.ts +9 -0
  83. package/dist/primitives/value/Markdown.js +18 -0
  84. package/dist/primitives/value/Metric.d.ts +13 -2
  85. package/dist/primitives/value/Metric.js +25 -3
  86. package/dist/primitives/value/index.d.ts +1 -0
  87. package/dist/primitives/value/index.js +1 -0
  88. package/dist/tokens.css +73 -0
  89. package/dist/views/list/List.d.ts +2 -1
  90. package/dist/views/list/List.js +8 -1
  91. package/dist/views/list/ListView.d.ts +1 -1
  92. package/dist/views/list/ListView.js +37 -5
  93. package/dist/views/list/index.d.ts +1 -1
  94. package/dist/views/list/types.d.ts +34 -0
  95. package/package.json +5 -1
@@ -0,0 +1,235 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { SERIES_COLORS, } from "../../foundations/chart.js";
4
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
5
+ import { Empty } from "../notice/Notice.js";
6
+ import { useMemo, useState } from "react";
7
+ import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, LabelList, Line, LineChart, Pie, PieChart, ReferenceLine, Tooltip, XAxis, YAxis, } from "recharts";
8
+ const MAX_BAR = 24;
9
+ const RADIUS = 4;
10
+ function colorOf(point, index, alone) {
11
+ /* The tail and the previous period are context, not the subject: the de-emphasis grey. */
12
+ if (point.rest === true || point.previous === true)
13
+ return "var(--color-muted)";
14
+ /* The current period of a comparison is the one series that matters. */
15
+ if (point.id === "\u0000current")
16
+ return "var(--color-data)";
17
+ if (alone)
18
+ return "var(--color-data)";
19
+ return `var(--color-series-${String((index % SERIES_COLORS) + 1)})`;
20
+ }
21
+ /** A swatch: identity rides the mark beside the text, never the text's colour. */
22
+ function Swatch({ color, line = false }) {
23
+ return (_jsx("span", { "aria-hidden": true, className: `shrink-0 ${line ? "h-0.5 w-3 rounded-pill" : "size-2.5 rounded-mark"}`, style: { background: color } }));
24
+ }
25
+ export function Chart({ data, kind = "bar", stacked: stackedProp = false, horizontal: horizontalProp, onPoint, label, height, }) {
26
+ const copy = useUiCopy();
27
+ const words = copy.chart;
28
+ const [off, setOff] = useState(() => new Set());
29
+ const alone = data.series.length <= 1;
30
+ /* Stacking one series is the series: it would only cost the rounded tip and the number. */
31
+ const stacked = stackedProp && !alone && data.compare !== true;
32
+ const number = useMemo(
33
+ /* Grouping ALWAYS: Spanish writes 7000 but 14.000, and one axis cannot say both. */
34
+ () => new Intl.NumberFormat(copy.locale, { maximumFractionDigits: 2, useGrouping: "always" }), [copy.locale]);
35
+ const compact = useMemo(() => new Intl.NumberFormat(copy.locale, { notation: "compact", maximumFractionDigits: 1 }), [copy.locale]);
36
+ const format = (value) => data.measure.format?.(value) ?? number.format(value);
37
+ const peak = Math.max(0, ...data.values.flatMap((row) => row.map((value) => Math.abs(value ?? 0))));
38
+ const negative = data.values.some((row) => row.some((value) => (value ?? 0) < 0));
39
+ /* In full up to the millions (7.000, 14.000), compact from there (2,5 M): Spanish compact
40
+ thousands come out as «7 K» next to «14 k» on the same axis. */
41
+ const tick = (value) => peak >= 1_000_000 ? compact.format(value) : number.format(value);
42
+ /* One object per category, the shape Recharts reads: `s0`, `s1`… per series. */
43
+ const rows = useMemo(() => data.categories.map((category, c) => {
44
+ const row = { label: category.label };
45
+ data.series.forEach((_, s) => {
46
+ row[`s${String(s)}`] = data.values[c]?.[s] ?? null;
47
+ });
48
+ return row;
49
+ }), [data]);
50
+ const series = data.series.map((point, index) => ({
51
+ point,
52
+ index,
53
+ key: `s${String(index)}`,
54
+ color: colorOf(point, index, alone),
55
+ shown: !off.has(point.id),
56
+ }));
57
+ const visible = series.filter((one) => one.shown);
58
+ const open = (categoryIndex, seriesIndex) => {
59
+ const category = data.categories[categoryIndex];
60
+ if (onPoint === undefined || category === undefined || category.rest === true)
61
+ return;
62
+ if (seriesIndex === undefined)
63
+ return onPoint(category.key);
64
+ const one = data.series[seriesIndex];
65
+ /* The tail and the previous period are not records of THIS set: nothing to open. */
66
+ if (one === undefined || one.rest === true || one.previous === true)
67
+ return;
68
+ onPoint(category.key, one.key);
69
+ };
70
+ const hidden = data.hiddenSeries + data.hiddenCategories;
71
+ const note = hidden === 0 ? null : (_jsx("p", { className: "text-micro text-muted", children: fillCopy(words.hidden, { count: hidden }) }));
72
+ if (data.categories.length === 0 || data.series.length === 0) {
73
+ return _jsx(Empty, { sentence: words.empty });
74
+ }
75
+ /* ── The pie: one whole, split. ───────────────────────────────── */
76
+ if (kind === "pie") {
77
+ if (data.totals.some((value) => (value ?? 0) < 0)) {
78
+ return _jsx(Empty, { sentence: words.pieNegative });
79
+ }
80
+ const slices = data.categories
81
+ .map((category, index) => ({
82
+ category,
83
+ index,
84
+ value: data.totals[index] ?? 0,
85
+ color: colorOf(category, index, false),
86
+ }))
87
+ .filter((slice) => slice.value > 0);
88
+ const whole = slices.reduce((total, slice) => total + slice.value, 0);
89
+ if (whole === 0)
90
+ return _jsx(Empty, { sentence: words.empty });
91
+ const percent = new Intl.NumberFormat(copy.locale, {
92
+ style: "percent",
93
+ maximumFractionDigits: 1,
94
+ });
95
+ return (
96
+ /* The pie asks ITS width, not the window's: in a narrow board tile the legend goes
97
+ under the ring instead of being squeezed beside it. */
98
+ _jsxs("figure", { "aria-label": label, className: "@container flex min-w-0 flex-col gap-3", children: [_jsxs("div", { className: "flex min-w-0 flex-col items-center gap-6 @lg:flex-row", children: [_jsxs("div", { className: "relative aspect-square w-full max-w-64 shrink-0", children: [_jsxs(PieChart, { responsive: true, width: "100%", height: "100%", title: label, children: [_jsx(Pie, { data: slices.map((slice) => ({
99
+ name: slice.category.label,
100
+ value: slice.value,
101
+ })), dataKey: "value", nameKey: "name", innerRadius: "62%", outerRadius: "98%",
102
+ /* From twelve o'clock, clockwise: how a whole is read. */
103
+ startAngle: 90, endAngle: -270, stroke: "var(--color-surface)", strokeWidth: 2, isAnimationActive: false, ...(onPoint === undefined
104
+ ? {}
105
+ : { onClick: (_, at) => open(slices[at]?.index ?? -1) }), cursor: onPoint === undefined ? "default" : "pointer", children: slices.map((slice) => (_jsx(Cell, { fill: slice.color }, slice.category.id))) }), _jsx(Tooltip, { isAnimationActive: false, content: (props) => _jsx(Readout, { ...props, format: format }) })] }), _jsxs("div", { className: "pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center", children: [_jsx("span", { className: "text-title font-semibold text-ink", children: format(whole) }), _jsx("span", { className: "text-micro text-muted", children: data.measure.header })] })] }), _jsx("ul", { className: "flex w-full max-w-sm min-w-0 flex-col gap-1.5", "aria-label": label, children: slices.map((slice) => (_jsxs("li", { className: "flex min-w-0 items-center gap-2 text-meta", children: [_jsx(Swatch, { color: slice.color }), _jsx("span", { className: "min-w-0 flex-1 truncate text-ink", children: slice.category.label }), _jsx("span", { className: "shrink-0 text-ink tabular-nums", children: format(slice.value) }), _jsx("span", { className: "w-12 shrink-0 text-right text-muted tabular-nums", children: percent.format(slice.value / whole) })] }, slice.category.id))) })] }), note] }));
106
+ }
107
+ /* ── Bars and lines: categories along an axis. ────────────────── */
108
+ const longest = Math.max(0, ...data.categories.map((category) => category.label.length));
109
+ const horizontal = kind === "bar" && (horizontalProp ?? (data.categories.length > 10 || longest > 18));
110
+ const perCategory = stacked || visible.length <= 1 ? 1 : visible.length;
111
+ const size = height !== undefined
112
+ ? { height }
113
+ : horizontal
114
+ ? { height: `${String(data.categories.length * (1 + perCategory * 0.75) + 3)}rem` }
115
+ : {};
116
+ const grid = (_jsx(CartesianGrid, { vertical: horizontal, horizontal: !horizontal, stroke: "var(--color-line)" }));
117
+ const tickStyle = { fill: "currentColor" };
118
+ const valueAxis = {
119
+ type: "number",
120
+ tickFormatter: tick,
121
+ tick: tickStyle,
122
+ tickLine: false,
123
+ axisLine: false,
124
+ };
125
+ const categoryAxis = {
126
+ type: "category",
127
+ dataKey: "label",
128
+ tick: tickStyle,
129
+ tickLine: false,
130
+ axisLine: { stroke: "var(--color-line-strong)" },
131
+ };
132
+ const axes = horizontal ? (_jsxs(_Fragment, { children: [_jsx(XAxis, { ...valueAxis }), _jsx(YAxis, { ...categoryAxis, width: "auto", interval: 0 })] })) : (_jsxs(_Fragment, { children: [_jsx(XAxis, { ...categoryAxis, interval: "preserveStartEnd", minTickGap: 8 }), _jsx(YAxis, { ...valueAxis, width: "auto" })] }));
133
+ const zero = negative ? (_jsx(ReferenceLine, { ...(horizontal ? { x: 0 } : { y: 0 }), stroke: "var(--color-line-strong)" })) : null;
134
+ const readout = (props) => (_jsx(Readout, { ...props, format: format, compare: data.compare === true }));
135
+ /* The value rides the tip of its bar when there is ONE series: the axis gives the scale,
136
+ the tip gives the number, and nobody has to hover thirty bars to read them. With
137
+ several series it would be a number on every mark, which is noise. */
138
+ const tips = !stacked && visible.length === 1 && (horizontal || data.categories.length <= 12);
139
+ let plot;
140
+ if (kind === "bar") {
141
+ plot = (_jsxs(BarChart, { data: rows, layout: horizontal ? "vertical" : "horizontal", responsive: true, width: "100%", height: "100%", title: label, barGap: 2, barCategoryGap: "20%", margin: {
142
+ top: tips && !horizontal ? 20 : 8,
143
+ right: tips && horizontal ? 56 : 8,
144
+ bottom: 0,
145
+ left: 0,
146
+ }, stackOffset: negative ? "sign" : "none", children: [grid, axes, zero, _jsx(Tooltip, { isAnimationActive: false, cursor: { fill: "var(--color-ink)", fillOpacity: 0.04 }, content: readout }), visible.map((one) => (_jsx(Bar, { dataKey: one.key, name: one.point.label, fill: one.color, maxBarSize: MAX_BAR, isAnimationActive: false, ...(stacked
147
+ ? { stackId: "stack", stroke: "var(--color-surface)", strokeWidth: 1 }
148
+ : {
149
+ radius: horizontal
150
+ ? [0, RADIUS, RADIUS, 0]
151
+ : [RADIUS, RADIUS, 0, 0],
152
+ }), cursor: onPoint === undefined ? "default" : "pointer", ...(onPoint === undefined
153
+ ? {}
154
+ : { onClick: (_, at) => open(at, one.index) }), children: tips ? (_jsx(LabelList, { dataKey: one.key, content: (props) => (_jsx(Tip, { viewBox: props.viewBox, value: props.value, horizontal: horizontal, format: format })) })) : null }, one.point.id)))] }));
155
+ }
156
+ else {
157
+ const dots = rows.length <= 24;
158
+ const common = {
159
+ data: rows,
160
+ responsive: true,
161
+ width: "100%",
162
+ height: "100%",
163
+ title: label,
164
+ margin: { top: 8, right: 12, bottom: 0, left: 0 },
165
+ ...(onPoint === undefined
166
+ ? {}
167
+ : {
168
+ onClick: (state) => {
169
+ const at = Number(state.activeIndex);
170
+ if (Number.isInteger(at))
171
+ open(at, alone ? 0 : undefined);
172
+ },
173
+ style: { cursor: "pointer" },
174
+ }),
175
+ };
176
+ const ring = { r: 5, stroke: "var(--color-surface)", strokeWidth: 2 };
177
+ const tooltip = (_jsx(Tooltip, { isAnimationActive: false, cursor: { stroke: "var(--color-line-strong)" }, content: readout }));
178
+ plot = stacked ? (_jsxs(AreaChart, { ...common, stackOffset: negative ? "sign" : "none", children: [grid, axes, zero, tooltip, visible.map((one) => (_jsx(Area, { type: "monotone", dataKey: one.key, name: one.point.label, stackId: "stack", stroke: one.color, strokeWidth: 2, fill: one.color, fillOpacity: 0.12, dot: false, activeDot: { ...ring, fill: one.color }, isAnimationActive: false }, one.point.id)))] })) : (_jsxs(LineChart, { ...common, children: [grid, axes, zero, tooltip, visible.map((one) => (_jsx(Line, { type: "monotone", dataKey: one.key, name: one.point.label, stroke: one.color, strokeWidth: 2, dot: dots
179
+ ? { r: 4, fill: one.color, stroke: "var(--color-surface)", strokeWidth: 2 }
180
+ : false, activeDot: { ...ring, fill: one.color }, connectNulls: false, isAnimationActive: false }, one.point.id)))] }));
181
+ }
182
+ return (_jsxs("figure", { "aria-label": label, className: "flex min-w-0 flex-col gap-3", children: [alone ? null : (_jsx("ul", { className: "flex min-w-0 flex-wrap items-center gap-x-1 gap-y-1", children: series.map((one) => (_jsx("li", { className: "min-w-0", children: _jsxs("button", { type: "button", "aria-pressed": one.shown, "aria-label": fillCopy(one.shown ? words.hideSeries : words.showSeries, {
183
+ name: one.point.label,
184
+ }),
185
+ /* The last one on cannot be turned off: a chart with nothing on it reads
186
+ as broken, not as «you hid everything». */
187
+ disabled: one.shown && visible.length === 1, onClick: () => setOff((current) => {
188
+ const next = new Set(current);
189
+ if (next.has(one.point.id))
190
+ next.delete(one.point.id);
191
+ else
192
+ next.add(one.point.id);
193
+ return next;
194
+ }), className: `inline-flex max-w-full min-w-0 items-center gap-1.5 rounded-control px-1.5 py-0.5 text-meta transition-colors duration-(--duration-instant) outline-0 hover:bg-ink/5 focus-visible:outline-2 focus-visible:outline-primary ${one.shown ? "text-ink" : "text-muted line-through"}`, children: [_jsx(Swatch, { color: one.shown ? one.color : "var(--color-line-strong)", line: kind === "line" }), _jsx("span", { className: "truncate", children: one.point.label })] }) }, one.point.id))) })), _jsx("div", { className: `min-w-0 text-micro text-muted ${height === undefined && !horizontal ? "h-72" : ""}`, style: size, children: plot }), note] }));
195
+ }
196
+ /**
197
+ * The number at the tip of a bar, on ONE line. Recharts' own label wraps to the bar's
198
+ * width, which breaks «Bs. 51.100» in two over a 24 px bar.
199
+ */
200
+ function Tip({ viewBox, value, horizontal, format, }) {
201
+ if (typeof value !== "number" || typeof viewBox !== "object" || viewBox === null)
202
+ return null;
203
+ const box = viewBox;
204
+ const { x = 0, y = 0, width = 0, height = 0 } = box;
205
+ /* A negative bar has its tip on the other side of the zero. */
206
+ const below = value < 0;
207
+ return horizontal ? (_jsx("text", { x: below ? x + width - 6 : x + width + 6, y: y + height / 2, textAnchor: below ? "end" : "start", dominantBaseline: "central", fill: "var(--color-ink)", className: "tabular-nums", children: format(value) })) : (_jsx("text", { x: x + width / 2, y: below ? y + height + 6 : y - 6, textAnchor: "middle", dominantBaseline: below ? "hanging" : "auto", fill: "var(--color-ink)", className: "tabular-nums", children: format(value) }));
208
+ }
209
+ /** What hovering (or arrowing to) a category says: its name, and each series' number. */
210
+ function Readout({ active, payload, label, format, compare = false, }) {
211
+ const copy = useUiCopy();
212
+ const words = copy.chart;
213
+ const percent = useMemo(() => new Intl.NumberFormat(copy.locale, {
214
+ style: "percent",
215
+ maximumFractionDigits: 1,
216
+ signDisplay: "exceptZero",
217
+ }), [copy.locale]);
218
+ if (active !== true || payload === undefined || payload.length === 0)
219
+ return null;
220
+ const heading = label ?? payload[0]?.name;
221
+ /* Now against before, said as a change: the number a comparison is asked for. */
222
+ const now = payload[0]?.value;
223
+ const before = payload[1]?.value;
224
+ const change = compare && typeof now === "number" && typeof before === "number" && before !== 0
225
+ ? (now - before) / Math.abs(before)
226
+ : null;
227
+ return (_jsxs("div", { className: "max-w-xs min-w-40 rounded-control border border-line-strong bg-surface px-3 py-2 text-micro text-ink shadow-float", children: [heading === undefined || heading === "" ? null : (_jsx("p", { className: "mb-1.5 truncate font-medium", children: String(heading) })), _jsx("ul", { className: "flex flex-col gap-1", children: payload.map((entry) => {
228
+ const color = typeof entry.color === "string"
229
+ ? entry.color
230
+ : typeof entry.payload?.fill === "string"
231
+ ? entry.payload.fill
232
+ : "var(--color-data)";
233
+ return (_jsxs("li", { className: "flex items-center gap-2", children: [_jsx(Swatch, { color: color }), _jsx("span", { className: "min-w-0 flex-1 truncate text-muted", children: String(entry.name) }), _jsx("span", { className: "shrink-0 tabular-nums", children: typeof entry.value === "number" ? format(entry.value) : "—" })] }, String(entry.dataKey ?? entry.name)));
234
+ }) }), change === null ? null : (_jsxs("p", { className: "mt-1.5 flex items-center justify-between gap-3 border-t border-line pt-1.5", children: [_jsx("span", { className: "text-muted", children: words.change }), _jsx("span", { className: "tabular-nums", children: percent.format(change) })] }))] }));
235
+ }
@@ -0,0 +1 @@
1
+ export { Chart, type ChartProps } from "./Chart.js";
@@ -0,0 +1 @@
1
+ export { Chart } from "./Chart.js";
@@ -12,6 +12,7 @@ import { useSheetLayout } from "./layout.js";
12
12
  import { describedByOf, NoteCard, NoteFlag, } from "./note.js";
13
13
  import { Hint } from "../hint/Hint.js";
14
14
  import { Popover } from "../overlay/Popover.js";
15
+ import { CopyButton } from "../value/Copyable.js";
15
16
  import { roundTo } from "../value/rounding.js";
16
17
  import { AlertCircle, Check, ChevronDown, ChevronUp } from "lucide-react";
17
18
  import { useId, useRef } from "react";
@@ -76,7 +77,7 @@ export function Field({ label, hint, error, required = false, children, htmlFor,
76
77
  /* The render prop gets the same context as a control written directly: a system control
77
78
  inside it then also finds the label that names it, not only the id it is handed. */
78
79
  const content = (_jsx(FieldIdsContext.Provider, { value: ids, children: _jsx("div", { ref: shown, className: "contents", children: typeof children === "function" ? children(ids) : children }) }));
79
- const body = (_jsxs(_Fragment, { children: [mode === undefined ? (content) : (_jsx(FormModeProvider, { value: mode, children: content })), error === undefined ? null : (_jsxs("p", { id: errorId, role: "alert", className: "flex items-start gap-1.5 text-micro text-danger", children: [_jsx(AlertCircle, { className: "mt-px size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "max-w-prose", children: error })] }))] }));
80
+ const body = (_jsxs(_Fragment, { children: [mode === undefined ? (content) : (_jsx(FormModeProvider, { value: mode, children: content })), error === undefined ? null : (_jsxs("p", { id: errorId, role: "alert", className: "flex items-start gap-1.5 text-micro text-danger", children: [_jsx(AlertCircle, { className: "mt-px size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "max-w-prose", children: error }), _jsx(CopyButton, { label: copy.copyable.report, value: () => `${label}: ${error}` })] }))] }));
80
81
  if (inline) {
81
82
  return (_jsxs("div", { className: "grid-label grid min-w-0 items-start gap-x-4 gap-y-1 group/field", children: [labelNode, _jsx("div", { className: "flex min-w-0 flex-col gap-1", children: body }), action === undefined ? null : (_jsx("div", { "data-under-control": true, className: "flex items-center gap-2", children: action })), noteCard] }));
82
83
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./block/index.js";
2
2
  export * from "./button/index.js";
3
3
  export * from "./cell/index.js";
4
+ export * from "./chart/index.js";
4
5
  export * from "./choice/index.js";
5
6
  export * from "./date/index.js";
6
7
  export * from "./dialog/index.js";
@@ -2,6 +2,7 @@
2
2
  export * from "./block/index.js";
3
3
  export * from "./button/index.js";
4
4
  export * from "./cell/index.js";
5
+ export * from "./chart/index.js";
5
6
  export * from "./choice/index.js";
6
7
  export * from "./date/index.js";
7
8
  export * from "./dialog/index.js";
@@ -45,5 +45,8 @@ export type CalloutProps = {
45
45
  dismissLabel?: string;
46
46
  /** Un ícono propio, cuando el del tono no dice lo suficiente. */
47
47
  icon?: LucideIcon;
48
+ /** Lo que se copia con «Copiar el error» cuando el tono es `bad`. Sin esto, la
49
+ * oración (si es texto) con el título. Para un aviso con detalle técnico, pasarlo acá. */
50
+ report?: string;
48
51
  };
49
- export declare function Callout({ children, tone, title, action, onDismiss, dismissLabel, icon, }: CalloutProps): import("react").JSX.Element;
52
+ export declare function Callout({ children, tone, title, action, onDismiss, dismissLabel, icon, report, }: CalloutProps): import("react").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { byDensity, useDensity } from "../../foundations/density.js";
4
+ import { currentPage, ErrorCopy, errorReport, } from "./Notice.js";
4
5
  import { AlertTriangle, CheckCircle2, Info, OctagonAlert, X } from "lucide-react";
5
6
  const ICON = {
6
7
  info: Info,
@@ -17,12 +18,21 @@ const SKIN = {
17
18
  bad: "border-bad/25 bg-bad/8 text-bad",
18
19
  good: "border-good/25 bg-good/8 text-good",
19
20
  };
20
- export function Callout({ children, tone = "info", title, action, onDismiss, dismissLabel, icon, }) {
21
+ export function Callout({ children, tone = "info", title, action, onDismiss, dismissLabel, icon, report, }) {
21
22
  const d = useDensity();
22
23
  const Icon = icon ?? ICON[tone];
24
+ /* The text a person would paste: the sentence, or what the caller names. A title that
25
+ is text becomes the report's heading; without one the sentence is the heading. */
26
+ const sentence = report ?? (typeof children === "string" ? children : "");
27
+ const copyable = tone === "bad" && sentence !== "";
23
28
  return (_jsxs("div", {
24
29
  /* `status` y no `alert`: `alert` interrumpe al lector de pantalla y se
25
30
  reserva para lo que pasó JUSTO AHORA. Un aviso que ya estaba cuando la
26
31
  pantalla abrió no interrumpe nada. */
27
- role: "status", className: `flex min-w-0 items-start gap-2.5 rounded-box border ${SKIN[tone]} ${byDensity(d, "px-3 py-2.5", "px-2.5 py-2")}`, children: [_jsx(Icon, { className: "mt-0.5 size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-wrap items-start gap-x-3 gap-y-2", children: [_jsxs("div", { className: "flex min-w-0 flex-1 basis-(--container-name) flex-col gap-1", children: [title === undefined ? null : (_jsx("p", { className: "text-meta font-medium text-ink", children: title })), _jsx("div", { className: "min-w-0 text-meta text-ink", children: children })] }), action === undefined ? null : _jsx("span", { className: "shrink-0", children: action })] }), onDismiss === undefined ? null : (_jsx("button", { type: "button", onClick: onDismiss, "aria-label": dismissLabel ?? "cerrar", title: dismissLabel ?? "cerrar", className: "-mr-1 shrink-0 rounded-control p-0.5 text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink", children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2 }) }))] }));
32
+ role: "status", className: `flex min-w-0 items-start gap-2.5 rounded-box border ${SKIN[tone]} ${byDensity(d, "px-3 py-2.5", "px-2.5 py-2")}`, children: [_jsx(Icon, { className: "mt-0.5 size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-wrap items-start gap-x-3 gap-y-2", children: [_jsxs("div", { className: "flex min-w-0 flex-1 basis-(--container-name) flex-col gap-1", children: [title === undefined ? null : (_jsx("p", { className: "text-meta font-medium text-ink", children: title })), _jsx("div", { className: "min-w-0 text-meta text-ink", children: children })] }), action === undefined ? null : _jsx("span", { className: "shrink-0", children: action }), copyable ? (_jsx("span", { className: "shrink-0", children: _jsx(ErrorCopy, { report: () => errorReport({
33
+ heading: typeof title === "string" ? title : "",
34
+ sentence: typeof title === "string" ? sentence : undefined,
35
+ at: new Date(),
36
+ page: currentPage(),
37
+ }) }) })) : null] }), onDismiss === undefined ? null : (_jsx("button", { type: "button", onClick: onDismiss, "aria-label": dismissLabel ?? "cerrar", title: dismissLabel ?? "cerrar", className: "-mr-1 shrink-0 rounded-control p-0.5 text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink", children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2 }) }))] }));
28
38
  }
@@ -1,5 +1,5 @@
1
1
  import { type LucideIcon } from "lucide-react";
2
- import type { ReactNode } from "react";
2
+ import { type ReactNode } from "react";
3
3
  export declare function Skeleton({ rows, label, }: {
4
4
  /** How many row-silhouettes. Six is a screen of a list, not a guess at
5
5
  * the real count. */
@@ -25,10 +25,34 @@ align, }: {
25
25
  * replacing it with one of our own is what forces you to go to the console to
26
26
  * find out what happened.
27
27
  */
28
- export declare function Failed({ heading, sentence, action, }: {
28
+ /**
29
+ * The text a person pastes into a ticket or a chat when something broke: what
30
+ * the screen said, the technical detail if there is one, when it happened and
31
+ * where. Pure, so the same report reads the same in every error.
32
+ */
33
+ export declare function errorReport(report: {
34
+ heading: string;
35
+ sentence?: string;
36
+ detail?: string;
37
+ at: Date;
38
+ page?: string;
39
+ }): string;
40
+ export declare function currentPage(): string | undefined;
41
+ export declare function useErrorCopy(report: () => string): {
42
+ said: string;
43
+ state: "idle" | "done" | "failed";
44
+ run: () => Promise<void>;
45
+ };
46
+ export declare function ErrorCopy({ report }: {
47
+ report: () => string;
48
+ }): import("react").JSX.Element;
49
+ export declare function Failed({ heading, sentence, action, detail, }: {
29
50
  heading: string;
30
51
  sentence: string;
31
52
  action?: ReactNode;
53
+ /** The technical text (an HTTP status, a server message, an id). Drawn in mono
54
+ * so it reads as data, and included in what «Copiar el error» copies. */
55
+ detail?: string;
32
56
  }): import("react").JSX.Element;
33
57
  /**
34
58
  * Nobody knows how to draw this. It carries the full identifier because that is
@@ -1,7 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useUiCopy } from "../../foundations/copy.js";
3
4
  import { byDensity, useDensity } from "../../foundations/density.js";
4
- import { AlertTriangle, PackageX } from "lucide-react";
5
+ import { Button } from "../button/Button.js";
6
+ import { AlertTriangle, Check, Copy, PackageX } from "lucide-react";
7
+ import { useEffect, useRef, useState } from "react";
5
8
  /**
6
9
  * Context: the ways a view says there is no content yet, and they are
7
10
  * different because each one is fixed by a different person.
@@ -48,15 +51,72 @@ align = "center", }) {
48
51
  * replacing it with one of our own is what forces you to go to the console to
49
52
  * find out what happened.
50
53
  */
51
- export function Failed({ heading, sentence, action, }) {
52
- return (_jsxs("div", { className: "rounded-control border border-bad/40 bg-bad/5 px-3 py-2.5", children: [_jsx("p", { className: "text-body font-medium text-bad", children: heading }), _jsx("p", { className: "mt-1.5 max-w-prose text-lead leading-relaxed text-ink", children: sentence }), action === undefined ? null : _jsx("div", { className: "mt-2.5", children: action })] }));
54
+ /**
55
+ * The text a person pastes into a ticket or a chat when something broke: what
56
+ * the screen said, the technical detail if there is one, when it happened and
57
+ * where. Pure, so the same report reads the same in every error.
58
+ */
59
+ export function errorReport(report) {
60
+ /* An empty heading (a callout without a title) is left out, not written as a blank line. */
61
+ const lines = report.heading === "" ? [] : [report.heading];
62
+ if (report.sentence)
63
+ lines.push(report.sentence);
64
+ if (report.detail)
65
+ lines.push(report.detail);
66
+ lines.push(report.at.toISOString());
67
+ if (report.page)
68
+ lines.push(report.page);
69
+ return lines.join("\n");
70
+ }
71
+ /* The page is read when the button is pressed, not when the error is drawn: a
72
+ report copied later still says where the person was. */
73
+ export function currentPage() {
74
+ return typeof window === "undefined" ? undefined : window.location.href;
75
+ }
76
+ /* A visible, labelled button, not the icon-only `CopyButton`: on an error the
77
+ person has to SEE that there is something to copy, and «Copiar el error» says
78
+ what it copies. Its feedback is said in words too, and a failed copy is said
79
+ as a failure — never a check mark over a clipboard that did not get the text. */
80
+ export function useErrorCopy(report) {
81
+ const copy = useUiCopy();
82
+ const [state, setState] = useState("idle");
83
+ const timer = useRef(null);
84
+ useEffect(() => () => {
85
+ if (timer.current !== null)
86
+ clearTimeout(timer.current);
87
+ }, []);
88
+ async function run() {
89
+ if (timer.current !== null)
90
+ clearTimeout(timer.current);
91
+ try {
92
+ await navigator.clipboard.writeText(report());
93
+ setState("done");
94
+ }
95
+ catch {
96
+ setState("failed");
97
+ }
98
+ timer.current = setTimeout(() => setState("idle"), 2000);
99
+ }
100
+ const said = state === "done"
101
+ ? copy.copyable.done
102
+ : state === "failed"
103
+ ? copy.copyable.failed
104
+ : copy.copyable.report;
105
+ return { said, state, run };
106
+ }
107
+ export function ErrorCopy({ report }) {
108
+ const { said, state, run } = useErrorCopy(report);
109
+ return (_jsx(Button, { role: state === "failed" ? "danger" : "secondary", size: "sm", icon: state === "done" ? Check : Copy, onClick: () => void run(), children: said }));
110
+ }
111
+ export function Failed({ heading, sentence, action, detail, }) {
112
+ return (_jsxs("div", { className: "rounded-control border border-bad/40 bg-bad/5 px-4 py-3", children: [_jsx("p", { className: "text-body font-medium text-bad", children: heading }), _jsx("p", { className: "mt-1.5 max-w-prose text-lead leading-relaxed text-ink", children: sentence }), detail === undefined ? null : (_jsx("p", { className: "mt-2 max-w-prose font-mono text-micro break-words text-muted select-text", children: detail })), _jsxs("div", { className: "mt-3 flex flex-wrap items-center gap-x-4 gap-y-2", children: [action === undefined ? null : _jsx("div", { children: action }), _jsx(ErrorCopy, { report: () => errorReport({ heading, sentence, detail, at: new Date(), page: currentPage() }) })] })] }));
53
113
  }
54
114
  /**
55
115
  * Nobody knows how to draw this. It carries the full identifier because that is
56
116
  * the only thing that makes it fixable.
57
117
  */
58
118
  export function Missing({ heading, detail, icon: Icon = PackageX, tone = "warn", }) {
59
- return (_jsxs("div", { className: "flex h-full min-h-24 flex-col items-center justify-center gap-2 p-6 text-center", children: [_jsx(Icon, { className: `size-(--size-icon-lg) ${tone === "bad" ? "text-bad" : "text-warn"}`, strokeWidth: 1.75 }), _jsx("p", { className: "text-meta font-medium text-ink", children: heading }), detail === undefined ? null : (_jsx("p", { className: "max-w-short font-mono text-micro break-all text-muted", children: detail }))] }));
119
+ return (_jsxs("div", { className: "flex h-full min-h-24 flex-col items-center justify-center gap-2 p-6 text-center", children: [_jsx(Icon, { className: `size-(--size-icon-lg) ${tone === "bad" ? "text-bad" : "text-warn"}`, strokeWidth: 1.75 }), _jsx("p", { className: "text-meta font-medium text-ink", children: heading }), detail === undefined ? null : (_jsx("p", { className: "max-w-short font-mono text-micro break-words text-muted select-text", children: detail })), _jsx(ErrorCopy, { report: () => errorReport({ heading, detail, at: new Date(), page: currentPage() }) })] }));
60
120
  }
61
121
  /** The icon `Missing` uses for what broke while being drawn, so that whoever
62
122
  * composes does not have to choose it. */
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useUiCopy } from "../../foundations/copy.js";
4
4
  import { cn, focusRing } from "../../foundations/variants.js";
5
+ import { currentPage, errorReport, useErrorCopy, } from "./Notice.js";
5
6
  import { CheckCircle2, Info, TriangleAlert, X, XCircle } from "lucide-react";
6
7
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
7
8
  import { Button as AriaButton, Link as AriaLink, Text, UNSTABLE_Toast as AriaToast, UNSTABLE_ToastContent as ToastContent, UNSTABLE_ToastQueue as ToastQueue, UNSTABLE_ToastRegion as ToastRegion, } from "react-aria-components";
@@ -135,7 +136,15 @@ function ToastCard({ toast, queued, queue, }) {
135
136
  const Icon = ICON[tone];
136
137
  const close = () => queue.close(queued.key);
137
138
  const action = toast.action;
138
- return (_jsxs(AriaToast, { toast: queued, className: ({ isFocusVisible }) => cn("flex min-w-0 items-start gap-2.5 rounded-panel border border-line bg-surface px-3.5 py-3 shadow-float outline-offset-2", focusRing({ isFocusVisible })), children: [_jsx(Icon, { className: `mt-px size-(--size-icon-md) shrink-0 ${TONE[tone]}`, strokeWidth: 2, "aria-hidden": true }), _jsxs(ToastContent, { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsx(Text, { slot: "title", className: "text-meta text-ink", children: toast.message }), toast.detail === undefined ? null : (_jsx(Text, { slot: "description", className: "text-micro text-muted", children: toast.detail }))] }), action === undefined ? null : action.href !== undefined ? (_jsx(AriaLink, { href: action.href, onPress: close, className: ({ isFocusVisible }) => cn(LINK, "mt-px", focusRing({ isFocusVisible })), children: action.label })) : (_jsx(AriaButton, { onPress: () => {
139
+ /* Only an error is worth copying whole: what it said, the server's reason, when, where.
140
+ The hook runs for every toast so the rules of hooks hold; only a bad one draws it. */
141
+ const errorCopy = useErrorCopy(() => errorReport({
142
+ heading: toast.message,
143
+ detail: toast.detail,
144
+ at: new Date(),
145
+ page: currentPage(),
146
+ }));
147
+ return (_jsxs(AriaToast, { toast: queued, className: ({ isFocusVisible }) => cn("flex min-w-0 items-start gap-2.5 rounded-panel border border-line bg-surface px-3.5 py-3 shadow-float outline-offset-2", focusRing({ isFocusVisible })), children: [_jsx(Icon, { className: `mt-px size-(--size-icon-md) shrink-0 ${TONE[tone]}`, strokeWidth: 2, "aria-hidden": true }), _jsxs(ToastContent, { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsx(Text, { slot: "title", className: "text-meta text-ink", children: toast.message }), toast.detail === undefined ? null : (_jsx(Text, { slot: "description", className: "text-micro text-muted", children: toast.detail }))] }), tone !== "bad" ? null : (_jsx(AriaButton, { onPress: () => void errorCopy.run(), className: ({ isFocusVisible }) => cn(LINK, "mt-px", focusRing({ isFocusVisible })), children: errorCopy.said })), action === undefined ? null : action.href !== undefined ? (_jsx(AriaLink, { href: action.href, onPress: close, className: ({ isFocusVisible }) => cn(LINK, "mt-px", focusRing({ isFocusVisible })), children: action.label })) : (_jsx(AriaButton, { onPress: () => {
139
148
  action.onSelect?.();
140
149
  close();
141
150
  }, className: ({ isFocusVisible }) => cn(LINK, "mt-px", focusRing({ isFocusVisible })), children: action.label })), _jsx(AriaButton, { slot: "close", "aria-label": copy.shell.closeNotice, className: ({ isFocusVisible }) => cn("-mt-0.5 -mr-1 inline-flex size-6 shrink-0 cursor-default items-center justify-center rounded-pill text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink pressed:bg-ink/10", focusRing({ isFocusVisible })), children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }) })] }));
@@ -0,0 +1,9 @@
1
+ export type MarkdownProps = {
2
+ /** The markdown source. Plain text is valid markdown too. */
3
+ children: string;
4
+ /** The text is still arriving: hold back what cannot be read yet. */
5
+ streaming?: boolean;
6
+ /** The accessible name when the document is the point of the screen. */
7
+ label?: string;
8
+ };
9
+ export declare function Markdown({ children, streaming, label }: MarkdownProps): import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Streamdown } from "streamdown";
4
+ /* The document's own rhythm, in tokens. The arbitrary variants only select the
5
+ descendants; every value is a token. A heading is the same size as the rest
6
+ of the product's headings, not a browser default. */
7
+ const BODY = "max-w-prose text-body leading-relaxed text-ink " +
8
+ "[&_p]:mt-2 [&_p:first-child]:mt-0 " +
9
+ "[&_h1]:mt-4 [&_h1]:text-display [&_h1]:font-semibold " +
10
+ "[&_h2]:mt-4 [&_h2]:text-lead [&_h2]:font-semibold " +
11
+ "[&_h3]:mt-3 [&_h3]:text-body [&_h3]:font-semibold " +
12
+ "[&_ul]:mt-2 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:mt-2 [&_ol]:list-decimal [&_ol]:pl-5 " +
13
+ "[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-4 " +
14
+ "[&_code]:rounded-control [&_code]:bg-ink/6 [&_code]:px-1 [&_code]:font-mono [&_code]:text-micro " +
15
+ "[&_blockquote]:mt-2 [&_blockquote]:border-l-2 [&_blockquote]:border-line-strong [&_blockquote]:pl-3 [&_blockquote]:text-muted";
16
+ export function Markdown({ children, streaming = false, label }) {
17
+ return (_jsx("div", { role: label === undefined ? undefined : "document", "aria-label": label, className: BODY, children: _jsx(Streamdown, { mode: streaming ? "streaming" : "static", controls: false, children: children }) }));
18
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Tone } from "../../foundations/types.js";
2
- import type { LucideIcon } from "lucide-react";
2
+ import { type LucideIcon } from "lucide-react";
3
3
  /**
4
4
  * A metric that also FILTERS: «2 por confirmar», «41 por entregar».
5
5
  *
@@ -33,8 +33,19 @@ export type MetricProps = {
33
33
  onClick?: () => void;
34
34
  /** This narrowing is applied. */
35
35
  active?: boolean;
36
+ /**
37
+ * How it moved against a NAMED period: `{ by: 0.18, against: "2025" }` draws «↗ +18 % vs
38
+ * 2025». Whether up is good is the domain's (`better`, up by default): more sales is
39
+ * good news, more overdue invoices is not. The arrow carries the direction and the word
40
+ * the period, so the colour is never the only channel.
41
+ */
42
+ change?: {
43
+ by: number;
44
+ against: string;
45
+ better?: "up" | "down";
46
+ };
36
47
  };
37
- export declare function Metric({ value, label, tone, icon: Icon, onClick, active, }: MetricProps): import("react").JSX.Element;
48
+ export declare function Metric({ value, label, tone, icon: Icon, onClick, active, change, }: MetricProps): import("react").JSX.Element;
38
49
  /** The row of metrics. It wraps if they don't fit; it doesn't scroll: a hidden
39
50
  * metric is a filter nobody finds. */
40
51
  export declare function Metrics({ children }: {
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useUiCopy } from "../../foundations/copy.js";
3
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
4
4
  import { bySurface, useSurface } from "../../foundations/surface.js";
5
+ import { ArrowDownRight, ArrowUpRight } from "lucide-react";
6
+ import { useMemo } from "react";
5
7
  const TONE = {
6
8
  neutral: { background: "bg-ink/6", text: "text-ink", edge: "border-ink/20" },
7
9
  info: { background: "bg-info/10", text: "text-info", edge: "border-info/35" },
@@ -12,10 +14,15 @@ const TONE = {
12
14
  ink and the tone is only visible when the card is lit up. */
13
15
  accent: { background: "bg-accent/20", text: "text-ink", edge: "border-accent/50" },
14
16
  };
15
- export function Metric({ value, label, tone = "neutral", icon: Icon, onClick, active = false, }) {
17
+ export function Metric({ value, label, tone = "neutral", icon: Icon, onClick, active = false, change, }) {
16
18
  const copy = useUiCopy();
17
19
  const sup = useSurface();
18
20
  const t = TONE[tone];
21
+ const percent = useMemo(() => new Intl.NumberFormat(copy.locale, {
22
+ style: "percent",
23
+ maximumFractionDigits: 1,
24
+ signDisplay: "exceptZero",
25
+ }), [copy.locale]);
19
26
  /* At rest the box is the sheet with a hair of border: that is what makes four
20
27
  metrics read as one row and not as four notices. Lit up it gets tinted, and
21
28
  there the color says which one is applied. */
@@ -25,12 +32,27 @@ export function Metric({ value, label, tone = "neutral", icon: Icon, onClick, ac
25
32
  const box = `flex min-w-(--container-metric) shrink-0 flex-col justify-center gap-0.5 rounded-box border px-3.5 py-2 text-left transition-colors duration-(--duration-instant) ${skin} ${onClick === undefined
26
33
  ? ""
27
34
  : "cursor-pointer hover:border-line-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"}`;
28
- const content = (_jsxs(_Fragment, { children: [_jsxs("span", { className: `flex items-center gap-1.5 text-title font-semibold tabular-nums ${t.text}`, children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2, "aria-hidden": true })), typeof value === "number" ? value.toLocaleString(copy.locale) : value] }), _jsx("span", { className: `text-micro ${bySurface(sup, "text-muted", "text-chrome-muted")}`, children: label })] }));
35
+ const content = (_jsxs(_Fragment, { children: [_jsxs("span", { className: `flex items-center gap-1.5 text-title font-semibold tabular-nums ${t.text}`, children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2, "aria-hidden": true })), typeof value === "number" ? value.toLocaleString(copy.locale) : value] }), _jsx("span", { className: `text-micro ${bySurface(sup, "text-muted", "text-chrome-muted")}`, children: label }), change === undefined ? null : _jsx(Change, { change: change, format: percent.format })] }));
29
36
  if (onClick === undefined) {
30
37
  return (_jsx("div", { className: box, "aria-label": `${value} ${label}`, children: content }));
31
38
  }
32
39
  return (_jsx("button", { type: "button", onClick: onClick, "aria-pressed": active, className: box, children: content }));
33
40
  }
41
+ function Change({ change, format, }) {
42
+ const copy = useUiCopy();
43
+ const sup = useSurface();
44
+ const up = change.by > 0;
45
+ const flat = change.by === 0;
46
+ const good = flat ? null : up === ((change.better ?? "up") === "up");
47
+ const Arrow = up ? ArrowUpRight : ArrowDownRight;
48
+ /* On the chrome the states have their own steps; on the canvas, the usual ones. */
49
+ const color = good === null
50
+ ? bySurface(sup, "text-muted", "text-chrome-muted")
51
+ : good
52
+ ? bySurface(sup, "text-good", "text-chrome-good")
53
+ : bySurface(sup, "text-bad", "text-chrome-bad");
54
+ return (_jsxs("span", { className: `flex items-center gap-1 text-micro tabular-nums ${color}`, children: [flat ? null : _jsx(Arrow, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true }), format(change.by), _jsx("span", { className: bySurface(sup, "text-muted", "text-chrome-muted"), children: fillCopy(copy.chart.against, { name: change.against }) })] }));
55
+ }
34
56
  /** The row of metrics. It wraps if they don't fit; it doesn't scroll: a hidden
35
57
  * metric is a filter nobody finds. */
36
58
  export function Metrics({ children }) {
@@ -1,5 +1,6 @@
1
1
  export { Copyable, type CopyableProps, CopyButton, } from "./Copyable.js";
2
2
  export { DateValue, formatDateTime, formatRelative, } from "./DateValue.js";
3
+ export { Markdown, type MarkdownProps } from "./Markdown.js";
3
4
  export { Meter, type MeterLevel, meterLevel, type MeterProps, type MeterThresholds, } from "./Meter.js";
4
5
  export { Metric, type MetricProps, Metrics } from "./Metric.js";
5
6
  export { Avatar, type AvatarSize, type PersonContact, UserChip, type UserChipProps, UserStack, } from "./Person.js";