@vendure-io/ui 3.0.0-next.0 → 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.
Files changed (38) hide show
  1. package/package.json +2 -2
  2. package/src/components/atoms/alert.tsx +13 -6
  3. package/src/components/atoms/avatar.tsx +11 -3
  4. package/src/components/atoms/breadcrumb.tsx +467 -53
  5. package/src/components/atoms/button.tsx +1 -1
  6. package/src/components/atoms/calendar.tsx +11 -2
  7. package/src/components/atoms/combobox.tsx +220 -17
  8. package/src/components/atoms/command.tsx +51 -130
  9. package/src/components/atoms/dialog.tsx +23 -1
  10. package/src/components/atoms/empty.tsx +1 -1
  11. package/src/components/atoms/field.tsx +4 -1
  12. package/src/components/atoms/input-group.tsx +2 -2
  13. package/src/components/atoms/label-swap.tsx +59 -3
  14. package/src/components/atoms/popover.tsx +6 -1
  15. package/src/components/atoms/sheet.tsx +18 -1
  16. package/src/components/atoms/sidebar.tsx +73 -1
  17. package/src/components/atoms/sonner.tsx +1 -1
  18. package/src/components/atoms/table.tsx +133 -10
  19. package/src/components/atoms/tooltip.tsx +3 -3
  20. package/src/components/molecules/chip.tsx +43 -4
  21. package/src/components/molecules/confirm-dialog.tsx +9 -0
  22. package/src/components/molecules/count-badge.tsx +115 -0
  23. package/src/components/molecules/data-table/data-table-filters.tsx +61 -21
  24. package/src/components/molecules/data-table/data-table-helpers.tsx +26 -1
  25. package/src/components/molecules/data-table/data-table-types.tsx +66 -2
  26. package/src/components/molecules/data-table/data-table.tsx +190 -35
  27. package/src/components/molecules/direction-link.tsx +1 -1
  28. package/src/components/molecules/format-provider.tsx +12 -2
  29. package/src/components/molecules/page-header.tsx +1 -1
  30. package/src/components/molecules/search-trigger.tsx +2 -18
  31. package/src/components/molecules/secret-value.tsx +6 -3
  32. package/src/components/molecules/state-views/loading-state.tsx +37 -7
  33. package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
  34. package/src/components/molecules/status-badge.tsx +2 -2
  35. package/src/components/molecules/timeline.tsx +1 -1
  36. package/src/hooks/use-active-label-size.ts +39 -5
  37. package/src/hooks/use-apple-platform.ts +26 -0
  38. package/src/lib/utils.ts +0 -7
@@ -78,14 +78,34 @@ function DialogCloseButton({ className }: { className?: string }) {
78
78
  )
79
79
  }
80
80
 
81
+ // The width per size, as whole class strings so Tailwind finds them in this
82
+ // source. They sit before `className` in `cn`, so a consumer's `sm:max-w-*`
83
+ // still replaces them. Below the breakpoint a dialog is the viewport less 1rem
84
+ // on each side: `xl` waits for `lg`, where 800px fits with that margin.
85
+ const dialogSizes = {
86
+ default: "sm:max-w-110",
87
+ lg: "sm:max-w-140",
88
+ xl: "lg:max-w-200",
89
+ full: "",
90
+ } as const
91
+
81
92
  function DialogContent({
82
93
  className,
83
94
  children,
95
+ size = "default",
84
96
  showCloseButton,
85
97
  overlayClassName,
86
98
  style,
87
99
  ...props
88
100
  }: DialogPrimitive.Popup.Props & {
101
+ /**
102
+ * The width, by the dialog's job. `default` (440px): a confirmation or a
103
+ * form of a few fields. `lg` (560px): a form with longer fields or a short
104
+ * list. `xl` (800px): a wide form, a table or a tree. `full`: the viewport
105
+ * less 1rem on each side, for a picker or a preview. Every size shrinks to
106
+ * the viewport less that margin on a small screen.
107
+ */
108
+ size?: keyof typeof dialogSizes
89
109
  /**
90
110
  * Shows a ✕ in the top-right corner. Left out, the dialog shows it only
91
111
  * when it holds no `DialogFooter` and no `DialogClose`: a dialog with a
@@ -115,8 +135,10 @@ function DialogContent({
115
135
  <DialogPrimitive.Popup
116
136
  dir={dir}
117
137
  data-slot="dialog-content"
138
+ data-size={size}
118
139
  className={cn(
119
- "group/dialog-content bg-overlay shadow-overlay fixed top-1/2 left-1/2 z-50 grid grid-cols-[minmax(0,1fr)] max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-5 overflow-y-auto overscroll-contain rounded-2xl [--dialog-padding:--spacing(5)] p-(--dialog-padding) [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] text-sm transition-[opacity,scale,translate] duration-[var(--transition-duration-normal),var(--transition-duration-dialog-enter),var(--transition-duration-dialog-enter)] ease-out data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-[var(--transition-duration-quick),var(--transition-duration-dialog-exit),var(--transition-duration-dialog-exit)] data-ending-style:ease-[var(--ease-soft),var(--ease-out),var(--ease-out)] motion-safe:data-starting-style:scale-96 motion-safe:data-starting-style:translate-y-[calc(-50%+4px)] motion-safe:data-ending-style:scale-98 outline-none sm:max-w-110",
140
+ "group/dialog-content bg-overlay shadow-overlay fixed top-1/2 left-1/2 z-50 grid grid-cols-[minmax(0,1fr)] max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-5 overflow-y-auto overscroll-contain rounded-2xl [--dialog-padding:--spacing(5)] p-(--dialog-padding) [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] text-sm transition-[opacity,scale,translate] duration-[var(--transition-duration-normal),var(--transition-duration-dialog-enter),var(--transition-duration-dialog-enter)] ease-out data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-[var(--transition-duration-quick),var(--transition-duration-dialog-exit),var(--transition-duration-dialog-exit)] data-ending-style:ease-[var(--ease-soft),var(--ease-out),var(--ease-out)] motion-safe:data-starting-style:scale-96 motion-safe:data-starting-style:translate-y-[calc(-50%+4px)] motion-safe:data-ending-style:scale-98 outline-none",
141
+ dialogSizes[size],
120
142
  className
121
143
  )}
122
144
  style={dialogPaddingStyle(className, style)}
@@ -63,7 +63,7 @@ function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
63
63
  return (
64
64
  <div
65
65
  data-slot="empty-title"
66
- className={cn("text-style-section-title", className)}
66
+ className={cn("text-style-section-title text-foreground", className)}
67
67
  {...props}
68
68
  />
69
69
  )
@@ -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}
@@ -78,10 +78,10 @@ const inputGroupButtonVariants = cva(
78
78
  {
79
79
  variants: {
80
80
  size: {
81
- xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
81
+ xs: "h-6 gap-1 rounded-lg px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
82
82
  sm: "h-7 gap-1.5 px-2.5",
83
83
  "icon-xs":
84
- "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
84
+ "size-6 rounded-lg p-0 has-[>svg]:p-0",
85
85
  "icon-sm": "size-7 p-0 has-[>svg]:p-0",
86
86
  },
87
87
  },
@@ -24,6 +24,34 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
24
24
  timing: keyof typeof TIMINGS
25
25
  /** Classes for each label, after the shared ones. */
26
26
  labelClassName?: string
27
+ /**
28
+ * The swap may shrink below the active label's width, and the label then
29
+ * ends in an ellipsis. The swap still eases to the label's full width; its
30
+ * container (a flex row with `min-w-0`) decides how much of it shows.
31
+ */
32
+ truncate?: boolean
33
+ /**
34
+ * Changes when the active label's text changes at the same index, such as
35
+ * a placeholder that becomes the first loaded option. The swap then
36
+ * measures again: a cut label's box does not grow by itself.
37
+ */
38
+ activeKey?: string
39
+ }
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 }
27
55
  }
28
56
 
29
57
  /**
@@ -36,25 +64,51 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
36
64
  * the swap eases to the active label's width and height on the drawer curve.
37
65
  * The size follows the label while it is active (see `useActiveLabelSize`).
38
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.
39
69
  */
40
70
  function LabelSwap({
41
71
  labels,
42
72
  active,
43
73
  timing,
44
74
  labelClassName,
75
+ truncate = false,
76
+ activeKey,
45
77
  className,
46
78
  style,
47
79
  ...props
48
80
  }: LabelSwapProps) {
49
- const { refs, width, height } = useActiveLabelSize(active)
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
88
+ // While the width eases, a growing label is clipped, as without
89
+ // `truncate`; the ellipsis shows only at rest, so it does not flash.
90
+ const [resizing, setResizing] = React.useState(false)
91
+ const onResize = (running: boolean) => (event: React.TransitionEvent<HTMLSpanElement>) => {
92
+ if (event.target === event.currentTarget && event.propertyName === "width") setResizing(running)
93
+ }
94
+ const resizeHandlers = truncate
95
+ ? {
96
+ onTransitionRun: onResize(true),
97
+ onTransitionEnd: onResize(false),
98
+ onTransitionCancel: onResize(false),
99
+ }
100
+ : undefined
50
101
  return (
51
102
  <span
103
+ data-resizing={resizing ? "" : undefined}
104
+ {...resizeHandlers}
52
105
  className={cn(
53
106
  "grid grid-cols-[100%] justify-items-center motion-safe:transition-[width,height] motion-safe:duration-(--label-swap-resize) motion-safe:ease-drawer",
54
107
  TIMINGS[timing],
108
+ truncate && "min-w-0 shrink",
55
109
  className
56
110
  )}
57
- style={width === undefined ? style : { ...style, width, height }}
111
+ style={width === undefined ? { ...style, ...still } : { ...style, ...still, width, height }}
58
112
  {...props}
59
113
  >
60
114
  {labels.map((label, index) => (
@@ -65,9 +119,11 @@ function LabelSwap({
65
119
  refs.current[index] = element
66
120
  }}
67
121
  data-swap={index === active ? "in" : index < active ? "before" : "after"}
122
+ style={still}
68
123
  aria-hidden={index === active ? undefined : true}
69
124
  className={cn(
70
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]",
126
+ truncate && "max-w-full truncate in-data-resizing:text-clip",
71
127
  labelClassName
72
128
  )}
73
129
  >
@@ -78,5 +134,5 @@ function LabelSwap({
78
134
  )
79
135
  }
80
136
 
81
- export { LabelSwap }
137
+ export { LabelSwap, nextShown }
82
138
  export type { LabelSwapProps }
@@ -28,6 +28,9 @@ function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props) {
28
28
  * it up with its left edge. The side is picked each time it opens. A popover
29
29
  * that opens to the left or right of its trigger keeps "start". An explicit
30
30
  * `align` always wins. Do not set `align` unless there is a reason.
31
+ *
32
+ * `anchor` positions a popover that has no trigger against another element,
33
+ * e.g. an editor opened from an applied-filter chip.
31
34
  */
32
35
  function PopoverContent({
33
36
  className,
@@ -36,11 +39,12 @@ function PopoverContent({
36
39
  alignOffset = 0,
37
40
  side = "bottom",
38
41
  sideOffset = 6,
42
+ anchor,
39
43
  ...props
40
44
  }: PopoverPrimitive.Popup.Props &
41
45
  Pick<
42
46
  PopoverPrimitive.Positioner.Props,
43
- "align" | "alignOffset" | "side" | "sideOffset"
47
+ "align" | "alignOffset" | "side" | "sideOffset" | "anchor"
44
48
  >) {
45
49
  const dir = usePopupDir()
46
50
  const { popupRef, align: positionAlign } = usePopupAlign(align, side, ref)
@@ -52,6 +56,7 @@ function PopoverContent({
52
56
  alignOffset={alignOffset}
53
57
  side={side}
54
58
  sideOffset={sideOffset}
59
+ anchor={anchor}
55
60
  className="isolate z-50"
56
61
  >
57
62
  <PopoverPrimitive.Popup
@@ -62,14 +62,29 @@ function SheetCloseButton({ className }: { className?: string }) {
62
62
  )
63
63
  }
64
64
 
65
+ // The width of a left or right sheet per size, as whole class strings so
66
+ // Tailwind finds them in this source. A top or bottom sheet spans the viewport
67
+ // and ignores the size. Below `sm` every side sheet is 3/4 of the viewport.
68
+ const sheetSizes = {
69
+ default: "data-[side=left]:sm:max-w-lg data-[side=right]:sm:max-w-lg",
70
+ xl: "data-[side=left]:sm:max-w-200 data-[side=right]:sm:max-w-200",
71
+ } as const
72
+
65
73
  function SheetContent({
66
74
  className,
67
75
  children,
68
76
  side = "right",
77
+ size = "default",
69
78
  showCloseButton = true,
70
79
  ...props
71
80
  }: SheetPrimitive.Popup.Props & {
72
81
  side?: "top" | "right" | "bottom" | "left"
82
+ /**
83
+ * The width of a left or right sheet. `default` (512px): a short form or a
84
+ * settings list. `xl` (800px): a table or a wide form. Both stay at 3/4 of
85
+ * the viewport below 640px. Top and bottom sheets ignore it.
86
+ */
87
+ size?: keyof typeof sheetSizes
73
88
  showCloseButton?: boolean
74
89
  }) {
75
90
  const dir = usePopupDir()
@@ -81,8 +96,10 @@ function SheetContent({
81
96
  dir={dir}
82
97
  data-slot="sheet-content"
83
98
  data-side={side}
99
+ data-size={size}
84
100
  className={cn(
85
- "group/sheet-content bg-overlay fixed z-50 flex flex-col gap-4 overflow-y-auto overscroll-contain [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] bg-clip-padding text-sm shadow-overlay transition-[opacity,translate] duration-normal ease-drawer data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-fast motion-safe:data-[side=right]:data-starting-style:translate-x-10 motion-safe:data-[side=right]:data-ending-style:translate-x-10 motion-safe:data-[side=left]:data-starting-style:-translate-x-10 motion-safe:data-[side=left]:data-ending-style:-translate-x-10 motion-safe:data-[side=top]:data-starting-style:-translate-y-10 motion-safe:data-[side=top]:data-ending-style:-translate-y-10 motion-safe:data-[side=bottom]:data-starting-style:translate-y-10 motion-safe:data-[side=bottom]:data-ending-style:translate-y-10 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:max-h-dvh data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:max-h-dvh data-[side=left]:sm:max-w-lg data-[side=right]:sm:max-w-lg",
101
+ "group/sheet-content bg-overlay fixed z-50 flex flex-col gap-4 overflow-y-auto overscroll-contain [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] bg-clip-padding text-sm shadow-overlay transition-[opacity,translate] duration-normal ease-drawer data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-fast motion-safe:data-[side=right]:data-starting-style:translate-x-10 motion-safe:data-[side=right]:data-ending-style:translate-x-10 motion-safe:data-[side=left]:data-starting-style:-translate-x-10 motion-safe:data-[side=left]:data-ending-style:-translate-x-10 motion-safe:data-[side=top]:data-starting-style:-translate-y-10 motion-safe:data-[side=top]:data-ending-style:-translate-y-10 motion-safe:data-[side=bottom]:data-starting-style:translate-y-10 motion-safe:data-[side=bottom]:data-ending-style:translate-y-10 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:max-h-dvh data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:max-h-dvh",
102
+ sheetSizes[size],
86
103
  className
87
104
  )}
88
105
  {...props}
@@ -23,7 +23,7 @@ import {
23
23
  TooltipContent,
24
24
  TooltipTrigger,
25
25
  } from "@vendure-io/ui/components/atoms/tooltip"
26
- import { ChevronLeftIcon, PanelLeftIcon } from "lucide-react"
26
+ import { ChevronLeftIcon, ChevronsUpDownIcon, PanelLeftIcon } from "lucide-react"
27
27
 
28
28
  const SIDEBAR_COOKIE_NAME = "sidebar_state"
29
29
  const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
@@ -705,6 +705,76 @@ function SidebarMenuButton({
705
705
  )
706
706
  }
707
707
 
708
+ // The account or user switch at the top or bottom of the sidebar: media (an
709
+ // Avatar), a SidebarIdentityText (a title over a caption) and an up/down
710
+ // chevron. Render it as the trigger of the menu it opens:
711
+ // <DropdownMenuTrigger render={<SidebarIdentityButton />}>. It takes the fill
712
+ // while that menu is open: a Base UI trigger marks that with data-popup-open,
713
+ // not data-open. The muted avatar fill is translucent and darkens on that fill,
714
+ // so default initials take the sidebar text colour to keep their contrast. A
715
+ // fallback with its own colour (no text-muted-foreground) keeps it. In the
716
+ // icon rail the text and the chevron fade like a label and the media stays;
717
+ // both stay mounted, so the button keeps its accessible name in the rail.
718
+ function SidebarIdentityButton({
719
+ className,
720
+ children,
721
+ ...props
722
+ }: Omit<React.ComponentProps<typeof SidebarMenuButton>, "size">) {
723
+ return (
724
+ <SidebarMenuButton
725
+ size="lg"
726
+ className={cn(
727
+ "data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground [&_[data-slot=avatar-fallback].text-muted-foreground]:text-sidebar-foreground",
728
+ className
729
+ )}
730
+ {...props}
731
+ >
732
+ {children}
733
+ <ChevronsUpDownIcon
734
+ data-slot="sidebar-identity-chevron"
735
+ aria-hidden="true"
736
+ className="text-muted-foreground ms-auto transition-opacity duration-moderate group-data-[collapsible=icon]:opacity-0 group-data-[collapsible=icon]:duration-fast"
737
+ />
738
+ </SidebarMenuButton>
739
+ )
740
+ }
741
+
742
+ // The two lines of a SidebarIdentityButton. Also fits the identity row at the
743
+ // top of the menu it opens. The text fades in the icon rail even when the
744
+ // title holds an icon, which the generic label fade of SidebarMenuButton skips.
745
+ function SidebarIdentityText({
746
+ title,
747
+ caption,
748
+ className,
749
+ ...props
750
+ }: Omit<React.ComponentProps<"span">, "title" | "children"> & {
751
+ title: React.ReactNode
752
+ caption?: React.ReactNode
753
+ }) {
754
+ return (
755
+ <span
756
+ data-slot="sidebar-identity-text"
757
+ className={cn(
758
+ "grid min-w-0 flex-1 text-start text-sm leading-tight transition-opacity duration-moderate group-data-[collapsible=icon]:opacity-0 group-data-[collapsible=icon]:duration-fast",
759
+ className
760
+ )}
761
+ {...props}
762
+ >
763
+ <span data-slot="sidebar-identity-title" className="truncate font-semibold">
764
+ {title}
765
+ </span>
766
+ {caption ? (
767
+ <span
768
+ data-slot="sidebar-identity-caption"
769
+ className="text-muted-foreground truncate text-xs font-normal"
770
+ >
771
+ {caption}
772
+ </span>
773
+ ) : null}
774
+ </span>
775
+ )
776
+ }
777
+
708
778
  function SidebarMenuAction({
709
779
  className,
710
780
  render,
@@ -1028,6 +1098,8 @@ export {
1028
1098
  SidebarGroupContent,
1029
1099
  SidebarGroupLabel,
1030
1100
  SidebarHeader,
1101
+ SidebarIdentityButton,
1102
+ SidebarIdentityText,
1031
1103
  SidebarInput,
1032
1104
  SidebarInset,
1033
1105
  SidebarLevel,
@@ -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
  )}
@@ -18,11 +18,11 @@ const InTooltipProvider = React.createContext(false)
18
18
  * not import the tokens package at runtime; tooltip.test.ts keeps the two
19
19
  * equal.
20
20
  */
21
- const TOOLTIP_DELAY = 600
21
+ const TOOLTIP_DELAY = 350
22
22
 
23
23
  /**
24
24
  * Wrap the app in one TooltipProvider. The first tooltip then waits
25
- * `tooltip-delay` (600ms), so a pointer that only passes over a trigger opens
25
+ * `tooltip-delay` (350ms), so a pointer that only passes over a trigger opens
26
26
  * nothing. Once a tooltip is open, the next one opens at once and does not
27
27
  * animate, until no tooltip has been open for the provider's `timeout`.
28
28
  */
@@ -47,7 +47,7 @@ function Tooltip({ ...props }: TooltipPrimitive.Root.Props) {
47
47
 
48
48
  /**
49
49
  * Inside a TooltipProvider it leaves `delay` unset, so the provider's delay
50
- * applies. Without a provider the delay is `tooltip-delay` (600ms) too, so a
50
+ * applies. Without a provider the delay is `tooltip-delay` (350ms) too, so a
51
51
  * pointer that only passes over a trigger opens nothing. An explicit `delay`
52
52
  * wins in both cases. A provider is what lets the next tooltips open at once.
53
53
  */