@vendure-io/ui 2.1.0 → 3.0.0-next.0

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 (118) hide show
  1. package/package.json +19 -5
  2. package/src/components/atoms/accordion.tsx +21 -6
  3. package/src/components/atoms/alert-dialog.tsx +31 -6
  4. package/src/components/atoms/alert.tsx +73 -13
  5. package/src/components/atoms/avatar.tsx +1 -1
  6. package/src/components/atoms/badge.tsx +7 -2
  7. package/src/components/atoms/breadcrumb.tsx +137 -4
  8. package/src/components/atoms/button-group.tsx +30 -6
  9. package/src/components/atoms/button.tsx +128 -18
  10. package/src/components/atoms/calendar.tsx +6 -6
  11. package/src/components/atoms/card.tsx +130 -16
  12. package/src/components/atoms/carousel.tsx +16 -9
  13. package/src/components/atoms/chart.tsx +87 -1
  14. package/src/components/atoms/checkbox.tsx +85 -7
  15. package/src/components/atoms/collapsible.tsx +2 -1
  16. package/src/components/atoms/combobox.tsx +147 -21
  17. package/src/components/atoms/command.tsx +414 -12
  18. package/src/components/atoms/context-menu.tsx +28 -23
  19. package/src/components/atoms/dialog.tsx +151 -29
  20. package/src/components/atoms/direction.tsx +23 -2
  21. package/src/components/atoms/drawer.tsx +15 -10
  22. package/src/components/atoms/dropdown-menu.tsx +43 -28
  23. package/src/components/atoms/empty.tsx +4 -0
  24. package/src/components/atoms/field.tsx +41 -15
  25. package/src/components/atoms/hover-card.tsx +61 -8
  26. package/src/components/atoms/input-group.tsx +17 -9
  27. package/src/components/atoms/input-otp.tsx +6 -6
  28. package/src/components/atoms/input.tsx +7 -1
  29. package/src/components/atoms/item.tsx +3 -3
  30. package/src/components/atoms/kbd.tsx +32 -3
  31. package/src/components/atoms/label-swap.tsx +82 -0
  32. package/src/components/atoms/label.tsx +1 -1
  33. package/src/components/atoms/menubar.tsx +28 -26
  34. package/src/components/atoms/native-select.tsx +3 -2
  35. package/src/components/atoms/navigation-menu.tsx +13 -8
  36. package/src/components/atoms/pagination.tsx +2 -2
  37. package/src/components/atoms/popover.tsx +23 -5
  38. package/src/components/atoms/progress.tsx +46 -33
  39. package/src/components/atoms/radio-group.tsx +9 -4
  40. package/src/components/atoms/resizable.tsx +1 -1
  41. package/src/components/atoms/scroll-area.tsx +2 -2
  42. package/src/components/atoms/select.tsx +258 -19
  43. package/src/components/atoms/sheet.tsx +59 -23
  44. package/src/components/atoms/sidebar.tsx +333 -23
  45. package/src/components/atoms/skeleton.tsx +1 -1
  46. package/src/components/atoms/slider.tsx +1 -1
  47. package/src/components/atoms/sonner.tsx +128 -38
  48. package/src/components/atoms/spinner.tsx +1 -1
  49. package/src/components/atoms/switch.tsx +10 -5
  50. package/src/components/atoms/table.tsx +147 -7
  51. package/src/components/atoms/tabs.tsx +3 -3
  52. package/src/components/atoms/textarea.tsx +3 -1
  53. package/src/components/atoms/toggle-group.tsx +4 -2
  54. package/src/components/atoms/toggle.tsx +28 -6
  55. package/src/components/atoms/tooltip.tsx +85 -15
  56. package/src/components/molecules/anonymized-token.tsx +24 -8
  57. package/src/components/molecules/app-shell.tsx +53 -20
  58. package/src/components/molecules/arrow-link.tsx +40 -0
  59. package/src/components/molecules/chip.tsx +2 -2
  60. package/src/components/molecules/code-block.tsx +54 -31
  61. package/src/components/molecules/collapsible-section.tsx +129 -0
  62. package/src/components/molecules/confirm-dialog.tsx +113 -9
  63. package/src/components/molecules/copyable-text.tsx +75 -11
  64. package/src/components/molecules/data-table/data-table-bulk-actions.tsx +32 -4
  65. package/src/components/molecules/data-table/data-table-column-header.tsx +20 -3
  66. package/src/components/molecules/data-table/data-table-filters.tsx +1 -1
  67. package/src/components/molecules/data-table/data-table-helpers.tsx +68 -1
  68. package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
  69. package/src/components/molecules/data-table/data-table-types.tsx +138 -4
  70. package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
  71. package/src/components/molecules/data-table/data-table.tsx +916 -84
  72. package/src/components/molecules/data-table/table-pagination.tsx +2 -2
  73. package/src/components/molecules/date-picker.tsx +13 -7
  74. package/src/components/molecules/date-range-picker.tsx +13 -6
  75. package/src/components/molecules/date-time-picker.tsx +13 -7
  76. package/src/components/molecules/date-time.tsx +8 -1
  77. package/src/components/molecules/direction-link.tsx +130 -0
  78. package/src/components/molecules/elapsed-time.tsx +223 -0
  79. package/src/components/molecules/file-dropzone.tsx +2 -2
  80. package/src/components/molecules/id-chip.tsx +169 -32
  81. package/src/components/molecules/inline-code.tsx +4 -0
  82. package/src/components/molecules/issued-secret.tsx +318 -0
  83. package/src/components/molecules/list-row.tsx +349 -0
  84. package/src/components/molecules/live-indicator.tsx +83 -0
  85. package/src/components/molecules/page-header.tsx +117 -5
  86. package/src/components/molecules/password-input.tsx +2 -2
  87. package/src/components/molecules/relative-time.tsx +85 -56
  88. package/src/components/molecules/search-trigger.tsx +127 -0
  89. package/src/components/molecules/secret-value.tsx +26 -9
  90. package/src/components/molecules/skip-link.tsx +1 -1
  91. package/src/components/molecules/stat-card.tsx +4 -4
  92. package/src/components/molecules/state-views/empty-state.tsx +35 -17
  93. package/src/components/molecules/state-views/error-state.tsx +32 -14
  94. package/src/components/molecules/status-badge.tsx +415 -49
  95. package/src/components/molecules/time-tooltip.tsx +140 -0
  96. package/src/components/molecules/timeline.tsx +246 -0
  97. package/src/components/molecules/visibility-icon.tsx +89 -0
  98. package/src/hooks/use-active-label-size.ts +32 -0
  99. package/src/hooks/use-pinned-height.ts +55 -0
  100. package/src/hooks/use-scrolled.ts +27 -0
  101. package/src/lib/content-inset.ts +17 -0
  102. package/src/lib/control-name.ts +55 -0
  103. package/src/lib/dialog-padding.ts +48 -0
  104. package/src/lib/field-surface.ts +31 -0
  105. package/src/lib/format-elapsed.ts +67 -0
  106. package/src/lib/format-relative.ts +29 -1
  107. package/src/lib/highlight.ts +3 -3
  108. package/src/lib/menu-item.tsx +72 -0
  109. package/src/lib/outline-edge.ts +21 -0
  110. package/src/lib/popup-align.ts +67 -0
  111. package/src/lib/popup-direction.ts +22 -0
  112. package/src/lib/popup-motion.ts +19 -0
  113. package/src/lib/state-dictionary.ts +42 -6
  114. package/src/lib/syntax-colors.ts +8 -0
  115. package/src/lib/tint-recipes.ts +68 -0
  116. package/src/lib/tone-icons.ts +24 -0
  117. package/src/lib/trigger-slot.ts +16 -0
  118. package/src/lib/utils.ts +104 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendure-io/ui",
3
- "version": "2.1.0",
3
+ "version": "3.0.0-next.0",
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",
@@ -13,27 +13,41 @@
13
13
  "sideEffects": false,
14
14
  "exports": {
15
15
  "./components/atoms/*": "./src/components/atoms/*.tsx",
16
+ "./components/atoms/label-swap": null,
16
17
  "./components/molecules/*": "./src/components/molecules/*.tsx",
17
18
  "./components/molecules/code-block/*": null,
18
19
  "./components/molecules/data-table/data-table-helpers": null,
20
+ "./components/molecules/data-table/data-table-selection-storage": null,
21
+ "./components/molecules/direction-link": null,
22
+ "./components/molecules/time-tooltip": null,
19
23
  "./lib/*": "./src/lib/*.ts",
20
- "./hooks/*": "./src/hooks/*.ts"
24
+ "./lib/control-name": null,
25
+ "./lib/dialog-padding": null,
26
+ "./lib/menu-item": null,
27
+ "./lib/popup-align": null,
28
+ "./lib/popup-direction": null,
29
+ "./lib/popup-motion": null,
30
+ "./lib/trigger-slot": null,
31
+ "./hooks/*": "./src/hooks/*.ts",
32
+ "./hooks/use-active-label-size": null,
33
+ "./hooks/use-pinned-height": null
21
34
  },
22
35
  "files": [
23
36
  "src",
24
37
  "!src/**/*.test.ts",
25
38
  "!src/**/*.test.tsx",
39
+ "!src/test",
26
40
  "README.md",
27
41
  "LICENSE.md"
28
42
  ],
29
43
  "scripts": {
30
- "lint": "biome check src/",
31
- "check-types": "tsc --noEmit && tsc --noEmit -p tsconfig.stories.json",
44
+ "lint": "biome check src/ guidance/",
45
+ "check-types": "tsc --noEmit && tsc --noEmit -p tsconfig.consumer-lib.json && tsc --noEmit -p tsconfig.stories.json",
32
46
  "test": "bun test",
33
47
  "pack:check": "bun pm pack --dry-run"
34
48
  },
35
49
  "peerDependencies": {
36
- "@vendure-io/design-tokens": "^2.0.0",
50
+ "@vendure-io/design-tokens": "^3.0.0-next.0",
37
51
  "react": ">=19",
38
52
  "react-dom": ">=19",
39
53
  "next": ">=14",
@@ -3,7 +3,7 @@
3
3
  import { Accordion as AccordionPrimitive } from "@base-ui/react/accordion"
4
4
 
5
5
  import { cn } from "@vendure-io/ui/lib/utils"
6
- import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
6
+ import { ChevronDownIcon } from "lucide-react"
7
7
 
8
8
  function Accordion({ className, ...props }: AccordionPrimitive.Root.Props) {
9
9
  return (
@@ -25,6 +25,13 @@ function AccordionItem({ className, ...props }: AccordionPrimitive.Item.Props) {
25
25
  )
26
26
  }
27
27
 
28
+ /**
29
+ * The header of an item: one full-width button with the title and a down
30
+ * chevron. The chevron sits 2px down, centred on the title's first 20px line,
31
+ * so it stays on that line when the title wraps. A closed trigger fills on
32
+ * hover. The chevron turns over on the panel's height timing, so both settle
33
+ * together; its colour follows the hover on the fill's timing.
34
+ */
28
35
  function AccordionTrigger({
29
36
  className,
30
37
  children,
@@ -35,19 +42,27 @@ function AccordionTrigger({
35
42
  <AccordionPrimitive.Trigger
36
43
  data-slot="accordion-trigger"
37
44
  className={cn(
38
- "focus-visible:ring-ring/50 focus-visible:border-ring focus-visible:after:border-ring **:data-[slot=accordion-trigger-icon]:text-muted-foreground group/accordion-trigger relative flex flex-1 items-start justify-between rounded-md border border-transparent py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-3 aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4",
45
+ "focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring **:data-[slot=accordion-trigger-icon]:text-muted-foreground group/accordion-trigger relative flex flex-1 cursor-pointer items-start justify-between rounded-md border border-transparent px-3 py-4 text-start text-sm font-medium outline-none transition-colors duration-fast ease-default not-aria-expanded:hover:bg-muted aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:mt-0.5",
39
46
  className
40
47
  )}
41
48
  {...props}
42
49
  >
43
50
  {children}
44
- <ChevronDownIcon data-slot="accordion-trigger-icon" className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden" />
45
- <ChevronUpIcon data-slot="accordion-trigger-icon" className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline" />
51
+ <ChevronDownIcon
52
+ data-slot="accordion-trigger-icon"
53
+ aria-hidden="true"
54
+ className="pointer-events-none shrink-0 [transition:rotate_var(--transition-duration-slow)_var(--ease-height),color_var(--transition-duration-fast)_var(--ease-default)] group-hover/accordion-trigger:text-foreground group-aria-expanded/accordion-trigger:rotate-180 motion-reduce:[transition:color_var(--transition-duration-fast)_var(--ease-default)]"
55
+ />
46
56
  </AccordionPrimitive.Trigger>
47
57
  </AccordionPrimitive.Header>
48
58
  )
49
59
  }
50
60
 
61
+ /**
62
+ * The panel eases its height and opacity with CSS transitions, so a second
63
+ * click mid-way reverses from where the panel is. Under reduced motion the
64
+ * height snaps and only a short fade remains.
65
+ */
51
66
  function AccordionContent({
52
67
  className,
53
68
  children,
@@ -56,12 +71,12 @@ function AccordionContent({
56
71
  return (
57
72
  <AccordionPrimitive.Panel
58
73
  data-slot="accordion-content"
59
- className="data-open:animate-accordion-down data-closed:animate-accordion-up overflow-hidden text-sm"
74
+ className="h-(--accordion-panel-height) overflow-hidden text-sm data-starting-style:h-0 data-starting-style:opacity-0 data-ending-style:h-0 data-ending-style:opacity-0 motion-safe:transition-[height,opacity] motion-safe:duration-slow motion-safe:ease-height motion-reduce:transition-opacity motion-reduce:data-ending-style:h-(--accordion-panel-height) motion-reduce:duration-fast motion-reduce:ease-default"
60
75
  {...props}
61
76
  >
62
77
  <div
63
78
  className={cn(
64
- "[&_a]:hover:text-foreground h-(--accordion-panel-height) pt-0 pb-4 data-ending-style:h-0 data-starting-style:h-0 [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
79
+ "[&_a]:hover:text-foreground px-3 pt-0 pb-4 [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
65
80
  className
66
81
  )}
67
82
  >
@@ -5,6 +5,10 @@ import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog
5
5
 
6
6
  import { cn } from "@vendure-io/ui/lib/utils"
7
7
  import { Button } from "@vendure-io/ui/components/atoms/button"
8
+ import { usePopupDir } from "../../lib/popup-direction.ts"
9
+ import { dialogPaddingStyle } from "../../lib/dialog-padding.ts"
10
+ import { usePinnedHeight } from "../../hooks/use-pinned-height.ts"
11
+ import { triggerSlot } from "../../lib/trigger-slot.ts"
8
12
 
9
13
  function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props) {
10
14
  return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
@@ -12,7 +16,7 @@ function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props) {
12
16
 
13
17
  function AlertDialogTrigger({ ...props }: AlertDialogPrimitive.Trigger.Props) {
14
18
  return (
15
- <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
19
+ <AlertDialogPrimitive.Trigger {...triggerSlot("alert-dialog-trigger", props.render)} {...props} />
16
20
  )
17
21
  }
18
22
 
@@ -30,7 +34,7 @@ function AlertDialogOverlay({
30
34
  <AlertDialogPrimitive.Backdrop
31
35
  data-slot="alert-dialog-overlay"
32
36
  className={cn(
33
- "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 fixed inset-0 isolate z-50 bg-scrim motion-reduce:animate-none data-open:duration-(--transition-duration-normal) data-open:ease-(--ease-out) data-closed:duration-(--transition-duration-fast) data-closed:ease-(--ease-in) supports-backdrop-filter:backdrop-blur-xs",
37
+ "fixed inset-0 isolate z-50 bg-scrim transition-opacity duration-dialog-scrim ease-soft data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-dialog-exit supports-backdrop-filter:backdrop-blur-[2px]",
34
38
  className
35
39
  )}
36
40
  {...props}
@@ -41,35 +45,51 @@ function AlertDialogOverlay({
41
45
  function AlertDialogContent({
42
46
  className,
43
47
  size = "default",
48
+ style,
44
49
  ...props
45
50
  }: AlertDialogPrimitive.Popup.Props & {
46
51
  size?: "default" | "sm"
47
52
  }) {
53
+ const dir = usePopupDir()
48
54
  return (
49
55
  <AlertDialogPortal>
50
56
  <AlertDialogOverlay />
57
+ {/* At most the viewport height less 1rem on each side. A taller dialog scrolls inside; the header and the footer stick to its edges, as in DialogContent. The padding is `--dialog-padding`, which a `p-*` or `px-*` class also sets (dialogPaddingStyle), and the scroll padding keeps a focused field clear of the header and the footer. */}
51
58
  <AlertDialogPrimitive.Popup
59
+ dir={dir}
52
60
  data-slot="alert-dialog-content"
53
61
  data-size={size}
54
62
  className={cn(
55
- "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-overlay ring-foreground/10 group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-6 rounded-xl p-6 ring-1 motion-reduce:animate-none data-open:duration-(--transition-duration-normal) data-open:ease-(--ease-out) data-closed:duration-(--transition-duration-fast) data-closed:ease-(--ease-in) outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-lg",
63
+ "bg-overlay shadow-overlay group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid grid-cols-[minmax(0,1fr)] max-h-[calc(100dvh-2rem)] w-full -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))] 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 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-110",
56
64
  className
57
65
  )}
66
+ style={dialogPaddingStyle(className, style)}
58
67
  {...props}
59
68
  />
60
69
  </AlertDialogPortal>
61
70
  )
62
71
  }
63
72
 
73
+ // The header and the footer reach over the padding (`--dialog-padding`) and
74
+ // 16px of the 20px gap, with the surface behind, so a scrolled body passes
75
+ // under them. The margins cancel the paddings, and the negative offsets account
76
+ // for a sticky box sticking inside the padding. See DialogHeader.
77
+ const pinned = "sticky z-10 -mx-(--dialog-padding) bg-overlay px-(--dialog-padding)"
78
+
64
79
  function AlertDialogHeader({
65
80
  className,
81
+ ref,
66
82
  ...props
67
83
  }: React.ComponentProps<"div">) {
84
+ const pinnedRef = usePinnedHeight("--pinned-header-height", "alert-dialog-content", ref)
68
85
  return (
69
86
  <div
87
+ ref={pinnedRef}
70
88
  data-slot="alert-dialog-header"
71
89
  className={cn(
72
- "grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
90
+ pinned,
91
+ "-top-(--dialog-padding) -mt-(--dialog-padding) -mb-4 pt-(--dialog-padding) pb-4",
92
+ "grid grid-rows-[auto_1fr] place-items-center gap-2.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-start sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
73
93
  className
74
94
  )}
75
95
  {...props}
@@ -79,12 +99,17 @@ function AlertDialogHeader({
79
99
 
80
100
  function AlertDialogFooter({
81
101
  className,
102
+ ref,
82
103
  ...props
83
104
  }: React.ComponentProps<"div">) {
105
+ const pinnedRef = usePinnedHeight("--pinned-footer-height", "alert-dialog-content", ref)
84
106
  return (
85
107
  <div
108
+ ref={pinnedRef}
86
109
  data-slot="alert-dialog-footer"
87
110
  className={cn(
111
+ pinned,
112
+ "-bottom-(--dialog-padding) -mt-4 -mb-(--dialog-padding) pt-4 pb-(--dialog-padding)",
88
113
  "flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
89
114
  className
90
115
  )}
@@ -117,7 +142,7 @@ function AlertDialogTitle({
117
142
  <AlertDialogPrimitive.Title
118
143
  data-slot="alert-dialog-title"
119
144
  className={cn(
120
- "text-style-section-title sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
145
+ "text-style-dialog-title sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
121
146
  className
122
147
  )}
123
148
  {...props}
@@ -133,7 +158,7 @@ function AlertDialogDescription({
133
158
  <AlertDialogPrimitive.Description
134
159
  data-slot="alert-dialog-description"
135
160
  className={cn(
136
- "text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",
161
+ "text-foreground-secondary *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3",
137
162
  className
138
163
  )}
139
164
  {...props}
@@ -2,19 +2,46 @@ import * as React from "react"
2
2
  import { cva, type VariantProps } from "class-variance-authority"
3
3
 
4
4
  import { cn } from "@vendure-io/ui/lib/utils"
5
+ import { alertTint, alertToneVars } from "@vendure-io/ui/lib/tint-recipes"
6
+ import { toneIcons } from "@vendure-io/ui/lib/tone-icons"
5
7
 
8
+ // Alert is an inline-size container so AlertAction can move under the text when
9
+ // the alert is narrow. A container cannot size to its content: an Alert inside a
10
+ // flex row needs a width (it is w-full by default), not w-fit.
11
+ // The grid has no column gap: the icon carries its own margin, so the empty
12
+ // action column of a narrow alert takes no space.
13
+ // The v3 banner: a toned alert is a faint tint of its tone. In light mode the
14
+ // fill is 7% tone in the card and the border 14% tone in the border colour; in
15
+ // dark mode the tone sits over transparent (10% fill, 30% border), because
16
+ // mixed into the cool surface it reads grey. The modes switch the
17
+ // --alert-fill and --alert-border properties, not the utilities, so a
18
+ // consumer's bg-* or border-* class wins in both modes. The icon takes the
19
+ // tone's text slot. Warning tints with the brighter warning-indicator, as an
20
+ // amber text colour mixes to brown. The title stays foreground and the
21
+ // description foreground-secondary in every variant, because a muted grey on
22
+ // a tinted fill falls below text contrast.
23
+ // The recipe lives in lib/tint-recipes.ts, which the contrast test in
24
+ // @vendure-io/design-tokens reads.
25
+ const tonedAlert = alertTint
26
+
27
+ // An alert enters once when it mounts: it fades in and moves 4px down into
28
+ // place, 240ms ease-out (@starting-style: nothing runs after it). Reduced motion
29
+ // keeps the fade. Content padding is 12px inline, 10px block.
6
30
  const alertVariants = cva(
7
- "grid gap-0.5 rounded-lg border px-4 py-3 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2.5 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4 w-full relative group/alert",
31
+ "@container/alert grid grid-cols-[minmax(0,1fr)] rounded-xl border px-3 py-2.5 text-start text-sm has-[>svg]:grid-cols-[auto_minmax(0,1fr)] has-[>[data-slot=alert-action]]:grid-cols-[minmax(0,1fr)_auto] has-[>svg]:has-[>[data-slot=alert-action]]:grid-cols-[auto_minmax(0,1fr)_auto] *:[svg]:row-span-2 *:[svg]:me-3 *:[svg]:translate-y-0.5 *:[svg:not([class*='size-'])]:size-4 *:[svg:not([class*='stroke-'])]:stroke-[1.75] [&:has(>svg:not([data-slot=alert-icon]))>[data-slot=alert-icon]]:hidden w-full relative group/alert transition-[opacity,translate] duration-alert-enter ease-out starting:opacity-0 motion-safe:starting:-translate-y-1",
8
32
  {
9
33
  variants: {
10
34
  variant: {
11
- default: "bg-card text-card-foreground",
12
- destructive:
13
- "text-destructive-subtle-foreground bg-card *:data-[slot=alert-description]:text-destructive-subtle-foreground *:[svg]:text-current",
14
- warning:
15
- "text-warning-subtle-foreground bg-card *:data-[slot=alert-description]:text-warning-subtle-foreground *:[svg]:text-current",
16
- info:
17
- "text-info-subtle-foreground bg-card *:data-[slot=alert-description]:text-info-subtle-foreground *:[svg]:text-current",
35
+ default: "bg-card text-card-foreground *:[svg]:text-current",
36
+ destructive: [
37
+ tonedAlert,
38
+ alertToneVars.destructive,
39
+ ],
40
+ warning: [
41
+ tonedAlert,
42
+ alertToneVars.warning,
43
+ ],
44
+ info: [tonedAlert, alertToneVars.info],
18
45
  },
19
46
  },
20
47
  defaultVariants: {
@@ -23,18 +50,43 @@ const alertVariants = cva(
23
50
  }
24
51
  )
25
52
 
53
+ // A toned variant shows the icon of its tone, the same shape a StatusBadge of
54
+ // that tone shows. The default variant has no tone and no icon of its own.
55
+ const variantIcons = {
56
+ destructive: toneIcons.critical,
57
+ warning: toneIcons.warning,
58
+ info: toneIcons.info,
59
+ } as const
60
+
61
+ /**
62
+ * A toned Alert shows its tone icon unless the caller passes one. An `icon`
63
+ * prop replaces it, and so does an svg child (the older way): the tone icon is
64
+ * then hidden. `icon={false}` shows no icon.
65
+ */
26
66
  function Alert({
27
67
  className,
28
68
  variant,
69
+ icon,
70
+ children,
29
71
  ...props
30
- }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
72
+ }: React.ComponentProps<"div"> &
73
+ VariantProps<typeof alertVariants> & {
74
+ /** Replaces the tone icon. `false` or `null` shows no icon. */
75
+ icon?: React.ReactNode
76
+ }) {
77
+ const ToneIcon = variant && variant !== "default" ? variantIcons[variant] : undefined
78
+ const shownIcon =
79
+ icon !== undefined ? icon || null : ToneIcon ? <ToneIcon aria-hidden data-slot="alert-icon" /> : null
31
80
  return (
32
81
  <div
33
82
  data-slot="alert"
34
83
  role="alert"
35
84
  className={cn(alertVariants({ variant }), className)}
36
85
  {...props}
37
- />
86
+ >
87
+ {shownIcon}
88
+ {children}
89
+ </div>
38
90
  )
39
91
  }
40
92
 
@@ -43,7 +95,7 @@ function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
43
95
  <div
44
96
  data-slot="alert-title"
45
97
  className={cn(
46
- "[&_a]:hover:text-foreground font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3",
98
+ "[&_a]:hover:text-foreground col-start-1 font-semibold group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3",
47
99
  className
48
100
  )}
49
101
  {...props}
@@ -59,7 +111,7 @@ function AlertDescription({
59
111
  <div
60
112
  data-slot="alert-description"
61
113
  className={cn(
62
- "text-muted-foreground [&_a]:hover:text-foreground text-sm text-balance md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
114
+ "text-foreground-secondary [&_a]:hover:text-foreground col-start-1 text-sm text-balance wrap-anywhere group-has-[>svg]/alert:col-start-2 md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
63
115
  className
64
116
  )}
65
117
  {...props}
@@ -67,11 +119,19 @@ function AlertDescription({
67
119
  )
68
120
  }
69
121
 
122
+ // From a 28rem-wide alert up, the action takes the last grid column on the first
123
+ // row, so the text wraps before it. The action box is one text line high and
124
+ // centres its content, so a button lines up with the first line of the text and
125
+ // overflows into the alert padding instead of making the alert taller. In a
126
+ // narrower alert the action moves to its own row under the text.
70
127
  function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
71
128
  return (
72
129
  <div
73
130
  data-slot="alert-action"
74
- className={cn("absolute top-2.5 right-3", className)}
131
+ className={cn(
132
+ "col-end-[-1] flex flex-wrap content-center items-center gap-2 @max-md/alert:col-start-1 @max-md/alert:mt-2 @max-md/alert:group-has-[>svg]/alert:col-start-2 @md/alert:row-start-1 @md/alert:ms-3 @md/alert:h-lh @md/alert:self-start",
133
+ className
134
+ )}
75
135
  {...props}
76
136
  />
77
137
  )
@@ -59,7 +59,7 @@ function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
59
59
  <span
60
60
  data-slot="avatar-badge"
61
61
  className={cn(
62
- "bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-blend-color ring-2 select-none",
62
+ "bg-primary text-primary-foreground ring-background absolute end-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-blend-color ring-2 select-none",
63
63
  "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
64
64
  "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
65
65
  "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
@@ -2,10 +2,15 @@ import { mergeProps } from "@base-ui/react/merge-props"
2
2
  import { useRender } from "@base-ui/react/use-render"
3
3
  import { cva, type VariantProps } from "class-variance-authority"
4
4
 
5
+ import { contentInsetPull } from "@vendure-io/ui/lib/content-inset"
5
6
  import { cn } from "@vendure-io/ui/lib/utils"
6
7
 
8
+ // `--content-inset` is the distance from the box to the first letter: the
9
+ // padding and the 1px border, plus a leading `data-icon="inline-start"` icon
10
+ // and the gap. A DataTable cell pulls the badge back by it, so the text lines
11
+ // up with the column header.
7
12
  const badgeVariants = cva(
8
- "h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive overflow-hidden group/badge",
13
+ [contentInsetPull, "[--content-inset:calc(var(--spacing)*2+1px)] has-data-[icon=inline-start]:[--content-inset:calc(var(--spacing)*5.5+1px)] h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-[color,background-color,border-color] has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive overflow-hidden group/badge"],
9
14
  {
10
15
  variants: {
11
16
  variant: {
@@ -16,7 +21,7 @@ const badgeVariants = cva(
16
21
  primary: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
17
22
  brand: "bg-brand text-brand-foreground [a]:hover:bg-brand/80",
18
23
  destructive:
19
- "bg-destructive/10 [a]:hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 text-destructive-subtle-foreground dark:bg-destructive/20",
24
+ "bg-destructive/10 [a]:hover:bg-destructive/20 text-destructive-subtle-foreground dark:bg-destructive/20",
20
25
  outline:
21
26
  "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
22
27
  ghost:
@@ -1,9 +1,25 @@
1
+ "use client"
2
+
1
3
  import * as React from "react"
2
4
  import { mergeProps } from "@base-ui/react/merge-props"
3
5
  import { useRender } from "@base-ui/react/use-render"
4
6
 
7
+ import { Menu as MenuPrimitive } from "@base-ui/react/menu"
8
+
5
9
  import { cn } from "@vendure-io/ui/lib/utils"
6
- import { ChevronRightIcon, MoreHorizontalIcon } from "lucide-react"
10
+ import { ChevronsUpDownIcon, MoreHorizontalIcon } from "lucide-react"
11
+
12
+ import { Button } from "./button.tsx"
13
+ import {
14
+ DropdownMenu,
15
+ DropdownMenuContent,
16
+ DropdownMenuGroup,
17
+ DropdownMenuLabel,
18
+ DropdownMenuTrigger,
19
+ } from "./dropdown-menu.tsx"
20
+ // Relative: `label-swap` is closed in the package exports.
21
+ import { LabelSwap } from "./label-swap.tsx"
22
+ import { menuItem, menuRadioItem, MenuCheck } from "../../lib/menu-item.tsx"
7
23
 
8
24
  function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">) {
9
25
  return (
@@ -66,7 +82,7 @@ function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
66
82
  role="link"
67
83
  aria-disabled="true"
68
84
  aria-current="page"
69
- className={cn("text-foreground font-normal", className)}
85
+ className={cn("text-foreground-secondary font-medium", className)}
70
86
  {...props}
71
87
  />
72
88
  )
@@ -82,11 +98,14 @@ function BreadcrumbSeparator({
82
98
  data-slot="breadcrumb-separator"
83
99
  role="presentation"
84
100
  aria-hidden="true"
85
- className={cn("[&>svg]:size-3.5", className)}
101
+ className={cn("mx-0.5 [&>svg]:size-3.5", className)}
86
102
  {...props}
87
103
  >
88
104
  {children ?? (
89
- <ChevronRightIcon />
105
+ // A thin slanted slash, quieter than the crumbs on both sides.
106
+ <span className="inline-block -skew-x-12 text-base leading-none font-light text-muted-foreground/40 select-none">
107
+ /
108
+ </span>
90
109
  )}
91
110
  </li>
92
111
  )
@@ -114,8 +133,121 @@ function BreadcrumbEllipsis({
114
133
  )
115
134
  }
116
135
 
136
+ /** One item a `BreadcrumbMenu` can switch to. */
137
+ type BreadcrumbMenuOption = {
138
+ value: string
139
+ label: string
140
+ /** Before the label, in the crumb and in the menu: a status dot. */
141
+ leading?: React.ReactNode
142
+ /** Muted text after the label in the menu only, such as a type. */
143
+ detail?: React.ReactNode
144
+ /** The row shows but cannot be picked. The arrow keys still stop on it. */
145
+ disabled?: boolean
146
+ }
147
+
148
+ /**
149
+ * A crumb that opens a menu to switch the current item, such as the
150
+ * environment at the start of a breadcrumb. It shows the current option's
151
+ * `leading` slot (a status dot) and label, and an up-down chevron. The menu
152
+ * lists the options with a check on the current one and opens toward the
153
+ * centre of the screen. Picking an option calls `onValueChange` and keeps the
154
+ * menu open, so the check is seen moving; the crumb's label crossfades to the
155
+ * new one and its width follows. `children` go after the options, such as a
156
+ * separator and an "Add environment" item. The options and the switch stay
157
+ * with the consumer.
158
+ *
159
+ * `label` names the list: it heads the menu and prefixes the crumb's
160
+ * accessible name ("Environment: Production").
161
+ */
162
+ function BreadcrumbMenu({
163
+ options,
164
+ value,
165
+ onValueChange,
166
+ label,
167
+ children,
168
+ className,
169
+ contentClassName,
170
+ }: {
171
+ options: readonly BreadcrumbMenuOption[]
172
+ value: string
173
+ onValueChange?: (value: string) => void
174
+ label: string
175
+ children?: React.ReactNode
176
+ className?: string
177
+ contentClassName?: string
178
+ }) {
179
+ const active = Math.max(
180
+ 0,
181
+ options.findIndex((option) => option.value === value)
182
+ )
183
+ const current = options[active]
184
+ return (
185
+ <DropdownMenu>
186
+ <DropdownMenuTrigger
187
+ data-slot="breadcrumb-menu"
188
+ render={
189
+ <Button
190
+ variant="ghost"
191
+ size="sm"
192
+ className={cn(
193
+ "text-foreground hover:text-foreground aria-expanded:text-foreground h-7.5 gap-2.25 rounded-lg ps-2.25 pe-1.75 text-sm font-semibold",
194
+ className
195
+ )}
196
+ />
197
+ }
198
+ >
199
+ {current?.leading}
200
+ <span className="sr-only">{label}: </span>
201
+ <LabelSwap
202
+ timing="button"
203
+ labels={options.map((option) => option.label)}
204
+ active={active}
205
+ className="justify-items-start overflow-x-clip whitespace-nowrap"
206
+ />
207
+ <ChevronsUpDownIcon
208
+ aria-hidden
209
+ className="size-3.5 opacity-40 group-hover/button:opacity-80 group-aria-expanded/button:opacity-80"
210
+ />
211
+ </DropdownMenuTrigger>
212
+ <DropdownMenuContent
213
+ className={cn("w-max max-w-90", contentClassName)}
214
+ >
215
+ <DropdownMenuGroup>
216
+ <DropdownMenuLabel>{label}</DropdownMenuLabel>
217
+ <MenuPrimitive.RadioGroup
218
+ value={value}
219
+ onValueChange={(next: string) => onValueChange?.(next)}
220
+ >
221
+ {options.map((option) => (
222
+ <MenuPrimitive.RadioItem
223
+ key={option.value}
224
+ value={option.value}
225
+ disabled={option.disabled}
226
+ closeOnClick={false}
227
+ data-slot="breadcrumb-menu-item"
228
+ className={cn(menuItem, menuRadioItem)}
229
+ >
230
+ {option.leading}
231
+ <span className="min-w-0 flex-1 truncate">{option.label}</span>
232
+ {option.detail != null && (
233
+ <span className="text-muted-foreground text-xs font-medium">
234
+ {option.detail}
235
+ </span>
236
+ )}
237
+ <MenuCheck />
238
+ </MenuPrimitive.RadioItem>
239
+ ))}
240
+ </MenuPrimitive.RadioGroup>
241
+ </DropdownMenuGroup>
242
+ {children}
243
+ </DropdownMenuContent>
244
+ </DropdownMenu>
245
+ )
246
+ }
247
+
117
248
  export {
118
249
  Breadcrumb,
250
+ BreadcrumbMenu,
119
251
  BreadcrumbList,
120
252
  BreadcrumbItem,
121
253
  BreadcrumbLink,
@@ -123,3 +255,4 @@ export {
123
255
  BreadcrumbSeparator,
124
256
  BreadcrumbEllipsis,
125
257
  }
258
+ export type { BreadcrumbMenuOption }