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

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.
@@ -0,0 +1,38 @@
1
+ # Third-party notices
2
+
3
+ `@vendure-io/ui` ships under the Vendure licence (`LICENSE.md`). Some of its
4
+ files contain code adapted from the open-source projects below. Each of those
5
+ files names its source in a header comment. The licence of each project
6
+ follows its entry.
7
+
8
+ ## Stealth UI
9
+
10
+ - Source: https://github.com/paragonhq/stealth-ui
11
+ - Commit: `b7f23382e7dbbac3815dee70cb1b4759c040205c`
12
+ - Adapted from: `components/ui/checklist.tsx`
13
+ - Used in: `src/components/molecules/checklist/checklist.tsx`
14
+ - Licence: MIT
15
+
16
+ ```
17
+ MIT License
18
+
19
+ Copyright (c) 2026 Paragon
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ of this software and associated documentation files (the "Software"), to deal
23
+ in the Software without restriction, including without limitation the rights
24
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ copies of the Software, and to permit persons to whom the Software is
26
+ furnished to do so, subject to the following conditions:
27
+
28
+ The above copyright notice and this permission notice shall be included in all
29
+ copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ SOFTWARE.
38
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendure-io/ui",
3
- "version": "3.0.0-next.2",
3
+ "version": "3.0.0-next.3",
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",
@@ -30,7 +30,8 @@
30
30
  "./lib/trigger-slot": null,
31
31
  "./hooks/*": "./src/hooks/*.ts",
32
32
  "./hooks/use-active-label-size": null,
33
- "./hooks/use-pinned-height": null
33
+ "./hooks/use-pinned-height": null,
34
+ "./hooks/use-user-toggle-motion": null
34
35
  },
35
36
  "files": [
36
37
  "src",
@@ -38,7 +39,8 @@
38
39
  "!src/**/*.test.tsx",
39
40
  "!src/test",
40
41
  "README.md",
41
- "LICENSE.md"
42
+ "LICENSE.md",
43
+ "THIRD_PARTY_NOTICES.md"
42
44
  ],
43
45
  "scripts": {
44
46
  "lint": "biome check src/ guidance/",
@@ -1,7 +1,9 @@
1
1
  "use client"
2
2
 
3
- import type * as React from "react"
3
+ import * as React from "react"
4
4
  import { Button as ButtonPrimitive } from "@base-ui/react/button"
5
+ import { mergeProps } from "@base-ui/react/merge-props"
6
+ import { useRender } from "@base-ui/react/use-render"
5
7
  import { cva, type VariantProps } from "class-variance-authority"
6
8
 
7
9
  // Relative: `label-swap` is closed in the package exports.
@@ -128,24 +130,119 @@ const buttonVariants = cva(
128
130
  }
129
131
  )
130
132
 
131
- function Button({
133
+ type ButtonProps = ButtonPrimitive.Props & VariantProps<typeof buttonVariants>
134
+
135
+ // Whether `render` is a link, from what is known before the first render, so
136
+ // server markup is right too: an `<a>`, or an element with `href` (Next and
137
+ // plain components) or `to` (React Router and TanStack Router). A render
138
+ // function is opaque; it takes the button path, and the dev check in Button
139
+ // reports a link that slipped through.
140
+ function rendersLink(render: ButtonProps["render"]) {
141
+ if (!React.isValidElement<{ href?: unknown; to?: unknown }>(render)) return false
142
+ return render.type === "a" || render.props.href != null || render.props.to != null
143
+ }
144
+
145
+ // Base UI's Button, given `nativeButton={false}`, makes an anchor
146
+ // role="button", gives it a Space-key click and a tab stop of its own. A link
147
+ // wants none of that: it keeps its link role, Enter follows it natively and
148
+ // Space scrolls the page. So a link skips Base UI's Button and takes the same
149
+ // classes, plus its disabled rules (see Button).
150
+ function LinkButton({
132
151
  className,
133
- variant = "default",
134
- size = "default",
152
+ variant,
153
+ size,
135
154
  render,
136
- nativeButton,
155
+ disabled = false,
156
+ focusableWhenDisabled = false,
157
+ // Meaningless for a link; kept out of the DOM.
158
+ nativeButton: _nativeButton,
159
+ ref,
137
160
  ...props
138
- }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
161
+ }: ButtonProps) {
162
+ // A disabled link follows nothing. An `<a>` loses its href, which also stops
163
+ // a middle click and "open in new tab". A router link computes its own href,
164
+ // so it cannot lose it: only its clicks are stopped.
165
+ const rendered =
166
+ disabled && React.isValidElement<{ href?: unknown }>(render) && render.type === "a"
167
+ ? React.cloneElement(render, { href: undefined })
168
+ : render
169
+ return useRender({
170
+ defaultTagName: "a",
171
+ render: rendered,
172
+ ref,
173
+ state: { disabled },
174
+ props: mergeProps<"a">(
175
+ {
176
+ ...{ "data-slot": "button" },
177
+ className: cn(buttonVariants({ variant, size, className })),
178
+ ...(disabled && {
179
+ // An `<a>` without href has no role; the link role stays explicit.
180
+ role: "link",
181
+ "aria-disabled": true,
182
+ tabIndex: focusableWhenDisabled ? undefined : -1,
183
+ onClick: (event: React.MouseEvent) => event.preventDefault(),
184
+ onAuxClick: (event: React.MouseEvent) => event.preventDefault(),
185
+ }),
186
+ },
187
+ props as React.ComponentProps<"a">
188
+ ),
189
+ })
190
+ }
191
+
192
+ // Dev only. A render function can hide a link from `rendersLink`; the anchor in
193
+ // the DOM gives it away, and the Button would then announce it as a button.
194
+ function useUndetectedLinkCheck(ref: React.Ref<HTMLButtonElement> | undefined, enabled: boolean) {
195
+ return React.useCallback(
196
+ (element: HTMLButtonElement | null) => {
197
+ if (enabled && element instanceof HTMLAnchorElement && element.hasAttribute("href")) {
198
+ console.error(
199
+ 'Button rendered a link but gave it role="button". Pass the link as an element with `href` or `to` (render={<Link to="/x" />}), not as a render function, so Button can tell.'
200
+ )
201
+ }
202
+ if (typeof ref === "function") return ref(element)
203
+ if (ref) ref.current = element
204
+ },
205
+ [ref, enabled]
206
+ )
207
+ }
208
+
209
+ /**
210
+ * A button. Pass `render` to draw it as another element.
211
+ *
212
+ * A Button that renders a link keeps the link role: `render={<a href="/x" />}`
213
+ * or a router link such as `render={<Link to="/x" />}`. It gets the whole
214
+ * button look and states. Do not call `buttonVariants()` on your own `<a>`;
215
+ * that skips the disabled rules below. Button finds the link from the element
216
+ * you pass (an `<a>`, or an element with `href` or `to`), so there is no extra
217
+ * prop.
218
+ *
219
+ * A disabled link (`disabled`) has `role="link"` and `aria-disabled="true"`,
220
+ * follows nothing and leaves the tab order. An `<a>` loses its href; a router
221
+ * link keeps the href it computes, so it can still be copied, but a click,
222
+ * Enter and a middle click do nothing. Add `focusableWhenDisabled` to keep the
223
+ * tab stop, for a link with a tooltip that says why.
224
+ */
225
+ function Button({ className, variant = "default", size = "default", render, nativeButton, ...props }: ButtonProps) {
226
+ const isLink = rendersLink(render)
227
+ const ref = useUndetectedLinkCheck(
228
+ props.ref,
229
+ process.env.NODE_ENV !== "production" && Boolean(render) && !isLink
230
+ )
231
+ if (isLink) {
232
+ return <LinkButton className={className} variant={variant} size={size} render={render} {...props} />
233
+ }
234
+ const { ref: _ref, ...rest } = props
139
235
  return (
140
236
  <ButtonPrimitive
141
237
  data-slot="button"
142
238
  className={cn(buttonVariants({ variant, size, className }))}
143
239
  // Base UI warns when `render` swaps in a non-native element unless
144
240
  // nativeButton is false. Default it off when rendering as something else
145
- // (e.g. an anchor) so consumers don't have to pass it every time.
241
+ // (e.g. a div) so consumers don't have to pass it every time.
146
242
  render={render}
147
243
  nativeButton={render ? (nativeButton ?? false) : nativeButton}
148
- {...props}
244
+ ref={ref}
245
+ {...rest}
149
246
  />
150
247
  )
151
248
  }
@@ -1,8 +1,12 @@
1
+ import { mergeProps } from "@base-ui/react/merge-props"
2
+ import { useRender } from "@base-ui/react/use-render"
1
3
  import * as React from "react"
2
4
 
3
5
  import type { Tone } from "@vendure-io/ui/lib/state-dictionary"
4
6
  import { cn } from "@vendure-io/ui/lib/utils"
5
7
 
8
+ import { interactiveCardVariants } from "../molecules/interactive-card.tsx"
9
+
6
10
  // The size variant publishes the card's spacing contract as CSS variables
7
11
  // (--card-ps: start padding, --card-px: end padding, --card-gap: vertical
8
12
  // rhythm shared by the root padding and the flex gap). The default card starts
@@ -21,6 +25,17 @@ import { cn } from "@vendure-io/ui/lib/utils"
21
25
  // brand more weight in the mix), and a 1.5% brand wash fades out by 55% of
22
26
  // the height. The bright brand (brand-500) is the same in both modes. Use it on at most one card per
23
27
  // view, and show state inside it with a bare StatusBadge, not a chip.
28
+ // A Card with a CardLink inside opens as a whole: the link's ::after covers
29
+ // the card, the card takes the shared interactive look (hover border, press,
30
+ // focus ring), and every other control inside it (a "…" menu, a copy button,
31
+ // a Tooltip trigger, IdChip, CopyableText) is lifted above the stretched
32
+ // area, so it keeps its own click and tab stop. Any other element that must
33
+ // stay hoverable above the link takes `data-card-control`. All of it is gated
34
+ // on the card holding a CardLink, so a static card changes nothing. The class
35
+ // names stay literal so Tailwind can scan them.
36
+ const LINKED_CARD_CONTROLS =
37
+ "[&:has([data-slot=card-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-card-control]):not([data-slot=card-link],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:relative [&:has([data-slot=card-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-card-control]):not([data-slot=card-link],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:z-10"
38
+
24
39
  const ACCENT_CARD =
25
40
  "data-[variant=accent]:border-[color:color-mix(in_oklab,var(--brand-500)_30%,var(--border))] dark:data-[variant=accent]:border-[color:color-mix(in_oklab,var(--brand-500)_38%,var(--border))] data-[variant=accent]:bg-[image:linear-gradient(180deg,color-mix(in_oklab,var(--brand-500)_1.5%,transparent),transparent_55%)]"
26
41
 
@@ -40,6 +55,8 @@ function Card({
40
55
  data-variant={variant}
41
56
  className={cn(
42
57
  "bg-card text-card-foreground group/card [--card-gap:--spacing(4)] [--card-ps:--spacing(4.5)] [--card-px:--spacing(4)] [--card-head:--spacing(12)] data-[size=sm]:[--card-gap:--spacing(3)] data-[size=sm]:[--card-ps:--spacing(3)] data-[size=sm]:[--card-px:--spacing(3)] data-[size=sm]:[--card-head:--spacing(11)] flex flex-col gap-(--card-gap) overflow-hidden rounded-2xl border border-border shadow-control py-(--card-gap) text-sm has-[>img:first-child]:pt-0 *:[img:first-child]:rounded-t-2xl *:[img:last-child]:rounded-b-2xl",
58
+ interactiveCardVariants({ target: "link" }),
59
+ LINKED_CARD_CONTROLS,
43
60
  ACCENT_CARD,
44
61
  className
45
62
  )}
@@ -108,6 +125,35 @@ const cardCountTone: Record<CardCountTone, string> = {
108
125
  critical: "text-destructive-text",
109
126
  }
110
127
 
128
+ /**
129
+ * Makes the whole card open one page or one dialog. Place it in CardTitle
130
+ * around the title text: its ::after stretches over the card, so a click on
131
+ * any point of the card opens it, while keyboard and screen reader users get
132
+ * one tab stop named by the title. Renders a `<button>` for an `onClick`
133
+ * handler (a card that opens a dialog); pass `render={<a href="…" />}` or a
134
+ * router link element to open a page. Use one per card. Other controls in the
135
+ * card stay clickable above it.
136
+ */
137
+ function CardLink({ className, render, ...props }: useRender.ComponentProps<"button">) {
138
+ return useRender({
139
+ defaultTagName: "button",
140
+ render,
141
+ props: mergeProps<"button">(
142
+ {
143
+ // A native button submits its form by default; a rendered anchor or
144
+ // router link takes no type.
145
+ type: render ? undefined : "button",
146
+ className: cn(
147
+ "cursor-pointer text-start text-inherit outline-none after:absolute after:inset-0",
148
+ className
149
+ ),
150
+ },
151
+ props
152
+ ),
153
+ state: { slot: "card-link" },
154
+ })
155
+ }
156
+
111
157
  function CardCount({
112
158
  className,
113
159
  tone = "neutral",
@@ -241,6 +287,7 @@ export {
241
287
  CardHeader,
242
288
  CardFooter,
243
289
  CardTitle,
290
+ CardLink,
244
291
  CardCount,
245
292
  CardAction,
246
293
  CardDescription,
@@ -1,6 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible"
4
+ import { cn } from "../../lib/utils.ts"
4
5
  import { triggerSlot } from "../../lib/trigger-slot.ts"
5
6
 
6
7
  function Collapsible({ ...props }: CollapsiblePrimitive.Root.Props) {
@@ -13,9 +14,28 @@ function CollapsibleTrigger({ ...props }: CollapsiblePrimitive.Trigger.Props) {
13
14
  )
14
15
  }
15
16
 
16
- function CollapsibleContent({ ...props }: CollapsiblePrimitive.Panel.Props) {
17
+ /**
18
+ * The panel eases its height with a CSS transition on the height curve, so a
19
+ * second click mid-way reverses from where the panel is. Nothing animates on
20
+ * first render: a panel that starts open just shows. The panel clips its
21
+ * content only while the height runs (starting and ending style, and for one
22
+ * slow duration after the open starts), so focus rings and popovers inside are
23
+ * not cut off once it is open. Under reduced motion the height snaps and only
24
+ * a short fade remains.
25
+ */
26
+ function CollapsibleContent({
27
+ className,
28
+ ...props
29
+ }: CollapsiblePrimitive.Panel.Props) {
17
30
  return (
18
- <CollapsiblePrimitive.Panel data-slot="collapsible-content" {...props} />
31
+ <CollapsiblePrimitive.Panel
32
+ data-slot="collapsible-content"
33
+ className={cn(
34
+ "h-(--collapsible-panel-height) data-starting-style:h-0 data-starting-style:overflow-hidden data-ending-style:h-0 data-ending-style:overflow-hidden motion-safe:[transition:height_var(--transition-duration-slow)_var(--ease-height),overflow_0s_var(--transition-duration-slow)_allow-discrete] motion-safe:data-ending-style:[transition-delay:0s] motion-reduce:transition-opacity motion-reduce:duration-fast motion-reduce:ease-default motion-reduce:data-starting-style:opacity-0 motion-reduce:data-ending-style:h-(--collapsible-panel-height) motion-reduce:data-ending-style:opacity-0",
35
+ className
36
+ )}
37
+ {...props}
38
+ />
19
39
  )
20
40
  }
21
41
 
@@ -3,33 +3,89 @@
3
3
  import { Switch as SwitchPrimitive } from "@base-ui/react/switch"
4
4
 
5
5
  import { cn } from "@vendure-io/ui/lib/utils"
6
+ import { useUserToggleMotion } from "../../hooks/use-user-toggle-motion"
6
7
  import {
7
8
  useFieldControlProps,
8
9
  useFieldLabelCheckedClass,
9
10
  } from "@vendure-io/ui/components/atoms/field"
10
11
 
12
+ // The thumb slides with `translate` and widens a little while pressed, both
13
+ // with the Checkbox's tokens. Only `translate`, `scale` and colours move, so
14
+ // nothing changes layout.
15
+ // - Checking: the track fills in `normal` on `ease-out` and the thumb slides
16
+ // in `normal` on `ease-out`. Unchecking is quicker: `fast` on `ease-soft`
17
+ // for the track, `moderate` on `ease-out` for the thumb.
18
+ // - A press stretches the thumb to 115% of its width (`fast`, `ease-press`)
19
+ // toward the middle of the track: it grows from the side it rests on. The
20
+ // scale is its own property, so it adds to the slide instead of replacing
21
+ // it. A disabled switch does not respond.
22
+ // - Transitions only, no keyframes: a fast double toggle reverses from where
23
+ // the thumb is, and nothing plays on first render, where there is no
24
+ // previous value to move from.
25
+ // - Reduced motion: no slide and no stretch. The thumb is at its place at
26
+ // once; only the colours fade.
27
+ // - Only the user moves it. A controlled `checked` that changes from code
28
+ // (data loads after render, a form reset, another control) shows at once:
29
+ // the thumb and the track colours drop their transitions, and only the
30
+ // press stretch and the focus and disabled fades stay. A change after a
31
+ // pointer or keyboard toggle keeps the motion above. An uncontrolled switch
32
+ // only changes by the user, so it always moves.
33
+ const trackTransition =
34
+ "[transition:background-color_var(--transition-duration-fast)_var(--ease-soft),border-color_var(--transition-duration-fast)_var(--ease-soft),box-shadow_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-moderate)_var(--ease-default)] data-checked:[transition:background-color_var(--transition-duration-normal)_var(--ease-out),border-color_var(--transition-duration-normal)_var(--ease-out),box-shadow_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-moderate)_var(--ease-default)]"
35
+
36
+ const thumbTransition =
37
+ "[transition:translate_var(--transition-duration-moderate)_var(--ease-out),scale_var(--transition-duration-fast)_var(--ease-press),background-color_var(--transition-duration-fast)_var(--ease-soft)] data-checked:[transition:translate_var(--transition-duration-normal)_var(--ease-out),scale_var(--transition-duration-fast)_var(--ease-press),background-color_var(--transition-duration-normal)_var(--ease-out)] motion-reduce:[transition:background-color_var(--transition-duration-fast)_var(--ease-soft)] motion-reduce:data-checked:[transition:background-color_var(--transition-duration-normal)_var(--ease-soft)]"
38
+
39
+ const trackInstant =
40
+ "[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft),opacity_var(--transition-duration-moderate)_var(--ease-default)]"
41
+
42
+ const thumbInstant =
43
+ "[transition:scale_var(--transition-duration-fast)_var(--ease-press)] motion-reduce:[transition:none]"
44
+
45
+ const thumbPress =
46
+ "origin-left data-checked:origin-right motion-safe:group-[:active:not([data-disabled])]/switch:scale-x-[1.15]"
47
+
11
48
  function Switch({
12
49
  className,
13
50
  size = "default",
51
+ checked,
52
+ onCheckedChange,
14
53
  ...props
15
54
  }: SwitchPrimitive.Root.Props & {
16
55
  size?: "sm" | "default"
17
56
  }) {
18
57
  const fieldLabelChecked = useFieldLabelCheckedClass()
58
+ const { animate, markUserToggled } = useUserToggleMotion(checked)
59
+ const handleCheckedChange: SwitchPrimitive.Root.Props["onCheckedChange"] = (
60
+ value,
61
+ details
62
+ ) => {
63
+ markUserToggled()
64
+ onCheckedChange?.(value, details)
65
+ }
19
66
  return (
20
67
  <SwitchPrimitive.Root
21
68
  data-slot="switch"
22
69
  data-size={size}
23
70
  className={(state) => cn(
24
- "data-checked:bg-primary data-unchecked:bg-control-border focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring aria-invalid:focus-visible:outline-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-[background-color,border-color,box-shadow,opacity] outline-none after:absolute after:-inset-x-3 after:-inset-y-2 aria-invalid:ring-3 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px]",
71
+ "data-checked:bg-primary data-unchecked:bg-control-border focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring aria-invalid:focus-visible:outline-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent outline-none after:absolute after:-inset-x-3 after:-inset-y-2 aria-invalid:ring-3 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px]",
72
+ animate ? trackTransition : trackInstant,
25
73
  fieldLabelChecked(state.checked),
26
74
  typeof className === "function" ? className(state) : className
27
75
  )}
28
- {...useFieldControlProps(props)}
76
+ {...useFieldControlProps({
77
+ ...props,
78
+ checked,
79
+ onCheckedChange: handleCheckedChange,
80
+ })}
29
81
  >
30
82
  <SwitchPrimitive.Thumb
31
83
  data-slot="switch-thumb"
32
- className="bg-background dark:data-unchecked:bg-foreground dark:data-checked:bg-primary-foreground pointer-events-none block rounded-full ring-0 transition-transform motion-reduce:transition-none group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0"
84
+ className={cn(
85
+ animate ? thumbTransition : thumbInstant,
86
+ thumbPress,
87
+ "bg-background dark:data-unchecked:bg-foreground dark:data-checked:bg-primary-foreground pointer-events-none block rounded-full ring-0 group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0"
88
+ )}
33
89
  />
34
90
  </SwitchPrimitive.Root>
35
91
  )
@@ -0,0 +1,125 @@
1
+ import { mergeProps } from "@base-ui/react/merge-props"
2
+ import { useRender } from "@base-ui/react/use-render"
3
+ import { cva } from "class-variance-authority"
4
+ import { ArrowUpRight } from "lucide-react"
5
+
6
+ import { cn } from "@vendure-io/ui/lib/utils"
7
+
8
+ // A link for running text and for small standalone links. It is `inline`,
9
+ // not `inline-flex`, so a long label wraps with the sentence, and it sets no
10
+ // font size, weight or line height: it takes them from the text around it.
11
+ // `w-fit` keeps it to its label when it is a flex or grid item, where it
12
+ // would otherwise stretch, and has no effect inline.
13
+ //
14
+ // The underline sits 4px under the baseline (`underline-offset-4`, as the
15
+ // Button link look) and is 1px.
16
+ //
17
+ // The focus ring is the design-system ring, 2px solid `ring`, but at offset 0
18
+ // instead of 2px: the space between two words is about 4px, so an outset ring
19
+ // would touch the next word, and the ring of one line would touch the next
20
+ // line. While the ring shows, the underline is hidden: at offset 0 it would
21
+ // run into the ring's lower edge, and the ring already marks the link.
22
+ // `box-decoration-clone` closes the ring on each line of a wrapped link.
23
+ //
24
+ // `default`: `primary` text, always underlined in `brand-indicator`. The text
25
+ // colour alone is too close to body text to mark a link inside a sentence,
26
+ // so the underline is the cue. On hover the text and the underline turn
27
+ // `brand-text`; on keyboard focus the text turns `brand-text`.
28
+ // `quiet`: `muted-foreground` text with no underline at rest, for a small
29
+ // standalone link that must not compete with the actions next to it
30
+ // ("Forgot password?", "Terms"). On hover the text reaches `foreground` and
31
+ // the underline appears in the text colour; on keyboard focus the text
32
+ // reaches `foreground`. Without an
33
+ // underline at rest it is not marked as a link inside a sentence: use
34
+ // `default` there.
35
+ //
36
+ // Colour and underline colour ease in `quick` on `soft`. Nothing moves, so
37
+ // reduced motion needs no other look.
38
+ //
39
+ // `external`: opens in a new tab with `rel="noopener noreferrer"`, ends with a
40
+ // decorative up-right arrow sized to the text (60%, full on hover or focus),
41
+ // and adds "(opens in a new tab)" for screen readers. A word joiner keeps the
42
+ // arrow on the line of the last word; it is hidden with the arrow, so it
43
+ // stays out of the accessible name. In right-to-left the arrow points
44
+ // up-left.
45
+
46
+ const textLinkVariants = cva(
47
+ "group/text-link inline w-fit cursor-pointer rounded-sm underline decoration-1 underline-offset-4 box-decoration-clone transition-colors duration-quick ease-soft outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-ring focus-visible:decoration-transparent",
48
+ {
49
+ variants: {
50
+ tone: {
51
+ default:
52
+ "text-primary decoration-brand-indicator hover:text-brand-text hover:decoration-brand-text focus-visible:text-brand-text",
53
+ quiet:
54
+ "text-muted-foreground decoration-transparent hover:text-foreground hover:decoration-current focus-visible:text-foreground",
55
+ },
56
+ },
57
+ defaultVariants: {
58
+ tone: "default",
59
+ },
60
+ }
61
+ )
62
+
63
+ type TextLinkProps = useRender.ComponentProps<"a"> & {
64
+ /**
65
+ * - `'default'`: link colour, always underlined. Use it inside a sentence.
66
+ * - `'quiet'`: muted text, underlined on hover. Use it for a small
67
+ * standalone link next to more important actions.
68
+ */
69
+ tone?: "default" | "quiet"
70
+ /**
71
+ * Opens another site in a new tab: sets `target="_blank"` and
72
+ * `rel="noopener noreferrer"` (your own `target` and `rel` win) and adds a
73
+ * trailing arrow and a screen-reader note.
74
+ */
75
+ external?: boolean
76
+ /** The screen-reader note of an `external` link. */
77
+ externalLabel?: string
78
+ }
79
+
80
+ /**
81
+ * A link inside running text, or a small standalone link. Renders an `<a>`;
82
+ * pass `render` to use a router link. It always keeps the link role.
83
+ */
84
+ function TextLink({
85
+ tone = "default",
86
+ external = false,
87
+ externalLabel = "(opens in a new tab)",
88
+ className,
89
+ render,
90
+ children,
91
+ ...props
92
+ }: TextLinkProps) {
93
+ return useRender({
94
+ defaultTagName: "a",
95
+ render,
96
+ props: mergeProps<"a">(
97
+ {
98
+ className: cn(textLinkVariants({ tone }), className),
99
+ ...(external ? { target: "_blank", rel: "noopener noreferrer" } : {}),
100
+ children: external ? (
101
+ <>
102
+ {children}
103
+ <span className="sr-only"> {externalLabel}</span>
104
+ <span aria-hidden="true">
105
+ {"⁠"}
106
+ <ArrowUpRight
107
+ aria-hidden="true"
108
+ data-slot="text-link-external-icon"
109
+ strokeWidth={1.75}
110
+ className="ms-0.5 inline-block size-[0.875em] align-[-0.0625em] opacity-60 transition-opacity duration-moderate ease-soft group-hover/text-link:opacity-100 group-focus-visible/text-link:opacity-100 rtl:-scale-x-100"
111
+ />
112
+ </span>
113
+ </>
114
+ ) : (
115
+ children
116
+ ),
117
+ },
118
+ props
119
+ ),
120
+ state: { slot: "text-link", tone },
121
+ })
122
+ }
123
+
124
+ export { TextLink }
125
+ export type { TextLinkProps }
@@ -116,7 +116,21 @@ function AppShellMain({
116
116
  // it on the element that wraps the page and changes its `key` with the route.
117
117
  const pageEnterClassName = 'animate-page-enter motion-reduce:animate-page-fade';
118
118
 
119
- // AppShellPage wraps the page inside AppShellMain. When it mounts, the page
119
+ // The page frame: one frame for every app on AppShell. The page is centred in
120
+ // AppShellMain, its content is at most 1180px wide, and a gutter of 32px (16px
121
+ // below 768px) sits on every side, the top and bottom included. The gutter is
122
+ // outside the 1180px, so the frame is at most 1180px plus two gutters wide.
123
+ //
124
+ // The values are CSS variables on the frame, `--app-shell-page-width` and
125
+ // `--app-shell-page-gutter`, so a descendant can read them (a full-bleed band
126
+ // pulls out by the gutter). The app sets no page padding or width of its own.
127
+ // A page that wants a narrower column, such as a settings form at `max-w-4xl`,
128
+ // puts it inside the frame; it stays left-aligned there.
129
+ const pageFrameClassName =
130
+ '[--app-shell-page-width:1180px] [--app-shell-page-gutter:--spacing(4)] md:[--app-shell-page-gutter:--spacing(8)] mx-auto w-full min-w-0 max-w-[calc(var(--app-shell-page-width)+2*var(--app-shell-page-gutter))] p-(--app-shell-page-gutter)';
131
+
132
+ // AppShellPage wraps the page inside AppShellMain. It is the page frame (see
133
+ // pageFrameClassName), and it is the page enter: when it mounts, the page
120
134
  // fades in (220ms) and rises 6px into place (260ms) on the `out` curve; with
121
135
  // reduced motion it only fades. The header and the sidebar stay still.
122
136
  //
@@ -125,9 +139,16 @@ const pageEnterClassName = 'animate-page-enter motion-reduce:animate-page-fade';
125
139
  // it a `key` that changes with the route (the pathname) so a new page mounts a
126
140
  // new element. Only opacity and transform move: no layout shift, and the page
127
141
  // takes clicks while it settles.
142
+ //
143
+ // A layout that keeps its own wrapper takes the frame from pageFrameClassName
144
+ // and, if it wants the motion, the enter from pageEnterClassName.
128
145
  function AppShellPage({ className, ...props }: React.ComponentProps<'div'>) {
129
146
  return (
130
- <div data-slot="app-shell-page" className={cn(pageEnterClassName, className)} {...props} />
147
+ <div
148
+ data-slot="app-shell-page"
149
+ className={cn(pageFrameClassName, pageEnterClassName, className)}
150
+ {...props}
151
+ />
131
152
  );
132
153
  }
133
154
 
@@ -139,5 +160,6 @@ export {
139
160
  AppShellMain,
140
161
  AppShellPage,
141
162
  pageEnterClassName,
163
+ pageFrameClassName,
142
164
  type AppShellMainProps,
143
165
  };