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
package/src/table/data-table.tsx
CHANGED
|
@@ -54,7 +54,6 @@ import type {
|
|
|
54
54
|
ColumnVisibilityState,
|
|
55
55
|
FilterFn,
|
|
56
56
|
PaginationState,
|
|
57
|
-
Row,
|
|
58
57
|
RowData,
|
|
59
58
|
RowSelectionState,
|
|
60
59
|
SortingState,
|
|
@@ -62,7 +61,7 @@ import type {
|
|
|
62
61
|
} from '@tanstack/react-table'
|
|
63
62
|
import { constructFilterFn, FlexRender, useTable } from '@tanstack/react-table'
|
|
64
63
|
import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactNode, RefObject } from 'react'
|
|
65
|
-
import { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
64
|
+
import { Fragment, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
66
65
|
import { useDebouncedCallback } from '@mantine/hooks'
|
|
67
66
|
import { cx } from '../common/props'
|
|
68
67
|
import type { BasaltProps, SlotStylesProps } from '../common/props'
|
|
@@ -81,21 +80,47 @@ import { EnumFilter } from '../controls/enum-filter'
|
|
|
81
80
|
import { MultiSelectFilter } from '../controls/multi-select-filter'
|
|
82
81
|
import { CtlSlot } from '../theme'
|
|
83
82
|
import { IconSlot } from '../theme/icon-slot'
|
|
84
|
-
import {
|
|
83
|
+
import { CONTAINER_CLASSES, VX } from '../tokens'
|
|
85
84
|
import type { EnumField, FieldHandle, MultiField } from '../state/fields'
|
|
86
85
|
import { WidgetHeader } from '../dashboard'
|
|
86
|
+
import { EmptyState } from '../dashboard/empty-state'
|
|
87
87
|
import { ErrorState } from '../dashboard/query-state'
|
|
88
88
|
import type { QueryStateLike } from '../dashboard/query-state'
|
|
89
89
|
import {
|
|
90
90
|
activationProps,
|
|
91
|
-
EMPTY_FOLD_SET,
|
|
92
91
|
useCardProjection,
|
|
93
92
|
useDataTableState,
|
|
93
|
+
useNarrowerThan,
|
|
94
94
|
useRowDisclosure,
|
|
95
95
|
} from './data-table-state'
|
|
96
|
+
export { planColumnFold } from './data-table-fold'
|
|
96
97
|
import { dataQueryBranch } from './query-branch'
|
|
97
98
|
import { basaltTableFeatures } from './table-features'
|
|
98
99
|
import type { BasaltColumnDef, BasaltTableFeatures, DataTableAlign } from './table-features'
|
|
100
|
+
import {
|
|
101
|
+
columnDefId,
|
|
102
|
+
columnLabel,
|
|
103
|
+
FIXED_ID_ATTR,
|
|
104
|
+
FOLD_ID_ATTR,
|
|
105
|
+
foldOrder,
|
|
106
|
+
foldToggleCellProps,
|
|
107
|
+
FoldHeaderLabel,
|
|
108
|
+
FoldToggle,
|
|
109
|
+
PIN_MIN_WIDTH,
|
|
110
|
+
pinnedCellProps,
|
|
111
|
+
RowDisclosure,
|
|
112
|
+
useColumnFold,
|
|
113
|
+
} from './data-table-fold'
|
|
114
|
+
import type { PinContext } from './data-table-fold'
|
|
115
|
+
import {
|
|
116
|
+
CellContent,
|
|
117
|
+
DEFAULT_CELL,
|
|
118
|
+
kindAlign,
|
|
119
|
+
kindClass,
|
|
120
|
+
KindSkeleton,
|
|
121
|
+
planColumnSizing,
|
|
122
|
+
resolveKind,
|
|
123
|
+
} from './cell-kinds'
|
|
99
124
|
import classes from './data-table.module.css'
|
|
100
125
|
|
|
101
126
|
// ── Column alignment ──────────────────────────────────────────────────────────
|
|
@@ -321,6 +346,9 @@ const facetAnyOf = constructFilterFn({
|
|
|
321
346
|
* selection state, which is a reordering nobody asked for.
|
|
322
347
|
*/
|
|
323
348
|
const SELECT_COLUMN_ID = '__basalt_select__'
|
|
349
|
+
/** The checkbox column's width when it pins beside an auto-pinned identifier — the pinned offsets
|
|
350
|
+
* sum `getSize()`, so the real cell is held to it (the coarse hit floor, one tap target wide). */
|
|
351
|
+
const SELECT_COLUMN_SIZE = HIT_COARSE
|
|
324
352
|
|
|
325
353
|
/**
|
|
326
354
|
* Built per render inside a `useMemo`, not hoisted as a constant: `ColumnDef` is generic in `T`, and
|
|
@@ -333,6 +361,7 @@ const SELECT_COLUMN_ID = '__basalt_select__'
|
|
|
333
361
|
function selectionColumn<T extends RowData>(): ColumnDef<BasaltTableFeatures, T, unknown> {
|
|
334
362
|
return {
|
|
335
363
|
id: SELECT_COLUMN_ID,
|
|
364
|
+
size: SELECT_COLUMN_SIZE,
|
|
336
365
|
enableSorting: false,
|
|
337
366
|
header: ({ table }) => (
|
|
338
367
|
// oxlint-disable-next-line jsx-a11y/label-has-associated-control -- wraps <Checkbox>, which oxlint cannot see is an input
|
|
@@ -416,7 +445,7 @@ function RowActionCell<T>({
|
|
|
416
445
|
aria-label={named === undefined ? only.label : `${only.label}: ${named}`}
|
|
417
446
|
disabled={only.disabled?.(row) === true}
|
|
418
447
|
loading={only.loading?.(row) === true}
|
|
419
|
-
{...(only.danger === true && {
|
|
448
|
+
{...(only.danger === true && { className: classes.dangerAction })}
|
|
420
449
|
onClick={() => {
|
|
421
450
|
if (!inert) only.onClick(row)
|
|
422
451
|
}}
|
|
@@ -568,7 +597,8 @@ export type BasaltDataTableProps<T extends RowData> = BasaltProps &
|
|
|
568
597
|
manualSorting?: boolean
|
|
569
598
|
/** Stripe alternate rows. Forwarded to Mantine `Table` — `'odd'`/`'even'` pick the phase. */
|
|
570
599
|
striped?: boolean | 'odd' | 'even'
|
|
571
|
-
/** Highlight hovered rows. Forwarded to Mantine `Table`.
|
|
600
|
+
/** Highlight hovered rows with `VX.surface.rowHover` on a fine pointer. Forwarded to Mantine `Table`.
|
|
601
|
+
* @default true */
|
|
572
602
|
highlightOnHover?: boolean
|
|
573
603
|
/**
|
|
574
604
|
* Rendered when no rows are VISIBLE — `data` is empty, or a filter/page matches none of it.
|
|
@@ -604,7 +634,9 @@ export type BasaltDataTableProps<T extends RowData> = BasaltProps &
|
|
|
604
634
|
*/
|
|
605
635
|
query?: QueryStateLike<unknown>
|
|
606
636
|
/**
|
|
607
|
-
* Number of skeleton rows to render when `isLoading` is true
|
|
637
|
+
* Number of skeleton rows to render when `isLoading` is true and neither a page size nor an
|
|
638
|
+
* earlier load says better: a paginated table loads at its page size, any other at the row
|
|
639
|
+
* count it last showed.
|
|
608
640
|
* @default 5
|
|
609
641
|
*/
|
|
610
642
|
skeletonRows?: number
|
|
@@ -648,6 +680,11 @@ export type BasaltDataTableProps<T extends RowData> = BasaltProps &
|
|
|
648
680
|
* restoring the search term from a URL search param.
|
|
649
681
|
*/
|
|
650
682
|
initialGlobalFilter?: string
|
|
683
|
+
/**
|
|
684
|
+
* Initial facet filters — `[{ id: 'department', value: 'Engineering' }]` opens the table with
|
|
685
|
+
* that facet preset. Uncontrolled, like `initialSorting`; `onColumnFiltersChange` reports edits.
|
|
686
|
+
*/
|
|
687
|
+
initialColumnFilters?: ColumnFiltersState
|
|
651
688
|
/** Called whenever the internal global filter value changes. */
|
|
652
689
|
onGlobalFilterChange?: (value: string) => void
|
|
653
690
|
/**
|
|
@@ -952,6 +989,28 @@ export type BasaltDataTableProps<T extends RowData> = BasaltProps &
|
|
|
952
989
|
withTableBorder?: boolean
|
|
953
990
|
}
|
|
954
991
|
|
|
992
|
+
/**
|
|
993
|
+
* A skeleton cell's floor by `meta.kind`, rem: roughly what a typical value of the kind measures, so
|
|
994
|
+
* a loading table plans the same fold as the loaded one instead of squeezing every column to its
|
|
995
|
+
* (narrow) header. A column without a kind keeps its natural width.
|
|
996
|
+
*/
|
|
997
|
+
const SKELETON_MIN_REM: Record<string, number> = {
|
|
998
|
+
entity: 7,
|
|
999
|
+
text: 6,
|
|
1000
|
+
'relative-time': 5,
|
|
1001
|
+
status: 4,
|
|
1002
|
+
money: 4.5,
|
|
1003
|
+
number: 3.5,
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
function skeletonMinWidth<T extends RowData>(
|
|
1007
|
+
column: Column<BasaltTableFeatures, T, unknown>,
|
|
1008
|
+
): string | undefined {
|
|
1009
|
+
const kind = resolveKind(column)
|
|
1010
|
+
const rem = kind === undefined ? undefined : SKELETON_MIN_REM[kind]
|
|
1011
|
+
return rem === undefined ? undefined : `${rem}rem`
|
|
1012
|
+
}
|
|
1013
|
+
|
|
955
1014
|
// ── Sort indicator ────────────────────────────────────────────────────────────
|
|
956
1015
|
|
|
957
1016
|
function SortIndicator({ direction }: { direction: 'asc' | 'desc' | false }) {
|
|
@@ -965,21 +1024,21 @@ function SortIndicator({ direction }: { direction: 'asc' | 'desc' | false }) {
|
|
|
965
1024
|
|
|
966
1025
|
const ARIA_SORT = { asc: 'ascending', desc: 'descending' } as const
|
|
967
1026
|
|
|
968
|
-
// ── Numeral cell idiom (
|
|
969
|
-
//
|
|
970
|
-
// every numeric column gets tabular
|
|
1027
|
+
// ── Numeral cell idiom (SPEC D33: figures are the proportional sans with `tabular-nums`, mono is
|
|
1028
|
+
// for captions, times and code) — auto-detected from the cell's raw value (no column-level opt-in
|
|
1029
|
+
// prop needed) so every numeric column gets tabular figures with zero call-site configuration.
|
|
971
1030
|
const NUMERIC_CELL_STYLE: CSSProperties = {
|
|
972
|
-
fontFamily: 'var(--mantine-font-family-monospace)',
|
|
973
1031
|
fontSize: VX.text.sm,
|
|
974
1032
|
fontWeight: 500,
|
|
975
1033
|
fontVariantNumeric: 'tabular-nums',
|
|
976
1034
|
color: 'var(--vx-ink)',
|
|
977
1035
|
}
|
|
978
1036
|
|
|
979
|
-
// docs/DESIGN-SPEC.md §3: mono/micro-label idiom for the pagination bar's row-count label
|
|
1037
|
+
// docs/DESIGN-SPEC.md §3: mono/micro-label idiom for the pagination bar's row-count label — the
|
|
1038
|
+
// header's own micro size, so a paginated table reads in three sizes (micro, sm, the field's 16).
|
|
980
1039
|
const RANGE_LABEL_STYLE: CSSProperties = {
|
|
981
1040
|
fontFamily: 'var(--mantine-font-family-monospace)',
|
|
982
|
-
fontSize: VX.text.
|
|
1041
|
+
fontSize: VX.text.micro,
|
|
983
1042
|
fontVariantNumeric: 'tabular-nums',
|
|
984
1043
|
color: 'var(--vx-faint)',
|
|
985
1044
|
}
|
|
@@ -987,21 +1046,25 @@ const RANGE_LABEL_STYLE: CSSProperties = {
|
|
|
987
1046
|
const DEFAULT_PAGE_SIZE_OPTIONS = [10, 25, 50, 100]
|
|
988
1047
|
|
|
989
1048
|
/**
|
|
990
|
-
* The header row's two halves. The
|
|
991
|
-
*
|
|
1049
|
+
* The header row's two halves (`docs/waves/design-parity/SPEC.md` § 6.6). The TOOLBAR grows and the
|
|
1050
|
+
* title does not: the title ellipsizes into whatever it needs, and the toolbar takes the rest of the
|
|
1051
|
+
* row, so its facet row (`FilterSet`, `flex: 1 1 auto`) fills it and pushes the `actions` slot to
|
|
1052
|
+
* the right edge — beside the title when the two fit, full-width under it when they do not.
|
|
992
1053
|
*
|
|
993
1054
|
* Both SHRINK, and that half is not a preference. `CtlSlot` between the header row and the toolbar
|
|
994
|
-
* is `display: contents`, so the toolbar `Group` IS the row's flex item — and with
|
|
995
|
-
* `
|
|
996
|
-
*
|
|
997
|
-
*
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1055
|
+
* is `display: contents`, so the toolbar `Group` IS the row's flex item — and a flex item with
|
|
1056
|
+
* `min-width: auto` cannot give up a pixel. MEASURED at 390x844 on `/data`: a 220px search beside a
|
|
1057
|
+
* 230px facet pill row, gap 11, is a 461px item in a 302px column, and `AppShell.Main` read
|
|
1058
|
+
* `scrollWidth` 505 against `clientWidth` 390 — the whole app draggable sideways over a table
|
|
1059
|
+
* header. `min-width: 0` lets the item shrink to the column; inside it the search gives up width
|
|
1060
|
+
* down to its floor and `FilterSet` folds what still does not fit behind its own `+N`.
|
|
1061
|
+
*
|
|
1062
|
+
* The toolbar is ONE row at every container width from the `compact` class (240px) up
|
|
1063
|
+
* (`.toolbar` in `data-table.module.css`, keyed on the header row's own width — never the
|
|
1064
|
+
* viewport). Only below it may the row wrap.
|
|
1002
1065
|
*/
|
|
1003
|
-
const TABLE_HEADER_LEAD_STYLE: CSSProperties = { flex: '
|
|
1004
|
-
const TABLE_TOOLBAR_STYLE: CSSProperties = { flex: '
|
|
1066
|
+
const TABLE_HEADER_LEAD_STYLE: CSSProperties = { flex: '0 1 auto', minWidth: 0 }
|
|
1067
|
+
const TABLE_TOOLBAR_STYLE: CSSProperties = { flex: '1 1 auto', minWidth: 0 }
|
|
1005
1068
|
/**
|
|
1006
1069
|
* The toolbar search's width. Mantine's Input grows to its container, which in a `justify:
|
|
1007
1070
|
* space-between` row means "whatever is left" — so the field was 600px on a wide table and 180px on a
|
|
@@ -1017,12 +1080,20 @@ const TABLE_TOOLBAR_STYLE: CSSProperties = { flex: '0 1 auto', minWidth: 0 }
|
|
|
1017
1080
|
* column was half of the overflow above.
|
|
1018
1081
|
*/
|
|
1019
1082
|
const SEARCH_WIDTH = 220
|
|
1083
|
+
/**
|
|
1084
|
+
* The search gives up width FIRST. Flex shrinks items in proportion to `shrink × basis`; at `1` the
|
|
1085
|
+
* search and `FilterSet`'s row (`flex: 1 1 auto`, whose slots cannot shrink) split the deficit, so the
|
|
1086
|
+
* pills overflowed their own box and the phone's `Filters` pill was clipped. A large factor takes the
|
|
1087
|
+
* whole deficit from the search until its `12ch` floor, and only then from the pill row — where
|
|
1088
|
+
* `FilterSet`'s fold takes over.
|
|
1089
|
+
*/
|
|
1090
|
+
const SEARCH_SHRINK = 100
|
|
1020
1091
|
/** How long the global search waits after the last keystroke before filtering. */
|
|
1021
1092
|
const SEARCH_DEBOUNCE_MS = 250
|
|
1022
1093
|
const TABLE_SEARCH_STYLE: CSSProperties = {
|
|
1023
1094
|
// `width` as well as the basis — see the `SEARCH_WIDTH` JSDoc.
|
|
1024
1095
|
width: SEARCH_WIDTH,
|
|
1025
|
-
flex: `0
|
|
1096
|
+
flex: `0 ${SEARCH_SHRINK} ${SEARCH_WIDTH}px`,
|
|
1026
1097
|
minWidth: '12ch',
|
|
1027
1098
|
maxWidth: '100%',
|
|
1028
1099
|
}
|
|
@@ -1044,264 +1115,6 @@ function getOrderedHeaderGroups<T extends RowData>(table: TanstackTable<BasaltTa
|
|
|
1044
1115
|
}))
|
|
1045
1116
|
}
|
|
1046
1117
|
|
|
1047
|
-
// Sticky offset math (column.getStart('start') / getAfter('end')) is computed purely from the
|
|
1048
|
-
// pinned columns' own `getSize()`, so only pinned cells need an explicit width to keep the offsets
|
|
1049
|
-
// accurate — center columns stay naturally sized. The hairline shadow marks the edge column
|
|
1050
|
-
// touching the unpinned center (first end-pinned index 0 / last start-pinned index). Offsets are
|
|
1051
|
-
// logical insets, so `dir=rtl` mirrors them; the hairline shadow is a physical offset and does not.
|
|
1052
|
-
function getPinnedCellStyle<T extends RowData>(
|
|
1053
|
-
table: TanstackTable<BasaltTableFeatures, T>,
|
|
1054
|
-
column: Column<BasaltTableFeatures, T, unknown>,
|
|
1055
|
-
): CSSProperties | undefined {
|
|
1056
|
-
const pinned = column.getIsPinned()
|
|
1057
|
-
if (!pinned) return undefined
|
|
1058
|
-
const size = column.getSize()
|
|
1059
|
-
const shared: CSSProperties = {
|
|
1060
|
-
position: 'sticky',
|
|
1061
|
-
zIndex: 1,
|
|
1062
|
-
width: size,
|
|
1063
|
-
minWidth: size,
|
|
1064
|
-
maxWidth: size,
|
|
1065
|
-
backgroundColor: VX.surface.panel,
|
|
1066
|
-
}
|
|
1067
|
-
if (pinned === 'start') {
|
|
1068
|
-
const isEdge = column.getPinnedIndex() === table.getStartLeafColumns().length - 1
|
|
1069
|
-
return {
|
|
1070
|
-
...shared,
|
|
1071
|
-
insetInlineStart: column.getStart('start'),
|
|
1072
|
-
boxShadow: isEdge ? `4px 0 6px -4px ${alpha(VX.ink, 0.18)}` : undefined,
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
const isEdge = column.getPinnedIndex() === 0
|
|
1076
|
-
return {
|
|
1077
|
-
...shared,
|
|
1078
|
-
insetInlineEnd: column.getAfter('end'),
|
|
1079
|
-
boxShadow: isEdge ? `-4px 0 6px -4px ${alpha(VX.ink, 0.18)}` : undefined,
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
// ── Column fold (`meta.priority`, docs/CONTROLS-SPEC.md §2) ──────────────────
|
|
1084
|
-
|
|
1085
|
-
/** The column id TanStack will resolve internally for this raw def — explicit `id`, else the
|
|
1086
|
-
* accessor key string. Mirrors the resolution `facetColumns` already relies on above. */
|
|
1087
|
-
function columnDefId<T extends RowData>(
|
|
1088
|
-
column: ColumnDef<BasaltTableFeatures, T, unknown>,
|
|
1089
|
-
): string | undefined {
|
|
1090
|
-
if (column.id !== undefined) return column.id
|
|
1091
|
-
return 'accessorKey' in column && typeof column.accessorKey === 'string'
|
|
1092
|
-
? column.accessorKey
|
|
1093
|
-
: undefined
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
* Fold order for `meta.priority` — the FIRST id in the returned list folds first. Effective
|
|
1098
|
-
* priority is `meta.priority ?? declaredIndex`, so with no `meta.priority` set anywhere it is just
|
|
1099
|
-
* the column's position: the LAST declared column folds first, the zero-config default a bare
|
|
1100
|
-
* `<BasaltDataTable data columns />` needs. An explicit priority folds a HIGHER number before a
|
|
1101
|
-
* lower one; a tie folds in reverse declared order. A column with no resolvable id (an
|
|
1102
|
-
* `accessorFn` with no explicit `id`) is never a fold candidate — nothing downstream could
|
|
1103
|
-
* reliably re-identify it once hidden.
|
|
1104
|
-
*/
|
|
1105
|
-
function foldOrder<T extends RowData>(
|
|
1106
|
-
columns: readonly ColumnDef<BasaltTableFeatures, T, unknown>[],
|
|
1107
|
-
): string[] {
|
|
1108
|
-
return columns
|
|
1109
|
-
.map((column, index) => ({
|
|
1110
|
-
id: columnDefId(column),
|
|
1111
|
-
priority: column.meta?.priority ?? index,
|
|
1112
|
-
index,
|
|
1113
|
-
}))
|
|
1114
|
-
.filter((candidate): candidate is { id: string; priority: number; index: number } =>
|
|
1115
|
-
Boolean(candidate.id),
|
|
1116
|
-
)
|
|
1117
|
-
.toSorted((a, b) => b.priority - a.priority || b.index - a.index)
|
|
1118
|
-
.map((candidate) => candidate.id)
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
/** Marks a rendered data column header for `useColumnFold`'s width measurement — never read past
|
|
1122
|
-
* that hook, so it carries no styling and needs no CSS-module counterpart. */
|
|
1123
|
-
const FOLD_ID_ATTR = 'data-basalt-fold-id'
|
|
1124
|
-
|
|
1125
|
-
/**
|
|
1126
|
-
* Pure decision: fold columns off the FRONT of `order` (already fold-first sorted) until the
|
|
1127
|
-
* still-unfolded ones — plus `overhead` (the columns excluded from candidacy altogether — pinned,
|
|
1128
|
-
* or `enableHiding: false` — which occupy room but can never fold) and the disclosure toggle's own
|
|
1129
|
-
* width, once anything is folded — fit `room`. A candidate with no measured width yet (never
|
|
1130
|
-
* rendered) is skipped rather than folded blind, since folding it would remove the one place its
|
|
1131
|
-
* width could ever be read from.
|
|
1132
|
-
*
|
|
1133
|
-
* Every width is a rounded integer (`offsetWidth`, `clientWidth`), and a table that fills its
|
|
1134
|
-
* wrapper stretches its columns to sum to `room` exactly — so the rounded sum lands up to half a
|
|
1135
|
-
* pixel per column over it, and a table that fits folded a column on hydration (a server-painted
|
|
1136
|
-
* table whose cells then moved). The fit check forgives that rounding and nothing more: half a
|
|
1137
|
-
* pixel for each measured width (the foldable columns AND `fixedCount`, the pinned / non-hiding
|
|
1138
|
-
* ones `overhead` sums), plus half a pixel for `room`'s own rounding (the `+ 1` in the slack).
|
|
1139
|
-
*/
|
|
1140
|
-
export function planColumnFold(input: {
|
|
1141
|
-
room: number
|
|
1142
|
-
toggleWidth: number
|
|
1143
|
-
overhead: number
|
|
1144
|
-
/** How many columns `overhead` sums, for the rounding slack. */
|
|
1145
|
-
fixedCount?: number
|
|
1146
|
-
order: readonly string[]
|
|
1147
|
-
widths: ReadonlyMap<string, number>
|
|
1148
|
-
}): ReadonlySet<string> {
|
|
1149
|
-
const { room, toggleWidth, overhead, fixedCount = 0, order, widths } = input
|
|
1150
|
-
const known = order.filter((id) => widths.has(id))
|
|
1151
|
-
const roundingSlack = (known.length + fixedCount + 1) / 2
|
|
1152
|
-
let unfolded = overhead + known.reduce((sum, id) => sum + (widths.get(id) ?? 0), 0)
|
|
1153
|
-
const folded = new Set<string>()
|
|
1154
|
-
for (const id of known) {
|
|
1155
|
-
// Never fold the last remaining data column — a table with every column folded has no row
|
|
1156
|
-
// identifier left to read at all, which is worse than the horizontal scroll this exists to
|
|
1157
|
-
// avoid. With no explicit `meta.priority` this is `order`'s LAST id, which `foldOrder`'s own
|
|
1158
|
-
// doc pins as the FIRST declared column (the last-declared one folds first).
|
|
1159
|
-
if (folded.size >= known.length - 1) break
|
|
1160
|
-
const withToggle = unfolded + (folded.size > 0 ? toggleWidth : 0)
|
|
1161
|
-
if (withToggle <= room + roundingSlack) break
|
|
1162
|
-
folded.add(id)
|
|
1163
|
-
unfolded -= widths.get(id) ?? 0
|
|
1164
|
-
}
|
|
1165
|
-
return folded
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
/**
|
|
1169
|
-
* The general-case measured fold. Reacting to `useMeasuredContainment`'s boolean fit directly
|
|
1170
|
-
* (fold one, remeasure, maybe unfold) would oscillate, because folding changes the very box being
|
|
1171
|
-
* measured. Instead this reads each candidate `<th data-basalt-fold-id>`'s width once, while it is
|
|
1172
|
-
* visible, caches it, and decides analytically (`planColumnFold`). `useMeasuredWidths` owns the
|
|
1173
|
-
* cache and the wrapper-vs-table observer that `controls/actions.tsx`'s fold shares.
|
|
1174
|
-
*/
|
|
1175
|
-
function useColumnFold(input: {
|
|
1176
|
-
active: boolean
|
|
1177
|
-
order: readonly string[]
|
|
1178
|
-
/**
|
|
1179
|
-
* Columns excluded from fold candidacy altogether (pinned, or `enableHiding: false`) — they are
|
|
1180
|
-
* never in `order`, but they still occupy room, and their measured widths (carried in the same
|
|
1181
|
-
* `[data-basalt-fold-id]` sweep as every eligible column's) become fixed overhead against the
|
|
1182
|
-
* fold baseline. See `planColumnFold`'s `overhead` param.
|
|
1183
|
-
*/
|
|
1184
|
-
fixedIds: readonly string[]
|
|
1185
|
-
}): {
|
|
1186
|
-
wrapperRef: RefObject<HTMLDivElement | null>
|
|
1187
|
-
folded: ReadonlySet<string>
|
|
1188
|
-
} {
|
|
1189
|
-
const { active, order, fixedIds } = input
|
|
1190
|
-
const wrapperRef = useRef<HTMLDivElement>(null)
|
|
1191
|
-
const [folded, setFolded] = useState<ReadonlySet<string>>(EMPTY_FOLD_SET)
|
|
1192
|
-
const orderRef = useRef(order)
|
|
1193
|
-
const fixedIdsRef = useRef(fixedIds)
|
|
1194
|
-
useLayoutEffect(() => {
|
|
1195
|
-
orderRef.current = order
|
|
1196
|
-
fixedIdsRef.current = fixedIds
|
|
1197
|
-
})
|
|
1198
|
-
if ((!active || order.length === 0) && folded.size > 0) setFolded(EMPTY_FOLD_SET)
|
|
1199
|
-
|
|
1200
|
-
useMeasuredWidths({
|
|
1201
|
-
resolveRoot: () => wrapperRef.current,
|
|
1202
|
-
signature: `${order.join('|')}::${fixedIds.join('|')}`,
|
|
1203
|
-
enabled: active && order.length > 0,
|
|
1204
|
-
// The table too, not only the wrapper: a re-measured column set moves its min-content width
|
|
1205
|
-
// while the wrapper's own box never changes.
|
|
1206
|
-
extra: (root) => [root.querySelector('table')],
|
|
1207
|
-
onMeasure: (root, boxes) => {
|
|
1208
|
-
for (const cell of root.querySelectorAll<HTMLElement>(`[${FOLD_ID_ATTR}]`)) {
|
|
1209
|
-
const id = cell.getAttribute(FOLD_ID_ATTR)
|
|
1210
|
-
if (id !== null && cell.offsetWidth > 0) {
|
|
1211
|
-
boxes.current.set(id, { width: cell.offsetWidth, height: cell.offsetHeight })
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
const room = root.clientWidth
|
|
1215
|
-
// A zero reading is an un-laid-out ancestor, not a table with no room — the same guard
|
|
1216
|
-
// `useMeasuredContainment` above runs against the aside animating in from 0.
|
|
1217
|
-
if (room === 0) return
|
|
1218
|
-
const widths = new Map([...boxes.current].map(([id, box]) => [id, box.width]))
|
|
1219
|
-
const overhead = fixedIdsRef.current.reduce((sum, id) => sum + (widths.get(id) ?? 0), 0)
|
|
1220
|
-
const next = planColumnFold({
|
|
1221
|
-
room,
|
|
1222
|
-
// The disclosure toggle is a fixed icon-button cell matched to the coarse hit floor, so it
|
|
1223
|
-
// reads as one more `--vx-hit` control rather than a narrower afterthought.
|
|
1224
|
-
toggleWidth: HIT_COARSE,
|
|
1225
|
-
overhead,
|
|
1226
|
-
fixedCount: fixedIdsRef.current.length,
|
|
1227
|
-
order: orderRef.current,
|
|
1228
|
-
widths,
|
|
1229
|
-
})
|
|
1230
|
-
setFolded((current) =>
|
|
1231
|
-
current.size === next.size && [...current].every((id) => next.has(id)) ? current : next,
|
|
1232
|
-
)
|
|
1233
|
-
},
|
|
1234
|
-
})
|
|
1235
|
-
|
|
1236
|
-
return { wrapperRef, folded: active ? folded : EMPTY_FOLD_SET }
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
/** The label half of a folded column's disclosure row — its own header when it is a plain string
|
|
1240
|
-
* (the common case), else the column id, since a function/`ReactNode` header has no header
|
|
1241
|
-
* CONTEXT to render with here (this is a body row, not the `<thead>`). */
|
|
1242
|
-
function columnLabel<T extends RowData>(column: Column<BasaltTableFeatures, T, unknown>): string {
|
|
1243
|
-
const header = column.columnDef.header
|
|
1244
|
-
return typeof header === 'string' ? header : column.id
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
/** One row's folded columns as label/value pairs, directly under it. `row.getAllCells()` returns
|
|
1248
|
-
* every leaf cell regardless of visibility (unlike `getVisibleCells()`), so a folded column's own
|
|
1249
|
-
* `cell` renderer still draws here exactly as it would in the `<td>` it no longer occupies. */
|
|
1250
|
-
function RowDisclosure<T extends RowData>({
|
|
1251
|
-
row,
|
|
1252
|
-
folded,
|
|
1253
|
-
}: {
|
|
1254
|
-
row: Row<BasaltTableFeatures, T>
|
|
1255
|
-
folded: ReadonlySet<string>
|
|
1256
|
-
}): ReactNode {
|
|
1257
|
-
const cells = row.getAllCells().filter((cell) => folded.has(cell.column.id))
|
|
1258
|
-
return (
|
|
1259
|
-
<div className={classes.foldDisclosure}>
|
|
1260
|
-
{cells.map((cell) => (
|
|
1261
|
-
<div key={cell.id} className={classes.foldDisclosureRow}>
|
|
1262
|
-
<Text className={classes.foldDisclosureLabel}>{columnLabel(cell.column)}</Text>
|
|
1263
|
-
<div className={classes.foldDisclosureValue}>
|
|
1264
|
-
<FlexRender cell={cell} />
|
|
1265
|
-
</div>
|
|
1266
|
-
</div>
|
|
1267
|
-
))}
|
|
1268
|
-
</div>
|
|
1269
|
-
)
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
/** The per-row expand/collapse control the fold-disclosure column renders — a text glyph, since
|
|
1273
|
-
* basalt ships no icon set (`docs/CONTROLS-SPEC.md` §2, mirrors `SortIndicator` above). */
|
|
1274
|
-
function FoldToggle({
|
|
1275
|
-
expanded,
|
|
1276
|
-
controlsId,
|
|
1277
|
-
onToggle,
|
|
1278
|
-
}: {
|
|
1279
|
-
expanded: boolean
|
|
1280
|
-
controlsId: string
|
|
1281
|
-
onToggle: () => void
|
|
1282
|
-
}): ReactNode {
|
|
1283
|
-
return (
|
|
1284
|
-
<button
|
|
1285
|
-
type="button"
|
|
1286
|
-
className={classes.foldToggle}
|
|
1287
|
-
data-basalt-hit
|
|
1288
|
-
aria-expanded={expanded}
|
|
1289
|
-
aria-controls={controlsId}
|
|
1290
|
-
aria-label={expanded ? 'Hide row details' : 'Show row details'}
|
|
1291
|
-
// A row carrying `onRowActivate` reads a bubbled click as "activate the row" — the toggle
|
|
1292
|
-
// would open/close its disclosure AND fire the row's own action underneath it.
|
|
1293
|
-
onClick={(event) => {
|
|
1294
|
-
event.stopPropagation()
|
|
1295
|
-
onToggle()
|
|
1296
|
-
}}
|
|
1297
|
-
>
|
|
1298
|
-
<Box component="span" aria-hidden>
|
|
1299
|
-
{expanded ? '▾' : '▸'}
|
|
1300
|
-
</Box>
|
|
1301
|
-
</button>
|
|
1302
|
-
)
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
1118
|
// ── The manual-pagination contract ────────────────────────────────────────────
|
|
1306
1119
|
|
|
1307
1120
|
/** One client-side control that `manualPagination` turns into a claim the table cannot support. */
|
|
@@ -1478,11 +1291,11 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1478
1291
|
enableSorting = true,
|
|
1479
1292
|
manualSorting = false,
|
|
1480
1293
|
striped,
|
|
1481
|
-
highlightOnHover,
|
|
1294
|
+
highlightOnHover = true,
|
|
1482
1295
|
emptyState,
|
|
1483
1296
|
isLoading = false,
|
|
1484
1297
|
query,
|
|
1485
|
-
skeletonRows
|
|
1298
|
+
skeletonRows,
|
|
1486
1299
|
enableGlobalFilter = false,
|
|
1487
1300
|
globalFilterPlaceholder = 'Search…',
|
|
1488
1301
|
searchIcon,
|
|
@@ -1635,7 +1448,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1635
1448
|
// the declared-order default and the explicit-priority rule. `enableHiding: false` and a PINNED
|
|
1636
1449
|
// column are excluded outright, not merely de-prioritized — both are the caller stating this
|
|
1637
1450
|
// column must stay visible, the same declaration a fold candidate has no way to override.
|
|
1638
|
-
const { columnFoldOrder, columnFoldFixedIds } = useMemo(() => {
|
|
1451
|
+
const { columnFoldOrder, columnFoldFixedIds, pinCandidates } = useMemo(() => {
|
|
1639
1452
|
const pinnedIds = new Set([...columnPinning.start, ...columnPinning.end])
|
|
1640
1453
|
const excluded = new Set(
|
|
1641
1454
|
columns.flatMap((column) => {
|
|
@@ -1647,17 +1460,54 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1647
1460
|
return {
|
|
1648
1461
|
columnFoldOrder: foldOrder(columns).filter((id) => !excluded.has(id)),
|
|
1649
1462
|
columnFoldFixedIds: [...excluded],
|
|
1463
|
+
// Leaf columns the caller did not pin itself, declared order: a caller's END pin must not
|
|
1464
|
+
// also become the start pin, where TanStack would resolve it as start.
|
|
1465
|
+
pinCandidates: columns.flatMap((column) => {
|
|
1466
|
+
const id = columnDefId(column)
|
|
1467
|
+
return id === undefined || 'columns' in column || pinnedIds.has(id) ? [] : [id]
|
|
1468
|
+
}),
|
|
1650
1469
|
}
|
|
1651
1470
|
}, [columns, columnPinning])
|
|
1471
|
+
// ── The query branch (law C3) ───────────────────────────────────────────────
|
|
1472
|
+
// `query`, when given, owns the body: it resolves the pending branch `isLoading` used to own,
|
|
1473
|
+
// plus the error branch the table had none of. `isLoading` stays live for every caller who never
|
|
1474
|
+
// had a query result to hand — the dev warning above covers the pair.
|
|
1475
|
+
const branch = query === undefined ? undefined : dataQueryBranch('BasaltDataTable', query)
|
|
1476
|
+
const showSkeleton = branch === undefined ? isLoading : branch === 'pending'
|
|
1477
|
+
const queryError = branch === 'error' && query !== undefined ? query : undefined
|
|
1652
1478
|
// The card projection unmounts the table, so the fold and the containment wrapper go inactive with
|
|
1653
1479
|
// it — their measuring effects re-attach to the remounted table when the width returns.
|
|
1654
1480
|
const { cards: showCards, rootRef: projectionRootRef } = useCardProjection(
|
|
1655
1481
|
renderCard !== undefined,
|
|
1656
1482
|
)
|
|
1657
|
-
const
|
|
1483
|
+
const renderedRows = useRef(0)
|
|
1484
|
+
// The row count the table last showed with data: a reload skeleton is that tall, not a guess.
|
|
1485
|
+
const [lastLoadedRows, setLastLoadedRows] = useState(0)
|
|
1486
|
+
const foldExtraIds = useMemo(
|
|
1487
|
+
() => [
|
|
1488
|
+
...(enableRowSelection ? [SELECT_COLUMN_ID] : []),
|
|
1489
|
+
...(hasRowActions ? [ACTIONS_COLUMN_ID] : []),
|
|
1490
|
+
],
|
|
1491
|
+
[enableRowSelection, hasRowActions],
|
|
1492
|
+
)
|
|
1493
|
+
const {
|
|
1494
|
+
folded: foldedColumns,
|
|
1495
|
+
wrapperRef: foldWrapperRef,
|
|
1496
|
+
pinId: autoPinId,
|
|
1497
|
+
overflowing: foldOverflowing,
|
|
1498
|
+
widths: measuredWidths,
|
|
1499
|
+
} = useColumnFold({
|
|
1658
1500
|
active: foldEligible && !showCards,
|
|
1659
1501
|
order: columnFoldOrder,
|
|
1660
1502
|
fixedIds: columnFoldFixedIds,
|
|
1503
|
+
extraIds: foldExtraIds,
|
|
1504
|
+
pinCandidates,
|
|
1505
|
+
// An explicit caller pin wins: the fold already treats it as fixed overhead, and a second,
|
|
1506
|
+
// implicit one beside it would stack two sticky columns nobody asked for.
|
|
1507
|
+
// A one-column table has nothing to scroll beside an identifier.
|
|
1508
|
+
allowPin: columnPinning.start.length === 0 && columns.length > 1,
|
|
1509
|
+
headerOnly: showSkeleton || queryError !== undefined,
|
|
1510
|
+
renderedRows,
|
|
1661
1511
|
})
|
|
1662
1512
|
const columnVisibility: ColumnVisibilityState = useMemo(
|
|
1663
1513
|
() => Object.fromEntries([...foldedColumns].map((id) => [id, false])),
|
|
@@ -1668,19 +1518,33 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1668
1518
|
|
|
1669
1519
|
// The actions column always sticks to the end edge, behind any end-pinned columns the caller
|
|
1670
1520
|
// asked for — so it is pinned through TanStack's own state, which also keeps their offsets right.
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1521
|
+
//
|
|
1522
|
+
// The auto-pin (SPEC § 6.6): once the fold has hit its floor and the table STILL overflows, the
|
|
1523
|
+
// first visible data column pins to the start edge (with the checkbox column ahead of it) so the
|
|
1524
|
+
// rest scrolls under a fixed identifier. It rides TanStack's own `columnPinning` state, merged
|
|
1525
|
+
// with the caller's — which wins outright whenever it pins a start column itself.
|
|
1526
|
+
const pinningActive = enablePinning || hasRowActions || autoPinId !== undefined
|
|
1527
|
+
const tablePinning = useMemo(() => {
|
|
1528
|
+
const start =
|
|
1529
|
+
autoPinId === undefined
|
|
1530
|
+
? columnPinning.start
|
|
1531
|
+
: [...(enableRowSelection ? [SELECT_COLUMN_ID] : []), autoPinId]
|
|
1532
|
+
const end = hasRowActions ? [...columnPinning.end, ACTIONS_COLUMN_ID] : columnPinning.end
|
|
1533
|
+
return { start, end }
|
|
1534
|
+
}, [columnPinning, hasRowActions, autoPinId, enableRowSelection])
|
|
1535
|
+
// The fold toggle column leads the row and sticks beside the pinned start cells, so they sit past it.
|
|
1536
|
+
const pinStartOffset = hasFolded && tablePinning.start.length > 0 ? HIT_COARSE : 0
|
|
1537
|
+
const autoPinMinWidth =
|
|
1538
|
+
autoPinId === undefined
|
|
1539
|
+
? undefined
|
|
1540
|
+
: (columns.find((column) => columnDefId(column) === autoPinId)?.minSize ?? PIN_MIN_WIDTH)
|
|
1541
|
+
const tableId = useId()
|
|
1679
1542
|
|
|
1680
1543
|
const table = useTable({
|
|
1681
1544
|
features: basaltTableFeatures,
|
|
1682
1545
|
data,
|
|
1683
1546
|
columns: tableColumns,
|
|
1547
|
+
defaultColumn: { cell: DEFAULT_CELL },
|
|
1684
1548
|
state: {
|
|
1685
1549
|
sorting: tableState.sorting,
|
|
1686
1550
|
globalFilter,
|
|
@@ -1720,14 +1584,14 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1720
1584
|
const showSearch = enableGlobalFilter && filteringEnabled
|
|
1721
1585
|
const showFacets = hasFacets && filteringEnabled
|
|
1722
1586
|
const showToolbar = showSearch || showFacets || Boolean(actions)
|
|
1723
|
-
|
|
1724
|
-
//
|
|
1725
|
-
// `
|
|
1726
|
-
//
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1587
|
+
// The PHONE tier of the toolbar, read off the header row's own width (never the viewport): below
|
|
1588
|
+
// the `regular` container class the facets live behind the one `Filters (n)` pill
|
|
1589
|
+
// (`FilterSet inline={0}`) — a search, a facet pill, `Filters` and the actions cannot share a
|
|
1590
|
+
// ~272px row, and two homes for the same facets is worse than one.
|
|
1591
|
+
const { ref: headerRef, narrow: narrowToolbar } = useNarrowerThan(
|
|
1592
|
+
CONTAINER_CLASSES.regular,
|
|
1593
|
+
showToolbar,
|
|
1594
|
+
)
|
|
1731
1595
|
|
|
1732
1596
|
// Every colSpan and every skeleton row counts the RENDERED columns: one more than `columns` for
|
|
1733
1597
|
// the prepended checkbox column, one more again for the fold-disclosure toggle once anything has
|
|
@@ -1739,6 +1603,28 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1739
1603
|
(hasFolded ? 1 : 0) -
|
|
1740
1604
|
foldedColumns.size
|
|
1741
1605
|
|
|
1606
|
+
// ARIA column positions (WCAG F102): `aria-colcount` counts the FULL column set — folded and
|
|
1607
|
+
// hidden columns included — and every cell's `aria-colindex` is its 1-based slot in that order,
|
|
1608
|
+
// so a fold leaves a gap a screen-reader user can hear. The fold toggle column is a real cell
|
|
1609
|
+
// leading the row, so while it renders it takes slot 1 and shifts the rest.
|
|
1610
|
+
const fullLeafColumns = pinningActive
|
|
1611
|
+
? [
|
|
1612
|
+
...table.getStartLeafColumns(),
|
|
1613
|
+
...table.getCenterLeafColumns(),
|
|
1614
|
+
...table.getEndLeafColumns(),
|
|
1615
|
+
]
|
|
1616
|
+
: table.getAllLeafColumns()
|
|
1617
|
+
const colIndexOffset = hasFolded ? 1 : 0
|
|
1618
|
+
const colIndexById = new Map(
|
|
1619
|
+
fullLeafColumns.map((column, index) => [column.id, index + 1 + colIndexOffset]),
|
|
1620
|
+
)
|
|
1621
|
+
const ariaColCount = fullLeafColumns.length + colIndexOffset
|
|
1622
|
+
// What the toggle announces: the folded columns' own headers, in column order.
|
|
1623
|
+
const foldedLabel = fullLeafColumns
|
|
1624
|
+
.filter((column) => foldedColumns.has(column.id))
|
|
1625
|
+
.map((column) => columnLabel(column))
|
|
1626
|
+
.join(', ')
|
|
1627
|
+
|
|
1742
1628
|
// `getSelectedRowModel()` is TanStack's own memo, so its `rows` array keeps its identity until
|
|
1743
1629
|
// the selection or the row model actually moves — which is what makes both memos below hold.
|
|
1744
1630
|
const selectedModelRows = enableRowSelection ? table.getSelectedRowModel().rows : undefined
|
|
@@ -1760,6 +1646,14 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1760
1646
|
// The rows actually rendered, not `data` — a filter or a page index that matches nothing leaves
|
|
1761
1647
|
// `data` non-empty while the body has nothing in it, and a blank body reads as a broken table.
|
|
1762
1648
|
const rows = table.getRowModel().rows
|
|
1649
|
+
const stateless = showSkeleton || queryError !== undefined
|
|
1650
|
+
useLayoutEffect(() => {
|
|
1651
|
+
renderedRows.current = rows.length
|
|
1652
|
+
})
|
|
1653
|
+
// Derived during render (React's own seam for state that follows a prop), not in an effect.
|
|
1654
|
+
if (!stateless && rows.length > 0 && rows.length !== lastLoadedRows) {
|
|
1655
|
+
setLastLoadedRows(rows.length)
|
|
1656
|
+
}
|
|
1763
1657
|
|
|
1764
1658
|
// `stickyHeaderOffset` is a WINDOW-scroll concept — the height of whatever fixed chrome the page
|
|
1765
1659
|
// scrolls under (the AppShell header plus `PageBar` row 2). Inside the scroll container it is
|
|
@@ -1783,6 +1677,17 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1783
1677
|
pageStickyHeader && !showCards,
|
|
1784
1678
|
)
|
|
1785
1679
|
const resolvedStickyHeaderOffset = scrolls ? undefined : stickyHeaderOffset
|
|
1680
|
+
// The declared-`minWidth` shape has no fold hook, so its scroller is measured on its own.
|
|
1681
|
+
const { wrapperRef: minWidthScrollerRef, contained: minWidthOverflowing } =
|
|
1682
|
+
useMeasuredContainment(!foldEligible && !showCards)
|
|
1683
|
+
// A scroll container is a keyboard tab stop ONLY while it actually scrolls (WCAG 2.1.1 — a
|
|
1684
|
+
// sighted keyboard user otherwise has no way to reach the clipped columns), and a focusable box
|
|
1685
|
+
// needs a role and a name (axe `scrollable-region-focusable`). The ring is `.scroller`'s.
|
|
1686
|
+
const scrollerLabel = `${title ?? 'Table'}, scrolls horizontally`
|
|
1687
|
+
const scrollerProps = (overflowing: boolean) =>
|
|
1688
|
+
overflowing
|
|
1689
|
+
? { tabIndex: 0, role: 'region', 'aria-label': scrollerLabel, className: classes.scroller }
|
|
1690
|
+
: undefined
|
|
1786
1691
|
|
|
1787
1692
|
// The error branch the table did not have (components audit #3) carries the query's OWN `refetch`
|
|
1788
1693
|
// behind Retry, so the failure is reported where the rows would have been — in a row spanning
|
|
@@ -1790,17 +1695,44 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1790
1695
|
const errorNode = queryError !== undefined && (
|
|
1791
1696
|
<ErrorState
|
|
1792
1697
|
error={queryError.error}
|
|
1793
|
-
title="Could not load
|
|
1698
|
+
title="Could not load"
|
|
1794
1699
|
tier="section"
|
|
1795
1700
|
retrying={queryError.fetchStatus === 'fetching'}
|
|
1796
1701
|
onRetry={() => void queryError.refetch()}
|
|
1797
1702
|
/>
|
|
1798
1703
|
)
|
|
1799
|
-
const emptyNode = emptyState ??
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1704
|
+
const emptyNode = emptyState ?? <EmptyState tier="section" title="No data to display." />
|
|
1705
|
+
|
|
1706
|
+
// The cells in render order (start → center → end) with only the visible ones — the skeleton rows
|
|
1707
|
+
// mirror the header with it.
|
|
1708
|
+
const orderedVisibleColumns = pinningActive
|
|
1709
|
+
? [
|
|
1710
|
+
...table.getStartVisibleLeafColumns(),
|
|
1711
|
+
...table.getCenterVisibleLeafColumns(),
|
|
1712
|
+
...table.getEndVisibleLeafColumns(),
|
|
1713
|
+
]
|
|
1714
|
+
: table.getVisibleLeafColumns()
|
|
1715
|
+
// One description of every sticky cell, read by the header, skeleton and body sites alike.
|
|
1716
|
+
const pinCtx: PinContext<T> = {
|
|
1717
|
+
table,
|
|
1718
|
+
startOffset: pinStartOffset,
|
|
1719
|
+
autoPinId,
|
|
1720
|
+
autoPinMinWidth,
|
|
1721
|
+
}
|
|
1722
|
+
const toggleCell = foldToggleCellProps(pinCtx)
|
|
1723
|
+
const { fitIds, spacer } = planColumnSizing(
|
|
1724
|
+
orderedVisibleColumns,
|
|
1725
|
+
new Set([SELECT_COLUMN_ID, ACTIONS_COLUMN_ID]),
|
|
1803
1726
|
)
|
|
1727
|
+
const fitAttr = (id: string) => (fitIds.has(id) ? { 'data-fit': true } : undefined)
|
|
1728
|
+
// colSpan covers the rendered cells, the trailing spacer included.
|
|
1729
|
+
const spanCount = columnCount + (spacer ? 1 : 0)
|
|
1730
|
+
// A page of rows when paginated, else what the table last showed, else the caller's guess.
|
|
1731
|
+
const skeletonCount = enablePagination
|
|
1732
|
+
? table.state.pagination.pageSize
|
|
1733
|
+
: lastLoadedRows > 0
|
|
1734
|
+
? lastLoadedRows
|
|
1735
|
+
: (skeletonRows ?? 5)
|
|
1804
1736
|
|
|
1805
1737
|
const tableNode = (
|
|
1806
1738
|
<Table
|
|
@@ -1809,6 +1741,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1809
1741
|
pageStickyHeader && !contained && classes.pageSticky,
|
|
1810
1742
|
classNames?.table,
|
|
1811
1743
|
)}
|
|
1744
|
+
aria-colcount={ariaColCount}
|
|
1812
1745
|
{...(striped !== undefined && { striped })}
|
|
1813
1746
|
{...(highlightOnHover !== undefined && { highlightOnHover })}
|
|
1814
1747
|
{...(stickyHeader !== undefined && { stickyHeader })}
|
|
@@ -1823,30 +1756,32 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1823
1756
|
<Table.Thead>
|
|
1824
1757
|
{headerGroups.map((headerGroup) => (
|
|
1825
1758
|
<Table.Tr key={headerGroup.id}>
|
|
1826
|
-
{/* The disclosure toggle column
|
|
1827
|
-
|
|
1759
|
+
{/* The disclosure toggle column sorts and selects nothing: its header says that columns
|
|
1760
|
+
are folded, and which. */}
|
|
1828
1761
|
{hasFolded && (
|
|
1829
|
-
<Table.Th
|
|
1830
|
-
<
|
|
1762
|
+
<Table.Th {...toggleCell} aria-colindex={1}>
|
|
1763
|
+
<FoldHeaderLabel count={foldedColumns.size} foldedLabel={foldedLabel} />
|
|
1831
1764
|
</Table.Th>
|
|
1832
1765
|
)}
|
|
1833
1766
|
{headerGroup.headers.map((header) => {
|
|
1834
1767
|
const canSort = sortingEnabled && header.column.getCanSort()
|
|
1835
1768
|
const sorted = header.column.getIsSorted()
|
|
1836
1769
|
const toggleSorting = header.column.getToggleSortingHandler()
|
|
1837
|
-
const
|
|
1838
|
-
|
|
1839
|
-
: undefined
|
|
1840
|
-
const align = resolveAlign(header.column)
|
|
1770
|
+
const pinned = pinningActive ? pinnedCellProps(pinCtx, header.column) : undefined
|
|
1771
|
+
const align = resolveAlign(header.column) ?? kindAlign(resolveKind(header.column))
|
|
1841
1772
|
const isSelectColumn = header.column.id === SELECT_COLUMN_ID
|
|
1842
1773
|
const isFoldCandidate = !isSelectColumn && header.column.id !== ACTIONS_COLUMN_ID
|
|
1843
1774
|
return (
|
|
1844
1775
|
<Table.Th
|
|
1845
1776
|
key={header.id}
|
|
1846
|
-
{
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1777
|
+
aria-colindex={colIndexById.get(header.column.id)}
|
|
1778
|
+
className={cx(isSelectColumn && classes.selectCell, pinned?.className)}
|
|
1779
|
+
{...fitAttr(header.column.id)}
|
|
1780
|
+
// The measured fold's own read (`useColumnFold`): a candidate's width plans the
|
|
1781
|
+
// fold, the checkbox / actions column's is fixed overhead against it.
|
|
1782
|
+
{...{
|
|
1783
|
+
[isFoldCandidate ? FOLD_ID_ATTR : FIXED_ID_ATTR]: header.column.id,
|
|
1784
|
+
}}
|
|
1850
1785
|
onClick={canSort ? toggleSorting : undefined}
|
|
1851
1786
|
onKeyDown={
|
|
1852
1787
|
canSort
|
|
@@ -1862,7 +1797,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1862
1797
|
style={{
|
|
1863
1798
|
...(canSort ? { cursor: 'pointer', userSelect: 'none' } : undefined),
|
|
1864
1799
|
...(align !== undefined && { textAlign: align }),
|
|
1865
|
-
...
|
|
1800
|
+
...pinned?.style,
|
|
1866
1801
|
}}
|
|
1867
1802
|
>
|
|
1868
1803
|
{header.isPlaceholder ? null : <FlexRender header={header} />}
|
|
@@ -1870,27 +1805,60 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1870
1805
|
</Table.Th>
|
|
1871
1806
|
)
|
|
1872
1807
|
})}
|
|
1808
|
+
{spacer && <Table.Th className={classes.spacer} aria-hidden />}
|
|
1873
1809
|
</Table.Tr>
|
|
1874
1810
|
))}
|
|
1875
1811
|
</Table.Thead>
|
|
1876
1812
|
<Table.Tbody>
|
|
1877
1813
|
{queryError !== undefined ? (
|
|
1878
1814
|
<Table.Tr>
|
|
1879
|
-
<Table.Td colSpan={
|
|
1815
|
+
<Table.Td colSpan={spanCount}>{errorNode}</Table.Td>
|
|
1880
1816
|
</Table.Tr>
|
|
1881
1817
|
) : showSkeleton ? (
|
|
1882
|
-
|
|
1818
|
+
// The same visible columns as the header — a folded table loads folded, and the pinned
|
|
1819
|
+
// identifier keeps its sticky cell, so nothing shifts when the rows arrive.
|
|
1820
|
+
Array.from({ length: skeletonCount }, (_, rowIndex) => (
|
|
1883
1821
|
<Table.Tr key={`skeleton-${rowIndex}`}>
|
|
1884
|
-
{
|
|
1885
|
-
<Table.Td
|
|
1886
|
-
<Skeleton
|
|
1822
|
+
{hasFolded && (
|
|
1823
|
+
<Table.Td {...toggleCell} aria-colindex={1}>
|
|
1824
|
+
<Skeleton h={12} w={12} radius="sm" display="inline-block" />
|
|
1887
1825
|
</Table.Td>
|
|
1888
|
-
)
|
|
1826
|
+
)}
|
|
1827
|
+
{orderedVisibleColumns.map((column) => {
|
|
1828
|
+
const pinned = pinningActive ? pinnedCellProps(pinCtx, column) : undefined
|
|
1829
|
+
const kind = resolveKind(column)
|
|
1830
|
+
// The loaded grid: a content-sized column keeps the width it last measured, the
|
|
1831
|
+
// others the kind's floor, so the rows arrive without the columns moving.
|
|
1832
|
+
const measuredWidth = fitIds.has(column.id)
|
|
1833
|
+
? measuredWidths.get(column.id)
|
|
1834
|
+
: undefined
|
|
1835
|
+
return (
|
|
1836
|
+
<Table.Td
|
|
1837
|
+
key={column.id}
|
|
1838
|
+
aria-colindex={colIndexById.get(column.id)}
|
|
1839
|
+
className={pinned?.className}
|
|
1840
|
+
{...fitAttr(column.id)}
|
|
1841
|
+
style={{
|
|
1842
|
+
minWidth:
|
|
1843
|
+
measuredWidth === undefined ? skeletonMinWidth(column) : measuredWidth,
|
|
1844
|
+
...pinned?.style,
|
|
1845
|
+
}}
|
|
1846
|
+
>
|
|
1847
|
+
{column.id === SELECT_COLUMN_ID || column.id === ACTIONS_COLUMN_ID ? null : (
|
|
1848
|
+
<KindSkeleton
|
|
1849
|
+
kind={kind}
|
|
1850
|
+
right={(resolveAlign(column) ?? kindAlign(kind)) === 'right'}
|
|
1851
|
+
/>
|
|
1852
|
+
)}
|
|
1853
|
+
</Table.Td>
|
|
1854
|
+
)
|
|
1855
|
+
})}
|
|
1856
|
+
{spacer && <Table.Td aria-hidden />}
|
|
1889
1857
|
</Table.Tr>
|
|
1890
1858
|
))
|
|
1891
1859
|
) : rows.length === 0 ? (
|
|
1892
1860
|
<Table.Tr>
|
|
1893
|
-
<Table.Td colSpan={
|
|
1861
|
+
<Table.Td colSpan={spanCount}>{emptyNode}</Table.Td>
|
|
1894
1862
|
</Table.Tr>
|
|
1895
1863
|
) : (
|
|
1896
1864
|
rows.map((row) => {
|
|
@@ -1909,47 +1877,67 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1909
1877
|
{...activationProps(onRowActivate, row.original)}
|
|
1910
1878
|
>
|
|
1911
1879
|
{hasFolded && (
|
|
1912
|
-
<Table.Td
|
|
1880
|
+
<Table.Td {...toggleCell} aria-colindex={1}>
|
|
1913
1881
|
<FoldToggle
|
|
1914
1882
|
expanded={rowExpanded}
|
|
1915
|
-
controlsId={`${row.id}-fold`}
|
|
1883
|
+
controlsId={`${tableId}-${row.id}-fold`}
|
|
1884
|
+
foldedLabel={foldedLabel}
|
|
1916
1885
|
onToggle={() => foldRows.toggle(row.id)}
|
|
1917
1886
|
/>
|
|
1918
1887
|
</Table.Td>
|
|
1919
1888
|
)}
|
|
1920
1889
|
{cells.map((cell) => {
|
|
1921
|
-
const
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
const align = resolveAlign(cell.column)
|
|
1890
|
+
const pinned = pinningActive ? pinnedCellProps(pinCtx, cell.column) : undefined
|
|
1891
|
+
const pinnedValue = cell.column.id === autoPinId ? cell.getValue() : undefined
|
|
1892
|
+
const kind = resolveKind(cell.column)
|
|
1893
|
+
const align = resolveAlign(cell.column) ?? kindAlign(kind)
|
|
1925
1894
|
return (
|
|
1926
1895
|
<Table.Td
|
|
1927
1896
|
key={cell.id}
|
|
1928
|
-
{
|
|
1929
|
-
|
|
1897
|
+
aria-colindex={colIndexById.get(cell.column.id)}
|
|
1898
|
+
className={cx(
|
|
1899
|
+
cell.column.id === SELECT_COLUMN_ID && classes.selectCell,
|
|
1900
|
+
kind !== undefined && kindClass(kind),
|
|
1901
|
+
pinned?.className,
|
|
1902
|
+
)}
|
|
1903
|
+
// The pinned column ellipsizes past its cap — the full text stays reachable.
|
|
1904
|
+
{...((typeof pinnedValue === 'string' ||
|
|
1905
|
+
typeof pinnedValue === 'number') && {
|
|
1906
|
+
title: String(pinnedValue),
|
|
1930
1907
|
})}
|
|
1908
|
+
{...(kind !== undefined && { 'data-kind': kind })}
|
|
1909
|
+
{...fitAttr(cell.column.id)}
|
|
1931
1910
|
{...(stopsRowActivation(cell) && {
|
|
1932
1911
|
// The label's ::after fills the select cell, so a tap on it bubbles to the
|
|
1933
1912
|
// row; the actions menu portals out but React bubbles through the portal.
|
|
1934
1913
|
onClick: (event: ReactMouseEvent) => event.stopPropagation(),
|
|
1935
1914
|
})}
|
|
1936
1915
|
style={{
|
|
1937
|
-
...(
|
|
1916
|
+
...(kind === undefined &&
|
|
1917
|
+
typeof cell.getValue() === 'number' &&
|
|
1938
1918
|
cell.column.columnDef.meta?.numeral !== false
|
|
1939
1919
|
? NUMERIC_CELL_STYLE
|
|
1940
1920
|
: undefined),
|
|
1941
1921
|
...(align !== undefined && { textAlign: align }),
|
|
1942
|
-
...
|
|
1922
|
+
...pinned?.style,
|
|
1943
1923
|
}}
|
|
1944
1924
|
>
|
|
1945
|
-
<
|
|
1925
|
+
<CellContent cell={cell} />
|
|
1946
1926
|
</Table.Td>
|
|
1947
1927
|
)
|
|
1948
1928
|
})}
|
|
1929
|
+
{spacer && <Table.Td aria-hidden />}
|
|
1949
1930
|
</Table.Tr>
|
|
1950
1931
|
{rowExpanded && (
|
|
1951
|
-
<Table.Tr
|
|
1952
|
-
|
|
1932
|
+
<Table.Tr
|
|
1933
|
+
id={`${tableId}-${row.id}-fold`}
|
|
1934
|
+
className={classes.foldDisclosureRowTr}
|
|
1935
|
+
>
|
|
1936
|
+
<Table.Td
|
|
1937
|
+
colSpan={spanCount}
|
|
1938
|
+
className={classes.foldDisclosureCell}
|
|
1939
|
+
aria-colindex={1}
|
|
1940
|
+
>
|
|
1953
1941
|
<RowDisclosure row={row} folded={foldedColumns} />
|
|
1954
1942
|
</Table.Td>
|
|
1955
1943
|
</Table.Tr>
|
|
@@ -1968,7 +1956,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1968
1956
|
{queryError !== undefined
|
|
1969
1957
|
? errorNode
|
|
1970
1958
|
: showSkeleton
|
|
1971
|
-
? Array.from({ length:
|
|
1959
|
+
? Array.from({ length: skeletonCount }, (_, index) => (
|
|
1972
1960
|
<Skeleton key={`skeleton-${index}`} height={48} radius="md" />
|
|
1973
1961
|
))
|
|
1974
1962
|
: rows.length === 0
|
|
@@ -1992,6 +1980,14 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1992
1980
|
const total = table.getRowCount()
|
|
1993
1981
|
const rangeStart = total === 0 ? 0 : paginationState.pageIndex * paginationState.pageSize + 1
|
|
1994
1982
|
const rangeEnd = Math.min((paginationState.pageIndex + 1) * paginationState.pageSize, total)
|
|
1983
|
+
// A page past the end (server-driven, the count shrank) keeps its pager so the reader can step
|
|
1984
|
+
// back, but states no range: "Showing 91–7 of 7" is a contradiction.
|
|
1985
|
+
const rangeInBounds = rangeStart <= rangeEnd || total === 0
|
|
1986
|
+
// Only a table that has NO rows drops its footer: a filter or search that matches nothing keeps
|
|
1987
|
+
// it (the pager and "Showing 0–0 of 0" belong to a table that has rows to page). Loading and
|
|
1988
|
+
// error keep the box too, the rows are about to land.
|
|
1989
|
+
const unfilteredCount = manualPagination ? total : table.getPreFilteredRowModel().rows.length
|
|
1990
|
+
const showFooter = enablePagination && (stateless || unfilteredCount > 0)
|
|
1995
1991
|
|
|
1996
1992
|
return (
|
|
1997
1993
|
<div
|
|
@@ -2005,13 +2001,21 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2005
2001
|
* spent title → 11px → search → 11px → thead before a single datum appeared, and the toolbar
|
|
2006
2002
|
* read as page furniture rather than as this table's controls.
|
|
2007
2003
|
*
|
|
2008
|
-
* `wrap="wrap"` is the
|
|
2009
|
-
*
|
|
2010
|
-
*
|
|
2011
|
-
*
|
|
2004
|
+
* `wrap="wrap"` is the header row's own: a toolbar whose natural width exceeds what is left
|
|
2005
|
+
* beside a title drops under it, full width. The TOOLBAR itself never wraps from the `compact`
|
|
2006
|
+
* container class up (`.toolbar`) — the search shrinks to its floor and `FilterSet` folds the
|
|
2007
|
+
* rest behind `+N`. `align="center"` puts the 28px controls on the title's optical line.
|
|
2012
2008
|
*/}
|
|
2013
2009
|
{(title !== undefined || showToolbar) && (
|
|
2014
|
-
<Group
|
|
2010
|
+
<Group
|
|
2011
|
+
ref={headerRef}
|
|
2012
|
+
className={classes.tableHeader}
|
|
2013
|
+
justify="space-between"
|
|
2014
|
+
align="center"
|
|
2015
|
+
wrap="wrap"
|
|
2016
|
+
gap="xs"
|
|
2017
|
+
mb="xs"
|
|
2018
|
+
>
|
|
2015
2019
|
{title !== undefined ? (
|
|
2016
2020
|
<Box style={TABLE_HEADER_LEAD_STYLE}>
|
|
2017
2021
|
<WidgetHeader
|
|
@@ -2019,22 +2023,25 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2019
2023
|
title={title}
|
|
2020
2024
|
{...(icon !== undefined && { icon })}
|
|
2021
2025
|
{...(subtitle !== undefined && { subtitle })}
|
|
2022
|
-
count
|
|
2026
|
+
// A count is a figure read from rows: none while the rows are loading or failed.
|
|
2027
|
+
{...(!stateless && { count: table.getRowCount() })}
|
|
2023
2028
|
/>
|
|
2024
2029
|
</Box>
|
|
2025
2030
|
) : null}
|
|
2026
2031
|
{showToolbar && (
|
|
2027
2032
|
<CtlSlot>
|
|
2028
2033
|
<Group
|
|
2029
|
-
className={cx(classNames?.toolbar)}
|
|
2034
|
+
className={cx(classes.toolbar, classNames?.toolbar)}
|
|
2030
2035
|
data-basalt-dense
|
|
2031
2036
|
gap="xs"
|
|
2032
|
-
wrap="wrap"
|
|
2033
2037
|
align="center"
|
|
2034
2038
|
style={TABLE_TOOLBAR_STYLE}
|
|
2035
2039
|
>
|
|
2036
2040
|
{showSearch && (
|
|
2037
2041
|
<TextInput
|
|
2042
|
+
size="ctl"
|
|
2043
|
+
classNames={{ wrapper: classes.toolbarWrapper, input: classes.toolbarInput }}
|
|
2044
|
+
wrapperProps={{ 'data-basalt-hit': true }}
|
|
2038
2045
|
radius="md"
|
|
2039
2046
|
style={TABLE_SEARCH_STYLE}
|
|
2040
2047
|
placeholder={globalFilterPlaceholder}
|
|
@@ -2047,7 +2054,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2047
2054
|
/>
|
|
2048
2055
|
)}
|
|
2049
2056
|
{showFacets && (
|
|
2050
|
-
<FilterSet>
|
|
2057
|
+
<FilterSet inline={narrowToolbar ? 0 : 1}>
|
|
2051
2058
|
{facets?.map((facet) => {
|
|
2052
2059
|
const column = resolveFacetColumn(table, facet)
|
|
2053
2060
|
if (!column) return null
|
|
@@ -2067,7 +2074,11 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2067
2074
|
})}
|
|
2068
2075
|
</FilterSet>
|
|
2069
2076
|
)}
|
|
2070
|
-
{actions !== undefined &&
|
|
2077
|
+
{actions !== undefined && (
|
|
2078
|
+
<div className={classes.toolbarActions}>
|
|
2079
|
+
<BarActionSlot actions={actions} />
|
|
2080
|
+
</div>
|
|
2081
|
+
)}
|
|
2071
2082
|
</Group>
|
|
2072
2083
|
</CtlSlot>
|
|
2073
2084
|
)}
|
|
@@ -2088,7 +2099,13 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2088
2099
|
// An explicit `minWidth` is the one genuinely DECLARED horizontal floor — the column fold
|
|
2089
2100
|
// never engages here (see `foldEligible`, above), so this shape keeps its exact
|
|
2090
2101
|
// pre-existing DOM: no extra measuring wrapper for a table nothing folds.
|
|
2091
|
-
<Table.ScrollContainer
|
|
2102
|
+
<Table.ScrollContainer
|
|
2103
|
+
ref={minWidthScrollerRef}
|
|
2104
|
+
type="native"
|
|
2105
|
+
minWidth={minWidth ?? 0}
|
|
2106
|
+
maxHeight={maxHeight}
|
|
2107
|
+
{...scrollerProps(minWidthOverflowing)}
|
|
2108
|
+
>
|
|
2092
2109
|
{tableNode}
|
|
2093
2110
|
</Table.ScrollContainer>
|
|
2094
2111
|
) : (
|
|
@@ -2104,21 +2121,31 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2104
2121
|
// used to sit here was the exact inert-sticky defect this shape exists to avoid.
|
|
2105
2122
|
<div
|
|
2106
2123
|
ref={containmentRef}
|
|
2107
|
-
className={classes.containment}
|
|
2124
|
+
className={cx(classes.containment, contained && classes.scroller)}
|
|
2108
2125
|
data-contained={contained ? 'true' : 'false'}
|
|
2126
|
+
{...(contained && {
|
|
2127
|
+
tabIndex: 0,
|
|
2128
|
+
role: 'region',
|
|
2129
|
+
'aria-label': scrollerLabel,
|
|
2130
|
+
})}
|
|
2109
2131
|
>
|
|
2110
2132
|
{tableNode}
|
|
2111
2133
|
</div>
|
|
2112
2134
|
) : (
|
|
2113
2135
|
// `pageStickyHeader` is false whenever `maxHeight` is set (`scrolls` above), so a vertical
|
|
2114
2136
|
// cap lands here — its own `ScrollArea` scrollport, just with no `minWidth` floor.
|
|
2115
|
-
<Table.ScrollContainer
|
|
2137
|
+
<Table.ScrollContainer
|
|
2138
|
+
type="native"
|
|
2139
|
+
minWidth={0}
|
|
2140
|
+
maxHeight={maxHeight}
|
|
2141
|
+
{...scrollerProps(foldOverflowing)}
|
|
2142
|
+
>
|
|
2116
2143
|
{tableNode}
|
|
2117
2144
|
</Table.ScrollContainer>
|
|
2118
2145
|
)}
|
|
2119
2146
|
</div>
|
|
2120
2147
|
)}
|
|
2121
|
-
{
|
|
2148
|
+
{showFooter && (
|
|
2122
2149
|
<Group
|
|
2123
2150
|
className={cx(classNames?.footer)}
|
|
2124
2151
|
justify="space-between"
|
|
@@ -2127,15 +2154,24 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2127
2154
|
gap="xs"
|
|
2128
2155
|
align="center"
|
|
2129
2156
|
>
|
|
2130
|
-
<Text
|
|
2157
|
+
<Text
|
|
2158
|
+
// Hidden, not removed: the footer keeps its height and nothing shifts when rows land.
|
|
2159
|
+
style={
|
|
2160
|
+
stateless || !rangeInBounds
|
|
2161
|
+
? { ...RANGE_LABEL_STYLE, visibility: 'hidden' }
|
|
2162
|
+
: RANGE_LABEL_STYLE
|
|
2163
|
+
}
|
|
2164
|
+
>
|
|
2131
2165
|
Showing {rangeStart}–{rangeEnd}
|
|
2132
2166
|
{totalIsAuthoritative ? ` of ${total}` : ''}
|
|
2133
2167
|
</Text>
|
|
2134
|
-
<Group gap="xs" align="center">
|
|
2168
|
+
<Group gap="xs" align="center" data-basalt-dense>
|
|
2135
2169
|
{/* theme-allow control-outside-home — the table's own page-size setting, not a page
|
|
2136
2170
|
filter: its state is the table's pagination, owned inside this component. */}
|
|
2137
2171
|
<Select
|
|
2138
2172
|
size="ctl"
|
|
2173
|
+
classNames={{ wrapper: classes.toolbarWrapper, input: classes.toolbarInput }}
|
|
2174
|
+
wrapperProps={{ 'data-basalt-hit': true }}
|
|
2139
2175
|
radius="md"
|
|
2140
2176
|
w={PAGE_SIZE_WIDTH}
|
|
2141
2177
|
data={pageSizeRows}
|
|
@@ -2150,6 +2186,17 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
2150
2186
|
size on its own — an explicit `size="sm"` is the visual this footer always had. */}
|
|
2151
2187
|
<Pagination
|
|
2152
2188
|
size="sm"
|
|
2189
|
+
// Mantine writes `--pagination-control-size` inline from `size`, which a class cannot
|
|
2190
|
+
// outrank — `vars` is the seam. The `ctl` height of the dense group above: 28 at a
|
|
2191
|
+
// fine pointer, 32 at a coarse one, the Select's own height either way. The labels
|
|
2192
|
+
// read `sm`, the cells' size, whatever the `size` prop maps to.
|
|
2193
|
+
vars={() => ({
|
|
2194
|
+
root: {
|
|
2195
|
+
'--pagination-control-size':
|
|
2196
|
+
'calc(var(--vx-space-control-height-ctl) * var(--mantine-scale))',
|
|
2197
|
+
'--pagination-control-fz': 'var(--vx-text-sm)',
|
|
2198
|
+
},
|
|
2199
|
+
})}
|
|
2153
2200
|
radius="md"
|
|
2154
2201
|
total={Math.max(table.getPageCount(), 1)}
|
|
2155
2202
|
value={paginationState.pageIndex + 1}
|