basalt-ui 2.6.1 → 2.7.1
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/AGENTS.md +15 -15
- package/CHANGELOG.md +26 -0
- package/MIGRATING.md +47 -12
- package/agent/rules/basalt-batteries.md +3 -3
- package/agent/rules/basalt-controls.md +3 -3
- package/agent/skills/basalt-app/SKILL.md +44 -0
- package/configs/oxlint-plugin.js +48 -0
- package/configs/oxlint-plugin.test.ts +82 -0
- package/dist/charts/DualPanel.d.ts +1 -1
- package/dist/charts/DualPanel.d.ts.map +1 -1
- package/dist/charts/DualPanel.js +2 -1
- package/dist/charts/legend.d.ts +9 -1
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +3 -2
- package/dist/commands/define-overlays.d.ts +5 -0
- package/dist/commands/define-overlays.d.ts.map +1 -1
- package/dist/commands/define-overlays.js +2 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/notifications/define-notifications.d.ts +3 -0
- package/dist/commands/notifications/define-notifications.d.ts.map +1 -1
- package/dist/controls/form-layout.d.ts +15 -6
- package/dist/controls/form-layout.d.ts.map +1 -1
- package/dist/forms/field.d.ts +42 -2
- package/dist/forms/field.d.ts.map +1 -1
- package/dist/forms/field.js +2 -2
- package/dist/forms/index.d.ts +4 -5
- package/dist/forms/index.d.ts.map +1 -1
- package/dist/surfaces.d.ts +2 -2
- package/dist/surfaces.js +2 -2
- package/dist/table/data-table.d.ts +37 -0
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +100 -17
- package/dist/table/index.d.ts +1 -0
- package/dist/table/index.d.ts.map +1 -1
- package/llms.txt +238 -5
- package/package.json +1 -1
- package/src/charts/DualPanel.tsx +5 -3
- package/src/charts/legend.tsx +16 -5
- package/src/commands/define-overlays.ts +5 -0
- package/src/commands/index.ts +4 -0
- package/src/commands/notifications/define-notifications.ts +3 -0
- package/src/controls/form-layout.tsx +15 -6
- package/src/forms/field.ts +78 -3
- package/src/forms/index.ts +4 -5
- package/src/surfaces.ts +2 -2
- package/src/table/data-table.tsx +175 -17
- package/src/table/index.ts +2 -0
package/src/table/data-table.tsx
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* />
|
|
33
33
|
*/
|
|
34
34
|
import {
|
|
35
|
+
ActionIcon,
|
|
35
36
|
Box,
|
|
36
37
|
Checkbox,
|
|
37
38
|
Group,
|
|
@@ -46,6 +47,7 @@ import {
|
|
|
46
47
|
} from '@mantine/core'
|
|
47
48
|
import type { MantineSpacing } from '@mantine/core'
|
|
48
49
|
import type {
|
|
50
|
+
Cell,
|
|
49
51
|
Column,
|
|
50
52
|
ColumnDef,
|
|
51
53
|
ColumnFiltersState,
|
|
@@ -69,8 +71,8 @@ import { HIT_COARSE } from '../common/hit-floor'
|
|
|
69
71
|
import { useMeasuredWidths } from '../common/use-measured-widths'
|
|
70
72
|
import { assertRequiredProps, useValidateProps } from '../common/validate'
|
|
71
73
|
import { FilterSet } from '../controls'
|
|
72
|
-
import { ActionGroup, BarActionSlot } from '../controls/actions'
|
|
73
|
-
import type { BarAction, SlotActions } from '../controls/actions'
|
|
74
|
+
import { ActionGroup, BarActionSlot, OverflowMenu } from '../controls/actions'
|
|
75
|
+
import type { BarAction, BarActionItem, SlotActions } from '../controls/actions'
|
|
74
76
|
// `EnumFilter` is deliberately NOT on the `./controls` barrel (`docs/CONTROLS-SPEC.md` §3 —
|
|
75
77
|
// reaching for it directly is hand-rolling a filter, `basalt/hand-rolled-filter`); a facet column
|
|
76
78
|
// is the one place inside the framework itself that legitimately builds a `FieldHandle` over
|
|
@@ -78,6 +80,7 @@ import type { BarAction, SlotActions } from '../controls/actions'
|
|
|
78
80
|
import { EnumFilter } from '../controls/enum-filter'
|
|
79
81
|
import { MultiSelectFilter } from '../controls/multi-select-filter'
|
|
80
82
|
import { CtlSlot } from '../theme'
|
|
83
|
+
import { IconSlot } from '../theme/icon-slot'
|
|
81
84
|
import { alpha, VX } from '../tokens'
|
|
82
85
|
import type { EnumField, FieldHandle, MultiField } from '../state/fields'
|
|
83
86
|
import { WidgetHeader } from '../dashboard'
|
|
@@ -358,6 +361,113 @@ function selectionColumn<T extends RowData>(): ColumnDef<BasaltTableFeatures, T,
|
|
|
358
361
|
}
|
|
359
362
|
}
|
|
360
363
|
|
|
364
|
+
// ── Row actions ───────────────────────────────────────────────────────────────
|
|
365
|
+
|
|
366
|
+
/** One per-row action: `BarActionItem`'s vocabulary with the row handed to the handler. */
|
|
367
|
+
export type DataTableRowAction<T = unknown> = {
|
|
368
|
+
key: string
|
|
369
|
+
label: string
|
|
370
|
+
/** A lone action with an icon renders as that icon button; anything else folds into the menu. */
|
|
371
|
+
icon?: ReactNode
|
|
372
|
+
onClick: (row: T) => void
|
|
373
|
+
danger?: boolean
|
|
374
|
+
/** A disabled action renders inert and never fires. */
|
|
375
|
+
disabled?: (row: T) => boolean
|
|
376
|
+
/** A loading action shows the busy state (icon button) or sits inert (menu) and never fires. */
|
|
377
|
+
loading?: (row: T) => boolean
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** The synthetic trailing column `rowActions` appends — namespaced like {@link SELECT_COLUMN_ID}. */
|
|
381
|
+
const ACTIONS_COLUMN_ID = '__basalt_actions__'
|
|
382
|
+
|
|
383
|
+
/** Wide enough for one 30px control plus the cell's horizontal padding. */
|
|
384
|
+
const ACTIONS_COLUMN_SIZE = 56
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The cells whose own controls must not read as "activate the row": a tickable selection cell (a
|
|
388
|
+
* disabled row's tap IS a row tap) and every actions cell.
|
|
389
|
+
*/
|
|
390
|
+
function stopsRowActivation<T extends RowData>(
|
|
391
|
+
cell: Cell<BasaltTableFeatures, T, unknown>,
|
|
392
|
+
): boolean {
|
|
393
|
+
if (cell.column.id === ACTIONS_COLUMN_ID) return true
|
|
394
|
+
return cell.column.id === SELECT_COLUMN_ID && cell.row.getCanSelect()
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function RowActionCell<T>({
|
|
398
|
+
actions,
|
|
399
|
+
row,
|
|
400
|
+
rowIndex,
|
|
401
|
+
rowLabel,
|
|
402
|
+
}: {
|
|
403
|
+
actions: readonly DataTableRowAction<T>[]
|
|
404
|
+
row: T
|
|
405
|
+
rowIndex: number
|
|
406
|
+
rowLabel: ((row: T) => string) | undefined
|
|
407
|
+
}): ReactNode {
|
|
408
|
+
const named = rowLabel?.(row)
|
|
409
|
+
const [only] = actions
|
|
410
|
+
if (actions.length === 1 && only?.icon !== undefined) {
|
|
411
|
+
const inert = only.disabled?.(row) === true || only.loading?.(row) === true
|
|
412
|
+
return (
|
|
413
|
+
<ActionIcon
|
|
414
|
+
variant="subtle"
|
|
415
|
+
size="ctl"
|
|
416
|
+
aria-label={named === undefined ? only.label : `${only.label}: ${named}`}
|
|
417
|
+
disabled={only.disabled?.(row) === true}
|
|
418
|
+
loading={only.loading?.(row) === true}
|
|
419
|
+
{...(only.danger === true && { color: 'red' })}
|
|
420
|
+
onClick={() => {
|
|
421
|
+
if (!inert) only.onClick(row)
|
|
422
|
+
}}
|
|
423
|
+
>
|
|
424
|
+
<IconSlot>{only.icon}</IconSlot>
|
|
425
|
+
</ActionIcon>
|
|
426
|
+
)
|
|
427
|
+
}
|
|
428
|
+
const items: BarActionItem[] = actions.map((action) => ({
|
|
429
|
+
key: action.key,
|
|
430
|
+
label: action.label,
|
|
431
|
+
...(action.icon !== undefined && { icon: action.icon }),
|
|
432
|
+
...(action.danger === true && { danger: true }),
|
|
433
|
+
// The menu has no busy state of its own, so loading reads as inert there.
|
|
434
|
+
disabled: action.disabled?.(row) === true || action.loading?.(row) === true,
|
|
435
|
+
onClick: () => action.onClick(row),
|
|
436
|
+
}))
|
|
437
|
+
return (
|
|
438
|
+
<OverflowMenu
|
|
439
|
+
actions={items}
|
|
440
|
+
trigger="kebab"
|
|
441
|
+
label={named === undefined ? `Row ${rowIndex + 1} actions` : `Actions for ${named}`}
|
|
442
|
+
/>
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Header-less: the `<th>` carries a screen-reader-only name and nothing sorts across it. Built per
|
|
448
|
+
* render for the same reason as {@link selectionColumn} (`ColumnDef` is generic in `T`).
|
|
449
|
+
*/
|
|
450
|
+
function rowActionsColumn<T extends RowData>(
|
|
451
|
+
actions: readonly DataTableRowAction<T>[],
|
|
452
|
+
rowLabel: ((row: T) => string) | undefined,
|
|
453
|
+
): ColumnDef<BasaltTableFeatures, T, unknown> {
|
|
454
|
+
return {
|
|
455
|
+
id: ACTIONS_COLUMN_ID,
|
|
456
|
+
size: ACTIONS_COLUMN_SIZE,
|
|
457
|
+
enableSorting: false,
|
|
458
|
+
enableHiding: false,
|
|
459
|
+
header: () => <span className={classes.srOnly}>Actions</span>,
|
|
460
|
+
cell: ({ row }) => (
|
|
461
|
+
<RowActionCell
|
|
462
|
+
actions={actions}
|
|
463
|
+
row={row.original}
|
|
464
|
+
rowIndex={row.index}
|
|
465
|
+
rowLabel={rowLabel}
|
|
466
|
+
/>
|
|
467
|
+
),
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
361
471
|
/**
|
|
362
472
|
* The bar a selection raises, above the table and below its header — the count, then the actions,
|
|
363
473
|
* through the SAME `BarAction[]` vocabulary `PageBar` uses, so the ≤3-inline fold and the mobile
|
|
@@ -661,6 +771,31 @@ export type BasaltDataTableProps<T extends RowData> = BasaltProps &
|
|
|
661
771
|
*/
|
|
662
772
|
bulkActions?: (rows: T[]) => BarAction[]
|
|
663
773
|
|
|
774
|
+
/**
|
|
775
|
+
* Per-row actions as typed data. The table renders them itself in a trailing, pinned,
|
|
776
|
+
* header-less column: an icon button for one action that carries an `icon`, an overflow menu
|
|
777
|
+
* for anything else. Clicking either never fires `onRowActivate`. Never put a `Menu` or
|
|
778
|
+
* `ActionIcon` in a `display` / `cell` renderer (`basalt/control-outside-home`).
|
|
779
|
+
*
|
|
780
|
+
* Pass a STABLE reference — a module constant or a `useMemo` — because the column is rebuilt
|
|
781
|
+
* whenever the array identity changes. A `renderCard` projection owns its own card, so the
|
|
782
|
+
* column renders in the table body only.
|
|
783
|
+
*
|
|
784
|
+
* State-dependent actions keep that array stable and read the state per row: put it in
|
|
785
|
+
* `disabled(row)` / `loading(row)` (state in a ref or the row itself), or `useMemo` the array
|
|
786
|
+
* keyed on exactly that state.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* const ROW_ACTIONS: DataTableRowAction<Row>[] = [
|
|
790
|
+
* { key: 'edit', label: 'Edit', icon: <IconEdit />, onClick: (row) => edit(row) },
|
|
791
|
+
* { key: 'delete', label: 'Delete', danger: true, onClick: (row) => remove(row) },
|
|
792
|
+
* ]
|
|
793
|
+
* <BasaltDataTable rowActions={ROW_ACTIONS} rowLabel={(row) => row.name} … />
|
|
794
|
+
*/
|
|
795
|
+
rowActions?: DataTableRowAction<T>[]
|
|
796
|
+
/** Names a row for assistive tech in its action controls; default `Row N actions`. */
|
|
797
|
+
rowLabel?: (row: T) => string
|
|
798
|
+
|
|
664
799
|
// ── Pagination ────────────────────────────────────────────────────────────────
|
|
665
800
|
|
|
666
801
|
/**
|
|
@@ -1354,6 +1489,8 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1354
1489
|
enableRowSelection = false,
|
|
1355
1490
|
getRowId,
|
|
1356
1491
|
bulkActions,
|
|
1492
|
+
rowActions,
|
|
1493
|
+
rowLabel,
|
|
1357
1494
|
enablePagination = false,
|
|
1358
1495
|
pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
|
|
1359
1496
|
manualPagination = false,
|
|
@@ -1443,9 +1580,14 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1443
1580
|
// The checkbox column is PREPENDED here rather than asked of the caller, so `columns` stays the
|
|
1444
1581
|
// caller's own data columns and `meta.align` / `numeral` never have to reason about a synthetic
|
|
1445
1582
|
// one. Everything counting columns downstream reads `columnCount`, below.
|
|
1583
|
+
const hasRowActions = rowActions !== undefined && rowActions.length > 0
|
|
1446
1584
|
const tableColumns = useMemo(
|
|
1447
|
-
() =>
|
|
1448
|
-
|
|
1585
|
+
() => [
|
|
1586
|
+
...(enableRowSelection ? [selectionColumn<T>()] : []),
|
|
1587
|
+
...facetColumns,
|
|
1588
|
+
...(hasRowActions ? [rowActionsColumn<T>(rowActions, rowLabel)] : []),
|
|
1589
|
+
],
|
|
1590
|
+
[facetColumns, enableRowSelection, hasRowActions, rowActions, rowLabel],
|
|
1449
1591
|
)
|
|
1450
1592
|
|
|
1451
1593
|
// Enforced before the table is built, so the degraded options below are the ones TanStack gets —
|
|
@@ -1519,6 +1661,17 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1519
1661
|
const hasFolded = foldedColumns.size > 0
|
|
1520
1662
|
const foldRows = useRowDisclosure({ data, getRowId })
|
|
1521
1663
|
|
|
1664
|
+
// The actions column always sticks to the end edge, behind any end-pinned columns the caller
|
|
1665
|
+
// asked for — so it is pinned through TanStack's own state, which also keeps their offsets right.
|
|
1666
|
+
const pinningActive = enablePinning || hasRowActions
|
|
1667
|
+
const tablePinning = useMemo(
|
|
1668
|
+
() =>
|
|
1669
|
+
hasRowActions
|
|
1670
|
+
? { ...columnPinning, end: [...columnPinning.end, ACTIONS_COLUMN_ID] }
|
|
1671
|
+
: columnPinning,
|
|
1672
|
+
[columnPinning, hasRowActions],
|
|
1673
|
+
)
|
|
1674
|
+
|
|
1522
1675
|
const table = useTable({
|
|
1523
1676
|
features: basaltTableFeatures,
|
|
1524
1677
|
data,
|
|
@@ -1527,7 +1680,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1527
1680
|
sorting: tableState.sorting,
|
|
1528
1681
|
globalFilter,
|
|
1529
1682
|
columnFilters: tableState.columnFilters,
|
|
1530
|
-
columnPinning,
|
|
1683
|
+
columnPinning: tablePinning,
|
|
1531
1684
|
columnVisibility,
|
|
1532
1685
|
...(enablePagination && { pagination: tableState.pagination }),
|
|
1533
1686
|
...(enableRowSelection && { rowSelection: tableState.rowSelection }),
|
|
@@ -1556,7 +1709,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1556
1709
|
...(manualPagination && pageCount !== undefined && { pageCount }),
|
|
1557
1710
|
}),
|
|
1558
1711
|
enableSorting: sortingEnabled,
|
|
1559
|
-
enableColumnPinning:
|
|
1712
|
+
enableColumnPinning: pinningActive,
|
|
1560
1713
|
})
|
|
1561
1714
|
|
|
1562
1715
|
const showSearch = enableGlobalFilter && filteringEnabled
|
|
@@ -1575,7 +1728,11 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1575
1728
|
// the prepended checkbox column, one more again for the fold-disclosure toggle once anything has
|
|
1576
1729
|
// folded — a stale count left the empty state and the error row short of the header.
|
|
1577
1730
|
const columnCount =
|
|
1578
|
-
columns.length +
|
|
1731
|
+
columns.length +
|
|
1732
|
+
(enableRowSelection ? 1 : 0) +
|
|
1733
|
+
(hasRowActions ? 1 : 0) +
|
|
1734
|
+
(hasFolded ? 1 : 0) -
|
|
1735
|
+
foldedColumns.size
|
|
1579
1736
|
|
|
1580
1737
|
// `getSelectedRowModel()` is TanStack's own memo, so its `rows` array keeps its identity until
|
|
1581
1738
|
// the selection or the row model actually moves — which is what makes both memos below hold.
|
|
@@ -1594,7 +1751,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1594
1751
|
: bulkActions(selectedRows),
|
|
1595
1752
|
[bulkActions, selectedRows],
|
|
1596
1753
|
)
|
|
1597
|
-
const headerGroups =
|
|
1754
|
+
const headerGroups = pinningActive ? getOrderedHeaderGroups(table) : table.getHeaderGroups()
|
|
1598
1755
|
// The rows actually rendered, not `data` — a filter or a page index that matches nothing leaves
|
|
1599
1756
|
// `data` non-empty while the body has nothing in it, and a blank body reads as a broken table.
|
|
1600
1757
|
const rows = table.getRowModel().rows
|
|
@@ -1672,18 +1829,19 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1672
1829
|
const canSort = sortingEnabled && header.column.getCanSort()
|
|
1673
1830
|
const sorted = header.column.getIsSorted()
|
|
1674
1831
|
const toggleSorting = header.column.getToggleSortingHandler()
|
|
1675
|
-
const pinnedStyle =
|
|
1832
|
+
const pinnedStyle = pinningActive
|
|
1676
1833
|
? getPinnedCellStyle(table, header.column)
|
|
1677
1834
|
: undefined
|
|
1678
1835
|
const align = resolveAlign(header.column)
|
|
1679
1836
|
const isSelectColumn = header.column.id === SELECT_COLUMN_ID
|
|
1837
|
+
const isFoldCandidate = !isSelectColumn && header.column.id !== ACTIONS_COLUMN_ID
|
|
1680
1838
|
return (
|
|
1681
1839
|
<Table.Th
|
|
1682
1840
|
key={header.id}
|
|
1683
1841
|
{...(isSelectColumn && { className: classes.selectCell })}
|
|
1684
1842
|
// The measured fold's own read (`useColumnFold`) — never present on the
|
|
1685
1843
|
// selection column, which is never a fold candidate.
|
|
1686
|
-
{...(
|
|
1844
|
+
{...(isFoldCandidate && { [FOLD_ID_ATTR]: header.column.id })}
|
|
1687
1845
|
onClick={canSort ? toggleSorting : undefined}
|
|
1688
1846
|
onKeyDown={
|
|
1689
1847
|
canSort
|
|
@@ -1731,7 +1889,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1731
1889
|
</Table.Tr>
|
|
1732
1890
|
) : (
|
|
1733
1891
|
rows.map((row) => {
|
|
1734
|
-
const cells =
|
|
1892
|
+
const cells = pinningActive
|
|
1735
1893
|
? [
|
|
1736
1894
|
...row.getStartVisibleCells(),
|
|
1737
1895
|
...row.getCenterVisibleCells(),
|
|
@@ -1755,7 +1913,7 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1755
1913
|
</Table.Td>
|
|
1756
1914
|
)}
|
|
1757
1915
|
{cells.map((cell) => {
|
|
1758
|
-
const pinnedStyle =
|
|
1916
|
+
const pinnedStyle = pinningActive
|
|
1759
1917
|
? getPinnedCellStyle(table, cell.column)
|
|
1760
1918
|
: undefined
|
|
1761
1919
|
const align = resolveAlign(cell.column)
|
|
@@ -1764,11 +1922,11 @@ export function BasaltDataTable<T extends RowData>(props: BasaltDataTableProps<T
|
|
|
1764
1922
|
key={cell.id}
|
|
1765
1923
|
{...(cell.column.id === SELECT_COLUMN_ID && {
|
|
1766
1924
|
className: classes.selectCell,
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1925
|
+
})}
|
|
1926
|
+
{...(stopsRowActivation(cell) && {
|
|
1927
|
+
// The label's ::after fills the select cell, so a tap on it bubbles to the
|
|
1928
|
+
// row; the actions menu portals out but React bubbles through the portal.
|
|
1929
|
+
onClick: (event: ReactMouseEvent) => event.stopPropagation(),
|
|
1772
1930
|
})}
|
|
1773
1931
|
style={{
|
|
1774
1932
|
...(typeof cell.getValue() === 'number' &&
|
package/src/table/index.ts
CHANGED