@tristan2828/ui-foundation 4.131.0 → 4.132.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.
@@ -3,43 +3,44 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [Palettes](#palettes) · lines 52–161
7
- - [Glow](#glow) · lines 163–182
8
- - [Semantic tones](#semantic-tones) · lines 184–212
9
- - [The three badge styles](#the-three-badge-styles) · lines 214–231
10
- - [Status marks](#status-marks) · lines 233–278
11
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 280–309
12
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 311–324
13
- - [Logos and brand marks](#logos-and-brand-marks) · lines 326–370
14
- - [Categorical colour](#categorical-colour) · lines 372–442
15
- - [Heat scale](#heat-scale) · lines 444–505
16
- - [Depth ramps](#depth-ramps) · lines 507–592
17
- - [A stored colour](#a-stored-colour) · lines 594–651
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 653–674
19
- - [Typography](#typography) · lines 676–847
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 710–743
21
- - [Written text (notes)](#written-text-notes) · lines 745–847
22
- - [Density](#density) · lines 849–942
23
- - [Rows on this device](#rows-on-this-device) · lines 915–942
24
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 944–1058
25
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1060–1137
26
- - [Notices](#notices) · lines 1139–1167
27
- - [A value over time](#a-value-over-time) · lines 1169–1255
28
- - [Several values over time](#several-values-over-time) · lines 1218–1255
29
- - [A list as a board](#a-list-as-a-board) · lines 1257–1373
30
- - [Order, groups and the header (4.131)](#order-groups-and-the-header-4131) · lines 1310–1373
31
- - [A list as cards](#a-list-as-cards) · lines 1375–1421
32
- - [Images full screen](#images-full-screen) · lines 1423–1469
33
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1471–1507
34
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1509–1579
35
- - [A few equal things](#a-few-equal-things) · lines 1581–1701
36
- - [An overview page](#an-overview-page) · lines 1703–1774
37
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1775–1841
38
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1843–1980
39
- - [Picking at random](#picking-at-random) · lines 1982–2013
40
- - [Filling in what's missing](#filling-in-whats-missing) · lines 2015–2082
41
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2084–2109
42
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2111–2207
6
+ - [Palettes](#palettes) · lines 53–162
7
+ - [Glow](#glow) · lines 164–183
8
+ - [Semantic tones](#semantic-tones) · lines 185–213
9
+ - [The three badge styles](#the-three-badge-styles) · lines 215–232
10
+ - [Status marks](#status-marks) · lines 234–279
11
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 281–310
12
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 312–325
13
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 327–371
14
+ - [Categorical colour](#categorical-colour) · lines 373–443
15
+ - [Heat scale](#heat-scale) · lines 445–506
16
+ - [Depth ramps](#depth-ramps) · lines 508–593
17
+ - [A stored colour](#a-stored-colour) · lines 595–652
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 654–675
19
+ - [Typography](#typography) · lines 677–848
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 711–744
21
+ - [Written text (notes)](#written-text-notes) · lines 746–848
22
+ - [Density](#density) · lines 850–943
23
+ - [Rows on this device](#rows-on-this-device) · lines 916–943
24
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 945–1059
25
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1061–1138
26
+ - [Notices](#notices) · lines 1140–1168
27
+ - [A value over time](#a-value-over-time) · lines 1170–1300
28
+ - [Several values over time](#several-values-over-time) · lines 1219–1257
29
+ - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1259–1300
30
+ - [A list as a board](#a-list-as-a-board) · lines 1302–1418
31
+ - [Order, groups and the header (4.131)](#order-groups-and-the-header-4131) · lines 1355–1418
32
+ - [A list as cards](#a-list-as-cards) · lines 1420–1466
33
+ - [Images full screen](#images-full-screen) · lines 1468–1514
34
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1516–1552
35
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1554–1624
36
+ - [A few equal things](#a-few-equal-things) · lines 1626–1746
37
+ - [An overview page](#an-overview-page) · lines 1748–1819
38
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1820–1886
39
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1888–2025
40
+ - [Picking at random](#picking-at-random) · lines 2027–2058
41
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 2060–2127
42
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2129–2154
43
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2156–2252
43
44
 
44
45
  <!-- /index -->
45
46
 
@@ -1251,8 +1252,52 @@ balance's history beside low, middle and high projections.
1251
1252
  when no series has a point, a dot for a series of one point.
1252
1253
  - **A screen reader gets a summary** (each series from first to last
1253
1254
  value, and the target) and a table with a column per series.
1254
- - Up to four or five series. More than that, or bars and stacked areas,
1255
- are a request for the foundation.
1255
+ - Up to four or five series. More than that, or bars, are a request for
1256
+ the foundation. Amounts that add up to a total are a stacked area:
1257
+ `StackedAreaChart`, "Parts of a whole over time" below.
1258
+
1259
+ ### Parts of a whole over time
1260
+
1261
+ `StackedAreaChart` (4.132) shows several amounts that add up to a total,
1262
+ each a category, over time: a portfolio by asset class, a budget by
1263
+ envelope. Each band is stacked on the one below, from zero, so the top
1264
+ edge is the total and both the growth and the mix show.
1265
+
1266
+ ```tsx
1267
+ <StackedAreaChart
1268
+ label="Allocation over time"
1269
+ xs={snapshotDates}
1270
+ series={[
1271
+ { label: 'US stocks', values: usStocks },
1272
+ { label: 'International', values: international },
1273
+ { label: 'Bonds', values: bonds },
1274
+ { label: 'Cash', values: cash },
1275
+ ]}
1276
+ formatY={usd}
1277
+ formatX={month}
1278
+ isLoading={isLoading}
1279
+ />
1280
+ ```
1281
+
1282
+ - **Colours are categorical slots**, in order (band 1 takes
1283
+ `category-1`, unless it gives its own `category`), opaque, with a 1px
1284
+ card-coloured line between neighbouring bands. Keep it to about six:
1285
+ the first six slots stay apart for colour-blind readers.
1286
+ - **Amounts, stacked from zero:** the range is 0 to the largest total,
1287
+ with room above. There is no share (100%) mode.
1288
+ - **One shared `xs`**, oldest first; each band's `values` line up with
1289
+ it. A missing or negative value counts as 0 everywhere (the plot, the
1290
+ legend, the table), so a gap is a 0, not a hole.
1291
+ - **The legend** lists the top band first, as the picture reads, each
1292
+ with its latest value and its share of the latest total (rounded, so
1293
+ they may not add to exactly 100), then the total.
1294
+ - **The states:** a skeleton at its height while loading; one quiet line
1295
+ when there are no xs, no bands, or only zeros; one stacked column
1296
+ mid-plot for a single snapshot (it turns into bands at the second);
1297
+ the bands.
1298
+ - **A screen reader gets a summary** (the total from first to last, each
1299
+ band's latest value and share) and a table with a column per band and
1300
+ a Total column.
1256
1301
 
1257
1302
  ## A list as a board
1258
1303
 
@@ -0,0 +1,29 @@
1
+ import type { CategorySlot } from "./module-card.js";
2
+ import { type LineChartPoint } from "../../lib/line-chart-layout.js";
3
+ export type StackedSeries = {
4
+ /** The band's name in the legend and the table: "US stocks". */
5
+ label: string;
6
+ /** One amount per x, in xs' order: 0 or more. A missing or negative value counts as 0. */
7
+ values: readonly number[];
8
+ /** Its colour, a categorical slot. Defaults to its place in `series` + 1 (1, 2, 3…). */
9
+ category?: CategorySlot;
10
+ };
11
+ export type StackedAreaChartProps = {
12
+ /** The figure's name: "Allocation over time". */
13
+ label: string;
14
+ /** The shared x of every band, oldest first: days ('YYYY-MM-DD'), numbers or names. */
15
+ xs: readonly LineChartPoint["x"][];
16
+ /** The bands, bottom first. Keep it to about six: the slots that stay apart for colour-blind readers. */
17
+ series: readonly StackedSeries[];
18
+ /** A value as shown: `usd`. Defaults to the number as the browser writes it. */
19
+ formatY?: (y: number) => string;
20
+ /** An x as shown: `formatPlainDate`. Defaults to x as given. */
21
+ formatX?: (x: LineChartPoint["x"]) => string;
22
+ /** The plot's height in px; the chart fills its container's width. */
23
+ height?: number;
24
+ isLoading?: boolean;
25
+ /** What shows when there is nothing to stack. */
26
+ emptyMessage?: string;
27
+ className?: string;
28
+ };
29
+ export declare function StackedAreaChart({ label, xs, series, formatY, formatX, height, isLoading, emptyMessage, className, }: StackedAreaChartProps): import("react").JSX.Element;
@@ -0,0 +1,91 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ // Parts of a whole over time (4.132): several amounts that add up to a
3
+ // total, each a category (a portfolio by asset class), stacked from zero
4
+ // so the top edge is the total and both the growth and the mix show.
5
+ // MultiLineChart's sibling, plain SVG the same way: each band is its own
6
+ // <svg> drawing in currentColor in a categorical slot's text class, so the
7
+ // package's glyph check measures it like any icon, and a 1px card-coloured
8
+ // line runs between neighbours. A legend under the plot lists the top band
9
+ // first with its latest value and share, then the total, so the colours
10
+ // never carry the meaning alone.
11
+ //
12
+ // The bands share one `xs`; each band's `values` line up with it, and a
13
+ // missing or negative value counts as 0. The picture is for the eye: a
14
+ // screen reader gets the figure's name, a summary (the total from first to
15
+ // last, each band's latest value and share) and a table with a column per
16
+ // band and a Total column, all visually hidden. The states: a skeleton at
17
+ // `height` while loading, one quiet line when there is nothing to stack,
18
+ // one stacked column mid-plot for a single snapshot, and the bands.
19
+ import { cn } from "cn";
20
+ import { Skeleton } from "../ui/skeleton.js";
21
+ import { stackedLayout } from "../../lib/line-chart-layout.js";
22
+ // Whole class names, so Tailwind sees each one.
23
+ const CATEGORY = {
24
+ 1: "text-category-1",
25
+ 2: "text-category-2",
26
+ 3: "text-category-3",
27
+ 4: "text-category-4",
28
+ 5: "text-category-5",
29
+ 6: "text-category-6",
30
+ 7: "text-category-7",
31
+ 8: "text-category-8",
32
+ 9: "text-category-9",
33
+ 10: "text-category-10",
34
+ 11: "text-category-11",
35
+ 12: "text-category-12",
36
+ };
37
+ const defaultY = (y) => y.toLocaleString();
38
+ const defaultX = (x) => String(x);
39
+ const percent = (fraction) => `${fraction * 100}%`;
40
+ const slotOf = (one, index) => one.category ?? ((index % 12) + 1);
41
+ export function StackedAreaChart({ label, xs, series, formatY = defaultY, formatX = defaultX, height = 160, isLoading = false, emptyMessage = "No points yet", className, }) {
42
+ if (isLoading) {
43
+ return (_jsxs("div", { "data-slot": "stacked-area-chart", "data-state": "loading", "aria-busy": "true", className: cn("min-w-0", className), children: [_jsxs("span", { className: "sr-only", children: ["Loading ", label] }), _jsx(Skeleton, { style: { height }, className: "w-full" })] }));
44
+ }
45
+ // Cleaned once: what the plot, the legend, the summary and the table use.
46
+ const values = series.map((one) => xs.map((_, i) => Math.max(0, one.values[i] ?? 0)));
47
+ const layout = stackedLayout(xs, values);
48
+ if (xs.length === 0 ||
49
+ series.length === 0 ||
50
+ layout.totals.every((total) => total === 0)) {
51
+ return (_jsx("figure", { "data-slot": "stacked-area-chart", "data-state": "empty", "aria-label": label, className: cn("min-w-0", className), children: _jsx("p", { style: { height }, className: "flex items-center justify-center rounded-md border border-dashed border-border type-body text-muted-foreground", children: emptyMessage }) }));
52
+ }
53
+ const last = xs.length - 1;
54
+ const lastTotal = layout.totals[last];
55
+ const share = (s) => lastTotal === 0
56
+ ? undefined
57
+ : Math.round((values[s][last] / lastTotal) * 100);
58
+ const withShare = (s) => {
59
+ const part = share(s);
60
+ return part === undefined
61
+ ? formatY(values[s][last])
62
+ : `${formatY(values[s][last])} (${part}%)`;
63
+ };
64
+ const summary = [
65
+ xs.length === 1
66
+ ? `Total ${formatY(layout.totals[0])} on ${formatX(xs[0])}`
67
+ : `Total from ${formatY(layout.totals[0])} on ${formatX(xs[0])} to ${formatY(lastTotal)} on ${formatX(xs[last])}`,
68
+ ...series.map((one, s) => `${one.label} ${withShare(s)}`),
69
+ ].join("; ");
70
+ const edge = (row) => row.map((y, i) => `${layout.across[i] * 100},${y * 100}`);
71
+ return (_jsxs("figure", { "data-slot": "stacked-area-chart", "data-state": "success", "aria-label": label, className: cn("flex min-w-0 flex-col gap-1.5", className), children: [_jsx("div", { "aria-hidden": "true", className: "relative border-b border-border", style: { height }, children: xs.length === 1 ? (_jsx("div", { "data-slot": "stacked-area-chart-column", className: "absolute inset-y-0 left-1/2 w-3 -translate-x-1/2", children: series.map((one, s) => {
72
+ if (values[s][0] === 0)
73
+ return null;
74
+ const { top, bottom } = layout.bands[s];
75
+ return (_jsxs("svg", { "data-slot": "stacked-area-chart-segment", className: cn("absolute inset-x-0 w-full overflow-visible", CATEGORY[slotOf(one, s)]), style: {
76
+ top: percent(top[0]),
77
+ height: percent(bottom[0] - top[0]),
78
+ }, children: [_jsx("rect", { width: "100%", height: "100%", fill: "currentColor" }), _jsx("line", { x1: "0", x2: "100%", y1: "0", y2: "0", strokeWidth: 1, className: "stroke-card" })] }, s));
79
+ }) })) : (series.map((one, s) => {
80
+ if (values[s].every((value) => value === 0))
81
+ return null;
82
+ const { top, bottom } = layout.bands[s];
83
+ return (_jsxs("svg", { "data-slot": "stacked-area-chart-band", viewBox: "0 0 100 100", preserveAspectRatio: "none", className: cn("absolute inset-0 size-full overflow-visible", CATEGORY[slotOf(one, s)]), children: [_jsx("polygon", { points: [...edge(top), ...edge(bottom).reverse()].join(" "), fill: "currentColor" }), _jsx("polyline", { points: edge(top).join(" "), fill: "none", strokeWidth: 1, vectorEffect: "non-scaling-stroke", className: "stroke-card" })] }, s));
84
+ })) }), _jsxs("div", { "aria-hidden": "true", className: cn("flex gap-3 type-caption text-muted-foreground tabular-nums", xs.length === 1 ? "justify-center" : "justify-between"), children: [_jsx("span", { children: formatX(xs[0]) }), xs.length > 1 && _jsx("span", { children: formatX(xs[last]) })] }), _jsxs("ul", { "aria-hidden": "true", "data-slot": "stacked-area-chart-legend", className: "flex flex-wrap gap-x-4 gap-y-1 type-caption text-foreground", children: [series
85
+ .map((one, s) => ({ one, s }))
86
+ .reverse()
87
+ .map(({ one, s }) => {
88
+ const part = share(s);
89
+ return (_jsxs("li", { className: "flex items-center gap-1.5", children: [_jsx("svg", { viewBox: "0 0 10 10", className: cn("size-2.5 shrink-0", CATEGORY[slotOf(one, s)]), children: _jsx("rect", { width: "10", height: "10", rx: "2", fill: "currentColor" }) }), _jsx("span", { children: one.label }), _jsxs("span", { className: "font-medium tabular-nums", children: [formatY(values[s][last]), part !== undefined && ` · ${part}%`] })] }, s));
90
+ }), _jsxs("li", { className: "flex items-center gap-1.5 text-muted-foreground", children: [_jsx("span", { children: "Total" }), _jsx("span", { className: "font-medium tabular-nums", children: formatY(lastTotal) })] })] }), _jsx("figcaption", { className: "sr-only", children: summary }), _jsx("div", { className: "sr-only", children: _jsxs("table", { children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "When" }), series.map((one, s) => (_jsx("th", { scope: "col", children: one.label }, s))), _jsx("th", { scope: "col", children: "Total" })] }) }), _jsx("tbody", { children: xs.map((x, i) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatX(x) }), series.map((_, s) => (_jsx("td", { children: formatY(values[s][i]) }, s))), _jsx("td", { children: formatY(layout.totals[i]) })] }, `${String(x)}-${i}`))) })] }) })] }));
91
+ }
package/dist/index.d.ts CHANGED
@@ -95,6 +95,8 @@ export { SourceCredit, type Source, type SourceCreditProps } from './components/
95
95
  export { ProgressRing, type ProgressRingProps } from './components/app/progress-ring.js';
96
96
  export { LineChart, type LineChartMark, type LineChartPoint, type LineChartProps, } from './components/app/line-chart.js';
97
97
  export { MultiLineChart, type ChartSeries, type ChartTone, type MultiLineChartProps, } from './components/app/multi-line-chart.js';
98
+ export { StackedAreaChart, type StackedAreaChartProps, type StackedSeries, } from './components/app/stacked-area-chart.js';
99
+ export type { StackedLayout } from './lib/line-chart-layout.js';
98
100
  export { StepBar, type StepBarProps } from './components/app/step-bar.js';
99
101
  export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
100
102
  export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
package/dist/index.js CHANGED
@@ -106,6 +106,7 @@ export { SourceCredit } from './components/app/source-credit.js';
106
106
  export { ProgressRing } from './components/app/progress-ring.js';
107
107
  export { LineChart, } from './components/app/line-chart.js';
108
108
  export { MultiLineChart, } from './components/app/multi-line-chart.js';
109
+ export { StackedAreaChart, } from './components/app/stacked-area-chart.js';
109
110
  export { StepBar } from './components/app/step-bar.js';
110
111
  export { RatingStar } from './components/app/rating-star.js';
111
112
  export { RatingScore } from './components/app/rating-score.js';
@@ -43,3 +43,19 @@ export type SeriesLayout = {
43
43
  targetY?: number;
44
44
  };
45
45
  export declare function seriesLayout(series: readonly (readonly LineChartPoint[])[], target?: number): SeriesLayout;
46
+ export type StackedLayout = {
47
+ /** Each x's place across the plot, 0…1. */
48
+ across: number[];
49
+ /** Each band's top and bottom edge at each x, as fractions from the plot's top, bottom band first. */
50
+ bands: {
51
+ top: number[];
52
+ bottom: number[];
53
+ }[];
54
+ /** Each x's total. */
55
+ totals: number[];
56
+ domain: {
57
+ min: 0;
58
+ max: number;
59
+ };
60
+ };
61
+ export declare function stackedLayout(xs: readonly LineChartPoint['x'][], values: readonly (readonly number[])[]): StackedLayout;
@@ -77,3 +77,27 @@ export function seriesLayout(series, target) {
77
77
  targetY: shared.targetY,
78
78
  };
79
79
  }
80
+ // Amounts stacked from zero (StackedAreaChart, 4.132): every band shares
81
+ // `xs`, a band's bottom is the sum of the bands below it and its top adds
82
+ // its own value, so the top band's top is the total. The range is 0 to the
83
+ // largest total with room above only. `values` are already cleaned: one per
84
+ // x, 0 or more. x is placed as seriesLayout places it.
85
+ export function stackedLayout(xs, values) {
86
+ const totals = xs.map((_, i) => values.reduce((sum, band) => sum + (band[i] ?? 0), 0));
87
+ const max = (Math.max(0, ...totals) || 1) * (1 + PAD);
88
+ const height = (y) => (max - y) / max;
89
+ const times = xs.map(along);
90
+ const timed = times.every(Number.isFinite) && new Set(times).size > 1;
91
+ const first = timed ? Math.min(...times) : 0;
92
+ const span = timed ? Math.max(...times) - first : xs.length - 1;
93
+ const across = xs.map((_, i) => (span === 0 ? 0.5 : ((timed ? times[i] : i) - first) / span));
94
+ const below = xs.map(() => 0);
95
+ const bands = values.map((band) => {
96
+ const bottom = below.map(height);
97
+ xs.forEach((_, i) => {
98
+ below[i] += band[i] ?? 0;
99
+ });
100
+ return { top: below.map(height), bottom };
101
+ });
102
+ return { across, bands, totals, domain: { min: 0, max } };
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.131.0",
3
+ "version": "4.132.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {