@vendure-io/ui 3.0.0-next.1 → 3.0.0-next.2

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.
@@ -65,10 +65,12 @@ import {
65
65
  } from '@vendure-io/ui/components/molecules/data-table/list-header';
66
66
  import { TablePagination } from '@vendure-io/ui/components/molecules/data-table/table-pagination';
67
67
  import { ListRowChevron } from '@vendure-io/ui/components/molecules/list-row';
68
+ import { SkeletonLine } from '@vendure-io/ui/components/molecules/state-views/skeleton-parts';
68
69
  import { cn } from '@vendure-io/ui/lib/utils';
69
70
  import { ChevronRight } from 'lucide-react';
70
71
  import { AnimatePresence, MotionConfig, motion, useReducedMotion } from 'motion/react';
71
72
  import * as React from 'react';
73
+ import { createPortal } from 'react-dom';
72
74
  // Relative: `data-table-helpers` is closed in the package exports.
73
75
  import {
74
76
  buildDisplayColumns,
@@ -86,25 +88,6 @@ import { useSelectionStorage } from './data-table-selection-storage.tsx';
86
88
  // for the actions cell.
87
89
  const ACTIONS_COLUMN_ID = 'actions';
88
90
 
89
- /**
90
- * One text line of loading placeholder: a box exactly one line box tall (`1lh`
91
- * of the inherited font) with a bar centred in it, so a skeleton line is as tall
92
- * as the text line it stands in for. Size the line with a text utility
93
- * (`text-xs` for a muted sub-line) and its width with `w-*`. DataTable uses it as
94
- * the default loading cell; stack several for multi-line `skeletonCells`.
95
- */
96
- function DataTableSkeletonLine({ className, ...props }: React.ComponentProps<'div'>) {
97
- return (
98
- <div
99
- data-slot="data-table-skeleton-line"
100
- className={cn('flex h-[1lh] w-full items-center', className)}
101
- {...props}
102
- >
103
- <Skeleton className="h-[0.8lh] w-full" />
104
- </div>
105
- );
106
- }
107
-
108
91
  // The row link is a stretched link, like ListRowLink: one real link per row,
109
92
  // whose ::after covers the row (the row is `relative`), so a click on any point
110
93
  // of the row opens it, while keyboard and screen reader users get one tab stop
@@ -130,11 +113,15 @@ const LINKED_ROW_CLASS = cn(
130
113
  // before the click (useSelectAllRipple): the cursor is inherited, so its
131
114
  // change restyles every cell of every row.
132
115
  '[&[data-selecting-cursor]_tr]:cursor-default!',
133
- '[&_tr:has([data-slot=data-table-row-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]):not([data-slot=data-table-row-link],[data-slot=checkbox],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:relative',
134
- '[&_tr:has([data-slot=data-table-row-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]):not([data-slot=data-table-row-link],[data-slot=checkbox],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:z-10',
116
+ '[&_tr:has([data-slot=data-table-row-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]):not([data-slot=data-table-row-link],[data-slot=data-table-row-link-overlay],[data-slot=checkbox],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:relative',
117
+ '[&_tr:has([data-slot=data-table-row-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]):not([data-slot=data-table-row-link],[data-slot=data-table-row-link-overlay],[data-slot=checkbox],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:z-10',
135
118
  // Only the first row link of a row stretches. A later one (a variant's
136
119
  // Product, rendered by the same link component) is a plain link above it,
137
120
  // underlined on hover, without a chevron.
121
+ // Pinned (`pinFirstColumn`): while the row link holds keyboard focus, the
122
+ // pinned cells draw their part of the row's focus ring (inline-start side,
123
+ // top and bottom): they stack above the ring the link draws over the row.
124
+ '[&_tr:not([data-click-selects]):has([data-slot=data-table-row-link]:focus-visible)]:[--table-pin-ring-x:inset_2px_0_0_var(--ring)] rtl:[&_tr:not([data-click-selects]):has([data-slot=data-table-row-link]:focus-visible)]:[--table-pin-ring-x:inset_-2px_0_0_var(--ring)] [&_tr:not([data-click-selects]):has([data-slot=data-table-row-link]:focus-visible)]:[--table-pin-ring-top:inset_0_2px_0_var(--ring)] [&_tr:not([data-click-selects]):has([data-slot=data-table-row-link]:focus-visible)]:[--table-pin-ring-bottom:inset_0_-2px_0_var(--ring)]',
138
125
  '[&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:relative [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:z-10 [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:underline-offset-4 [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:hover:underline [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-chevron]]:hidden',
139
126
  );
140
127
 
@@ -146,6 +133,38 @@ const LINKED_ROW_CLASS = cn(
146
133
  const ROW_CHEVRON_SLOT_CLASS =
147
134
  '[&:has([data-slot=data-table-row-link])_tr>*:last-child]:pe-[calc(var(--card-px)+--spacing(7))]!';
148
135
 
136
+ // Pinned (`pinFirstColumn`): a pinned cell is positioned, so it becomes the
137
+ // containing block of the link's stretched ::after. A link in the pinned cell
138
+ // then covers only that cell, and a link in a scrolling cell covers every cell
139
+ // but the pinned ones, which stack above it. The cells on the other side of
140
+ // the pinned edge open the item through an overlay: a second anchor with the
141
+ // same href, hidden from assistive technology and from the tab order, so the
142
+ // row keeps one link and one tab stop. Cmd+click, middle-click and the hover
143
+ // URL work on it as on the link. It renders (in a portal) into a host the
144
+ // DataTable puts in the other side: in the last cell when the link is pinned,
145
+ // so the row is its containing block, else in the pinned cell. It sits under
146
+ // the row controls, as the ::after does.
147
+ const PINNED_CELL_SELECTOR = ':first-child, [data-pinned]';
148
+ const OVERLAY_HOST_SELECTOR = ':scope > * > [data-slot=data-table-row-link-overlay-host]';
149
+
150
+ interface RowLinkOverlay {
151
+ host: Element;
152
+ pinnedLink: boolean;
153
+ }
154
+
155
+ function rowLinkOverlay(link: HTMLElement): RowLinkOverlay | null {
156
+ const cell = link.closest('td, th');
157
+ const row = cell?.parentElement;
158
+ if (!cell || !row || row.tagName !== 'TR' || !row.closest('[data-pin-first-column]')) return null;
159
+ // Only the first row link of a row stretches.
160
+ if (row.querySelector('[data-slot=data-table-row-link]') !== link) return null;
161
+ const pinnedLink = cell.matches(PINNED_CELL_SELECTOR);
162
+ const host = Array.from(row.querySelectorAll(OVERLAY_HOST_SELECTOR)).find(
163
+ (candidate) => candidate.parentElement?.matches(PINNED_CELL_SELECTOR) !== pinnedLink,
164
+ );
165
+ return host ? { host, pinnedLink } : null;
166
+ }
167
+
149
168
  /**
150
169
  * Opens the row's item from any point of the row. Render it in the cell that
151
170
  * names the item, around the name: its children are the accessible name of
@@ -178,6 +197,11 @@ const ROW_CHEVRON_SLOT_CLASS =
178
197
  * the end of the row, the full row height, the chevron stays on row hover and
179
198
  * turns blue on the target's hover or focus, and the focus ring goes around
180
199
  * the slot. A click anywhere else on the row selects it.
200
+ *
201
+ * In a table with `pinFirstColumn`, the cells on the other side of the pinned
202
+ * edge open the item through an overlay anchor with the same href (see
203
+ * rowLinkOverlay). It is hidden from assistive technology and from the tab
204
+ * order, so the row still has one link and one tab stop.
181
205
  */
182
206
  function DataTableRowLink({
183
207
  className,
@@ -190,16 +214,62 @@ function DataTableRowLink({
190
214
  // target is the row-end chevron instead.
191
215
  const linkRef = React.useRef<HTMLAnchorElement>(null);
192
216
  const [nameless, setNameless] = React.useState(false);
217
+ const [overlay, setOverlay] = React.useState<RowLinkOverlay | null>(null);
193
218
  React.useLayoutEffect(() => {
194
219
  const link = linkRef.current;
195
- if (link) setNameless(link.getBoundingClientRect().width < 1);
220
+ if (!link) return;
221
+ setNameless(link.getBoundingClientRect().width < 1);
222
+ const next = rowLinkOverlay(link);
223
+ setOverlay((current) =>
224
+ current?.host === next?.host && current?.pinnedLink === next?.pinnedLink ? current : next,
225
+ );
226
+ });
227
+ // In a pinned cell the link's ::after covers only that cell, and its
228
+ // chevron would sit at the cell's end: the overlay draws both for the row.
229
+ const pinnedLink = overlay?.pinnedLink === true;
230
+ // The overlay goes to the same place as the link, with the link's own props
231
+ // (a router link's `render` included), but no id and no styling of its own.
232
+ const { id: _id, style: _style, ...overlayLinkProps } = props;
233
+ const overlayNode = useRender({
234
+ defaultTagName: 'a',
235
+ render,
236
+ enabled: overlay != null,
237
+ props: mergeProps<'a'>(overlayLinkProps, {
238
+ 'aria-hidden': true,
239
+ tabIndex: -1,
240
+ className: cn(
241
+ 'group/row-link-overlay absolute inset-0 z-1 cursor-pointer outline-none',
242
+ // While rows are selected a click on the row selects it.
243
+ 'in-data-click-selects:hidden',
244
+ pinnedLink && [
245
+ // The row's focus ring while the link holds keyboard focus; the
246
+ // pinned cells draw their part of it (LINKED_ROW_CLASS).
247
+ 'in-[tr:has([data-slot=data-table-row-link]:focus-visible)]:outline-2 in-[tr:has([data-slot=data-table-row-link]:focus-visible)]:-outline-offset-2 in-[tr:has([data-slot=data-table-row-link]:focus-visible)]:outline-ring in-[tr:has([data-slot=data-table-row-link]:focus-visible)]:outline-solid',
248
+ // A link without a visible name: while rows are selected the
249
+ // overlay is its target over the row-end chevron slot.
250
+ 'in-data-click-selects:data-nameless:block in-data-click-selects:data-nameless:start-auto in-data-click-selects:data-nameless:w-[calc(var(--card-px)+--spacing(7))] in-data-click-selects:data-nameless:rounded-md',
251
+ ],
252
+ ),
253
+ children: pinnedLink ? (
254
+ <ListRowChevron
255
+ data-slot="data-table-row-link-overlay-chevron"
256
+ className={cn(
257
+ 'pointer-events-none absolute end-(--card-px) top-1/2 -translate-y-1/2 in-data-selecting:hidden',
258
+ 'in-data-click-selects:group-data-nameless/row-link-overlay:block in-data-click-selects:group-data-nameless/row-link-overlay:transition-[opacity,translate,color]',
259
+ 'in-data-click-selects:group-data-nameless/row-link-overlay:group-hover/row-link-overlay:text-brand-text in-data-click-selects:group-data-nameless/row-link-overlay:in-[tr:has([data-slot=data-table-row-link]:focus-visible)]:text-brand-text',
260
+ )}
261
+ />
262
+ ) : null,
263
+ }),
264
+ state: { slot: 'data-table-row-link-overlay', nameless },
196
265
  });
197
- return useRender({
266
+ const linkNode = useRender({
198
267
  defaultTagName: 'a',
199
268
  render,
200
269
  ref: linkRef,
201
270
  props: mergeProps<'a'>(
202
271
  {
272
+ ...(pinnedLink ? { 'data-pinned-link': '' } : {}),
203
273
  className: cn(
204
274
  'group/row-link cursor-pointer font-medium text-foreground outline-none',
205
275
  'after:absolute after:inset-0 after:z-1 focus-visible:after:outline-2 focus-visible:after:-outline-offset-2 focus-visible:after:outline-ring focus-visible:after:outline-solid',
@@ -212,6 +282,8 @@ function DataTableRowLink({
212
282
  // is drawn around that slot.
213
283
  'in-data-click-selects:data-nameless:after:block in-data-click-selects:data-nameless:after:start-auto in-data-click-selects:data-nameless:after:w-[calc(var(--card-px)+--spacing(7))] in-data-click-selects:data-nameless:after:rounded-md',
214
284
  'in-data-click-selects:data-nameless:focus-visible:outline-none',
285
+ // In a pinned cell the overlay draws the ring and the row-end target.
286
+ 'data-pinned-link:focus-visible:after:outline-none in-data-click-selects:data-nameless:data-pinned-link:after:hidden',
215
287
  className,
216
288
  ),
217
289
  children: (
@@ -234,7 +306,7 @@ function DataTableRowLink({
234
306
  <ListRowChevron
235
307
  data-slot="data-table-row-chevron"
236
308
  className={cn(
237
- 'pointer-events-none absolute end-(--card-px) top-1/2 -translate-y-1/2 in-data-selecting:hidden',
309
+ 'pointer-events-none absolute end-(--card-px) top-1/2 -translate-y-1/2 in-data-selecting:hidden group-data-pinned-link/row-link:hidden!',
238
310
  // The target of a link without a visible name while rows are
239
311
  // selected: shown on row hover, blue on its own hover or focus.
240
312
  'in-data-click-selects:group-data-nameless/row-link:block in-data-click-selects:group-data-nameless/row-link:transition-[opacity,translate,color]',
@@ -249,6 +321,12 @@ function DataTableRowLink({
249
321
  // `nameless` renders as `data-nameless` while true.
250
322
  state: { slot: 'data-table-row-link', nameless },
251
323
  });
324
+ return (
325
+ <>
326
+ {linkNode}
327
+ {overlay != null && overlayNode != null && createPortal(overlayNode, overlay.host)}
328
+ </>
329
+ );
252
330
  }
253
331
 
254
332
  // The composition root. Owns the single `useReactTable` instance and the
@@ -338,7 +416,7 @@ const HEADER_LABEL_UNDER_BULK_CLASS =
338
416
  // control inside the row counts: an ancestor of the table that matches (an app
339
417
  // shell's `<main tabindex="-1">`, the skip link target) is not a row control.
340
418
  const ROW_CONTROL_SELECTOR =
341
- '[data-slot=data-table-select-area],a:not([data-slot=data-table-row-link]),button,input,select,textarea,[role=button],[role=checkbox],[role=menuitem],[tabindex]:not([data-slot=data-table-row-link]),[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]';
419
+ '[data-slot=data-table-select-area],a:not([data-slot=data-table-row-link],[data-slot=data-table-row-link-overlay]),button,input,select,textarea,[role=button],[role=checkbox],[role=menuitem],[tabindex]:not([data-slot=data-table-row-link],[data-slot=data-table-row-link-overlay]),[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]';
342
420
 
343
421
  // The select gutter is `--spacing(10)`, 40px: the checkbox (8px in, 16px wide,
344
422
  // ending at 24px), a 5px gap, then the 11px `--content-inset` of a sortable
@@ -399,6 +477,16 @@ const SELECT_RIPPLE_ROW_CLASS = cn(
399
477
  'in-data-[select-ripple=select]:not-data-[state=selected]:before:[transition:none]! in-data-[select-ripple=select]:not-data-[state=selected]:after:[transition:none]!',
400
478
  'in-data-[select-ripple=clear]:not-data-[state=selected]:before:[clip-path:inset(100%_0_0_0)]! in-data-[select-ripple=clear]:not-data-[state=selected]:after:[clip-path:inset(100%_0_0_0)]!',
401
479
  );
480
+ // Pinned (`pinFirstColumn`), the first cell draws the selected-row bar (see
481
+ // Table), so the select cell takes the row's ripple on its own bar: the same
482
+ // rules, reading the row's state and delay.
483
+ const SELECT_RIPPLE_PINNED_BAR_CLASS = cn(
484
+ 'in-data-[select-ripple=select]:before:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-moderate)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-moderate)_var(--ease-out)_var(--row-ripple-delay)]! in-data-[select-ripple=select]:after:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-moderate)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-moderate)_var(--ease-out)_var(--row-ripple-delay)]!',
485
+ 'in-data-[select-ripple=clear]:before:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay)]! in-data-[select-ripple=clear]:after:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay)]!',
486
+ 'in-data-[select-ripple=select]:[tr:not([data-state=selected])>&]:before:[clip-path:inset(0_0_100%_0)]! in-data-[select-ripple=select]:[tr:not([data-state=selected])>&]:after:[clip-path:inset(0_0_100%_0)]!',
487
+ 'in-data-[select-ripple=select]:[tr:not([data-state=selected])>&]:before:[transition:none]! in-data-[select-ripple=select]:[tr:not([data-state=selected])>&]:after:[transition:none]!',
488
+ 'in-data-[select-ripple=clear]:[tr:not([data-state=selected])>&]:before:[clip-path:inset(100%_0_0_0)]! in-data-[select-ripple=clear]:[tr:not([data-state=selected])>&]:after:[clip-path:inset(100%_0_0_0)]!',
489
+ );
402
490
  // The row checkbox keeps its own transitions (the fill, the mark revealed with
403
491
  // it, the fade in) and only takes the row's delay. Row checkboxes are never
404
492
  // indeterminate, so their mark never swaps and needs no delay.
@@ -650,6 +738,7 @@ function DataTable<TData>({
650
738
  setTableOptions,
651
739
  onTableReady,
652
740
  frame = 'card',
741
+ pinFirstColumn = false,
653
742
  footerRows,
654
743
  labels,
655
744
  className,
@@ -925,6 +1014,14 @@ function DataTable<TData>({
925
1014
  if (rowActions != null && id === ACTIONS_COLUMN_ID) return 'actions';
926
1015
  return undefined;
927
1016
  };
1017
+ // Pinned (`pinFirstColumn`): the first data column. With row selection the
1018
+ // zero-width select cell is the first cell and the checkbox floats over this
1019
+ // column's gutter, so its cells carry `data-pinned` and Table pins them
1020
+ // with the select cell, at the same inline-start edge.
1021
+ const pinnedColumnId = pinFirstColumn
1022
+ ? table.getVisibleLeafColumns().find((column) => generatedColumn(column.id) !== 'select')?.id
1023
+ : undefined;
1024
+ const pinnedMark = (id: string): '' | undefined => (id === pinnedColumnId ? '' : undefined);
928
1025
  // Columns whose `meta.align` is `'end'`: their header, sort control and
929
1026
  // cells line up on the end side, so the digits of a number column line up.
930
1027
  const endColumnIds = new Set(
@@ -1002,14 +1099,29 @@ function DataTable<TData>({
1002
1099
  const bodyCellProps = (columnId: string): DataTableRowCellProps => ({
1003
1100
  'data-column-id': columnId,
1004
1101
  'data-content-inset-cell': '',
1102
+ 'data-pinned': pinnedMark(columnId),
1005
1103
  className: cn(
1006
1104
  columnClass(columnId),
1007
1105
  bodyCellClass,
1008
1106
  endColumnIds.has(columnId) ? endPullClass : startPullClass,
1107
+ pinFirstColumn && generatedColumn(columnId) === 'select' && SELECT_RIPPLE_PINNED_BAR_CLASS,
1009
1108
  ),
1010
1109
  style: columnIndentStyle(columnId),
1011
1110
  });
1012
1111
 
1112
+ // Pinned: where a DataTableRowLink renders its overlay (see rowLinkOverlay),
1113
+ // one host on each side of the pinned edge: in the pinned cell, and in the
1114
+ // last cell when that one scrolls. A host has no box of its own. Handed to
1115
+ // `renderRow` as `ctx.rowLinkHost`, so a row a consumer renders itself gets
1116
+ // the same hosts.
1117
+ const lastColumnId = table.getVisibleLeafColumns().at(-1)?.id;
1118
+ const rowLinkHost = (columnId: string): React.ReactNode =>
1119
+ pinFirstColumn &&
1120
+ pinnedColumnId != null &&
1121
+ (columnId === pinnedColumnId || columnId === lastColumnId) ? (
1122
+ <span data-slot="data-table-row-link-overlay-host" className="contents" />
1123
+ ) : null;
1124
+
1013
1125
  // Loading cells follow the real column layout (same ids, same cell classes),
1014
1126
  // so a consumer's `skeletonCells` entry can match its loaded cell's height.
1015
1127
  const skeletonCell = (id: string): React.ReactNode => {
@@ -1021,7 +1133,7 @@ function DataTable<TData>({
1021
1133
  const custom = skeletonCells?.[id];
1022
1134
  if (custom !== undefined) return custom;
1023
1135
  if (generated === 'actions') return <Skeleton className="size-8" />;
1024
- return <DataTableSkeletonLine />;
1136
+ return <SkeletonLine data-slot="data-table-skeleton-line" />;
1025
1137
  };
1026
1138
 
1027
1139
  const warnedUnknownSkeletonCells = React.useRef(false);
@@ -1107,8 +1219,13 @@ function DataTable<TData>({
1107
1219
  if (!event.currentTarget.contains(target) || isRowControl(target, event.currentTarget)) return;
1108
1220
  // The name: the row link does not stretch while rows are selected, so a
1109
1221
  // click that lands in it was on the name, and opens the item. Shift+click
1110
- // on it still extends the selection.
1111
- if (!event.shiftKey && target.closest('[data-slot=data-table-row-link]')) return;
1222
+ // on it still extends the selection. In a pinned table the link's overlay
1223
+ // then shows only as the row-end target of a link without a visible name.
1224
+ if (
1225
+ !event.shiftKey &&
1226
+ target.closest('[data-slot=data-table-row-link],[data-slot=data-table-row-link-overlay]')
1227
+ )
1228
+ return;
1112
1229
  event.preventDefault();
1113
1230
  event.stopPropagation();
1114
1231
  selectAllRipple.end();
@@ -1257,6 +1374,7 @@ function DataTable<TData>({
1257
1374
  )}
1258
1375
  <Table
1259
1376
  ref={tableRef}
1377
+ pinFirstColumn={pinFirstColumn}
1260
1378
  className={cn(LINKED_ROW_CLASS, ROW_CHEVRON_SLOT_CLASS, SELECT_RIPPLE_TABLE_CLASS)}
1261
1379
  data-selecting={selecting ? '' : undefined}
1262
1380
  data-bulk-over-header={bulkOverHeader && showBulk ? '' : undefined}
@@ -1273,6 +1391,7 @@ function DataTable<TData>({
1273
1391
  key={headerCell.id}
1274
1392
  aria-sort={ariaSort(sorting != null, headerCell.column)}
1275
1393
  data-column-id={headerCell.column.id}
1394
+ data-pinned={pinnedMark(headerCell.column.id)}
1276
1395
  className={cn(
1277
1396
  columnClass(headerCell.column.id),
1278
1397
  generatedColumn(headerCell.column.id) !== 'select' &&
@@ -1303,13 +1422,14 @@ function DataTable<TData>({
1303
1422
  <TableRow key={`skeleton-${rowIndex}`}>
1304
1423
  {columnCount === 0 ? (
1305
1424
  <TableCell>
1306
- <DataTableSkeletonLine />
1425
+ <SkeletonLine data-slot="data-table-skeleton-line" />
1307
1426
  </TableCell>
1308
1427
  ) : (
1309
1428
  table.getVisibleLeafColumns().map((column) => (
1310
1429
  <TableCell
1311
1430
  key={column.id}
1312
1431
  data-column-id={column.id}
1432
+ data-pinned={pinnedMark(column.id)}
1313
1433
  className={columnClass(column.id)}
1314
1434
  style={columnIndentStyle(column.id)}
1315
1435
  >
@@ -1346,6 +1466,7 @@ function DataTable<TData>({
1346
1466
  {row.getVisibleCells().map((cell) => (
1347
1467
  <TableCell key={cell.id} {...bodyCellProps(cell.column.id)}>
1348
1468
  {flexRender(cell.column.columnDef.cell, cell.getContext())}
1469
+ {rowLinkHost(cell.column.id)}
1349
1470
  </TableCell>
1350
1471
  ))}
1351
1472
  </TableRow>
@@ -1375,6 +1496,7 @@ function DataTable<TData>({
1375
1496
  defaultRow,
1376
1497
  ripple,
1377
1498
  cellProps: bodyCellProps,
1499
+ rowLinkHost,
1378
1500
  selectProps,
1379
1501
  })
1380
1502
  : defaultRow}
@@ -1432,7 +1554,9 @@ function DataTable<TData>({
1432
1554
  );
1433
1555
  }
1434
1556
 
1435
- export { DataTable, DataTableRowLink, DataTableSkeletonLine };
1557
+ // `DataTableSkeletonLine` is the shared SkeletonLine under its old name, kept for
1558
+ // consumers that stack it in `skeletonCells`.
1559
+ export { DataTable, DataTableRowLink, SkeletonLine as DataTableSkeletonLine };
1436
1560
 
1437
1561
  // Re-export the consumer-facing TanStack types so columns can be authored from
1438
1562
  // the same import as `DataTable` — no direct `@tanstack/react-table` dependency
@@ -8,7 +8,7 @@ import type * as React from 'react';
8
8
  // this, and PageHeaderFactLink renders ExternalArrow. The package exports map
9
9
  // this file to null.
10
10
  //
11
- // The v3 look: 13px medium text, and a 15px chevron at 45%: trailing forward,
11
+ // The v3 look: 14px medium text, and a 15px chevron at 45%: trailing forward,
12
12
  // leading back. A straight direction takes a chevron; an arrow is for a
13
13
  // diagonal only, such as a link that leaves the app. On hover or keyboard
14
14
  // focus the text reaches full foreground and the chevron full strength, and
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { createContext, type ReactNode, useContext, useMemo } from 'react';
4
+ import type { Locale } from 'react-day-picker';
4
5
 
5
6
  // The design system cannot depend on any app's i18n. Formatters resolve their
6
7
  // locale/currency in a fixed order — explicit prop → this context → `undefined`
@@ -21,6 +22,14 @@ interface FormatContextValue {
21
22
  * digits (2 for USD, 0 for JPY, 3 for BHD).
22
23
  */
23
24
  currencyPrecision?: number;
25
+ /**
26
+ * Language of every `Calendar`, including the date pickers' popups: month
27
+ * caption, weekday names, first day of the week and screen-reader labels.
28
+ * Import only the active language, e.g. `react-day-picker/locale/fr`, never
29
+ * the `react-day-picker/locale` barrel (every language, about 1.6 MB).
30
+ * `undefined` → US English. A `Calendar`'s own `locale` prop wins.
31
+ */
32
+ calendarLocale?: Locale;
24
33
  }
25
34
 
26
35
  const FormatContext = createContext<FormatContextValue>({});
@@ -31,10 +40,11 @@ function FormatProvider({
31
40
  timeZone,
32
41
  currency,
33
42
  currencyPrecision,
43
+ calendarLocale,
34
44
  }: FormatContextValue & { children: ReactNode }) {
35
45
  const value = useMemo(
36
- () => ({ locale, timeZone, currency, currencyPrecision }),
37
- [locale, timeZone, currency, currencyPrecision],
46
+ () => ({ locale, timeZone, currency, currencyPrecision, calendarLocale }),
47
+ [locale, timeZone, currency, currencyPrecision, calendarLocale],
38
48
  );
39
49
  return <FormatContext.Provider value={value}>{children}</FormatContext.Provider>;
40
50
  }
@@ -67,7 +67,7 @@ function PageHeaderActions({ className, ...props }: React.ComponentProps<'div'>)
67
67
  }
68
68
 
69
69
  /**
70
- * The facts under the title: branch, region, host, owner. 13px text in
70
+ * The facts under the title: branch, region, host, owner. 14px text in
71
71
  * `foreground-secondary`, 18px between facts and 6px between rows when they
72
72
  * wrap. Put it in PageHeaderContent, below the title.
73
73
  */
@@ -9,7 +9,7 @@ import type * as React from 'react';
9
9
  type SearchTriggerCollapse = 'md' | 'never' | 'always';
10
10
 
11
11
  // The v3 look: a button that looks like a field. 28px high, 220px wide, on
12
- // the muted fill with a 1px inset hairline and the lg radius. The 13px text
12
+ // the muted fill with a 1px inset hairline and the lg radius. The 14px text
13
13
  // is `foreground-secondary`: muted text on the muted fill is under 4.5:1.
14
14
  // The icon is 14px and quieter than the text (55%). Hover steps the fill up
15
15
  // to `accent` in 120ms. No press scale: it is a field, not a button, to
@@ -2,6 +2,7 @@ import { Skeleton } from '@vendure-io/ui/components/atoms/skeleton';
2
2
  import { Spinner } from '@vendure-io/ui/components/atoms/spinner';
3
3
  import { cn } from '@vendure-io/ui/lib/utils';
4
4
  import { cva, type VariantProps } from 'class-variance-authority';
5
+ import { Children } from 'react';
5
6
 
6
7
  const loadingStateVariants = cva('flex w-full min-w-0 flex-col gap-3', {
7
8
  variants: {
@@ -20,7 +21,7 @@ const loadingStateVariants = cva('flex w-full min-w-0 flex-col gap-3', {
20
21
  export interface LoadingStateProps
21
22
  extends React.ComponentProps<'output'>,
22
23
  VariantProps<typeof loadingStateVariants> {
23
- /** Number of skeleton rows. `skeleton` variant only; defaults to 5. */
24
+ /** Number of skeleton rows. `skeleton` variant without children only; defaults to 5. */
24
25
  rows?: number;
25
26
  /** Classes applied to each skeleton row (e.g. `h-10` for tighter lists). */
26
27
  rowClassName?: string;
@@ -28,14 +29,33 @@ export interface LoadingStateProps
28
29
  label?: React.ReactNode;
29
30
  /** Sr-only label announced to assistive tech. Override for host i18n. @default "Loading…" */
30
31
  srLabel?: string;
32
+ /**
33
+ * Milliseconds before the placeholder appears. A load that ends sooner never
34
+ * shows it, so fast loads do not flash. `0` shows it at once. @default 150
35
+ */
36
+ delay?: number;
37
+ /**
38
+ * Skeleton parts in the shape of the page (`SkeletonPageHeader`,
39
+ * `SkeletonCard`, `SkeletonListRow`, …). Replace the `rows` bars.
40
+ * `skeleton` variant only. Children that render nothing (`false`, `null`,
41
+ * an empty array) fall back to the `rows` bars.
42
+ */
43
+ children?: React.ReactNode;
31
44
  }
32
45
 
46
+ // The placeholder holds its space at once but stays transparent for `delay`,
47
+ // then fades in. Under reduced motion it appears without the fade, still after
48
+ // the delay: the delay is not motion, it keeps fast loads from flashing.
49
+ const DELAYED_ENTRY =
50
+ '[animation:page-fade_var(--transition-duration-page-fade)_var(--ease-out)_var(--loading-state-delay)_both] motion-reduce:[animation-duration:0s]';
51
+
33
52
  /**
34
53
  * Placeholder shell for in-flight list/detail queries. Renders as an
35
54
  * `aria-live` `<output>` with an always-present sr-only `srLabel` (defaults to
36
55
  * "Loading…", overridable for host i18n).
37
- * `skeleton` (default) draws N shimmer rows; `spinner` centers the `Spinner`
38
- * atom for compact or unknown-height regions.
56
+ * `skeleton` (default) draws N shimmer rows, or the skeleton parts passed as
57
+ * children; `spinner` centers the `Spinner` atom for compact or unknown-height
58
+ * regions. Nothing shows for the first `delay` ms (150 by default).
39
59
  */
40
60
  function LoadingState({
41
61
  variant = 'skeleton',
@@ -43,14 +63,22 @@ function LoadingState({
43
63
  rowClassName,
44
64
  label,
45
65
  srLabel = 'Loading…',
66
+ delay = 150,
67
+ children,
46
68
  className,
69
+ style,
47
70
  ...props
48
71
  }: LoadingStateProps) {
49
72
  return (
50
73
  <output
51
74
  data-slot="loading-state"
52
75
  aria-live="polite"
53
- className={cn(loadingStateVariants({ variant }), className)}
76
+ className={cn(loadingStateVariants({ variant }), delay > 0 && DELAYED_ENTRY, className)}
77
+ style={
78
+ delay > 0
79
+ ? ({ '--loading-state-delay': `${delay}ms`, ...style } as React.CSSProperties)
80
+ : style
81
+ }
54
82
  {...props}
55
83
  >
56
84
  <span className="sr-only">{srLabel}</span>
@@ -72,9 +100,11 @@ function LoadingState({
72
100
  {label}
73
101
  </span>
74
102
  ) : null}
75
- {Array.from({ length: rows }).map((_, i) => (
76
- <Skeleton key={i} className={cn('h-14 w-full rounded-md', rowClassName)} />
77
- ))}
103
+ {Children.toArray(children).length > 0
104
+ ? children
105
+ : Array.from({ length: rows }).map((_, i) => (
106
+ <Skeleton key={i} className={cn('h-14 w-full rounded-md', rowClassName)} />
107
+ ))}
78
108
  </>
79
109
  )}
80
110
  </output>