@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
|
@@ -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
|
-
/**
|
|
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;
|
|
@@ -48,12 +51,14 @@ interface AnonymizedTokenProps extends Omit<React.ComponentProps<'span'>, 'child
|
|
|
48
51
|
previewSuffixLength?: number;
|
|
49
52
|
/** Text placed between visible preview segments. @default "..." */
|
|
50
53
|
previewSeparator?: string;
|
|
51
|
-
/** Accessible name while the preview is blurred. @default "Partially obscured token" */
|
|
54
|
+
/** Accessible name while the preview is blurred. @default `messages.anonymizedToken.obscured`, "Partially obscured token" */
|
|
52
55
|
obscuredLabel?: string;
|
|
53
|
-
/** Accessible name while the preview is sharp. @default "Partially visible token" */
|
|
56
|
+
/** Accessible name while the preview is sharp. @default `messages.anonymizedToken.preview`, "Partially visible token" */
|
|
54
57
|
previewLabel?: string;
|
|
55
|
-
/** Rendered
|
|
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. */
|
|
@@ -62,9 +67,9 @@ interface AnonymizedTokenProps extends Omit<React.ComponentProps<'span'>, 'child
|
|
|
62
67
|
onCopied?: CopyButtonProps['onCopied'];
|
|
63
68
|
/** Called when the clipboard write fails. Falls back to `CopyFeedbackProvider`. */
|
|
64
69
|
onCopyError?: CopyButtonProps['onCopyError'];
|
|
65
|
-
/** Accessible label before copying. @default "Copy token" */
|
|
70
|
+
/** Accessible label before copying. @default `messages.anonymizedToken.copy`, "Copy token" */
|
|
66
71
|
copyLabel?: CopyButtonProps['copyLabel'];
|
|
67
|
-
/** Accessible label while the copied state is active. @default "Token copied" */
|
|
72
|
+
/** Accessible label while the copied state is active. @default `messages.anonymizedToken.copied`, "Token copied" */
|
|
68
73
|
copiedLabel?: CopyButtonProps['copiedLabel'];
|
|
69
74
|
}
|
|
70
75
|
|
|
@@ -81,15 +86,16 @@ function AnonymizedToken({
|
|
|
81
86
|
previewPrefixLength = 8,
|
|
82
87
|
previewSuffixLength = 4,
|
|
83
88
|
previewSeparator = '...',
|
|
84
|
-
obscuredLabel
|
|
85
|
-
previewLabel
|
|
86
|
-
fallback = '
|
|
89
|
+
obscuredLabel,
|
|
90
|
+
previewLabel,
|
|
91
|
+
fallback = '—',
|
|
92
|
+
loadingLabel,
|
|
87
93
|
copyable = true,
|
|
88
94
|
timeout,
|
|
89
95
|
onCopied,
|
|
90
96
|
onCopyError,
|
|
91
|
-
copyLabel
|
|
92
|
-
copiedLabel
|
|
97
|
+
copyLabel,
|
|
98
|
+
copiedLabel,
|
|
93
99
|
className,
|
|
94
100
|
onMouseEnter,
|
|
95
101
|
onMouseLeave,
|
|
@@ -99,6 +105,50 @@ 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', {
|
|
109
|
+
loading: loadingLabel,
|
|
110
|
+
obscured: obscuredLabel,
|
|
111
|
+
preview: previewLabel,
|
|
112
|
+
copy: copyLabel,
|
|
113
|
+
copied: copiedLabel,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// The skeleton is the chip's own box: 24px tall, rounded like the chip and
|
|
117
|
+
// as wide as the preview this token will show (prefix, separator and
|
|
118
|
+
// suffix in monospace `ch`) plus the padding and the copy button, so
|
|
119
|
+
// nothing moves when the token arrives. A zero-width space, centred like
|
|
120
|
+
// the chip's text, gives it the chip's baseline.
|
|
121
|
+
if (value === undefined) {
|
|
122
|
+
const previewLength = getTokenPreview(
|
|
123
|
+
'x'.repeat(clampLength(previewPrefixLength) + clampLength(previewSuffixLength) + 1),
|
|
124
|
+
previewPrefixLength,
|
|
125
|
+
previewSuffixLength,
|
|
126
|
+
previewSeparator,
|
|
127
|
+
).length;
|
|
128
|
+
return (
|
|
129
|
+
<span
|
|
130
|
+
data-slot="anonymized-token"
|
|
131
|
+
aria-busy="true"
|
|
132
|
+
className={cn(
|
|
133
|
+
'inline-flex w-fit items-center font-mono text-xs [--content-inset:calc(var(--spacing)*2)]',
|
|
134
|
+
// Pulled to the column edge like the chip, so it starts where the chip starts.
|
|
135
|
+
contentInsetPull,
|
|
136
|
+
className,
|
|
137
|
+
)}
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
<span aria-hidden="true">{'\u200b'}</span>
|
|
141
|
+
<Skeleton
|
|
142
|
+
aria-hidden="true"
|
|
143
|
+
className="h-6 rounded-lg"
|
|
144
|
+
style={{
|
|
145
|
+
width: `calc(${previewLength}ch + var(--spacing) * ${copyable ? 8.25 : 4})`,
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
<span className="sr-only">{t.loading}</span>
|
|
149
|
+
</span>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
102
152
|
|
|
103
153
|
if (!value) {
|
|
104
154
|
return (
|
|
@@ -156,13 +206,13 @@ function AnonymizedToken({
|
|
|
156
206
|
>
|
|
157
207
|
{preview}
|
|
158
208
|
</code>
|
|
159
|
-
<span className="sr-only">{showRevealed ?
|
|
209
|
+
<span className="sr-only">{showRevealed ? t.preview : t.obscured}</span>
|
|
160
210
|
{copyable ? (
|
|
161
211
|
<CopyButton
|
|
162
212
|
value={value}
|
|
163
213
|
copyAction={action}
|
|
164
|
-
copyLabel={
|
|
165
|
-
copiedLabel={
|
|
214
|
+
copyLabel={t.copy}
|
|
215
|
+
copiedLabel={t.copied}
|
|
166
216
|
{...chipCopyButtonProps}
|
|
167
217
|
/>
|
|
168
218
|
) : null}
|
|
@@ -173,12 +223,7 @@ function AnonymizedToken({
|
|
|
173
223
|
|
|
174
224
|
// The whole chip copies, like `IdChip`. The tooltip never shows the value.
|
|
175
225
|
return (
|
|
176
|
-
<ChipCopyTooltip
|
|
177
|
-
chip={chip}
|
|
178
|
-
copied={action.copied}
|
|
179
|
-
copyLabel={copyLabel}
|
|
180
|
-
copiedLabel={copiedLabel}
|
|
181
|
-
/>
|
|
226
|
+
<ChipCopyTooltip chip={chip} copied={action.copied} copyLabel={t.copy} copiedLabel={t.copied} />
|
|
182
227
|
);
|
|
183
228
|
}
|
|
184
229
|
|