@tristan2828/ui-foundation 4.99.0 → 4.100.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/cell-patterns.md +81 -40
- package/dist/components/app/data-table-tools.d.ts +5 -1
- package/dist/components/app/data-table-tools.js +7 -2
- package/dist/components/app/data-table.d.ts +16 -1
- package/dist/components/app/data-table.js +128 -67
- package/dist/components/app/list-header.d.ts +21 -1
- package/dist/components/app/list-header.js +23 -4
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -3,46 +3,47 @@
|
|
|
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
|
-
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines
|
|
41
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
42
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
43
|
-
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines
|
|
44
|
-
- [
|
|
45
|
-
- [
|
|
6
|
+
- [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 75–98
|
|
7
|
+
- [1. Plain text](#1-plain-text) · lines 100–153
|
|
8
|
+
- [2. Icon + label](#2-icon--label) · lines 155–178
|
|
9
|
+
- [3. Icon in a badge](#3-icon-in-a-badge) · lines 180–193
|
|
10
|
+
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 195–272
|
|
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 220–272
|
|
12
|
+
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 274–294
|
|
13
|
+
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 296–308
|
|
14
|
+
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines 310–331
|
|
15
|
+
- [8. Date, relative](#8-date-relative) · lines 333–370
|
|
16
|
+
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 372–420
|
|
17
|
+
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 390–420
|
|
18
|
+
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 422–472
|
|
19
|
+
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 440–472
|
|
20
|
+
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 474–514
|
|
21
|
+
- [12. Boolean](#12-boolean) · lines 516–546
|
|
22
|
+
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 548–584
|
|
23
|
+
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 568–584
|
|
24
|
+
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 586–603
|
|
25
|
+
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 605–714
|
|
26
|
+
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 631–714
|
|
27
|
+
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 716–751
|
|
28
|
+
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 753–826
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 828–1506
|
|
30
|
+
- [Presets: one line per field](#presets-one-line-per-field) · lines 1138–1206
|
|
31
|
+
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1208–1244
|
|
32
|
+
- [A link and its label](#a-link-and-its-label) · lines 1246–1270
|
|
33
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1272–1405
|
|
34
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1407–1492
|
|
35
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1494–1506
|
|
36
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1508–1574
|
|
37
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1576–1640
|
|
38
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1642–1740
|
|
39
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1742–1771
|
|
40
|
+
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1773–1811
|
|
41
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1813–1889
|
|
42
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1891–1914
|
|
43
|
+
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1916–2042
|
|
44
|
+
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2004–2042
|
|
45
|
+
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2044–2080
|
|
46
|
+
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2082–2127
|
|
46
47
|
|
|
47
48
|
<!-- /index -->
|
|
48
49
|
|
|
@@ -2000,6 +2001,46 @@ const { filters, multiFilters, setFilter, setFilters, setMultiFilter, activeView
|
|
|
2000
2001
|
pick and a view's columns winning, the ⋯ menu, the 44px rows, the
|
|
2001
2002
|
phone's line and sheet.
|
|
2002
2003
|
|
|
2004
|
+
### The framed look, and sibling lists beside the title
|
|
2005
|
+
|
|
2006
|
+
The toolbar a list-page review picked (4.100): `look="framed"` on
|
|
2007
|
+
`DataTable`, and `siblings` on `ListHeader`. Both are opt-in.
|
|
2008
|
+
|
|
2009
|
+
```tsx
|
|
2010
|
+
<ListHeader
|
|
2011
|
+
title="Exercises" count={total}
|
|
2012
|
+
siblings={[
|
|
2013
|
+
{ label: 'Exercises', to: '/training/exercises', count: 5 },
|
|
2014
|
+
{ label: 'Targets', to: '/training/targets', count: 9 },
|
|
2015
|
+
{ label: 'Weak spots', to: '/training/weak-spots', count: 4 },
|
|
2016
|
+
]}
|
|
2017
|
+
deleted={{ shown, onShownChange: setShown, noun: 'exercises' }}
|
|
2018
|
+
newAction={{ label: 'New Exercise', to: '/training/exercises/new' }}
|
|
2019
|
+
/>
|
|
2020
|
+
<DataTable look="framed" views={VIEWS} columnsMenu={…} groupings={…} toolbar={<FilterBar … />} … />
|
|
2021
|
+
```
|
|
2022
|
+
|
|
2023
|
+
- **The card**: the toolbar in its top bar (search and Filters keep their
|
|
2024
|
+
words), the rows, then the count and pager in its bottom bar. Saved
|
|
2025
|
+
views sit above it, outside the bar. Loading, empty and error show
|
|
2026
|
+
inside it.
|
|
2027
|
+
- **The tools end at the table's edge**: the card is as wide as `width`
|
|
2028
|
+
makes the table, tools and pager with it, so nothing sits off at the
|
|
2029
|
+
far right of a wide page. `width="full"` fills the area as before.
|
|
2030
|
+
- **One settings button** in place of Columns and Group: the Columns
|
|
2031
|
+
ticks, then Group By, in one menu. Its name says the grouping that's on
|
|
2032
|
+
("Table Settings, Grouped by Status") and a dot marks it. Fold All
|
|
2033
|
+
stays a button of its own while grouped. On a phone it holds Group By
|
|
2034
|
+
alone.
|
|
2035
|
+
- **Siblings** are the page's peers, a switch of links beside the title,
|
|
2036
|
+
the current one marked (`aria-current="page"`); they don't go in ⋯,
|
|
2037
|
+
which keeps what's left. Two or more; on a phone the switch has its own
|
|
2038
|
+
line. Pass `current` when the siblings differ only by query string.
|
|
2039
|
+
- The fixtures' `app/DataTable tools` Framed and `app/ListHeader`
|
|
2040
|
+
Siblings stories hold it, under axe and the token check in both
|
|
2041
|
+
themes; `e2e/data-table-framed.spec.ts` checks the edges, the menu
|
|
2042
|
+
from the mouse and the keyboard, the switch and the phone.
|
|
2043
|
+
|
|
2003
2044
|
## 26. A record's related list, capped
|
|
2004
2045
|
|
|
2005
2046
|
A list of records related to this one, in a section of its view (a
|
|
@@ -30,7 +30,7 @@ export type DataTableColumnsMenu = {
|
|
|
30
30
|
/** The button's text: "Columns" unless set. */
|
|
31
31
|
label?: string;
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
type ColumnsMenuProps = {
|
|
34
34
|
/** Every column the menu can tick, in order, with its name. */
|
|
35
35
|
columns: readonly {
|
|
36
36
|
id: string;
|
|
@@ -44,6 +44,9 @@ export declare function ColumnsMenu({ columns, visible, fixed, pick, onPickChang
|
|
|
44
44
|
onPickChange: (pick: ColumnsPick | null) => void;
|
|
45
45
|
/** A view on that sets its own columns: the ticks show them and can't change. */
|
|
46
46
|
setByView: boolean;
|
|
47
|
+
};
|
|
48
|
+
export declare function ColumnsMenuItems({ columns, visible, fixed, pick, onPickChange, setByView }: ColumnsMenuProps): import("react").JSX.Element;
|
|
49
|
+
export declare function ColumnsMenu({ label, ...props }: ColumnsMenuProps & {
|
|
47
50
|
label?: string;
|
|
48
51
|
}): import("react").JSX.Element;
|
|
49
52
|
/** One of a row's actions (DataTable `rowActions`). */
|
|
@@ -96,3 +99,4 @@ export declare function ViewAllLink({ viewAll, total, navigator }: {
|
|
|
96
99
|
total: number;
|
|
97
100
|
navigator?: Navigator;
|
|
98
101
|
}): import("react").JSX.Element;
|
|
102
|
+
export {};
|
|
@@ -14,9 +14,14 @@ export function ViewPills({ views, value, onValueChange, label, }) {
|
|
|
14
14
|
// No view's id matches '' (filters set by hand), so none is pressed.
|
|
15
15
|
value: value ?? '', onValueChange: onValueChange, className: "max-md:w-max max-md:flex-nowrap" }) }));
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
// The menu's items alone: the Columns menu's, and the framed look's
|
|
18
|
+
// settings menu's first group (data-table.tsx's TableSettingsMenu).
|
|
19
|
+
export function ColumnsMenuItems({ columns, visible, fixed, pick, onPickChange, setByView }) {
|
|
18
20
|
const ids = [...fixed, ...columns.map((column) => column.id)];
|
|
19
|
-
return (_jsxs(
|
|
21
|
+
return (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: setByView ? 'Set by This View' : 'Show Columns' }), columns.map((column) => (_jsx(DropdownMenuCheckboxItem, { checked: visible.includes(column.id), disabled: setByView, onCheckedChange: (checked) => onPickChange(togglePick(ids, visible, column.id, checked, pick)), children: column.label }, column.id)))] }), pick && !setByView ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onClick: () => onPickChange(null), children: "Reset to the List's Columns" })] })) : null] }));
|
|
22
|
+
}
|
|
23
|
+
export function ColumnsMenu({ label = 'Columns', ...props }) {
|
|
24
|
+
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { variant: "outline", size: "sm", "data-slot": "data-table-columns-menu" }), children: [_jsx(Columns3Icon, { "aria-hidden": "true" }), label] }), _jsx(DropdownMenuContent, { align: "end", className: "w-52", children: _jsx(ColumnsMenuItems, { ...props }) })] }));
|
|
20
25
|
}
|
|
21
26
|
export function RowActions({ actions, rowLabel }) {
|
|
22
27
|
if (actions.length === 0)
|
|
@@ -305,7 +305,22 @@ export type DataTableProps<TData extends Record<string, unknown>, TView extends
|
|
|
305
305
|
* when there are more than the rows shown.
|
|
306
306
|
*/
|
|
307
307
|
viewAll?: DataTableViewAll;
|
|
308
|
+
/**
|
|
309
|
+
* How the list is drawn around its rows (4.100). `plain` (the default):
|
|
310
|
+
* the toolbar above the whole width, the Columns and Group menus as
|
|
311
|
+
* buttons at its end, the pagination under the rows. `framed`: the
|
|
312
|
+
* list is a card with a border, as wide as the table under `width`'s
|
|
313
|
+
* rules, so its tools end at the table's own edge and nothing sits off
|
|
314
|
+
* at the far right of a wide page. The card's top bar holds the toolbar
|
|
315
|
+
* (search and Filters keep their words), Fold All while grouped, one
|
|
316
|
+
* settings button holding the Columns ticks and Group By, and the layout
|
|
317
|
+
* switch; its bottom bar holds the count and the pager. Saved views stay
|
|
318
|
+
* above the card, outside its bar. Every other prop works the same way.
|
|
319
|
+
*/
|
|
320
|
+
look?: DataTableLook;
|
|
308
321
|
};
|
|
322
|
+
/** How DataTable draws the list around its rows (`look`). */
|
|
323
|
+
export type DataTableLook = 'plain' | 'framed';
|
|
309
324
|
/** A field DataTable's rows can be grouped by (`groupings`). */
|
|
310
325
|
export type DataTableGrouping<TData> = {
|
|
311
326
|
/**
|
|
@@ -380,4 +395,4 @@ export type DataTableTotals = {
|
|
|
380
395
|
*/
|
|
381
396
|
cells?: Partial<Record<string, ReactNode>>;
|
|
382
397
|
};
|
|
383
|
-
export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ 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, views, activeView, onViewChange, viewsLabel, columnsMenu, rowActions, phoneRow, limit, viewAll, }: DataTableProps<TData, TView>): import("react").JSX.Element;
|
|
398
|
+
export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ 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, views, activeView, onViewChange, viewsLabel, columnsMenu, rowActions, phoneRow, limit, viewAll, look, }: DataTableProps<TData, TView>): import("react").JSX.Element;
|
|
@@ -15,10 +15,10 @@ import { UNSAFE_LocationContext as LocationContext, UNSAFE_NavigationContext as
|
|
|
15
15
|
import { flexRender } from '@tanstack/react-table';
|
|
16
16
|
import { cn } from 'cn';
|
|
17
17
|
import { getCoreRowModel, useLegacyTable } from '@tanstack/react-table/legacy';
|
|
18
|
-
import { ArrowDownIcon, ArrowUpIcon, ArrowUpDownIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ListTreeIcon, TableIcon, XIcon, } from 'lucide-react';
|
|
18
|
+
import { ArrowDownIcon, ArrowUpIcon, ArrowUpDownIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ListTreeIcon, Settings2Icon, TableIcon, XIcon, } from 'lucide-react';
|
|
19
19
|
import { ErrorState } from './error-state.js';
|
|
20
20
|
import { Button } from '../ui/button.js';
|
|
21
|
-
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
21
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
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';
|
|
@@ -28,8 +28,9 @@ import { EditInPlaceContext } from './edit-in-place.js';
|
|
|
28
28
|
import { EditInPlaceStore } from './edit-in-place-store.js';
|
|
29
29
|
import { LeaveGuard } from './editable-value.js';
|
|
30
30
|
import { recordDialogState } from './record-dialog-context.js';
|
|
31
|
+
import { IconAction } from './icon-action.js';
|
|
31
32
|
import { groupByValues, groupRuns } from './table-groups.js';
|
|
32
|
-
import { ColumnsMenu, PHONE_LIST_CLASS, PhoneRow, PhoneRowsSkeleton, RowActions, ViewAllLink, ViewPills, } from './data-table-tools.js';
|
|
33
|
+
import { ColumnsMenu, ColumnsMenuItems, PHONE_LIST_CLASS, PhoneRow, PhoneRowsSkeleton, RowActions, ViewAllLink, ViewPills, } from './data-table-tools.js';
|
|
33
34
|
import { ROW_ACTIONS_COLUMN_ID, visibleFromPick } from './table-columns.js';
|
|
34
35
|
import { useColumnsPick } from '../../hooks/use-columns-pick.js';
|
|
35
36
|
import { useIsPhone } from '../../hooks/use-is-phone.js';
|
|
@@ -95,10 +96,38 @@ function LayoutSwitch({ options, value, onValueChange, }) {
|
|
|
95
96
|
// a pick. Base UI's radio group needs a value for None, so it's this
|
|
96
97
|
// stand-in, never '' (the grouping's own word for None).
|
|
97
98
|
const NO_GROUPING = '__none__';
|
|
98
|
-
|
|
99
|
+
// The Group menu's items alone: its own menu's, and the framed look's
|
|
100
|
+
// settings menu's second group.
|
|
101
|
+
function GroupMenuItems({ groupings, value, onValueChange }) {
|
|
99
102
|
const current = groupings.find((grouping) => grouping.id === value);
|
|
100
|
-
return (_jsxs(
|
|
103
|
+
return (_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)))] })] }));
|
|
101
104
|
}
|
|
105
|
+
function GroupMenu(props) {
|
|
106
|
+
const current = props.groupings.find((grouping) => grouping.id === props.value);
|
|
107
|
+
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: _jsx(GroupMenuItems, { ...props }) })] }));
|
|
108
|
+
}
|
|
109
|
+
// The framed look's one settings button (`look="framed"`): the Columns
|
|
110
|
+
// ticks, then Group By, in one menu, in place of the two buttons with
|
|
111
|
+
// words. Its name says what's set that the bar no longer shows ("Table
|
|
112
|
+
// Settings, Grouped by Status"), and a dot on it says so to the eye.
|
|
113
|
+
function TableSettingsMenu({ columns, grouping, changed, }) {
|
|
114
|
+
const current = grouping?.groupings.find((each) => each.id === grouping.value);
|
|
115
|
+
const label = current ? `Table Settings, Grouped by ${current.label}` : 'Table Settings';
|
|
116
|
+
return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(IconAction, { icon: Settings2Icon, label: label, size: "sm", "data-tool": "table-settings", "data-set": current || changed ? true : undefined, className: SETTINGS_DOT_CLASS }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-56", children: [columns ? _jsx(ColumnsMenuItems, { ...columns }) : null, columns && grouping ? _jsx(DropdownMenuSeparator, {}) : null, grouping ? _jsx(GroupMenuItems, { ...grouping }) : null] })] }));
|
|
117
|
+
}
|
|
118
|
+
// The dot on the settings button while something in it is set: the
|
|
119
|
+
// primary colour, ringed in the button's own background so it reads on
|
|
120
|
+
// either theme. Decoration: the button's name says it in words.
|
|
121
|
+
const SETTINGS_DOT_CLASS = 'relative data-set:after:absolute data-set:after:top-0.5 data-set:after:right-0.5 data-set:after:size-2 ' +
|
|
122
|
+
'data-set:after:rounded-full data-set:after:bg-primary data-set:after:ring-2 data-set:after:ring-background ' +
|
|
123
|
+
"data-set:after:content-['']";
|
|
124
|
+
// `look="framed"`: the card around the list, and its two bars. The card
|
|
125
|
+
// clips (never hides) its overflow, so the rounded corners hold and sticky
|
|
126
|
+
// headings still stick to the page.
|
|
127
|
+
const FRAME_CLASS = 'flex flex-col overflow-clip rounded-lg border border-border bg-background';
|
|
128
|
+
// The phone's row list inside the card: the card is its border.
|
|
129
|
+
const FRAMED_PHONE_ROWS_CLASS = '[&_[data-slot=data-table-phone-rows]_ul]:rounded-none [&_[data-slot=data-table-phone-rows]_ul]:border-0';
|
|
130
|
+
const FRAME_BAR_CLASS = 'flex flex-wrap items-center gap-x-4 gap-y-2 bg-card px-3 py-2.5 text-card-foreground max-md:gap-x-2';
|
|
102
131
|
// The rows-per-page menu in the pagination bar (`pageSizes`): a radio list
|
|
103
132
|
// that closes on a pick. The button says the size in words of its own
|
|
104
133
|
// ("50 rows", as the list page standard drew it), and the menu says
|
|
@@ -383,7 +412,7 @@ const ROW_ACTIONS_COLUMN = {
|
|
|
383
412
|
};
|
|
384
413
|
// The cell under the actions' column: as narrow as its button.
|
|
385
414
|
const ROW_ACTIONS_CELL_CLASS = 'w-px py-0';
|
|
386
|
-
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', views, activeView = null, onViewChange, viewsLabel = 'Views', columnsMenu, rowActions, phoneRow, limit, viewAll, }) {
|
|
415
|
+
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', views, activeView = null, onViewChange, viewsLabel = 'Views', columnsMenu, rowActions, phoneRow, limit, viewAll, look = 'plain', }) {
|
|
387
416
|
// The switch's own state, for a table that doesn't pass `layout`.
|
|
388
417
|
const [ownLayout, setOwnLayout] = useState('table');
|
|
389
418
|
const requestedLayout = layoutProp ?? ownLayout;
|
|
@@ -707,67 +736,99 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
|
|
|
707
736
|
const viewAllTotal = viewAll?.total ?? total;
|
|
708
737
|
// The row list a phone gets has no columns to pick.
|
|
709
738
|
const showColumnsMenu = Boolean(columnsMenu) && !showPhoneRows;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
739
|
+
// The pieces, placed as `look` says: plain, or a framed card.
|
|
740
|
+
const framed = look === 'framed';
|
|
741
|
+
const viewPills = (_jsx(_Fragment, { children: viewEntries.length > 0 ? (_jsx(ViewPills, { label: viewsLabel, views: viewEntries.map(([id, view]) => ({ id, label: view.label ?? id })), value: activeView, onValueChange: (id) => {
|
|
742
|
+
const view = views?.[id];
|
|
743
|
+
if (view)
|
|
744
|
+
onViewChange?.(view, id);
|
|
745
|
+
} })) : null }));
|
|
746
|
+
const foldAllButton = activeGrouping ? (_jsx(Button, { variant: "ghost", size: "sm", "data-slot": "data-table-fold-all", disabled: !runs?.length, onClick: foldAll, children: allFolded ? 'Unfold All' : 'Fold All' })) : null;
|
|
747
|
+
const columnsItems = showColumnsMenu
|
|
748
|
+
? {
|
|
749
|
+
columns: menuColumns,
|
|
750
|
+
visible: shownColumns ?? leafIds,
|
|
751
|
+
fixed: fixedColumns,
|
|
752
|
+
pick: columnsPick,
|
|
753
|
+
onPickChange: setColumnsPick,
|
|
754
|
+
setByView: viewColumns !== undefined,
|
|
755
|
+
}
|
|
756
|
+
: undefined;
|
|
757
|
+
const layoutSwitch = layouts?.length ? (_jsx(LayoutSwitch, { options: [
|
|
758
|
+
{ id: 'table', label: tableLayout?.label ?? 'Table', icon: tableLayout?.icon ?? TableIcon },
|
|
759
|
+
...layouts,
|
|
760
|
+
], value: currentLayout, onValueChange: setLayout })) : null;
|
|
761
|
+
const hasTools = Boolean(layouts?.length || groupings?.length || showColumnsMenu);
|
|
762
|
+
// `plain`: the toolbar, then the Columns and Group menus as buttons.
|
|
763
|
+
const plainToolbar = hasTools ? (_jsxs("div", { className: "flex flex-wrap items-end gap-x-4 gap-y-2", children: [_jsx("div", { className: "min-w-0 flex-1 basis-72", children: toolbar }), columnsItems ? _jsx(ColumnsMenu, { label: columnsMenu?.label, ...columnsItems }) : null, groupings?.length ? (_jsxs("div", { className: "flex items-center gap-2", children: [foldAllButton, _jsx(GroupMenu, { groupings: groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping })] })) : null, layoutSwitch] })) : (toolbar);
|
|
764
|
+
// `framed`: the card's top bar, one settings button in place of the two
|
|
765
|
+
// menus. Left out when there's nothing to put in it.
|
|
766
|
+
const framedToolbar = toolbar || hasTools ? (_jsxs("div", { "data-slot": "data-table-top-bar", className: cn(FRAME_BAR_CLASS, 'border-b border-border'), children: [_jsx("div", { className: "min-w-0 flex-1 basis-72 max-md:basis-0", children: toolbar }), hasTools ? (_jsxs("div", { className: "flex items-center gap-2", children: [foldAllButton, columnsItems || groupings?.length ? (_jsx(TableSettingsMenu, { columns: columnsItems, grouping: groupings?.length
|
|
767
|
+
? { groupings, value: activeGrouping?.id ?? '', onValueChange: setGrouping }
|
|
768
|
+
: undefined, changed: Boolean(columnsItems && (columnsPick || viewColumns !== undefined)) })) : null, layoutSwitch] })) : null] })) : null;
|
|
769
|
+
// Loading, empty or failed: in place of the rows.
|
|
770
|
+
const stateView = error ? (_jsx(ErrorState, { error: error, onRetry: onRetry })) : isLoading || isPastLastPage ? (cardLayout ? (_jsx(CardsSkeleton, { layout: cardLayout })) : showPhoneRows ? (_jsx(PhoneRowsSkeleton, {})) : (_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] })) : null;
|
|
771
|
+
const detailAside = !isSuccessView
|
|
772
|
+
? null
|
|
773
|
+
: (selectedRow && detailPanel && isWide ? (_jsxs("aside", { "aria-label": detailLabel, "data-slot": "data-table-detail", className: DETAIL_ASIDE_CLASS, onKeyDown: (event) => {
|
|
774
|
+
const target = event.target;
|
|
775
|
+
if (event.key !== 'Escape' || event.defaultPrevented || target.closest(TYPING_SELECTOR))
|
|
776
|
+
return;
|
|
777
|
+
event.preventDefault();
|
|
778
|
+
closeDetail();
|
|
779
|
+
}, 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);
|
|
780
|
+
const rowsView = (_jsxs(_Fragment, { children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons, onCardClick: onCardClick })) : showPhoneRows ? (_jsx("div", { "data-state": "success", "data-slot": "data-table-phone-rows", className: "flex flex-col gap-4", children: runs
|
|
781
|
+
? runs.map((run, runIndex) => {
|
|
782
|
+
const isFolded = folded.has(run.key);
|
|
783
|
+
return (_jsxs("section", { "data-slot": "table-group", "data-folded": isFolded || undefined, className: "flex flex-col gap-2", children: [_jsxs("h2", { "data-slot": "table-group-heading", className: "flex items-baseline gap-2 px-1", 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 }) }))] }), !isFolded && phoneList(run.rows)] }, `${runIndex}:${run.key}`));
|
|
784
|
+
})
|
|
785
|
+
: phoneList(rows) })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined, className: cn(stickyGroups && STICKY_FOCUS_CLASS), containerStyle: stickyGroups
|
|
786
|
+
? {
|
|
787
|
+
'--data-table-head-height': `${headHeight}px`,
|
|
788
|
+
'--data-table-sticky-top': stickyTop,
|
|
789
|
+
'--data-table-pin-top': scrollsSideways ? '0px' : stickyTop,
|
|
790
|
+
}
|
|
791
|
+
: undefined,
|
|
792
|
+
// With the sticky bar below as the visible scrollbar, hide the
|
|
793
|
+
// container's own. It stays overflow-x-auto and fully
|
|
794
|
+
// scrollable (wheel, trackpad, drag, and the sync effect); it
|
|
795
|
+
// just no longer draws a bar directly under the last row.
|
|
796
|
+
containerClassName: cn(
|
|
797
|
+
// A size container has no width of its own to give, so
|
|
798
|
+
// `width="content"` couldn't fit the table: there the
|
|
799
|
+
// pinned column's `cqw` measures the table's area
|
|
800
|
+
// (`@container/data-table`) instead.
|
|
801
|
+
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) => {
|
|
802
|
+
const canSort = header.column.getCanSort();
|
|
803
|
+
const sortDirection = header.column.getIsSorted();
|
|
804
|
+
// Hidden, a header is its name only: a sort button no
|
|
805
|
+
// one can see would still take focus.
|
|
806
|
+
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',
|
|
807
|
+
// The arrow on the label's left, so the label's
|
|
808
|
+
// right edge lines up with the numbers under it.
|
|
809
|
+
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()));
|
|
810
|
+
return (_jsx(TableHead, { className: cn(!showHeader && HIDDEN_HEAD_CLASS, pinFirstColumn && index === 0 && PINNED_COLUMN_CLASS, pinLast &&
|
|
811
|
+
index === headerGroup.headers.length - 1 &&
|
|
812
|
+
PINNED_LAST_COLUMN_CLASS, stickyGroups && showHeader && STICKY_HEAD_CELL_CLASS, alignClass(header.column.columnDef.meta?.align)), "aria-sort": !canSort
|
|
813
|
+
? undefined
|
|
814
|
+
: sortDirection === 'asc'
|
|
815
|
+
? 'ascending'
|
|
816
|
+
: sortDirection === 'desc'
|
|
817
|
+
? 'descending'
|
|
818
|
+
: '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));
|
|
819
|
+
}) }, headerGroup.id))) }), runs ? (runs.map((run, runIndex) => {
|
|
820
|
+
const isFolded = folded.has(run.key);
|
|
821
|
+
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}`));
|
|
822
|
+
})) : (_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) => {
|
|
823
|
+
const className = cn(pinFirstColumn && index === 0 && PINNED_TOTALS_LABEL_CLASS, pinLast && index === visibleColumnCount - 1 && PINNED_LAST_COLUMN_CLASS, alignClass(column.columnDef.meta?.align));
|
|
824
|
+
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));
|
|
825
|
+
}) }) }))] })), pinFirstColumn && isOverflowing && !cardLayout && !showPhoneRows && (_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 } }) })), viewAll && limit !== undefined && viewAllTotal > rows.length ? (_jsx(ViewAllLink, { viewAll: viewAll, total: viewAllTotal, navigator: navigation?.navigator })) : null] }));
|
|
826
|
+
const pagination = limit === undefined ? (_jsxs("div", { className: cn('flex flex-wrap items-center justify-between gap-x-4 gap-y-2', framed && [FRAME_BAR_CLASS, 'border-t border-border py-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, {}) })] })] })) : null;
|
|
827
|
+
// `width="content"`'s last width, kept while another state shows.
|
|
828
|
+
const lastWidthStyle = fitsColumns && !isSuccessView && lastWidth !== null
|
|
829
|
+
? { '--data-table-last-width': `${lastWidth}px` }
|
|
830
|
+
: undefined;
|
|
831
|
+
const content = framed ? (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-look": "framed", "data-layout": layouts?.length ? currentLayout : undefined, children: [viewPills, _jsx(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: _jsxs("div", { ref: body, "data-slot": "data-table-frame", className: cn(FRAME_CLASS, fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: [framedToolbar, _jsx("div", { "data-slot": "data-table-body", className: cn('flex flex-col gap-4', (stateView || cardLayout) && 'p-3', showPhoneRows && !stateView && FRAMED_PHONE_ROWS_CLASS), children: stateView ?? rowsView }), stateView ? null : pagination] }) })] })) : (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [viewPills, plainToolbar, _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: stateView ?? (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: [rowsView, pagination] })) })] }));
|
|
771
832
|
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs(RowActionsContext.Provider, { value: rowActions, 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) => {
|
|
772
833
|
if (!open)
|
|
773
834
|
setSelection(null);
|
|
@@ -10,6 +10,19 @@ export type ListHeaderAction = {
|
|
|
10
10
|
onSelect: () => void;
|
|
11
11
|
icon?: IconComponent;
|
|
12
12
|
};
|
|
13
|
+
/** One list in the `siblings` switch. */
|
|
14
|
+
export type ListHeaderSibling = {
|
|
15
|
+
label: string;
|
|
16
|
+
to: To;
|
|
17
|
+
/** How many records it holds, after its label. */
|
|
18
|
+
count?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Whether it's the list showing. Left out, it's the one whose path is
|
|
21
|
+
* the page's (react-router's NavLink, `end`), so set it for siblings
|
|
22
|
+
* told apart by their query string.
|
|
23
|
+
*/
|
|
24
|
+
current?: boolean;
|
|
25
|
+
};
|
|
13
26
|
export type ListHeaderProps = {
|
|
14
27
|
/** The list's name: the page's h1. */
|
|
15
28
|
title: string;
|
|
@@ -39,6 +52,13 @@ export type ListHeaderProps = {
|
|
|
39
52
|
onShownChange: (shown: boolean) => void;
|
|
40
53
|
noun?: string;
|
|
41
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Lists that are this one's peers (4.100): a switch beside the title,
|
|
57
|
+
* this list among them. Two or more; fewer draws nothing.
|
|
58
|
+
*/
|
|
59
|
+
siblings?: readonly ListHeaderSibling[];
|
|
60
|
+
/** The switch's landmark name: "<title> Lists" unless set. */
|
|
61
|
+
siblingsLabel?: string;
|
|
42
62
|
className?: string;
|
|
43
63
|
};
|
|
44
|
-
export declare function ListHeader({ title, count, links, newAction, more, deleted, className }: ListHeaderProps): import("react").JSX.Element;
|
|
64
|
+
export declare function ListHeader({ title, count, links, newAction, more, deleted, siblings, siblingsLabel, className, }: ListHeaderProps): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// A list page's header (list standard L12): the title with its count,
|
|
3
3
|
// the New button alone beside it, and everything else behind one ⋯ menu.
|
|
4
4
|
// The related screens (Board, Change log) stay out as buttons while
|
|
@@ -11,17 +11,36 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
// Holds no state: the app keeps `shown` (usually a URL filter). `links`
|
|
12
12
|
// are routes, `more` are the app's own actions. The ⋯ button has an
|
|
13
13
|
// accessible name and is left out when the menu would be empty.
|
|
14
|
+
//
|
|
15
|
+
// `siblings` (4.100) is a switch beside the title between lists that are
|
|
16
|
+
// one thing seen three ways (Exercises / Targets / Weak spots): links in a
|
|
17
|
+
// segmented row, the one on marked as the current page. They're the
|
|
18
|
+
// page's own peers, so they aren't in ⋯, which keeps only what's left
|
|
19
|
+
// (Show deleted). On a phone the switch takes its own line under the
|
|
20
|
+
// title and scrolls sideways if it must.
|
|
14
21
|
import { EllipsisIcon, PlusIcon, Trash2Icon } from 'lucide-react';
|
|
15
|
-
import { Link } from 'react-router';
|
|
22
|
+
import { Link, NavLink } from 'react-router';
|
|
16
23
|
import { cn } from 'cn';
|
|
17
24
|
import { Notice } from './notice.js';
|
|
18
25
|
import { Button } from '../ui/button.js';
|
|
19
26
|
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
20
|
-
|
|
27
|
+
// The switch: one bordered row, the current list filled. Each link is
|
|
28
|
+
// 32px tall (40 on a phone), its focus ring inside the row.
|
|
29
|
+
const SIBLING_CLASS = 'inline-flex min-h-8 shrink-0 items-center gap-1.5 border-r border-border px-3 type-body whitespace-nowrap ' +
|
|
30
|
+
'text-muted-foreground outline-none last:border-r-0 hover:bg-muted hover:text-foreground ' +
|
|
31
|
+
'focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset max-md:min-h-10 ' +
|
|
32
|
+
'aria-[current=page]:bg-muted aria-[current=page]:font-medium aria-[current=page]:text-foreground';
|
|
33
|
+
function SiblingSwitch({ siblings, label }) {
|
|
34
|
+
return (_jsx("nav", { "aria-label": label, "data-slot": "list-header-siblings", className: "max-w-full max-md:order-last max-md:basis-full max-md:overflow-x-auto", children: _jsx("div", { className: "inline-flex overflow-hidden rounded-md border border-border", children: siblings.map((sibling) => {
|
|
35
|
+
const inner = (_jsxs(_Fragment, { children: [sibling.label, sibling.count !== undefined && (_jsxs("span", { className: "tabular-nums", children: [_jsx("span", { className: "sr-only", children: ", " }), sibling.count] }))] }));
|
|
36
|
+
return sibling.current === undefined ? (_jsx(NavLink, { to: sibling.to, end: true, className: SIBLING_CLASS, children: inner }, sibling.label)) : (_jsx(Link, { to: sibling.to, "aria-current": sibling.current ? 'page' : undefined, className: SIBLING_CLASS, children: inner }, sibling.label));
|
|
37
|
+
}) }) }));
|
|
38
|
+
}
|
|
39
|
+
export function ListHeader({ title, count, links = [], newAction, more = [], deleted, siblings = [], siblingsLabel, className, }) {
|
|
21
40
|
// One link is a button of its own; two or more go in the menu.
|
|
22
41
|
const outLink = links.length === 1 ? links[0] : undefined;
|
|
23
42
|
const menuLinks = links.length > 1 ? links : [];
|
|
24
43
|
const hasMenu = menuLinks.length > 0 || more.length > 0 || deleted !== undefined;
|
|
25
|
-
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more" }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), newAction &&
|
|
44
|
+
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: "ml-auto flex flex-wrap items-center gap-2", children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more" }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), newAction &&
|
|
26
45
|
(newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the List" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
|
|
27
46
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { Artwork, ArtworkTag, ArtworkToggle, type ArtworkAspect, type ArtworkPro
|
|
|
9
9
|
export { ColorSwatch, type ColorSwatchProps } from './components/app/color-swatch.js';
|
|
10
10
|
export { storedColor } from './lib/stored-color.js';
|
|
11
11
|
export { CountLink, type CountLinkProps } from './components/app/count-link.js';
|
|
12
|
-
export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
|
|
12
|
+
export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableLook, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
|
|
13
13
|
export { type DataTableColumnsMenu, type DataTablePhoneRow, type DataTableRowAction, type DataTableView, type DataTableViewAll, } from './components/app/data-table-tools.js';
|
|
14
14
|
export { RelatedTable, type RelatedTableProps } from './components/app/related-table.js';
|
|
15
15
|
export { type RowGroup } from './components/app/table-groups.js';
|
|
@@ -74,7 +74,7 @@ export { AllowReminders, type AllowRemindersProps } from './components/app/allow
|
|
|
74
74
|
export { StageCircle, type StageCircleProps, type StageCircleStage, type StageCircleTone, } from './components/app/stage-circle.js';
|
|
75
75
|
export { Notice, type NoticeProps, type NoticeTone } from './components/app/notice.js';
|
|
76
76
|
export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
|
|
77
|
-
export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, } from './components/app/list-header.js';
|
|
77
|
+
export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, type ListHeaderSibling, } from './components/app/list-header.js';
|
|
78
78
|
export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
|
|
79
79
|
export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
|
|
80
80
|
export { NeedsYou, type NeedsYouItem, type NeedsYouProps, type NeedsYouTone } from './components/app/needs-you.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.100.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": {
|