basalt-ui 2.27.2 → 2.28.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/CHANGELOG.md +99 -0
- package/MIGRATING.md +168 -12
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-tokens.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +40 -36
- package/agent/skills/basalt-design/references/recipes.md +47 -0
- package/configs/oxlint-basalt.json +2 -1
- package/configs/oxlint-plugin.js +110 -2
- package/configs/oxlint-plugin.test.ts +99 -4
- package/dist/agent/chat/thread-message.d.ts +1 -160
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +7 -162
- package/dist/agent/chat/virtualize.d.ts +5 -5
- package/dist/charts/ChartCard.d.ts +5 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +46 -13
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +11 -4
- package/dist/charts/Sparkline.d.ts +9 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +104 -41
- package/dist/charts/chart-box.module.css +50 -0
- package/dist/charts/chart-box.module.css.d.ts +5 -0
- package/dist/charts/chart-card.module.css +12 -4
- package/dist/charts/chart-card.module.css.d.ts +1 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +20 -18
- package/dist/charts/labels.d.ts +13 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +131 -20
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +1 -1
- package/dist/charts/ref-label.d.ts +31 -8
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +40 -9
- package/dist/charts/sparkline.module.css +6 -0
- package/dist/charts/state.d.ts +3 -3
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +20 -2
- package/dist/cli/shot/capture.d.ts +6 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +18 -5
- package/dist/common/empty-copy.d.ts +16 -0
- package/dist/common/empty-copy.d.ts.map +1 -0
- package/dist/common/empty-copy.js +9 -0
- package/dist/common/virtual-rows.d.ts +196 -0
- package/dist/common/virtual-rows.d.ts.map +1 -0
- package/dist/common/virtual-rows.js +290 -0
- package/dist/controls/controls.module.css +33 -1
- package/dist/controls/controls.module.css.d.ts +2 -0
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -2
- package/dist/controls/filter-pill.d.ts +27 -3
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +15 -4
- package/dist/controls/form-layout.d.ts +9 -3
- package/dist/controls/form-layout.d.ts.map +1 -1
- package/dist/controls/form-layout.js +74 -12
- package/dist/controls/form-layout.module.css +112 -7
- package/dist/controls/form-layout.module.css.d.ts +1 -0
- package/dist/controls/multi-select-filter.d.ts +2 -2
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +12 -6
- package/dist/controls/range-filter.d.ts +1 -1
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +8 -2
- package/dist/dashboard/bar-list.d.ts +1 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +6 -2
- package/dist/dashboard/bar-list.module.css +0 -2
- package/dist/dashboard/board-nav.d.ts +22 -0
- package/dist/dashboard/board-nav.d.ts.map +1 -0
- package/dist/dashboard/board-nav.js +49 -0
- package/dist/dashboard/board.d.ts +52 -0
- package/dist/dashboard/board.d.ts.map +1 -0
- package/dist/dashboard/board.js +228 -0
- package/dist/dashboard/board.module.css +160 -0
- package/dist/dashboard/board.module.css.d.ts +26 -0
- package/dist/dashboard/empty-state.d.ts +3 -3
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +13 -6
- package/dist/dashboard/event-list-model.d.ts +51 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -0
- package/dist/dashboard/event-list-model.js +72 -0
- package/dist/dashboard/event-list-rows.d.ts +23 -0
- package/dist/dashboard/event-list-rows.d.ts.map +1 -0
- package/dist/dashboard/event-list-rows.js +93 -0
- package/dist/dashboard/event-list-scroll.d.ts +27 -0
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
- package/dist/dashboard/event-list-scroll.js +103 -0
- package/dist/dashboard/event-list-skeleton.d.ts +10 -0
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
- package/dist/dashboard/event-list-skeleton.js +36 -0
- package/dist/dashboard/event-list.d.ts +65 -0
- package/dist/dashboard/event-list.d.ts.map +1 -0
- package/dist/dashboard/event-list.js +178 -0
- package/dist/dashboard/event-list.module.css +283 -0
- package/dist/dashboard/event-list.module.css.d.ts +33 -0
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +5 -3
- package/dist/dashboard/meter.module.css +2 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/settings-section.d.ts +4 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +1 -1
- package/dist/dashboard/settings-section.module.css +19 -4
- package/dist/dashboard/stat-card-parts.d.ts +5 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +8 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +25 -6
- package/dist/dashboard/stat-card.module.css +31 -7
- package/dist/dashboard/stat-card.module.css.d.ts +3 -0
- package/dist/dashboard/stat-strip.module.css +4 -1
- package/dist/dashboard/widget-header.module.css +17 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/shell/app-main.module.css +18 -0
- package/dist/styles.css +46 -0
- package/dist/surfaces.d.ts +2 -2
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +8 -2
- package/dist/table/cell-kinds.d.ts +44 -0
- package/dist/table/cell-kinds.d.ts.map +1 -0
- package/dist/table/cell-kinds.js +169 -0
- package/dist/table/cell-kinds.module.css +55 -0
- package/dist/table/cell-kinds.module.css.d.ts +15 -0
- package/dist/table/data-table-fold.d.ts +147 -0
- package/dist/table/data-table-fold.d.ts.map +1 -0
- package/dist/table/data-table-fold.js +288 -0
- package/dist/table/data-table-state.d.ts +10 -3
- package/dist/table/data-table-state.d.ts.map +1 -1
- package/dist/table/data-table-state.js +11 -6
- package/dist/table/data-table.d.ts +11 -26
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +354 -254
- package/dist/table/data-table.module.css +210 -3
- package/dist/table/data-table.module.css.d.ts +12 -0
- package/dist/table/table-features.d.ts +34 -4
- package/dist/table/table-features.d.ts.map +1 -1
- package/dist/table/table-features.js +10 -0
- package/dist/theme/card-inset.module.css +35 -0
- package/dist/theme/controls.module.css +32 -0
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +5 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +14 -10
- package/dist/tokens/core.d.ts +1 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +1 -0
- package/dist/tokens/derive.js +1 -1
- package/dist/tokens/palette.d.ts +2 -1
- package/dist/tokens/palette.d.ts.map +1 -1
- package/llms.txt +34 -5
- package/package.json +1 -1
- package/src/agent/chat/thread-message.tsx +10 -403
- package/src/agent/chat/virtualize.ts +5 -5
- package/src/charts/ChartCard.tsx +79 -17
- package/src/charts/Lines.tsx +13 -4
- package/src/charts/Sparkline.tsx +131 -45
- package/src/charts/chart-box.module.css +50 -0
- package/src/charts/chart-box.module.css.d.ts +5 -0
- package/src/charts/chart-card.module.css +12 -4
- package/src/charts/chart-card.module.css.d.ts +1 -0
- package/src/charts/compile.ts +22 -18
- package/src/charts/labels.ts +175 -24
- package/src/charts/legend.tsx +3 -2
- package/src/charts/ref-label.ts +86 -17
- package/src/charts/sparkline.module.css +6 -0
- package/src/charts/state.tsx +36 -7
- package/src/cli/shot/capture.ts +29 -6
- package/src/common/empty-copy.ts +17 -0
- package/src/common/virtual-rows.tsx +682 -0
- package/src/controls/controls.module.css +33 -1
- package/src/controls/controls.module.css.d.ts +2 -0
- package/src/controls/enum-filter.tsx +8 -2
- package/src/controls/filter-pill.tsx +80 -27
- package/src/controls/form-layout.module.css +112 -7
- package/src/controls/form-layout.module.css.d.ts +1 -0
- package/src/controls/form-layout.tsx +115 -22
- package/src/controls/multi-select-filter.tsx +22 -11
- package/src/controls/range-filter.tsx +9 -3
- package/src/dashboard/bar-list.module.css +0 -2
- package/src/dashboard/bar-list.tsx +8 -5
- package/src/dashboard/board-nav.ts +67 -0
- package/src/dashboard/board.module.css +160 -0
- package/src/dashboard/board.module.css.d.ts +26 -0
- package/src/dashboard/board.tsx +394 -0
- package/src/dashboard/empty-state.tsx +16 -9
- package/src/dashboard/event-list-model.ts +113 -0
- package/src/dashboard/event-list-rows.tsx +120 -0
- package/src/dashboard/event-list-scroll.ts +145 -0
- package/src/dashboard/event-list-skeleton.tsx +58 -0
- package/src/dashboard/event-list.module.css +283 -0
- package/src/dashboard/event-list.module.css.d.ts +33 -0
- package/src/dashboard/event-list.tsx +309 -0
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-parts.tsx +9 -2
- package/src/dashboard/meter.module.css +2 -1
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/settings-section.module.css +19 -4
- package/src/dashboard/settings-section.tsx +7 -2
- package/src/dashboard/stat-card-parts.tsx +20 -3
- package/src/dashboard/stat-card.module.css +31 -7
- package/src/dashboard/stat-card.module.css.d.ts +3 -0
- package/src/dashboard/stat-card.tsx +24 -5
- package/src/dashboard/stat-strip.module.css +4 -1
- package/src/dashboard/widget-header.module.css +17 -1
- package/src/guard/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/shell/app-main.module.css +18 -0
- package/src/styles.css +46 -0
- package/src/surfaces.ts +7 -1
- package/src/table/cell-kinds.module.css +55 -0
- package/src/table/cell-kinds.module.css.d.ts +15 -0
- package/src/table/cell-kinds.tsx +234 -0
- package/src/table/data-table-fold.tsx +514 -0
- package/src/table/data-table-state.ts +24 -13
- package/src/table/data-table.module.css +210 -3
- package/src/table/data-table.module.css.d.ts +12 -0
- package/src/table/data-table.tsx +406 -359
- package/src/table/table-features.ts +44 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
- package/src/theme/card-inset.module.css +35 -0
- package/src/theme/controls.module.css +32 -0
- package/src/theme/ctl-theme.tsx +8 -0
- package/src/theme/index.ts +12 -8
- package/src/tokens/core.ts +1 -0
- package/src/tokens/derive.ts +1 -1
- package/src/tokens/palette.ts +4 -1
package/src/index.ts
CHANGED
|
@@ -107,6 +107,24 @@
|
|
|
107
107
|
* table's page-sticky offset reads it instead of repeating this module's `sm` switch.
|
|
108
108
|
*/
|
|
109
109
|
--basalt-main-pad-block: var(--vx-space-stack-md);
|
|
110
|
+
/*
|
|
111
|
+
* PUBLIC `--basalt-main-content-h` — the height of Main's CONTENT box: what an element at
|
|
112
|
+
* `height: var(--basalt-main-content-h)` needs to fill the scrollport with nothing to scroll (a
|
|
113
|
+
* map, an editor, a full-page canvas). Descendants inherit the resolved length.
|
|
114
|
+
*
|
|
115
|
+
* It is the viewport minus the five things that are not content: the header offset, the footer
|
|
116
|
+
* offset PLUS the safe-area inset (same pair as `margin-bottom` above), the band, and Main's block
|
|
117
|
+
* padding twice. The band is `--basalt-page-bar-h` (its content box, published by `PageBar`) plus
|
|
118
|
+
* its own 1 px `border-bottom` the var never counts (`page-aside.module.css` explains the same
|
|
119
|
+
* pixel): `var(--basalt-page-bar-h, -1px) + 1px` adds it only while a band exists and nets to 0
|
|
120
|
+
* without one. `h="100%"` cannot do this job — Main sizes itself by flex, so a percentage height
|
|
121
|
+
* on a child does not resolve against it.
|
|
122
|
+
*/
|
|
123
|
+
--basalt-main-content-h: calc(
|
|
124
|
+
100dvh - var(--app-shell-header-offset, 0px) - var(--app-shell-footer-offset, 0px) -
|
|
125
|
+
env(safe-area-inset-bottom, 0px) - (var(--basalt-page-bar-h, -1px) + 1px) - 2 *
|
|
126
|
+
var(--basalt-main-pad-block)
|
|
127
|
+
);
|
|
110
128
|
padding: var(--basalt-main-pad-block) var(--app-shell-padding);
|
|
111
129
|
/* Without this a wide flex/grid child (a bare table, a nowrap control row) sizes Main to ITSELF. */
|
|
112
130
|
min-width: 0;
|
package/src/styles.css
CHANGED
|
@@ -386,6 +386,52 @@
|
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
+
/* MapLibre's compact attribution (Wave 43, argo's astro Map tab). basalt has no maplibre dependency;
|
|
390
|
+
* this only restyles the control a consumer's map renders, onto the radius scale and the micro text
|
|
391
|
+
* size: the shipped 12 px radius on the box and its 24 px button is off the scale and, over a card,
|
|
392
|
+
* a nested step under 3 px. The box takes the control tier (4 px under a flush card), the button the
|
|
393
|
+
* Mantine `xs` step (4 px under the box).
|
|
394
|
+
*
|
|
395
|
+
* UNLAYERED on purpose: `maplibre-gl.css` is unlayered, and an unlayered rule beats every layered
|
|
396
|
+
* one whatever the specificity, so a `@layer basalt` block would lose to it. The doubled `:root`
|
|
397
|
+
* lifts each rule to (0,4,0), over maplibre's highest (0,3,0) (`.maplibregl-ctrl-bottom-left >
|
|
398
|
+
* .maplibregl-ctrl-attrib.maplibregl-compact-show`, which sets its own 12 px radius), whichever
|
|
399
|
+
* stylesheet loads last and in every corner and state. A consumer overrides with a longer selector,
|
|
400
|
+
* or an equal one later in source. `.maplibregl-ctrl-group` is not here: its 4 px radius is already
|
|
401
|
+
* a scale step. */
|
|
402
|
+
:root:root .maplibregl-ctrl.maplibregl-ctrl-attrib {
|
|
403
|
+
border-radius: var(--vx-radius-ctrl);
|
|
404
|
+
background-color: var(--vx-surface-panel);
|
|
405
|
+
color: var(--vx-muted);
|
|
406
|
+
font-size: var(--vx-text-micro);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
:root:root .maplibregl-ctrl-attrib a {
|
|
410
|
+
color: inherit;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/* One step under the box, snapped onto the scale like the SegmentedControl indicator: 2 when the box
|
|
414
|
+
* leaves a 3 px step, else square. */
|
|
415
|
+
:root:root .maplibregl-ctrl-attrib-button {
|
|
416
|
+
/* theme-allow css-raw-surface — a snapped nested step: the scale's 2 px xs, or square under a small box */
|
|
417
|
+
border-radius: round(down, min(2px, max(0px, var(--vx-radius-ctrl) - 3px)), 2px);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/* The glyph is maplibre's dark SVG background-image, drawn again as a mask in the muted ink so it
|
|
421
|
+
* follows the scheme (a `filter` would also invert the button's own fill). */
|
|
422
|
+
:root:root .maplibregl-ctrl-attrib-button {
|
|
423
|
+
background-image: none;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
:root:root .maplibregl-ctrl-attrib-button::after {
|
|
427
|
+
content: '';
|
|
428
|
+
position: absolute;
|
|
429
|
+
inset: 0;
|
|
430
|
+
background-color: var(--vx-muted);
|
|
431
|
+
mask: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 20 20'%3E%3Cpath fill-rule='evenodd' d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0v-3'/%3E%3C/svg%3E")
|
|
432
|
+
center / 24px 24px no-repeat;
|
|
433
|
+
}
|
|
434
|
+
|
|
389
435
|
/* chart-engine:start — generated by scripts/gen-chart-css.ts from chartEngineCss() */
|
|
390
436
|
@layer basalt {
|
|
391
437
|
:root {
|
package/src/surfaces.ts
CHANGED
|
@@ -63,6 +63,7 @@ export const PLUGIN_RULE_ID_LIST = [
|
|
|
63
63
|
'raw-breakpoint',
|
|
64
64
|
'no-dev-helper',
|
|
65
65
|
'route-view-transition',
|
|
66
|
+
'status-fill-as-text',
|
|
66
67
|
] as const
|
|
67
68
|
|
|
68
69
|
/** One registered oxlint plugin rule id — the literal union of {@link PLUGIN_RULE_ID_LIST}. */
|
|
@@ -357,7 +358,12 @@ export const SURFACES = {
|
|
|
357
358
|
// The type-scale rules live with the tokens, not with `.`: both police a value that left the
|
|
358
359
|
// `--vx-*` system, which is this surface's whole subject. `token-layer-boundary` is the
|
|
359
360
|
// repo-local-only rule that keeps the layer upstream of Mantine (see below).
|
|
360
|
-
pluginRules: [
|
|
361
|
+
pluginRules: [
|
|
362
|
+
'no-raw-font-size',
|
|
363
|
+
'raw-size-literal',
|
|
364
|
+
'status-fill-as-text',
|
|
365
|
+
'token-layer-boundary',
|
|
366
|
+
],
|
|
361
367
|
description:
|
|
362
368
|
'VX token refs, buildPaletteCss, defineSeries, seriesTokens, groupTokens, alpha (Mantine-free)',
|
|
363
369
|
globs: {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Cell kinds (`meta.kind`, SPEC § 6.6). Each class is the CHROME of one kind on its `<td>`; the font
|
|
3
|
+
* SIZE stays the theme's `sm` on `td`. Colours are tokens, never literals.
|
|
4
|
+
*/
|
|
5
|
+
.entity {
|
|
6
|
+
max-width: 100%;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
font-weight: 500;
|
|
9
|
+
color: var(--vx-ink);
|
|
10
|
+
text-overflow: ellipsis;
|
|
11
|
+
white-space: nowrap;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.status {
|
|
15
|
+
white-space: nowrap;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* SPEC D33: figures are the proportional sans with lining tabular numerals; only times are mono. */
|
|
19
|
+
.number {
|
|
20
|
+
font-variant-numeric: tabular-nums;
|
|
21
|
+
font-weight: 500;
|
|
22
|
+
color: var(--vx-ink);
|
|
23
|
+
white-space: nowrap;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.relativeTime {
|
|
27
|
+
font-family: var(--mantine-font-family-monospace);
|
|
28
|
+
font-variant-numeric: tabular-nums;
|
|
29
|
+
color: var(--vx-muted);
|
|
30
|
+
white-space: nowrap;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.meter {
|
|
34
|
+
min-width: calc(4rem * var(--mantine-scale));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.text {
|
|
38
|
+
color: var(--vx-ink);
|
|
39
|
+
white-space: normal;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* An absent value: a muted em dash, never an empty cell. */
|
|
43
|
+
.dash {
|
|
44
|
+
color: var(--vx-faint);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* The full date for assistive tech, inside the `<time>`: visually hidden, still announced. */
|
|
48
|
+
.srOnly {
|
|
49
|
+
position: absolute;
|
|
50
|
+
width: 1px;
|
|
51
|
+
height: 1px;
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
clip-path: inset(50%);
|
|
54
|
+
white-space: nowrap;
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
|
|
3
|
+
* signature — so dot access stays verbatim under the package's strict flags.
|
|
4
|
+
*/
|
|
5
|
+
declare const classes: {
|
|
6
|
+
readonly dash: string
|
|
7
|
+
readonly entity: string
|
|
8
|
+
readonly meter: string
|
|
9
|
+
readonly number: string
|
|
10
|
+
readonly relativeTime: string
|
|
11
|
+
readonly srOnly: string
|
|
12
|
+
readonly status: string
|
|
13
|
+
readonly text: string
|
|
14
|
+
}
|
|
15
|
+
export default classes
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `meta.kind` for `BasaltDataTable` (`docs/waves/design-parity/SPEC.md` § 6.6): the chrome a cell
|
|
3
|
+
* takes by KIND, and the content a kind supplies when its column has no `cell` of its own. The table
|
|
4
|
+
* calls three seams from its header and cell render sites: {@link resolveKind} (validate),
|
|
5
|
+
* {@link kindClass} / {@link kindAlign} (chrome) and {@link KindCell} (content).
|
|
6
|
+
*/
|
|
7
|
+
import { Badge, Skeleton, Tooltip } from '@mantine/core'
|
|
8
|
+
import type { Cell, Column, RowData } from '@tanstack/react-table'
|
|
9
|
+
import { FlexRender } from '@tanstack/react-table'
|
|
10
|
+
import type { ReactNode } from 'react'
|
|
11
|
+
import { cx } from '../common/props'
|
|
12
|
+
import { Meter } from '../dashboard/meter'
|
|
13
|
+
import { dateTime, integer, relativeTime } from '../format'
|
|
14
|
+
import { numberFormat } from '../format/shared'
|
|
15
|
+
import { DATA_TABLE_COLUMN_KINDS } from './table-features'
|
|
16
|
+
import type { BasaltTableFeatures, DataTableAlign, DataTableColumnKind } from './table-features'
|
|
17
|
+
import classes from './cell-kinds.module.css'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The table's own default `cell` (TanStack's, restated), installed as `defaultColumn.cell` so a
|
|
21
|
+
* column WITHOUT a renderer is identifiable by identity: v9 merges its default into every
|
|
22
|
+
* `columnDef`, so `columnDef.cell === undefined` can never be asked.
|
|
23
|
+
*/
|
|
24
|
+
export function DEFAULT_CELL(props: { renderValue(): unknown }) {
|
|
25
|
+
return (props.renderValue() as { toString?(): string } | null | undefined)?.toString?.() ?? null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const KINDS: ReadonlySet<string> = new Set(DATA_TABLE_COLUMN_KINDS)
|
|
29
|
+
|
|
30
|
+
/** Reads `meta.kind`, throwing on a value outside the seven — the check a type cannot make at runtime. */
|
|
31
|
+
export function resolveKind<T extends RowData>(
|
|
32
|
+
column: Column<BasaltTableFeatures, T, unknown>,
|
|
33
|
+
): DataTableColumnKind | undefined {
|
|
34
|
+
const kind = column.columnDef.meta?.kind
|
|
35
|
+
if (kind === undefined) return undefined
|
|
36
|
+
if (!KINDS.has(kind)) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`BasaltDataTable: column "${column.id}" has meta.kind=${JSON.stringify(kind)} — ` +
|
|
39
|
+
`expected ${DATA_TABLE_COLUMN_KINDS.map((k) => `'${k}'`).join(' | ')}.`,
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
return kind
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Figures read right: the kind's default alignment, which an explicit `meta.align` overrides. */
|
|
46
|
+
export function kindAlign(kind: DataTableColumnKind | undefined): DataTableAlign | undefined {
|
|
47
|
+
return kind === 'number' || kind === 'money' ? 'right' : undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Column sizing law (SPEC § 6.6): a data column is as wide as its header or widest cell (body cells
|
|
52
|
+
* hold one line), and the slack of a wide container goes to ONE place — the LAST `text` column (a
|
|
53
|
+
* notes/detail column that may wrap), else a trailing spacer after the last data column — so a name
|
|
54
|
+
* sits beside its figures, never a third of the table away. An `entity` column is content-sized.
|
|
55
|
+
* `fixedIds` (the checkbox and actions columns) fit too but are not data. An earlier `text` column
|
|
56
|
+
* keeps its auto share (it may wrap), and a table where no column opted into a kind renders as
|
|
57
|
+
* before: no fit marks, no spacer.
|
|
58
|
+
*/
|
|
59
|
+
export function planColumnSizing<T extends RowData>(
|
|
60
|
+
columns: readonly Column<BasaltTableFeatures, T, unknown>[],
|
|
61
|
+
fixedIds: ReadonlySet<string>,
|
|
62
|
+
): { fitIds: ReadonlySet<string>; spacer: boolean } {
|
|
63
|
+
const data = columns.filter((column) => !fixedIds.has(column.id))
|
|
64
|
+
const kinds = new Map(data.map((column) => [column.id, resolveKind(column)]))
|
|
65
|
+
const fitIds = new Set(columns.filter((column) => fixedIds.has(column.id)).map((c) => c.id))
|
|
66
|
+
const hasKinds = data.some((column) => kinds.get(column.id) !== undefined)
|
|
67
|
+
if (!hasKinds) return { fitIds, spacer: false }
|
|
68
|
+
const slackId = data.findLast((column) => kinds.get(column.id) === 'text')?.id
|
|
69
|
+
for (const column of data) {
|
|
70
|
+
if (column.id === slackId || kinds.get(column.id) === 'text') continue
|
|
71
|
+
fitIds.add(column.id)
|
|
72
|
+
}
|
|
73
|
+
return { fitIds, spacer: slackId === undefined }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A bar's width by kind. A share (`100%`) of a content-sized cell is that cell's own width, so the
|
|
78
|
+
* fit columns take it; the slack column has no width of its own and takes a fixed length.
|
|
79
|
+
*/
|
|
80
|
+
const SKELETON_WIDTH: Record<DataTableColumnKind | 'kindless', string> = {
|
|
81
|
+
number: '3rem',
|
|
82
|
+
money: '3rem',
|
|
83
|
+
status: '4.5rem',
|
|
84
|
+
'relative-time': '4.5rem',
|
|
85
|
+
meter: '4rem',
|
|
86
|
+
entity: '100%',
|
|
87
|
+
text: '10rem',
|
|
88
|
+
kindless: '100%',
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A loading bar shaped like the kind's value: a figure short and flush right, a chip chip-sized. */
|
|
92
|
+
export function KindSkeleton({
|
|
93
|
+
kind,
|
|
94
|
+
right,
|
|
95
|
+
}: {
|
|
96
|
+
kind: DataTableColumnKind | undefined
|
|
97
|
+
right: boolean
|
|
98
|
+
}): ReactNode {
|
|
99
|
+
const chip = kind === 'status'
|
|
100
|
+
const width = SKELETON_WIDTH[kind ?? 'kindless']
|
|
101
|
+
return (
|
|
102
|
+
<Skeleton
|
|
103
|
+
height={chip ? 20 : 16}
|
|
104
|
+
radius="sm"
|
|
105
|
+
w={width}
|
|
106
|
+
maw="100%"
|
|
107
|
+
{...(right && { ml: 'auto' })}
|
|
108
|
+
/>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const KIND_CLASS: Record<DataTableColumnKind, string> = {
|
|
113
|
+
entity: classes.entity,
|
|
114
|
+
status: classes.status,
|
|
115
|
+
number: classes.number,
|
|
116
|
+
money: classes.number,
|
|
117
|
+
'relative-time': classes.relativeTime,
|
|
118
|
+
meter: classes.meter,
|
|
119
|
+
text: classes.text,
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function kindClass(kind: DataTableColumnKind): string {
|
|
123
|
+
return cx(KIND_CLASS[kind])
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A whole number groups; a fraction is kept whole (`integer` would round 12.5 to 13). */
|
|
127
|
+
function formatFigure(value: number): string {
|
|
128
|
+
return Number.isInteger(value)
|
|
129
|
+
? integer(value)
|
|
130
|
+
: numberFormat(undefined, { signDisplay: 'negative', maximumFractionDigits: 20 }).format(value)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A `money` figure: grouped, with the currency's own minor digits (`120,000.00` USD, `120,000` JPY)
|
|
135
|
+
* and no symbol — the header names the code (`Salary (USD / yr)`, SPEC § 6.6).
|
|
136
|
+
*/
|
|
137
|
+
function formatMoney(value: number, currency: string): string {
|
|
138
|
+
const digits = numberFormat(undefined, { style: 'currency', currency }).resolvedOptions()
|
|
139
|
+
.maximumFractionDigits
|
|
140
|
+
return numberFormat(undefined, {
|
|
141
|
+
signDisplay: 'negative',
|
|
142
|
+
minimumFractionDigits: digits,
|
|
143
|
+
maximumFractionDigits: digits,
|
|
144
|
+
}).format(value)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The theme draws no dot for plain `gray`, but every chip in a status column carries one. */
|
|
148
|
+
const chipColor = (color: string | undefined): string =>
|
|
149
|
+
color === undefined || color === 'gray' ? 'var(--vx-faint)' : color
|
|
150
|
+
|
|
151
|
+
const Dash = () => <span className={classes.dash}>—</span>
|
|
152
|
+
|
|
153
|
+
function isAbsent(value: unknown): boolean {
|
|
154
|
+
return value === null || value === undefined || value === ''
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function toDate(value: unknown): Date | undefined {
|
|
158
|
+
if (!(value instanceof Date) && typeof value !== 'number' && typeof value !== 'string') {
|
|
159
|
+
return undefined
|
|
160
|
+
}
|
|
161
|
+
const date = new Date(value)
|
|
162
|
+
return Number.isNaN(date.getTime()) ? undefined : date
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function columnLabel<T extends RowData>(column: Column<BasaltTableFeatures, T, unknown>): string {
|
|
166
|
+
const { header } = column.columnDef
|
|
167
|
+
return typeof header === 'string' ? header : column.id
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function RelativeTime({ value }: { value: unknown }) {
|
|
171
|
+
const date = toDate(value)
|
|
172
|
+
if (date === undefined) return <Dash />
|
|
173
|
+
const full = dateTime(date)
|
|
174
|
+
return (
|
|
175
|
+
// Below the cell and on keyboard focus: above it the tip covered the header's label on row one.
|
|
176
|
+
<Tooltip label={full} position="bottom" events={{ hover: true, focus: true, touch: false }}>
|
|
177
|
+
{/* oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- the tooltip opens on focus */}
|
|
178
|
+
<time dateTime={date.toISOString()} tabIndex={0}>
|
|
179
|
+
{relativeTime(date)}
|
|
180
|
+
<span className={classes.srOnly}>{`, ${full}`}</span>
|
|
181
|
+
</time>
|
|
182
|
+
</Tooltip>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The cell of a column with a `kind`: the column's own `cell` if it has one, else the kind's content. */
|
|
187
|
+
export function KindCell<T extends RowData>({
|
|
188
|
+
kind,
|
|
189
|
+
cell,
|
|
190
|
+
}: {
|
|
191
|
+
kind: DataTableColumnKind
|
|
192
|
+
cell: Cell<BasaltTableFeatures, T, unknown>
|
|
193
|
+
}): ReactNode {
|
|
194
|
+
const { column } = cell
|
|
195
|
+
const { cell: render, meta } = column.columnDef
|
|
196
|
+
if (render !== DEFAULT_CELL) return <FlexRender cell={cell} />
|
|
197
|
+
const value = cell.getValue()
|
|
198
|
+
switch (kind) {
|
|
199
|
+
case 'number':
|
|
200
|
+
case 'money': {
|
|
201
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return <Dash />
|
|
202
|
+
return kind === 'money' ? formatMoney(value, meta?.currency ?? 'USD') : formatFigure(value)
|
|
203
|
+
}
|
|
204
|
+
case 'relative-time':
|
|
205
|
+
return <RelativeTime value={value} />
|
|
206
|
+
case 'status':
|
|
207
|
+
if (isAbsent(value)) return <Dash />
|
|
208
|
+
return <Badge color={chipColor(meta?.statusColor?.(value))}>{String(value)}</Badge>
|
|
209
|
+
case 'meter':
|
|
210
|
+
return (
|
|
211
|
+
<Meter
|
|
212
|
+
size="row"
|
|
213
|
+
label={columnLabel(column)}
|
|
214
|
+
value={typeof value === 'number' ? value : null}
|
|
215
|
+
max={meta?.meterMax ?? 1}
|
|
216
|
+
/>
|
|
217
|
+
)
|
|
218
|
+
case 'entity':
|
|
219
|
+
case 'text':
|
|
220
|
+
return isAbsent(value) ? <Dash /> : String(value)
|
|
221
|
+
default:
|
|
222
|
+
return kind satisfies never
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** A cell's content through its kind when it has one — the body cell and the fold disclosure share it. */
|
|
227
|
+
export function CellContent<T extends RowData>({
|
|
228
|
+
cell,
|
|
229
|
+
}: {
|
|
230
|
+
cell: Cell<BasaltTableFeatures, T, unknown>
|
|
231
|
+
}): ReactNode {
|
|
232
|
+
const kind = resolveKind(cell.column)
|
|
233
|
+
return kind === undefined ? <FlexRender cell={cell} /> : <KindCell kind={kind} cell={cell} />
|
|
234
|
+
}
|