@vendure-io/ui 3.0.0-next.4 → 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.
- 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 +124 -49
- 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/chart.tsx +3 -3
- package/src/components/atoms/checkbox.tsx +1 -1
- package/src/components/atoms/combobox.tsx +37 -26
- package/src/components/atoms/command.tsx +3 -3
- 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 +9 -3
- 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 +200 -31
- package/src/components/atoms/skeleton.tsx +6 -3
- 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 +52 -8
- package/src/components/molecules/chip.tsx +37 -19
- package/src/components/molecules/choice-card.tsx +114 -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 +11 -1
- package/src/components/molecules/copyable-text.tsx +10 -8
- package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
- 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 +123 -13
- package/src/components/molecules/data-table/data-table.tsx +109 -49
- package/src/components/molecules/data-table/table-pagination.tsx +96 -14
- package/src/components/molecules/date-picker.tsx +55 -24
- package/src/components/molecules/date-range-picker.tsx +54 -23
- package/src/components/molecules/date-time-picker.tsx +60 -24
- 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 +139 -39
- 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 +3 -107
- package/src/components/molecules/issued-secret.tsx +1 -1
- package/src/components/molecules/live-indicator.tsx +1 -1
- package/src/components/molecules/money.tsx +44 -3
- package/src/components/molecules/multi-select.tsx +56 -14
- 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 +10 -2
- package/src/components/molecules/stat-card.tsx +143 -33
- package/src/components/molecules/state-views/empty-state.tsx +16 -12
- package/src/components/molecules/state-views/error-state.tsx +19 -15
- package/src/components/molecules/state-views/loading-state.tsx +16 -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 +192 -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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { Button } from '@vendure-io/ui/components/atoms/button';
|
|
4
|
+
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
4
5
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
5
6
|
import { FileIcon, UploadCloudIcon, XIcon } from 'lucide-react';
|
|
6
7
|
import * as React from 'react';
|
|
8
|
+
import { defaultMessages, useMessages } from '../../lib/format-messages.ts';
|
|
7
9
|
|
|
8
10
|
type FileValidationResult = string | readonly string[] | null | undefined;
|
|
9
11
|
type FileValidator = (file: File) => FileValidationResult | Promise<FileValidationResult>;
|
|
@@ -13,8 +15,40 @@ interface FileRejection {
|
|
|
13
15
|
messages: string[];
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The texts of a FileDropzone. Each one is optional and wins over
|
|
20
|
+
* `FormatProvider`'s `messages.fileDropzone`, which wins over English.
|
|
21
|
+
* Texts with a value in them are functions here (and `{name}`, `{size}`,
|
|
22
|
+
* `{max}` placeholders in `messages`).
|
|
23
|
+
*/
|
|
24
|
+
interface FileDropzoneLabels {
|
|
25
|
+
/** @default `messages.fileDropzone.typeNotAccepted`, "This file type is not accepted." */
|
|
26
|
+
typeNotAccepted?: string;
|
|
27
|
+
/** Receives the largest allowed size, already formatted. @default `messages.fileDropzone.fileTooLarge`, "File size must be {size} or smaller." */
|
|
28
|
+
fileTooLarge?: (size: string) => string;
|
|
29
|
+
/** Receives the file limit. @default `messages.fileDropzone.tooManyFiles` ("You can select up to {max} files.") and `tooManyFilesOne` for a limit of one */
|
|
30
|
+
tooManyFiles?: (max: number) => string;
|
|
31
|
+
/** Shown when `validateFile` throws. @default `messages.fileDropzone.validationFailed`, "This file could not be validated." */
|
|
32
|
+
validationFailed?: string;
|
|
33
|
+
/** Replaces the drop prompt while `validateFile` runs. @default `messages.fileDropzone.checking`, "Checking files…" */
|
|
34
|
+
checking?: string;
|
|
35
|
+
/** Placed before the `accept` list. @default `messages.fileDropzone.accepted`, "Accepted:" */
|
|
36
|
+
accepted?: string;
|
|
37
|
+
/** Accessible name of a file's remove button. Receives the file name. @default `messages.fileDropzone.remove`, "Remove {name}" */
|
|
38
|
+
remove?: (name: string) => string;
|
|
39
|
+
/** @default `messages.fileDropzone.byte`, "B" */
|
|
40
|
+
byte?: string;
|
|
41
|
+
/** @default `messages.fileDropzone.kilobyte`, "KB" */
|
|
42
|
+
kilobyte?: string;
|
|
43
|
+
/** @default `messages.fileDropzone.megabyte`, "MB" */
|
|
44
|
+
megabyte?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface FileDropzoneProps extends Omit<React.ComponentProps<'div'>, 'defaultValue' | 'onChange'> {
|
|
48
|
+
/** Selected files. Pass `value` to control the dropzone. Leave the prop out and it keeps its own state. */
|
|
17
49
|
value?: readonly File[];
|
|
50
|
+
/** Initial files when `value` is not passed. */
|
|
51
|
+
defaultValue?: readonly File[];
|
|
18
52
|
onValueChange?: (files: File[]) => void;
|
|
19
53
|
onRejected?: (rejections: FileRejection[]) => void;
|
|
20
54
|
accept?: string;
|
|
@@ -31,6 +65,8 @@ interface FileDropzoneProps extends Omit<React.ComponentProps<'div'>, 'onChange'
|
|
|
31
65
|
emptyLabel?: React.ReactNode;
|
|
32
66
|
dragLabel?: React.ReactNode;
|
|
33
67
|
renderFile?: (file: File, remove: () => void) => React.ReactNode;
|
|
68
|
+
/** The component's own texts: rejection messages, status text, remove button and size units. */
|
|
69
|
+
labels?: FileDropzoneLabels;
|
|
34
70
|
}
|
|
35
71
|
|
|
36
72
|
function fileMatchesAccept(file: File, accept: string | undefined): boolean {
|
|
@@ -46,10 +82,36 @@ function fileMatchesAccept(file: File, accept: string | undefined): boolean {
|
|
|
46
82
|
});
|
|
47
83
|
}
|
|
48
84
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
85
|
+
interface FormatFileSizeOptions {
|
|
86
|
+
/** BCP 47 locale of the number. Default: the runtime locale. */
|
|
87
|
+
locale?: string;
|
|
88
|
+
/** Unit texts. Default: `B`, `KB` and `MB`. */
|
|
89
|
+
units?: { byte?: string; kilobyte?: string; megabyte?: string };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Whole bytes below 1 KB, whole KB below 1 MB, MB with one decimal above. The
|
|
94
|
+
* number follows `locale`; the unit texts are English unless `units` is passed.
|
|
95
|
+
*/
|
|
96
|
+
function formatFileSize(bytes: number, { locale, units }: FormatFileSizeOptions = {}): string {
|
|
97
|
+
const defaults = defaultMessages.fileDropzone;
|
|
98
|
+
const format = (value: number, fractionDigits: number) =>
|
|
99
|
+
new Intl.NumberFormat(locale, {
|
|
100
|
+
minimumFractionDigits: fractionDigits,
|
|
101
|
+
maximumFractionDigits: fractionDigits,
|
|
102
|
+
useGrouping: false,
|
|
103
|
+
}).format(value);
|
|
104
|
+
if (bytes < 1024) return `${format(bytes, 0)} ${units?.byte ?? defaults.byte}`;
|
|
105
|
+
if (bytes < 1024 ** 2)
|
|
106
|
+
return `${format(bytes / 1024, 0)} ${units?.kilobyte ?? defaults.kilobyte}`;
|
|
107
|
+
return `${format(bytes / 1024 ** 2, 1)} ${units?.megabyte ?? defaults.megabyte}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Replaces each `{key}` in a message with its value. */
|
|
111
|
+
function fillMessage(template: string, values: Record<string, string | number>): string {
|
|
112
|
+
return template.replace(/\{(\w+)\}/g, (match, key: string) =>
|
|
113
|
+
key in values ? String(values[key]) : match,
|
|
114
|
+
);
|
|
53
115
|
}
|
|
54
116
|
|
|
55
117
|
function normalizeValidationResult(result: FileValidationResult): string[] {
|
|
@@ -57,32 +119,60 @@ function normalizeValidationResult(result: FileValidationResult): string[] {
|
|
|
57
119
|
return typeof result === 'string' ? [result] : [...result];
|
|
58
120
|
}
|
|
59
121
|
|
|
122
|
+
const NO_FILES: readonly File[] = [];
|
|
123
|
+
|
|
60
124
|
/**
|
|
61
|
-
*
|
|
125
|
+
* Transport-agnostic file input, controlled with `value` or uncontrolled with
|
|
126
|
+
* `defaultValue`. It owns accessible picking,
|
|
62
127
|
* drag-and-drop, limits, validation, errors, and removal; consumers own upload
|
|
63
128
|
* persistence and can replace the selected-file rendering with `renderFile`.
|
|
64
129
|
*/
|
|
65
|
-
function FileDropzone({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
130
|
+
function FileDropzone(allProps: FileDropzoneProps) {
|
|
131
|
+
const {
|
|
132
|
+
value: valueProp,
|
|
133
|
+
defaultValue,
|
|
134
|
+
onValueChange,
|
|
135
|
+
onRejected,
|
|
136
|
+
accept,
|
|
137
|
+
multiple = false,
|
|
138
|
+
maxFiles = multiple ? Number.POSITIVE_INFINITY : 1,
|
|
139
|
+
maxSize,
|
|
140
|
+
validateFile,
|
|
141
|
+
disabled,
|
|
142
|
+
required,
|
|
143
|
+
name,
|
|
144
|
+
id: providedId,
|
|
145
|
+
label = 'Upload files',
|
|
146
|
+
description,
|
|
147
|
+
emptyLabel = 'Drag and drop files here, or choose files',
|
|
148
|
+
dragLabel = 'Drop files to add them',
|
|
149
|
+
renderFile,
|
|
150
|
+
labels,
|
|
151
|
+
className,
|
|
152
|
+
...props
|
|
153
|
+
} = allProps;
|
|
154
|
+
// Controlled when the `value` prop is passed, even as `undefined` (no value).
|
|
155
|
+
const controlled = 'value' in allProps;
|
|
156
|
+
const [own, setOwn] = React.useState(defaultValue ?? NO_FILES);
|
|
157
|
+
const value = controlled ? (valueProp ?? NO_FILES) : own;
|
|
158
|
+
function commit(files: File[]) {
|
|
159
|
+
if (!controlled) setOwn(files);
|
|
160
|
+
onValueChange?.(files);
|
|
161
|
+
}
|
|
162
|
+
const { locale } = useFormatSettings();
|
|
163
|
+
const t = useMessages('fileDropzone', {
|
|
164
|
+
typeNotAccepted: labels?.typeNotAccepted,
|
|
165
|
+
validationFailed: labels?.validationFailed,
|
|
166
|
+
checking: labels?.checking,
|
|
167
|
+
accepted: labels?.accepted,
|
|
168
|
+
byte: labels?.byte,
|
|
169
|
+
kilobyte: labels?.kilobyte,
|
|
170
|
+
megabyte: labels?.megabyte,
|
|
171
|
+
});
|
|
172
|
+
const sizeOptions = {
|
|
173
|
+
locale,
|
|
174
|
+
units: { byte: t.byte, kilobyte: t.kilobyte, megabyte: t.megabyte },
|
|
175
|
+
};
|
|
86
176
|
const generatedId = React.useId();
|
|
87
177
|
const id = providedId ?? generatedId;
|
|
88
178
|
const descriptionId = `${id}-description`;
|
|
@@ -105,15 +195,16 @@ function FileDropzone({
|
|
|
105
195
|
|
|
106
196
|
for (const file of incoming.slice(0, remaining)) {
|
|
107
197
|
const messages: string[] = [];
|
|
108
|
-
if (!fileMatchesAccept(file, accept)) messages.push(
|
|
198
|
+
if (!fileMatchesAccept(file, accept)) messages.push(t.typeNotAccepted);
|
|
109
199
|
if (maxSize !== undefined && file.size > maxSize) {
|
|
110
|
-
|
|
200
|
+
const size = formatFileSize(maxSize, sizeOptions);
|
|
201
|
+
messages.push(labels?.fileTooLarge?.(size) ?? fillMessage(t.fileTooLarge, { size }));
|
|
111
202
|
}
|
|
112
203
|
if (validateFile) {
|
|
113
204
|
try {
|
|
114
205
|
messages.push(...normalizeValidationResult(await validateFile(file)));
|
|
115
206
|
} catch {
|
|
116
|
-
messages.push(
|
|
207
|
+
messages.push(t.validationFailed);
|
|
117
208
|
}
|
|
118
209
|
}
|
|
119
210
|
if (messages.length > 0) rejected.push({ file, messages });
|
|
@@ -124,7 +215,10 @@ function FileDropzone({
|
|
|
124
215
|
for (const file of incoming.slice(remaining)) {
|
|
125
216
|
rejected.push({
|
|
126
217
|
file,
|
|
127
|
-
messages: [
|
|
218
|
+
messages: [
|
|
219
|
+
labels?.tooManyFiles?.(maxFiles) ??
|
|
220
|
+
fillMessage(maxFiles === 1 ? t.tooManyFilesOne : t.tooManyFiles, { max: maxFiles }),
|
|
221
|
+
],
|
|
128
222
|
});
|
|
129
223
|
}
|
|
130
224
|
}
|
|
@@ -134,12 +228,12 @@ function FileDropzone({
|
|
|
134
228
|
setValidating(false);
|
|
135
229
|
if (rejected.length > 0) onRejected?.(rejected);
|
|
136
230
|
if (accepted.length > 0) {
|
|
137
|
-
|
|
231
|
+
commit(multiple ? [...value, ...accepted] : accepted.slice(0, 1));
|
|
138
232
|
}
|
|
139
233
|
}
|
|
140
234
|
|
|
141
235
|
function removeFile(index: number) {
|
|
142
|
-
|
|
236
|
+
commit(value.filter((_, fileIndex) => fileIndex !== index));
|
|
143
237
|
setRejections([]);
|
|
144
238
|
}
|
|
145
239
|
|
|
@@ -148,7 +242,7 @@ function FileDropzone({
|
|
|
148
242
|
<div>
|
|
149
243
|
<label htmlFor={id} className="text-sm font-medium">
|
|
150
244
|
{label}
|
|
151
|
-
{required ? <span className="text-destructive"> *</span> : null}
|
|
245
|
+
{required ? <span className="text-destructive-text"> *</span> : null}
|
|
152
246
|
</label>
|
|
153
247
|
{description ? (
|
|
154
248
|
<p id={descriptionId} className="text-muted-foreground mt-1 text-sm">
|
|
@@ -211,9 +305,9 @@ function FileDropzone({
|
|
|
211
305
|
>
|
|
212
306
|
<UploadCloudIcon className="size-7" />
|
|
213
307
|
<span className="text-foreground text-sm font-medium">
|
|
214
|
-
{validating ?
|
|
308
|
+
{validating ? t.checking : dragging ? dragLabel : emptyLabel}
|
|
215
309
|
</span>
|
|
216
|
-
{accept ? <span className="text-xs">
|
|
310
|
+
{accept ? <span className="text-xs">{`${t.accepted} ${accept}`}</span> : null}
|
|
217
311
|
</label>
|
|
218
312
|
|
|
219
313
|
{value.length > 0 ? (
|
|
@@ -229,14 +323,18 @@ function FileDropzone({
|
|
|
229
323
|
<FileIcon className="text-muted-foreground size-4 shrink-0" />
|
|
230
324
|
<div className="min-w-0 flex-1">
|
|
231
325
|
<p className="truncate text-sm font-medium">{file.name}</p>
|
|
232
|
-
<p className="text-muted-foreground text-xs">
|
|
326
|
+
<p className="text-muted-foreground text-xs">
|
|
327
|
+
{formatFileSize(file.size, sizeOptions)}
|
|
328
|
+
</p>
|
|
233
329
|
</div>
|
|
234
330
|
<Button
|
|
235
331
|
type="button"
|
|
236
332
|
variant="ghost"
|
|
237
333
|
size="icon-xs"
|
|
238
334
|
disabled={disabled}
|
|
239
|
-
aria-label={
|
|
335
|
+
aria-label={
|
|
336
|
+
labels?.remove?.(file.name) ?? fillMessage(t.remove, { name: file.name })
|
|
337
|
+
}
|
|
240
338
|
onClick={() => removeFile(index)}
|
|
241
339
|
>
|
|
242
340
|
<XIcon />
|
|
@@ -249,7 +347,7 @@ function FileDropzone({
|
|
|
249
347
|
) : null}
|
|
250
348
|
|
|
251
349
|
{rejections.length > 0 ? (
|
|
252
|
-
<div id={errorId} role="alert" className="text-destructive text-sm">
|
|
350
|
+
<div id={errorId} role="alert" className="text-destructive-text text-sm">
|
|
253
351
|
{rejections.map(({ file, messages }, index) => (
|
|
254
352
|
<p key={`${file.name}-${file.size}-${index}`}>
|
|
255
353
|
<span className="font-medium">{file.name}:</span> {messages.join(' ')}
|
|
@@ -265,7 +363,9 @@ export {
|
|
|
265
363
|
FileDropzone,
|
|
266
364
|
fileMatchesAccept,
|
|
267
365
|
formatFileSize,
|
|
366
|
+
type FileDropzoneLabels,
|
|
268
367
|
type FileDropzoneProps,
|
|
269
368
|
type FileRejection,
|
|
369
|
+
type FormatFileSizeOptions,
|
|
270
370
|
type FileValidator,
|
|
271
371
|
};
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { createContext, type ReactNode, useContext, useMemo } from 'react';
|
|
4
4
|
import type { Locale } from 'react-day-picker';
|
|
5
|
+
import type { FormatMessages } from '../../lib/format-messages.ts';
|
|
5
6
|
|
|
6
7
|
// The design system cannot depend on any app's i18n. Formatters resolve their
|
|
7
8
|
// locale/currency in a fixed order — explicit prop → this context → `undefined`
|
|
8
9
|
// (a valid Intl argument that falls back to the runtime default locale) — so a
|
|
9
10
|
// bare `<Money>` or `<DateTime>` works with zero setup, and an app that mounts
|
|
10
11
|
// `FormatProvider` (e.g. from its own locale + server config) gets consistent
|
|
11
|
-
// output everywhere without threading props.
|
|
12
|
+
// output everywhere without threading props. Texts follow the same order
|
|
13
|
+
// through `messages` (see `lib/format-messages.ts`).
|
|
12
14
|
interface FormatContextValue {
|
|
13
15
|
/** BCP 47 locale tag, e.g. `en-GB`. */
|
|
14
16
|
locale?: string;
|
|
@@ -30,6 +32,13 @@ interface FormatContextValue {
|
|
|
30
32
|
* `undefined` → US English. A `Calendar`'s own `locale` prop wins.
|
|
31
33
|
*/
|
|
32
34
|
calendarLocale?: Locale;
|
|
35
|
+
/**
|
|
36
|
+
* The library's texts in the active language, nested by component, for
|
|
37
|
+
* example `{ passwordInput: { showPassword: 'Passwort anzeigen' } }`. Every
|
|
38
|
+
* text is optional: a missing one stays English. A component's own label
|
|
39
|
+
* prop wins over this.
|
|
40
|
+
*/
|
|
41
|
+
messages?: FormatMessages;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
const FormatContext = createContext<FormatContextValue>({});
|
|
@@ -41,10 +50,11 @@ function FormatProvider({
|
|
|
41
50
|
currency,
|
|
42
51
|
currencyPrecision,
|
|
43
52
|
calendarLocale,
|
|
53
|
+
messages,
|
|
44
54
|
}: FormatContextValue & { children: ReactNode }) {
|
|
45
55
|
const value = useMemo(
|
|
46
|
-
() => ({ locale, timeZone, currency, currencyPrecision, calendarLocale }),
|
|
47
|
-
[locale, timeZone, currency, currencyPrecision, calendarLocale],
|
|
56
|
+
() => ({ locale, timeZone, currency, currencyPrecision, calendarLocale, messages }),
|
|
57
|
+
[locale, timeZone, currency, currencyPrecision, calendarLocale, messages],
|
|
48
58
|
);
|
|
49
59
|
return <FormatContext.Provider value={value}>{children}</FormatContext.Provider>;
|
|
50
60
|
}
|
|
@@ -53,4 +63,4 @@ function useFormatSettings(): FormatContextValue {
|
|
|
53
63
|
return useContext(FormatContext);
|
|
54
64
|
}
|
|
55
65
|
|
|
56
|
-
export { FormatProvider, useFormatSettings, type FormatContextValue };
|
|
66
|
+
export { FormatProvider, useFormatSettings, type FormatContextValue, type FormatMessages };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Tooltip,
|
|
5
|
+
TooltipContent,
|
|
6
|
+
TooltipLabelSwap,
|
|
7
|
+
TooltipTrigger,
|
|
8
|
+
} from '@vendure-io/ui/components/atoms/tooltip';
|
|
9
|
+
import type * as React from 'react';
|
|
10
|
+
import { contentInsetPull } from '../../lib/content-inset.ts';
|
|
11
|
+
import { cn } from '../../lib/utils.ts';
|
|
12
|
+
|
|
13
|
+
// Internal: closed in `package.json` exports. Only the identifier-chip family
|
|
14
|
+
// imports it, by a relative path.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Shared chrome for the identifier-chip family (`IdChip`, `AnonymizedToken`,
|
|
18
|
+
* `SecretValue`): a borderless `bg-muted`, monospace `text-xs` chip, 24px
|
|
19
|
+
* tall, sized to its content. Its `--content-inset` (the 8px start padding)
|
|
20
|
+
* lets a DataTable cell line the value up with the column header. Kept in
|
|
21
|
+
* one place so the chips can't drift
|
|
22
|
+
* apart: only their *contents* differ (a plain value, a blurred
|
|
23
|
+
* reveal-on-hover secret, or a masked secret loaded on click).
|
|
24
|
+
*
|
|
25
|
+
* A chip that copies as a whole (see `chipCopyButtonProps`) gets the hover
|
|
26
|
+
* fill and the press feedback here, keyed on that button, so a chip with
|
|
27
|
+
* several controls (`SecretValue`) keeps a still surface.
|
|
28
|
+
*/
|
|
29
|
+
function chipChromeClass(copyable: boolean, className?: string): string {
|
|
30
|
+
return cn(
|
|
31
|
+
'relative inline-flex min-h-6 w-fit items-center gap-1.5 rounded-lg bg-muted py-0.5 ps-2 [--content-inset:calc(var(--spacing)*2)] font-mono text-xs text-foreground-secondary',
|
|
32
|
+
'transition-[background-color,color,scale] duration-quick ease-soft',
|
|
33
|
+
contentInsetPull,
|
|
34
|
+
'has-data-chip-copy:cursor-pointer has-data-chip-copy:hover:bg-accent has-data-chip-copy:hover:text-foreground motion-safe:has-data-chip-copy:active:scale-[0.97]',
|
|
35
|
+
// The chip is the copy target, so the focus ring goes around the chip, not the 13px button.
|
|
36
|
+
'has-[[data-chip-copy]:focus-visible]:outline-2 has-[[data-chip-copy]:focus-visible]:outline-offset-2 has-[[data-chip-copy]:focus-visible]:outline-ring has-[[data-chip-copy]:focus-visible]:outline-solid',
|
|
37
|
+
copyable ? 'pe-1.5' : 'pe-2',
|
|
38
|
+
className,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The look of an icon button inside an identifier chip: exactly the 13px
|
|
44
|
+
* icon, in the chip's text colour, with no fill on hover. The icon shows at
|
|
45
|
+
* 55%, quieter than the value beside it; a spinner (`role=status`) and the
|
|
46
|
+
* copied check keep full strength. The chip's 6px end padding is the visible
|
|
47
|
+
* inset. `IdChip`, `AnonymizedToken` and `SecretValue` all build on it, so
|
|
48
|
+
* their buttons cannot drift apart.
|
|
49
|
+
*/
|
|
50
|
+
const chipIconButtonClass = cn(
|
|
51
|
+
"size-3.25 [&_svg:not([class*='size-'])]:size-3.25",
|
|
52
|
+
'text-inherit hover:bg-transparent dark:hover:bg-transparent',
|
|
53
|
+
'[&>svg:not([role=status])]:opacity-55',
|
|
54
|
+
'[&_[data-slot=copy-state-icon]:not([data-copied])>svg:first-child]:opacity-55',
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Props for a `CopyButton` that turns its whole chip into the copy target. Its
|
|
59
|
+
* `::after` stretches over the chip (the chip is `relative`), so a click
|
|
60
|
+
* anywhere on the chip copies, while the button stays the only tab stop and
|
|
61
|
+
* keeps its accessible name. The value text stays plain, readable text.
|
|
62
|
+
*
|
|
63
|
+
* It has the `chipIconButtonClass` look. Its focus ring moves to the chip
|
|
64
|
+
* (see `chipChromeClass`), and it keeps the chip's text colour on hover: the
|
|
65
|
+
* whole chip brightens instead.
|
|
66
|
+
*
|
|
67
|
+
* The button never scales on press (the chip does). Any `scale` other than
|
|
68
|
+
* `none` makes the button the containing block of its `::after`, which then
|
|
69
|
+
* shrinks to the 13px icon between mousedown and mouseup. A mouseup over the
|
|
70
|
+
* value text then lands outside the button, and the click goes to the chip
|
|
71
|
+
* instead of the button, so nothing is copied.
|
|
72
|
+
*/
|
|
73
|
+
const chipCopyButtonProps = {
|
|
74
|
+
'data-chip-copy': '',
|
|
75
|
+
className: cn(
|
|
76
|
+
chipIconButtonClass,
|
|
77
|
+
'after:absolute after:inset-0 focus-visible:outline-none hover:text-inherit',
|
|
78
|
+
'active:scale-none motion-reduce:active:scale-none',
|
|
79
|
+
),
|
|
80
|
+
} as const;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Tooltip text of a whole-chip copy target: "Copy" until the copy succeeds,
|
|
84
|
+
* then "Copied", swapped in one motion by `TooltipLabelSwap`. Nothing else:
|
|
85
|
+
* the chip shows the start and end of its value, and a click copies all of it.
|
|
86
|
+
*
|
|
87
|
+
* The tooltip closes as soon as the pointer leaves the chip. In a list it can
|
|
88
|
+
* open below the chip and cover the chip in the next row; a tooltip that stays
|
|
89
|
+
* open while the pointer moves onto it would block that chip. Nothing in it
|
|
90
|
+
* needs the pointer.
|
|
91
|
+
*/
|
|
92
|
+
function ChipCopyTooltip({
|
|
93
|
+
chip,
|
|
94
|
+
copied,
|
|
95
|
+
copyLabel,
|
|
96
|
+
copiedLabel,
|
|
97
|
+
}: {
|
|
98
|
+
chip: React.ReactElement;
|
|
99
|
+
copied: boolean;
|
|
100
|
+
copyLabel: string;
|
|
101
|
+
copiedLabel: string;
|
|
102
|
+
}) {
|
|
103
|
+
return (
|
|
104
|
+
<Tooltip disableHoverablePopup>
|
|
105
|
+
{/* The click that copies must not close the tooltip, or "Copied" is never seen. */}
|
|
106
|
+
<TooltipTrigger render={chip} closeOnClick={false} />
|
|
107
|
+
<TooltipContent>
|
|
108
|
+
<TooltipLabelSwap labels={[copyLabel, copiedLabel]} active={copied ? 1 : 0} />
|
|
109
|
+
</TooltipContent>
|
|
110
|
+
</Tooltip>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { ChipCopyTooltip, chipChromeClass, chipCopyButtonProps, chipIconButtonClass };
|
|
@@ -1,116 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
Tooltip,
|
|
5
|
-
TooltipContent,
|
|
6
|
-
TooltipLabelSwap,
|
|
7
|
-
TooltipTrigger,
|
|
8
|
-
} from '@vendure-io/ui/components/atoms/tooltip';
|
|
3
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
|
|
9
4
|
import { CopyButton, useCopyAction } from '@vendure-io/ui/components/molecules/copyable-text';
|
|
10
|
-
import { contentInsetPull } from '@vendure-io/ui/lib/content-inset';
|
|
11
5
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
12
|
-
import
|
|
6
|
+
import { ChipCopyTooltip, chipChromeClass, chipCopyButtonProps } from './id-chip-chrome.tsx';
|
|
13
7
|
|
|
14
8
|
type TruncateMode = 'middle' | 'start' | 'none';
|
|
15
9
|
|
|
16
|
-
/**
|
|
17
|
-
* Shared chrome for the identifier-chip family (`IdChip`, `AnonymizedToken`,
|
|
18
|
-
* `SecretValue`): a borderless `bg-muted`, monospace `text-xs` chip, 24px
|
|
19
|
-
* tall, sized to its content. Its `--content-inset` (the 8px start padding)
|
|
20
|
-
* lets a DataTable cell line the value up with the column header. Kept in
|
|
21
|
-
* one place so the chips can't drift
|
|
22
|
-
* apart: only their *contents* differ (a plain value, a blurred
|
|
23
|
-
* reveal-on-hover secret, or a masked secret loaded on click).
|
|
24
|
-
*
|
|
25
|
-
* A chip that copies as a whole (see `chipCopyButtonProps`) gets the hover
|
|
26
|
-
* fill and the press feedback here, keyed on that button, so a chip with
|
|
27
|
-
* several controls (`SecretValue`) keeps a still surface.
|
|
28
|
-
*/
|
|
29
|
-
function chipChromeClass(copyable: boolean, className?: string): string {
|
|
30
|
-
return cn(
|
|
31
|
-
'relative inline-flex min-h-6 w-fit items-center gap-1.5 rounded-lg bg-muted py-0.5 ps-2 [--content-inset:calc(var(--spacing)*2)] font-mono text-xs text-foreground-secondary',
|
|
32
|
-
'transition-[background-color,color,scale] duration-quick ease-soft',
|
|
33
|
-
contentInsetPull,
|
|
34
|
-
'has-data-chip-copy:cursor-pointer has-data-chip-copy:hover:bg-accent has-data-chip-copy:hover:text-foreground motion-safe:has-data-chip-copy:active:scale-[0.97]',
|
|
35
|
-
// The chip is the copy target, so the focus ring goes around the chip, not the 13px button.
|
|
36
|
-
'has-[[data-chip-copy]:focus-visible]:outline-2 has-[[data-chip-copy]:focus-visible]:outline-offset-2 has-[[data-chip-copy]:focus-visible]:outline-ring has-[[data-chip-copy]:focus-visible]:outline-solid',
|
|
37
|
-
copyable ? 'pe-1.5' : 'pe-2',
|
|
38
|
-
className,
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The look of an icon button inside an identifier chip: exactly the 13px
|
|
44
|
-
* icon, in the chip's text colour, with no fill on hover. The icon shows at
|
|
45
|
-
* 55%, quieter than the value beside it; a spinner (`role=status`) and the
|
|
46
|
-
* copied check keep full strength. The chip's 6px end padding is the visible
|
|
47
|
-
* inset. `IdChip`, `AnonymizedToken` and `SecretValue` all build on it, so
|
|
48
|
-
* their buttons cannot drift apart.
|
|
49
|
-
*/
|
|
50
|
-
const chipIconButtonClass = cn(
|
|
51
|
-
"size-3.25 [&_svg:not([class*='size-'])]:size-3.25",
|
|
52
|
-
'text-inherit hover:bg-transparent dark:hover:bg-transparent',
|
|
53
|
-
'[&>svg:not([role=status])]:opacity-55',
|
|
54
|
-
'[&_[data-slot=copy-state-icon]:not([data-copied])>svg:first-child]:opacity-55',
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Props for a `CopyButton` that turns its whole chip into the copy target. Its
|
|
59
|
-
* `::after` stretches over the chip (the chip is `relative`), so a click
|
|
60
|
-
* anywhere on the chip copies, while the button stays the only tab stop and
|
|
61
|
-
* keeps its accessible name. The value text stays plain, readable text.
|
|
62
|
-
*
|
|
63
|
-
* It has the `chipIconButtonClass` look. Its focus ring moves to the chip
|
|
64
|
-
* (see `chipChromeClass`), and it keeps the chip's text colour on hover: the
|
|
65
|
-
* whole chip brightens instead.
|
|
66
|
-
*
|
|
67
|
-
* The button never scales on press (the chip does). Any `scale` other than
|
|
68
|
-
* `none` makes the button the containing block of its `::after`, which then
|
|
69
|
-
* shrinks to the 13px icon between mousedown and mouseup. A mouseup over the
|
|
70
|
-
* value text then lands outside the button, and the click goes to the chip
|
|
71
|
-
* instead of the button, so nothing is copied.
|
|
72
|
-
*/
|
|
73
|
-
const chipCopyButtonProps = {
|
|
74
|
-
'data-chip-copy': '',
|
|
75
|
-
className: cn(
|
|
76
|
-
chipIconButtonClass,
|
|
77
|
-
'after:absolute after:inset-0 focus-visible:outline-none hover:text-inherit',
|
|
78
|
-
'active:scale-none motion-reduce:active:scale-none',
|
|
79
|
-
),
|
|
80
|
-
} as const;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Tooltip text of a whole-chip copy target: "Copy" until the copy succeeds,
|
|
84
|
-
* then "Copied", swapped in one motion by `TooltipLabelSwap`. Nothing else:
|
|
85
|
-
* the chip shows the start and end of its value, and a click copies all of it.
|
|
86
|
-
*
|
|
87
|
-
* The tooltip closes as soon as the pointer leaves the chip. In a list it can
|
|
88
|
-
* open below the chip and cover the chip in the next row; a tooltip that stays
|
|
89
|
-
* open while the pointer moves onto it would block that chip. Nothing in it
|
|
90
|
-
* needs the pointer.
|
|
91
|
-
*/
|
|
92
|
-
function ChipCopyTooltip({
|
|
93
|
-
chip,
|
|
94
|
-
copied,
|
|
95
|
-
copyLabel,
|
|
96
|
-
copiedLabel,
|
|
97
|
-
}: {
|
|
98
|
-
chip: React.ReactElement;
|
|
99
|
-
copied: boolean;
|
|
100
|
-
copyLabel: string;
|
|
101
|
-
copiedLabel: string;
|
|
102
|
-
}) {
|
|
103
|
-
return (
|
|
104
|
-
<Tooltip disableHoverablePopup>
|
|
105
|
-
{/* The click that copies must not close the tooltip, or "Copied" is never seen. */}
|
|
106
|
-
<TooltipTrigger render={chip} closeOnClick={false} />
|
|
107
|
-
<TooltipContent>
|
|
108
|
-
<TooltipLabelSwap labels={[copyLabel, copiedLabel]} active={copied ? 1 : 0} />
|
|
109
|
-
</TooltipContent>
|
|
110
|
-
</Tooltip>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
10
|
// Middle truncation renders 13 chars (8 + ellipsis + 4), so anything at or
|
|
115
11
|
// below that length would lose information without saving space — skip it.
|
|
116
12
|
const TRUNCATE_THRESHOLD = 13;
|
|
@@ -242,5 +138,5 @@ function IdChip({
|
|
|
242
138
|
);
|
|
243
139
|
}
|
|
244
140
|
|
|
245
|
-
export {
|
|
141
|
+
export { IdChip };
|
|
246
142
|
export type { IdChipProps };
|
|
@@ -206,7 +206,7 @@ function IssuedSecret({
|
|
|
206
206
|
</Field>
|
|
207
207
|
) : null}
|
|
208
208
|
{guard.warned ? (
|
|
209
|
-
<Alert data-slot="issued-secret-warning"
|
|
209
|
+
<Alert data-slot="issued-secret-warning" tone="warning">
|
|
210
210
|
<AlertTitle>{warningTitle}</AlertTitle>
|
|
211
211
|
<AlertDescription>{warningDescription}</AlertDescription>
|
|
212
212
|
</Alert>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
|
|
2
|
-
import { statusToneText } from '@vendure-io/ui/lib/tint-recipes';
|
|
3
2
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
4
3
|
import type * as React from 'react';
|
|
4
|
+
import { statusToneText } from '../../lib/tint-recipes.ts';
|
|
5
5
|
|
|
6
6
|
// The dot fill of each tone, as in StatusBadge: a dot is a filled shape, so
|
|
7
7
|
// warning takes `warning-indicator`; in `warning-text` the dot reads brown.
|