@tristan2828/ui-foundation 4.130.3 → 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.
- package/conventions/docs/design-language.md +149 -38
- package/dist/components/app/board-order.d.ts +34 -0
- package/dist/components/app/board-order.js +60 -0
- package/dist/components/app/board.d.ts +56 -6
- package/dist/components/app/board.js +300 -54
- package/dist/components/app/stacked-area-chart.d.ts +29 -0
- package/dist/components/app/stacked-area-chart.js +91 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/lib/line-chart-layout.d.ts +16 -0
- package/dist/lib/line-chart-layout.js +24 -0
- package/package.json +3 -2
|
@@ -3,42 +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
|
|
7
|
-
- [Glow](#glow) · lines
|
|
8
|
-
- [Semantic tones](#semantic-tones) · lines
|
|
9
|
-
- [The three badge styles](#the-three-badge-styles) · lines
|
|
10
|
-
- [Status marks](#status-marks) · lines
|
|
11
|
-
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines
|
|
12
|
-
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines
|
|
13
|
-
- [Logos and brand marks](#logos-and-brand-marks) · lines
|
|
14
|
-
- [Categorical colour](#categorical-colour) · lines
|
|
15
|
-
- [Heat scale](#heat-scale) · lines
|
|
16
|
-
- [Depth ramps](#depth-ramps) · lines
|
|
17
|
-
- [A stored colour](#a-stored-colour) · lines
|
|
18
|
-
- [Shapes and sizes](#shapes-and-sizes) · lines
|
|
19
|
-
- [Typography](#typography) · lines
|
|
20
|
-
- [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines
|
|
21
|
-
- [Written text (notes)](#written-text-notes) · lines
|
|
22
|
-
- [Density](#density) · lines
|
|
23
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
24
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
25
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
26
|
-
- [Notices](#notices) · lines
|
|
27
|
-
- [A value over time](#a-value-over-time) · lines
|
|
28
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
29
|
-
- [
|
|
30
|
-
- [A list as
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [A
|
|
37
|
-
- [
|
|
38
|
-
- [
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
41
|
-
- [
|
|
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
|
|
42
44
|
|
|
43
45
|
<!-- /index -->
|
|
44
46
|
|
|
@@ -1250,8 +1252,52 @@ balance's history beside low, middle and high projections.
|
|
|
1250
1252
|
when no series has a point, a dot for a series of one point.
|
|
1251
1253
|
- **A screen reader gets a summary** (each series from first to last
|
|
1252
1254
|
value, and the target) and a table with a column per series.
|
|
1253
|
-
- Up to four or five series. More than that, or bars
|
|
1254
|
-
|
|
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.
|
|
1255
1301
|
|
|
1256
1302
|
## A list as a board
|
|
1257
1303
|
|
|
@@ -1306,6 +1352,71 @@ the table's.
|
|
|
1306
1352
|
snap points; a phone shows one column at a time, with the edge of the
|
|
1307
1353
|
next one showing.
|
|
1308
1354
|
|
|
1355
|
+
### Order, groups and the header (4.131)
|
|
1356
|
+
|
|
1357
|
+
```tsx
|
|
1358
|
+
<Board<Job, Stage, Size>
|
|
1359
|
+
aria-label="Jobs"
|
|
1360
|
+
columns={[
|
|
1361
|
+
{ value: 'idea', label: 'Idea', lead: true, action: <AddButton />, description: 'Worth doing one day',
|
|
1362
|
+
groups: [{ value: 'quick', label: 'Quick' }, { value: 'big', label: 'Big', defaultOpen: false }],
|
|
1363
|
+
footer: <Link to="/jobs?size=someday">Someday {somedayCount}</Link> },
|
|
1364
|
+
{ value: 'active', label: 'Active', note: `${waiting} waiting` },
|
|
1365
|
+
{ value: 'done', label: 'Done', ordered: false },
|
|
1366
|
+
]}
|
|
1367
|
+
getGroup={(job) => job.size}
|
|
1368
|
+
ordered
|
|
1369
|
+
pageSize={20}
|
|
1370
|
+
pageKey={filtersKey}
|
|
1371
|
+
phone="counts"
|
|
1372
|
+
menu={(job) => <JobMenuItems job={job} />}
|
|
1373
|
+
onMove={(job, stage, place) => save(job, stage, place.group, place.beforeId ?? afterOf(place.afterId))}
|
|
1374
|
+
{...rest}
|
|
1375
|
+
/>
|
|
1376
|
+
```
|
|
1377
|
+
|
|
1378
|
+
- **Order:** with `ordered`, cards keep `items`' order within their
|
|
1379
|
+
column (and group). A drag within a column reorders, and a 3px line in
|
|
1380
|
+
the text colour (`data-slot="board-drop-line"`) in the gap shows where
|
|
1381
|
+
the card lands; the card dragged is faded where it was. The card's menu
|
|
1382
|
+
has an Order section (Move Up, Move Down, Move to Top, disabled where
|
|
1383
|
+
they can't apply). After any menu move the focus is on the card's menu
|
|
1384
|
+
button wherever it now is, and the status line says "Moved <name> up"
|
|
1385
|
+
(or "down", "to the top"), "to <column>, <group>", or "to place 3 of 8
|
|
1386
|
+
in <column>" for a drag.
|
|
1387
|
+
- **`onMove(item, value, place)`:** `place.beforeId` is the card it now
|
|
1388
|
+
sits before and `place.afterId` the one after, among `items` in that
|
|
1389
|
+
column (and group), null at the end and the start. A server that orders
|
|
1390
|
+
by "before this id" takes `beforeId`; one that keeps a position takes
|
|
1391
|
+
the halfway point. The place counts every card in `items`, not only
|
|
1392
|
+
those shown: a drop after the last shown card is before the first one
|
|
1393
|
+
"Show N More" hides. A drop that leaves the card where it was calls
|
|
1394
|
+
nothing. A column with `ordered: false` (Done, by date) has no line, no
|
|
1395
|
+
Order items, and a drop there only changes the column.
|
|
1396
|
+
- **Groups:** a column's `groups` split its cards by `getGroup`, each a
|
|
1397
|
+
heading one level under the column's: a chevron, the label in small
|
|
1398
|
+
capitals and its count, a button that folds the group (`defaultOpen:
|
|
1399
|
+
false` starts folded). A drop on a group's cards reports that group; a
|
|
1400
|
+
drop on a folded group's heading outlines it and lands at the group's
|
|
1401
|
+
end. A card whose group isn't one of the column's isn't on the board.
|
|
1402
|
+
The keyboard's way to change group is the app's own field in `menu`
|
|
1403
|
+
(Priority, Size): Board's menu has no group section.
|
|
1404
|
+
- **Paging:** `pageSize` shows a column's (or each group's) first cards,
|
|
1405
|
+
then "Show N More"; `pageKey` changing (the filters) folds them back.
|
|
1406
|
+
- **The header's slots:** `description` is a caption under the name,
|
|
1407
|
+
`note` short muted text, `action` a control at the end (a +; the other
|
|
1408
|
+
columns keep the header's height), and `lead` outlines the column a
|
|
1409
|
+
list starts in.
|
|
1410
|
+
- **The phone's counts:** `phone="counts"` puts a row of buttons over the
|
|
1411
|
+
columns below `lg`, each a column's count over its `shortName`, that
|
|
1412
|
+
shows that one column (`aria-pressed`); from `lg` up, the columns as
|
|
1413
|
+
usual.
|
|
1414
|
+
- **The menu:** `menu(item)` appends the app's own items after a
|
|
1415
|
+
separator; the button is then ⋯, "Actions for <name>", holding Move To,
|
|
1416
|
+
Order and the app's items. Without it, the Move button as before.
|
|
1417
|
+
- **No grip:** a card that drags shows a grab hand over it, and is picked
|
|
1418
|
+
up whole, from its title link too.
|
|
1419
|
+
|
|
1309
1420
|
## A list as cards
|
|
1310
1421
|
|
|
1311
1422
|
`DataTable`'s `layouts` (4.39) draw the same rows as cards beside the
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type BoardId = string | number;
|
|
2
|
+
/** Where a card now sits in its zone: the card it is before, and the one after it (null at the end, the start). */
|
|
3
|
+
export type BoardNeighbours = {
|
|
4
|
+
beforeId: BoardId | null;
|
|
5
|
+
afterId: BoardId | null;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A drop at `index` (0 to the cards shown) in a zone whose cards are `ids`
|
|
9
|
+
* (all of them, not only those shown: after the last shown card the card
|
|
10
|
+
* lands before the first hidden one). `dragged` is the card dropped. Null
|
|
11
|
+
* when the drop leaves the card between the neighbours it has now.
|
|
12
|
+
*/
|
|
13
|
+
export declare function dropPlace(ids: readonly BoardId[], index: number, dragged: BoardId): BoardNeighbours | null;
|
|
14
|
+
/** The end of a zone, for a card that isn't in it yet (or is, and leaves its place for the end). */
|
|
15
|
+
export declare function endPlace(ids: readonly BoardId[], card: BoardId): BoardNeighbours;
|
|
16
|
+
/** The card's neighbours in its zone now. */
|
|
17
|
+
export declare function neighboursOf(ids: readonly BoardId[], card: BoardId): BoardNeighbours | null;
|
|
18
|
+
export type BoardOrderKind = 'up' | 'down' | 'top';
|
|
19
|
+
/**
|
|
20
|
+
* Where the menu's Order items put a card within its zone: up (before the
|
|
21
|
+
* card above it), down (after the card below it), to the top (before the
|
|
22
|
+
* zone's first card). Undefined where one can't apply: the first card can't
|
|
23
|
+
* go up or to the top, the last can't go down.
|
|
24
|
+
*/
|
|
25
|
+
export declare function orderTargets(ids: readonly BoardId[], card: BoardId): Record<BoardOrderKind, BoardNeighbours | undefined>;
|
|
26
|
+
/** The card's place (1 to n) in its zone once it sits between `place`'s neighbours. */
|
|
27
|
+
export declare function placeNumber(ids: readonly BoardId[], card: BoardId, place: BoardNeighbours): {
|
|
28
|
+
k: number;
|
|
29
|
+
n: number;
|
|
30
|
+
};
|
|
31
|
+
/** The cards a zone shows: its first `pageSize` times the pages opened, or all of them. */
|
|
32
|
+
export declare function shownCount(total: number, pageSize: number | undefined, pages: number): number;
|
|
33
|
+
/** "Show N More": the smaller of a page and what's left. 0 when nothing is left. */
|
|
34
|
+
export declare function moreCount(total: number, pageSize: number | undefined, pages: number): number;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const same = (a, b) => (a === null || b === null ? a === b : String(a) === String(b));
|
|
2
|
+
/**
|
|
3
|
+
* A drop at `index` (0 to the cards shown) in a zone whose cards are `ids`
|
|
4
|
+
* (all of them, not only those shown: after the last shown card the card
|
|
5
|
+
* lands before the first hidden one). `dragged` is the card dropped. Null
|
|
6
|
+
* when the drop leaves the card between the neighbours it has now.
|
|
7
|
+
*/
|
|
8
|
+
export function dropPlace(ids, index, dragged) {
|
|
9
|
+
const at = Math.max(0, Math.min(index, ids.length));
|
|
10
|
+
const afterId = at > 0 ? ids[at - 1] : null;
|
|
11
|
+
const beforeId = at < ids.length ? ids[at] : null;
|
|
12
|
+
if (same(afterId, dragged) || same(beforeId, dragged))
|
|
13
|
+
return null;
|
|
14
|
+
return { beforeId, afterId };
|
|
15
|
+
}
|
|
16
|
+
/** The end of a zone, for a card that isn't in it yet (or is, and leaves its place for the end). */
|
|
17
|
+
export function endPlace(ids, card) {
|
|
18
|
+
const rest = ids.filter((id) => !same(id, card));
|
|
19
|
+
return { beforeId: null, afterId: rest.length > 0 ? rest[rest.length - 1] : null };
|
|
20
|
+
}
|
|
21
|
+
/** The card's neighbours in its zone now. */
|
|
22
|
+
export function neighboursOf(ids, card) {
|
|
23
|
+
const at = ids.findIndex((id) => same(id, card));
|
|
24
|
+
if (at < 0)
|
|
25
|
+
return null;
|
|
26
|
+
return { beforeId: at + 1 < ids.length ? ids[at + 1] : null, afterId: at > 0 ? ids[at - 1] : null };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Where the menu's Order items put a card within its zone: up (before the
|
|
30
|
+
* card above it), down (after the card below it), to the top (before the
|
|
31
|
+
* zone's first card). Undefined where one can't apply: the first card can't
|
|
32
|
+
* go up or to the top, the last can't go down.
|
|
33
|
+
*/
|
|
34
|
+
export function orderTargets(ids, card) {
|
|
35
|
+
const at = ids.findIndex((id) => same(id, card));
|
|
36
|
+
if (at < 0)
|
|
37
|
+
return { up: undefined, down: undefined, top: undefined };
|
|
38
|
+
return {
|
|
39
|
+
up: at > 0 ? { beforeId: ids[at - 1], afterId: at > 1 ? ids[at - 2] : null } : undefined,
|
|
40
|
+
down: at < ids.length - 1 ? { beforeId: at + 2 < ids.length ? ids[at + 2] : null, afterId: ids[at + 1] } : undefined,
|
|
41
|
+
top: at > 0 ? { beforeId: ids[0], afterId: null } : undefined,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** The card's place (1 to n) in its zone once it sits between `place`'s neighbours. */
|
|
45
|
+
export function placeNumber(ids, card, place) {
|
|
46
|
+
const rest = ids.filter((id) => !same(id, card));
|
|
47
|
+
const before = place.beforeId === null ? -1 : rest.findIndex((id) => same(id, place.beforeId));
|
|
48
|
+
const k = (before < 0 ? rest.length : before) + 1;
|
|
49
|
+
return { k, n: rest.length + 1 };
|
|
50
|
+
}
|
|
51
|
+
/** The cards a zone shows: its first `pageSize` times the pages opened, or all of them. */
|
|
52
|
+
export function shownCount(total, pageSize, pages) {
|
|
53
|
+
return pageSize === undefined ? total : Math.min(total, pageSize * pages);
|
|
54
|
+
}
|
|
55
|
+
/** "Show N More": the smaller of a page and what's left. 0 when nothing is left. */
|
|
56
|
+
export function moreCount(total, pageSize, pages) {
|
|
57
|
+
if (pageSize === undefined)
|
|
58
|
+
return 0;
|
|
59
|
+
return Math.min(pageSize, total - shownCount(total, pageSize, pages));
|
|
60
|
+
}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { AppError } from '../../api/contracts.js';
|
|
3
|
-
|
|
3
|
+
import { type BoardId } from './board-order.js';
|
|
4
|
+
/** A group of a column's cards: a heading that folds them. */
|
|
5
|
+
export type BoardGroup<G extends string = string> = {
|
|
6
|
+
/** The value `getGroup` gives this group's cards. */
|
|
7
|
+
value: G;
|
|
8
|
+
/** The heading, plain text: shown in small capitals, and heard after a move. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Beside the heading. Omitted: the group's cards on the board are counted. */
|
|
11
|
+
count?: number;
|
|
12
|
+
/** Open at first. Default true. */
|
|
13
|
+
defaultOpen?: boolean;
|
|
14
|
+
/** The line an empty group shows. Default "Nothing here". */
|
|
15
|
+
empty?: ReactNode;
|
|
16
|
+
/** Under the group's cards. */
|
|
17
|
+
footer?: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
/** Where a move put a card: its group, and its new neighbours on an ordered column (both null otherwise). */
|
|
20
|
+
export type BoardPlace<G extends string = string> = {
|
|
21
|
+
group?: G;
|
|
22
|
+
/** The card it now sits before, among `items` in that column (and group); null at the end. */
|
|
23
|
+
beforeId: BoardId | null;
|
|
24
|
+
/** The card it now sits after; null at the start. */
|
|
25
|
+
afterId: BoardId | null;
|
|
26
|
+
};
|
|
27
|
+
export type BoardColumn<V extends string, G extends string = string> = {
|
|
4
28
|
/** The field's value this column holds. */
|
|
5
29
|
value: V;
|
|
6
30
|
/** The column's heading: a word, or a glyph and a word. */
|
|
@@ -17,16 +41,30 @@ export type BoardColumn<V extends string> = {
|
|
|
17
41
|
empty?: ReactNode;
|
|
18
42
|
/** Under the cards: "Showing 100 of 240", a link to the whole list. */
|
|
19
43
|
footer?: ReactNode;
|
|
44
|
+
/** The column's groups, in order (4.131). Needs the board's `getGroup`. */
|
|
45
|
+
groups?: readonly BoardGroup<G>[];
|
|
46
|
+
/** Default: the board's `ordered`. `false` gives this column no order (4.131). */
|
|
47
|
+
ordered?: boolean;
|
|
48
|
+
/** A caption under the column's name (4.131). */
|
|
49
|
+
description?: ReactNode;
|
|
50
|
+
/** A control at the end of the header, a + (4.131). */
|
|
51
|
+
action?: ReactNode;
|
|
52
|
+
/** Short muted text in the header before the action: "3 need review" (4.131). */
|
|
53
|
+
note?: ReactNode;
|
|
54
|
+
/** The lead column, outlined: where the list starts (4.131). */
|
|
55
|
+
lead?: boolean;
|
|
56
|
+
/** Its name in the phone's row of counts (4.131). Default: its name. */
|
|
57
|
+
shortName?: string;
|
|
20
58
|
};
|
|
21
59
|
/** A value a card can be moved to from its Move menu. */
|
|
22
60
|
export type BoardMoveTarget<V extends string> = {
|
|
23
61
|
value: V;
|
|
24
62
|
label: string;
|
|
25
63
|
};
|
|
26
|
-
export type BoardProps<T, V extends string> = {
|
|
64
|
+
export type BoardProps<T, V extends string, G extends string = string> = {
|
|
27
65
|
/** Names the board as a whole ("Tasks by status"). */
|
|
28
66
|
'aria-label': string;
|
|
29
|
-
columns: readonly BoardColumn<V>[];
|
|
67
|
+
columns: readonly BoardColumn<V, G>[];
|
|
30
68
|
items: readonly T[];
|
|
31
69
|
getId: (item: T) => string | number;
|
|
32
70
|
/** The record's value of the field: which column its card is in. */
|
|
@@ -34,12 +72,24 @@ export type BoardProps<T, V extends string> = {
|
|
|
34
72
|
/** What the Move button calls the record: "Move <name>". */
|
|
35
73
|
getName: (item: T) => string;
|
|
36
74
|
renderCard: (item: T) => ReactNode;
|
|
37
|
-
/** Saves the record's new value. Omitted: a read-only board. */
|
|
38
|
-
onMove?: (item: T, value: V) => void;
|
|
75
|
+
/** Saves the record's new value, and its place. Omitted: a read-only board. */
|
|
76
|
+
onMove?: (item: T, value: V, place: BoardPlace<G>) => void;
|
|
39
77
|
/** The Move menu's choices. Default: the columns, by their `name`. */
|
|
40
78
|
moveTo?: readonly BoardMoveTarget<V>[];
|
|
41
79
|
/** The columns' heading level: 2 under the page's h1 (the default), deeper under a section. */
|
|
42
80
|
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
81
|
+
/** Cards keep `items`' order and can be reordered (4.131). Only with `onMove`. */
|
|
82
|
+
ordered?: boolean;
|
|
83
|
+
/** Which group of its column a card is in (4.131), for a column with `groups`. */
|
|
84
|
+
getGroup?: (item: T) => G;
|
|
85
|
+
/** Each column, or group, shows this many cards, then "Show N More" (4.131). */
|
|
86
|
+
pageSize?: number;
|
|
87
|
+
/** When it changes, every column and group goes back to its first page (4.131). */
|
|
88
|
+
pageKey?: string;
|
|
89
|
+
/** The app's own items, after the board's in the card's menu (4.131). */
|
|
90
|
+
menu?: (item: T) => ReactNode;
|
|
91
|
+
/** Below lg: one column with the next one's edge (`swipe`, the default), or a row of counts that picks it (4.131). */
|
|
92
|
+
phone?: 'swipe' | 'counts';
|
|
43
93
|
isLoading?: boolean;
|
|
44
94
|
error?: AppError | null;
|
|
45
95
|
onRetry?: () => void;
|
|
@@ -47,4 +97,4 @@ export type BoardProps<T, V extends string> = {
|
|
|
47
97
|
emptyDescription?: ReactNode;
|
|
48
98
|
emptyAction?: ReactNode;
|
|
49
99
|
};
|
|
50
|
-
export declare function Board<T, V extends string>({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, }: BoardProps<T, V>): import("react").JSX.Element;
|
|
100
|
+
export declare function Board<T, V extends string, G extends string = string>({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel, ordered, getGroup, pageSize, pageKey, menu, phone, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, }: BoardProps<T, V, G>): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// A board: a column per value of one choice field (a status, a stage), a
|
|
3
3
|
// card per record, and a record moved by moving its card. A second way to
|
|
4
4
|
// look at a list, beside its DataTable, never instead of it: filters, sort
|
|
@@ -9,22 +9,37 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
9
9
|
// which may be more than the cards loaded), an `empty` line, and a
|
|
10
10
|
// `footer` ("Showing 100 of 240", a link to the filtered list). A
|
|
11
11
|
// column whose `label` isn't plain text gives its `name` for the Move
|
|
12
|
-
// menu and what a screen reader hears after a move.
|
|
12
|
+
// menu and what a screen reader hears after a move. A column's header
|
|
13
|
+
// may also hold a `description` (a caption under the name), a `note`
|
|
14
|
+
// and an `action` (a +); `lead` outlines the column the list starts in.
|
|
13
15
|
// - Cards: every record in `items` whose `getColumn` is one of the
|
|
14
16
|
// columns' values, in `items`' order; a record whose value has no column
|
|
15
17
|
// isn't shown. `renderCard` is the card's content: the title (a link to
|
|
16
18
|
// the record's page) and a few values.
|
|
19
|
+
// - Groups (4.131): a column with `groups` splits its cards by `getGroup`,
|
|
20
|
+
// each group a heading with its count that folds its cards. A card whose
|
|
21
|
+
// group isn't one of the column's isn't shown.
|
|
22
|
+
// - Order (4.131): with `ordered`, cards keep `items`' order and a drag
|
|
23
|
+
// within a column (or a group) reorders them, a line showing where the
|
|
24
|
+
// card will land; the menu has Move Up, Move Down and Move to Top. A
|
|
25
|
+
// column with `ordered: false` (a Done column, by date) has none of it.
|
|
26
|
+
// - Paging (4.131): with `pageSize`, a column or a group shows its first
|
|
27
|
+
// cards, then "Show N More". `pageKey` changing (the filters) folds every
|
|
28
|
+
// one back to its first page.
|
|
17
29
|
// - Moving: with `onMove`, a card drags to another column (a pointer) and
|
|
18
30
|
// has a Move button (a menu of `moveTo`, by default the columns: the
|
|
19
31
|
// keyboard and a phone, where there is no drag). `moveTo` may add values
|
|
20
32
|
// with no column, such as Dropped, which take the card off the board.
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
33
|
+
// With `menu`, the button is ⋯ ("Actions for <name>") and holds the app's
|
|
34
|
+
// own items too. After a move from the menu the focus goes back to the
|
|
35
|
+
// card's menu button where it now is (to the board, if the card left it),
|
|
36
|
+
// and a status line says where the card went.
|
|
24
37
|
// Without `onMove` the board is read-only: a computed field.
|
|
25
|
-
// `onMove(item, value)` is the save
|
|
26
|
-
//
|
|
27
|
-
//
|
|
38
|
+
// `onMove(item, value, place)` is the save: `place` is the card's group
|
|
39
|
+
// and its new neighbours (`beforeId`, `afterId`) on an ordered column.
|
|
40
|
+
// The app makes it optimistic (useRecordUpdate), so placing cards by
|
|
41
|
+
// `getColumn` on the record shows a move at once, and a refusal puts the
|
|
42
|
+
// card back.
|
|
28
43
|
// - States: `isLoading` (skeleton columns), `error` (ErrorState with
|
|
29
44
|
// `onRetry`), and an empty board (`emptyTitle`, `emptyDescription`,
|
|
30
45
|
// `emptyAction`), each for the board as a whole; an empty column is not
|
|
@@ -32,100 +47,331 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
32
47
|
//
|
|
33
48
|
// Columns share the width, at least 16rem each, and scroll sideways with
|
|
34
49
|
// snap points when they don't fit. A phone shows one column at a time,
|
|
35
|
-
// with the edge of the next one showing
|
|
50
|
+
// with the edge of the next one showing; `phone="counts"` shows a row of
|
|
51
|
+
// the columns' counts instead, below lg, that picks the one column shown.
|
|
36
52
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
37
|
-
import { ArrowRightLeftIcon } from 'lucide-react';
|
|
53
|
+
import { ArrowRightLeftIcon, ChevronDownIcon, ChevronRightIcon, EllipsisIcon } from 'lucide-react';
|
|
38
54
|
import { cn } from 'cn';
|
|
39
55
|
import { ErrorState } from './error-state.js';
|
|
40
56
|
import { Button } from '../ui/button.js';
|
|
41
57
|
import { Card } from '../ui/card.js';
|
|
42
|
-
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
58
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
43
59
|
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle } from '../ui/empty.js';
|
|
44
60
|
import { Skeleton } from '../ui/skeleton.js';
|
|
61
|
+
import { dropPlace, endPlace, moreCount, neighboursOf, orderTargets, placeNumber, shownCount, } from './board-order.js';
|
|
45
62
|
// The drag's data type: a card of this board, and nothing a drop from
|
|
46
63
|
// elsewhere (a file, a link) carries.
|
|
47
64
|
const DRAG_TYPE = 'application/x-ui-foundation-board-card';
|
|
48
65
|
// At least 16rem, sharing the width; on a phone the board's width less 2rem,
|
|
49
66
|
// so the next column's edge shows there is more to scroll to.
|
|
50
67
|
const COLUMN_WIDTH = 'min-w-[calc(100%-2rem)] flex-1 basis-0 sm:min-w-64';
|
|
68
|
+
// The phone's counts row picks one column, the board's whole width below lg.
|
|
69
|
+
const COUNTS_COLUMN_WIDTH = 'min-w-0 flex-1 basis-0 lg:min-w-64';
|
|
70
|
+
// The drop line (1A): 3px in the text colour, inset 4px, centred in the
|
|
71
|
+
// 8px gap above (or below) a card.
|
|
72
|
+
const DROP_LINE = 'pointer-events-none absolute inset-x-1 h-[3px] rounded-full bg-foreground';
|
|
51
73
|
const columnName = (column) => column.name ?? (typeof column.label === 'string' ? column.label : column.value);
|
|
52
|
-
|
|
74
|
+
const sameId = (a, b) => (a === null || b === null ? a === b : String(a) === String(b));
|
|
75
|
+
const zoneKey = (value, group) => (group === undefined ? value : `${value}\u0000${group}`);
|
|
76
|
+
const ORDER_WORDS = { up: 'up', down: 'down', top: 'to the top' };
|
|
77
|
+
// Where in a zone's shown cards a drag's pointer is: before or after the
|
|
78
|
+
// card under it (its top or bottom half), or after the last when on none.
|
|
79
|
+
function pointerIndex(event, shownIds) {
|
|
80
|
+
const card = event.target.closest('[data-board-card]');
|
|
81
|
+
const at = card ? shownIds.findIndex((id) => String(id) === card.getAttribute('data-board-card')) : -1;
|
|
82
|
+
if (card === null || at < 0)
|
|
83
|
+
return shownIds.length;
|
|
84
|
+
const box = card.getBoundingClientRect();
|
|
85
|
+
return at + (event.clientY > box.top + box.height / 2 ? 1 : 0);
|
|
86
|
+
}
|
|
87
|
+
export function Board({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel = 2, ordered = false, getGroup, pageSize, pageKey, menu, phone = 'swipe', isLoading = false, error = null, onRetry, emptyTitle = 'Nothing here yet', emptyDescription, emptyAction, }) {
|
|
53
88
|
const boardRef = useRef(null);
|
|
89
|
+
const boardId = useId();
|
|
54
90
|
const [announcement, setAnnouncement] = useState('');
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
91
|
+
// The card being dragged: the native events come faster than React
|
|
92
|
+
// renders, and dragover can't read the drag's data, so a ref holds it.
|
|
93
|
+
const dragging = useRef(null);
|
|
94
|
+
const [dragId, setDragId] = useState(null);
|
|
95
|
+
const [over, setOver] = useState(null);
|
|
96
|
+
const [pages, setPages] = useState({ key: pageKey, open: {} });
|
|
97
|
+
const [folded, setFolded] = useState({});
|
|
98
|
+
const [phoneColumn, setPhoneColumn] = useState(undefined);
|
|
99
|
+
// A move from the menu, until its card is where it was sent. A card moved
|
|
100
|
+
// to another column is remounted there, so the button that had the focus
|
|
101
|
+
// is gone: its new one takes the focus, or the board does.
|
|
58
102
|
const moved = useRef(null);
|
|
59
103
|
useEffect(() => {
|
|
60
104
|
const pending = moved.current;
|
|
61
105
|
if (pending === null)
|
|
62
106
|
return;
|
|
63
107
|
const item = items.find((candidate) => String(getId(candidate)) === pending.id);
|
|
64
|
-
if (item !== undefined
|
|
65
|
-
|
|
108
|
+
if (item !== undefined) {
|
|
109
|
+
if (getColumn(item) !== pending.value)
|
|
110
|
+
return;
|
|
111
|
+
if (pending.group !== undefined && getGroup?.(item) !== pending.group)
|
|
112
|
+
return;
|
|
113
|
+
if (pending.neighbours !== undefined) {
|
|
114
|
+
const ids = items
|
|
115
|
+
.filter((candidate) => getColumn(candidate) === pending.value && (pending.group === undefined || getGroup?.(candidate) === pending.group))
|
|
116
|
+
.map(getId);
|
|
117
|
+
const now = neighboursOf(ids, pending.id);
|
|
118
|
+
if (now === null || !sameId(now.beforeId, pending.neighbours.beforeId) || !sameId(now.afterId, pending.neighbours.afterId))
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
66
122
|
moved.current = null;
|
|
67
123
|
const board = boardRef.current;
|
|
68
|
-
|
|
69
|
-
// wherever the user has gone since.
|
|
70
|
-
if (board === null || (document.activeElement !== null && document.activeElement !== document.body))
|
|
124
|
+
if (board === null)
|
|
71
125
|
return;
|
|
72
126
|
const button = Array.from(board.querySelectorAll('[data-board-move]')).find((candidate) => candidate.dataset.boardMove === pending.id);
|
|
127
|
+
// Only when the focus was lost with the old button (or is still on it),
|
|
128
|
+
// never taken from wherever the user has gone since.
|
|
129
|
+
const active = document.activeElement;
|
|
130
|
+
if (active !== null && active !== document.body && active !== button)
|
|
131
|
+
return;
|
|
73
132
|
(button ?? board).focus();
|
|
74
|
-
}, [items, getId, getColumn]);
|
|
133
|
+
}, [items, getId, getColumn, getGroup]);
|
|
75
134
|
if (error) {
|
|
76
135
|
return (_jsx("div", { "data-slot": "board", "data-state": "error", children: _jsx(ErrorState, { error: error, onRetry: onRetry }) }));
|
|
77
136
|
}
|
|
78
137
|
if (isLoading) {
|
|
79
138
|
return (_jsx("div", { "data-slot": "board", "data-state": "loading", role: "group", "aria-busy": "true", "aria-label": ariaLabel, className: "flex gap-3 overflow-x-auto pb-2", children: columns.map((column) => (_jsxs("div", { className: cn('flex flex-col gap-2 rounded-lg bg-muted p-2 [--muted-foreground:var(--table-highlight-muted-foreground)]', COLUMN_WIDTH), children: [_jsx(Skeleton, { className: "h-5 w-24" }), _jsx(Skeleton, { className: "h-20 w-full" }), _jsx(Skeleton, { className: "h-20 w-full" })] }, column.value))) }));
|
|
80
139
|
}
|
|
81
|
-
const
|
|
140
|
+
const groupOf = (item) => getGroup?.(item);
|
|
141
|
+
const inColumn = (item, column) => getColumn(item) === column.value && (column.groups === undefined || column.groups.some((group) => group.value === groupOf(item)));
|
|
142
|
+
const shown = items.filter((item) => columns.some((column) => inColumn(item, column)));
|
|
82
143
|
if (shown.length === 0) {
|
|
83
144
|
return (_jsx("div", { "data-slot": "board", "data-state": "empty", children: _jsxs(Empty, { children: [_jsxs(EmptyHeader, { children: [_jsx(EmptyTitle, { children: emptyTitle }), emptyDescription && _jsx(EmptyDescription, { children: emptyDescription })] }), emptyAction && _jsx(EmptyContent, { children: emptyAction })] }) }));
|
|
84
145
|
}
|
|
85
146
|
const targets = moveTo ?? columns.map((column) => ({ value: column.value, label: columnName(column) }));
|
|
86
|
-
const
|
|
87
|
-
|
|
147
|
+
const isOrdered = (column) => onMove !== undefined && column !== undefined && (column.ordered ?? ordered);
|
|
148
|
+
const zoneItems = (value, group) => items.filter((item) => getColumn(item) === value && (group === undefined || groupOf(item) === group));
|
|
149
|
+
const zoneIds = (value, group) => zoneItems(value, group).map(getId);
|
|
150
|
+
const pagesOf = (zone) => (pages.key === pageKey ? (pages.open[zone] ?? 1) : 1);
|
|
151
|
+
const showMore = (zone) => setPages((was) => {
|
|
152
|
+
const open = was.key === pageKey ? was.open : {};
|
|
153
|
+
return { key: pageKey, open: { ...open, [zone]: (open[zone] ?? 1) + 1 } };
|
|
154
|
+
});
|
|
155
|
+
const whereLabel = (value, group) => {
|
|
156
|
+
const column = columns.find((candidate) => candidate.value === value);
|
|
157
|
+
const where = targets.find((target) => target.value === value)?.label ?? (column ? columnName(column) : value);
|
|
158
|
+
const groupLabel = group === undefined ? undefined : column?.groups?.find((candidate) => candidate.value === group)?.label;
|
|
159
|
+
return groupLabel === undefined ? where : `${where}, ${groupLabel}`;
|
|
160
|
+
};
|
|
161
|
+
const save = (item, value, place, message, pending) => {
|
|
162
|
+
setAnnouncement(message);
|
|
163
|
+
if (pending)
|
|
164
|
+
moved.current = pending;
|
|
165
|
+
onMove?.(item, value, place);
|
|
166
|
+
};
|
|
167
|
+
const find = (id) => items.find((candidate) => String(getId(candidate)) === id);
|
|
168
|
+
// The Move To menu: to the end of the column (the card's own group, when
|
|
169
|
+
// it's one of the column's), or off the board.
|
|
170
|
+
const moveToValue = (id, value) => {
|
|
171
|
+
const item = find(id);
|
|
88
172
|
if (onMove === undefined || item === undefined || getColumn(item) === value)
|
|
89
173
|
return;
|
|
90
174
|
const column = columns.find((candidate) => candidate.value === value);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
175
|
+
const own = groupOf(item);
|
|
176
|
+
const group = column?.groups?.some((candidate) => candidate.value === own) ? own : undefined;
|
|
177
|
+
const place = isOrdered(column) && (column?.groups === undefined || group !== undefined)
|
|
178
|
+
? { group, ...endPlace(zoneIds(value, group), id) }
|
|
179
|
+
: { group, beforeId: null, afterId: null };
|
|
180
|
+
save(item, value, place, `Moved ${getName(item)} to ${whereLabel(value, group)}`, { id, value, group });
|
|
96
181
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
182
|
+
// The menu's Order items, within the card's own zone.
|
|
183
|
+
const orderCard = (item, kind) => {
|
|
184
|
+
const value = getColumn(item);
|
|
185
|
+
const column = columns.find((candidate) => candidate.value === value);
|
|
186
|
+
const group = column?.groups ? groupOf(item) : undefined;
|
|
187
|
+
const id = String(getId(item));
|
|
188
|
+
const target = orderTargets(zoneIds(value, group), id)[kind];
|
|
189
|
+
if (target === undefined)
|
|
190
|
+
return;
|
|
191
|
+
save(item, value, { group, ...target }, `Moved ${getName(item)} ${ORDER_WORDS[kind]}`, { id, value, group, neighbours: target });
|
|
192
|
+
};
|
|
193
|
+
// A drop into a zone at an index of its cards (its end, for a folded group).
|
|
194
|
+
const dropInto = (value, group, index) => {
|
|
195
|
+
const id = dragging.current;
|
|
196
|
+
const item = id === null ? undefined : find(id);
|
|
197
|
+
if (onMove === undefined || id === null || item === undefined)
|
|
198
|
+
return;
|
|
199
|
+
const column = columns.find((candidate) => candidate.value === value);
|
|
200
|
+
const sameZone = getColumn(item) === value && (group === undefined || groupOf(item) === group);
|
|
201
|
+
let place;
|
|
202
|
+
if (isOrdered(column)) {
|
|
203
|
+
const ids = zoneIds(value, group);
|
|
204
|
+
const at = dropPlace(ids, index, id);
|
|
205
|
+
if (at === null)
|
|
206
|
+
return;
|
|
207
|
+
place = { group, ...at };
|
|
208
|
+
if (sameZone) {
|
|
209
|
+
const { k, n } = placeNumber(ids, id, at);
|
|
210
|
+
save(item, value, place, `Moved ${getName(item)} to place ${k} of ${n} in ${column ? columnName(column) : value}`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (sameZone)
|
|
216
|
+
return;
|
|
217
|
+
place = { group, beforeId: null, afterId: null };
|
|
218
|
+
}
|
|
219
|
+
save(item, value, place, `Moved ${getName(item)} to ${whereLabel(value, group)}`);
|
|
220
|
+
};
|
|
221
|
+
const endDrag = () => {
|
|
222
|
+
dragging.current = null;
|
|
223
|
+
setDragId(null);
|
|
224
|
+
setOver(null);
|
|
225
|
+
};
|
|
226
|
+
const accepts = (event) => onMove !== undefined && event.dataTransfer.types.includes(DRAG_TYPE);
|
|
227
|
+
// The drag-over and drop handlers of an ordered zone (a column, or a
|
|
228
|
+
// group): the line follows the pointer; a folded group drops at its end.
|
|
229
|
+
const zoneHandlers = (zone, value, group, shownIds, foldedTo) => ({
|
|
230
|
+
onDragOver: (event) => {
|
|
113
231
|
if (!accepts(event))
|
|
114
232
|
return;
|
|
115
233
|
event.preventDefault();
|
|
234
|
+
event.stopPropagation();
|
|
116
235
|
event.dataTransfer.dropEffect = 'move';
|
|
117
|
-
|
|
118
|
-
|
|
236
|
+
const index = foldedTo ?? pointerIndex(event, shownIds);
|
|
237
|
+
if (over?.zone !== zone || over.index !== index)
|
|
238
|
+
setOver({ zone, index });
|
|
239
|
+
},
|
|
240
|
+
onDragLeave: (event) => {
|
|
119
241
|
if (!event.currentTarget.contains(event.relatedTarget))
|
|
120
|
-
setOver(
|
|
121
|
-
},
|
|
122
|
-
|
|
242
|
+
setOver((was) => (was?.zone === zone ? null : was));
|
|
243
|
+
},
|
|
244
|
+
onDrop: (event) => {
|
|
123
245
|
if (!accepts(event))
|
|
124
246
|
return;
|
|
125
247
|
event.preventDefault();
|
|
126
|
-
|
|
127
|
-
|
|
248
|
+
event.stopPropagation();
|
|
249
|
+
dropInto(value, group, foldedTo ?? pointerIndex(event, shownIds));
|
|
250
|
+
endDrag();
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
const anyAction = columns.some((column) => column.action !== undefined);
|
|
254
|
+
const counts = phone === 'counts';
|
|
255
|
+
const chosen = phoneColumn ?? columns[0]?.value;
|
|
256
|
+
const columnId = (value) => `${boardId}-column-${value}`;
|
|
257
|
+
// One card. On an ordered column it sits in a slot that holds the drop
|
|
258
|
+
// line (the card itself clips what overflows it).
|
|
259
|
+
const cardView = (item, column, zone, index, shownLength) => {
|
|
260
|
+
const id = String(getId(item));
|
|
261
|
+
const ordering = isOrdered(column);
|
|
262
|
+
const value = getColumn(item);
|
|
263
|
+
const group = column.groups ? groupOf(item) : undefined;
|
|
264
|
+
const order = ordering ? orderTargets(zoneIds(value, group), id) : undefined;
|
|
265
|
+
const card = (_jsx(Card, { size: "sm", "data-slot": "board-card", "data-board-card": ordering ? id : undefined, draggable: onMove ? true : undefined, onDragStart: onMove
|
|
266
|
+
? (event) => {
|
|
267
|
+
// Picked up by its title link or anywhere else: the whole
|
|
268
|
+
// card is what's dragged, not the link's text.
|
|
269
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
270
|
+
event.dataTransfer.setDragImage(event.currentTarget, event.clientX - box.left, event.clientY - box.top);
|
|
271
|
+
event.dataTransfer.setData(DRAG_TYPE, id);
|
|
272
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
273
|
+
dragging.current = id;
|
|
274
|
+
setDragId(id);
|
|
275
|
+
}
|
|
276
|
+
: undefined, onDragEnd: onMove ? endDrag : undefined, className: cn('glow-edge gap-2 px-3 py-3', onMove && 'cursor-grab active:cursor-grabbing', ordering && dragId === id && 'opacity-50'), children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: renderCard(item) }), onMove && (_jsx(CardMenu, { id: id, name: getName(item), value: value, targets: targets, onMove: (next) => moveToValue(id, next), order: order && {
|
|
277
|
+
allowed: { up: order.up !== undefined, down: order.down !== undefined, top: order.top !== undefined },
|
|
278
|
+
run: (kind) => orderCard(item, kind),
|
|
279
|
+
}, extra: menu?.(item) }))] }) }, getId(item)));
|
|
280
|
+
if (!ordering)
|
|
281
|
+
return card;
|
|
282
|
+
const line = over?.zone === zone ? (over.index === index ? 'before' : over.index >= shownLength && index === shownLength - 1 ? 'after' : null) : null;
|
|
283
|
+
return (_jsxs("div", { "data-slot": "board-card-slot", className: "relative", children: [line && _jsx("span", { "aria-hidden": "true", "data-slot": "board-drop-line", className: cn(DROP_LINE, line === 'before' ? '-top-[5.5px]' : '-bottom-[5.5px]') }), card] }, getId(item)));
|
|
284
|
+
};
|
|
285
|
+
// A zone's cards: its first page, "Show N More", or its empty line.
|
|
286
|
+
const zoneCards = (column, zone, cards, empty) => {
|
|
287
|
+
const page = pagesOf(zone);
|
|
288
|
+
const visible = cards.slice(0, shownCount(cards.length, pageSize, page));
|
|
289
|
+
const more = moreCount(cards.length, pageSize, page);
|
|
290
|
+
const lineInEmpty = isOrdered(column) && cards.length === 0 && over?.zone === zone;
|
|
291
|
+
return (_jsxs(_Fragment, { children: [visible.map((item, index) => cardView(item, column, zone, index, visible.length)), more > 0 && (_jsxs(Button, { variant: "ghost", size: "sm", className: "self-start", onClick: () => showMore(zone), children: ["Show ", more, " More"] })), cards.length === 0 && (_jsxs("p", { className: cn('px-1 py-6 text-center type-caption text-muted-foreground', lineInEmpty && 'relative'), children: [empty ?? 'Nothing here', lineInEmpty && _jsx("span", { "aria-hidden": "true", "data-slot": "board-drop-line", className: cn(DROP_LINE, 'top-0') })] }))] }));
|
|
292
|
+
};
|
|
293
|
+
// A drop on a column with no order: only a change of column.
|
|
294
|
+
const moveToValueByDrag = (id, value) => {
|
|
295
|
+
dragging.current = id;
|
|
296
|
+
dropInto(value, undefined, 0);
|
|
297
|
+
endDrag();
|
|
298
|
+
};
|
|
299
|
+
const columnsView = columns.map((column) => {
|
|
300
|
+
const ordering = isOrdered(column);
|
|
301
|
+
const headingId = `${columnId(column.value)}-heading`;
|
|
302
|
+
let body;
|
|
303
|
+
let count;
|
|
304
|
+
let handlers;
|
|
305
|
+
if (column.groups) {
|
|
306
|
+
const groups = column.groups.map((group) => ({ group, cards: zoneItems(column.value, group.value) }));
|
|
307
|
+
count = column.count ?? groups.reduce((sum, { cards }) => sum + cards.length, 0);
|
|
308
|
+
const GroupHeading = `h${Math.min(headingLevel + 1, 6)}`;
|
|
309
|
+
body = groups.map(({ group, cards }) => {
|
|
310
|
+
const zone = zoneKey(column.value, group.value);
|
|
311
|
+
const open = !(folded[zone] ?? group.defaultOpen === false);
|
|
312
|
+
const visible = cards.slice(0, shownCount(cards.length, pageSize, pagesOf(zone))).map(getId);
|
|
313
|
+
const groupId = `${columnId(column.value)}-group-${group.value}`;
|
|
314
|
+
const dropHere = onMove === undefined
|
|
315
|
+
? undefined
|
|
316
|
+
: ordering
|
|
317
|
+
? zoneHandlers(zone, column.value, group.value, open ? visible : [], open ? undefined : cards.length)
|
|
318
|
+
: zoneHandlers(zone, column.value, group.value, [], 0);
|
|
319
|
+
const overFolded = !open && over?.zone === zone;
|
|
320
|
+
return (_jsxs("div", { role: "group", "aria-labelledby": `${groupId}-heading`, "data-slot": "board-group", className: "flex flex-col gap-2", ...dropHere, children: [_jsx(GroupHeading, { id: `${groupId}-heading`, className: "m-0", children: _jsxs("button", { type: "button", "aria-expanded": open, "aria-controls": groupId, onClick: () => setFolded((was) => ({ ...was, [zone]: open })), className: cn('flex min-h-9 w-full items-center gap-1.5 rounded-md px-1 text-left text-xs font-semibold tracking-wide text-muted-foreground uppercase outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50', overFolded && 'ring-2 ring-foreground'), children: [open ? _jsx(ChevronDownIcon, { "aria-hidden": "true", className: "size-4" }) : _jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-4" }), group.label, " ", _jsx("span", { className: "font-normal tracking-normal tabular-nums", children: group.count ?? cards.length })] }) }), _jsxs("div", { id: groupId, hidden: !open, className: "flex flex-col gap-2", children: [open && zoneCards(column, zone, cards, group.empty), open && group.footer && _jsx("div", { className: "px-1 type-caption text-muted-foreground", children: group.footer })] })] }, group.value));
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const zone = zoneKey(column.value);
|
|
325
|
+
const cards = shown.filter((item) => getColumn(item) === column.value);
|
|
326
|
+
count = column.count ?? cards.length;
|
|
327
|
+
const visible = cards.slice(0, shownCount(cards.length, pageSize, pagesOf(zone))).map(getId);
|
|
328
|
+
if (ordering)
|
|
329
|
+
handlers = zoneHandlers(zone, column.value, undefined, visible);
|
|
330
|
+
body = zoneCards(column, zone, cards, column.empty);
|
|
331
|
+
}
|
|
332
|
+
return (_jsxs(BoardColumnView, { id: counts ? columnId(column.value) : undefined, headingId: counts || column.groups ? headingId : undefined, column: column, count: count, headingLevel: headingLevel, actionSpace: anyAction, className: counts ? cn(COUNTS_COLUMN_WIDTH, chosen !== column.value && 'hidden lg:flex') : COLUMN_WIDTH, handlers: handlers, onDrop: onMove && !ordering && !column.groups ? (id) => moveToValueByDrag(id, column.value) : undefined, children: [body, column.footer && _jsx("div", { className: "px-1 type-caption text-muted-foreground", children: column.footer })] }, column.value));
|
|
333
|
+
});
|
|
334
|
+
const board = (_jsxs("div", { ref: boardRef, "data-slot": "board", "data-state": "success", role: "group", "aria-label": ariaLabel, tabIndex: -1, className: "flex snap-x snap-mandatory gap-3 overflow-x-auto pb-2 outline-none", children: [columnsView, _jsx("span", { role: "status", className: "sr-only", children: announcement })] }));
|
|
335
|
+
if (!counts)
|
|
336
|
+
return board;
|
|
337
|
+
return (_jsxs("div", { "data-slot": "board-frame", className: "flex min-w-0 flex-col gap-3", children: [_jsx("div", { role: "group", "aria-label": `${ariaLabel}: columns`, "data-slot": "board-counts", className: "grid gap-1 lg:hidden", style: { gridTemplateColumns: `repeat(${columns.length}, minmax(0, 1fr))` }, children: columns.map((column) => {
|
|
338
|
+
const total = column.count ??
|
|
339
|
+
(column.groups ? items.filter((item) => inColumn(item, column)).length : items.filter((item) => getColumn(item) === column.value).length);
|
|
340
|
+
return (_jsxs("button", { type: "button", "aria-pressed": chosen === column.value, "aria-controls": columnId(column.value), onClick: () => setPhoneColumn(column.value), className: cn('flex min-h-11 min-w-0 flex-col items-center justify-center gap-0.5 rounded-lg border px-0.5 py-1.5 outline-none focus-visible:ring-3 focus-visible:ring-ring/50', chosen === column.value ? 'border-primary bg-primary/10 text-foreground' : 'border-transparent bg-muted/50 text-muted-foreground'), children: [_jsx("span", { className: "text-base font-semibold tabular-nums", children: total }), ' ', _jsx("span", { className: "max-w-full truncate text-[0.6875rem] font-medium", children: column.shortName ?? columnName(column) })] }, column.value));
|
|
341
|
+
}) }), board] }));
|
|
342
|
+
}
|
|
343
|
+
function BoardColumnView({ id, headingId: givenHeadingId, column, count, headingLevel, actionSpace, className, handlers, onDrop, children, }) {
|
|
344
|
+
const [over, setOver] = useState(false);
|
|
345
|
+
const ownHeadingId = useId();
|
|
346
|
+
const headingId = givenHeadingId ?? ownHeadingId;
|
|
347
|
+
const Heading = `h${headingLevel}`;
|
|
348
|
+
const accepts = (event) => onDrop !== undefined && event.dataTransfer.types.includes(DRAG_TYPE);
|
|
349
|
+
const slotted = column.note !== undefined || column.action !== undefined || actionSpace || column.description !== undefined;
|
|
350
|
+
const heading = (_jsxs(Heading, { id: headingId, className: slotted ? 'flex items-center gap-2 type-label' : 'flex items-center gap-2 px-1 pt-0.5 type-label', children: [column.label, _jsx("span", { className: "font-normal tabular-nums text-muted-foreground", children: count })] }));
|
|
351
|
+
return (_jsxs("section", { id: id, "aria-labelledby": headingId, "data-slot": "board-column", "data-over": over || undefined, className: cn(column.lead
|
|
352
|
+
? 'flex snap-start flex-col gap-2 rounded-lg border-2 border-foreground bg-background p-2 outline-2 outline-offset-2 outline-transparent data-over:outline-ring'
|
|
353
|
+
: 'flex snap-start flex-col gap-2 rounded-lg bg-muted p-2 [--muted-foreground:var(--table-highlight-muted-foreground)] outline-2 outline-offset-2 outline-transparent data-over:outline-ring', className), ...(handlers ?? {
|
|
354
|
+
onDragOver: (event) => {
|
|
355
|
+
if (!accepts(event))
|
|
356
|
+
return;
|
|
357
|
+
event.preventDefault();
|
|
358
|
+
event.dataTransfer.dropEffect = 'move';
|
|
359
|
+
setOver(true);
|
|
360
|
+
},
|
|
361
|
+
onDragLeave: (event) => {
|
|
362
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
363
|
+
setOver(false);
|
|
364
|
+
},
|
|
365
|
+
onDrop: (event) => {
|
|
366
|
+
setOver(false);
|
|
367
|
+
if (!accepts(event))
|
|
368
|
+
return;
|
|
369
|
+
event.preventDefault();
|
|
370
|
+
onDrop?.(event.dataTransfer.getData(DRAG_TYPE));
|
|
371
|
+
},
|
|
372
|
+
}), children: [slotted ? (_jsxs("div", { className: "flex flex-col gap-0.5 px-1 pt-0.5", children: [_jsxs("div", { className: "flex min-h-9 items-center gap-2", children: [heading, _jsx("span", { "aria-hidden": "true", className: "flex-1" }), column.note !== undefined && _jsx("span", { className: "type-caption text-muted-foreground", children: column.note }), column.action ?? (actionSpace && _jsx("span", { "aria-hidden": "true", className: "size-9 shrink-0" }))] }), column.description !== undefined && _jsx("p", { className: "type-caption text-muted-foreground", children: column.description })] })) : (heading), children] }));
|
|
128
373
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
374
|
+
function CardMenu({ id, name, value, targets, onMove, order, extra, }) {
|
|
375
|
+
const actions = extra !== undefined && extra !== null && extra !== false;
|
|
376
|
+
return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: actions ? (_jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Actions for ${name}`, title: "Actions", "data-board-move": id })) : (_jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Move ${name}`, title: "Move To\u2026", "data-board-move": id })), children: actions ? _jsx(EllipsisIcon, { "aria-hidden": "true" }) : _jsx(ArrowRightLeftIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-44", children: [_jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Move To" }), _jsx(DropdownMenuRadioGroup, { value: value, onValueChange: (next) => onMove(next), children: targets.map((target) => (_jsx(DropdownMenuRadioItem, { value: target.value, closeOnClick: true, children: target.label }, target.value))) })] }), order && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Order" }), _jsx(DropdownMenuItem, { disabled: !order.allowed.up, onClick: () => order.run('up'), children: "Move Up" }), _jsx(DropdownMenuItem, { disabled: !order.allowed.down, onClick: () => order.run('down'), children: "Move Down" }), _jsx(DropdownMenuItem, { disabled: !order.allowed.top, onClick: () => order.run('top'), children: "Move to Top" })] })] })), actions && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), extra] }))] })] }));
|
|
131
377
|
}
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AppShell, type AppShellProps, type AppShellSearch, type RecentRecord, type SearchRecord, type AppShellVersion, type BottomBarItem, type NavEntry, type NavItem, type NavLook, type NavSection, } from './components/app/app-shell.js';
|
|
2
2
|
export type { IconComponent } from './components/app/icon-component.js';
|
|
3
|
-
export { Board, type BoardColumn, type BoardMoveTarget, type BoardProps } from './components/app/board.js';
|
|
3
|
+
export { Board, type BoardColumn, type BoardGroup, type BoardMoveTarget, type BoardPlace, type BoardProps } from './components/app/board.js';
|
|
4
4
|
export { SpinWheel, type SpinWheelProps } from './components/app/spin-wheel.js';
|
|
5
5
|
export { pickSpinWheelIndex, type SpinWheelItem } from './components/app/spin-wheel-pick.js';
|
|
6
6
|
export { FillInChoice, FillInQueue, type FillInChoiceProps, type FillInQueueGroup, type FillInQueueProgress, type FillInQueueProps, } from './components/app/fill-in-queue.js';
|
|
@@ -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.
|
|
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": {
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
"build-harness": "vite build -c vite.harness.config.ts",
|
|
71
71
|
"preview-harness": "vite preview -c vite.harness.config.ts",
|
|
72
72
|
"verify:fast": "npm run gen:api && git diff --exit-code -- src/api/schema.ts && node scripts/doc-index.mjs --check && tsc -b && eslint . --max-warnings 0 && node bin/ui-foundation.mjs check-deps && npm run build && vitest run",
|
|
73
|
-
"verify": "
|
|
73
|
+
"verify:harness": "playwright test -c playwright.harness.config.ts",
|
|
74
|
+
"verify": "npm run verify:fast && npm run verify:harness"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
77
|
"@axe-core/playwright": "^4.13.0",
|