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

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 (86) hide show
  1. package/package.json +12 -10
  2. package/src/components/atoms/alert-dialog.tsx +1 -4
  3. package/src/components/atoms/alert.tsx +59 -35
  4. package/src/components/atoms/badge.tsx +2 -2
  5. package/src/components/atoms/breadcrumb.tsx +124 -49
  6. package/src/components/atoms/button-group.tsx +1 -1
  7. package/src/components/atoms/button.tsx +4 -3
  8. package/src/components/atoms/calendar.tsx +2 -2
  9. package/src/components/atoms/card.tsx +15 -2
  10. package/src/components/atoms/chart.tsx +3 -3
  11. package/src/components/atoms/checkbox.tsx +1 -1
  12. package/src/components/atoms/combobox.tsx +37 -26
  13. package/src/components/atoms/command.tsx +3 -3
  14. package/src/components/atoms/context-menu.tsx +5 -5
  15. package/src/components/atoms/dialog.tsx +30 -14
  16. package/src/components/atoms/dropdown-menu.tsx +1 -1
  17. package/src/components/atoms/hover-card.tsx +1 -1
  18. package/src/components/atoms/input-group.tsx +30 -12
  19. package/src/components/atoms/input-otp.tsx +2 -2
  20. package/src/components/atoms/input.tsx +13 -3
  21. package/src/components/atoms/menubar.tsx +2 -2
  22. package/src/components/atoms/native-select.tsx +1 -1
  23. package/src/components/atoms/navigation-menu.tsx +3 -3
  24. package/src/components/atoms/pagination.tsx +9 -3
  25. package/src/components/atoms/popover.tsx +1 -1
  26. package/src/components/atoms/select.tsx +3 -3
  27. package/src/components/atoms/sheet.tsx +35 -15
  28. package/src/components/atoms/sidebar.tsx +200 -31
  29. package/src/components/atoms/skeleton.tsx +6 -3
  30. package/src/components/atoms/switch.tsx +1 -1
  31. package/src/components/atoms/tabs.tsx +6 -2
  32. package/src/components/atoms/textarea.tsx +1 -1
  33. package/src/components/atoms/toggle.tsx +1 -1
  34. package/src/components/molecules/action-needed.tsx +483 -0
  35. package/src/components/molecules/anonymized-token.tsx +52 -8
  36. package/src/components/molecules/chip.tsx +37 -18
  37. package/src/components/molecules/choice-card.tsx +114 -9
  38. package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
  39. package/src/components/molecules/code-block/process-code.ts +1 -1
  40. package/src/components/molecules/code-block.tsx +58 -47
  41. package/src/components/molecules/combobox-free-text.tsx +75 -20
  42. package/src/components/molecules/confirm-dialog.tsx +11 -1
  43. package/src/components/molecules/copyable-text.tsx +10 -8
  44. package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
  45. package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
  46. package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
  47. package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
  48. package/src/components/molecules/data-table/data-table-types.tsx +123 -13
  49. package/src/components/molecules/data-table/data-table.tsx +112 -55
  50. package/src/components/molecules/data-table/table-pagination.tsx +96 -14
  51. package/src/components/molecules/date-picker.tsx +55 -24
  52. package/src/components/molecules/date-range-picker.tsx +54 -23
  53. package/src/components/molecules/date-time-picker.tsx +60 -24
  54. package/src/components/molecules/date-time.tsx +38 -3
  55. package/src/components/molecules/elapsed-time.tsx +61 -12
  56. package/src/components/molecules/file-dropzone.tsx +139 -39
  57. package/src/components/molecules/format-provider.tsx +14 -4
  58. package/src/components/molecules/id-chip-chrome.tsx +114 -0
  59. package/src/components/molecules/id-chip.tsx +3 -107
  60. package/src/components/molecules/issued-secret.tsx +1 -1
  61. package/src/components/molecules/live-indicator.tsx +1 -1
  62. package/src/components/molecules/money.tsx +46 -4
  63. package/src/components/molecules/multi-select.tsx +58 -15
  64. package/src/components/molecules/page-header.tsx +6 -2
  65. package/src/components/molecules/password-input.tsx +11 -10
  66. package/src/components/molecules/relative-time.tsx +88 -16
  67. package/src/components/molecules/search-trigger.tsx +5 -3
  68. package/src/components/molecules/secret-value.tsx +10 -2
  69. package/src/components/molecules/stat-card.tsx +143 -33
  70. package/src/components/molecules/state-views/empty-state.tsx +16 -12
  71. package/src/components/molecules/state-views/error-state.tsx +19 -15
  72. package/src/components/molecules/state-views/loading-state.tsx +16 -6
  73. package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
  74. package/src/components/molecules/status-badge.tsx +11 -35
  75. package/src/components/molecules/time-tooltip.tsx +55 -1
  76. package/src/hooks/use-copy.ts +3 -1
  77. package/src/lib/deprecated.ts +71 -0
  78. package/src/lib/env.ts +9 -0
  79. package/src/lib/field-surface.ts +7 -7
  80. package/src/lib/format-messages.ts +192 -0
  81. package/src/lib/highlight.ts +1 -1
  82. package/src/lib/menu-item.tsx +1 -1
  83. package/src/lib/state-dictionary.ts +2 -3
  84. package/src/lib/tint-recipes.ts +10 -5
  85. package/src/lib/utils.ts +19 -1
  86. package/src/lib/dialog-padding.ts +0 -48
@@ -0,0 +1,483 @@
1
+ 'use client';
2
+
3
+ import { buttonVariants } from '@vendure-io/ui/components/atoms/button';
4
+ import { StatusBadge } from '@vendure-io/ui/components/molecules/status-badge';
5
+ import { toneIcons } from '@vendure-io/ui/lib/tone-icons';
6
+ import { cn } from '@vendure-io/ui/lib/utils';
7
+ import { ChevronDown } from 'lucide-react';
8
+ import {
9
+ type ComponentProps,
10
+ type CSSProperties,
11
+ type ReactNode,
12
+ useId,
13
+ useLayoutEffect,
14
+ useRef,
15
+ useState,
16
+ } from 'react';
17
+
18
+ /** The tones a finding can have, worst first. */
19
+ export const ACTION_NEEDED_TONES = ['critical', 'warning', 'info'] as const;
20
+ export type ActionNeededTone = (typeof ACTION_NEEDED_TONES)[number];
21
+
22
+ /** One finding. `key` names the occurrence: a key the fold memory has not seen opens the list. */
23
+ export interface ActionNeededItem {
24
+ key: string;
25
+ tone: ActionNeededTone;
26
+ /** A short label: "Default superadmin password". */
27
+ title: ReactNode;
28
+ /** One sentence on what is wrong and what it costs. */
29
+ description?: ReactNode;
30
+ /** One action that fixes it, usually a small outline Button that opens the page. */
31
+ action?: ReactNode;
32
+ /** Replaces the tone icon. */
33
+ icon?: ReactNode;
34
+ }
35
+
36
+ /** The number of findings of each tone, worst first, without the tones that have none. */
37
+ export function actionNeededCounts(items: readonly Pick<ActionNeededItem, 'tone'>[]) {
38
+ return ACTION_NEEDED_TONES.map((tone) => ({
39
+ tone,
40
+ count: items.filter((item) => item.tone === tone).length,
41
+ })).filter(({ count }) => count > 0);
42
+ }
43
+
44
+ /*
45
+ * Fold memory. Every fold and every opening stores the choice with the keys of the findings that
46
+ * were shown, under a memory key. On load, a finding whose key is not stored opens the list again.
47
+ * Without new findings, the stored choice applies. Without a stored choice (the first visit), the
48
+ * list starts as `defaultOpen` says.
49
+ */
50
+
51
+ /** The part of `Storage` the fold memory uses, so a host can pass its own store. */
52
+ export type FoldMemoryStorage = Pick<Storage, 'getItem' | 'setItem'>;
53
+ export type FoldMemory = { open: boolean; keys: readonly string[] };
54
+
55
+ const foldStorageKey = (memoryKey: string) => `vendure-ui:action-needed:fold:${memoryKey}`;
56
+
57
+ /** The stored choice, or null when nothing is stored or the stored value has another shape. */
58
+ export function readFoldMemory(storage: FoldMemoryStorage, memoryKey: string): FoldMemory | null {
59
+ try {
60
+ const value: unknown = JSON.parse(storage.getItem(foldStorageKey(memoryKey)) ?? 'null');
61
+ if (typeof value !== 'object' || value === null) return null;
62
+ const { open, keys } = value as Record<string, unknown>;
63
+ if (typeof open !== 'boolean' || !Array.isArray(keys)) return null;
64
+ return { open, keys: keys.filter((key): key is string => typeof key === 'string') };
65
+ } catch {
66
+ // A value that is not JSON, or a storage that throws, counts as nothing stored.
67
+ return null;
68
+ }
69
+ }
70
+
71
+ export function storeFoldMemory(storage: FoldMemoryStorage, memoryKey: string, memory: FoldMemory) {
72
+ try {
73
+ storage.setItem(foldStorageKey(memoryKey), JSON.stringify(memory));
74
+ } catch {
75
+ // A full or blocked storage only loses the memory.
76
+ }
77
+ }
78
+
79
+ /** Whether the list opens: when the memory says open, or for a key the memory has not seen. */
80
+ export function opensOnLoad(memory: FoldMemory, keys: readonly string[]): boolean {
81
+ return memory.open || keys.some((key) => !memory.keys.includes(key));
82
+ }
83
+
84
+ function browserStorage(): FoldMemoryStorage | null {
85
+ try {
86
+ return globalThis.localStorage ?? null;
87
+ } catch {
88
+ // Reading localStorage throws where storage is blocked.
89
+ return null;
90
+ }
91
+ }
92
+
93
+ interface FoldOptions {
94
+ keys: readonly string[];
95
+ memoryKey: string | undefined;
96
+ storage: FoldMemoryStorage | null | undefined;
97
+ open: boolean | undefined;
98
+ defaultOpen: boolean;
99
+ onOpenChange: ((open: boolean) => void) | undefined;
100
+ }
101
+
102
+ /**
103
+ * The open state of the list. The stored choice is read in a layout effect on mount, so a server
104
+ * render and the first client render agree, and the list never paints in the wrong state. After
105
+ * that, a change of the findings or of the memory key only ever opens the list: when the memory
106
+ * has not seen a finding. In controlled mode the hook only calls `onOpenChange`.
107
+ */
108
+ function useFold({ keys, memoryKey, storage, open, defaultOpen, onOpenChange }: FoldOptions) {
109
+ const [uncontrolled, setUncontrolled] = useState(defaultOpen);
110
+ const controlled = open !== undefined;
111
+ const current = controlled ? open : uncontrolled;
112
+ // The memory of this visit, per memory key: it stands in when there is no storage or no key,
113
+ // so a new finding still opens the list.
114
+ const session = useRef(new Map<string, FoldMemory>());
115
+ const latest = useRef({ current, controlled, onOpenChange, defaultOpen, storage });
116
+ latest.current = { current, controlled, onOpenChange, defaultOpen, storage };
117
+ const keyString = keys.join('\n');
118
+ const mounted = useRef(false);
119
+
120
+ useLayoutEffect(() => {
121
+ const { current, controlled, onOpenChange, defaultOpen, storage } = latest.current;
122
+ const ids = keyString ? keyString.split('\n') : [];
123
+ const store = storage === undefined ? browserStorage() : storage;
124
+ const slot = memoryKey ?? '';
125
+ const memory =
126
+ (store && memoryKey !== undefined ? readFoldMemory(store, memoryKey) : null) ??
127
+ session.current.get(slot) ??
128
+ null;
129
+ if (memory === null) session.current.set(slot, { open: defaultOpen, keys: ids });
130
+ const next = memory === null ? defaultOpen : opensOnLoad(memory, ids);
131
+ const first = !mounted.current;
132
+ mounted.current = true;
133
+ // On mount the stored choice applies both ways; later, a new finding can only open the list.
134
+ if (next === current || (!first && !next)) return;
135
+ if (controlled) onOpenChange?.(next);
136
+ else setUncontrolled(next);
137
+ }, [memoryKey, keyString]);
138
+
139
+ const toggle = () => {
140
+ const next = !current;
141
+ const memory = { open: next, keys };
142
+ session.current.set(memoryKey ?? '', memory);
143
+ const store = storage === undefined ? browserStorage() : storage;
144
+ if (store && memoryKey !== undefined) storeFoldMemory(store, memoryKey, memory);
145
+ if (!controlled) setUncontrolled(next);
146
+ onOpenChange?.(next);
147
+ };
148
+
149
+ return { open: current, toggle };
150
+ }
151
+
152
+ /**
153
+ * Whether a new row enters with motion. The rows that are there when the host reveals the list
154
+ * take their place at once, so they push nothing down. A row that arrives after that enters. A
155
+ * list that mounts revealed lets every row enter.
156
+ */
157
+ function useEntersOnScreen(revealed: boolean, keyString: string) {
158
+ const [enters, setEnters] = useState(revealed);
159
+ const [revealedKey, setRevealedKey] = useState<string | null>(null);
160
+ if (!enters && revealed) {
161
+ if (revealedKey === null) setRevealedKey(keyString);
162
+ else if (revealedKey !== keyString) setEnters(true);
163
+ }
164
+ return enters;
165
+ }
166
+
167
+ // The colour of the tone icon on a row. Warning takes the brighter indicator amber, as the
168
+ // StatusBadge and the Alert do: the amber text colour reads brown at icon size.
169
+ const toneIconClass: Record<ActionNeededTone, string> = {
170
+ critical: 'text-destructive-text',
171
+ warning: 'text-warning-indicator',
172
+ info: 'text-info-text',
173
+ };
174
+
175
+ const DEFAULT_COUNT_WORDS: Record<ActionNeededTone, readonly [one: string, other: string]> = {
176
+ critical: ['error', 'errors'],
177
+ warning: ['warning', 'warnings'],
178
+ info: ['info', 'info'],
179
+ };
180
+
181
+ /** The default badge text: the count and the tone word, singular for one ("1 error", "2 warnings"). */
182
+ function defaultCountLabel(count: number, tone: ActionNeededTone): string {
183
+ const [one, other] = DEFAULT_COUNT_WORDS[tone];
184
+ return `${count} ${count === 1 ? one : other}`;
185
+ }
186
+
187
+ /*
188
+ * Motion. Folded: one count badge per tone. Opening: the badges fade out, then each row opens
189
+ * from its own slot (grid rows 0fr to 1fr) and fades down 4px into place, 50ms apart, worst
190
+ * first. Folding plays it in reverse, a bit faster. Only CSS transitions, so a second click
191
+ * starts from where the motion is. --i is the index from the top, --r the index from the bottom.
192
+ * Reduced motion: the badges and the rows only fade. The height and the chevron snap.
193
+ */
194
+ const badgeClass = cn(
195
+ 'inline-flex',
196
+ 'motion-safe:[transition-property:opacity,scale,filter] motion-safe:duration-fold-badge-in motion-safe:ease-fold motion-safe:delay-[calc(var(--transition-duration-fold-hand-off)+var(--i)*var(--transition-duration-fold-step))]',
197
+ 'data-open:opacity-0 motion-safe:data-open:scale-95 motion-safe:data-open:blur-[2px] motion-safe:data-open:duration-moderate motion-safe:data-open:delay-[calc(var(--i)*var(--transition-duration-fold-step))]',
198
+ 'motion-reduce:transition-opacity motion-reduce:duration-moderate motion-reduce:ease-linear',
199
+ );
200
+
201
+ const slotClass = cn(
202
+ 'grid grid-rows-[0fr] data-open:grid-rows-[1fr]',
203
+ 'motion-safe:[transition:grid-template-rows_var(--transition-duration-fold-close)_var(--ease-fold)_calc(var(--r)*var(--transition-duration-fold-step))]',
204
+ 'motion-safe:data-open:[transition:grid-template-rows_var(--transition-duration-fold-open)_var(--ease-height)_calc(var(--transition-duration-fold-hand-off)+var(--i)*var(--transition-duration-fold-stagger))]',
205
+ // A row that arrives while the list is open and on screen opens from its own slot.
206
+ 'motion-safe:data-enter:data-open:starting:grid-rows-[0fr]',
207
+ );
208
+
209
+ const rowMotionClass = cn(
210
+ 'opacity-0 data-open:opacity-100 motion-safe:-translate-y-1 motion-safe:data-open:translate-y-0',
211
+ 'motion-safe:[transition:opacity_var(--transition-duration-fold-row-out)_var(--ease-fold)_calc(var(--r)*var(--transition-duration-fold-step)),translate_var(--transition-duration-fold-row-out)_var(--ease-fold)_calc(var(--r)*var(--transition-duration-fold-step))]',
212
+ 'motion-safe:data-open:[transition:opacity_var(--transition-duration-fold-row-in)_var(--ease-height)_calc(var(--transition-duration-fold-hand-off)+var(--transition-duration-fold-step)+var(--i)*var(--transition-duration-fold-stagger)),translate_var(--transition-duration-fold-row-in)_var(--ease-height)_calc(var(--transition-duration-fold-hand-off)+var(--transition-duration-fold-step)+var(--i)*var(--transition-duration-fold-stagger))]',
213
+ 'motion-reduce:transition-opacity motion-reduce:duration-moderate motion-reduce:ease-linear',
214
+ 'data-enter:data-open:starting:opacity-0 motion-safe:data-enter:data-open:starting:-translate-y-1',
215
+ );
216
+
217
+ // The chevron turns when the list opens. On hover of the fold row it darkens and moves 1px its way.
218
+ const chevronClass = cn(
219
+ 'size-5! text-foreground-secondary',
220
+ 'motion-safe:[transition-property:rotate,translate,color] motion-safe:duration-normal motion-safe:ease-out motion-reduce:transition-none',
221
+ 'group-hover/action-needed-trigger:text-foreground motion-safe:group-hover/action-needed-trigger:translate-y-px',
222
+ 'group-aria-expanded/action-needed-trigger:rotate-180 motion-safe:group-aria-expanded/action-needed-trigger:group-hover/action-needed-trigger:-translate-y-px',
223
+ );
224
+
225
+ type ActionNeededRowProps = Omit<ComponentProps<'div'>, 'title'> &
226
+ Pick<ActionNeededItem, 'tone' | 'title' | 'description' | 'action' | 'icon'>;
227
+
228
+ /**
229
+ * One finding as a plain row: the tone icon, the title and its sentence, and the action at the
230
+ * end. The tone is on the icon only. From a 28rem-wide row down, the action moves under the text.
231
+ */
232
+ function ActionNeededRow({
233
+ tone,
234
+ title,
235
+ description,
236
+ action,
237
+ icon,
238
+ className,
239
+ ...props
240
+ }: ActionNeededRowProps) {
241
+ const ToneIcon = toneIcons[tone];
242
+ return (
243
+ <div
244
+ data-slot="action-needed-row"
245
+ data-tone={tone}
246
+ className={cn(
247
+ '@container/action-needed-row grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 py-3 text-sm',
248
+ className,
249
+ )}
250
+ {...props}
251
+ >
252
+ <span
253
+ data-slot="action-needed-icon"
254
+ className={cn(
255
+ 'row-span-2 flex h-lh items-center self-start [&_svg:not([class*=size-])]:size-4 [&_svg:not([class*=stroke-])]:stroke-[1.75]',
256
+ toneIconClass[tone],
257
+ )}
258
+ >
259
+ {icon ?? <ToneIcon aria-hidden />}
260
+ </span>
261
+ <div data-slot="action-needed-text" className="col-start-2 row-span-2 min-w-0">
262
+ <div data-slot="action-needed-title" className="font-medium text-foreground">
263
+ {title}
264
+ </div>
265
+ {description ? (
266
+ <div data-slot="action-needed-description" className="text-pretty text-muted-foreground">
267
+ {description}
268
+ </div>
269
+ ) : null}
270
+ </div>
271
+ {action ? (
272
+ <div
273
+ data-slot="action-needed-action"
274
+ className="col-start-3 row-span-2 row-start-1 flex items-center gap-2 ps-3 @max-md/action-needed-row:col-start-2 @max-md/action-needed-row:row-span-1 @max-md/action-needed-row:row-start-3 @max-md/action-needed-row:mt-2 @max-md/action-needed-row:ps-0"
275
+ >
276
+ {action}
277
+ </div>
278
+ ) : null}
279
+ </div>
280
+ );
281
+ }
282
+
283
+ type ActionNeededProps<T extends ActionNeededItem> = Omit<
284
+ ComponentProps<'div'>,
285
+ 'children' | 'defaultValue' | 'title'
286
+ > & {
287
+ /** The header text, such as "Store setup" or "Action needed". The strongest text of the list. */
288
+ title: ReactNode;
289
+ /** An optional line under the title. */
290
+ description?: ReactNode;
291
+ /** The findings, worst first. They show in the order given. */
292
+ items: readonly T[];
293
+ /** Renders one finding. Default: an `ActionNeededRow` of the item's parts. */
294
+ renderItem?: (item: T) => ReactNode;
295
+ /**
296
+ * The text of one count badge, such as "2 warnings". Pass it to translate the badges with the
297
+ * plural rules of the language. Default: English, "1 error", "2 warnings", "1 info".
298
+ */
299
+ countLabel?: (count: number, tone: ActionNeededTone) => ReactNode;
300
+ /** Names the fold memory, such as a channel or project id. Without it, the choice lasts for this visit. */
301
+ memoryKey?: string;
302
+ /** Where the fold memory lives. Default `localStorage`. `null` keeps it for this visit only. */
303
+ storage?: FoldMemoryStorage | null;
304
+ /** Controlled open state. */
305
+ open?: boolean;
306
+ /** Open state on the first visit, before anything is stored. Default `true`. */
307
+ defaultOpen?: boolean;
308
+ /** Called with the new state when the user folds or opens the list, or a new finding opens it. */
309
+ onOpenChange?: (open: boolean) => void;
310
+ /**
311
+ * False while the host keeps the list hidden until its layout is known. The rows there when it
312
+ * turns true take their place at once; rows that arrive later enter with motion. Default `true`.
313
+ */
314
+ revealed?: boolean;
315
+ };
316
+
317
+ /**
318
+ * A foldable list of findings that need someone. The header is the fold row: the title, one
319
+ * count badge per tone, the chevron at the end and an optional description under the title. The
320
+ * whole header opens and folds the list. The badges show only while the list is folded. The rows
321
+ * are plain, with a divider between them, and stay in the page while folded, inert, so the motion
322
+ * runs both ways. A finding with a key the memory has not seen opens the list again. Renders
323
+ * nothing without findings.
324
+ *
325
+ * In a Card, render it as the Card's only child: it takes the card's padding, so the whole card
326
+ * header is the fold row. Outside a Card it has no padding of its own.
327
+ */
328
+ function ActionNeeded<T extends ActionNeededItem>({
329
+ title,
330
+ description,
331
+ items,
332
+ renderItem,
333
+ countLabel = defaultCountLabel,
334
+ memoryKey,
335
+ storage,
336
+ open: openProp,
337
+ defaultOpen = true,
338
+ onOpenChange,
339
+ revealed = true,
340
+ className,
341
+ ...props
342
+ }: ActionNeededProps<T>) {
343
+ const keys = items.map((item) => item.key);
344
+ const { open, toggle } = useFold({
345
+ keys,
346
+ memoryKey,
347
+ storage,
348
+ open: openProp,
349
+ defaultOpen,
350
+ onOpenChange,
351
+ });
352
+ const enters = useEntersOnScreen(revealed, keys.join('\n'));
353
+ const listId = useId();
354
+ const state = { 'data-open': open || undefined, 'data-enter': enters || undefined };
355
+
356
+ if (items.length === 0) return null;
357
+
358
+ return (
359
+ <div
360
+ data-slot="action-needed"
361
+ {...state}
362
+ // In a Card it takes over the card's vertical padding, so the whole header is the fold row.
363
+ className={cn('-my-(--card-gap) flex flex-col', className)}
364
+ {...props}
365
+ >
366
+ <button
367
+ aria-controls={listId}
368
+ aria-expanded={open}
369
+ data-slot="action-needed-trigger"
370
+ className="group/action-needed-trigger flex w-full cursor-pointer items-start gap-3 rounded-[inherit] py-[var(--card-gap,0.5rem)] ps-(--card-ps) pe-(--card-px) text-start text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
371
+ type="button"
372
+ onClick={toggle}
373
+ >
374
+ <span className="flex min-w-0 flex-1 flex-col gap-1">
375
+ <span className="flex flex-wrap items-center gap-x-2.5 gap-y-1">
376
+ <span
377
+ data-slot="action-needed-heading"
378
+ className="font-heading text-sm font-semibold tracking-[-0.005em] text-foreground"
379
+ >
380
+ {title}
381
+ </span>
382
+ <span
383
+ aria-hidden={open || undefined}
384
+ data-slot="action-needed-counts"
385
+ // The badges overlap the line's padding, so the title line keeps the text's
386
+ // height and the space above the title equals the space under the last row.
387
+ className="-my-1 flex min-w-0 flex-wrap items-center gap-1.5"
388
+ >
389
+ {actionNeededCounts(items).map(({ tone, count }, index) => (
390
+ <span
391
+ key={tone}
392
+ data-slot="action-needed-count"
393
+ {...state}
394
+ className={badgeClass}
395
+ style={{ '--i': index } as CSSProperties}
396
+ >
397
+ <StatusBadge className="tabular-nums" size="lg" tone={tone}>
398
+ {countLabel(count, tone)}
399
+ </StatusBadge>
400
+ </span>
401
+ ))}
402
+ </span>
403
+ </span>
404
+ {description ? (
405
+ <span
406
+ data-slot="action-needed-description"
407
+ className="text-sm text-foreground-secondary"
408
+ >
409
+ {description}
410
+ </span>
411
+ ) : null}
412
+ </span>
413
+ {/* The header is the toggle. The chevron only looks like a button: a hover anywhere on
414
+ the header gives it the ghost hover fill, so the header reads as clickable. */}
415
+ <span
416
+ aria-hidden
417
+ className={cn(
418
+ buttonVariants({ size: 'icon-sm', variant: 'ghost' }),
419
+ '-my-1.5 ms-auto shrink-0 group-hover/action-needed-trigger:bg-muted group-hover/action-needed-trigger:text-foreground',
420
+ )}
421
+ >
422
+ {/* A wrapper, so the Button's own icon transition (on its direct svg child) does not
423
+ replace the chevron's. */}
424
+ <span className="flex">
425
+ <ChevronDown
426
+ data-slot="action-needed-chevron"
427
+ className={chevronClass}
428
+ strokeWidth={2.25}
429
+ />
430
+ </span>
431
+ </span>
432
+ </button>
433
+ <div
434
+ id={listId}
435
+ role="list"
436
+ data-slot="action-needed-list"
437
+ className="ps-(--card-ps) pe-(--card-px)"
438
+ >
439
+ {items.map((item, index) => (
440
+ <div
441
+ key={item.key}
442
+ role="listitem"
443
+ data-slot="action-needed-slot"
444
+ {...state}
445
+ className={slotClass}
446
+ style={{ '--i': index, '--r': items.length - 1 - index } as CSSProperties}
447
+ >
448
+ <div className="min-h-0 overflow-hidden" inert={!open}>
449
+ {/* The divider moves with its row, so a folding row takes its line with it. In a
450
+ Card, the card's bottom padding folds away with the last row. */}
451
+ <div
452
+ data-slot="action-needed-item"
453
+ {...state}
454
+ className={cn(
455
+ rowMotionClass,
456
+ 'border-t border-border',
457
+ // The last row ends on the card's padding alone: its own bottom padding
458
+ // goes, so the space under it equals the space above the title.
459
+ index === items.length - 1 &&
460
+ 'mb-(--card-gap) *:data-[slot=action-needed-row]:pb-0',
461
+ )}
462
+ >
463
+ {renderItem ? (
464
+ renderItem(item)
465
+ ) : (
466
+ <ActionNeededRow
467
+ action={item.action}
468
+ description={item.description}
469
+ icon={item.icon}
470
+ title={item.title}
471
+ tone={item.tone}
472
+ />
473
+ )}
474
+ </div>
475
+ </div>
476
+ </div>
477
+ ))}
478
+ </div>
479
+ </div>
480
+ );
481
+ }
482
+
483
+ export { ActionNeeded, ActionNeededRow, type ActionNeededProps, type ActionNeededRowProps };
@@ -1,18 +1,17 @@
1
1
  'use client';
2
2
 
3
+ import { Skeleton } from '@vendure-io/ui/components/atoms/skeleton';
3
4
  import {
4
5
  CopyButton,
5
6
  type CopyButtonProps,
6
7
  useCopyAction,
7
8
  } from '@vendure-io/ui/components/molecules/copyable-text';
8
- import {
9
- ChipCopyTooltip,
10
- chipChromeClass,
11
- chipCopyButtonProps,
12
- } from '@vendure-io/ui/components/molecules/id-chip';
13
9
  import { cn } from '@vendure-io/ui/lib/utils';
14
10
  import type * as React from 'react';
15
11
  import { useState } from 'react';
12
+ import { contentInsetPull } from '../../lib/content-inset.ts';
13
+ import { useMessages } from '../../lib/format-messages.ts';
14
+ import { ChipCopyTooltip, chipChromeClass, chipCopyButtonProps } from './id-chip-chrome.tsx';
16
15
 
17
16
  function clampLength(value: number): number {
18
17
  return Number.isFinite(value) ? Math.max(0, Math.trunc(value)) : 0;
@@ -38,7 +37,11 @@ function getTokenPreview(
38
37
  }
39
38
 
40
39
  interface AnonymizedTokenProps extends Omit<React.ComponentProps<'span'>, 'children'> {
41
- /** Full token copied by the button. Never rendered in full by the component. */
40
+ /**
41
+ * Full token copied by the button. Never rendered in full by the component.
42
+ * `undefined` means not loaded yet and renders a skeleton the size of the
43
+ * chip; `null` and `''` mean there is no token and render `fallback`.
44
+ */
42
45
  value: string | null | undefined;
43
46
  /** Remove the blur from the preview on hover/focus. @default true */
44
47
  revealOnHover?: boolean;
@@ -52,8 +55,10 @@ interface AnonymizedTokenProps extends Omit<React.ComponentProps<'span'>, 'child
52
55
  obscuredLabel?: string;
53
56
  /** Accessible name while the preview is sharp. @default "Partially visible token" */
54
57
  previewLabel?: string;
55
- /** Rendered for nullish or empty values. @default "-" */
58
+ /** Rendered when `value` is `null` or `''`. @default "—" */
56
59
  fallback?: React.ReactNode;
60
+ /** Screen-reader text while `value` is `undefined`. @default `messages.anonymizedToken.loading`, "Loading token" */
61
+ loadingLabel?: string;
57
62
  /** Render the copy affordance. @default true */
58
63
  copyable?: boolean;
59
64
  /** How long the check-mark feedback stays visible, in ms. */
@@ -83,7 +88,8 @@ function AnonymizedToken({
83
88
  previewSeparator = '...',
84
89
  obscuredLabel = 'Partially obscured token',
85
90
  previewLabel = 'Partially visible token',
86
- fallback = '-',
91
+ fallback = '—',
92
+ loadingLabel,
87
93
  copyable = true,
88
94
  timeout,
89
95
  onCopied,
@@ -99,6 +105,44 @@ function AnonymizedToken({
99
105
  }: AnonymizedTokenProps) {
100
106
  const [previewRevealed, setPreviewRevealed] = useState(false);
101
107
  const action = useCopyAction({ timeout, onCopied, onCopyError });
108
+ const t = useMessages('anonymizedToken', { loading: loadingLabel });
109
+
110
+ // The skeleton is the chip's own box: 24px tall, rounded like the chip and
111
+ // as wide as the preview this token will show (prefix, separator and
112
+ // suffix in monospace `ch`) plus the padding and the copy button, so
113
+ // nothing moves when the token arrives. A zero-width space, centred like
114
+ // the chip's text, gives it the chip's baseline.
115
+ if (value === undefined) {
116
+ const previewLength = getTokenPreview(
117
+ 'x'.repeat(clampLength(previewPrefixLength) + clampLength(previewSuffixLength) + 1),
118
+ previewPrefixLength,
119
+ previewSuffixLength,
120
+ previewSeparator,
121
+ ).length;
122
+ return (
123
+ <span
124
+ data-slot="anonymized-token"
125
+ aria-busy="true"
126
+ className={cn(
127
+ 'inline-flex w-fit items-center font-mono text-xs [--content-inset:calc(var(--spacing)*2)]',
128
+ // Pulled to the column edge like the chip, so it starts where the chip starts.
129
+ contentInsetPull,
130
+ className,
131
+ )}
132
+ {...props}
133
+ >
134
+ <span aria-hidden="true">{'\u200b'}</span>
135
+ <Skeleton
136
+ aria-hidden="true"
137
+ className="h-6 rounded-lg"
138
+ style={{
139
+ width: `calc(${previewLength}ch + var(--spacing) * ${copyable ? 8.25 : 4})`,
140
+ }}
141
+ />
142
+ <span className="sr-only">{t.loading}</span>
143
+ </span>
144
+ );
145
+ }
102
146
 
103
147
  if (!value) {
104
148
  return (
@@ -6,21 +6,11 @@ import type { VariantProps } from 'class-variance-authority';
6
6
  import { XIcon } from 'lucide-react';
7
7
  import type * as React from 'react';
8
8
 
9
- interface ChipProps extends React.ComponentProps<'span'> {
9
+ interface ChipBaseProps extends React.ComponentProps<'span'> {
10
10
  /** Badge variants a tag can take. `link` and `ghost` are not tag treatments. */
11
11
  variant?: Exclude<VariantProps<typeof badgeVariants>['variant'], 'link' | 'ghost'>;
12
12
  /** Leading icon slot. */
13
13
  icon?: React.ReactNode;
14
- /**
15
- * Presence of this handler renders the remove (×) button; the caller closes
16
- * over its own id (`onRemove={() => remove(item.id)}`). Absent → static chip.
17
- */
18
- onRemove?: () => void;
19
- /**
20
- * Accessible label for the remove button (e.g. `Remove ${name}`). Required
21
- * whenever `onRemove` is set — the × has no text otherwise.
22
- */
23
- removeLabel?: string;
24
14
  /**
25
15
  * Presence of this handler makes the label a button that runs it, e.g. to
26
16
  * open an editor for the chip's value. The remove button stays a separate
@@ -38,6 +28,41 @@ interface ChipProps extends React.ComponentProps<'span'> {
38
28
  disabled?: boolean;
39
29
  }
40
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
+
41
66
  /**
42
67
  * A compact, optionally removable tag built on the `Badge` atom. Generalizes the
43
68
  * hand-rolled entity chips (facet-value / channel / customer-group) — the label
@@ -62,12 +87,6 @@ function Chip({
62
87
  children,
63
88
  ...props
64
89
  }: ChipProps) {
65
- if (process.env.NODE_ENV !== 'production' && onRemove && !removeLabel) {
66
- console.warn(
67
- 'Chip: `removeLabel` is required when `onRemove` is set — the remove button has no accessible name otherwise. Pass e.g. removeLabel="Remove <name>".',
68
- );
69
- }
70
-
71
90
  return (
72
91
  <Badge
73
92
  data-slot="chip"
@@ -126,4 +145,4 @@ function Chip({
126
145
  }
127
146
 
128
147
  export { Chip };
129
- export type { ChipProps };
148
+ export type { ChipProps, ChipRemoveProps };