@vendure-io/ui 3.0.0-next.1 → 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.
Files changed (32) hide show
  1. package/THIRD_PARTY_NOTICES.md +38 -0
  2. package/package.json +6 -4
  3. package/src/components/atoms/breadcrumb.tsx +67 -9
  4. package/src/components/atoms/button.tsx +106 -9
  5. package/src/components/atoms/calendar.tsx +11 -2
  6. package/src/components/atoms/card.tsx +47 -0
  7. package/src/components/atoms/collapsible.tsx +22 -2
  8. package/src/components/atoms/field.tsx +4 -1
  9. package/src/components/atoms/label-swap.tsx +27 -2
  10. package/src/components/atoms/sonner.tsx +1 -1
  11. package/src/components/atoms/switch.tsx +59 -3
  12. package/src/components/atoms/table.tsx +133 -10
  13. package/src/components/atoms/text-link.tsx +125 -0
  14. package/src/components/molecules/app-shell.tsx +24 -2
  15. package/src/components/molecules/checklist/checklist.tsx +891 -0
  16. package/src/components/molecules/choice-card.tsx +377 -0
  17. package/src/components/molecules/collapsible-section.tsx +6 -5
  18. package/src/components/molecules/data-table/data-table-helpers.tsx +6 -1
  19. package/src/components/molecules/data-table/data-table-types.tsx +27 -2
  20. package/src/components/molecules/data-table/data-table.tsx +154 -30
  21. package/src/components/molecules/direction-link.tsx +1 -1
  22. package/src/components/molecules/format-provider.tsx +12 -2
  23. package/src/components/molecules/interactive-card.tsx +45 -0
  24. package/src/components/molecules/page-header.tsx +1 -1
  25. package/src/components/molecules/search-trigger.tsx +1 -1
  26. package/src/components/molecules/state-views/loading-state.tsx +37 -7
  27. package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
  28. package/src/components/molecules/status-badge.tsx +49 -16
  29. package/src/components/molecules/step-indicator.tsx +341 -0
  30. package/src/components/molecules/timeline.tsx +1 -1
  31. package/src/hooks/use-user-toggle-motion.ts +50 -0
  32. package/src/lib/state-dictionary.ts +9 -7
@@ -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.1",
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/",
@@ -47,7 +49,7 @@
47
49
  "pack:check": "bun pm pack --dry-run"
48
50
  },
49
51
  "peerDependencies": {
50
- "@vendure-io/design-tokens": "^3.0.0-next.1",
52
+ "@vendure-io/design-tokens": "^3.0.0-next.2",
51
53
  "react": ">=19",
52
54
  "react-dom": ">=19",
53
55
  "next": ">=14",
@@ -32,6 +32,7 @@ import {
32
32
  CommandList,
33
33
  } from "./command.tsx"
34
34
  import { Popover, PopoverContent, PopoverTrigger } from "./popover.tsx"
35
+ import { Skeleton } from "./skeleton.tsx"
35
36
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.tsx"
36
37
  // Relative: `label-swap` is closed in the package exports.
37
38
  import { LabelSwap } from "./label-swap.tsx"
@@ -196,8 +197,24 @@ type BreadcrumbMenuBaseProps = {
196
197
  /**
197
198
  * The crumb's label when no option has `value`, such as "All projects"
198
199
  * while none is open, or "Projects unavailable". It swaps like an option.
200
+ * While `pending`, pass the last known name here (from a cache or the
201
+ * previous page) when the options do not have it yet; `undefined` when
202
+ * nothing is known.
199
203
  */
200
204
  placeholder?: string
205
+ /**
206
+ * The current item is still loading or being confirmed. Show the name
207
+ * until it is known to be wrong: while pending, the crumb shows the
208
+ * option for `value`, or else `placeholder`, as usual. Only when neither
209
+ * names the item does it show a text skeleton one line tall: it takes no
210
+ * clicks or focus, and a screen reader hears one status, "<label>:
211
+ * Loading…". The first name after the skeleton shows at once, with no
212
+ * swap. When the confirmed name differs from the one shown, the label
213
+ * swaps as usual; when it is the same, nothing moves. Never pass a
214
+ * placeholder word such as "Project" for an unknown name: leave
215
+ * `placeholder` undefined and the skeleton shows.
216
+ */
217
+ pending?: boolean
201
218
  open?: boolean
202
219
  onOpenChange?: (open: boolean) => void
203
220
  defaultOpen?: boolean
@@ -236,6 +253,30 @@ function useMenuOpen(
236
253
  const crumbTriggerClassName =
237
254
  "text-foreground hover:text-foreground aria-expanded:text-foreground min-w-0 shrink gap-2.25 rounded-lg ps-2.25 pe-1.75 text-sm font-semibold [--content-inset:calc(var(--spacing)*2.25+1px)]"
238
255
 
256
+ /**
257
+ * A crumb menu while its name loads: the crumb's box (28px tall, the same
258
+ * insets and transparent border) with a text skeleton where the name goes.
259
+ * The bar is `0.8lh` of the `text-sm` line, so it follows the line-height
260
+ * token, not a pixel size. It is not a button: nothing opens until the name
261
+ * is known. The skeleton is hidden from screen readers, which hear the
262
+ * status text instead. A `div`, as the skeleton is one.
263
+ */
264
+ function PendingCrumb({ label, className }: { label: string; className?: string }) {
265
+ return (
266
+ <div
267
+ role="status"
268
+ data-slot="breadcrumb-menu-pending"
269
+ className={cn(
270
+ "inline-flex h-7 min-w-0 shrink items-center rounded-lg border border-transparent ps-2.25 pe-1.75 text-sm",
271
+ className
272
+ )}
273
+ >
274
+ <span className="sr-only">{`${label}: Loading…`}</span>
275
+ <Skeleton aria-hidden className="h-[0.8lh] w-24 min-w-0 shrink" />
276
+ </div>
277
+ )
278
+ }
279
+
239
280
  /**
240
281
  * The inside of the crumb, and its tooltip. The crumb's accessible name is
241
282
  * the list label, the option label and then the status, whatever shows
@@ -254,14 +295,16 @@ function useCrumbTrigger({
254
295
  }) {
255
296
  const found = options.findIndex((option) => option.value === value)
256
297
  const fallback = placeholder !== undefined && found === -1
257
- // The placeholder has its own place before the options, so the options
258
- // arriving after a read swap the label, never rewrite it in place.
259
- const offset = placeholder === undefined ? 0 : 1
260
- const active = fallback ? 0 : Math.max(0, found) + offset
261
- const current = fallback ? undefined : options[active - offset]
262
- const labels = options.map((option) => option.label)
263
- if (placeholder !== undefined) labels.unshift(placeholder)
298
+ // The placeholder has its own place before the options, also while it is
299
+ // undefined, so the options arriving after a read swap the label, never
300
+ // rewrite it in place: a last known name passed while pending and then
301
+ // dropped does not shift the options' places.
302
+ const active = fallback ? 0 : Math.max(0, found) + 1
303
+ const current = fallback ? undefined : options[active - 1]
304
+ const labels = [placeholder ?? "", ...options.map((option) => option.label)]
264
305
  const currentLabel = labels[active] ?? ""
306
+ // Whether an option or the placeholder names the current item.
307
+ const named = found !== -1 || placeholder !== undefined
265
308
  // With a status, the name is set so the status comes after the label.
266
309
  // Without one, the name comes from the content, as before.
267
310
  const name = current?.status ? `${label}: ${currentLabel}, ${current.status}` : undefined
@@ -297,7 +340,7 @@ function useCrumbTrigger({
297
340
  // The tooltip shows only for a cut label, and never over the open menu.
298
341
  const tooltip =
299
342
  cut && !open ? <TooltipContent side="bottom">{currentLabel}</TooltipContent> : null
300
- return { triggerProps, content, tooltip }
343
+ return { triggerProps, content, tooltip, named }
301
344
  }
302
345
 
303
346
  function stopPropagation(event: React.SyntheticEvent) {
@@ -372,6 +415,10 @@ function isNewTabClick(event: Event | undefined) {
372
415
  * shows it in full. An option with `href` or `render` is a link; the current
373
416
  * row stays a checked `menuitemradio`. `open` and `onOpenChange` control the
374
417
  * menu. For a long list with a search field, use `BreadcrumbSearchMenu`.
418
+ *
419
+ * While the current item loads, pass `pending`, and the last known name as an
420
+ * option or `placeholder` if there is one: the crumb shows that name, or a
421
+ * text skeleton when there is none.
375
422
  */
376
423
  function BreadcrumbMenu({
377
424
  options,
@@ -379,6 +426,7 @@ function BreadcrumbMenu({
379
426
  onValueChange,
380
427
  label,
381
428
  placeholder,
429
+ pending = false,
382
430
  open: openProp,
383
431
  onOpenChange,
384
432
  defaultOpen = false,
@@ -391,6 +439,9 @@ function BreadcrumbMenu({
391
439
  }) {
392
440
  const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
393
441
  const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
442
+ // Without a name, a skeleton. The trigger mounts with the first name, so
443
+ // it shows without a swap.
444
+ if (pending && !crumb.named) return <PendingCrumb label={label} className={className} />
394
445
  return (
395
446
  <DropdownMenu open={open} onOpenChange={setOpen}>
396
447
  <Tooltip>
@@ -471,7 +522,10 @@ function searchFilter(_value: string, search: string, keywords?: string[]) {
471
522
  * options. `error` shows its text as a row that cannot be picked and, with
472
523
  * `onRetry`, a Retry row. A search that matches nothing shows `emptyText`.
473
524
  * Footer items are `CommandItem`s with `forceMount`, so a search does not
474
- * hide them, and close the popup themselves through `onOpenChange`.
525
+ * hide them, and close the popup themselves through `onOpenChange`. *
526
+ * `loading` is about the list in the open popup. `pending` is about the
527
+ * crumb: while the current item loads, it shows the last known name, or a
528
+ * text skeleton in place of a placeholder word when no name is known.
475
529
  */
476
530
  function BreadcrumbSearchMenu({
477
531
  options,
@@ -479,6 +533,7 @@ function BreadcrumbSearchMenu({
479
533
  onValueChange,
480
534
  label,
481
535
  placeholder,
536
+ pending = false,
482
537
  open: openProp,
483
538
  onOpenChange,
484
539
  defaultOpen = false,
@@ -507,6 +562,9 @@ function BreadcrumbSearchMenu({
507
562
  const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
508
563
  const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
509
564
  const failed = error != null && error !== false
565
+ // Without a name, a skeleton. The trigger mounts with the first name, so
566
+ // it shows without a swap.
567
+ if (pending && !crumb.named) return <PendingCrumb label={label} className={className} />
510
568
  return (
511
569
  <Popover open={open} onOpenChange={setOpen}>
512
570
  <Tooltip>
@@ -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.
@@ -10,7 +12,7 @@ import { contentInsetPull } from "@vendure-io/ui/lib/content-inset"
10
12
  import { cn } from "@vendure-io/ui/lib/utils"
11
13
  import { outlineEdge, outlineEdgeHover } from "@vendure-io/ui/lib/outline-edge"
12
14
 
13
- // The v3 look: 34px default and 28px sm, the xl radius, 13px medium text.
15
+ // The v3 look: 34px default and 28px sm, the xl radius, 14px medium text.
14
16
  // Every size keeps its side padding with or without a `data-icon` icon;
15
17
  // default and sm have a 7px gap. Press feedback is a 0.97 scale on :active,
16
18
  // on ease-press in 150ms. Base UI's Button never emits data-pressed, so the
@@ -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
  }
@@ -10,6 +10,7 @@ import {
10
10
 
11
11
  import { cn } from "@vendure-io/ui/lib/utils"
12
12
  import { Button, buttonVariants } from "@vendure-io/ui/components/atoms/button"
13
+ import { useFormatSettings } from "@vendure-io/ui/components/molecules/format-provider"
13
14
  import { ChevronLeftIcon, ChevronRightIcon, ChevronDownIcon } from "lucide-react"
14
15
 
15
16
  function Calendar({
@@ -26,6 +27,10 @@ function Calendar({
26
27
  buttonVariant?: React.ComponentProps<typeof Button>["variant"]
27
28
  }) {
28
29
  const defaultClassNames = getDefaultClassNames()
30
+ // The pickers render this Calendar, so the language set on FormatProvider
31
+ // reaches their popups without each caller passing `locale`.
32
+ const { calendarLocale } = useFormatSettings()
33
+ locale ??= calendarLocale
29
34
 
30
35
  return (
31
36
  <DayPicker
@@ -39,8 +44,12 @@ function Calendar({
39
44
  captionLayout={captionLayout}
40
45
  locale={locale}
41
46
  formatters={{
42
- formatMonthDropdown: (date) =>
43
- date.toLocaleString(locale?.code, { month: "short" }),
47
+ // Through DayPicker's date library, so the month names follow `locale`
48
+ // (US English without one) like the caption, not the browser language.
49
+ formatMonthDropdown: (date, dateLib) =>
50
+ dateLib
51
+ ? dateLib.format(date, "LLL")
52
+ : date.toLocaleString(locale?.code, { month: "short" }),
44
53
  ...formatters,
45
54
  }}
46
55
  classNames={{
@@ -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
 
@@ -19,8 +19,11 @@ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
19
19
  return (
20
20
  <fieldset
21
21
  data-slot="field-set"
22
+ // min-w-0: a browser fieldset defaults to min-inline-size: min-content, so
23
+ // a wide child (a table) would stretch it past its container instead of
24
+ // scrolling in the child's own container.
22
25
  className={cn(
23
- "flex flex-col gap-6 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
26
+ "flex min-w-0 flex-col gap-6 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
24
27
  className
25
28
  )}
26
29
  {...props}
@@ -38,6 +38,22 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
38
38
  activeKey?: string
39
39
  }
40
40
 
41
+ /** The label a swap shows, and whether it arrived without the swap. */
42
+ type Shown = { active: number; label: React.ReactNode; still: boolean }
43
+
44
+ /**
45
+ * The next `Shown` when `active` or its label changes, or `undefined` when
46
+ * nothing changed. A move to another index whose label has the same words
47
+ * (text or a number) is still: the words do not change, so nothing moves.
48
+ * A new text at the same index rewrites in place, as before.
49
+ */
50
+ function nextShown(shown: Shown, active: number, label: React.ReactNode): Shown | undefined {
51
+ if (shown.active === active && shown.label === label) return undefined
52
+ const sameWords =
53
+ (typeof label === "string" || typeof label === "number") && shown.label === label
54
+ return { active, label, still: shown.active !== active && sameWords }
55
+ }
56
+
41
57
  /**
42
58
  * Internal: the one label swap behind `ButtonLabelSwap` and
43
59
  * `TooltipLabelSwap`. Not exported from the package.
@@ -48,6 +64,8 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
48
64
  * the swap eases to the active label's width and height on the drawer curve.
49
65
  * The size follows the label while it is active (see `useActiveLabelSize`).
50
66
  * With reduced motion the labels only crossfade, and the size changes at once.
67
+ * When `active` moves to a label with the same words as the one shown, the
68
+ * labels change places without a transition, so nothing moves.
51
69
  */
52
70
  function LabelSwap({
53
71
  labels,
@@ -61,6 +79,12 @@ function LabelSwap({
61
79
  ...props
62
80
  }: LabelSwapProps) {
63
81
  const { refs, width, height } = useActiveLabelSize(active, { natural: truncate, key: activeKey })
82
+ // Kept across renders, so a move between labels with the same words is
83
+ // known in the render that makes it.
84
+ const [shown, setShown] = React.useState<Shown>({ active, label: labels[active], still: false })
85
+ const next = nextShown(shown, active, labels[active])
86
+ if (next) setShown(next)
87
+ const still = (next ?? shown).still ? { transition: "none" } : undefined
64
88
  // While the width eases, a growing label is clipped, as without
65
89
  // `truncate`; the ellipsis shows only at rest, so it does not flash.
66
90
  const [resizing, setResizing] = React.useState(false)
@@ -84,7 +108,7 @@ function LabelSwap({
84
108
  truncate && "min-w-0 shrink",
85
109
  className
86
110
  )}
87
- style={width === undefined ? style : { ...style, width, height }}
111
+ style={width === undefined ? { ...style, ...still } : { ...style, ...still, width, height }}
88
112
  {...props}
89
113
  >
90
114
  {labels.map((label, index) => (
@@ -95,6 +119,7 @@ function LabelSwap({
95
119
  refs.current[index] = element
96
120
  }}
97
121
  data-swap={index === active ? "in" : index < active ? "before" : "after"}
122
+ style={still}
98
123
  aria-hidden={index === active ? undefined : true}
99
124
  className={cn(
100
125
  "col-start-1 row-start-1 [transition:opacity_var(--label-swap-fade)_var(--ease-soft),translate_var(--label-swap-move)_var(--ease-out),filter_var(--label-swap-fade)_var(--ease-soft)] data-[swap=after]:opacity-0 data-[swap=before]:opacity-0 motion-safe:data-[swap=after]:translate-y-(--label-swap-shift) motion-safe:data-[swap=before]:-translate-y-(--label-swap-shift) motion-safe:data-[swap=after]:blur-[2px] motion-safe:data-[swap=before]:blur-[2px]",
@@ -109,5 +134,5 @@ function LabelSwap({
109
134
  )
110
135
  }
111
136
 
112
- export { LabelSwap }
137
+ export { LabelSwap, nextShown }
113
138
  export type { LabelSwapProps }
@@ -91,7 +91,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
91
91
  classNames: {
92
92
  // Sonner's own stylesheet is unlayered, so the overlay shadow and
93
93
  // the type need ! to win over it.
94
- // 44px high, 10px 14px padding, 13px medium text, a 10px gap. The
94
+ // 44px high, 10px 14px padding, 14px medium text, a 10px gap. The
95
95
  // overlay shadow gives the edge. The toast has no
96
96
  // border and no inset hairline: either would sit next to the
97
97
  // shadow's 1px edge and read as a second line. A new toast fades in from 12px