@vendure-io/ui 3.0.0-next.3 → 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.
Files changed (86) hide show
  1. package/package.json +12 -10
  2. package/src/components/atoms/alert-dialog.tsx +1 -4
  3. package/src/components/atoms/alert.tsx +59 -35
  4. package/src/components/atoms/badge.tsx +2 -2
  5. package/src/components/atoms/breadcrumb.tsx +124 -49
  6. package/src/components/atoms/button-group.tsx +1 -1
  7. package/src/components/atoms/button.tsx +4 -3
  8. package/src/components/atoms/calendar.tsx +2 -2
  9. package/src/components/atoms/card.tsx +15 -2
  10. package/src/components/atoms/chart.tsx +3 -3
  11. package/src/components/atoms/checkbox.tsx +1 -1
  12. package/src/components/atoms/combobox.tsx +37 -26
  13. package/src/components/atoms/command.tsx +3 -3
  14. package/src/components/atoms/context-menu.tsx +5 -5
  15. package/src/components/atoms/dialog.tsx +30 -14
  16. package/src/components/atoms/dropdown-menu.tsx +1 -1
  17. package/src/components/atoms/hover-card.tsx +1 -1
  18. package/src/components/atoms/input-group.tsx +30 -12
  19. package/src/components/atoms/input-otp.tsx +2 -2
  20. package/src/components/atoms/input.tsx +13 -3
  21. package/src/components/atoms/menubar.tsx +2 -2
  22. package/src/components/atoms/native-select.tsx +1 -1
  23. package/src/components/atoms/navigation-menu.tsx +3 -3
  24. package/src/components/atoms/pagination.tsx +9 -3
  25. package/src/components/atoms/popover.tsx +1 -1
  26. package/src/components/atoms/select.tsx +3 -3
  27. package/src/components/atoms/sheet.tsx +35 -15
  28. package/src/components/atoms/sidebar.tsx +200 -31
  29. package/src/components/atoms/skeleton.tsx +6 -3
  30. package/src/components/atoms/switch.tsx +1 -1
  31. package/src/components/atoms/tabs.tsx +6 -2
  32. package/src/components/atoms/textarea.tsx +1 -1
  33. package/src/components/atoms/toggle.tsx +1 -1
  34. package/src/components/molecules/action-needed.tsx +483 -0
  35. package/src/components/molecules/anonymized-token.tsx +52 -8
  36. package/src/components/molecules/chip.tsx +37 -18
  37. package/src/components/molecules/choice-card.tsx +114 -9
  38. package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
  39. package/src/components/molecules/code-block/process-code.ts +1 -1
  40. package/src/components/molecules/code-block.tsx +58 -47
  41. package/src/components/molecules/combobox-free-text.tsx +75 -20
  42. package/src/components/molecules/confirm-dialog.tsx +11 -1
  43. package/src/components/molecules/copyable-text.tsx +10 -8
  44. package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
  45. package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
  46. package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
  47. package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
  48. package/src/components/molecules/data-table/data-table-types.tsx +123 -13
  49. package/src/components/molecules/data-table/data-table.tsx +112 -55
  50. package/src/components/molecules/data-table/table-pagination.tsx +96 -14
  51. package/src/components/molecules/date-picker.tsx +55 -24
  52. package/src/components/molecules/date-range-picker.tsx +54 -23
  53. package/src/components/molecules/date-time-picker.tsx +60 -24
  54. package/src/components/molecules/date-time.tsx +38 -3
  55. package/src/components/molecules/elapsed-time.tsx +61 -12
  56. package/src/components/molecules/file-dropzone.tsx +139 -39
  57. package/src/components/molecules/format-provider.tsx +14 -4
  58. package/src/components/molecules/id-chip-chrome.tsx +114 -0
  59. package/src/components/molecules/id-chip.tsx +3 -107
  60. package/src/components/molecules/issued-secret.tsx +1 -1
  61. package/src/components/molecules/live-indicator.tsx +1 -1
  62. package/src/components/molecules/money.tsx +46 -4
  63. package/src/components/molecules/multi-select.tsx +58 -15
  64. package/src/components/molecules/page-header.tsx +6 -2
  65. package/src/components/molecules/password-input.tsx +11 -10
  66. package/src/components/molecules/relative-time.tsx +88 -16
  67. package/src/components/molecules/search-trigger.tsx +5 -3
  68. package/src/components/molecules/secret-value.tsx +10 -2
  69. package/src/components/molecules/stat-card.tsx +143 -33
  70. package/src/components/molecules/state-views/empty-state.tsx +16 -12
  71. package/src/components/molecules/state-views/error-state.tsx +19 -15
  72. package/src/components/molecules/state-views/loading-state.tsx +16 -6
  73. package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
  74. package/src/components/molecules/status-badge.tsx +11 -35
  75. package/src/components/molecules/time-tooltip.tsx +55 -1
  76. package/src/hooks/use-copy.ts +3 -1
  77. package/src/lib/deprecated.ts +71 -0
  78. package/src/lib/env.ts +9 -0
  79. package/src/lib/field-surface.ts +7 -7
  80. package/src/lib/format-messages.ts +192 -0
  81. package/src/lib/highlight.ts +1 -1
  82. package/src/lib/menu-item.tsx +1 -1
  83. package/src/lib/state-dictionary.ts +2 -3
  84. package/src/lib/tint-recipes.ts +10 -5
  85. package/src/lib/utils.ts +19 -1
  86. 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 `onChange` (if given) only
39
- * observes. Never mix `value` with `defaultValue`.
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; onChange: OnChangeFn<T>; defaultValue?: never }
43
- | { value?: never; onChange?: OnChangeFn<T>; defaultValue?: T };
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
- export interface DataTablePagination {
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
- rows: TData[]; // current page (server) or full set (client). The core never fetches.
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>[]; // `meta` passed through untouched. THE cell/header seam.
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
- isLoading?: boolean; // skeleton rows only while `rows` is empty; never blanks populated rows
292
- skeletonRowCount?: number; // default 10
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.onChange`.
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,
@@ -71,22 +65,39 @@ import { ChevronRight } from 'lucide-react';
71
65
  import { AnimatePresence, MotionConfig, motion, useReducedMotion } from 'motion/react';
72
66
  import * as React from 'react';
73
67
  import { createPortal } from 'react-dom';
68
+ import { isDevelopment } from '../../../lib/env.ts';
69
+ import { DataTableBulkActions, useSelectionCache } from './data-table-bulk-actions.tsx';
74
70
  // Relative: `data-table-helpers` is closed in the package exports.
75
71
  import {
76
72
  buildDisplayColumns,
77
73
  columnAlign,
74
+ columnContentIndent,
75
+ columnMinWidth,
76
+ columnWidth,
78
77
  getSelectedRowIds,
79
78
  measureColumnIndents,
79
+ PENDING_CLASS,
80
80
  resolveClearFilters,
81
81
  resolveSlot,
82
82
  sameIndents,
83
+ useControlledTableState,
84
+ warnOnChange,
83
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';
84
88
  // Relative: `data-table-selection-storage` is closed in the package exports.
85
89
  import { useSelectionStorage } from './data-table-selection-storage.tsx';
90
+ import { DataTableViewOptions } from './data-table-view-options.tsx';
86
91
 
87
92
  // Id of the generated row-actions column. Public: it is the `skeletonCells` key
88
93
  // for the actions cell.
89
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';
90
101
 
91
102
  // The row link is a stretched link, like ListRowLink: one real link per row,
92
103
  // whose ::after covers the row (the row is `relative`), so a click on any point
@@ -129,9 +140,11 @@ const LINKED_ROW_CLASS = cn(
129
140
  // cell of every row, header included, so the chevron never covers a cell and
130
141
  // a row without a link lines up with the others. The chevron is 15px and sits
131
142
  // one 12px gap after the last cell, like ListRowChevron. Important: CardTable
132
- // 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.
133
146
  const ROW_CHEVRON_SLOT_CLASS =
134
- '[&: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))]!';
135
148
 
136
149
  // Pinned (`pinFirstColumn`): a pinned cell is positioned, so it becomes the
137
150
  // containing block of the link's stretched ::after. A link in the pinned cell
@@ -339,30 +352,6 @@ function DataTableRowLink({
339
352
  // placeholders. Only this folder imports TanStack; the composed
340
353
  // ListHeader/TablePagination/Chip primitives stay TanStack-free.
341
354
 
342
- /**
343
- * Bridge a capability config to a `[value, onChange]` pair TanStack can consume
344
- * as fully controlled. Controlled configs (`value`) are the source of truth every
345
- * render; uncontrolled configs (`defaultValue` or nothing) get internal state the
346
- * core owns, with any `onChange` observing. This fixes the donor's seed-then-emit
347
- * bug: the prop, not a one-time seed, drives every render.
348
- */
349
- function useControlledTableState<T>(
350
- config: ControlledState<T> | undefined,
351
- fallback: T,
352
- ): readonly [T, OnChangeFn<T>] {
353
- const controlled = config?.value !== undefined;
354
- const [internal, setInternal] = React.useState<T>(config?.defaultValue ?? fallback);
355
- const value = controlled ? (config?.value as T) : internal;
356
- const onChange = React.useCallback<OnChangeFn<T>>(
357
- (updater) => {
358
- if (!controlled) setInternal((old) => functionalUpdate(updater, old));
359
- config?.onChange?.(updater);
360
- },
361
- [controlled, config],
362
- );
363
- return [value, onChange] as const;
364
- }
365
-
366
355
  /** A string label for a column, from a string `header`, else the column id. */
367
356
  function headerLabelText<TData>(column: Column<TData, unknown>): string {
368
357
  const header = column.columnDef.header;
@@ -722,6 +711,7 @@ function DataTable<TData>({
722
711
  isLoading,
723
712
  skeletonRowCount = 10,
724
713
  skeletonCells,
714
+ expectedTotal,
725
715
  pagination,
726
716
  sorting,
727
717
  filters,
@@ -739,13 +729,14 @@ function DataTable<TData>({
739
729
  onTableReady,
740
730
  frame = 'card',
741
731
  pinFirstColumn = false,
732
+ rowLinks = false,
742
733
  footerRows,
743
734
  labels,
744
735
  className,
745
736
  }: DataTableProps<TData>) {
746
737
  const warnedMissingPaginatedSelectionRowId = React.useRef(false);
747
738
  if (
748
- process.env.NODE_ENV !== 'production' &&
739
+ isDevelopment &&
749
740
  rowSelection != null &&
750
741
  pagination != null &&
751
742
  pagination.mode !== 'client' &&
@@ -759,6 +750,32 @@ function DataTable<TData>({
759
750
  );
760
751
  }
761
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
+
762
779
  // Resolve labels once per `labels` identity.
763
780
  const l = React.useMemo(
764
781
  () => ({
@@ -781,6 +798,10 @@ function DataTable<TData>({
781
798
  [labels],
782
799
  );
783
800
 
801
+ warnOnChange(sorting, 'sorting');
802
+ warnOnChange(filters, 'filters');
803
+ warnOnChange(columnVisibility, 'columnVisibility');
804
+ warnOnChange(rowSelection, 'rowSelection');
784
805
  const [sortingState, onSortingChange] = useControlledTableState<SortingState>(sorting, []);
785
806
  const [filtersState, onColumnFiltersChange] = useControlledTableState<ColumnFiltersState>(
786
807
  filters,
@@ -950,7 +971,7 @@ function DataTable<TData>({
950
971
  };
951
972
 
952
973
  const baseOptions: TableOptions<TData> = {
953
- data: rows,
974
+ data: rows ?? NO_ROWS,
954
975
  columns: displayColumns,
955
976
  state,
956
977
  getRowId,
@@ -961,7 +982,7 @@ function DataTable<TData>({
961
982
  manualSorting: sorting ? sorting.mode !== 'client' : undefined,
962
983
  manualFiltering: filters ? filters.mode !== 'client' : undefined,
963
984
  manualPagination: pagination ? pagination.mode !== 'client' : undefined,
964
- rowCount: pagination && pagination.mode !== 'client' ? pagination.totalItems : undefined,
985
+ rowCount: serverTotal ?? undefined,
965
986
  };
966
987
 
967
988
  if (sorting) {
@@ -998,6 +1019,8 @@ function DataTable<TData>({
998
1019
 
999
1020
  const bodyRows = table.getRowModel().rows;
1000
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);
1001
1024
 
1002
1025
  // The select checkbox is floated absolutely over a zero-width cell, so the
1003
1026
  // gutter it needs is folded into the leading data column as left padding —
@@ -1088,9 +1111,22 @@ function DataTable<TData>({
1088
1111
  generatedColumn(columnId) === 'select' && leadingColumnId != null
1089
1112
  ? leadingColumnId
1090
1113
  : columnId;
1091
- return columnIndents[id]
1092
- ? ({ '--column-indent': `${columnIndents[id]}px` } as React.CSSProperties)
1093
- : undefined;
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 };
1094
1130
  };
1095
1131
 
1096
1132
  // What a built-in body cell of this column carries. Handed to `renderRow` as
@@ -1137,11 +1173,7 @@ function DataTable<TData>({
1137
1173
  };
1138
1174
 
1139
1175
  const warnedUnknownSkeletonCells = React.useRef(false);
1140
- if (
1141
- process.env.NODE_ENV !== 'production' &&
1142
- skeletonCells != null &&
1143
- !warnedUnknownSkeletonCells.current
1144
- ) {
1176
+ if (isDevelopment && skeletonCells != null && !warnedUnknownSkeletonCells.current) {
1145
1177
  const knownIds = new Set(
1146
1178
  table
1147
1179
  .getAllLeafColumns()
@@ -1175,7 +1207,7 @@ function DataTable<TData>({
1175
1207
  const clearFilters = resolveClearFilters(
1176
1208
  filters?.clearFilters,
1177
1209
  table,
1178
- !(isLoading && rows.length === 0) && bodyRows.length === 0,
1210
+ !firstLoad && bodyRows.length === 0,
1179
1211
  );
1180
1212
  // The bulk bar exists only while rows are selected. It takes the controls
1181
1213
  // row's place, or, with no controls row, covers the column header row (see
@@ -1289,6 +1321,7 @@ function DataTable<TData>({
1289
1321
  table={table}
1290
1322
  columns={filters.columns}
1291
1323
  label={l.addFilter}
1324
+ valueLabel={labels?.filterValue}
1292
1325
  />
1293
1326
  )}
1294
1327
  {showViewOptions && (
@@ -1377,6 +1410,7 @@ function DataTable<TData>({
1377
1410
  pinFirstColumn={pinFirstColumn}
1378
1411
  className={cn(LINKED_ROW_CLASS, ROW_CHEVRON_SLOT_CLASS, SELECT_RIPPLE_TABLE_CLASS)}
1379
1412
  data-selecting={selecting ? '' : undefined}
1413
+ data-row-links={rowLinks ? '' : undefined}
1380
1414
  data-bulk-over-header={bulkOverHeader && showBulk ? '' : undefined}
1381
1415
  >
1382
1416
  <TableHeader>
@@ -1397,7 +1431,7 @@ function DataTable<TData>({
1397
1431
  generatedColumn(headerCell.column.id) !== 'select' &&
1398
1432
  HEADER_LABEL_UNDER_BULK_CLASS,
1399
1433
  )}
1400
- style={columnIndentStyle(headerCell.column.id)}
1434
+ style={headerCellStyle(headerCell.column)}
1401
1435
  >
1402
1436
  {sorting != null && !headerCell.isPlaceholder ? (
1403
1437
  <DataTableColumnHeader
@@ -1416,9 +1450,13 @@ function DataTable<TData>({
1416
1450
  </TableRow>
1417
1451
  ))}
1418
1452
  </TableHeader>
1419
- <TableBody>
1420
- {isLoading && rows.length === 0 ? (
1421
- Array.from({ length: skeletonRowCount }).map((_, rowIndex) => (
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) => (
1422
1460
  <TableRow key={`skeleton-${rowIndex}`}>
1423
1461
  {columnCount === 0 ? (
1424
1462
  <TableCell>
@@ -1440,11 +1478,17 @@ function DataTable<TData>({
1440
1478
  </TableRow>
1441
1479
  ))
1442
1480
  ) : bodyRows.length === 0 ? (
1443
- <TableRow className="hover:bg-transparent">
1444
- <TableCell
1445
- colSpan={Math.max(columnCount, 1)}
1446
- className="text-muted-foreground h-24 text-center"
1447
- >
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}>
1448
1492
  {emptyState ?? l.empty}
1449
1493
  </TableCell>
1450
1494
  </TableRow>
@@ -1516,7 +1560,15 @@ function DataTable<TData>({
1516
1560
  className="w-full"
1517
1561
  page={pagination.page}
1518
1562
  pageSize={pagination.pageSize}
1519
- totalItems={pagination.totalItems ?? table.getPrePaginationRowModel().rows.length}
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}
1520
1572
  onPageChange={pagination.onPageChange}
1521
1573
  onPageSizeChange={pagination.onPageSizeChange}
1522
1574
  pageSizeOptions={pagination.pageSizeOptions}
@@ -1556,7 +1608,12 @@ function DataTable<TData>({
1556
1608
 
1557
1609
  // `DataTableSkeletonLine` is the shared SkeletonLine under its old name, kept for
1558
1610
  // consumers that stack it in `skeletonCells`.
1559
- export { DataTable, DataTableRowLink, SkeletonLine as DataTableSkeletonLine };
1611
+ export {
1612
+ DataTable,
1613
+ DataTableRowLink,
1614
+ SkeletonLine as DataTableSkeletonLine,
1615
+ useRememberedListTotal,
1616
+ };
1560
1617
 
1561
1618
  // Re-export the consumer-facing TanStack types so columns can be authored from
1562
1619
  // the same import as `DataTable` — no direct `@tanstack/react-table` dependency