@vendure-io/ui 2.2.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 +59 -12
  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 +121 -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 +837 -80
  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
@@ -60,15 +60,17 @@ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
60
60
  }
61
61
 
62
62
  const fieldVariants = cva(
63
- "data-[invalid=true]:text-destructive-subtle-foreground gap-3 group/field flex w-full",
63
+ "data-[invalid=true]:text-destructive-subtle-foreground group/field flex w-full",
64
64
  {
65
65
  variants: {
66
66
  orientation: {
67
- vertical: "flex-col *:w-full [&>.sr-only]:w-auto",
67
+ // A label above its field: 12px, muted, 6px above it. An invalid
68
+ // field keeps its label red.
69
+ vertical: "flex-col gap-1.5 *:w-full [&>.sr-only]:w-auto *:data-[slot=field-label]:text-xs *:data-[slot=field-label]:text-muted-foreground data-[invalid=true]:*:data-[slot=field-label]:text-destructive-subtle-foreground",
68
70
  horizontal:
69
- "flex-row items-center *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
71
+ "flex-row items-center gap-3 *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
70
72
  responsive:
71
- "flex-col *:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:*:data-[slot=field-label]:flex-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
73
+ "flex-col gap-3 *:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:*:data-[slot=field-label]:flex-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
72
74
  },
73
75
  },
74
76
  defaultVariants: {
@@ -191,20 +193,43 @@ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
191
193
  )
192
194
  }
193
195
 
196
+ // A FieldLabel around a checkbox, radio or switch (a choice card) tints while
197
+ // the control is checked. The control marks itself with the class
198
+ // `choice-checked` (useFieldLabelCheckedClass), only inside a FieldLabel. The
199
+ // label does not read `data-checked` with :has(): in Chromium any :has() keyed
200
+ // on `data-checked` restyles every row of a DataTable when its checkboxes
201
+ // change, and select all on a long table then drops frames.
202
+ const FieldLabelContext = createContext(false)
203
+
204
+ /**
205
+ * For a checkbox, radio or switch: returns the class to add for its checked
206
+ * state, which a FieldLabel around it reads. Outside a FieldLabel, nothing.
207
+ */
208
+ function useFieldLabelCheckedClass() {
209
+ const inFieldLabel = useContext(FieldLabelContext)
210
+ return (checked: boolean) =>
211
+ inFieldLabel && checked ? "choice-checked" : undefined
212
+ }
213
+
194
214
  function FieldLabel({
195
215
  className,
216
+ children,
196
217
  ...props
197
218
  }: React.ComponentProps<typeof Label>) {
198
219
  return (
199
- <Label
200
- data-slot="field-label"
201
- className={cn(
202
- "has-data-checked:bg-primary/5 has-data-checked:border-primary/30 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10 group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border *:data-[slot=field]:p-3",
203
- "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col",
204
- className
205
- )}
206
- {...props}
207
- />
220
+ <FieldLabelContext.Provider value={true}>
221
+ <Label
222
+ data-slot="field-label"
223
+ className={cn(
224
+ "has-[.choice-checked]:bg-primary/5 has-[.choice-checked]:border-primary/30 dark:has-[.choice-checked]:border-primary/20 dark:has-[.choice-checked]:bg-primary/10 group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border *:data-[slot=field]:p-3",
225
+ "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col",
226
+ className
227
+ )}
228
+ {...props}
229
+ >
230
+ {children}
231
+ </Label>
232
+ </FieldLabelContext.Provider>
208
233
  )
209
234
  }
210
235
 
@@ -232,7 +257,7 @@ function FieldDescription({
232
257
  id={messageId}
233
258
  data-slot="field-description"
234
259
  className={cn(
235
- "text-muted-foreground text-left text-sm leading-normal font-normal group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5",
260
+ "text-muted-foreground text-start text-sm leading-normal font-normal group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5",
236
261
  "last:mt-0 nth-last-2:-mt-1",
237
262
  "[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
238
263
  className
@@ -299,7 +324,7 @@ function FieldError({
299
324
  }
300
325
 
301
326
  return (
302
- <ul className="ml-4 flex list-disc flex-col gap-1">
327
+ <ul className="ms-4 flex list-disc flex-col gap-1">
303
328
  {uniqueErrors.map(
304
329
  (error, index) =>
305
330
  error?.message && <li key={index}>{error.message}</li>
@@ -358,4 +383,5 @@ export {
358
383
  fieldDescribedBy,
359
384
  mergeFieldControlProps,
360
385
  useFieldControlProps,
386
+ useFieldLabelCheckedClass,
361
387
  }
@@ -1,44 +1,97 @@
1
1
  "use client"
2
2
 
3
+ import * as React from "react"
3
4
  import { PreviewCard as PreviewCardPrimitive } from "@base-ui/react/preview-card"
4
5
 
5
6
  import { cn } from "@vendure-io/ui/lib/utils"
7
+ import { popupMotion } from "../../lib/popup-motion.ts"
8
+ import { usePopupDir } from "../../lib/popup-direction.ts"
9
+ import { usePopupAlign } from "../../lib/popup-align.ts"
10
+ import { triggerSlot } from "../../lib/trigger-slot.ts"
11
+
12
+ // A hover card trigger sets no aria-controls, so the trigger hands its element
13
+ // to the card here. A trigger outside a HoverCard (a detached one) is not seen.
14
+ const HoverCardTriggerRef = React.createContext<React.RefObject<Element | null> | null>(null)
6
15
 
7
16
  function HoverCard({ ...props }: PreviewCardPrimitive.Root.Props) {
8
- return <PreviewCardPrimitive.Root data-slot="hover-card" {...props} />
17
+ const triggerRef = React.useRef<Element | null>(null)
18
+ return (
19
+ <HoverCardTriggerRef value={triggerRef}>
20
+ <PreviewCardPrimitive.Root data-slot="hover-card" {...props} />
21
+ </HoverCardTriggerRef>
22
+ )
9
23
  }
10
24
 
11
- function HoverCardTrigger({ ...props }: PreviewCardPrimitive.Trigger.Props) {
25
+ function HoverCardTrigger({
26
+ ref,
27
+ ...props
28
+ }: PreviewCardPrimitive.Trigger.Props) {
29
+ const triggerRef = React.useContext(HoverCardTriggerRef)
30
+ const setRef = React.useCallback(
31
+ (trigger: HTMLAnchorElement | null) => {
32
+ if (triggerRef) triggerRef.current = trigger
33
+ if (typeof ref === "function") ref(trigger)
34
+ else if (ref) ref.current = trigger
35
+ },
36
+ [triggerRef, ref]
37
+ )
12
38
  return (
13
- <PreviewCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
39
+ <PreviewCardPrimitive.Trigger
40
+ ref={setRef}
41
+ {...triggerSlot("hover-card-trigger", props.render)}
42
+ {...props}
43
+ />
14
44
  )
15
45
  }
16
46
 
47
+ /**
48
+ * Without an `align`, the card opens toward the centre of the screen: a
49
+ * trigger in the right half lines the card up with its right edge, so it grows
50
+ * to the left and stays on screen, and a trigger in the left half lines it up
51
+ * with its left edge. The side is picked each time it opens. A card that opens
52
+ * to the left or right of its trigger keeps "start". An explicit `align`
53
+ * always wins. Do not set `align` unless there is a reason.
54
+ */
17
55
  function HoverCardContent({
18
56
  className,
19
57
  side = "bottom",
20
- sideOffset = 4,
21
- align = "center",
22
- alignOffset = 4,
58
+ sideOffset = 6,
59
+ align,
60
+ // The 4px nudge belongs to an explicit align. The centre-aware edge lines up
61
+ // with the trigger's edge, as in the menu and the popover.
62
+ alignOffset = align ? 4 : 0,
63
+ ref,
23
64
  ...props
24
65
  }: PreviewCardPrimitive.Popup.Props &
25
66
  Pick<
26
67
  PreviewCardPrimitive.Positioner.Props,
27
68
  "align" | "alignOffset" | "side" | "sideOffset"
28
69
  >) {
70
+ const dir = usePopupDir()
71
+ const triggerRef = React.useContext(HoverCardTriggerRef)
72
+ const getTrigger = React.useCallback(() => triggerRef?.current, [triggerRef])
73
+ const { popupRef, align: positionAlign } = usePopupAlign(
74
+ align,
75
+ side,
76
+ ref,
77
+ getTrigger
78
+ )
29
79
  return (
30
80
  <PreviewCardPrimitive.Portal data-slot="hover-card-portal">
31
81
  <PreviewCardPrimitive.Positioner
32
- align={align}
82
+ dir={dir}
83
+ align={positionAlign}
33
84
  alignOffset={alignOffset}
34
85
  side={side}
35
86
  sideOffset={sideOffset}
36
87
  className="isolate z-50"
37
88
  >
38
89
  <PreviewCardPrimitive.Popup
90
+ ref={popupRef}
39
91
  data-slot="hover-card-content"
40
92
  className={cn(
41
- "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 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 w-64 origin-(--transform-origin) rounded-lg p-4 text-sm shadow-md ring-1 outline-hidden 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)",
93
+ "bg-popover text-popover-foreground shadow-overlay z-50 w-64 rounded-xl p-4 text-sm outline-hidden",
94
+ popupMotion,
42
95
  className
43
96
  )}
44
97
  {...props}
@@ -4,6 +4,7 @@ import * as React from "react"
4
4
  import { cva, type VariantProps } from "class-variance-authority"
5
5
 
6
6
  import { cn } from "@vendure-io/ui/lib/utils"
7
+ import { fieldSurface } from "@vendure-io/ui/lib/field-surface"
7
8
  import { Button } from "@vendure-io/ui/components/atoms/button"
8
9
  import { Input } from "@vendure-io/ui/components/atoms/input"
9
10
  import { Textarea } from "@vendure-io/ui/components/atoms/textarea"
@@ -14,7 +15,8 @@ function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
14
15
  data-slot="input-group"
15
16
  role="group"
16
17
  className={cn(
17
- "border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border transition-[color,box-shadow] outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-3 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
18
+ fieldSurface,
19
+ "has-[[data-slot=input-group-control]:focus-visible]:outline-solid has-[[data-slot=input-group-control]:focus-visible]:outline-2 has-[[data-slot=input-group-control]:focus-visible]:-outline-offset-2 has-[[data-slot=input-group-control]:focus-visible]:outline-ring has-[[data-slot][aria-invalid=true]]:outline-destructive has-[[data-slot][aria-invalid=true]]:shadow-[inset_0_0_0_1px_var(--destructive)] group/input-group relative flex h-8.5 w-full min-w-0 items-center in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 in-data-[slot=combobox-content]:outline-none! has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pe-1.5 has-[>[data-align=inline-start]]:[&>input]:ps-1.5",
18
20
  className
19
21
  )}
20
22
  {...props}
@@ -22,15 +24,21 @@ function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
22
24
  )
23
25
  }
24
26
 
27
+ // An inline addon starts 10px in, like the text of an Input. A button or kbd
28
+ // in it keeps to its old spot nearer the edge: its own padding puts its
29
+ // content about 10px in. Logical sides, so right-to-left mirrors it.
30
+ // A kbd in an addon drops its own fill and uses the secondary text colour
31
+ // and the input hairline, as the v3 look's search field does: its muted text
32
+ // on its fill on the muted field fails the axe contrast check.
25
33
  const inputGroupAddonVariants = cva(
26
- "text-muted-foreground h-auto gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4 flex cursor-text items-center justify-center select-none",
34
+ "text-muted-foreground **:data-[slot=kbd]:bg-transparent **:data-[slot=kbd]:text-foreground-secondary **:data-[slot=kbd]:inset-ring-input h-auto gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>svg:not([class*='size-'])]:size-4 [&>svg:not([class*='stroke-'])]:stroke-[1.75] flex cursor-text items-center justify-center select-none",
27
35
  {
28
36
  variants: {
29
37
  align: {
30
38
  "inline-start":
31
- "pl-2 has-[>button]:-ml-1 has-[>kbd]:ml-[-0.15rem] order-first",
39
+ "ps-2.5 has-[>button]:-ms-1.5 has-[>kbd]:ms-[-0.275rem] order-first",
32
40
  "inline-end":
33
- "pr-2 has-[>button]:-mr-1 has-[>kbd]:mr-[-0.15rem] order-last",
41
+ "pe-2.5 has-[>button]:-me-1.5 has-[>kbd]:me-[-0.275rem] order-last",
34
42
  "block-start":
35
43
  "px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2 order-first w-full justify-start",
36
44
  "block-end":
@@ -71,10 +79,10 @@ const inputGroupButtonVariants = cva(
71
79
  variants: {
72
80
  size: {
73
81
  xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
74
- sm: "",
82
+ sm: "h-7 gap-1.5 px-2.5",
75
83
  "icon-xs":
76
84
  "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
77
- "icon-sm": "size-8 p-0 has-[>svg]:p-0",
85
+ "icon-sm": "size-7 p-0 has-[>svg]:p-0",
78
86
  },
79
87
  },
80
88
  defaultVariants: {
@@ -108,7 +116,7 @@ function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
108
116
  return (
109
117
  <span
110
118
  className={cn(
111
- "text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
119
+ "text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75]",
112
120
  className
113
121
  )}
114
122
  {...props}
@@ -124,7 +132,7 @@ function InputGroupInput({
124
132
  <Input
125
133
  data-slot="input-group-control"
126
134
  className={cn(
127
- "flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent",
135
+ "flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:shadow-none focus-visible:ring-0 focus-visible:outline-none aria-invalid:shadow-none aria-invalid:focus-visible:shadow-none aria-invalid:ring-0 dark:bg-transparent",
128
136
  className
129
137
  )}
130
138
  {...props}
@@ -140,7 +148,7 @@ function InputGroupTextarea({
140
148
  <Textarea
141
149
  data-slot="input-group-control"
142
150
  className={cn(
143
- "flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent",
151
+ "flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:shadow-none focus-visible:ring-0 focus-visible:outline-none aria-invalid:shadow-none aria-invalid:focus-visible:shadow-none aria-invalid:ring-0 dark:bg-transparent",
144
152
  className
145
153
  )}
146
154
  {...props}
@@ -4,6 +4,7 @@ import * as React from "react"
4
4
  import { OTPInput, OTPInputContext } from "input-otp"
5
5
 
6
6
  import { cn } from "@vendure-io/ui/lib/utils"
7
+ import { fieldSurfaceWithin } from "@vendure-io/ui/lib/field-surface"
7
8
  import { MinusIcon } from "lucide-react"
8
9
 
9
10
  function InputOTP({
@@ -31,10 +32,9 @@ function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {
31
32
  return (
32
33
  <div
33
34
  data-slot="input-otp-group"
34
- className={cn(
35
- "has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40 has-aria-invalid:border-destructive flex items-center rounded-md has-aria-invalid:ring-3",
36
- className
37
- )}
35
+ // The group draws the field. The OTP input sits outside the group, so
36
+ // its focus-within ring never shows: the active slot carries the ring.
37
+ className={cn(fieldSurfaceWithin, "flex items-center", className)}
38
38
  {...props}
39
39
  />
40
40
  )
@@ -55,7 +55,7 @@ function InputOTPSlot({
55
55
  data-slot="input-otp-slot"
56
56
  data-active={isActive}
57
57
  className={cn(
58
- "dark:bg-input/30 border-input data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive relative flex size-9 items-center justify-center border-y border-r text-sm transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-3",
58
+ "border-border data-[active=true]:outline-solid data-[active=true]:outline-2 data-[active=true]:-outline-offset-2 data-[active=true]:outline-ring data-[active=true]:aria-invalid:outline-destructive relative flex size-8.5 items-center justify-center border-s text-sm outline-none first:rounded-s-lg first:border-s-0 last:rounded-e-lg data-[active=true]:z-10",
59
59
  className
60
60
  )}
61
61
  {...props}
@@ -63,7 +63,7 @@ function InputOTPSlot({
63
63
  {char}
64
64
  {hasFakeCaret && (
65
65
  <div className="pointer-events-none absolute inset-0 flex items-center justify-center">
66
- <div className="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
66
+ <div className="animate-caret-blink bg-foreground h-4 w-px" />
67
67
  </div>
68
68
  )}
69
69
  </div>
@@ -4,15 +4,21 @@ import * as React from "react"
4
4
  import { Input as InputPrimitive } from "@base-ui/react/input"
5
5
 
6
6
  import { cn } from "@vendure-io/ui/lib/utils"
7
+ import { fieldSurface } from "@vendure-io/ui/lib/field-surface"
7
8
  import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
8
9
 
10
+ // The v3 look: a 34px field on the `muted` tint with a 1px inset hairline in
11
+ // `border` (a real border only in forced-colors mode). Focus draws the ring
12
+ // 2px inside the field, over the hairline, so a field in a dialog or a dense
13
+ // form never touches its neighbours.
9
14
  function Input({ className, type, ...props }: React.ComponentProps<"input">) {
10
15
  return (
11
16
  <InputPrimitive
12
17
  type={type}
13
18
  data-slot="input"
14
19
  className={cn(
15
- "dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive file:text-foreground placeholder:text-muted-foreground h-9 w-full min-w-0 rounded-md border bg-transparent px-2.5 py-1 text-base transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-3 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 md:text-sm",
20
+ fieldSurface,
21
+ "file:text-foreground placeholder:text-faint-foreground h-8.5 w-full min-w-0 px-2.5 py-1 text-base file:inline-flex file:h-6.5 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
16
22
  className
17
23
  )}
18
24
  {...useFieldControlProps(props)}
@@ -38,7 +38,7 @@ function ItemSeparator({
38
38
  }
39
39
 
40
40
  const itemVariants = cva(
41
- "[a]:hover:bg-muted rounded-md border text-sm w-full group/item focus-visible:border-ring focus-visible:ring-ring/50 flex items-center flex-wrap outline-none transition-colors duration-100 focus-visible:ring-[3px] [a]:transition-colors",
41
+ "[a]:hover:bg-muted rounded-md border text-sm w-full group/item focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring flex items-center flex-wrap outline-none transition-colors duration-fast [a]:transition-colors",
42
42
  {
43
43
  variants: {
44
44
  variant: {
@@ -89,7 +89,7 @@ const itemMediaVariants = cva(
89
89
  variants: {
90
90
  variant: {
91
91
  default: "bg-transparent",
92
- icon: "[&_svg:not([class*='size-'])]:size-4",
92
+ icon: "[&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>svg:not([class*='opacity-']):not([class*='text-'])]:opacity-55 [&>svg:not([class*='opacity-']):not([class*='text-'])]:transition-opacity [&>svg:not([class*='opacity-']):not([class*='text-'])]:duration-moderate group-hover/item:[&>svg:not([class*='opacity-']):not([class*='text-'])]:opacity-85 group-focus-visible/item:[&>svg:not([class*='opacity-']):not([class*='text-'])]:opacity-85",
93
93
  image:
94
94
  "size-10 overflow-hidden rounded-sm group-data-[size=sm]/item:size-8 group-data-[size=xs]/item:size-6 [&_img]:size-full [&_img]:object-cover",
95
95
  },
@@ -146,7 +146,7 @@ function ItemDescription({ className, ...props }: React.ComponentProps<"p">) {
146
146
  <p
147
147
  data-slot="item-description"
148
148
  className={cn(
149
- "text-muted-foreground [&>a:hover]:text-primary line-clamp-2 text-left text-sm leading-normal font-normal group-data-[size=xs]/item:text-xs [&>a]:underline [&>a]:underline-offset-4",
149
+ "text-muted-foreground [&>a:hover]:text-primary line-clamp-2 text-start text-sm leading-normal font-normal group-data-[size=xs]/item:text-xs [&>a]:underline [&>a]:underline-offset-4",
150
150
  className
151
151
  )}
152
152
  {...props}
@@ -1,15 +1,44 @@
1
+ import * as React from "react"
2
+
1
3
  import { cn } from "@vendure-io/ui/lib/utils"
2
4
 
3
- function Kbd({ className, ...props }: React.ComponentProps<"kbd">) {
5
+ // A key name such as Ctrl+O or ⌘K reads left to right in a right-to-left
6
+ // page too. Each run of text sits in a span with dir="ltr"; the kbd box keeps
7
+ // the page direction, so a logical margin such as ms-auto still points to the
8
+ // end of the line. A run of text stays one flex item, as it was.
9
+ function ltrText(children: React.ReactNode) {
10
+ const out: React.ReactNode[] = []
11
+ let run: React.ReactNode[] = []
12
+ const flush = () => {
13
+ if (run.length > 0) out.push(<span key={out.length} dir="ltr">{run}</span>)
14
+ run = []
15
+ }
16
+ React.Children.toArray(children).forEach((child) => {
17
+ if (typeof child === "string" || typeof child === "number") run.push(child)
18
+ else {
19
+ flush()
20
+ out.push(child)
21
+ }
22
+ })
23
+ flush()
24
+ return out
25
+ }
26
+
27
+ // The v3 look: 12px medium text on the muted tint with a 1px inset hairline,
28
+ // 20px high, 5px side padding and the md radius. Inside a tooltip the
29
+ // hairline drops, so the key sits on the inverted fill alone.
30
+ function Kbd({ className, children, ...props }: React.ComponentProps<"kbd">) {
4
31
  return (
5
32
  <kbd
6
33
  data-slot="kbd"
7
34
  className={cn(
8
- "bg-muted text-muted-foreground in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10 pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-sm px-1 font-sans text-xs font-medium select-none [&_svg:not([class*='size-'])]:size-3",
35
+ "bg-muted text-muted-foreground inset-ring inset-ring-border in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background in-data-[slot=tooltip-content]:inset-ring-0 dark:in-data-[slot=tooltip-content]:bg-background/10 pointer-events-none inline-flex h-5 w-fit min-w-5 items-center justify-center gap-1 rounded-md px-1.25 font-sans text-xs leading-none font-medium select-none [&_svg:not([class*='size-'])]:size-3",
9
36
  className
10
37
  )}
11
38
  {...props}
12
- />
39
+ >
40
+ {ltrText(children)}
41
+ </kbd>
13
42
  )
14
43
  }
15
44
 
@@ -0,0 +1,82 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { useActiveLabelSize } from "../../hooks/use-active-label-size.ts"
6
+ import { cn } from "@vendure-io/ui/lib/utils"
7
+
8
+ /**
9
+ * How far a label slides and how long each part takes. `button`: 4px, the
10
+ * label fades in `moderate` and slides and resizes in `normal`. `tooltip`:
11
+ * 6px, on the tooltip label durations (fade 180ms, slide 260ms, resize
12
+ * 320ms).
13
+ */
14
+ const TIMINGS = {
15
+ button:
16
+ "[--label-swap-shift:calc(var(--spacing)*1)] [--label-swap-fade:var(--transition-duration-moderate)] [--label-swap-move:var(--transition-duration-normal)] [--label-swap-resize:var(--transition-duration-normal)]",
17
+ tooltip:
18
+ "[--label-swap-shift:calc(var(--spacing)*1.5)] [--label-swap-fade:var(--transition-duration-tooltip-label-fade)] [--label-swap-move:var(--transition-duration-tooltip-label-move)] [--label-swap-resize:var(--transition-duration-tooltip-resize)]",
19
+ } as const
20
+
21
+ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
22
+ labels: readonly React.ReactNode[]
23
+ active: number
24
+ timing: keyof typeof TIMINGS
25
+ /** Classes for each label, after the shared ones. */
26
+ labelClassName?: string
27
+ }
28
+
29
+ /**
30
+ * Internal: the one label swap behind `ButtonLabelSwap` and
31
+ * `TooltipLabelSwap`. Not exported from the package.
32
+ *
33
+ * The labels share one grid cell and `active` picks the one that shows; the
34
+ * others are hidden from the accessible name. A label before it leaves
35
+ * upward, a label after it waits below, both faded out with a 2px blur, and
36
+ * the swap eases to the active label's width and height on the drawer curve.
37
+ * The size follows the label while it is active (see `useActiveLabelSize`).
38
+ * With reduced motion the labels only crossfade, and the size changes at once.
39
+ */
40
+ function LabelSwap({
41
+ labels,
42
+ active,
43
+ timing,
44
+ labelClassName,
45
+ className,
46
+ style,
47
+ ...props
48
+ }: LabelSwapProps) {
49
+ const { refs, width, height } = useActiveLabelSize(active)
50
+ return (
51
+ <span
52
+ className={cn(
53
+ "grid grid-cols-[100%] justify-items-center motion-safe:transition-[width,height] motion-safe:duration-(--label-swap-resize) motion-safe:ease-drawer",
54
+ TIMINGS[timing],
55
+ className
56
+ )}
57
+ style={width === undefined ? style : { ...style, width, height }}
58
+ {...props}
59
+ >
60
+ {labels.map((label, index) => (
61
+ <span
62
+ // The labels are positions in a fixed list, so the index is their identity.
63
+ key={index}
64
+ ref={(element) => {
65
+ refs.current[index] = element
66
+ }}
67
+ data-swap={index === active ? "in" : index < active ? "before" : "after"}
68
+ aria-hidden={index === active ? undefined : true}
69
+ className={cn(
70
+ "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]",
71
+ labelClassName
72
+ )}
73
+ >
74
+ {label}
75
+ </span>
76
+ ))}
77
+ </span>
78
+ )
79
+ }
80
+
81
+ export { LabelSwap }
82
+ export type { LabelSwapProps }
@@ -9,7 +9,7 @@ function Label({ className, ...props }: React.ComponentProps<"label">) {
9
9
  <label
10
10
  data-slot="label"
11
11
  className={cn(
12
- "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
12
+ "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50 peer-data-disabled:cursor-not-allowed peer-data-disabled:opacity-50",
13
13
  className
14
14
  )}
15
15
  {...props}