basalt-ui 2.27.1 → 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 +111 -0
- package/MIGRATING.md +172 -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 +69 -3
- 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 +21 -19
- 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 +26 -7
- 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.js +1 -1
- package/dist/dashboard/stat-strip.module.css +4 -1
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +15 -2
- 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 -8
- 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 +69 -3
- 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 +24 -20
- 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 +25 -6
- package/src/dashboard/stat-strip.module.css +4 -1
- package/src/dashboard/stat-strip.tsx +1 -1
- package/src/dashboard/widget-header.module.css +17 -1
- package/src/dashboard/widget-header.tsx +29 -5
- 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 -8
- 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
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Board — status columns of cards (docs/waves/design-parity/SPEC.md § 6.8): a column header (status
|
|
3
|
+
* dot, title, count, right-aligned `total`), then cards stacked 6 px apart, each column scrolling alone
|
|
4
|
+
* inside a `ScrollArea` bounded by `height`. Choose it for work that moves through states (a queue
|
|
5
|
+
* of agent runs, a review pipeline); a table is for comparing rows. No drag and drop: a card changes
|
|
6
|
+
* column when its data does.
|
|
7
|
+
*
|
|
8
|
+
* Cards are typed data: a caption (`actor · type`), a `title`, an optional linked `record`, a `status`
|
|
9
|
+
* line and one optional `meter` slot. `record.href` renders as a link only when it is http(s) or
|
|
10
|
+
* relative; anything else stays text. The theme owns the card's inset, radius and surface.
|
|
11
|
+
*
|
|
12
|
+
* Keyboard: the board is one tab stop (roving tabindex). ArrowUp/Down and Home/End move within a
|
|
13
|
+
* column; ArrowLeft/Right jump to the nearest non-empty column on the same row index (clamped to its
|
|
14
|
+
* last card). Enter and Space call `onOpen`, and so does a click anywhere on the card. A polite live
|
|
15
|
+
* region announces "<column>, card i of n: <title>" on every move.
|
|
16
|
+
*
|
|
17
|
+
* Semantics: each column is a `role="group"` named by its title and count, its cards a `list` of
|
|
18
|
+
* `listitem`s; the focusable element is one `button` per card, named by the card title (its
|
|
19
|
+
* `::after` stretches over the card, so the whole card is the target). No `grid` role.
|
|
20
|
+
*
|
|
21
|
+
* Compact (`useSizeClass() === 'compact'`): one column at a time under a `SegmentedControl` labelled
|
|
22
|
+
* "<title> <count>" (not `ViewTabs`: past three options it becomes a `Select` on a phone, and the
|
|
23
|
+
* board's switcher is always the track). The selected column is a store field when you pass `field` (an enum field whose
|
|
24
|
+
* values are column ids, like `ViewTabs`'s; the URL or storage then remembers it), else internal
|
|
25
|
+
* state. An empty column and an empty board are both `EmptyState` tiles (`empty` on the column
|
|
26
|
+
* or the board); `loading` is column-shaped skeletons. An error is the caller's: put the board in a `Section` with `query`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* import { Board } from 'basalt-ui'
|
|
30
|
+
*
|
|
31
|
+
* <Board
|
|
32
|
+
* label="Warden board"
|
|
33
|
+
* height={480}
|
|
34
|
+
* onOpen={(id) => openTimeline(id)}
|
|
35
|
+
* columns={[
|
|
36
|
+
* { id: 'needs', title: 'Needs you', tone: VX.status.warn, total: '3 items', cards: [
|
|
37
|
+
* { id: '41', actor: 'warden', type: 'PR review', title: 'Fix the cache key', record: { label: '#482', href: url }, status: 'Waiting 2 h' },
|
|
38
|
+
* ] },
|
|
39
|
+
* { id: 'done', title: 'Done', empty: 'Nothing finished today', cards: [] },
|
|
40
|
+
* ]}
|
|
41
|
+
* />
|
|
42
|
+
*/
|
|
43
|
+
import { ScrollArea, SegmentedControl, Skeleton, Card, VisuallyHidden } from '@mantine/core'
|
|
44
|
+
import { Fragment, useEffect, useId, useRef, useState } from 'react'
|
|
45
|
+
import type { KeyboardEvent, ReactNode } from 'react'
|
|
46
|
+
import { cx } from '../common/props'
|
|
47
|
+
import type { BasaltProps } from '../common/props'
|
|
48
|
+
import { useSizeClass } from '../shell/use-size-class'
|
|
49
|
+
import type { EnumField, FieldHandle } from '../state'
|
|
50
|
+
import { StatusDot } from '../theme/status-dot'
|
|
51
|
+
import { VX } from '../tokens'
|
|
52
|
+
import classes from './board.module.css'
|
|
53
|
+
import { isBoardKey, isSafeHref, moveOnBoard } from './board-nav'
|
|
54
|
+
import type { BoardPos } from './board-nav'
|
|
55
|
+
import { EmptyState } from './empty-state'
|
|
56
|
+
|
|
57
|
+
export type BoardProps<T extends string = string> = BasaltProps & {
|
|
58
|
+
/** Accessible name of the board. Default "Board". */
|
|
59
|
+
label?: string
|
|
60
|
+
/** Columns in display order. Column and card `id`s must be unique within their parent. */
|
|
61
|
+
columns: readonly {
|
|
62
|
+
id: T
|
|
63
|
+
title: string
|
|
64
|
+
/** Colour of the header's status dot (a `VX.status.*` token). Default muted. */
|
|
65
|
+
tone?: string
|
|
66
|
+
/** Right-aligned header text, already formatted ("3 items", "$12.40"). */
|
|
67
|
+
total?: string
|
|
68
|
+
/** The title of the `EmptyState` tile an empty column shows. Default "Nothing here"; say why it is empty. */
|
|
69
|
+
empty?: string
|
|
70
|
+
cards: readonly {
|
|
71
|
+
id: string
|
|
72
|
+
actor?: string
|
|
73
|
+
type?: string
|
|
74
|
+
title: string
|
|
75
|
+
/** A linked record; `href` is a link only when http(s) or relative. */
|
|
76
|
+
record?: { label: string; href?: string }
|
|
77
|
+
/** One muted status line ("Deferred · waiting on CI"). */
|
|
78
|
+
status?: string
|
|
79
|
+
/** An optional meter or preview; the one ReactNode slot. */
|
|
80
|
+
meter?: ReactNode
|
|
81
|
+
}[]
|
|
82
|
+
}[]
|
|
83
|
+
/** Called with the card and column ids on Enter, Space or a click. */
|
|
84
|
+
onOpen?: (cardId: string, columnId: string) => void
|
|
85
|
+
/** Each column scrolls alone inside a box of this height. Omitted: content-sized. */
|
|
86
|
+
height?: number | string
|
|
87
|
+
/** Renders column-shaped skeletons. */
|
|
88
|
+
loading?: boolean
|
|
89
|
+
/** The tile shown when no column has a card. Default "Nothing on the board". */
|
|
90
|
+
empty?: { title: string; description?: string; action?: ReactNode }
|
|
91
|
+
/**
|
|
92
|
+
* Compact: the store field holding the selected column id (an enum field of the column ids, the
|
|
93
|
+
* type `ViewTabs` takes). Omitted: internal state, first column.
|
|
94
|
+
*/
|
|
95
|
+
field?: FieldHandle<EnumField<T>>
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const DEFAULT_EMPTY = { title: 'Nothing on the board' } as const
|
|
99
|
+
const SKELETON_COLUMNS = 3
|
|
100
|
+
const SKELETON_CARDS = 3
|
|
101
|
+
|
|
102
|
+
const cardKey = (col: string, card: string): string => `${col}\u0000${card}`
|
|
103
|
+
|
|
104
|
+
/** The compact board's column switcher: the loading and the loaded branch share one box and one selection. */
|
|
105
|
+
function ColumnSwitcher({
|
|
106
|
+
label,
|
|
107
|
+
items,
|
|
108
|
+
value,
|
|
109
|
+
onChange,
|
|
110
|
+
disabled = false,
|
|
111
|
+
}: {
|
|
112
|
+
label: string
|
|
113
|
+
items: readonly { id: string; text: string }[]
|
|
114
|
+
value: string
|
|
115
|
+
onChange?: (id: string) => void
|
|
116
|
+
disabled?: boolean
|
|
117
|
+
}) {
|
|
118
|
+
return (
|
|
119
|
+
// theme-allow raw-selection-control — the board's own column switcher, its selection is the board's own (a `field` when given, else internal), not a page filter.
|
|
120
|
+
<SegmentedControl
|
|
121
|
+
aria-label={`${label} column`}
|
|
122
|
+
disabled={disabled}
|
|
123
|
+
fullWidth
|
|
124
|
+
size="ctl"
|
|
125
|
+
value={value}
|
|
126
|
+
{...(onChange !== undefined && { onChange })}
|
|
127
|
+
data={items.map((i) => ({ value: i.id, label: i.text }))}
|
|
128
|
+
/>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function SkeletonColumn({ title }: { title?: string }) {
|
|
133
|
+
return (
|
|
134
|
+
<div className={classes.column} aria-hidden>
|
|
135
|
+
<div className={classes.head}>
|
|
136
|
+
{title === undefined ? (
|
|
137
|
+
<Skeleton className={classes.skeletonTitle} />
|
|
138
|
+
) : (
|
|
139
|
+
<span className={classes.title}>{title}</span>
|
|
140
|
+
)}
|
|
141
|
+
</div>
|
|
142
|
+
<div className={classes.list}>
|
|
143
|
+
{Array.from({ length: SKELETON_CARDS }, (_, i) => (
|
|
144
|
+
<Card key={i} className={classes.card}>
|
|
145
|
+
<Skeleton className={classes.skeletonCaption} />
|
|
146
|
+
<Skeleton className={classes.skeletonLine} />
|
|
147
|
+
<Skeleton className={classes.skeletonStatus} />
|
|
148
|
+
</Card>
|
|
149
|
+
))}
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type BoardViewProps<T extends string> = Omit<BoardProps<T>, 'field'> & {
|
|
156
|
+
/** The selected column id and its setter, from the field or from internal state. */
|
|
157
|
+
picked: T | undefined
|
|
158
|
+
onPick: (columnId: T) => void
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The field's `use()` is a hook, so the field and internal-state forms are two components over one view. */
|
|
162
|
+
function FieldBoard<T extends string>({
|
|
163
|
+
field,
|
|
164
|
+
...props
|
|
165
|
+
}: Omit<BoardProps<T>, 'field'> & { field: FieldHandle<EnumField<T>> }) {
|
|
166
|
+
const [picked, setPicked] = field.use()
|
|
167
|
+
return <BoardView {...props} picked={picked} onPick={setPicked} />
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function InternalBoard<T extends string>(props: Omit<BoardProps<T>, 'field'>) {
|
|
171
|
+
const [picked, setPicked] = useState<T | undefined>(undefined)
|
|
172
|
+
return <BoardView {...props} picked={picked} onPick={setPicked} />
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function Board<T extends string = string>({ field, ...props }: BoardProps<T>) {
|
|
176
|
+
return field === undefined ? (
|
|
177
|
+
<InternalBoard {...props} />
|
|
178
|
+
) : (
|
|
179
|
+
<FieldBoard field={field} {...props} />
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function BoardView<T extends string>({
|
|
184
|
+
label = 'Board',
|
|
185
|
+
columns,
|
|
186
|
+
onOpen,
|
|
187
|
+
height,
|
|
188
|
+
loading = false,
|
|
189
|
+
empty = DEFAULT_EMPTY,
|
|
190
|
+
picked,
|
|
191
|
+
onPick,
|
|
192
|
+
className,
|
|
193
|
+
style,
|
|
194
|
+
}: BoardViewProps<T>) {
|
|
195
|
+
const compact = useSizeClass() === 'compact'
|
|
196
|
+
const labelId = useId()
|
|
197
|
+
const [active, setActive] = useState<{ col: string; card: string } | null>(null)
|
|
198
|
+
const [announcement, setAnnouncement] = useState('')
|
|
199
|
+
const buttons = useRef(new Map<string, HTMLButtonElement>())
|
|
200
|
+
const pending = useRef<string | null>(null)
|
|
201
|
+
|
|
202
|
+
const sizes = columns.map((c) => c.cards.length)
|
|
203
|
+
const total = sizes.reduce((a, b) => a + b, 0)
|
|
204
|
+
const selected = columns.find((c) => c.id === picked) ?? columns[0]
|
|
205
|
+
const selectColumn = onPick
|
|
206
|
+
|
|
207
|
+
// The roving stop sits in what is rendered: the focused card if it still exists there (compact
|
|
208
|
+
// renders only the selected column), else the first card of the first rendered non-empty column.
|
|
209
|
+
const selectedIndex = selected === undefined ? -1 : columns.indexOf(selected)
|
|
210
|
+
const rendered = (colIndex: number): boolean => !compact || colIndex === selectedIndex
|
|
211
|
+
const firstCol = columns.findIndex((c, i) => rendered(i) && c.cards.length > 0)
|
|
212
|
+
const activeCol = columns.findIndex((c) => c.id === active?.col)
|
|
213
|
+
const activeRow = columns[activeCol]?.cards.findIndex((c) => c.id === active?.card) ?? -1
|
|
214
|
+
const stop: BoardPos | null =
|
|
215
|
+
activeCol >= 0 && activeRow >= 0 && rendered(activeCol)
|
|
216
|
+
? { col: activeCol, row: activeRow }
|
|
217
|
+
: firstCol >= 0
|
|
218
|
+
? { col: firstCol, row: 0 }
|
|
219
|
+
: null
|
|
220
|
+
|
|
221
|
+
// A move in compact may first have to mount the target column; focus lands after that render.
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
const key = pending.current
|
|
224
|
+
if (key === null) return
|
|
225
|
+
// One shot: a target that did not mount is dropped, never retried on a later render.
|
|
226
|
+
pending.current = null
|
|
227
|
+
buttons.current.get(key)?.focus()
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>, from: BoardPos): void => {
|
|
231
|
+
if (!isBoardKey(event.key)) return
|
|
232
|
+
event.preventDefault()
|
|
233
|
+
const to = moveOnBoard(sizes, from, event.key)
|
|
234
|
+
const col = to && columns[to.col]
|
|
235
|
+
const card = col && col.cards[to.row]
|
|
236
|
+
if (!to || !col || !card) return
|
|
237
|
+
pending.current = cardKey(col.id, card.id)
|
|
238
|
+
setActive({ col: col.id, card: card.id })
|
|
239
|
+
setAnnouncement(`${col.title}, card ${to.row + 1} of ${col.cards.length}: ${card.title}`)
|
|
240
|
+
if (compact && col.id !== selected?.id) selectColumn(col.id)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const renderColumn = (col: (typeof columns)[number], colIndex: number): ReactNode => {
|
|
244
|
+
const headId = `${labelId}-${col.id}`
|
|
245
|
+
const list =
|
|
246
|
+
col.cards.length === 0 ? (
|
|
247
|
+
<EmptyState tier="section" title={col.empty ?? 'Nothing here'} />
|
|
248
|
+
) : (
|
|
249
|
+
// The explicit role is deliberate: `list-style: none` makes Safari/VoiceOver drop the implicit one.
|
|
250
|
+
// oxlint-disable-next-line jsx-a11y/no-redundant-roles
|
|
251
|
+
<ul className={classes.list} role="list" aria-labelledby={headId}>
|
|
252
|
+
{col.cards.map((card, row) => {
|
|
253
|
+
const here = stop?.col === colIndex && stop.row === row
|
|
254
|
+
const caption = [card.actor, card.type].filter(Boolean).join(' · ')
|
|
255
|
+
return (
|
|
256
|
+
<li key={card.id}>
|
|
257
|
+
<Card className={classes.card}>
|
|
258
|
+
{caption !== '' && <p className={classes.caption}>{caption}</p>}
|
|
259
|
+
<button
|
|
260
|
+
type="button"
|
|
261
|
+
className={classes.open}
|
|
262
|
+
tabIndex={here ? 0 : -1}
|
|
263
|
+
ref={(el) => {
|
|
264
|
+
const key = cardKey(col.id, card.id)
|
|
265
|
+
if (el) buttons.current.set(key, el)
|
|
266
|
+
else buttons.current.delete(key)
|
|
267
|
+
}}
|
|
268
|
+
onFocus={() => setActive({ col: col.id, card: card.id })}
|
|
269
|
+
onKeyDown={(e) => onKeyDown(e, { col: colIndex, row })}
|
|
270
|
+
onClick={() => onOpen?.(card.id, col.id)}
|
|
271
|
+
>
|
|
272
|
+
{card.title}
|
|
273
|
+
</button>
|
|
274
|
+
{card.record !== undefined &&
|
|
275
|
+
(card.record.href !== undefined && isSafeHref(card.record.href) ? (
|
|
276
|
+
<a
|
|
277
|
+
className={classes.record}
|
|
278
|
+
href={card.record.href}
|
|
279
|
+
{...(/^https?:/i.test(card.record.href) && {
|
|
280
|
+
target: '_blank',
|
|
281
|
+
rel: 'noreferrer',
|
|
282
|
+
})}
|
|
283
|
+
>
|
|
284
|
+
{card.record.label}
|
|
285
|
+
</a>
|
|
286
|
+
) : (
|
|
287
|
+
<span className={classes.record}>{card.record.label}</span>
|
|
288
|
+
))}
|
|
289
|
+
{card.status !== undefined && <p className={classes.status}>{card.status}</p>}
|
|
290
|
+
{card.meter !== undefined && <div className={classes.meter}>{card.meter}</div>}
|
|
291
|
+
</Card>
|
|
292
|
+
</li>
|
|
293
|
+
)
|
|
294
|
+
})}
|
|
295
|
+
</ul>
|
|
296
|
+
)
|
|
297
|
+
return (
|
|
298
|
+
// oxlint-disable-next-line jsx-a11y/prefer-tag-over-role -- a named group of cards, not a fieldset
|
|
299
|
+
<div key={col.id} className={classes.column} role="group" aria-labelledby={headId}>
|
|
300
|
+
{/* Compact: the switcher already names the column and its count, so only the total stays visible. */}
|
|
301
|
+
<div className={classes.head}>
|
|
302
|
+
{!compact && <StatusDot color={col.tone ?? VX.muted} />}
|
|
303
|
+
<h3 id={headId} className={classes.title}>
|
|
304
|
+
{compact ? <VisuallyHidden>{col.title}</VisuallyHidden> : col.title}
|
|
305
|
+
<VisuallyHidden>{`, ${col.cards.length} ${col.cards.length === 1 ? 'card' : 'cards'}`}</VisuallyHidden>
|
|
306
|
+
</h3>
|
|
307
|
+
{!compact && (
|
|
308
|
+
<span className={classes.count} aria-hidden>
|
|
309
|
+
{col.cards.length}
|
|
310
|
+
</span>
|
|
311
|
+
)}
|
|
312
|
+
{col.total !== undefined && <span className={classes.total}>{col.total}</span>}
|
|
313
|
+
</div>
|
|
314
|
+
<ScrollArea.Autosize
|
|
315
|
+
{...(height !== undefined && { mah: height })}
|
|
316
|
+
type="auto"
|
|
317
|
+
offsetScrollbars="y"
|
|
318
|
+
>
|
|
319
|
+
{list}
|
|
320
|
+
</ScrollArea.Autosize>
|
|
321
|
+
</div>
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let content: ReactNode
|
|
326
|
+
if (loading) {
|
|
327
|
+
content = (
|
|
328
|
+
<div aria-busy="true">
|
|
329
|
+
<VisuallyHidden>{`Loading ${label}`}</VisuallyHidden>
|
|
330
|
+
{compact && columns.length > 0 && (
|
|
331
|
+
// The loaded switcher's footprint with the titles it will carry, inert until the cards land.
|
|
332
|
+
<ColumnSwitcher
|
|
333
|
+
label={label}
|
|
334
|
+
disabled
|
|
335
|
+
value={selected?.id ?? ''}
|
|
336
|
+
items={columns.map((c) => ({ id: c.id, text: c.title }))}
|
|
337
|
+
/>
|
|
338
|
+
)}
|
|
339
|
+
<div className={classes.columns}>
|
|
340
|
+
{compact ? (
|
|
341
|
+
<SkeletonColumn />
|
|
342
|
+
) : columns.length > 0 ? (
|
|
343
|
+
columns.map((c) => <SkeletonColumn key={c.id} title={c.title} />)
|
|
344
|
+
) : (
|
|
345
|
+
Array.from({ length: SKELETON_COLUMNS }, (_, i) => <SkeletonColumn key={i} />)
|
|
346
|
+
)}
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
)
|
|
350
|
+
} else if (total === 0) {
|
|
351
|
+
content = (
|
|
352
|
+
// oxlint-disable-next-line jsx-a11y/prefer-tag-over-role -- a polite live region whose name is the visually hidden label inside
|
|
353
|
+
<div className={classes.empty} role="status">
|
|
354
|
+
<VisuallyHidden>{label}</VisuallyHidden>
|
|
355
|
+
<EmptyState
|
|
356
|
+
tier="section"
|
|
357
|
+
title={empty.title}
|
|
358
|
+
{...(empty.description !== undefined && { description: empty.description })}
|
|
359
|
+
{...(empty.action !== undefined && { action: empty.action })}
|
|
360
|
+
/>
|
|
361
|
+
</div>
|
|
362
|
+
)
|
|
363
|
+
} else {
|
|
364
|
+
content = (
|
|
365
|
+
<Fragment>
|
|
366
|
+
{compact && (
|
|
367
|
+
<ColumnSwitcher
|
|
368
|
+
label={label}
|
|
369
|
+
value={selected?.id ?? ''}
|
|
370
|
+
onChange={(id) => {
|
|
371
|
+
const col = columns.find((c) => c.id === id)
|
|
372
|
+
if (col) selectColumn(col.id)
|
|
373
|
+
}}
|
|
374
|
+
items={columns.map((c) => ({ id: c.id, text: `${c.title} ${c.cards.length}` }))}
|
|
375
|
+
/>
|
|
376
|
+
)}
|
|
377
|
+
<div className={classes.columns}>
|
|
378
|
+
{compact
|
|
379
|
+
? selected && renderColumn(selected, columns.indexOf(selected))
|
|
380
|
+
: columns.map(renderColumn)}
|
|
381
|
+
</div>
|
|
382
|
+
<VisuallyHidden component="output" aria-live="polite">
|
|
383
|
+
{announcement}
|
|
384
|
+
</VisuallyHidden>
|
|
385
|
+
</Fragment>
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return (
|
|
390
|
+
<div className={cx(classes.root, className)} style={style} data-board="">
|
|
391
|
+
{content}
|
|
392
|
+
</div>
|
|
393
|
+
)
|
|
394
|
+
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { Center, Stack } from '@mantine/core'
|
|
21
21
|
import type { ReactNode } from 'react'
|
|
22
|
-
import { VX } from '../tokens'
|
|
22
|
+
import { VX, alpha } from '../tokens'
|
|
23
23
|
import { cx } from '../common/props'
|
|
24
24
|
import type { BasaltProps, SlotStylesProps } from '../common/props'
|
|
25
25
|
|
|
@@ -30,10 +30,10 @@ export type EmptyStateProps = BasaltProps &
|
|
|
30
30
|
SlotStylesProps<EmptyStateSlot> & {
|
|
31
31
|
/** Optional glyph slot, rendered faint at ~28-32px. No shipped illustration assets. */
|
|
32
32
|
icon?: ReactNode
|
|
33
|
-
/**
|
|
33
|
+
/** Weight 500, ink: `sm` in a section tile (never louder than its host's title), `md` on a page (SPEC § 6.11). */
|
|
34
34
|
title: string
|
|
35
35
|
/**
|
|
36
|
-
* Muted
|
|
36
|
+
* Muted `sm` description, capped at ~360px so it reads as a short explanation. Optional: a
|
|
37
37
|
* compact panel ("No data yet") should not have to invent a second sentence, and five argo
|
|
38
38
|
* features wrapped this component solely to avoid doing so.
|
|
39
39
|
*/
|
|
@@ -41,7 +41,7 @@ export type EmptyStateProps = BasaltProps &
|
|
|
41
41
|
/** Optional call-to-action rendered below the description. */
|
|
42
42
|
action?: ReactNode
|
|
43
43
|
/** How loud this state is: `'page'` (default) = generous padding for a full-page state;
|
|
44
|
-
* `'section'` = compact. */
|
|
44
|
+
* `'section'` = a compact, ring-edged tile (one ring, card radius) inside the surface it replaces. */
|
|
45
45
|
tier?: 'page' | 'section'
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -78,6 +78,14 @@ export function EmptyState({
|
|
|
78
78
|
? `${PAGE_PADDING_Y} ${PAGE_PADDING_X}`
|
|
79
79
|
: `${SECTION_PADDING_Y} ${SECTION_PADDING_X}`,
|
|
80
80
|
textAlign: 'center',
|
|
81
|
+
// The section tile: one ring (a shadow, never a border), card radius. The ring is a neutral
|
|
82
|
+
// tint, not the card hairline: the tile sits on the page or a panel, and the hairline (a card
|
|
83
|
+
// edge on a white card) vanishes on the grey page in light.
|
|
84
|
+
...(resolved === 'section' && {
|
|
85
|
+
// theme-allow surface-shadow-override — an inset ring on a tile inside a surface, not a card's depth
|
|
86
|
+
boxShadow: `inset 0 0 0 1px ${alpha(VX.neutral, 0.25)}`,
|
|
87
|
+
borderRadius: 'var(--vx-radius-card)',
|
|
88
|
+
}),
|
|
81
89
|
...style,
|
|
82
90
|
}}
|
|
83
91
|
>
|
|
@@ -94,10 +102,9 @@ export function EmptyState({
|
|
|
94
102
|
<span
|
|
95
103
|
className={classNames?.title}
|
|
96
104
|
style={{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
fontWeight: 550,
|
|
105
|
+
// A section tile never out-sizes its host's own title (`sm`); the page tier has none and keeps `md`.
|
|
106
|
+
fontSize: resolved === 'section' ? VX.text.sm : VX.text.md,
|
|
107
|
+
fontWeight: 500,
|
|
101
108
|
color: VX.ink,
|
|
102
109
|
}}
|
|
103
110
|
>
|
|
@@ -107,7 +114,7 @@ export function EmptyState({
|
|
|
107
114
|
// 360px (22.5rem) is a reading-width cap, not a density inset — kept structural.
|
|
108
115
|
<span
|
|
109
116
|
className={classNames?.description}
|
|
110
|
-
style={{ fontSize: VX.text.
|
|
117
|
+
style={{ fontSize: VX.text.sm, color: VX.muted, maxWidth: '22.5rem' }}
|
|
111
118
|
>
|
|
112
119
|
{description}
|
|
113
120
|
</span>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `EventList`'s pure half: day grouping and the labels. Local-time day boundaries, the caller's
|
|
3
|
+
* order kept (a group is a run of adjacent items on one local day, never a re-sort).
|
|
4
|
+
*/
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
import { date, dateTime, relativeTime, time, weekday } from '../format'
|
|
7
|
+
|
|
8
|
+
export type EventTimeMode = 'clock' | 'relative' | 'date-time' | ((at: Date) => string)
|
|
9
|
+
|
|
10
|
+
export const toEventDate = (at: Date | number): Date => (at instanceof Date ? at : new Date(at))
|
|
11
|
+
|
|
12
|
+
export const isValidEventDate = (at: Date): boolean => Number.isFinite(at.getTime())
|
|
13
|
+
|
|
14
|
+
/** Shown in the time column of a row whose `at` is not a real instant. */
|
|
15
|
+
const NO_TIME = '—'
|
|
16
|
+
|
|
17
|
+
/** Local calendar day, `YYYY-MM-DD`. */
|
|
18
|
+
export function dayKey(at: Date): string {
|
|
19
|
+
const month = String(at.getMonth() + 1).padStart(2, '0')
|
|
20
|
+
const day = String(at.getDate()).padStart(2, '0')
|
|
21
|
+
return `${at.getFullYear()}-${month}-${day}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type EventGroup<T extends { readonly at: Date | number }> = {
|
|
25
|
+
readonly day: Date
|
|
26
|
+
/** The local day, `YYYY-MM-DD`, or `invalid` for a list with no real instant. */
|
|
27
|
+
readonly key: string
|
|
28
|
+
/** `key` plus the run's occurrence, so a same-day prepend keeps every group's identity. */
|
|
29
|
+
readonly id: string
|
|
30
|
+
readonly items: readonly T[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Runs of adjacent items on one local day, in the order given. An item whose `at` is invalid has no
|
|
35
|
+
* day of its own: it joins the run before it, or (leading) the first real run that follows. A list
|
|
36
|
+
* with no real instant at all is one group on an invalid day, which renders without a header.
|
|
37
|
+
*/
|
|
38
|
+
export function groupByDay<T extends { readonly at: Date | number }>(
|
|
39
|
+
items: readonly T[],
|
|
40
|
+
): EventGroup<T>[] {
|
|
41
|
+
const runs: { day: Date; key: string; items: T[] }[] = []
|
|
42
|
+
const leading: T[] = []
|
|
43
|
+
for (const item of items) {
|
|
44
|
+
const at = toEventDate(item.at)
|
|
45
|
+
const last = runs[runs.length - 1]
|
|
46
|
+
if (!isValidEventDate(at)) {
|
|
47
|
+
if (last === undefined) leading.push(item)
|
|
48
|
+
else last.items.push(item)
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
const key = dayKey(at)
|
|
52
|
+
if (last !== undefined && last.key === key) last.items.push(item)
|
|
53
|
+
else runs.push({ day: at, key, items: runs.length === 0 ? [...leading, item] : [item] })
|
|
54
|
+
}
|
|
55
|
+
if (runs.length === 0) {
|
|
56
|
+
return leading.length === 0
|
|
57
|
+
? []
|
|
58
|
+
: [{ day: new Date(Number.NaN), key: 'invalid', id: 'invalid#0', items: leading }]
|
|
59
|
+
}
|
|
60
|
+
const seen = new Map<string, number>()
|
|
61
|
+
return runs.map((run) => {
|
|
62
|
+
const n = seen.get(run.key) ?? 0
|
|
63
|
+
seen.set(run.key, n + 1)
|
|
64
|
+
return { ...run, id: `${run.key}#${n}` }
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** `Today`, `Yesterday`, else `Wed, Sep 2, 2026`. With no clock yet (the server render) always the date. */
|
|
69
|
+
export function defaultDayLabel(day: Date, now: Date | null): string {
|
|
70
|
+
if (!isValidEventDate(day)) return NO_TIME
|
|
71
|
+
if (now === null) return `${weekday(day)}, ${date(day)}`
|
|
72
|
+
const key = dayKey(day)
|
|
73
|
+
if (key === dayKey(now)) return 'Today'
|
|
74
|
+
const before = new Date(now)
|
|
75
|
+
before.setDate(before.getDate() - 1)
|
|
76
|
+
if (key === dayKey(before)) return 'Yesterday'
|
|
77
|
+
return `${weekday(day)}, ${date(day)}`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function formatEventTime(at: Date, mode: EventTimeMode, now: Date | null): string {
|
|
81
|
+
if (!isValidEventDate(at)) return NO_TIME
|
|
82
|
+
if (typeof mode === 'function') return mode(at)
|
|
83
|
+
// Relative needs a clock; before there is one (the server render) the absolute stamp stands in.
|
|
84
|
+
if (mode === 'relative' && now !== null) return relativeTime(at, { now: now.getTime() })
|
|
85
|
+
if (mode === 'relative') return dateTime(at, { format: 'short' })
|
|
86
|
+
if (mode === 'date-time') return dateTime(at, { format: 'short' })
|
|
87
|
+
return time(at, { format: 'short' })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** What every row (real or skeleton) shares: the list's density, rail, lead column, time mode and "now". */
|
|
91
|
+
export type RowContext = {
|
|
92
|
+
readonly density: 'feed' | 'timeline'
|
|
93
|
+
readonly rail: boolean
|
|
94
|
+
readonly lead: boolean
|
|
95
|
+
readonly timeMode: EventTimeMode
|
|
96
|
+
/** `null` until the client clock is read (the server render and the hydrating paint). */
|
|
97
|
+
readonly now: Date | null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** `null`, `undefined`, booleans and the empty string render nothing, so they are not content. */
|
|
101
|
+
export const present = (node: ReactNode): boolean =>
|
|
102
|
+
node !== undefined && node !== null && typeof node !== 'boolean' && node !== ''
|
|
103
|
+
|
|
104
|
+
/** The data attributes a row (real or skeleton) carries; the CSS keys on them. */
|
|
105
|
+
export function rowAttributes(ctx: RowContext, first: boolean, last: boolean) {
|
|
106
|
+
return {
|
|
107
|
+
'data-density': ctx.density,
|
|
108
|
+
'data-lead': ctx.lead ? '' : undefined,
|
|
109
|
+
'data-rail': ctx.rail ? '' : undefined,
|
|
110
|
+
'data-first': first ? '' : undefined,
|
|
111
|
+
'data-last': last ? '' : undefined,
|
|
112
|
+
}
|
|
113
|
+
}
|