@vendure-io/ui 3.0.0-next.4 → 3.0.0-next.5
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/package.json +12 -11
- package/src/components/atoms/alert-dialog.tsx +1 -4
- package/src/components/atoms/alert.tsx +59 -35
- package/src/components/atoms/badge.tsx +2 -2
- package/src/components/atoms/breadcrumb.tsx +124 -49
- package/src/components/atoms/button-group.tsx +1 -1
- package/src/components/atoms/button.tsx +2 -2
- package/src/components/atoms/calendar.tsx +2 -2
- package/src/components/atoms/card.tsx +15 -2
- package/src/components/atoms/chart.tsx +3 -3
- package/src/components/atoms/checkbox.tsx +1 -1
- package/src/components/atoms/combobox.tsx +37 -26
- package/src/components/atoms/command.tsx +3 -3
- package/src/components/atoms/context-menu.tsx +5 -5
- package/src/components/atoms/dialog.tsx +30 -14
- package/src/components/atoms/dropdown-menu.tsx +1 -1
- package/src/components/atoms/hover-card.tsx +1 -1
- package/src/components/atoms/input-group.tsx +30 -12
- package/src/components/atoms/input-otp.tsx +2 -2
- package/src/components/atoms/input.tsx +13 -3
- package/src/components/atoms/menubar.tsx +2 -2
- package/src/components/atoms/native-select.tsx +1 -1
- package/src/components/atoms/navigation-menu.tsx +3 -3
- package/src/components/atoms/pagination.tsx +9 -3
- package/src/components/atoms/popover.tsx +1 -1
- package/src/components/atoms/select.tsx +3 -3
- package/src/components/atoms/sheet.tsx +35 -15
- package/src/components/atoms/sidebar.tsx +200 -31
- package/src/components/atoms/skeleton.tsx +6 -3
- package/src/components/atoms/tabs.tsx +6 -2
- package/src/components/atoms/textarea.tsx +1 -1
- package/src/components/atoms/toggle.tsx +1 -1
- package/src/components/molecules/action-needed.tsx +483 -0
- package/src/components/molecules/anonymized-token.tsx +52 -8
- package/src/components/molecules/chip.tsx +37 -19
- package/src/components/molecules/choice-card.tsx +114 -9
- package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
- package/src/components/molecules/code-block/process-code.ts +1 -1
- package/src/components/molecules/code-block.tsx +58 -47
- package/src/components/molecules/combobox-free-text.tsx +75 -20
- package/src/components/molecules/confirm-dialog.tsx +11 -1
- package/src/components/molecules/copyable-text.tsx +10 -8
- package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
- package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
- package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
- package/src/components/molecules/data-table/data-table-types.tsx +123 -13
- package/src/components/molecules/data-table/data-table.tsx +109 -49
- package/src/components/molecules/data-table/table-pagination.tsx +96 -14
- package/src/components/molecules/date-picker.tsx +55 -24
- package/src/components/molecules/date-range-picker.tsx +54 -23
- package/src/components/molecules/date-time-picker.tsx +60 -24
- package/src/components/molecules/date-time.tsx +38 -3
- package/src/components/molecules/elapsed-time.tsx +61 -12
- package/src/components/molecules/file-dropzone.tsx +139 -39
- package/src/components/molecules/format-provider.tsx +14 -4
- package/src/components/molecules/id-chip-chrome.tsx +114 -0
- package/src/components/molecules/id-chip.tsx +3 -107
- package/src/components/molecules/issued-secret.tsx +1 -1
- package/src/components/molecules/live-indicator.tsx +1 -1
- package/src/components/molecules/money.tsx +44 -3
- package/src/components/molecules/multi-select.tsx +56 -14
- package/src/components/molecules/page-header.tsx +6 -2
- package/src/components/molecules/password-input.tsx +11 -10
- package/src/components/molecules/relative-time.tsx +88 -16
- package/src/components/molecules/search-trigger.tsx +5 -3
- package/src/components/molecules/secret-value.tsx +10 -2
- package/src/components/molecules/stat-card.tsx +143 -33
- package/src/components/molecules/state-views/empty-state.tsx +16 -12
- package/src/components/molecules/state-views/error-state.tsx +19 -15
- package/src/components/molecules/state-views/loading-state.tsx +16 -6
- package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
- package/src/components/molecules/status-badge.tsx +11 -35
- package/src/components/molecules/time-tooltip.tsx +55 -1
- package/src/hooks/use-copy.ts +3 -1
- package/src/lib/deprecated.ts +71 -0
- package/src/lib/field-surface.ts +7 -7
- package/src/lib/format-messages.ts +192 -0
- package/src/lib/highlight.ts +1 -1
- package/src/lib/menu-item.tsx +1 -1
- package/src/lib/tint-recipes.ts +10 -5
- package/src/lib/utils.ts +19 -1
- package/src/lib/dialog-padding.ts +0 -48
|
@@ -25,6 +25,38 @@ export interface DataTableColumnMeta {
|
|
|
25
25
|
* Logical, so it flips in right-to-left. Defaults to `'start'`.
|
|
26
26
|
*/
|
|
27
27
|
align?: 'start' | 'end';
|
|
28
|
+
/**
|
|
29
|
+
* The column's width: a number in px or a CSS length (`'8rem'`). The column
|
|
30
|
+
* has it while the skeleton shows and once the rows arrive, so the headers
|
|
31
|
+
* do not move when the data replaces the skeleton. Give one to each column
|
|
32
|
+
* whose content has a known width (a code, a status, a date, a total) and
|
|
33
|
+
* leave the widest text column without, so it takes the rest of the row.
|
|
34
|
+
* Wider content still widens the column (the table keeps its automatic
|
|
35
|
+
* layout). It is also the column's minimum: a table narrower than its
|
|
36
|
+
* columns scrolls sideways instead of squeezing them. TanStack's `size` is
|
|
37
|
+
* not read: TanStack gives every column a default `size`, so a set one can't
|
|
38
|
+
* be told from the default.
|
|
39
|
+
*/
|
|
40
|
+
width?: number | string;
|
|
41
|
+
/**
|
|
42
|
+
* The column's minimum width, for a text column without a `width`: it still
|
|
43
|
+
* takes the rest of the row, but never gets narrower than this, so in a
|
|
44
|
+
* narrow table it keeps a readable width and the same width while the
|
|
45
|
+
* skeleton shows and once the rows arrive.
|
|
46
|
+
*/
|
|
47
|
+
minWidth?: number | string;
|
|
48
|
+
/**
|
|
49
|
+
* The `--content-inset` of the column's cell content: how far it pulls back
|
|
50
|
+
* so its first letter lines up with the header. For a default-size
|
|
51
|
+
* StatusBadge: `'status-badge'` (chip with an icon), `'status-badge-dot'`
|
|
52
|
+
* (chip with a dot) or `'status-icon'` (`appearance="icon"`). Otherwise a
|
|
53
|
+
* number in px or a CSS length. When the pull-back is wider than the cell's gutter, the column's
|
|
54
|
+
* header and cells indent by the rest. With this set, that indent applies in
|
|
55
|
+
* every state, so the header does not move when the rows replace the
|
|
56
|
+
* skeleton. Without it the table measures the indent from the loaded cells,
|
|
57
|
+
* so the header moves once they arrive.
|
|
58
|
+
*/
|
|
59
|
+
contentInset?: 'status-badge' | 'status-badge-dot' | 'status-icon' | number | string;
|
|
28
60
|
}
|
|
29
61
|
|
|
30
62
|
// Pure type module for the DataTable molecule. Kept runtime-free so it can be
|
|
@@ -35,12 +67,22 @@ export interface DataTableColumnMeta {
|
|
|
35
67
|
/**
|
|
36
68
|
* Controlled OR uncontrolled, per capability. `value` present → controlled: the
|
|
37
69
|
* prop is the source of truth on every render (no internal seeding). `defaultValue`
|
|
38
|
-
* → uncontrolled: the core seeds its own state and `
|
|
39
|
-
* observes.
|
|
70
|
+
* → uncontrolled: the core seeds its own state and `onValueChange` (if given)
|
|
71
|
+
* only observes. `onValueChange` always gets the next value, never an updater
|
|
72
|
+
* function. Never mix `value` with `defaultValue`.
|
|
40
73
|
*/
|
|
41
|
-
export type ControlledState<T> =
|
|
42
|
-
| { value: T;
|
|
43
|
-
| { value?:
|
|
74
|
+
export type ControlledState<T> = (
|
|
75
|
+
| { value: T; onValueChange: (value: T) => void; defaultValue?: never }
|
|
76
|
+
| { value: T; onValueChange?: (value: T) => void; onChange: OnChangeFn<T>; defaultValue?: never }
|
|
77
|
+
| { value?: never; onValueChange?: (value: T) => void; defaultValue?: T }
|
|
78
|
+
) & {
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `onValueChange`, which gets the next value. `onChange`
|
|
81
|
+
* gets TanStack's updater (the next value or a function of the previous
|
|
82
|
+
* one). When both are set, only `onValueChange` is called. Removed in 4.0.
|
|
83
|
+
*/
|
|
84
|
+
onChange?: OnChangeFn<T>;
|
|
85
|
+
};
|
|
44
86
|
|
|
45
87
|
/* --- capability configs; PRESENCE of the config is the only feature switch --- */
|
|
46
88
|
|
|
@@ -68,11 +110,9 @@ export type DataTableRowSelection<TData> = ControlledState<RowSelectionState> &
|
|
|
68
110
|
* controlled via `page`/`onPageChange` — no `defaultValue` branch, because page
|
|
69
111
|
* is typically URL-owned.
|
|
70
112
|
*/
|
|
71
|
-
|
|
72
|
-
mode?: 'server' | 'client'; // default 'server'
|
|
113
|
+
interface DataTablePaginationBase {
|
|
73
114
|
page: number; // 1-based
|
|
74
115
|
pageSize: number;
|
|
75
|
-
totalItems?: number; // required in server mode
|
|
76
116
|
onPageChange: (page: number) => void;
|
|
77
117
|
onPageSizeChange?: (size: number) => void; // presence renders the size selector
|
|
78
118
|
pageSizeOptions?: number[]; // default [10, 25, 50, 100]
|
|
@@ -80,6 +120,24 @@ export interface DataTablePagination {
|
|
|
80
120
|
formatRange?: (range: { start: number; end: number; total: number }) => string;
|
|
81
121
|
}
|
|
82
122
|
|
|
123
|
+
/** The server pages, sorts and filters. The table shows one page of `rows`. */
|
|
124
|
+
export interface DataTableServerPagination extends DataTablePaginationBase {
|
|
125
|
+
mode?: 'server';
|
|
126
|
+
/**
|
|
127
|
+
* The number of rows on all pages. `null` or `undefined` while it is not
|
|
128
|
+
* known (the first page has not loaded yet): the footer range is a skeleton
|
|
129
|
+
* until then. Do not pass 0 for "not known": 0 means the list is empty.
|
|
130
|
+
*/
|
|
131
|
+
totalItems: number | null | undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `rows` is the full set. The table pages it. */
|
|
135
|
+
export interface DataTableClientPagination extends DataTablePaginationBase {
|
|
136
|
+
mode: 'client';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type DataTablePagination = DataTableServerPagination | DataTableClientPagination;
|
|
140
|
+
|
|
83
141
|
/**
|
|
84
142
|
* Open operator vocabulary — the core never interprets it; it only stores it in
|
|
85
143
|
* `ColumnFiltersState` and renders chips. Matches the donor's `{ [operator]: value }`.
|
|
@@ -268,6 +326,11 @@ export interface DataTableLabels {
|
|
|
268
326
|
columnsTrigger?: string; // 'Columns'
|
|
269
327
|
columnsHeading?: string; // 'Toggle columns'
|
|
270
328
|
addFilter?: string; // 'Add filter'
|
|
329
|
+
/**
|
|
330
|
+
* Placeholder and accessible name of the filter editor's default value input.
|
|
331
|
+
* @default `messages.dataTable.filterValue`, "Value"
|
|
332
|
+
*/
|
|
333
|
+
filterValue?: string;
|
|
271
334
|
clearFilters?: string; // 'Clear filters'
|
|
272
335
|
removeFilter?: (columnLabel: string) => string; // (l) => `Remove ${l} filter`
|
|
273
336
|
sortLabel?: (columnLabel: string) => string; // (c) => `Sort by ${c}`
|
|
@@ -282,14 +345,53 @@ export interface DataTableLabels {
|
|
|
282
345
|
}
|
|
283
346
|
|
|
284
347
|
export interface DataTableProps<TData> {
|
|
285
|
-
|
|
348
|
+
/**
|
|
349
|
+
* The current page (server) or the full set (client). The core never
|
|
350
|
+
* fetches. `undefined` until the first load finishes: the body shows
|
|
351
|
+
* skeleton rows. `[]` is a loaded empty list and shows the empty state, also
|
|
352
|
+
* while a new load runs. Do not pass `[]` for "not loaded".
|
|
353
|
+
*/
|
|
354
|
+
rows: TData[] | undefined;
|
|
355
|
+
/**
|
|
356
|
+
* THE cell/header seam. `meta` is passed through; the DataTable reads
|
|
357
|
+
* `meta.align` and `meta.width` (see `DataTableColumnMeta`).
|
|
358
|
+
*/
|
|
286
359
|
// biome-ignore lint/suspicious/noExplicitAny: matches TanStack's ColumnDef value-type convention
|
|
287
|
-
columns: ColumnDef<TData, any>[];
|
|
360
|
+
columns: ColumnDef<TData, any>[];
|
|
288
361
|
/** TanStack getRowId. Required with server pagination + rowSelection. */
|
|
289
362
|
getRowId?: (row: TData, index: number) => string;
|
|
290
363
|
|
|
291
|
-
|
|
292
|
-
|
|
364
|
+
/**
|
|
365
|
+
* A load is running. With `rows` loaded (a page, sort or filter change that
|
|
366
|
+
* keeps the previous rows, or the empty state) they stay: the body is
|
|
367
|
+
* `aria-busy`, the rows and the footer range dim after a short delay, and
|
|
368
|
+
* prev/next ignore presses. Never blanks loaded rows. Before the first load
|
|
369
|
+
* (`rows` is `undefined`) the body shows skeleton rows with or without it.
|
|
370
|
+
*/
|
|
371
|
+
isLoading?: boolean;
|
|
372
|
+
/**
|
|
373
|
+
* Skeleton rows before the first load of a table without `pagination`.
|
|
374
|
+
* Default 10. With `pagination` the count comes from the page size (and
|
|
375
|
+
* `expectedTotal`), so this prop is not used.
|
|
376
|
+
*/
|
|
377
|
+
skeletonRowCount?: number;
|
|
378
|
+
/**
|
|
379
|
+
* The list's total row count (all pages) from an earlier visit, while the
|
|
380
|
+
* rows are not loaded yet. The first load then draws as many skeleton rows
|
|
381
|
+
* as the current page will have: the page size, fewer on a short last page,
|
|
382
|
+
* so the table does not change height when the rows arrive. A page that will
|
|
383
|
+
* be empty renders the empty state (`emptyState` or "No results") hidden and
|
|
384
|
+
* inert instead, so the body has its exact height.
|
|
385
|
+
*
|
|
386
|
+
* - Only the skeleton row count uses it. The footer never shows it: it can
|
|
387
|
+
* be out of date.
|
|
388
|
+
* - Without it a paginated table draws one full page, any other table
|
|
389
|
+
* `skeletonRowCount`.
|
|
390
|
+
*
|
|
391
|
+
* `useRememberedListTotal` keeps the total in local storage. Any other store
|
|
392
|
+
* works too.
|
|
393
|
+
*/
|
|
394
|
+
expectedTotal?: number | null;
|
|
293
395
|
/**
|
|
294
396
|
* Per-column loading cells, keyed by column id, for cells that are not one
|
|
295
397
|
* text line tall (a title over a muted sub-line, an avatar, a button), so the
|
|
@@ -319,7 +421,7 @@ export interface DataTableProps<TData> {
|
|
|
319
421
|
* reload and a visit to another page in the same tab. Needs `rowSelection`.
|
|
320
422
|
*
|
|
321
423
|
* - On the first load the table restores the ids stored under the key and
|
|
322
|
-
* reports them through `rowSelection.
|
|
424
|
+
* reports them through `rowSelection.onValueChange`.
|
|
323
425
|
* - Every change is stored, with the ids of rows on other pages: a selection
|
|
324
426
|
* can span pages. An empty selection removes the entry.
|
|
325
427
|
* - A new key switches to the selection stored under it, or to none. Nothing
|
|
@@ -460,6 +562,14 @@ export interface DataTableProps<TData> {
|
|
|
460
562
|
* item.
|
|
461
563
|
*/
|
|
462
564
|
pinFirstColumn?: boolean;
|
|
565
|
+
/**
|
|
566
|
+
* The rows open an item through `DataTableRowLink`. The table then keeps the
|
|
567
|
+
* row chevron's slot after the last column in every state: while the
|
|
568
|
+
* skeleton shows, when empty and with rows. Without it the slot appears only
|
|
569
|
+
* once a row with a link renders, so on the first load every column moves
|
|
570
|
+
* sideways by the slot's width when the rows arrive.
|
|
571
|
+
*/
|
|
572
|
+
rowLinks?: boolean;
|
|
463
573
|
/**
|
|
464
574
|
* Extra `<TableRow>`s appended inside `TableBody` after the data rows — e.g.
|
|
465
575
|
* an order table's subtotal/shipping/total rows. Rendered only alongside
|
|
@@ -41,23 +41,17 @@ import {
|
|
|
41
41
|
TableRow,
|
|
42
42
|
} from '@vendure-io/ui/components/atoms/table';
|
|
43
43
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
|
|
44
|
-
import {
|
|
45
|
-
DataTableBulkActions,
|
|
46
|
-
useSelectionCache,
|
|
47
|
-
} from '@vendure-io/ui/components/molecules/data-table/data-table-bulk-actions';
|
|
48
44
|
import { DataTableColumnHeader } from '@vendure-io/ui/components/molecules/data-table/data-table-column-header';
|
|
49
45
|
import {
|
|
50
46
|
DataTableAddFilter,
|
|
51
47
|
DataTableAppliedFilters,
|
|
52
48
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-filters';
|
|
53
49
|
import type {
|
|
54
|
-
ControlledState,
|
|
55
50
|
DataTableProps,
|
|
56
51
|
DataTableRowCellProps,
|
|
57
52
|
DataTableRowRipple,
|
|
58
53
|
DataTableRowSelectProps,
|
|
59
54
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-types';
|
|
60
|
-
import { DataTableViewOptions } from '@vendure-io/ui/components/molecules/data-table/data-table-view-options';
|
|
61
55
|
import {
|
|
62
56
|
ListHeader,
|
|
63
57
|
ListHeaderChips,
|
|
@@ -72,22 +66,38 @@ import { AnimatePresence, MotionConfig, motion, useReducedMotion } from 'motion/
|
|
|
72
66
|
import * as React from 'react';
|
|
73
67
|
import { createPortal } from 'react-dom';
|
|
74
68
|
import { isDevelopment } from '../../../lib/env.ts';
|
|
69
|
+
import { DataTableBulkActions, useSelectionCache } from './data-table-bulk-actions.tsx';
|
|
75
70
|
// Relative: `data-table-helpers` is closed in the package exports.
|
|
76
71
|
import {
|
|
77
72
|
buildDisplayColumns,
|
|
78
73
|
columnAlign,
|
|
74
|
+
columnContentIndent,
|
|
75
|
+
columnMinWidth,
|
|
76
|
+
columnWidth,
|
|
79
77
|
getSelectedRowIds,
|
|
80
78
|
measureColumnIndents,
|
|
79
|
+
PENDING_CLASS,
|
|
81
80
|
resolveClearFilters,
|
|
82
81
|
resolveSlot,
|
|
83
82
|
sameIndents,
|
|
83
|
+
useControlledTableState,
|
|
84
|
+
warnOnChange,
|
|
84
85
|
} from './data-table-helpers.tsx';
|
|
86
|
+
// Relative: `data-table-row-count-storage` is closed in the package exports.
|
|
87
|
+
import { skeletonRowCountFor, useRememberedListTotal } from './data-table-row-count-storage.tsx';
|
|
85
88
|
// Relative: `data-table-selection-storage` is closed in the package exports.
|
|
86
89
|
import { useSelectionStorage } from './data-table-selection-storage.tsx';
|
|
90
|
+
import { DataTableViewOptions } from './data-table-view-options.tsx';
|
|
87
91
|
|
|
88
92
|
// Id of the generated row-actions column. Public: it is the `skeletonCells` key
|
|
89
93
|
// for the actions cell.
|
|
90
94
|
const ACTIONS_COLUMN_ID = 'actions';
|
|
95
|
+
// The table's data before the first load. One array, so TanStack's row model
|
|
96
|
+
// does not rebuild on every render.
|
|
97
|
+
const NO_ROWS: never[] = [];
|
|
98
|
+
|
|
99
|
+
// The built-in empty-state cell.
|
|
100
|
+
const EMPTY_CELL_CLASS = 'text-muted-foreground h-24 text-center';
|
|
91
101
|
|
|
92
102
|
// The row link is a stretched link, like ListRowLink: one real link per row,
|
|
93
103
|
// whose ::after covers the row (the row is `relative`), so a click on any point
|
|
@@ -130,9 +140,11 @@ const LINKED_ROW_CLASS = cn(
|
|
|
130
140
|
// cell of every row, header included, so the chevron never covers a cell and
|
|
131
141
|
// a row without a link lines up with the others. The chevron is 15px and sits
|
|
132
142
|
// one 12px gap after the last cell, like ListRowChevron. Important: CardTable
|
|
133
|
-
// sets the edge padding with a descendant rule.
|
|
143
|
+
// sets the edge padding with a descendant rule. `rowLinks` (`data-row-links`)
|
|
144
|
+
// keeps the slot in every state, also while skeleton or empty rows have no
|
|
145
|
+
// link to find, so the columns do not move when the linked rows arrive.
|
|
134
146
|
const ROW_CHEVRON_SLOT_CLASS =
|
|
135
|
-
'[&:has([data-slot=data-table-row-link])_tr>*:last-child]:pe-[calc(var(--card-px)+--spacing(7))]!';
|
|
147
|
+
'[&:has([data-slot=data-table-row-link])_tr>*:last-child]:pe-[calc(var(--card-px)+--spacing(7))]! [&[data-row-links]_tr>*:last-child]:pe-[calc(var(--card-px)+--spacing(7))]!';
|
|
136
148
|
|
|
137
149
|
// Pinned (`pinFirstColumn`): a pinned cell is positioned, so it becomes the
|
|
138
150
|
// containing block of the link's stretched ::after. A link in the pinned cell
|
|
@@ -340,30 +352,6 @@ function DataTableRowLink({
|
|
|
340
352
|
// placeholders. Only this folder imports TanStack; the composed
|
|
341
353
|
// ListHeader/TablePagination/Chip primitives stay TanStack-free.
|
|
342
354
|
|
|
343
|
-
/**
|
|
344
|
-
* Bridge a capability config to a `[value, onChange]` pair TanStack can consume
|
|
345
|
-
* as fully controlled. Controlled configs (`value`) are the source of truth every
|
|
346
|
-
* render; uncontrolled configs (`defaultValue` or nothing) get internal state the
|
|
347
|
-
* core owns, with any `onChange` observing. This fixes the donor's seed-then-emit
|
|
348
|
-
* bug: the prop, not a one-time seed, drives every render.
|
|
349
|
-
*/
|
|
350
|
-
function useControlledTableState<T>(
|
|
351
|
-
config: ControlledState<T> | undefined,
|
|
352
|
-
fallback: T,
|
|
353
|
-
): readonly [T, OnChangeFn<T>] {
|
|
354
|
-
const controlled = config?.value !== undefined;
|
|
355
|
-
const [internal, setInternal] = React.useState<T>(config?.defaultValue ?? fallback);
|
|
356
|
-
const value = controlled ? (config?.value as T) : internal;
|
|
357
|
-
const onChange = React.useCallback<OnChangeFn<T>>(
|
|
358
|
-
(updater) => {
|
|
359
|
-
if (!controlled) setInternal((old) => functionalUpdate(updater, old));
|
|
360
|
-
config?.onChange?.(updater);
|
|
361
|
-
},
|
|
362
|
-
[controlled, config],
|
|
363
|
-
);
|
|
364
|
-
return [value, onChange] as const;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
355
|
/** A string label for a column, from a string `header`, else the column id. */
|
|
368
356
|
function headerLabelText<TData>(column: Column<TData, unknown>): string {
|
|
369
357
|
const header = column.columnDef.header;
|
|
@@ -723,6 +711,7 @@ function DataTable<TData>({
|
|
|
723
711
|
isLoading,
|
|
724
712
|
skeletonRowCount = 10,
|
|
725
713
|
skeletonCells,
|
|
714
|
+
expectedTotal,
|
|
726
715
|
pagination,
|
|
727
716
|
sorting,
|
|
728
717
|
filters,
|
|
@@ -740,6 +729,7 @@ function DataTable<TData>({
|
|
|
740
729
|
onTableReady,
|
|
741
730
|
frame = 'card',
|
|
742
731
|
pinFirstColumn = false,
|
|
732
|
+
rowLinks = false,
|
|
743
733
|
footerRows,
|
|
744
734
|
labels,
|
|
745
735
|
className,
|
|
@@ -760,6 +750,32 @@ function DataTable<TData>({
|
|
|
760
750
|
);
|
|
761
751
|
}
|
|
762
752
|
|
|
753
|
+
// Before the first load (`rows` undefined) the body shows skeleton rows. A
|
|
754
|
+
// load with rows loaded (a page, sort or filter change, or a refetch of an
|
|
755
|
+
// empty list) is pending instead: the rows or the empty state stay and dim
|
|
756
|
+
// after a short delay.
|
|
757
|
+
const firstLoad = rows === undefined;
|
|
758
|
+
const pending = Boolean(isLoading) && !firstLoad;
|
|
759
|
+
const serverTotal =
|
|
760
|
+
pagination != null && pagination.mode !== 'client' ? pagination.totalItems : undefined;
|
|
761
|
+
const serverTotalUnknown =
|
|
762
|
+
pagination != null && pagination.mode !== 'client' && serverTotal == null;
|
|
763
|
+
|
|
764
|
+
const warnedUnknownTotal = React.useRef(false);
|
|
765
|
+
if (
|
|
766
|
+
isDevelopment &&
|
|
767
|
+
serverTotalUnknown &&
|
|
768
|
+
!firstLoad &&
|
|
769
|
+
!isLoading &&
|
|
770
|
+
!warnedUnknownTotal.current
|
|
771
|
+
) {
|
|
772
|
+
warnedUnknownTotal.current = true;
|
|
773
|
+
console.warn(
|
|
774
|
+
'[DataTable] The rows have loaded but pagination.totalItems is not known (null or undefined). ' +
|
|
775
|
+
'Pass the total with the rows: the footer range stays a skeleton until then.',
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
|
|
763
779
|
// Resolve labels once per `labels` identity.
|
|
764
780
|
const l = React.useMemo(
|
|
765
781
|
() => ({
|
|
@@ -782,6 +798,10 @@ function DataTable<TData>({
|
|
|
782
798
|
[labels],
|
|
783
799
|
);
|
|
784
800
|
|
|
801
|
+
warnOnChange(sorting, 'sorting');
|
|
802
|
+
warnOnChange(filters, 'filters');
|
|
803
|
+
warnOnChange(columnVisibility, 'columnVisibility');
|
|
804
|
+
warnOnChange(rowSelection, 'rowSelection');
|
|
785
805
|
const [sortingState, onSortingChange] = useControlledTableState<SortingState>(sorting, []);
|
|
786
806
|
const [filtersState, onColumnFiltersChange] = useControlledTableState<ColumnFiltersState>(
|
|
787
807
|
filters,
|
|
@@ -951,7 +971,7 @@ function DataTable<TData>({
|
|
|
951
971
|
};
|
|
952
972
|
|
|
953
973
|
const baseOptions: TableOptions<TData> = {
|
|
954
|
-
data: rows,
|
|
974
|
+
data: rows ?? NO_ROWS,
|
|
955
975
|
columns: displayColumns,
|
|
956
976
|
state,
|
|
957
977
|
getRowId,
|
|
@@ -962,7 +982,7 @@ function DataTable<TData>({
|
|
|
962
982
|
manualSorting: sorting ? sorting.mode !== 'client' : undefined,
|
|
963
983
|
manualFiltering: filters ? filters.mode !== 'client' : undefined,
|
|
964
984
|
manualPagination: pagination ? pagination.mode !== 'client' : undefined,
|
|
965
|
-
rowCount:
|
|
985
|
+
rowCount: serverTotal ?? undefined,
|
|
966
986
|
};
|
|
967
987
|
|
|
968
988
|
if (sorting) {
|
|
@@ -999,6 +1019,8 @@ function DataTable<TData>({
|
|
|
999
1019
|
|
|
1000
1020
|
const bodyRows = table.getRowModel().rows;
|
|
1001
1021
|
const columnCount = table.getVisibleLeafColumns().length;
|
|
1022
|
+
// The first load draws as many skeleton rows as the current page will have.
|
|
1023
|
+
const skeletonRows = skeletonRowCountFor(expectedTotal ?? null, pagination, skeletonRowCount);
|
|
1002
1024
|
|
|
1003
1025
|
// The select checkbox is floated absolutely over a zero-width cell, so the
|
|
1004
1026
|
// gutter it needs is folded into the leading data column as left padding —
|
|
@@ -1089,9 +1111,22 @@ function DataTable<TData>({
|
|
|
1089
1111
|
generatedColumn(columnId) === 'select' && leadingColumnId != null
|
|
1090
1112
|
? leadingColumnId
|
|
1091
1113
|
: columnId;
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1114
|
+
// A declared inset (`meta.contentInset`) indents the column the same in
|
|
1115
|
+
// every state; the measured indent is the fallback.
|
|
1116
|
+
const declared = columnContentIndent(table.getColumn(id)?.columnDef.meta);
|
|
1117
|
+
const indent = declared ?? (columnIndents[id] ? `${columnIndents[id]}px` : undefined);
|
|
1118
|
+
return indent ? ({ '--column-indent': indent } as React.CSSProperties) : undefined;
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
// A column's `meta.width` is set on its header cell, so the column has that
|
|
1122
|
+
// width while the skeleton shows and once the rows arrive (the table keeps
|
|
1123
|
+
// its automatic layout: wider content still widens it).
|
|
1124
|
+
// biome-ignore lint/suspicious/noExplicitAny: matches TanStack's ColumnDef value-type convention
|
|
1125
|
+
const headerCellStyle = (column: Column<TData, any>): React.CSSProperties | undefined => {
|
|
1126
|
+
const indent = columnIndentStyle(column.id);
|
|
1127
|
+
const width = columnWidth(column.columnDef.meta);
|
|
1128
|
+
const minWidth = columnMinWidth(column.columnDef.meta);
|
|
1129
|
+
return width == null && minWidth == null ? indent : { ...indent, width, minWidth };
|
|
1095
1130
|
};
|
|
1096
1131
|
|
|
1097
1132
|
// What a built-in body cell of this column carries. Handed to `renderRow` as
|
|
@@ -1172,7 +1207,7 @@ function DataTable<TData>({
|
|
|
1172
1207
|
const clearFilters = resolveClearFilters(
|
|
1173
1208
|
filters?.clearFilters,
|
|
1174
1209
|
table,
|
|
1175
|
-
!
|
|
1210
|
+
!firstLoad && bodyRows.length === 0,
|
|
1176
1211
|
);
|
|
1177
1212
|
// The bulk bar exists only while rows are selected. It takes the controls
|
|
1178
1213
|
// row's place, or, with no controls row, covers the column header row (see
|
|
@@ -1286,6 +1321,7 @@ function DataTable<TData>({
|
|
|
1286
1321
|
table={table}
|
|
1287
1322
|
columns={filters.columns}
|
|
1288
1323
|
label={l.addFilter}
|
|
1324
|
+
valueLabel={labels?.filterValue}
|
|
1289
1325
|
/>
|
|
1290
1326
|
)}
|
|
1291
1327
|
{showViewOptions && (
|
|
@@ -1374,6 +1410,7 @@ function DataTable<TData>({
|
|
|
1374
1410
|
pinFirstColumn={pinFirstColumn}
|
|
1375
1411
|
className={cn(LINKED_ROW_CLASS, ROW_CHEVRON_SLOT_CLASS, SELECT_RIPPLE_TABLE_CLASS)}
|
|
1376
1412
|
data-selecting={selecting ? '' : undefined}
|
|
1413
|
+
data-row-links={rowLinks ? '' : undefined}
|
|
1377
1414
|
data-bulk-over-header={bulkOverHeader && showBulk ? '' : undefined}
|
|
1378
1415
|
>
|
|
1379
1416
|
<TableHeader>
|
|
@@ -1394,7 +1431,7 @@ function DataTable<TData>({
|
|
|
1394
1431
|
generatedColumn(headerCell.column.id) !== 'select' &&
|
|
1395
1432
|
HEADER_LABEL_UNDER_BULK_CLASS,
|
|
1396
1433
|
)}
|
|
1397
|
-
style={
|
|
1434
|
+
style={headerCellStyle(headerCell.column)}
|
|
1398
1435
|
>
|
|
1399
1436
|
{sorting != null && !headerCell.isPlaceholder ? (
|
|
1400
1437
|
<DataTableColumnHeader
|
|
@@ -1413,9 +1450,13 @@ function DataTable<TData>({
|
|
|
1413
1450
|
</TableRow>
|
|
1414
1451
|
))}
|
|
1415
1452
|
</TableHeader>
|
|
1416
|
-
<TableBody
|
|
1417
|
-
{isLoading
|
|
1418
|
-
|
|
1453
|
+
<TableBody
|
|
1454
|
+
aria-busy={isLoading || firstLoad ? true : undefined}
|
|
1455
|
+
data-pending={pending ? '' : undefined}
|
|
1456
|
+
className={PENDING_CLASS}
|
|
1457
|
+
>
|
|
1458
|
+
{firstLoad && skeletonRows > 0 ? (
|
|
1459
|
+
Array.from({ length: skeletonRows }).map((_, rowIndex) => (
|
|
1419
1460
|
<TableRow key={`skeleton-${rowIndex}`}>
|
|
1420
1461
|
{columnCount === 0 ? (
|
|
1421
1462
|
<TableCell>
|
|
@@ -1437,11 +1478,17 @@ function DataTable<TData>({
|
|
|
1437
1478
|
</TableRow>
|
|
1438
1479
|
))
|
|
1439
1480
|
) : bodyRows.length === 0 ? (
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1481
|
+
// The empty state. Before the first load of a page that will be
|
|
1482
|
+
// empty (by the remembered total), it is already here but hidden
|
|
1483
|
+
// and inert, so the body has its exact height and the empty
|
|
1484
|
+
// result shows in place.
|
|
1485
|
+
<TableRow
|
|
1486
|
+
data-slot={firstLoad ? 'data-table-empty-placeholder' : undefined}
|
|
1487
|
+
aria-hidden={firstLoad ? true : undefined}
|
|
1488
|
+
inert={firstLoad ? true : undefined}
|
|
1489
|
+
className={cn('hover:bg-transparent', firstLoad && 'invisible')}
|
|
1490
|
+
>
|
|
1491
|
+
<TableCell colSpan={Math.max(columnCount, 1)} className={EMPTY_CELL_CLASS}>
|
|
1445
1492
|
{emptyState ?? l.empty}
|
|
1446
1493
|
</TableCell>
|
|
1447
1494
|
</TableRow>
|
|
@@ -1513,7 +1560,15 @@ function DataTable<TData>({
|
|
|
1513
1560
|
className="w-full"
|
|
1514
1561
|
page={pagination.page}
|
|
1515
1562
|
pageSize={pagination.pageSize}
|
|
1516
|
-
|
|
1563
|
+
// Unknown (null or undefined, or client rows not loaded): a skeleton, not "0 of 0".
|
|
1564
|
+
totalItems={
|
|
1565
|
+
pagination.mode === 'client'
|
|
1566
|
+
? firstLoad
|
|
1567
|
+
? undefined
|
|
1568
|
+
: table.getPrePaginationRowModel().rows.length
|
|
1569
|
+
: pagination.totalItems
|
|
1570
|
+
}
|
|
1571
|
+
isLoading={pending}
|
|
1517
1572
|
onPageChange={pagination.onPageChange}
|
|
1518
1573
|
onPageSizeChange={pagination.onPageSizeChange}
|
|
1519
1574
|
pageSizeOptions={pagination.pageSizeOptions}
|
|
@@ -1553,7 +1608,12 @@ function DataTable<TData>({
|
|
|
1553
1608
|
|
|
1554
1609
|
// `DataTableSkeletonLine` is the shared SkeletonLine under its old name, kept for
|
|
1555
1610
|
// consumers that stack it in `skeletonCells`.
|
|
1556
|
-
export {
|
|
1611
|
+
export {
|
|
1612
|
+
DataTable,
|
|
1613
|
+
DataTableRowLink,
|
|
1614
|
+
SkeletonLine as DataTableSkeletonLine,
|
|
1615
|
+
useRememberedListTotal,
|
|
1616
|
+
};
|
|
1557
1617
|
|
|
1558
1618
|
// Re-export the consumer-facing TanStack types so columns can be authored from
|
|
1559
1619
|
// the same import as `DataTable` — no direct `@tanstack/react-table` dependency
|