@tristan2828/ui-foundation 4.82.0 → 4.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/conventions/docs/add-an-entity.md +4 -4
- package/conventions/docs/cell-patterns.md +111 -50
- package/conventions/docs/entity-plan-template.md +3 -3
- package/dist/components/app/data-table.d.ts +36 -8
- package/dist/components/app/data-table.js +142 -90
- package/dist/hooks/use-table-url-state.d.ts +19 -1
- package/dist/hooks/use-table-url-state.js +31 -3
- package/package.json +1 -1
- package/styles/theme.css +6 -0
|
@@ -98,8 +98,8 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
98
98
|
cell pattern 18, "In a table's rows": each field's cell an
|
|
99
99
|
`EditableValue` over the shared control from `<entity>-fields.tsx` and
|
|
100
100
|
`useEdit<Entity>Field`, `InlineCreate` in the toolbar for create, a
|
|
101
|
-
delete row action with its confirm dialog, and `width="
|
|
102
|
-
plan's List screen says so. There's no reference file in the template
|
|
101
|
+
delete row action with its confirm dialog, and `width="full"` only if
|
|
102
|
+
the plan's List screen says so. There's no reference file in the template
|
|
103
103
|
for this shape; the pattern's code is the reference. Its specs: each
|
|
104
104
|
cell kind saves, a refusal stays in its cell, one cell at a time, the
|
|
105
105
|
leave prompt, create (Enter, a blank name, a taken one), delete, and
|
|
@@ -1034,8 +1034,8 @@ Every dialog is one of three widths, `DialogContent`'s `size` (4.82):
|
|
|
1034
1034
|
the in-place a11y block unless the plan has an `Edit in place` line,
|
|
1035
1035
|
and then only for the fields it names.
|
|
1036
1036
|
|
|
1037
|
-
- `width="
|
|
1038
|
-
`Width:
|
|
1037
|
+
- `width="full"` on `DataTable` unless the plan's List screen says
|
|
1038
|
+
`Width: full` (`content`, the default, is right for almost every list).
|
|
1039
1039
|
- The saved-views row in `widgets-table.tsx` (`VIEWS`, the "Saved views"
|
|
1040
1040
|
button group and `visibleColumns`) unless the plan's List screen lists
|
|
1041
1041
|
saved views. When it does, copy it: `useTableUrlState`'s third argument
|
|
@@ -3,42 +3,43 @@
|
|
|
3
3
|
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
|
-
- [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines
|
|
7
|
-
- [1. Plain text](#1-plain-text) · lines
|
|
8
|
-
- [2. Icon + label](#2-icon--label) · lines
|
|
9
|
-
- [3. Icon in a badge](#3-icon-in-a-badge) · lines
|
|
10
|
-
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines
|
|
11
|
-
- [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines
|
|
12
|
-
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines
|
|
13
|
-
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines
|
|
14
|
-
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines
|
|
15
|
-
- [8. Date, relative](#8-date-relative) · lines
|
|
16
|
-
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines
|
|
17
|
-
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines
|
|
18
|
-
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines
|
|
19
|
-
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines
|
|
20
|
-
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines
|
|
21
|
-
- [12. Boolean](#12-boolean) · lines
|
|
22
|
-
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines
|
|
23
|
-
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines
|
|
24
|
-
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines
|
|
25
|
-
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines
|
|
26
|
-
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines
|
|
27
|
-
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines
|
|
28
|
-
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines
|
|
30
|
-
- [Presets: one line per field](#presets-one-line-per-field) · lines
|
|
31
|
-
- [Several fields edited as one](#several-fields-edited-as-one) · lines
|
|
32
|
-
- [A link and its label](#a-link-and-its-label) · lines
|
|
33
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
34
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
35
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
36
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
37
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
38
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
39
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
40
|
-
- [
|
|
41
|
-
- [
|
|
6
|
+
- [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 71–90
|
|
7
|
+
- [1. Plain text](#1-plain-text) · lines 92–145
|
|
8
|
+
- [2. Icon + label](#2-icon--label) · lines 147–170
|
|
9
|
+
- [3. Icon in a badge](#3-icon-in-a-badge) · lines 172–185
|
|
10
|
+
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 187–264
|
|
11
|
+
- [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines 212–264
|
|
12
|
+
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 266–279
|
|
13
|
+
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 281–293
|
|
14
|
+
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines 295–316
|
|
15
|
+
- [8. Date, relative](#8-date-relative) · lines 318–355
|
|
16
|
+
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 357–405
|
|
17
|
+
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 375–405
|
|
18
|
+
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 407–457
|
|
19
|
+
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 425–457
|
|
20
|
+
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 459–499
|
|
21
|
+
- [12. Boolean](#12-boolean) · lines 501–531
|
|
22
|
+
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 533–569
|
|
23
|
+
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 553–569
|
|
24
|
+
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 571–588
|
|
25
|
+
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 590–699
|
|
26
|
+
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 616–699
|
|
27
|
+
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 701–736
|
|
28
|
+
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 738–811
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 813–1456
|
|
30
|
+
- [Presets: one line per field](#presets-one-line-per-field) · lines 1098–1156
|
|
31
|
+
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1158–1194
|
|
32
|
+
- [A link and its label](#a-link-and-its-label) · lines 1196–1220
|
|
33
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1222–1355
|
|
34
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1357–1442
|
|
35
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1444–1456
|
|
36
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1458–1524
|
|
37
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1526–1590
|
|
38
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1592–1690
|
|
39
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1692–1721
|
|
40
|
+
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1723–1761
|
|
41
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1763–1839
|
|
42
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1841–1864
|
|
42
43
|
|
|
43
44
|
<!-- /index -->
|
|
44
45
|
|
|
@@ -126,6 +127,23 @@ cell, a card's line or a caption with `<Markdown inline>`, not the block
|
|
|
126
127
|
- It's for one line. Long text is notes, the block `<Markdown>` on the
|
|
127
128
|
record's view.
|
|
128
129
|
|
|
130
|
+
**Long text in a list's column: `meta.clip`.** A column whose values run
|
|
131
|
+
long (a description, a note, a path) is cut to one line, so one long value
|
|
132
|
+
can't make the whole table thousands of pixels wide:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
{ id: 'notes', header: 'Notes', meta: { clip: true }, cell: ({ row }) => row.original.notes }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- One line, cut at `meta.maxWidth` (`'24rem'` unless set, and never over
|
|
139
|
+
60% of the table's area, so a phone keeps room for the name) with an
|
|
140
|
+
ellipsis.
|
|
141
|
+
- The whole text shows in a tooltip on hover and on focus: a cell that's
|
|
142
|
+
actually cut takes a tab stop, one that fits takes none. A screen reader
|
|
143
|
+
reads the whole text either way, and the record shows it too.
|
|
144
|
+
- `meta.maxWidth` alone caps the column and lets its text wrap, for a
|
|
145
|
+
value worth reading whole in the row.
|
|
146
|
+
|
|
129
147
|
## 2. Icon + label
|
|
130
148
|
|
|
131
149
|
A single-value enum where a glyph speeds up scanning but the word still
|
|
@@ -1376,7 +1394,7 @@ column and no edit route.
|
|
|
1376
1394
|
(`schema`), and a refusal (a taken name's 422) shows under the box.
|
|
1377
1395
|
- **Delete** stays a row action: a trash button in a pinned last column
|
|
1378
1396
|
(`pinLastColumn`), with its confirm dialog.
|
|
1379
|
-
- **
|
|
1397
|
+
- **Width:** the default, `width="content"` (below), keeps the row's cells
|
|
1380
1398
|
and its delete together on a wide screen.
|
|
1381
1399
|
|
|
1382
1400
|
```tsx
|
|
@@ -1425,15 +1443,17 @@ entity yet.
|
|
|
1425
1443
|
|
|
1426
1444
|
### A table of a few short columns: `width="content"`
|
|
1427
1445
|
|
|
1428
|
-
On a wide screen a table of
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1446
|
+
On a wide screen a table of a few short columns (a name, a colour, a
|
|
1447
|
+
count, its delete) spread across the page puts the row's actions far
|
|
1448
|
+
from its name. `width="content"`, the default since 4.83 (it was an
|
|
1449
|
+
opt-in from 80rem), sizes the table and its pagination to its columns at
|
|
1450
|
+
every width, never under 36rem (or the whole width, when that's less),
|
|
1451
|
+
with empty space at the right; the toolbar keeps the whole width, so its
|
|
1452
|
+
controls sit in the same place on every list. A table wider than its
|
|
1453
|
+
area scrolls sideways inside it. While it's loading, empty or failed
|
|
1454
|
+
after a load, it keeps the width it last had, so paging and filtering
|
|
1455
|
+
don't move it; only the first load can. `width="full"` takes the whole
|
|
1456
|
+
width, the look before 4.83; a card layout always does.
|
|
1437
1457
|
|
|
1438
1458
|
## 19. Stage circle for an ordered status
|
|
1439
1459
|
|
|
@@ -1678,10 +1698,11 @@ current one. `DataTable`'s `highlightRow` returns true for it.
|
|
|
1678
1698
|
<DataTable highlightRow={(book) => book.id === nextUpId} … />
|
|
1679
1699
|
```
|
|
1680
1700
|
|
|
1681
|
-
- **A wash of info on every cell**, over
|
|
1682
|
-
columns' opaque backgrounds (`--table-highlight`, pre-mixed onto
|
|
1683
|
-
page), and a bar in `info-text` at the row's start, so it reads
|
|
1684
|
-
colour too.
|
|
1701
|
+
- **A wash of info on every cell**, over a stripe (`striped`) and the
|
|
1702
|
+
pinned columns' opaque backgrounds (`--table-highlight`, pre-mixed onto
|
|
1703
|
+
the page), and a bar in `info-text` at the row's start, so it reads
|
|
1704
|
+
without colour too. The pointer's hover (pattern 24) leaves it as it
|
|
1705
|
+
is, so "next up" never reads as the hovered row. Still **say why in the row** (a "Next up" word or badge):
|
|
1685
1706
|
the wash says "look here", not what it is.
|
|
1686
1707
|
- **Muted text inside it is darkened for you.** `muted-foreground`
|
|
1687
1708
|
measures 4.09:1 on the wash, under 4.5:1, and no lighter wash fixes it
|
|
@@ -1699,6 +1720,46 @@ current one. `DataTable`'s `highlightRow` returns true for it.
|
|
|
1699
1720
|
the token check in both themes; `e2e/data-table.spec.ts` checks every
|
|
1700
1721
|
cell wears the wash.
|
|
1701
1722
|
|
|
1723
|
+
## 24. A list's rows: hover, lines, rows per page
|
|
1724
|
+
|
|
1725
|
+
What every `DataTable` does by default since 4.83 (the list page
|
|
1726
|
+
standard), and the two choices it leaves an app.
|
|
1727
|
+
|
|
1728
|
+
- **The row under the pointer** lights whole: every cell, pinned ones
|
|
1729
|
+
included, in `--table-hover` (the muted fill, solid), with a 3px bar in
|
|
1730
|
+
`--primary` on its first cell. Muted text inside it takes the darker
|
|
1731
|
+
grey a highlighted row's does (4.34:1 would be under 4.5 in light). A
|
|
1732
|
+
row that opens a record (`opens` with a dialog, a page or the panel, or
|
|
1733
|
+
`onRowClick`) takes the hand cursor; a row edited in place
|
|
1734
|
+
(`opens={{ kind: 'rows' }}`) gets the same highlight and keeps the
|
|
1735
|
+
arrow. A highlighted row (pattern 22) and the panel's picked row keep
|
|
1736
|
+
their own look.
|
|
1737
|
+
- **No zebra stripes:** rows are told apart by the line under each.
|
|
1738
|
+
`striped` brings the stripes back for an app that wants them. Tables in
|
|
1739
|
+
notes keep theirs (4.67.1).
|
|
1740
|
+
- **Rows per page:** a menu in the pagination bar, from
|
|
1741
|
+
`useTableUrlState`, which keeps the pick in the URL (`?size=`) and on
|
|
1742
|
+
this device:
|
|
1743
|
+
|
|
1744
|
+
```tsx
|
|
1745
|
+
const { page, setPage, pageSize, pageSizes, setPageSize } = useTableUrlState(FILTERS, MULTI, VIEWS, {
|
|
1746
|
+
pageSizeStorageKey: 'my-app:recipes:page-size', // defaults: pageSizes [25, 50, 100], defaultPageSize 50
|
|
1747
|
+
})
|
|
1748
|
+
const query = useRecipes({ page, pageSize, ... })
|
|
1749
|
+
<DataTable page={page} pageSize={pageSize} onPageChange={setPage}
|
|
1750
|
+
pageSizes={pageSizes} onPageSizeChange={setPageSize} … />
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
A pick returns to page 1. A size in the URL or storage that isn't one
|
|
1754
|
+
of `pageSizes` is ignored, so `?size=100000` can't ask the server for
|
|
1755
|
+
everything. Without `pageSizes` and `onPageSizeChange` the bar has no
|
|
1756
|
+
menu, as before.
|
|
1757
|
+
- The fixtures' `app/DataTable` ListLook, ListLookInRows and
|
|
1758
|
+
ListLookStriped stories hold all of it (with a `meta.clip` Notes
|
|
1759
|
+
column, pattern 1), under axe and the token check in both themes;
|
|
1760
|
+
`e2e/data-table.spec.ts` "list look" checks the hover on every cell,
|
|
1761
|
+
the cursors, the stripes, the tooltip, the widths and the menu.
|
|
1762
|
+
|
|
1702
1763
|
## 23. A Group menu, and a record read beside the list
|
|
1703
1764
|
|
|
1704
1765
|
A working list (tasks, chores, a backlog) is read two ways besides its
|
|
@@ -143,9 +143,9 @@ per list; delete the section if there are none.
|
|
|
143
143
|
| All tasks | none | dueDate asc | |
|
|
144
144
|
| Bugs | kind = bug | dueDate asc | title, severity, assignee, dueDate |
|
|
145
145
|
|
|
146
|
-
- Width (optional): `
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
- Width (optional): `full` for a table that should take the whole page.
|
|
147
|
+
Leave it out for the default, as wide as the columns need (cell pattern
|
|
148
|
+
18, "`width="content"`").
|
|
149
149
|
- Anything else the table must show or do:
|
|
150
150
|
|
|
151
151
|
## View screen
|
|
@@ -12,6 +12,18 @@ export type SortingState = {
|
|
|
12
12
|
declare module '@tanstack/table-core' {
|
|
13
13
|
interface ColumnMeta<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
|
|
14
14
|
align?: 'center' | 'right';
|
|
15
|
+
/**
|
|
16
|
+
* Long text on one line (DataTable): cut at `maxWidth` with an ellipsis,
|
|
17
|
+
* the whole text in a tooltip on hover and on focus (a cut cell takes a
|
|
18
|
+
* tab stop, so the keyboard reaches it too). Screen readers read it whole.
|
|
19
|
+
*/
|
|
20
|
+
clip?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The widest the column's content gets, as a CSS length: `'24rem'`
|
|
23
|
+
* unless set, with `clip` (and never over 60% of the table's area, for
|
|
24
|
+
* a phone). Without `clip`, the content wraps at it.
|
|
25
|
+
*/
|
|
26
|
+
maxWidth?: string;
|
|
15
27
|
}
|
|
16
28
|
}
|
|
17
29
|
export type DataTableProps<TData extends Record<string, unknown>> = {
|
|
@@ -22,6 +34,14 @@ export type DataTableProps<TData extends Record<string, unknown>> = {
|
|
|
22
34
|
page: number;
|
|
23
35
|
pageSize: number;
|
|
24
36
|
onPageChange: (page: number) => void;
|
|
37
|
+
/**
|
|
38
|
+
* The rows-per-page choices (`[25, 50, 100]`), drawn as a menu in the
|
|
39
|
+
* pagination bar with `onPageSizeChange`: useTableUrlState's `pageSizes`,
|
|
40
|
+
* `pageSize` and `setPageSize`, which keep the pick in the URL and on this
|
|
41
|
+
* device (`pageSizeStorageKey`). Left out, the bar has no menu.
|
|
42
|
+
*/
|
|
43
|
+
pageSizes?: readonly number[];
|
|
44
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
25
45
|
sorting: SortingState;
|
|
26
46
|
onSortingChange: (sorting: SortingState) => void;
|
|
27
47
|
isLoading: boolean;
|
|
@@ -65,15 +85,23 @@ export type DataTableProps<TData extends Record<string, unknown>> = {
|
|
|
65
85
|
*/
|
|
66
86
|
visibleColumns?: readonly string[];
|
|
67
87
|
/**
|
|
68
|
-
* `
|
|
69
|
-
* the
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
88
|
+
* `content` (the default, 4.83): the table and its pagination are as wide
|
|
89
|
+
* as the columns need, at least 36rem (or the whole width, when that's
|
|
90
|
+
* less), with empty space at the right, so a name stays close to its
|
|
91
|
+
* values at any screen size; wider than the area, the table scrolls
|
|
92
|
+
* sideways in it. The toolbar keeps the whole width, so its controls
|
|
93
|
+
* don't move between lists. While loading, empty or failed after a
|
|
94
|
+
* load, it keeps the width it last had, so paging and filtering don't
|
|
95
|
+
* move it (only the first load can). `full`: the table takes the whole
|
|
96
|
+
* width too (the default before 4.83). A card layout takes the whole
|
|
97
|
+
* width either way.
|
|
75
98
|
*/
|
|
76
99
|
width?: DataTableWidth;
|
|
100
|
+
/**
|
|
101
|
+
* Zebra stripes on the body rows (every other row tinted), as before
|
|
102
|
+
* 4.83. Off by default: rows are told apart by the line under each.
|
|
103
|
+
*/
|
|
104
|
+
striped?: boolean;
|
|
77
105
|
/**
|
|
78
106
|
* Rows under headings: each row's group (`byDay(field)` for a feed or a
|
|
79
107
|
* log). Rows keep the server's order, and a heading row spanning every
|
|
@@ -294,4 +322,4 @@ export type DataTableTotals = {
|
|
|
294
322
|
*/
|
|
295
323
|
cells?: Partial<Record<string, ReactNode>>;
|
|
296
324
|
};
|
|
297
|
-
export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
|
|
325
|
+
export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
|
|
@@ -22,6 +22,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel
|
|
|
22
22
|
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from '../ui/empty.js';
|
|
23
23
|
import { Sheet, SheetContent, SheetHeader, SheetTitle } from '../ui/sheet.js';
|
|
24
24
|
import { Skeleton } from '../ui/skeleton.js';
|
|
25
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
|
|
25
26
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
26
27
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
27
28
|
import { EditInPlaceStore } from './edit-in-place-store.js';
|
|
@@ -94,6 +95,40 @@ function GroupMenu({ groupings, value, onValueChange, }) {
|
|
|
94
95
|
const current = groupings.find((grouping) => grouping.id === value);
|
|
95
96
|
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { variant: "outline", size: "sm", "data-slot": "data-table-group-menu" }), children: [_jsx(ListTreeIcon, { "aria-hidden": "true" }), current ? `Group: ${current.label}` : 'Group'] }), _jsx(DropdownMenuContent, { align: "end", className: "w-48", children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Group by" }), _jsxs(DropdownMenuRadioGroup, { value: current?.id ?? NO_GROUPING, onValueChange: (next) => onValueChange(next === NO_GROUPING ? '' : String(next)), children: [_jsx(DropdownMenuRadioItem, { value: NO_GROUPING, closeOnClick: true, children: "None" }), groupings.map((grouping) => (_jsx(DropdownMenuRadioItem, { value: grouping.id, closeOnClick: true, children: grouping.label }, grouping.id)))] })] }) })] }));
|
|
96
97
|
}
|
|
98
|
+
// The rows-per-page menu in the pagination bar (`pageSizes`): a radio list
|
|
99
|
+
// that closes on a pick. The button says the size in words of its own
|
|
100
|
+
// ("50 rows", as the list page standard drew it), and the menu says
|
|
101
|
+
// what it is.
|
|
102
|
+
function PageSizeMenu({ pageSizes, value, onValueChange, }) {
|
|
103
|
+
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { variant: "outline", size: "sm", "data-slot": "data-table-page-size", "aria-label": `${value} rows per page` }), children: [value, " rows", _jsx(ChevronDownIcon, { "aria-hidden": "true" })] }), _jsx(DropdownMenuContent, { align: "end", className: "w-40", children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Rows per page" }), _jsx(DropdownMenuRadioGroup, { value: String(value), onValueChange: (next) => onValueChange(Number(next)), children: pageSizes.map((size) => (_jsx(DropdownMenuRadioItem, { value: String(size), closeOnClick: true, children: size }, size))) })] }) })] }));
|
|
104
|
+
}
|
|
105
|
+
// A cell's text cut to one line (`meta.clip`). Only when it is cut does it
|
|
106
|
+
// take a tab stop and a tooltip with the whole text, on hover and on focus;
|
|
107
|
+
// re-measured on every render (the text may change) and on every resize.
|
|
108
|
+
function ClippedText({ maxWidth, children }) {
|
|
109
|
+
const ref = useRef(null);
|
|
110
|
+
const [fullText, setFullText] = useState(null);
|
|
111
|
+
const measure = () => {
|
|
112
|
+
const element = ref.current;
|
|
113
|
+
if (!element)
|
|
114
|
+
return;
|
|
115
|
+
const isCut = element.scrollWidth > element.clientWidth + 0.5;
|
|
116
|
+
setFullText(isCut ? element.textContent?.trim() || null : null);
|
|
117
|
+
};
|
|
118
|
+
useLayoutEffect(measure);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
const element = ref.current;
|
|
121
|
+
if (!element)
|
|
122
|
+
return;
|
|
123
|
+
const observer = new ResizeObserver(() => measure());
|
|
124
|
+
observer.observe(element);
|
|
125
|
+
return () => observer.disconnect();
|
|
126
|
+
}, []);
|
|
127
|
+
return (_jsxs(Tooltip, { disabled: fullText === null, children: [_jsx(TooltipTrigger, { render: _jsx("span", { ref: ref, "data-slot": "data-table-clip", className: CLIP_CLASS,
|
|
128
|
+
// Never more than 60% of the table's area, so on a phone the
|
|
129
|
+
// cut column leaves the name and the rest room.
|
|
130
|
+
style: { maxWidth: `min(${maxWidth}, 60cqw)` }, tabIndex: fullText === null ? undefined : 0 }), children: children }), _jsx(TooltipContent, { className: "max-w-sm break-words whitespace-normal", children: fullText })] }));
|
|
131
|
+
}
|
|
97
132
|
// Whether the detail panel (`detailPanel`) fits beside the table, or opens
|
|
98
133
|
// as a bottom sheet. Wide on the server and wherever matchMedia is missing
|
|
99
134
|
// (a test's DOM), so markup never depends on it.
|
|
@@ -121,44 +156,49 @@ function TableSkeleton({ columnCount }) {
|
|
|
121
156
|
// The pinned cell gets an opaque background, not `bg-inherit`: the zebra
|
|
122
157
|
// stripe (table.tsx) is a *translucent* color, so inheriting it would let
|
|
123
158
|
// the columns scrolling behind show through at 40% opacity — exactly the
|
|
124
|
-
// bleed-through a solid background avoids.
|
|
125
|
-
// pre-mixed onto the page (--table-stripe), so the stripe
|
|
126
|
-
// row's width (issue #92); `:where()` keeps that rule's
|
|
127
|
-
// background's, so the
|
|
128
|
-
const PINNED_CELL_CLASS = 'z-10 bg-background
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// an inset shadow rather than a border, so nothing reflows.
|
|
132
|
-
const PINNED_COLUMN_CLASS = `sticky left-0 border-r ${PINNED_CELL_CLASS} group-hover/row:bg-accent ` +
|
|
133
|
-
'group-hover/row:shadow-[inset_3px_0_0_0_var(--primary)]';
|
|
134
|
-
// The right-edge mirror, opaque for the same reason, but with no hover
|
|
135
|
-
// highlight (issue #103): it holds the row's actions, which name nothing,
|
|
136
|
-
// so lighting it too read as a second selected thing. Only the first
|
|
137
|
-
// column marks the hovered row.
|
|
159
|
+
// bleed-through a solid background avoids. With `striped`, on an even row
|
|
160
|
+
// it's the stripe pre-mixed onto the page (--table-stripe), so the stripe
|
|
161
|
+
// runs the whole row's width (issue #92); `:where()` keeps that rule's
|
|
162
|
+
// specificity at the background's, so the row's hover below still wins.
|
|
163
|
+
const PINNED_CELL_CLASS = 'z-10 bg-background';
|
|
164
|
+
const PINNED_STRIPED_CELL_CLASS = '[:where(tbody>tr:nth-child(even))>&]:bg-(--table-stripe)';
|
|
165
|
+
const PINNED_COLUMN_CLASS = `sticky left-0 border-r ${PINNED_CELL_CLASS}`;
|
|
138
166
|
const PINNED_LAST_COLUMN_CLASS = `sticky right-0 border-l ${PINNED_CELL_CLASS}`;
|
|
139
167
|
// The totals row's label, pinned with the first column (`totals`): the
|
|
140
168
|
// same opaque cell, with no hover, since the row isn't one to pick.
|
|
141
|
-
const PINNED_TOTALS_LABEL_CLASS =
|
|
169
|
+
const PINNED_TOTALS_LABEL_CLASS = PINNED_COLUMN_CLASS;
|
|
170
|
+
// `striped` off (the default, 4.83): table.tsx's zebra taken back off the
|
|
171
|
+
// body (tailwind-merge drops its even-row tint for this one), so rows are
|
|
172
|
+
// told apart by the line under each.
|
|
173
|
+
const UNSTRIPED_BODY_CLASS = '[&_tr:nth-child(even)]:bg-transparent';
|
|
174
|
+
// A body row under the pointer (4.83): every cell, pinned ones included,
|
|
175
|
+
// in --table-hover (solid, so a pinned cell can wear it), with a bar in
|
|
176
|
+
// --primary on the first cell, so it reads without colour too; an inset
|
|
177
|
+
// shadow rather than a border, so nothing reflows. On a cell, not the row,
|
|
178
|
+
// so it covers a stripe and a pinned cell's opaque background alike
|
|
179
|
+
// (`.row:hover > td` outranks both). Muted text on it takes the darker grey
|
|
180
|
+
// a highlighted row's does (theme.css --table-hover). table.tsx's own row
|
|
181
|
+
// hover comes off: it would sit under the cells' tint anyway. A row that
|
|
182
|
+
// opens a record adds the hand cursor (SELECTABLE_ROW_CLASS); one edited in
|
|
183
|
+
// place keeps the arrow. A highlighted or picked row keeps its own look.
|
|
184
|
+
const HOVER_ROW_CLASS = 'hover:bg-transparent hover:[--muted-foreground:var(--table-highlight-muted-foreground)] ' +
|
|
185
|
+
'hover:[&>td]:bg-(--table-hover) hover:[&>td:first-child]:shadow-[inset_3px_0_0_0_var(--primary)]';
|
|
186
|
+
// Its bar and a focused row's ring, both on the first cell's shadow.
|
|
187
|
+
const HOVER_FOCUSED_ROW_CLASS = 'focus-visible:hover:[&>td:first-child]:shadow-[inset_3px_0_0_0_var(--primary),inset_0_2px_0_0_var(--ring),inset_0_-2px_0_0_var(--ring)]';
|
|
188
|
+
// A column's `meta.clip`: one line, cut at `meta.maxWidth` with an ellipsis.
|
|
189
|
+
const DEFAULT_CLIP_WIDTH = '24rem';
|
|
190
|
+
const CLIP_CLASS = 'block truncate rounded-sm outline-none focus-visible:ring-3 focus-visible:ring-ring/50';
|
|
142
191
|
// A pinned first column's content, capped below md at 45% of the table's
|
|
143
192
|
// scroll area (`cqw`: the container is an inline-size query container)
|
|
144
193
|
// and wrapping, so a long title can't widen the column past the screen
|
|
145
194
|
// and leave every other column scrolling underneath it (issue #91).
|
|
146
195
|
// Wider screens are unchanged: the column sizes to its content.
|
|
147
196
|
const PINNED_FIRST_CONTENT_CLASS = 'max-md:max-w-[45cqw] max-md:whitespace-normal max-md:break-words';
|
|
148
|
-
// Hover highlights the pinned cell, not the whole row. A row-level hover
|
|
149
|
-
// cannot be made consistent against the zebra stripe: `tr:nth-child(even)`
|
|
150
|
-
// is specificity (0,2,1) and `tr:hover` is (0,2,0), so the stripe wins and
|
|
151
|
-
// even rows stay unlit — odd rows highlight, even rows don't.
|
|
152
|
-
// `hover:bg-transparent` drops table.tsx's own `hover:bg-muted/50` via
|
|
153
|
-
// tailwind-merge so no row hover is attempted at all. The pinned cell is
|
|
154
|
-
// the better target anyway: it names the row, it sits on an opaque
|
|
155
|
-
// background so it reads identically on striped and unstriped rows, and it
|
|
156
|
-
// stays on screen when the table is scrolled right.
|
|
157
|
-
const ROW_GROUP_CLASS = 'group/row hover:bg-transparent';
|
|
158
197
|
// `highlightRow`: the wash on every cell, so it covers the zebra stripe
|
|
159
198
|
// (on the row) and the pinned cells' opaque backgrounds (on the cell, and
|
|
160
|
-
// one class weaker than this)
|
|
161
|
-
//
|
|
199
|
+
// one class weaker than this); hover leaves it as it is, so "next up" never
|
|
200
|
+
// reads as the pointer's row. A bar in info-text on the first cell, as
|
|
201
|
+
// hover's is in --primary, so it reads without colour too.
|
|
162
202
|
// Inside, muted text takes the darker grey the wash needs (theme.css).
|
|
163
203
|
const HIGHLIGHTED_ROW_CLASS = '[--muted-foreground:var(--table-highlight-muted-foreground)] [&>td]:bg-(--table-highlight) ' +
|
|
164
204
|
'[&>td:first-child]:shadow-[inset_3px_0_0_0_var(--info-text)]';
|
|
@@ -225,12 +265,13 @@ const WITH_DETAIL_OPEN_CLASS = 'grid-cols-[minmax(0,1fr)_minmax(18rem,26rem)]';
|
|
|
225
265
|
const DETAIL_ASIDE_CLASS = 'sticky top-4 flex max-h-[calc(100dvh-2rem)] min-w-0 flex-col gap-3 overflow-y-auto rounded-lg border ' +
|
|
226
266
|
'border-border bg-card p-4 text-card-foreground';
|
|
227
267
|
const EMPTY_KEYS = new Set();
|
|
228
|
-
// `width="content"`:
|
|
229
|
-
// need (`w-fit` over the table's own `w-full`), at least
|
|
230
|
-
// width it last had loaded while it shows another state
|
|
231
|
-
// (--data-table-last-width),
|
|
232
|
-
|
|
233
|
-
|
|
268
|
+
// `width="content"`: the table and its pagination (not the toolbar) as wide
|
|
269
|
+
// as the columns need (`w-fit` over the table's own `w-full`), at least
|
|
270
|
+
// 36rem, or the width it last had loaded while it shows another state
|
|
271
|
+
// (--data-table-last-width), and never wider than the area: `min()` keeps
|
|
272
|
+
// the minimum from pushing past a phone's width, since a min-width
|
|
273
|
+
// outranks a max-width.
|
|
274
|
+
const CONTENT_WIDTH_CLASS = 'w-fit max-w-full min-w-[min(100%,max(--spacing(144),var(--data-table-last-width,0px)))]';
|
|
234
275
|
// A second horizontal scrollbar, stuck to the viewport's bottom edge. The
|
|
235
276
|
// real one sits directly under the last row, which on a full page is
|
|
236
277
|
// off-screen until you have already scrolled past every row. Only rendered
|
|
@@ -320,7 +361,7 @@ function useStickyHeadings(containerRef, enabled) {
|
|
|
320
361
|
}, [containerRef, enabled]);
|
|
321
362
|
return { scrollsSideways, headHeight };
|
|
322
363
|
}
|
|
323
|
-
export function DataTable({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = '
|
|
364
|
+
export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', }) {
|
|
324
365
|
// The switch's own state, for a table that doesn't pass `layout`.
|
|
325
366
|
const [ownLayout, setOwnLayout] = useState('table');
|
|
326
367
|
const requestedLayout = layoutProp ?? ownLayout;
|
|
@@ -429,16 +470,19 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
|
|
|
429
470
|
const isSuccessView = !error && !isLoading && !isPastLastPage && !isEmpty;
|
|
430
471
|
// `width="content"`: the width the table last had loaded, kept while it
|
|
431
472
|
// shows another state.
|
|
473
|
+
// A card layout's grid takes the whole width whatever `width` says.
|
|
474
|
+
const fitsColumns = width === 'content' && !cardLayout;
|
|
432
475
|
const root = useRef(null);
|
|
476
|
+
const body = useRef(null);
|
|
433
477
|
const [lastWidth, setLastWidth] = useState(null);
|
|
434
478
|
useLayoutEffect(() => {
|
|
435
|
-
const element =
|
|
436
|
-
if (
|
|
479
|
+
const element = body.current;
|
|
480
|
+
if (!fitsColumns || !isSuccessView || !element)
|
|
437
481
|
return;
|
|
438
482
|
const observer = new ResizeObserver(() => setLastWidth(Math.round(element.getBoundingClientRect().width)));
|
|
439
483
|
observer.observe(element);
|
|
440
484
|
return () => observer.disconnect();
|
|
441
|
-
}, [
|
|
485
|
+
}, [fitsColumns, isSuccessView]);
|
|
442
486
|
const containerRef = useRef(null);
|
|
443
487
|
const { barRef, isOverflowing, scrollWidth } = useBottomScrollbar(containerRef, Boolean(pinFirstColumn) && isSuccessView && !cardLayout);
|
|
444
488
|
const rows = table.getRowModel().rows;
|
|
@@ -577,68 +621,76 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
|
|
|
577
621
|
// One body row, the same in a plain table and a grouped one.
|
|
578
622
|
const renderRow = (row, key = row.id) => {
|
|
579
623
|
const isSelected = Boolean(detailPanel) && key === selectedKey;
|
|
580
|
-
|
|
624
|
+
const isHighlighted = Boolean(highlightRow?.(row.original));
|
|
625
|
+
const hovers = !isHighlighted && !isSelected;
|
|
626
|
+
return (_jsx(TableRow, { "data-highlighted": isHighlighted || undefined, ...(rowsOpen
|
|
581
627
|
? {
|
|
582
628
|
'data-row-key': key,
|
|
583
629
|
...(detailPanel ? { 'data-selected': isSelected || undefined, 'aria-selected': isSelected } : {}),
|
|
584
630
|
tabIndex: key === tabStopKey ? 0 : -1,
|
|
585
631
|
onClickCapture: (event) => onRowClick(event, { key, rowId: row.id }),
|
|
586
632
|
}
|
|
587
|
-
: {}), className: cn(
|
|
633
|
+
: {}), className: cn('hover:bg-transparent', hovers && HOVER_ROW_CLASS, isHighlighted && HIGHLIGHTED_ROW_CLASS, rowsOpen && SELECTABLE_ROW_CLASS, rowsOpen && hovers && HOVER_FOCUSED_ROW_CLASS, isSelected && SELECTED_ROW_CLASS), children: row.getVisibleCells().map((cell, index) => {
|
|
634
|
+
const meta = cell.column.columnDef.meta;
|
|
635
|
+
const value = flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
636
|
+
const shown = meta?.clip ? (_jsx(ClippedText, { maxWidth: meta.maxWidth ?? DEFAULT_CLIP_WIDTH, children: value })) : meta?.maxWidth ? (_jsx("div", { className: "whitespace-normal break-words", style: { maxWidth: meta.maxWidth }, children: value })) : (value);
|
|
637
|
+
const isPinnedFirst = pinFirstColumn && index === 0;
|
|
638
|
+
const isPinnedLast = pinLastColumn && index === row.getVisibleCells().length - 1;
|
|
639
|
+
return (_jsx(TableCell, { className: cn(isPinnedFirst && PINNED_COLUMN_CLASS, isPinnedLast && PINNED_LAST_COLUMN_CLASS, (isPinnedFirst || isPinnedLast) && striped && PINNED_STRIPED_CELL_CLASS, alignClass(meta?.align)), children: isPinnedFirst ? _jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: shown }) : shown }, cell.id));
|
|
640
|
+
}) }, key));
|
|
588
641
|
};
|
|
589
|
-
const content = (_jsxs("div", { ref: root, className:
|
|
590
|
-
? { '--data-table-last-width': `${lastWidth}px` }
|
|
591
|
-
: undefined, children: [layouts?.length || groupings?.length ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: toolbar }), groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [activeGrouping && (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold all' : 'Fold all' })), _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layouts?.length ? (_jsx(LayoutSwitch, { options: [
|
|
642
|
+
const content = (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [layouts?.length || groupings?.length ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: toolbar }), groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [activeGrouping && (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold all' : 'Fold all' })), _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layouts?.length ? (_jsx(LayoutSwitch, { options: [
|
|
592
643
|
{ id: 'table', label: tableLayout?.label ?? 'Table', icon: tableLayout?.icon ?? TableIcon },
|
|
593
644
|
...layouts,
|
|
594
|
-
], value: currentLayout, onValueChange: setLayout })) : null] })) : (toolbar),
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
645
|
+
], value: currentLayout, onValueChange: setLayout })) : null] })) : (toolbar), _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: fitsColumns && !isSuccessView && lastWidth !== null
|
|
646
|
+
? { '--data-table-last-width': `${lastWidth}px` }
|
|
647
|
+
: undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry })) : isLoading || isPastLastPage ? (cardLayout ? (_jsx(CardsSkeleton, { layout: cardLayout })) : (_jsx(TableSkeleton, { columnCount: table.getVisibleLeafColumns().length }))) : isEmpty ? (_jsxs(Empty, { "data-state": "empty", children: [_jsxs(EmptyHeader, { children: [_jsx(EmptyTitle, { children: emptyTitle }), emptyDescription && _jsx(EmptyDescription, { children: emptyDescription })] }), emptyAction] })) : (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: selectedRow && detailPanel && isWide ? (_jsxs("aside", { "aria-label": detailLabel, "data-slot": "data-table-detail", className: DETAIL_ASIDE_CLASS, onKeyDown: (event) => {
|
|
648
|
+
const target = event.target;
|
|
649
|
+
if (event.key !== 'Escape' || event.defaultPrevented || target.closest(TYPING_SELECTOR))
|
|
650
|
+
return;
|
|
651
|
+
event.preventDefault();
|
|
652
|
+
closeDetail();
|
|
653
|
+
}, children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("h2", { className: "type-label text-muted-foreground", children: detailLabel }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: closeDetail, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }), detailPanel(selectedRow.original)] })) : null, children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons, onCardClick: onCardClick })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined, className: cn(stickyGroups && STICKY_FOCUS_CLASS), containerStyle: stickyGroups
|
|
654
|
+
? {
|
|
655
|
+
'--data-table-head-height': `${headHeight}px`,
|
|
656
|
+
'--data-table-sticky-top': stickyTop,
|
|
657
|
+
'--data-table-pin-top': scrollsSideways ? '0px' : stickyTop,
|
|
658
|
+
}
|
|
659
|
+
: undefined,
|
|
660
|
+
// With the sticky bar below as the visible scrollbar, hide the
|
|
661
|
+
// container's own. It stays overflow-x-auto and fully
|
|
662
|
+
// scrollable (wheel, trackpad, drag, and the sync effect); it
|
|
663
|
+
// just no longer draws a bar directly under the last row.
|
|
664
|
+
containerClassName: cn(
|
|
665
|
+
// A size container has no width of its own to give, so
|
|
666
|
+
// `width="content"` couldn't fit the table: there the
|
|
667
|
+
// pinned column's `cqw` measures the table's area
|
|
668
|
+
// (`@container/data-table`) instead.
|
|
669
|
+
pinFirstColumn && width !== 'content' && '@container', pinFirstColumn && '[scrollbar-width:none] [&::-webkit-scrollbar]:hidden', stickyGroups && (scrollsSideways ? STICKY_OWN_SCROLL_CLASS : STICKY_PAGE_SCROLL_CLASS)), children: [_jsx(TableHeader, { className: cn((!showHeader || stickyGroups) && '[&_tr]:border-0'), children: table.getHeaderGroups().map((headerGroup) => (_jsx(TableRow, { children: headerGroup.headers.map((header, index) => {
|
|
670
|
+
const canSort = header.column.getCanSort();
|
|
671
|
+
const sortDirection = header.column.getIsSorted();
|
|
672
|
+
// Hidden, a header is its name only: a sort button no
|
|
673
|
+
// one can see would still take focus.
|
|
674
|
+
const content = header.isPlaceholder ? null : canSort && showHeader ? (_jsxs("button", { type: "button", className: cn('flex items-center gap-1 text-foreground', header.column.columnDef.meta?.align === 'center' && 'w-full justify-center',
|
|
675
|
+
// The arrow on the label's left, so the label's
|
|
676
|
+
// right edge lines up with the numbers under it.
|
|
677
|
+
header.column.columnDef.meta?.align === 'right' && 'ml-auto flex-row-reverse'), onClick: header.column.getToggleSortingHandler(), children: [flexRender(header.column.columnDef.header, header.getContext()), sortDirection === 'asc' ? (_jsx(ArrowUpIcon, { className: "size-3.5 text-muted-foreground" })) : sortDirection === 'desc' ? (_jsx(ArrowDownIcon, { className: "size-3.5 text-muted-foreground" })) : (_jsx(ArrowUpDownIcon, { className: "size-3.5 text-muted-foreground/50" }))] })) : (flexRender(header.column.columnDef.header, header.getContext()));
|
|
678
|
+
return (_jsx(TableHead, { className: cn(!showHeader && HIDDEN_HEAD_CLASS, pinFirstColumn && index === 0 && PINNED_COLUMN_CLASS, pinLastColumn &&
|
|
679
|
+
index === headerGroup.headers.length - 1 &&
|
|
680
|
+
PINNED_LAST_COLUMN_CLASS, stickyGroups && showHeader && STICKY_HEAD_CELL_CLASS, alignClass(header.column.columnDef.meta?.align)), "aria-sort": !canSort
|
|
681
|
+
? undefined
|
|
682
|
+
: sortDirection === 'asc'
|
|
683
|
+
? 'ascending'
|
|
684
|
+
: sortDirection === 'desc'
|
|
685
|
+
? 'descending'
|
|
686
|
+
: 'none', children: !showHeader ? (_jsx("span", { className: "sr-only", children: content })) : pinFirstColumn && index === 0 ? (_jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: content })) : (content) }, header.id));
|
|
687
|
+
}) }, headerGroup.id))) }), runs ? (runs.map((run, runIndex) => {
|
|
688
|
+
const isFolded = folded.has(run.key);
|
|
689
|
+
return (_jsxs(TableBody, { "data-slot": "table-group", "data-folded": isFolded || undefined, className: cn(!striped && UNSTRIPED_BODY_CLASS), children: [_jsx(TableRow, { "data-slot": "table-group-heading", className: cn('hover:bg-transparent has-aria-expanded:bg-transparent', stickyGroups && 'border-b-0'), children: _jsx(TableHead, { scope: "rowgroup", colSpan: visibleColumnCount, className: cn(GROUP_HEADING_CLASS, stickyGroups && STICKY_GROUP_HEADING_CLASS), children: _jsxs("span", { className: "sticky left-(--table-cell-px) inline-flex items-baseline gap-2", children: [_jsx(GroupLabel, { run: run, icon: groupIcons?.get(run.key), isFolded: isFolded, onToggle: () => toggleFold(run.key) }), groupSummary && (_jsx("span", { className: "type-caption text-muted-foreground tabular-nums", children: groupSummary(run.rows.map((row) => row.original), { key: run.key, label: run.label }) }))] }) }) }), _jsx("tr", { hidden: true, "aria-hidden": "true", "data-slot": "table-group-stripe-offset" }), !isFolded && run.rows.map((row) => renderRow(row, placeKey(run.key, row.id)))] }, `${runIndex}:${run.key}`));
|
|
690
|
+
})) : (_jsx(TableBody, { className: cn(!striped && UNSTRIPED_BODY_CLASS), children: rows.map((row) => renderRow(row)) })), totals && (_jsx(TableFooter, { className: TOTALS_FOOTER_CLASS, children: _jsx(TableRow, { "data-slot": "table-totals", className: "hover:bg-transparent", children: visibleLeafColumns.map((column, index) => {
|
|
691
|
+
const className = cn(pinFirstColumn && index === 0 && PINNED_TOTALS_LABEL_CLASS, pinLastColumn && index === visibleColumnCount - 1 && PINNED_LAST_COLUMN_CLASS, alignClass(column.columnDef.meta?.align));
|
|
692
|
+
return index === 0 ? (_jsx(TableHead, { scope: "row", className: cn(TOTALS_LABEL_CLASS, className), children: pinFirstColumn ? (_jsx("div", { className: PINNED_FIRST_CONTENT_CLASS, children: totals.label })) : (totals.label) }, column.id)) : (_jsx(TableCell, { className: className, children: totals.cells?.[column.id] }, column.id));
|
|
693
|
+
}) }) }))] })), pinFirstColumn && isOverflowing && !cardLayout && (_jsx("div", { ref: barRef, "aria-hidden": "true", tabIndex: -1, "data-slot": "bottom-scrollbar", className: "sticky bottom-0 z-20 h-4 overflow-x-auto border-t border-border bg-background", children: _jsx("div", { style: { width: scrollWidth, height: 1 } }) })), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", "data-slot": "data-table-pagination", children: [_jsxs("p", { className: "type-body text-muted-foreground", children: [total === 0 ? 0 : (page - 1) * pageSize + 1, '–', Math.min(page * pageSize, total), " of ", total] }), _jsxs("div", { className: "flex items-center gap-2", children: [pageSizes && pageSizes.length > 1 && onPageSizeChange ? (_jsx(PageSizeMenu, { pageSizes: pageSizes, value: pageSize, onValueChange: onPageSizeChange })) : null, _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Previous page", disabled: page <= 1, onClick: () => onPageChange(page - 1), children: _jsx(ChevronLeftIcon, {}) }), _jsxs("span", { className: "type-body text-muted-foreground", children: ["Page ", page, " of ", pageCount] }), _jsx(Button, { variant: "outline", size: "icon-sm", "aria-label": "Next page", disabled: page >= pageCount, onClick: () => onPageChange(page + 1), children: _jsx(ChevronRightIcon, {}) })] })] })] })) })] }));
|
|
642
694
|
return (_jsxs(EditInPlaceContext.Provider, { value: store, children: [editing && _jsx(LeaveGuard, { store: store }), width === 'content' ? _jsx("div", { className: "@container/data-table", children: content }) : content, detailPanel && (_jsx(Sheet, { open: Boolean(selectedRow) && !isWide && isSuccessView && !cardLayout, onOpenChange: (open) => {
|
|
643
695
|
if (!open)
|
|
644
696
|
setSelection(null);
|
|
@@ -7,14 +7,30 @@ export type TableUrlStateOptions = {
|
|
|
7
7
|
* useTableLayout remembers a layout. Without one it lives only in the URL.
|
|
8
8
|
*/
|
|
9
9
|
groupStorageKey?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The rows-per-page choices, for DataTable's `pageSizes`: `[25, 50, 100]`
|
|
12
|
+
* unless set. A size from the URL or storage that isn't one of them is
|
|
13
|
+
* ignored.
|
|
14
|
+
*/
|
|
15
|
+
pageSizes?: readonly number[];
|
|
16
|
+
/** The rows per page until one is picked: 50 unless set (one of `pageSizes`). */
|
|
17
|
+
defaultPageSize?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Where the rows per page are remembered on this device, one key per table
|
|
20
|
+
* (`"my-app:tasks:page-size"`). Without one the pick lives only in the URL.
|
|
21
|
+
*/
|
|
22
|
+
pageSizeStorageKey?: string;
|
|
10
23
|
};
|
|
11
|
-
export declare function useTableUrlState<F extends string, M extends string = never, V extends string = never>(filterNames: readonly F[], multiFilterNames?: readonly M[], views?: Readonly<Record<V, TableView<NoInfer<F>, NoInfer<M>>>>, { groupStorageKey }?: TableUrlStateOptions): {
|
|
24
|
+
export declare function useTableUrlState<F extends string, M extends string = never, V extends string = never>(filterNames: readonly F[], multiFilterNames?: readonly M[], views?: Readonly<Record<V, TableView<NoInfer<F>, NoInfer<M>>>>, { groupStorageKey, pageSizes, defaultPageSize, pageSizeStorageKey, }?: TableUrlStateOptions): {
|
|
12
25
|
page: number;
|
|
13
26
|
sorting: SortingState;
|
|
14
27
|
filters: Record<F, string>;
|
|
15
28
|
multiFilters: Record<M, string[]>;
|
|
16
29
|
activeView: V | null;
|
|
17
30
|
grouping: string;
|
|
31
|
+
pageSize: number;
|
|
32
|
+
pageSizes: readonly number[];
|
|
33
|
+
setPageSize: (next: number) => void;
|
|
18
34
|
setGrouping: (next: string) => void;
|
|
19
35
|
setPage: (next: number) => void;
|
|
20
36
|
setSorting: (next: SortingState) => void;
|
|
@@ -23,3 +39,5 @@ export declare function useTableUrlState<F extends string, M extends string = ne
|
|
|
23
39
|
setMultiFilter: (name: M, values: string[]) => void;
|
|
24
40
|
applyView: (view: TableView<F, M>) => void;
|
|
25
41
|
};
|
|
42
|
+
/** The rows per page: the URL's if it's one of the choices, then the remembered one, then the default. */
|
|
43
|
+
export declare function resolvePageSize(pageSizes: readonly number[], fromUrl: string | null, remembered: string | null, defaultPageSize: number): number;
|
|
@@ -2,6 +2,7 @@ import { useCallback, useSyncExternalStore } from 'react';
|
|
|
2
2
|
import { useSearchParams } from 'react-router';
|
|
3
3
|
import { activeViewOf, applyUrlChanges, serializeSort, viewToUrlChanges, } from './table-url-changes.js';
|
|
4
4
|
import { browserStore } from './use-table-layout.js';
|
|
5
|
+
const DEFAULT_PAGE_SIZES = [25, 50, 100];
|
|
5
6
|
// A table's page, sort and filters, kept in the URL query string
|
|
6
7
|
// (`?page=2&sort=name:asc&search=mouse&tags=fragile&tags=bulky`) instead of
|
|
7
8
|
// component state, so they survive going to the edit form and back, a
|
|
@@ -17,6 +18,11 @@ import { browserStore } from './use-table-layout.js';
|
|
|
17
18
|
// counts as active); pass that view's `columns` to DataTable. A view is
|
|
18
19
|
// pressed with applyView().
|
|
19
20
|
//
|
|
21
|
+
// `pageSize` is the rows per page, for the query and DataTable: `?size=` in
|
|
22
|
+
// the URL, then the one remembered under `pageSizeStorageKey`, then
|
|
23
|
+
// `defaultPageSize`; `setPageSize` (DataTable's `onPageSizeChange`) picks
|
|
24
|
+
// one and returns to page 1. `pageSizes` is the menu's choices.
|
|
25
|
+
//
|
|
20
26
|
// `grouping` is DataTable's: a grouping's id, or '' for None. It's
|
|
21
27
|
// `?group=` in the URL, then the one remembered under `groupStorageKey`,
|
|
22
28
|
// then None. Like the sort it doesn't change which rows are shown, so it
|
|
@@ -24,10 +30,11 @@ import { browserStore } from './use-table-layout.js';
|
|
|
24
30
|
// names a `group` sets it when pressed.
|
|
25
31
|
//
|
|
26
32
|
// Every setter is one update(), and must stay one: see setFilters.
|
|
27
|
-
export function useTableUrlState(filterNames, multiFilterNames = [], views = {}, { groupStorageKey } = {}) {
|
|
33
|
+
export function useTableUrlState(filterNames, multiFilterNames = [], views = {}, { groupStorageKey, pageSizes = DEFAULT_PAGE_SIZES, defaultPageSize = 50, pageSizeStorageKey, } = {}) {
|
|
28
34
|
const [params, setParams] = useSearchParams();
|
|
29
|
-
const
|
|
30
|
-
const
|
|
35
|
+
const rememberedPageSize = useRemembered(pageSizeStorageKey);
|
|
36
|
+
const pageSize = resolvePageSize(pageSizes, params.get('size'), rememberedPageSize, defaultPageSize);
|
|
37
|
+
const rememberedGrouping = useRemembered(groupStorageKey);
|
|
31
38
|
const grouping = params.get('group') ?? rememberedGrouping ?? '';
|
|
32
39
|
const rememberGrouping = (next) => {
|
|
33
40
|
if (groupStorageKey !== undefined)
|
|
@@ -49,6 +56,13 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
49
56
|
multiFilters,
|
|
50
57
|
activeView,
|
|
51
58
|
grouping,
|
|
59
|
+
pageSize,
|
|
60
|
+
pageSizes,
|
|
61
|
+
setPageSize: (next) => {
|
|
62
|
+
if (pageSizeStorageKey !== undefined)
|
|
63
|
+
browserStore.set(pageSizeStorageKey, String(next));
|
|
64
|
+
update({ size: next === defaultPageSize ? null : String(next), page: null });
|
|
65
|
+
},
|
|
52
66
|
setGrouping: (next) => {
|
|
53
67
|
rememberGrouping(next);
|
|
54
68
|
update({ group: next || null });
|
|
@@ -73,3 +87,17 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
73
87
|
},
|
|
74
88
|
};
|
|
75
89
|
}
|
|
90
|
+
// A value remembered on this device under `key`, or null (none, or no key).
|
|
91
|
+
function useRemembered(key) {
|
|
92
|
+
const subscribe = useCallback((listener) => (key === undefined ? () => { } : browserStore.subscribe(key, listener)), [key]);
|
|
93
|
+
return useSyncExternalStore(subscribe, () => (key === undefined ? null : browserStore.get(key)), () => null);
|
|
94
|
+
}
|
|
95
|
+
/** The rows per page: the URL's if it's one of the choices, then the remembered one, then the default. */
|
|
96
|
+
export function resolvePageSize(pageSizes, fromUrl, remembered, defaultPageSize) {
|
|
97
|
+
for (const candidate of [fromUrl, remembered]) {
|
|
98
|
+
const size = candidate === null ? NaN : Number(candidate);
|
|
99
|
+
if (pageSizes.includes(size))
|
|
100
|
+
return size;
|
|
101
|
+
}
|
|
102
|
+
return defaultPageSize;
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.83.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/styles/theme.css
CHANGED
|
@@ -672,6 +672,11 @@
|
|
|
672
672
|
6.75:1. In dark the usual muted already clears it (6.61:1). */
|
|
673
673
|
--table-highlight: color-mix(in srgb, var(--info) 10%, var(--background));
|
|
674
674
|
--table-highlight-muted-foreground: var(--gray-600);
|
|
675
|
+
/* A body row under the pointer (DataTable, 4.83): the muted fill, solid
|
|
676
|
+
so pinned cells can wear it. Muted text measures 4.34:1 on it, so the
|
|
677
|
+
row takes --table-highlight-muted-foreground's darker grey (7.0:1).
|
|
678
|
+
In dark the usual muted clears it (5.9:1); a palette's dim, 5.8. */
|
|
679
|
+
--table-hover: var(--muted);
|
|
675
680
|
--border: var(--gray-200);
|
|
676
681
|
--input: var(--gray-200);
|
|
677
682
|
--ring: var(--gray-400);
|
|
@@ -962,6 +967,7 @@
|
|
|
962
967
|
--category-12-depth-5-foreground: var(--black);
|
|
963
968
|
--table-stripe: color-mix(in srgb, var(--muted) 40%, var(--background));
|
|
964
969
|
--table-highlight: color-mix(in srgb, var(--info) 20%, var(--background));
|
|
970
|
+
--table-hover: var(--muted);
|
|
965
971
|
--table-highlight-muted-foreground: var(--gray-400); /* the usual muted: not var(--muted-foreground), which the row redefines from this */
|
|
966
972
|
--border: var(--white-a10);
|
|
967
973
|
--input: var(--white-a15);
|