@vendure-io/ui 3.0.0-next.4 → 3.0.0-next.6
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.
- package/package.json +12 -11
- package/src/components/atoms/alert-dialog.tsx +1 -4
- package/src/components/atoms/alert.tsx +59 -35
- package/src/components/atoms/badge.tsx +2 -2
- package/src/components/atoms/breadcrumb.tsx +154 -59
- package/src/components/atoms/button-group.tsx +1 -1
- package/src/components/atoms/button.tsx +2 -2
- package/src/components/atoms/calendar.tsx +2 -2
- package/src/components/atoms/card.tsx +15 -2
- package/src/components/atoms/carousel.tsx +33 -7
- package/src/components/atoms/chart.tsx +3 -3
- package/src/components/atoms/checkbox.tsx +1 -1
- package/src/components/atoms/combobox.tsx +60 -36
- package/src/components/atoms/command.tsx +17 -7
- package/src/components/atoms/context-menu.tsx +5 -5
- package/src/components/atoms/dialog.tsx +30 -14
- package/src/components/atoms/dropdown-menu.tsx +1 -1
- package/src/components/atoms/hover-card.tsx +1 -1
- package/src/components/atoms/input-group.tsx +30 -12
- package/src/components/atoms/input-otp.tsx +2 -2
- package/src/components/atoms/input.tsx +13 -3
- package/src/components/atoms/menubar.tsx +2 -2
- package/src/components/atoms/native-select.tsx +1 -1
- package/src/components/atoms/navigation-menu.tsx +3 -3
- package/src/components/atoms/pagination.tsx +52 -15
- package/src/components/atoms/popover.tsx +1 -1
- package/src/components/atoms/select.tsx +3 -3
- package/src/components/atoms/sheet.tsx +35 -15
- package/src/components/atoms/sidebar.tsx +224 -36
- package/src/components/atoms/skeleton.tsx +6 -3
- package/src/components/atoms/spinner.tsx +7 -2
- package/src/components/atoms/tabs.tsx +6 -2
- package/src/components/atoms/textarea.tsx +1 -1
- package/src/components/atoms/toggle.tsx +1 -1
- package/src/components/molecules/action-needed.tsx +483 -0
- package/src/components/molecules/anonymized-token.tsx +70 -25
- package/src/components/molecules/app-shell.tsx +14 -5
- package/src/components/molecules/checklist/checklist.tsx +47 -17
- package/src/components/molecules/chip.tsx +37 -19
- package/src/components/molecules/choice-card.tsx +117 -9
- package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
- package/src/components/molecules/code-block/process-code.ts +1 -1
- package/src/components/molecules/code-block.tsx +58 -47
- package/src/components/molecules/combobox-free-text.tsx +75 -20
- package/src/components/molecules/confirm-dialog.tsx +17 -5
- package/src/components/molecules/copyable-text.tsx +10 -8
- package/src/components/molecules/data-table/data-table-filters.tsx +36 -6
- package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
- package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
- package/src/components/molecules/data-table/data-table-types.tsx +156 -29
- package/src/components/molecules/data-table/data-table-view-options.tsx +14 -4
- package/src/components/molecules/data-table/data-table.tsx +156 -75
- package/src/components/molecules/data-table/table-pagination.tsx +142 -38
- package/src/components/molecules/date-picker.tsx +58 -25
- package/src/components/molecules/date-range-picker.tsx +59 -24
- package/src/components/molecules/date-time-picker.tsx +63 -25
- package/src/components/molecules/date-time.tsx +38 -3
- package/src/components/molecules/elapsed-time.tsx +61 -12
- package/src/components/molecules/file-dropzone.tsx +151 -40
- package/src/components/molecules/format-provider.tsx +14 -4
- package/src/components/molecules/id-chip-chrome.tsx +114 -0
- package/src/components/molecules/id-chip.tsx +13 -115
- package/src/components/molecules/issued-secret.tsx +35 -25
- package/src/components/molecules/live-indicator.tsx +1 -1
- package/src/components/molecules/money.tsx +44 -3
- package/src/components/molecules/multi-select.tsx +62 -16
- package/src/components/molecules/page-header.tsx +6 -2
- package/src/components/molecules/password-input.tsx +11 -10
- package/src/components/molecules/relative-time.tsx +88 -16
- package/src/components/molecules/search-trigger.tsx +5 -3
- package/src/components/molecules/secret-value.tsx +35 -19
- package/src/components/molecules/skip-link.tsx +11 -9
- package/src/components/molecules/stat-card.tsx +145 -33
- package/src/components/molecules/state-views/empty-state.tsx +16 -12
- package/src/components/molecules/state-views/error-state.tsx +36 -20
- package/src/components/molecules/state-views/loading-state.tsx +18 -6
- package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
- package/src/components/molecules/status-badge.tsx +11 -35
- package/src/components/molecules/time-tooltip.tsx +55 -1
- package/src/hooks/use-copy.ts +3 -1
- package/src/lib/deprecated.ts +71 -0
- package/src/lib/field-surface.ts +7 -7
- package/src/lib/format-messages.ts +368 -0
- package/src/lib/highlight.ts +1 -1
- package/src/lib/menu-item.tsx +1 -1
- package/src/lib/tint-recipes.ts +10 -5
- package/src/lib/utils.ts +19 -1
- package/src/lib/dialog-padding.ts +0 -48
|
@@ -68,6 +68,12 @@ function AppShellContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
|
68
68
|
// centred in 52px), and 12px to the divider after it (the 6px gap plus a
|
|
69
69
|
// 6px end margin). The header owns these margins, so a margin a consumer
|
|
70
70
|
// puts on the toggle does not apply.
|
|
71
|
+
//
|
|
72
|
+
// The end padding (pe-4) is the page gutter, --app-shell-page-gutter in
|
|
73
|
+
// pageFrameClassName, so the last item in the header ends where the page
|
|
74
|
+
// content does. The header is outside the page frame and cannot read that
|
|
75
|
+
// variable: change both together. On a window wider than the frame, the
|
|
76
|
+
// centred page ends before the header.
|
|
71
77
|
const headerToggleClassName =
|
|
72
78
|
'[&_[data-slot=sidebar-trigger]]:ms-0 [&_[data-slot=sidebar-trigger]]:me-1.5';
|
|
73
79
|
|
|
@@ -76,7 +82,8 @@ function AppShellHeader({ className, ...props }: React.ComponentProps<'header'>)
|
|
|
76
82
|
<header
|
|
77
83
|
data-slot="app-shell-header"
|
|
78
84
|
className={cn(
|
|
79
|
-
|
|
85
|
+
// biome-ignore lint/plugin/no-raw-shadow: the header hairline is an inset shadow so it never adds height
|
|
86
|
+
'bg-background md:in-[[data-variant=inset]~[data-slot=sidebar-inset]]:bg-surface sticky top-0 z-10 flex h-13 shrink-0 items-center gap-1.5 pe-4 ps-3 shadow-[inset_0_-1px_0_var(--border)] forced-colors:after:pointer-events-none forced-colors:after:absolute forced-colors:after:inset-x-0 forced-colors:after:bottom-0 forced-colors:after:border-b forced-colors:after:border-[CanvasText]',
|
|
80
87
|
headerToggleClassName,
|
|
81
88
|
className,
|
|
82
89
|
)}
|
|
@@ -117,9 +124,11 @@ function AppShellMain({
|
|
|
117
124
|
const pageEnterClassName = 'animate-page-enter motion-reduce:animate-page-fade';
|
|
118
125
|
|
|
119
126
|
// The page frame: one frame for every app on AppShell. The page is centred in
|
|
120
|
-
// AppShellMain, its content is at most
|
|
121
|
-
//
|
|
122
|
-
//
|
|
127
|
+
// AppShellMain, its content is at most 1480px wide, and a 16px gutter sits on
|
|
128
|
+
// every side at every width, the top and bottom included. The gutter is outside
|
|
129
|
+
// the 1480px, so the frame is at most 1480px plus two gutters wide.
|
|
130
|
+
// The end padding of AppShellHeader (pe-4) is the same value as the gutter:
|
|
131
|
+
// change both together.
|
|
123
132
|
//
|
|
124
133
|
// The values are CSS variables on the frame, `--app-shell-page-width` and
|
|
125
134
|
// `--app-shell-page-gutter`, so a descendant can read them (a full-bleed band
|
|
@@ -127,7 +136,7 @@ const pageEnterClassName = 'animate-page-enter motion-reduce:animate-page-fade';
|
|
|
127
136
|
// A page that wants a narrower column, such as a settings form at `max-w-4xl`,
|
|
128
137
|
// puts it inside the frame; it stays left-aligned there.
|
|
129
138
|
const pageFrameClassName =
|
|
130
|
-
'[--app-shell-page-width:
|
|
139
|
+
'[--app-shell-page-width:1480px] [--app-shell-page-gutter:--spacing(4)] 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
140
|
|
|
132
141
|
// AppShellPage wraps the page inside AppShellMain. It is the page frame (see
|
|
133
142
|
// pageFrameClassName), and it is the page enter: when it mounts, the page
|
|
@@ -10,6 +10,7 @@ import { cn } from '@vendure-io/ui/lib/utils';
|
|
|
10
10
|
import { ChevronDown, X } from 'lucide-react';
|
|
11
11
|
import { AnimatePresence, LayoutGroup, motion, useIsPresent, useReducedMotion } from 'motion/react';
|
|
12
12
|
import * as React from 'react';
|
|
13
|
+
import { fillMessage, useMessages } from '../../../lib/format-messages.ts';
|
|
13
14
|
|
|
14
15
|
// What was taken from Stealth UI's Checklist: the two lists (open steps, then
|
|
15
16
|
// a "Completed" group) joined by a shared `layoutId`, so a finished step flies
|
|
@@ -166,22 +167,40 @@ type ChecklistProps = Omit<React.ComponentProps<'div'>, 'title' | 'children'> &
|
|
|
166
167
|
* hide itself: remove it in this callback.
|
|
167
168
|
*/
|
|
168
169
|
onDismiss?: () => void;
|
|
169
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Accessible name of the dismiss button.
|
|
172
|
+
* @default `messages.checklist.dismiss`, "Dismiss checklist"
|
|
173
|
+
*/
|
|
170
174
|
dismissLabel?: string;
|
|
171
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Label of the group of finished steps.
|
|
177
|
+
* @default `messages.checklist.completed`, "Completed"
|
|
178
|
+
*/
|
|
172
179
|
completedLabel?: string;
|
|
173
180
|
/** Whether the Completed group is open (controlled). */
|
|
174
181
|
completedOpen?: boolean;
|
|
175
182
|
/** Whether the Completed group starts open. Default `true`. */
|
|
176
183
|
defaultCompletedOpen?: boolean;
|
|
177
184
|
onCompletedOpenChange?: (open: boolean) => void;
|
|
178
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* What a screen reader hears after a done step's label in system mode.
|
|
187
|
+
* @default `messages.checklist.stepDone`, "done"
|
|
188
|
+
*/
|
|
179
189
|
stepDoneLabel?: string;
|
|
180
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* What a screen reader hears after an open step's label in system mode.
|
|
192
|
+
* @default `messages.checklist.stepOpen`, "not done"
|
|
193
|
+
*/
|
|
181
194
|
stepOpenLabel?: string;
|
|
182
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* The count beside the title.
|
|
197
|
+
* @default `messages.checklist.count`, "{done} of {total}"
|
|
198
|
+
*/
|
|
183
199
|
formatCount?: (done: number, total: number) => string;
|
|
184
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* What a screen reader hears when the count changes.
|
|
202
|
+
* @default `messages.checklist.announcement`, "{done} of {total} steps done"
|
|
203
|
+
*/
|
|
185
204
|
formatAnnouncement?: (done: number, total: number) => string;
|
|
186
205
|
/** The steps: ChecklistStep elements, as direct children (fragments and arrays are fine). */
|
|
187
206
|
children?: React.ReactNode;
|
|
@@ -219,19 +238,30 @@ function Checklist({
|
|
|
219
238
|
mode = 'system',
|
|
220
239
|
onStepCheckedChange,
|
|
221
240
|
onDismiss,
|
|
222
|
-
dismissLabel
|
|
223
|
-
completedLabel
|
|
224
|
-
stepDoneLabel
|
|
225
|
-
stepOpenLabel
|
|
241
|
+
dismissLabel,
|
|
242
|
+
completedLabel,
|
|
243
|
+
stepDoneLabel,
|
|
244
|
+
stepOpenLabel,
|
|
226
245
|
completedOpen: completedOpenProp,
|
|
227
246
|
defaultCompletedOpen = true,
|
|
228
247
|
onCompletedOpenChange,
|
|
229
|
-
formatCount
|
|
230
|
-
formatAnnouncement
|
|
248
|
+
formatCount: formatCountProp,
|
|
249
|
+
formatAnnouncement: formatAnnouncementProp,
|
|
231
250
|
className,
|
|
232
251
|
children,
|
|
233
252
|
...props
|
|
234
253
|
}: ChecklistProps) {
|
|
254
|
+
const t = useMessages('checklist', {
|
|
255
|
+
dismiss: dismissLabel,
|
|
256
|
+
completed: completedLabel,
|
|
257
|
+
stepDone: stepDoneLabel,
|
|
258
|
+
stepOpen: stepOpenLabel,
|
|
259
|
+
});
|
|
260
|
+
const formatCount =
|
|
261
|
+
formatCountProp ?? ((done: number, total: number) => fillMessage(t.count, { done, total }));
|
|
262
|
+
const formatAnnouncement =
|
|
263
|
+
formatAnnouncementProp ??
|
|
264
|
+
((done: number, total: number) => fillMessage(t.announcement, { done, total }));
|
|
235
265
|
const reduce = useReducedMotion() ?? false;
|
|
236
266
|
const groupId = React.useId();
|
|
237
267
|
const titleId = React.useId();
|
|
@@ -303,8 +333,8 @@ function Checklist({
|
|
|
303
333
|
isDone: (id) => doneById.get(id) ?? false,
|
|
304
334
|
isKnown: (id) => knownBefore.has(id),
|
|
305
335
|
justDone: (id) => knownBefore.get(id) === false && doneById.get(id) === true,
|
|
306
|
-
doneLabel:
|
|
307
|
-
openLabel:
|
|
336
|
+
doneLabel: t.stepDone,
|
|
337
|
+
openLabel: t.stepOpen,
|
|
308
338
|
toggle: (id, checked, input) => {
|
|
309
339
|
const from = checklistSection(!checked, holdsRef.current[id]);
|
|
310
340
|
setToggled((prev) => ({ ...prev, [id]: checked }));
|
|
@@ -405,7 +435,7 @@ function Checklist({
|
|
|
405
435
|
data-slot="checklist-dismiss"
|
|
406
436
|
variant="ghost"
|
|
407
437
|
size="icon-sm"
|
|
408
|
-
aria-label={
|
|
438
|
+
aria-label={t.dismiss}
|
|
409
439
|
onClick={onDismiss}
|
|
410
440
|
className="-me-1.5"
|
|
411
441
|
>
|
|
@@ -461,7 +491,7 @@ function Checklist({
|
|
|
461
491
|
onClick={() => setCompletedOpen(!completedOpen)}
|
|
462
492
|
className="group/checklist-completed text-foreground-secondary flex min-h-11 w-full cursor-pointer items-center gap-2 ps-(--card-ps) pe-(--card-px) text-start text-sm font-medium outline-none [transition:color_var(--transition-duration-fast)_var(--ease-default),background-color_var(--transition-duration-fast)_var(--ease-default),opacity_var(--transition-duration-moderate)_var(--ease-soft)] data-arrived:starting:opacity-0 hover:bg-muted focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
|
|
463
493
|
>
|
|
464
|
-
{
|
|
494
|
+
{t.completed}
|
|
465
495
|
<CardCount className="ms-0">{finished.length}</CardCount>
|
|
466
496
|
<ChevronDown
|
|
467
497
|
aria-hidden="true"
|
|
@@ -476,7 +506,7 @@ function Checklist({
|
|
|
476
506
|
<ul
|
|
477
507
|
id={completedId}
|
|
478
508
|
data-slot="checklist-completed-steps"
|
|
479
|
-
aria-label={
|
|
509
|
+
aria-label={t.completed}
|
|
480
510
|
className="relative flex flex-col"
|
|
481
511
|
>
|
|
482
512
|
<AnimatePresence initial={false} mode="popLayout">
|
|
@@ -5,23 +5,12 @@ import { cn } from '@vendure-io/ui/lib/utils';
|
|
|
5
5
|
import type { VariantProps } from 'class-variance-authority';
|
|
6
6
|
import { XIcon } from 'lucide-react';
|
|
7
7
|
import type * as React from 'react';
|
|
8
|
-
import { isDevelopment } from '../../lib/env.ts';
|
|
9
8
|
|
|
10
|
-
interface
|
|
9
|
+
interface ChipBaseProps extends React.ComponentProps<'span'> {
|
|
11
10
|
/** Badge variants a tag can take. `link` and `ghost` are not tag treatments. */
|
|
12
11
|
variant?: Exclude<VariantProps<typeof badgeVariants>['variant'], 'link' | 'ghost'>;
|
|
13
12
|
/** Leading icon slot. */
|
|
14
13
|
icon?: React.ReactNode;
|
|
15
|
-
/**
|
|
16
|
-
* Presence of this handler renders the remove (×) button; the caller closes
|
|
17
|
-
* over its own id (`onRemove={() => remove(item.id)}`). Absent → static chip.
|
|
18
|
-
*/
|
|
19
|
-
onRemove?: () => void;
|
|
20
|
-
/**
|
|
21
|
-
* Accessible label for the remove button (e.g. `Remove ${name}`). Required
|
|
22
|
-
* whenever `onRemove` is set — the × has no text otherwise.
|
|
23
|
-
*/
|
|
24
|
-
removeLabel?: string;
|
|
25
14
|
/**
|
|
26
15
|
* Presence of this handler makes the label a button that runs it, e.g. to
|
|
27
16
|
* open an editor for the chip's value. The remove button stays a separate
|
|
@@ -39,6 +28,41 @@ interface ChipProps extends React.ComponentProps<'span'> {
|
|
|
39
28
|
disabled?: boolean;
|
|
40
29
|
}
|
|
41
30
|
|
|
31
|
+
/**
|
|
32
|
+
* The remove button's props: both or neither. Type a conditional value with
|
|
33
|
+
* it, then spread that value. A `{}` else branch written inside the JSX spread
|
|
34
|
+
* does not compile.
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const removeProps: ChipRemoveProps = canRemove
|
|
38
|
+
* ? { onRemove: remove, removeLabel: `Remove ${name}` }
|
|
39
|
+
* : {};
|
|
40
|
+
*
|
|
41
|
+
* <Chip {...removeProps}>{name}</Chip>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Inline, give the else branch `{ onRemove: undefined }`.
|
|
45
|
+
*/
|
|
46
|
+
type ChipRemoveProps =
|
|
47
|
+
| {
|
|
48
|
+
/**
|
|
49
|
+
* Presence of this handler renders the remove (×) button; the caller closes
|
|
50
|
+
* over its own id (`onRemove={() => remove(item.id)}`). Absent → static chip.
|
|
51
|
+
*/
|
|
52
|
+
onRemove: () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Accessible label for the remove button (e.g. `Remove ${name}`). Required
|
|
55
|
+
* with `onRemove`: the × has no text of its own.
|
|
56
|
+
*/
|
|
57
|
+
removeLabel: string;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
onRemove?: undefined;
|
|
61
|
+
removeLabel?: undefined;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type ChipProps = ChipBaseProps & ChipRemoveProps;
|
|
65
|
+
|
|
42
66
|
/**
|
|
43
67
|
* A compact, optionally removable tag built on the `Badge` atom. Generalizes the
|
|
44
68
|
* hand-rolled entity chips (facet-value / channel / customer-group) — the label
|
|
@@ -63,12 +87,6 @@ function Chip({
|
|
|
63
87
|
children,
|
|
64
88
|
...props
|
|
65
89
|
}: ChipProps) {
|
|
66
|
-
if (isDevelopment && onRemove && !removeLabel) {
|
|
67
|
-
console.warn(
|
|
68
|
-
'Chip: `removeLabel` is required when `onRemove` is set — the remove button has no accessible name otherwise. Pass e.g. removeLabel="Remove <name>".',
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
90
|
return (
|
|
73
91
|
<Badge
|
|
74
92
|
data-slot="chip"
|
|
@@ -127,4 +145,4 @@ function Chip({
|
|
|
127
145
|
}
|
|
128
146
|
|
|
129
147
|
export { Chip };
|
|
130
|
-
export type { ChipProps };
|
|
148
|
+
export type { ChipProps, ChipRemoveProps };
|
|
@@ -9,6 +9,7 @@ import { useFieldControlProps } from '@vendure-io/ui/components/atoms/field';
|
|
|
9
9
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
10
10
|
import { cva } from 'class-variance-authority';
|
|
11
11
|
import { CheckIcon } from 'lucide-react';
|
|
12
|
+
import { motion, useReducedMotionConfig } from 'motion/react';
|
|
12
13
|
import * as React from 'react';
|
|
13
14
|
|
|
14
15
|
import { interactiveCardVariants } from './interactive-card.tsx';
|
|
@@ -25,13 +26,29 @@ import { interactiveCardVariants } from './interactive-card.tsx';
|
|
|
25
26
|
// ring is an outline outside it, so both show together. The indicator (a radio
|
|
26
27
|
// dot or a check box) shows the state in shape too, not only in colour.
|
|
27
28
|
//
|
|
29
|
+
// In a single-choice group the selected edge is one element that moves: when
|
|
30
|
+
// the user picks another card, it glides from the old card to the new one
|
|
31
|
+
// (Motion `layoutId`, scoped to the group). See SelectedEdge for the timing.
|
|
32
|
+
//
|
|
28
33
|
// The card's accessible name is its title, and its description is the
|
|
29
34
|
// description plus the meta. Slots hold text and images only: a card is one
|
|
30
35
|
// control, so a link or button inside it is not reachable as its own control.
|
|
31
36
|
|
|
32
37
|
type ChoiceCardMode = 'single' | 'multiple';
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
type ChoiceCardInput = 'pointer' | 'keyboard' | null;
|
|
40
|
+
|
|
41
|
+
interface ChoiceCardGroupState {
|
|
42
|
+
mode: ChoiceCardMode;
|
|
43
|
+
/** Single choice: the selected value, controlled or not. */
|
|
44
|
+
selected?: unknown;
|
|
45
|
+
/** Single choice: the layoutId of the group's selected edge. */
|
|
46
|
+
edgeId?: string;
|
|
47
|
+
/** The last input in the group: arrow keys move the edge without a glide. */
|
|
48
|
+
lastInput?: React.RefObject<ChoiceCardInput>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ChoiceCardGroupContext = React.createContext<ChoiceCardGroupState>({ mode: 'single' });
|
|
35
52
|
|
|
36
53
|
type ChoiceCardGroupProps =
|
|
37
54
|
| ({ multiple?: false } & RadioGroupPrimitive.Props)
|
|
@@ -49,7 +66,7 @@ function ChoiceCardGroup(props: ChoiceCardGroupProps) {
|
|
|
49
66
|
if (fieldProps.multiple) {
|
|
50
67
|
const { multiple: _, className, ...rest } = fieldProps;
|
|
51
68
|
return (
|
|
52
|
-
<ChoiceCardGroupContext.Provider value=
|
|
69
|
+
<ChoiceCardGroupContext.Provider value={MULTIPLE}>
|
|
53
70
|
<CheckboxGroupPrimitive
|
|
54
71
|
data-slot="choice-card-group"
|
|
55
72
|
data-mode="multiple"
|
|
@@ -61,21 +78,104 @@ function ChoiceCardGroup(props: ChoiceCardGroupProps) {
|
|
|
61
78
|
</ChoiceCardGroupContext.Provider>
|
|
62
79
|
);
|
|
63
80
|
}
|
|
64
|
-
|
|
81
|
+
return <SingleChoiceCardGroup {...fieldProps} />;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const MULTIPLE: ChoiceCardGroupState = { mode: 'multiple' };
|
|
85
|
+
|
|
86
|
+
function SingleChoiceCardGroup({
|
|
87
|
+
multiple: _,
|
|
88
|
+
className,
|
|
89
|
+
value,
|
|
90
|
+
defaultValue,
|
|
91
|
+
onValueChange,
|
|
92
|
+
onKeyDown,
|
|
93
|
+
onPointerDown,
|
|
94
|
+
...rest
|
|
95
|
+
}: { multiple?: false } & RadioGroupPrimitive.Props) {
|
|
96
|
+
// The group keeps its own copy of the value so the selected card can host
|
|
97
|
+
// the moving edge, uncontrolled too.
|
|
98
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
|
|
99
|
+
const selected = value !== undefined ? value : uncontrolled;
|
|
100
|
+
const edgeId = React.useId();
|
|
101
|
+
const lastInput = React.useRef<ChoiceCardInput>(null);
|
|
102
|
+
const state = React.useMemo<ChoiceCardGroupState>(
|
|
103
|
+
() => ({ mode: 'single', selected, edgeId, lastInput }),
|
|
104
|
+
[selected, edgeId],
|
|
105
|
+
);
|
|
65
106
|
return (
|
|
66
|
-
<ChoiceCardGroupContext.Provider value=
|
|
107
|
+
<ChoiceCardGroupContext.Provider value={state}>
|
|
67
108
|
<RadioGroupPrimitive
|
|
68
109
|
data-slot="choice-card-group"
|
|
69
110
|
data-mode="single"
|
|
70
|
-
className={(
|
|
71
|
-
cn(groupClassName, typeof className === 'function' ? className(
|
|
111
|
+
className={(groupState) =>
|
|
112
|
+
cn(groupClassName, typeof className === 'function' ? className(groupState) : className)
|
|
72
113
|
}
|
|
114
|
+
value={value}
|
|
115
|
+
defaultValue={defaultValue}
|
|
116
|
+
onValueChange={(next, details) => {
|
|
117
|
+
setUncontrolled(next);
|
|
118
|
+
onValueChange?.(next, details);
|
|
119
|
+
}}
|
|
120
|
+
onKeyDown={(event) => {
|
|
121
|
+
lastInput.current = 'keyboard';
|
|
122
|
+
onKeyDown?.(event);
|
|
123
|
+
}}
|
|
124
|
+
onPointerDown={(event) => {
|
|
125
|
+
lastInput.current = 'pointer';
|
|
126
|
+
onPointerDown?.(event);
|
|
127
|
+
}}
|
|
73
128
|
{...rest}
|
|
74
129
|
/>
|
|
75
130
|
</ChoiceCardGroupContext.Provider>
|
|
76
131
|
);
|
|
77
132
|
}
|
|
78
133
|
|
|
134
|
+
// The selected edge of a single-choice group: one element per group, inside
|
|
135
|
+
// the selected card, on the card's border box. When the selection changes it
|
|
136
|
+
// unmounts in the old card and mounts in the new one under the same layoutId,
|
|
137
|
+
// so Motion glides it between them.
|
|
138
|
+
// - A pointer pick glides on a spring with no bounce (0.25s). A new pick
|
|
139
|
+
// mid-flight retargets from where the edge is.
|
|
140
|
+
// - Arrow keys repeat, so the edge jumps there and fades in `fast`.
|
|
141
|
+
// - Reduced motion: no glide, the same `fast` fade.
|
|
142
|
+
// - The first render and a remount do not animate.
|
|
143
|
+
// The 2px line is an inset box-shadow, not a border: Motion corrects a shadow
|
|
144
|
+
// and a pixel radius while the edge stretches between cards of different
|
|
145
|
+
// sizes. The radius is read from the card, so it stays the card's token.
|
|
146
|
+
const GLIDE = { type: 'spring', visualDuration: 0.25, bounce: 0 } as const;
|
|
147
|
+
const FADE = { duration: 0.1, ease: [0.25, 0.1, 0.25, 1] } as const;
|
|
148
|
+
|
|
149
|
+
function SelectedEdge({ edgeId, input }: { edgeId: string; input: ChoiceCardInput }) {
|
|
150
|
+
const ref = React.useRef<HTMLSpanElement>(null);
|
|
151
|
+
const [radius, setRadius] = React.useState<number>();
|
|
152
|
+
React.useLayoutEffect(() => {
|
|
153
|
+
const card = ref.current?.parentElement;
|
|
154
|
+
if (card) setRadius(Number.parseFloat(getComputedStyle(card).borderTopLeftRadius));
|
|
155
|
+
}, []);
|
|
156
|
+
const reduce = useReducedMotionConfig();
|
|
157
|
+
// `input` is null on the first render of the group: nothing animates then.
|
|
158
|
+
const jump = reduce || input === 'keyboard';
|
|
159
|
+
return (
|
|
160
|
+
<motion.span
|
|
161
|
+
ref={ref}
|
|
162
|
+
layoutId={edgeId}
|
|
163
|
+
aria-hidden="true"
|
|
164
|
+
data-slot="choice-card-edge"
|
|
165
|
+
className="pointer-events-none absolute -inset-px z-10 rounded-[inherit]"
|
|
166
|
+
style={{
|
|
167
|
+
// biome-ignore lint/plugin/no-raw-shadow: the moving edge draws the same inset ring as the checked card
|
|
168
|
+
boxShadow: 'inset 0 0 0 2px var(--primary)',
|
|
169
|
+
// biome-ignore lint/plugin/no-raw-radius: motion measures the radius for the layout animation
|
|
170
|
+
...(radius !== undefined ? { borderRadius: radius } : null),
|
|
171
|
+
}}
|
|
172
|
+
initial={jump && input !== null ? { opacity: 0 } : false}
|
|
173
|
+
animate={{ opacity: 1 }}
|
|
174
|
+
transition={jump ? { layout: { duration: 0 }, opacity: FADE } : { layout: GLIDE }}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
79
179
|
// The ids the card points its aria-labelledby and aria-describedby at. The
|
|
80
180
|
// title is the name from the first render, so a card without a ChoiceCardTitle
|
|
81
181
|
// needs an aria-label (the media variant). The description and the meta
|
|
@@ -105,13 +205,15 @@ function useChoiceCardPart(part: 'title' | 'description' | 'meta') {
|
|
|
105
205
|
const choiceCardVariants = cva(
|
|
106
206
|
[
|
|
107
207
|
'group/choice-card flex text-start',
|
|
108
|
-
// Selected: one 2px inset primary stroke on ::after
|
|
208
|
+
// Selected, multiple choice: one 2px inset primary stroke on ::after (a
|
|
209
|
+
// single-choice group draws a SelectedEdge instead, which moves). The ::after sits on
|
|
109
210
|
// the border box (-inset-px) with the card's radius, so it covers the
|
|
110
211
|
// border and adds the inner pixel in one curve. On the padding box
|
|
111
212
|
// (inset-0) its corners would take the outer radius and leave a gap
|
|
112
213
|
// between two strokes. So the card never clips its children: the media
|
|
113
214
|
// variant rounds the image itself to the padding box instead.
|
|
114
|
-
|
|
215
|
+
// biome-ignore lint/plugin/no-raw-shadow: the checked ring is an inset shadow on the card edge
|
|
216
|
+
'after:pointer-events-none after:absolute after:-inset-px after:z-10 after:rounded-[inherit] after:[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft)] data-[mode=multiple]:data-checked:border-primary data-[mode=multiple]:data-checked:hover:border-primary data-[mode=multiple]:data-checked:after:shadow-[inset_0_0_0_2px_var(--primary)]',
|
|
115
217
|
],
|
|
116
218
|
{
|
|
117
219
|
variants: {
|
|
@@ -208,7 +310,9 @@ function ChoiceCard({
|
|
|
208
310
|
children,
|
|
209
311
|
...props
|
|
210
312
|
}: ChoiceCardProps) {
|
|
211
|
-
const
|
|
313
|
+
const group = React.useContext(ChoiceCardGroupContext);
|
|
314
|
+
const mode = group.mode;
|
|
315
|
+
const showEdge = mode === 'single' && group.edgeId !== undefined && group.selected === value;
|
|
212
316
|
const id = React.useId();
|
|
213
317
|
const [mounted, setMounted] = React.useState<ReadonlySet<string>>(new Set());
|
|
214
318
|
const register = React.useCallback((part: string) => {
|
|
@@ -249,6 +353,7 @@ function ChoiceCard({
|
|
|
249
353
|
'data-slot': 'choice-card',
|
|
250
354
|
'data-variant': variant,
|
|
251
355
|
'data-size': size,
|
|
356
|
+
'data-mode': mode,
|
|
252
357
|
className: cn(interactiveCardVariants(), choiceCardVariants({ variant, size }), className),
|
|
253
358
|
render: <div />,
|
|
254
359
|
value,
|
|
@@ -258,6 +363,9 @@ function ChoiceCard({
|
|
|
258
363
|
const content = (
|
|
259
364
|
<ChoiceCardPartsContext.Provider value={parts}>
|
|
260
365
|
<ChoiceCardIndicator mode={mode} />
|
|
366
|
+
{showEdge && group.edgeId ? (
|
|
367
|
+
<SelectedEdge edgeId={group.edgeId} input={group.lastInput?.current ?? null} />
|
|
368
|
+
) : null}
|
|
261
369
|
{children}
|
|
262
370
|
</ChoiceCardPartsContext.Provider>
|
|
263
371
|
);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { migrateStorageKey } from '../../../lib/deprecated.ts';
|
|
2
|
+
import { PACKAGE_MANAGERS, type PackageManager } from './transform-command.tsx';
|
|
3
|
+
|
|
4
|
+
const STORAGE_KEY = 'vendure-ui:code-block:package-manager';
|
|
5
|
+
const STORAGE_EVENT = 'vendure-ui:code-block:package-manager-change';
|
|
6
|
+
// The 2.x key and event. The key moves on read; the event is sent under both
|
|
7
|
+
// names, so a 2.x listener still hears it. Remove in 4.0.
|
|
8
|
+
const OLD_STORAGE_KEY = 'vendure-ui-package-manager';
|
|
9
|
+
const OLD_STORAGE_EVENT = 'vendure-ui-package-manager-change';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the stored package manager preference from localStorage
|
|
13
|
+
*/
|
|
14
|
+
function getStoredPackageManager(): PackageManager {
|
|
15
|
+
if (typeof window === 'undefined') return 'npm';
|
|
16
|
+
migrateStorageKey('localStorage', OLD_STORAGE_KEY, STORAGE_KEY);
|
|
17
|
+
try {
|
|
18
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
19
|
+
if (stored && PACKAGE_MANAGERS.includes(stored as PackageManager)) {
|
|
20
|
+
return stored as PackageManager;
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// localStorage might not be available
|
|
24
|
+
}
|
|
25
|
+
return 'npm';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Store the package manager preference in localStorage
|
|
30
|
+
*/
|
|
31
|
+
function setStoredPackageManager(pm: PackageManager): void {
|
|
32
|
+
if (typeof window === 'undefined') return;
|
|
33
|
+
try {
|
|
34
|
+
localStorage.setItem(STORAGE_KEY, pm);
|
|
35
|
+
// Dispatch a custom event so other CodeBlock instances can update
|
|
36
|
+
window.dispatchEvent(new CustomEvent(STORAGE_EVENT, { detail: pm }));
|
|
37
|
+
window.dispatchEvent(new CustomEvent(OLD_STORAGE_EVENT, { detail: pm }));
|
|
38
|
+
} catch {
|
|
39
|
+
// localStorage might not be available
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
getStoredPackageManager,
|
|
45
|
+
OLD_STORAGE_EVENT,
|
|
46
|
+
OLD_STORAGE_KEY,
|
|
47
|
+
STORAGE_EVENT,
|
|
48
|
+
STORAGE_KEY,
|
|
49
|
+
setStoredPackageManager,
|
|
50
|
+
};
|