@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendure-io/ui",
3
- "version": "3.0.0-next.1",
3
+ "version": "3.0.0-next.2",
4
4
  "description": "React component library for Vendure, built on shadcn/ui and Tailwind v4",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "homepage": "https://github.com/vendurehq/design/tree/main/packages/ui",
@@ -47,7 +47,7 @@
47
47
  "pack:check": "bun pm pack --dry-run"
48
48
  },
49
49
  "peerDependencies": {
50
- "@vendure-io/design-tokens": "^3.0.0-next.1",
50
+ "@vendure-io/design-tokens": "^3.0.0-next.2",
51
51
  "react": ">=19",
52
52
  "react-dom": ">=19",
53
53
  "next": ">=14",
@@ -32,6 +32,7 @@ import {
32
32
  CommandList,
33
33
  } from "./command.tsx"
34
34
  import { Popover, PopoverContent, PopoverTrigger } from "./popover.tsx"
35
+ import { Skeleton } from "./skeleton.tsx"
35
36
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.tsx"
36
37
  // Relative: `label-swap` is closed in the package exports.
37
38
  import { LabelSwap } from "./label-swap.tsx"
@@ -196,8 +197,24 @@ type BreadcrumbMenuBaseProps = {
196
197
  /**
197
198
  * The crumb's label when no option has `value`, such as "All projects"
198
199
  * while none is open, or "Projects unavailable". It swaps like an option.
200
+ * While `pending`, pass the last known name here (from a cache or the
201
+ * previous page) when the options do not have it yet; `undefined` when
202
+ * nothing is known.
199
203
  */
200
204
  placeholder?: string
205
+ /**
206
+ * The current item is still loading or being confirmed. Show the name
207
+ * until it is known to be wrong: while pending, the crumb shows the
208
+ * option for `value`, or else `placeholder`, as usual. Only when neither
209
+ * names the item does it show a text skeleton one line tall: it takes no
210
+ * clicks or focus, and a screen reader hears one status, "<label>:
211
+ * Loading…". The first name after the skeleton shows at once, with no
212
+ * swap. When the confirmed name differs from the one shown, the label
213
+ * swaps as usual; when it is the same, nothing moves. Never pass a
214
+ * placeholder word such as "Project" for an unknown name: leave
215
+ * `placeholder` undefined and the skeleton shows.
216
+ */
217
+ pending?: boolean
201
218
  open?: boolean
202
219
  onOpenChange?: (open: boolean) => void
203
220
  defaultOpen?: boolean
@@ -236,6 +253,30 @@ function useMenuOpen(
236
253
  const crumbTriggerClassName =
237
254
  "text-foreground hover:text-foreground aria-expanded:text-foreground min-w-0 shrink gap-2.25 rounded-lg ps-2.25 pe-1.75 text-sm font-semibold [--content-inset:calc(var(--spacing)*2.25+1px)]"
238
255
 
256
+ /**
257
+ * A crumb menu while its name loads: the crumb's box (28px tall, the same
258
+ * insets and transparent border) with a text skeleton where the name goes.
259
+ * The bar is `0.8lh` of the `text-sm` line, so it follows the line-height
260
+ * token, not a pixel size. It is not a button: nothing opens until the name
261
+ * is known. The skeleton is hidden from screen readers, which hear the
262
+ * status text instead. A `div`, as the skeleton is one.
263
+ */
264
+ function PendingCrumb({ label, className }: { label: string; className?: string }) {
265
+ return (
266
+ <div
267
+ role="status"
268
+ data-slot="breadcrumb-menu-pending"
269
+ className={cn(
270
+ "inline-flex h-7 min-w-0 shrink items-center rounded-lg border border-transparent ps-2.25 pe-1.75 text-sm",
271
+ className
272
+ )}
273
+ >
274
+ <span className="sr-only">{`${label}: Loading…`}</span>
275
+ <Skeleton aria-hidden className="h-[0.8lh] w-24 min-w-0 shrink" />
276
+ </div>
277
+ )
278
+ }
279
+
239
280
  /**
240
281
  * The inside of the crumb, and its tooltip. The crumb's accessible name is
241
282
  * the list label, the option label and then the status, whatever shows
@@ -254,14 +295,16 @@ function useCrumbTrigger({
254
295
  }) {
255
296
  const found = options.findIndex((option) => option.value === value)
256
297
  const fallback = placeholder !== undefined && found === -1
257
- // The placeholder has its own place before the options, so the options
258
- // arriving after a read swap the label, never rewrite it in place.
259
- const offset = placeholder === undefined ? 0 : 1
260
- const active = fallback ? 0 : Math.max(0, found) + offset
261
- const current = fallback ? undefined : options[active - offset]
262
- const labels = options.map((option) => option.label)
263
- if (placeholder !== undefined) labels.unshift(placeholder)
298
+ // The placeholder has its own place before the options, also while it is
299
+ // undefined, so the options arriving after a read swap the label, never
300
+ // rewrite it in place: a last known name passed while pending and then
301
+ // dropped does not shift the options' places.
302
+ const active = fallback ? 0 : Math.max(0, found) + 1
303
+ const current = fallback ? undefined : options[active - 1]
304
+ const labels = [placeholder ?? "", ...options.map((option) => option.label)]
264
305
  const currentLabel = labels[active] ?? ""
306
+ // Whether an option or the placeholder names the current item.
307
+ const named = found !== -1 || placeholder !== undefined
265
308
  // With a status, the name is set so the status comes after the label.
266
309
  // Without one, the name comes from the content, as before.
267
310
  const name = current?.status ? `${label}: ${currentLabel}, ${current.status}` : undefined
@@ -297,7 +340,7 @@ function useCrumbTrigger({
297
340
  // The tooltip shows only for a cut label, and never over the open menu.
298
341
  const tooltip =
299
342
  cut && !open ? <TooltipContent side="bottom">{currentLabel}</TooltipContent> : null
300
- return { triggerProps, content, tooltip }
343
+ return { triggerProps, content, tooltip, named }
301
344
  }
302
345
 
303
346
  function stopPropagation(event: React.SyntheticEvent) {
@@ -372,6 +415,10 @@ function isNewTabClick(event: Event | undefined) {
372
415
  * shows it in full. An option with `href` or `render` is a link; the current
373
416
  * row stays a checked `menuitemradio`. `open` and `onOpenChange` control the
374
417
  * menu. For a long list with a search field, use `BreadcrumbSearchMenu`.
418
+ *
419
+ * While the current item loads, pass `pending`, and the last known name as an
420
+ * option or `placeholder` if there is one: the crumb shows that name, or a
421
+ * text skeleton when there is none.
375
422
  */
376
423
  function BreadcrumbMenu({
377
424
  options,
@@ -379,6 +426,7 @@ function BreadcrumbMenu({
379
426
  onValueChange,
380
427
  label,
381
428
  placeholder,
429
+ pending = false,
382
430
  open: openProp,
383
431
  onOpenChange,
384
432
  defaultOpen = false,
@@ -391,6 +439,9 @@ function BreadcrumbMenu({
391
439
  }) {
392
440
  const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
393
441
  const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
442
+ // Without a name, a skeleton. The trigger mounts with the first name, so
443
+ // it shows without a swap.
444
+ if (pending && !crumb.named) return <PendingCrumb label={label} className={className} />
394
445
  return (
395
446
  <DropdownMenu open={open} onOpenChange={setOpen}>
396
447
  <Tooltip>
@@ -471,7 +522,10 @@ function searchFilter(_value: string, search: string, keywords?: string[]) {
471
522
  * options. `error` shows its text as a row that cannot be picked and, with
472
523
  * `onRetry`, a Retry row. A search that matches nothing shows `emptyText`.
473
524
  * Footer items are `CommandItem`s with `forceMount`, so a search does not
474
- * hide them, and close the popup themselves through `onOpenChange`.
525
+ * hide them, and close the popup themselves through `onOpenChange`. *
526
+ * `loading` is about the list in the open popup. `pending` is about the
527
+ * crumb: while the current item loads, it shows the last known name, or a
528
+ * text skeleton in place of a placeholder word when no name is known.
475
529
  */
476
530
  function BreadcrumbSearchMenu({
477
531
  options,
@@ -479,6 +533,7 @@ function BreadcrumbSearchMenu({
479
533
  onValueChange,
480
534
  label,
481
535
  placeholder,
536
+ pending = false,
482
537
  open: openProp,
483
538
  onOpenChange,
484
539
  defaultOpen = false,
@@ -507,6 +562,9 @@ function BreadcrumbSearchMenu({
507
562
  const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
508
563
  const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
509
564
  const failed = error != null && error !== false
565
+ // Without a name, a skeleton. The trigger mounts with the first name, so
566
+ // it shows without a swap.
567
+ if (pending && !crumb.named) return <PendingCrumb label={label} className={className} />
510
568
  return (
511
569
  <Popover open={open} onOpenChange={setOpen}>
512
570
  <Tooltip>
@@ -10,7 +10,7 @@ import { contentInsetPull } from "@vendure-io/ui/lib/content-inset"
10
10
  import { cn } from "@vendure-io/ui/lib/utils"
11
11
  import { outlineEdge, outlineEdgeHover } from "@vendure-io/ui/lib/outline-edge"
12
12
 
13
- // The v3 look: 34px default and 28px sm, the xl radius, 13px medium text.
13
+ // The v3 look: 34px default and 28px sm, the xl radius, 14px medium text.
14
14
  // Every size keeps its side padding with or without a `data-icon` icon;
15
15
  // default and sm have a 7px gap. Press feedback is a 0.97 scale on :active,
16
16
  // on ease-press in 150ms. Base UI's Button never emits data-pressed, so the
@@ -10,6 +10,7 @@ import {
10
10
 
11
11
  import { cn } from "@vendure-io/ui/lib/utils"
12
12
  import { Button, buttonVariants } from "@vendure-io/ui/components/atoms/button"
13
+ import { useFormatSettings } from "@vendure-io/ui/components/molecules/format-provider"
13
14
  import { ChevronLeftIcon, ChevronRightIcon, ChevronDownIcon } from "lucide-react"
14
15
 
15
16
  function Calendar({
@@ -26,6 +27,10 @@ function Calendar({
26
27
  buttonVariant?: React.ComponentProps<typeof Button>["variant"]
27
28
  }) {
28
29
  const defaultClassNames = getDefaultClassNames()
30
+ // The pickers render this Calendar, so the language set on FormatProvider
31
+ // reaches their popups without each caller passing `locale`.
32
+ const { calendarLocale } = useFormatSettings()
33
+ locale ??= calendarLocale
29
34
 
30
35
  return (
31
36
  <DayPicker
@@ -39,8 +44,12 @@ function Calendar({
39
44
  captionLayout={captionLayout}
40
45
  locale={locale}
41
46
  formatters={{
42
- formatMonthDropdown: (date) =>
43
- date.toLocaleString(locale?.code, { month: "short" }),
47
+ // Through DayPicker's date library, so the month names follow `locale`
48
+ // (US English without one) like the caption, not the browser language.
49
+ formatMonthDropdown: (date, dateLib) =>
50
+ dateLib
51
+ ? dateLib.format(date, "LLL")
52
+ : date.toLocaleString(locale?.code, { month: "short" }),
44
53
  ...formatters,
45
54
  }}
46
55
  classNames={{
@@ -19,8 +19,11 @@ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
19
19
  return (
20
20
  <fieldset
21
21
  data-slot="field-set"
22
+ // min-w-0: a browser fieldset defaults to min-inline-size: min-content, so
23
+ // a wide child (a table) would stretch it past its container instead of
24
+ // scrolling in the child's own container.
22
25
  className={cn(
23
- "flex flex-col gap-6 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
26
+ "flex min-w-0 flex-col gap-6 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
24
27
  className
25
28
  )}
26
29
  {...props}
@@ -38,6 +38,22 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
38
38
  activeKey?: string
39
39
  }
40
40
 
41
+ /** The label a swap shows, and whether it arrived without the swap. */
42
+ type Shown = { active: number; label: React.ReactNode; still: boolean }
43
+
44
+ /**
45
+ * The next `Shown` when `active` or its label changes, or `undefined` when
46
+ * nothing changed. A move to another index whose label has the same words
47
+ * (text or a number) is still: the words do not change, so nothing moves.
48
+ * A new text at the same index rewrites in place, as before.
49
+ */
50
+ function nextShown(shown: Shown, active: number, label: React.ReactNode): Shown | undefined {
51
+ if (shown.active === active && shown.label === label) return undefined
52
+ const sameWords =
53
+ (typeof label === "string" || typeof label === "number") && shown.label === label
54
+ return { active, label, still: shown.active !== active && sameWords }
55
+ }
56
+
41
57
  /**
42
58
  * Internal: the one label swap behind `ButtonLabelSwap` and
43
59
  * `TooltipLabelSwap`. Not exported from the package.
@@ -48,6 +64,8 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
48
64
  * the swap eases to the active label's width and height on the drawer curve.
49
65
  * The size follows the label while it is active (see `useActiveLabelSize`).
50
66
  * With reduced motion the labels only crossfade, and the size changes at once.
67
+ * When `active` moves to a label with the same words as the one shown, the
68
+ * labels change places without a transition, so nothing moves.
51
69
  */
52
70
  function LabelSwap({
53
71
  labels,
@@ -61,6 +79,12 @@ function LabelSwap({
61
79
  ...props
62
80
  }: LabelSwapProps) {
63
81
  const { refs, width, height } = useActiveLabelSize(active, { natural: truncate, key: activeKey })
82
+ // Kept across renders, so a move between labels with the same words is
83
+ // known in the render that makes it.
84
+ const [shown, setShown] = React.useState<Shown>({ active, label: labels[active], still: false })
85
+ const next = nextShown(shown, active, labels[active])
86
+ if (next) setShown(next)
87
+ const still = (next ?? shown).still ? { transition: "none" } : undefined
64
88
  // While the width eases, a growing label is clipped, as without
65
89
  // `truncate`; the ellipsis shows only at rest, so it does not flash.
66
90
  const [resizing, setResizing] = React.useState(false)
@@ -84,7 +108,7 @@ function LabelSwap({
84
108
  truncate && "min-w-0 shrink",
85
109
  className
86
110
  )}
87
- style={width === undefined ? style : { ...style, width, height }}
111
+ style={width === undefined ? { ...style, ...still } : { ...style, ...still, width, height }}
88
112
  {...props}
89
113
  >
90
114
  {labels.map((label, index) => (
@@ -95,6 +119,7 @@ function LabelSwap({
95
119
  refs.current[index] = element
96
120
  }}
97
121
  data-swap={index === active ? "in" : index < active ? "before" : "after"}
122
+ style={still}
98
123
  aria-hidden={index === active ? undefined : true}
99
124
  className={cn(
100
125
  "col-start-1 row-start-1 [transition:opacity_var(--label-swap-fade)_var(--ease-soft),translate_var(--label-swap-move)_var(--ease-out),filter_var(--label-swap-fade)_var(--ease-soft)] data-[swap=after]:opacity-0 data-[swap=before]:opacity-0 motion-safe:data-[swap=after]:translate-y-(--label-swap-shift) motion-safe:data-[swap=before]:-translate-y-(--label-swap-shift) motion-safe:data-[swap=after]:blur-[2px] motion-safe:data-[swap=before]:blur-[2px]",
@@ -109,5 +134,5 @@ function LabelSwap({
109
134
  )
110
135
  }
111
136
 
112
- export { LabelSwap }
137
+ export { LabelSwap, nextShown }
113
138
  export type { LabelSwapProps }
@@ -91,7 +91,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
91
91
  classNames: {
92
92
  // Sonner's own stylesheet is unlayered, so the overlay shadow and
93
93
  // the type need ! to win over it.
94
- // 44px high, 10px 14px padding, 13px medium text, a 10px gap. The
94
+ // 44px high, 10px 14px padding, 14px medium text, a 10px gap. The
95
95
  // overlay shadow gives the edge. The toast has no
96
96
  // border and no inset hairline: either would sit next to the
97
97
  // shadow's 1px edge and read as a second line. A new toast fades in from 12px
@@ -4,32 +4,153 @@ import * as React from "react"
4
4
 
5
5
  import { cn } from "@vendure-io/ui/lib/utils"
6
6
 
7
+ // How far the table runs past each edge of its scroll container, in px.
8
+ // Start and end follow the reading direction. Right to left, browsers report
9
+ // `scrollLeft` from 0 at the start down to a negative number at the end, so
10
+ // the distance from the start is its absolute value.
11
+ function overflowAtEdges(container: HTMLElement) {
12
+ const overflow = Math.max(container.scrollWidth - container.clientWidth, 0)
13
+ const start = Math.min(Math.abs(container.scrollLeft), overflow)
14
+ return { start, end: overflow - start }
15
+ }
16
+
17
+ // The scroll cue: when the table is wider than its container, each edge with
18
+ // hidden content past it fades out, so the column cut at the edge reads as
19
+ // cut, not as the last column. The fade is a mask on the container, so it
20
+ // needs no background colour and works on any surface (page, card). Each fade
21
+ // is as wide as the content hidden past its edge, up to 32px, so it shrinks
22
+ // with the scroll and is gone when that edge is reached; it follows the
23
+ // scroll and has no transition of its own. `data-overflow-start` and
24
+ // `data-overflow-end` mark the edges that fade. A table that fits has no mask.
25
+ // The focus ring is drawn inside the container, where the mask would fade it,
26
+ // so while it shows, a 2px frame under it stays opaque.
27
+ const scrollCue = [
28
+ "[--table-fade-start:min(var(--table-overflow-start,0px),calc(var(--spacing)*8))] [--table-fade-end:min(var(--table-overflow-end,0px),calc(var(--spacing)*8))]",
29
+ "[--table-fade:linear-gradient(to_right,transparent,black_var(--table-fade-start),black_calc(100%_-_var(--table-fade-end)),transparent)]",
30
+ "rtl:[--table-fade:linear-gradient(to_left,transparent,black_var(--table-fade-start),black_calc(100%_-_var(--table-fade-end)),transparent)]",
31
+ "data-overflow-start:[mask-image:var(--table-fade)] data-overflow-end:[mask-image:var(--table-fade)]",
32
+ "focus-visible:[mask-image:var(--table-fade),var(--table-ring-strip),var(--table-ring-strip),var(--table-ring-strip),var(--table-ring-strip)]! [--table-ring-strip:linear-gradient(black,black)]",
33
+ "focus-visible:[mask-position:0_0,left,right,top,bottom] focus-visible:[mask-size:100%_100%,2px_100%,2px_100%,100%_2px,100%_2px] focus-visible:[mask-repeat:no-repeat]",
34
+ ].join(" ")
35
+
36
+ // Pinning (`pinFirstColumn`): the first cell of every row (header, body,
37
+ // footer) stays at the inline-start edge while the other columns scroll under
38
+ // it. A cell marked `data-pinned` is pinned with it, at the same inline-start
39
+ // 0: the DataTable marks its leading column, whose content starts in the
40
+ // zero-width select cell's gutter, so the checkbox and the name stay together.
41
+ // The pinned cells stack above the other cells and above their raised
42
+ // controls (`z-10`, the stretched-link convention): the first cell at 12, a
43
+ // `data-pinned` cell at 11, so the first cell (the select checkbox) stays on
44
+ // top. The container is isolated, so this order stays inside the table;
45
+ // popovers and menus render in a portal and stay above. The other cells are
46
+ // not isolated: a row-wide link layer in them (DataTableRowLink's overlay)
47
+ // must stay under the controls of every cell.
48
+ // A pinned cell must be opaque. It paints `--table-surface` (default: the card
49
+ // surface; set it on an ancestor when the table sits on another surface) and
50
+ // layers the row's state fill over it (`--table-row-fill`, set by TableRow on
51
+ // hover and selection and by TableFooter), so hover and selection still show.
52
+ // While content is scrolled under it (`data-overflow-start`), the pinned cell
53
+ // shows a 1px edge in the input colour on its inline-end side, the sideways
54
+ // twin of `shadow-scrolled` on a sticky header. It is an inset shadow: a
55
+ // table cell with collapsed borders does not paint an outer one. The edge fades in and out
56
+ // (`fast`) and switches at once under reduced motion. The start fade is off
57
+ // when pinned: it would fade the pinned cell, and the edge replaces it. The
58
+ // end fade stays. The pinned cell stacks above the container's focus ring,
59
+ // so while the container has keyboard focus the pinned cells draw their part
60
+ // of the ring (inline-start side, and top and bottom on the first and last row).
61
+ // The selected-row bar of a row sits on the row's start edge, which scrolls
62
+ // away. While pinned, the first cell draws the bar instead (pinnedBar below,
63
+ // the same recipe as selectedBar on the cell's own pseudo-elements) and the
64
+ // row's bar is hidden.
65
+ // Tailwind reads class names from this source as written, so each one is
66
+ // spelled out in full.
67
+ const pinnedColumn = [
68
+ "[&[data-pin-first-column]]:isolate",
69
+ "[&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:sticky [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:start-0 [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:z-12 [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[background-color:var(--table-surface,var(--card))] [&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[background-image:linear-gradient(var(--table-row-fill,transparent),var(--table-row-fill,transparent))]",
70
+ "[&[data-pin-first-column]_tr>[data-pinned]:not(:first-child)]:z-11",
71
+ "[&[data-pin-first-column]_tr]:before:hidden [&[data-pin-first-column]_tr]:after:hidden",
72
+ "[&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[box-shadow:var(--table-pin-edge),var(--table-pin-ring-x,inset_0_0_0_transparent),var(--table-pin-ring-top,inset_0_0_0_transparent),var(--table-pin-ring-bottom,inset_0_0_0_transparent)] [--table-pin-edge:inset_0_0_0_transparent] data-overflow-start:[--table-pin-edge:inset_-1px_0_0_var(--input)] rtl:data-overflow-start:[--table-pin-edge:inset_1px_0_0_var(--input)]",
73
+ "motion-safe:[&[data-pin-first-column]_tr>:is(:first-child,[data-pinned])]:[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft)]",
74
+ "[&[data-pin-first-column]]:[--table-fade-start:0px]",
75
+ "[&[data-pin-first-column]:focus-visible]:[--table-pin-ring-x:inset_2px_0_0_var(--ring)] rtl:[&[data-pin-first-column]:focus-visible]:[--table-pin-ring-x:inset_-2px_0_0_var(--ring)]",
76
+ "[&[data-pin-first-column]:focus-visible_table>:is(thead,tbody,tfoot):not(:is(thead,tbody,tfoot)~*)>tr:first-child]:[--table-pin-ring-top:inset_0_2px_0_var(--ring)]",
77
+ "[&[data-pin-first-column]:focus-visible_table>:is(thead,tbody,tfoot):not(:has(~:is(thead,tbody,tfoot)))>tr:last-child]:[--table-pin-ring-bottom:inset_0_-2px_0_var(--ring)]",
78
+ ].join(" ")
79
+
80
+ // The selected-row bar on the first pinned cell: selectedBar's recipe, with
81
+ // each row state read from the cell's row.
82
+ const pinnedBar = [
83
+ "[&[data-pin-first-column]_tr>:first-child]:before:pointer-events-none [&[data-pin-first-column]_tr>:first-child]:before:absolute [&[data-pin-first-column]_tr>:first-child]:before:inset-y-0 [&[data-pin-first-column]_tr>:first-child]:before:start-0 [&[data-pin-first-column]_tr>:first-child]:before:w-0.5 [&[data-pin-first-column]_tr>:first-child]:before:bg-brand-indicator",
84
+ "[&[data-pin-first-column]_tr>:first-child]:after:pointer-events-none [&[data-pin-first-column]_tr>:first-child]:after:absolute [&[data-pin-first-column]_tr>:first-child]:after:inset-y-0 [&[data-pin-first-column]_tr>:first-child]:after:start-0 [&[data-pin-first-column]_tr>:first-child]:after:w-0.5 [&[data-pin-first-column]_tr>:first-child]:after:bg-brand-indicator",
85
+ "[&[data-pin-first-column]_tr>:first-child]:before:[clip-path:inset(50%_0_50%_0)] [&[data-pin-first-column]_tr>:first-child]:after:[clip-path:inset(50%_0_50%_0)]",
86
+ "[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[clip-path:inset(0_0_100%_0)] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[clip-path:inset(0_0_100%_0)]",
87
+ "[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[clip-path:inset(100%_0_0_0)] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[clip-path:inset(100%_0_0_0)]",
88
+ "[&[data-pin-first-column]_[data-state=selected]+tr[data-next-selected]>:first-child]:before:[clip-path:inset(0_0_100%_0)] [&[data-pin-first-column]_[data-state=selected]+tr[data-next-selected]>:first-child]:after:[clip-path:inset(100%_0_0_0)]",
89
+ "[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[clip-path:inset(0_0_calc(50%_-_0.5px)_0)]! [&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[clip-path:inset(calc(50%_-_0.5px)_0_0_0)]!",
90
+ "[&[data-pin-first-column]_tr>:first-child]:before:origin-left [&[data-pin-first-column]_tr>:first-child]:after:origin-left rtl:[&[data-pin-first-column]_tr>:first-child]:before:origin-right rtl:[&[data-pin-first-column]_tr>:first-child]:after:origin-right",
91
+ "motion-safe:[&[data-pin-first-column]_tr>:first-child]:before:opacity-0 motion-safe:[&[data-pin-first-column]_tr>:first-child]:after:opacity-0 motion-safe:[&[data-pin-first-column]_tr>:first-child]:before:[scale:0.5_1] motion-safe:[&[data-pin-first-column]_tr>:first-child]:after:[scale:0.5_1]",
92
+ "motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:opacity-100 motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:opacity-100 motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[scale:none] motion-safe:[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[scale:none]",
93
+ "motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[scale:none] motion-safe:[&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[scale:none]",
94
+ "motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:opacity-100 motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[scale:none] motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[scale:none]",
95
+ "[&[data-pin-first-column]_tr>:first-child]:before:[--bar-clip-duration:0s] [&[data-pin-first-column]_tr>:first-child]:after:[--bar-clip-duration:0s] [&[data-pin-first-column]_tr>:first-child]:before:[--bar-clip-delay:var(--transition-duration-fast)] [&[data-pin-first-column]_tr>:first-child]:after:[--bar-clip-delay:var(--transition-duration-fast)]",
96
+ "[&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:before:[--bar-clip-delay:0s] [&[data-pin-first-column]_[data-state=selected]+tr>:first-child]:after:[--bar-clip-delay:0s] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[--bar-clip-duration:var(--transition-duration-moderate)] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:before:[--bar-clip-delay:0s] [&[data-pin-first-column]_tr[data-next-selected]>:first-child]:after:[--bar-clip-delay:0s]",
97
+ "[&[data-pin-first-column]_tr>:first-child]:before:[transition:clip-path_var(--bar-clip-duration)_var(--ease-out)_var(--bar-clip-delay),opacity_var(--transition-duration-fast)_var(--ease-soft),scale_var(--transition-duration-fast)_var(--ease-soft)] [&[data-pin-first-column]_tr>:first-child]:after:[transition:clip-path_var(--bar-clip-duration)_var(--ease-out)_var(--bar-clip-delay),opacity_var(--transition-duration-fast)_var(--ease-soft),scale_var(--transition-duration-fast)_var(--ease-soft)]",
98
+ "motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out),opacity_var(--transition-duration-moderate)_var(--ease-soft),scale_var(--transition-duration-moderate)_var(--ease-out)] motion-safe:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[transition:clip-path_var(--transition-duration-moderate)_var(--ease-out),opacity_var(--transition-duration-moderate)_var(--ease-soft),scale_var(--transition-duration-moderate)_var(--ease-out)]",
99
+ "motion-reduce:[&[data-pin-first-column]_tr>:first-child]:before:opacity-0 motion-reduce:[&[data-pin-first-column]_tr>:first-child]:after:opacity-0 motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:opacity-100 motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:opacity-100",
100
+ "motion-reduce:[&[data-pin-first-column]_tr>:first-child]:before:[transition:opacity_var(--transition-duration-fast)_var(--ease-soft),clip-path_0s_linear_var(--transition-duration-fast)] motion-reduce:[&[data-pin-first-column]_tr>:first-child]:after:[transition:opacity_var(--transition-duration-fast)_var(--ease-soft),clip-path_0s_linear_var(--transition-duration-fast)]",
101
+ "motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:before:[transition:opacity_var(--transition-duration-moderate)_var(--ease-soft)] motion-reduce:[&[data-pin-first-column]_tr[data-state=selected]>:first-child]:after:[transition:opacity_var(--transition-duration-moderate)_var(--ease-soft)]",
102
+ ].join(" ")
103
+
7
104
  // When the table is wider than its container, the container scrolls and must
8
105
  // be reachable by keyboard (axe scrollable-region-focusable), so it becomes a
9
106
  // tab stop with a focus ring. A table that fits adds no tab stop.
10
- function Table({ className, ...props }: React.ComponentProps<"table">) {
107
+ function Table({
108
+ className,
109
+ pinFirstColumn = false,
110
+ ...props
111
+ }: React.ComponentProps<"table"> & {
112
+ /** Keeps the first column in place while the others scroll sideways. */
113
+ pinFirstColumn?: boolean
114
+ }) {
11
115
  const containerRef = React.useRef<HTMLDivElement>(null)
12
116
  const [scrollable, setScrollable] = React.useState(false)
13
117
 
14
- // Measure before the first paint, so an overflowing table is a tab stop
15
- // from the start; the observer then tracks later size changes.
118
+ // Measure before the first paint, so an overflowing table is a tab stop and
119
+ // shows its cue from the start; the observer then tracks later size
120
+ // changes, and the scroll listener moves the cue. The cue is written to the
121
+ // container directly, not through state, so a scroll does not re-render.
16
122
  React.useLayoutEffect(() => {
17
123
  const container = containerRef.current
18
124
  if (!container) {
19
125
  return
20
126
  }
21
- const update = () =>
127
+ const updateCue = () => {
128
+ const { start, end } = overflowAtEdges(container)
129
+ // `scrollWidth` and `clientWidth` are rounded, so at the end of the
130
+ // scroll up to 1px can still seem hidden. That is not worth a cue.
131
+ container.toggleAttribute("data-overflow-start", start > 1)
132
+ container.toggleAttribute("data-overflow-end", end > 1)
133
+ container.style.setProperty("--table-overflow-start", `${start}px`)
134
+ container.style.setProperty("--table-overflow-end", `${end}px`)
135
+ }
136
+ const update = () => {
22
137
  setScrollable(container.scrollWidth > container.clientWidth)
138
+ updateCue()
139
+ }
23
140
  update()
141
+ container.addEventListener("scroll", updateCue, { passive: true })
24
142
  if (typeof ResizeObserver === "undefined") {
25
- return
143
+ return () => container.removeEventListener("scroll", updateCue)
26
144
  }
27
145
  const observer = new ResizeObserver(update)
28
146
  observer.observe(container)
29
147
  if (container.firstElementChild) {
30
148
  observer.observe(container.firstElementChild)
31
149
  }
32
- return () => observer.disconnect()
150
+ return () => {
151
+ observer.disconnect()
152
+ container.removeEventListener("scroll", updateCue)
153
+ }
33
154
  }, [])
34
155
 
35
156
  return (
@@ -37,7 +158,8 @@ function Table({ className, ...props }: React.ComponentProps<"table">) {
37
158
  ref={containerRef}
38
159
  data-slot="table-container"
39
160
  tabIndex={scrollable ? 0 : undefined}
40
- className="focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring relative w-full overflow-x-auto rounded-[inherit] outline-none"
161
+ data-pin-first-column={pinFirstColumn ? "" : undefined}
162
+ className={`focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring relative w-full overflow-x-auto rounded-[inherit] outline-none ${scrollCue} ${pinnedColumn} ${pinnedBar}`}
41
163
  >
42
164
  <table
43
165
  data-slot="table"
@@ -141,7 +263,7 @@ function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
141
263
  <tfoot
142
264
  data-slot="table-footer"
143
265
  className={cn(
144
- "bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
266
+ "bg-muted/50 border-t font-medium [&>tr]:last:border-b-0 [--table-row-fill:color-mix(in_oklab,var(--muted)_50%,transparent)]",
145
267
  className
146
268
  )}
147
269
  {...props}
@@ -189,7 +311,8 @@ function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
189
311
  // table then drops frames. At rest
190
312
  // the bar is the same as without the motion: opacity 1, no scale. Under
191
313
  // reduced motion the bar is whole and only fades: the clip jumps on select and
192
- // waits for the fade on deselect.
314
+ // waits for the fade on deselect. With `pinFirstColumn` the first cell draws
315
+ // the bar instead (pinnedBar), so it stays on the pinned edge.
193
316
  const selectedBar = [
194
317
  "before:pointer-events-none before:absolute before:inset-y-0 before:start-0 before:w-0.5 before:bg-brand-indicator",
195
318
  "after:pointer-events-none after:absolute after:inset-y-0 after:start-0 after:w-0.5 after:bg-brand-indicator",
@@ -217,7 +340,7 @@ function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
217
340
  <tr
218
341
  data-slot="table-row"
219
342
  className={cn(
220
- "hover:bg-muted/50 data-[state=selected]:bg-muted relative border-b border-border/50 transition-colors",
343
+ "hover:bg-muted/50 data-[state=selected]:bg-muted relative border-b border-border/50 transition-colors hover:[--table-row-fill:color-mix(in_oklab,var(--muted)_50%,transparent)] data-[state=selected]:[--table-row-fill:var(--muted)]",
221
344
  selectedBar,
222
345
  className
223
346
  )}
@@ -123,7 +123,12 @@ export function measureColumnIndents(table: HTMLTableElement): Record<string, nu
123
123
  for (const cell of cells) {
124
124
  const id = cell.dataset.columnId;
125
125
  const first = cell.firstElementChild;
126
- if (id == null || first == null) continue;
126
+ // A pinned table's row-link overlay host comes after the content, so it is
127
+ // first only in a cell without content elements. It is not content: its
128
+ // overlay spans the whole row.
129
+ const host =
130
+ (first as HTMLElement | null)?.dataset?.slot === 'data-table-row-link-overlay-host';
131
+ if (id == null || first == null || host) continue;
127
132
  const style = getComputedStyle(cell);
128
133
  const rtl = style.direction === 'rtl';
129
134
  const start = (rect: DOMRect) => (rtl ? -rect.right : rect.left);
@@ -225,11 +225,14 @@ export interface DataTableRowRipple {
225
225
  * (`<TableCell {...cellProps(cell.column.id)}>`) and the cell matches the
226
226
  * built-in row: the select cell is the zero-width cell the checkbox floats
227
227
  * over, the leading data cell carries the checkbox gutter, and every cell
228
- * lines its content up with the header. Merge your own classes with `cn`.
228
+ * lines its content up with the header. With `pinFirstColumn`, the leading
229
+ * data cell carries `data-pinned`, so it stays at the edge with the select
230
+ * cell. Merge your own classes with `cn`.
229
231
  */
230
232
  export interface DataTableRowCellProps {
231
233
  'data-column-id': string;
232
234
  'data-content-inset-cell': string;
235
+ 'data-pinned': '' | undefined;
233
236
  className: string;
234
237
  style: React.CSSProperties | undefined;
235
238
  }
@@ -381,7 +384,9 @@ export interface DataTableProps<TData> {
381
384
  * are selected; a row without it keeps opening the item from anywhere on it.
382
385
  * A row with a `DataTableRowLink` needs nothing more: the table raises its
383
386
  * buttons, links, inputs and copy chips above the stretched link, as it does
384
- * on a built-in row.
387
+ * on a built-in row. With `pinFirstColumn`, render `ctx.rowLinkHost(columnId)`
388
+ * at the end of every cell too, so the whole row opens the item (see
389
+ * `pinFirstColumn`).
385
390
  */
386
391
  renderRow?: (
387
392
  row: Row<TData>,
@@ -391,6 +396,13 @@ export interface DataTableProps<TData> {
391
396
  defaultRow: React.ReactNode;
392
397
  ripple: DataTableRowRipple;
393
398
  cellProps: (columnId: string) => DataTableRowCellProps;
399
+ /**
400
+ * Where a `DataTableRowLink` draws the anchor that opens the item from
401
+ * the cells on the other side of the pinned edge. Render it as the last
402
+ * child of every cell: `{ctx.rowLinkHost(cell.column.id)}`. It is `null`
403
+ * without `pinFirstColumn`, and in the cells that need no host.
404
+ */
405
+ rowLinkHost: (columnId: string) => React.ReactNode;
394
406
  selectProps: DataTableRowSelectProps;
395
407
  },
396
408
  ) => React.ReactNode;
@@ -435,6 +447,19 @@ export interface DataTableProps<TData> {
435
447
  * edge-cell alignment — the host card is the frame.
436
448
  */
437
449
  frame?: 'card' | 'plain';
450
+ /**
451
+ * Keeps the first column in place while the others scroll sideways (Table's
452
+ * `pinFirstColumn`). The select checkbox is pinned with it, and a selected
453
+ * row's bar stays on the pinned edge. A `DataTableRowLink` still opens the
454
+ * item from every cell: the name stays the row's one link, and the cells
455
+ * that scroll under the pinned column open it through a second anchor with
456
+ * the same href, hidden from assistive technology and the tab order. A row
457
+ * from `renderRow` that renders its own cells gets that anchor when it
458
+ * renders `ctx.rowLinkHost(cell.column.id)` after the content of every cell;
459
+ * without it, only the cells on the link's side of the pinned edge open the
460
+ * item.
461
+ */
462
+ pinFirstColumn?: boolean;
438
463
  /**
439
464
  * Extra `<TableRow>`s appended inside `TableBody` after the data rows — e.g.
440
465
  * an order table's subtotal/shipping/total rows. Rendered only alongside