@vendure-io/ui 3.0.0-next.5 → 3.0.0-next.7
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 +1 -1
- package/src/components/atoms/breadcrumb.tsx +31 -11
- package/src/components/atoms/carousel.tsx +33 -7
- package/src/components/atoms/combobox.tsx +144 -17
- package/src/components/atoms/command.tsx +14 -4
- package/src/components/atoms/pagination.tsx +43 -12
- package/src/components/atoms/sidebar.tsx +24 -5
- package/src/components/atoms/spinner.tsx +7 -2
- package/src/components/molecules/action-needed.tsx +4 -4
- package/src/components/molecules/anonymized-token.tsx +19 -18
- package/src/components/molecules/app-shell.tsx +14 -5
- package/src/components/molecules/checklist/checklist.tsx +47 -17
- package/src/components/molecules/choice-card.tsx +3 -0
- package/src/components/molecules/confirm-dialog.tsx +6 -4
- package/src/components/molecules/data-table/data-table-filters.tsx +25 -7
- package/src/components/molecules/data-table/data-table-types.tsx +33 -16
- package/src/components/molecules/data-table/data-table-view-options.tsx +14 -4
- package/src/components/molecules/data-table/data-table.tsx +47 -26
- package/src/components/molecules/data-table/table-pagination.tsx +51 -29
- package/src/components/molecules/date-picker.tsx +4 -2
- package/src/components/molecules/date-range-picker.tsx +6 -2
- package/src/components/molecules/date-time-picker.tsx +4 -2
- package/src/components/molecules/file-dropzone.tsx +16 -5
- package/src/components/molecules/id-chip.tsx +10 -8
- package/src/components/molecules/issued-secret.tsx +34 -24
- package/src/components/molecules/multi-select.tsx +470 -107
- package/src/components/molecules/secret-value.tsx +26 -18
- package/src/components/molecules/skip-link.tsx +11 -9
- package/src/components/molecules/stat-card.tsx +2 -0
- package/src/components/molecules/state-views/error-state.tsx +18 -6
- package/src/components/molecules/state-views/loading-state.tsx +2 -0
- package/src/components/molecules/status-badge.tsx +5 -2
- package/src/lib/chip-fit.ts +62 -0
- package/src/lib/format-messages.ts +189 -0
- package/src/lib/multi-select-keys.ts +77 -0
|
@@ -66,6 +66,7 @@ import { AnimatePresence, MotionConfig, motion, useReducedMotion } from 'motion/
|
|
|
66
66
|
import * as React from 'react';
|
|
67
67
|
import { createPortal } from 'react-dom';
|
|
68
68
|
import { isDevelopment } from '../../../lib/env.ts';
|
|
69
|
+
import { fillMessage, useMessages } from '../../../lib/format-messages.ts';
|
|
69
70
|
import { DataTableBulkActions, useSelectionCache } from './data-table-bulk-actions.tsx';
|
|
70
71
|
// Relative: `data-table-helpers` is closed in the package exports.
|
|
71
72
|
import {
|
|
@@ -776,26 +777,46 @@ function DataTable<TData>({
|
|
|
776
777
|
);
|
|
777
778
|
}
|
|
778
779
|
|
|
779
|
-
//
|
|
780
|
+
// The texts DataTable draws itself: the `labels` entry, then
|
|
781
|
+
// `messages.dataTable`, then English. The texts of the toolbar parts
|
|
782
|
+
// (DataTableAddFilter, DataTableViewOptions, DataTableAppliedFilters,
|
|
783
|
+
// TablePagination) get the raw `labels` entry and resolve it there, so each
|
|
784
|
+
// text has one resolution point.
|
|
785
|
+
const t = useMessages('dataTable', {
|
|
786
|
+
empty: labels?.empty,
|
|
787
|
+
selectAllRows: labels?.selectAllRows,
|
|
788
|
+
selectAllOnPage: labels?.selectAllOnPage,
|
|
789
|
+
clearPageSelection: labels?.clearPageSelection,
|
|
790
|
+
rowActions: labels?.rowActions,
|
|
791
|
+
clearFilters: labels?.clearFilters,
|
|
792
|
+
});
|
|
793
|
+
// Resolve labels once per `labels` identity and messages.
|
|
780
794
|
const l = React.useMemo(
|
|
781
795
|
() => ({
|
|
782
|
-
empty:
|
|
783
|
-
selectAllRows:
|
|
784
|
-
selectAllOnPage:
|
|
785
|
-
clearPageSelection:
|
|
786
|
-
selectRow:
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
labels?.removeFilter ?? ((columnLabel: string) => `Remove ${columnLabel} filter`),
|
|
794
|
-
sortLabel: labels?.sortLabel ?? ((columnLabel: string) => `Sort by ${columnLabel}`),
|
|
795
|
-
filtersCollapsed: labels?.filtersCollapsed ?? ((count: number) => `${count} filters`),
|
|
796
|
-
pagination: labels?.pagination,
|
|
796
|
+
empty: t.empty,
|
|
797
|
+
selectAllRows: t.selectAllRows,
|
|
798
|
+
selectAllOnPage: t.selectAllOnPage,
|
|
799
|
+
clearPageSelection: t.clearPageSelection,
|
|
800
|
+
selectRow:
|
|
801
|
+
labels?.selectRow ?? ((index: number) => fillMessage(t.selectRow, { row: index + 1 })),
|
|
802
|
+
rowActions: t.rowActions,
|
|
803
|
+
clearFilters: t.clearFilters,
|
|
804
|
+
sortLabel:
|
|
805
|
+
labels?.sortLabel ??
|
|
806
|
+
((columnLabel: string) => fillMessage(t.sortLabel, { column: columnLabel })),
|
|
797
807
|
}),
|
|
798
|
-
[
|
|
808
|
+
[
|
|
809
|
+
labels?.selectRow,
|
|
810
|
+
labels?.sortLabel,
|
|
811
|
+
t.empty,
|
|
812
|
+
t.selectAllRows,
|
|
813
|
+
t.selectAllOnPage,
|
|
814
|
+
t.clearPageSelection,
|
|
815
|
+
t.selectRow,
|
|
816
|
+
t.rowActions,
|
|
817
|
+
t.clearFilters,
|
|
818
|
+
t.sortLabel,
|
|
819
|
+
],
|
|
799
820
|
);
|
|
800
821
|
|
|
801
822
|
warnOnChange(sorting, 'sorting');
|
|
@@ -1320,15 +1341,15 @@ function DataTable<TData>({
|
|
|
1320
1341
|
<DataTableAddFilter
|
|
1321
1342
|
table={table}
|
|
1322
1343
|
columns={filters.columns}
|
|
1323
|
-
label={
|
|
1344
|
+
label={labels?.addFilter}
|
|
1324
1345
|
valueLabel={labels?.filterValue}
|
|
1325
1346
|
/>
|
|
1326
1347
|
)}
|
|
1327
1348
|
{showViewOptions && (
|
|
1328
1349
|
<DataTableViewOptions
|
|
1329
1350
|
table={table}
|
|
1330
|
-
triggerLabel={
|
|
1331
|
-
heading={
|
|
1351
|
+
triggerLabel={labels?.columnsTrigger}
|
|
1352
|
+
heading={labels?.columnsHeading}
|
|
1332
1353
|
/>
|
|
1333
1354
|
)}
|
|
1334
1355
|
</ListHeaderControls>
|
|
@@ -1361,8 +1382,8 @@ function DataTable<TData>({
|
|
|
1361
1382
|
table={table}
|
|
1362
1383
|
columns={filters?.columns}
|
|
1363
1384
|
inlineChipLimit={filters?.inlineChipLimit}
|
|
1364
|
-
removeLabel={
|
|
1365
|
-
collapsedLabel={
|
|
1385
|
+
removeLabel={labels?.removeFilter}
|
|
1386
|
+
collapsedLabel={labels?.filtersCollapsed}
|
|
1366
1387
|
/>
|
|
1367
1388
|
{clearFilters && !clearFilters.hidden && (
|
|
1368
1389
|
<Button
|
|
@@ -1574,10 +1595,10 @@ function DataTable<TData>({
|
|
|
1574
1595
|
pageSizeOptions={pagination.pageSizeOptions}
|
|
1575
1596
|
getPageHref={pagination.getPageHref}
|
|
1576
1597
|
formatRange={pagination.formatRange}
|
|
1577
|
-
navLabel={
|
|
1578
|
-
previousLabel={
|
|
1579
|
-
nextLabel={
|
|
1580
|
-
pageSizeLabel={
|
|
1598
|
+
navLabel={labels?.pagination?.navLabel}
|
|
1599
|
+
previousLabel={labels?.pagination?.previousLabel}
|
|
1600
|
+
nextLabel={labels?.pagination?.nextLabel}
|
|
1601
|
+
pageSizeLabel={labels?.pagination?.pageSizeLabel}
|
|
1581
1602
|
/>
|
|
1582
1603
|
</CardFooter>
|
|
1583
1604
|
)}
|
|
@@ -14,6 +14,7 @@ import { cn } from '@vendure-io/ui/lib/utils';
|
|
|
14
14
|
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
|
|
15
15
|
import type * as React from 'react';
|
|
16
16
|
// Relative: `data-table-helpers` is closed in the package exports.
|
|
17
|
+
import { fillMessage, useMessages } from '../../../lib/format-messages.ts';
|
|
17
18
|
import { PENDING_CLASS } from './data-table-helpers.tsx';
|
|
18
19
|
|
|
19
20
|
// The list-page pagination footer: range text on one side, optional page-size
|
|
@@ -66,19 +67,17 @@ function getRange(
|
|
|
66
67
|
// of its English words, so a server render and the browser agree.
|
|
67
68
|
const rangeNumber = new Intl.NumberFormat('en');
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
total
|
|
78
|
-
}): string {
|
|
79
|
-
if (total <= 0) return '0 of 0';
|
|
70
|
+
/**
|
|
71
|
+
* Default range string from `messages.tablePagination`: `rangeEmpty` ("0 of 0")
|
|
72
|
+
* when empty, else `range` ("start–end of total", en dash).
|
|
73
|
+
*/
|
|
74
|
+
function defaultFormatRange(
|
|
75
|
+
{ start, end, total }: { start: number; end: number; total: number },
|
|
76
|
+
messages: { range: string; rangeEmpty: string },
|
|
77
|
+
): string {
|
|
78
|
+
if (total <= 0) return messages.rangeEmpty;
|
|
80
79
|
const n = (value: number) => rangeNumber.format(value);
|
|
81
|
-
return
|
|
80
|
+
return fillMessage(messages.range, { start: n(start), end: n(end), total: n(total) });
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
interface TablePaginationProps extends React.ComponentProps<'div'> {
|
|
@@ -127,17 +126,30 @@ interface TablePaginationProps extends React.ComponentProps<'div'> {
|
|
|
127
126
|
getPageHref?: (page: number) => string;
|
|
128
127
|
/**
|
|
129
128
|
* Override the range text. Receives the clamped 1-based range and total, and
|
|
130
|
-
* defaults to "start–end of total"
|
|
131
|
-
*
|
|
129
|
+
* defaults to `messages.tablePagination.range`, "{start}–{end} of {total}"
|
|
130
|
+
* (`rangeEmpty`, "0 of 0", when empty). A function, not a word-swap prop, so
|
|
131
|
+
* it survives non-English word order.
|
|
132
132
|
*/
|
|
133
133
|
formatRange?: (range: { start: number; end: number; total: number }) => string;
|
|
134
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Accessible name for the prev/next navigation landmark.
|
|
136
|
+
* @default `messages.tablePagination.nav`, "Pagination"
|
|
137
|
+
*/
|
|
135
138
|
navLabel?: string;
|
|
136
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* Accessible name for the previous-page control.
|
|
141
|
+
* @default `messages.tablePagination.previous`, "Go to previous page"
|
|
142
|
+
*/
|
|
137
143
|
previousLabel?: string;
|
|
138
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* Accessible name for the next-page control.
|
|
146
|
+
* @default `messages.tablePagination.next`, "Go to next page"
|
|
147
|
+
*/
|
|
139
148
|
nextLabel?: string;
|
|
140
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Visible + accessible name for the page-size selector.
|
|
151
|
+
* @default `messages.tablePagination.pageSize`, "Items per page"
|
|
152
|
+
*/
|
|
141
153
|
pageSizeLabel?: string;
|
|
142
154
|
}
|
|
143
155
|
|
|
@@ -150,14 +162,20 @@ function TablePagination({
|
|
|
150
162
|
onPageSizeChange,
|
|
151
163
|
pageSizeOptions = [10, 25, 50, 100],
|
|
152
164
|
getPageHref,
|
|
153
|
-
formatRange
|
|
154
|
-
navLabel
|
|
155
|
-
previousLabel
|
|
156
|
-
nextLabel
|
|
157
|
-
pageSizeLabel
|
|
165
|
+
formatRange,
|
|
166
|
+
navLabel,
|
|
167
|
+
previousLabel,
|
|
168
|
+
nextLabel,
|
|
169
|
+
pageSizeLabel,
|
|
158
170
|
className,
|
|
159
171
|
...props
|
|
160
172
|
}: TablePaginationProps) {
|
|
173
|
+
const t = useMessages('tablePagination', {
|
|
174
|
+
nav: navLabel,
|
|
175
|
+
previous: previousLabel,
|
|
176
|
+
next: nextLabel,
|
|
177
|
+
pageSize: pageSizeLabel,
|
|
178
|
+
});
|
|
161
179
|
const totalKnown = totalItems != null;
|
|
162
180
|
const pageCount = getPageCount(totalItems ?? 0, pageSize);
|
|
163
181
|
const current = clampPage(page, pageCount);
|
|
@@ -188,7 +206,11 @@ function TablePagination({
|
|
|
188
206
|
)}
|
|
189
207
|
>
|
|
190
208
|
{totalKnown ? (
|
|
191
|
-
formatRange(
|
|
209
|
+
(formatRange ?? ((range) => defaultFormatRange(range, t)))({
|
|
210
|
+
start,
|
|
211
|
+
end,
|
|
212
|
+
total: totalItems,
|
|
213
|
+
})
|
|
192
214
|
) : (
|
|
193
215
|
// One line box tall, so the footer keeps the height it has with the
|
|
194
216
|
// range text. The text is not known, so there is nothing to announce.
|
|
@@ -201,10 +223,10 @@ function TablePagination({
|
|
|
201
223
|
{onPageSizeChange && (
|
|
202
224
|
<div className="flex items-center gap-2">
|
|
203
225
|
<span className="text-muted-foreground text-sm whitespace-nowrap @max-md/table-pagination:sr-only">
|
|
204
|
-
{
|
|
226
|
+
{t.pageSize}
|
|
205
227
|
</span>
|
|
206
228
|
<Select value={pageSize} onValueChange={(value) => onPageSizeChange(Number(value))}>
|
|
207
|
-
<SelectTrigger aria-label={
|
|
229
|
+
<SelectTrigger aria-label={t.pageSize} className="w-fit">
|
|
208
230
|
<SelectValue />
|
|
209
231
|
</SelectTrigger>
|
|
210
232
|
<SelectContent>
|
|
@@ -225,7 +247,7 @@ function TablePagination({
|
|
|
225
247
|
// text or size selector. Mirrors the shadcn pagination atom's
|
|
226
248
|
// role="navigation" + aria-label.
|
|
227
249
|
<nav
|
|
228
|
-
aria-label={
|
|
250
|
+
aria-label={t.nav}
|
|
229
251
|
data-pending={pending ? '' : undefined}
|
|
230
252
|
className={cn('flex items-center gap-1', PENDING_CLASS)}
|
|
231
253
|
>
|
|
@@ -234,7 +256,7 @@ function TablePagination({
|
|
|
234
256
|
anchor={anchorMode}
|
|
235
257
|
disabled={isFirst}
|
|
236
258
|
pending={pending}
|
|
237
|
-
label={
|
|
259
|
+
label={t.previous}
|
|
238
260
|
href={anchorMode && !isFirst ? getPageHref?.(current - 1) : undefined}
|
|
239
261
|
onClick={onPageChange ? () => onPageChange(current - 1) : undefined}
|
|
240
262
|
>
|
|
@@ -245,7 +267,7 @@ function TablePagination({
|
|
|
245
267
|
anchor={anchorMode}
|
|
246
268
|
disabled={isLast}
|
|
247
269
|
pending={pending}
|
|
248
|
-
label={
|
|
270
|
+
label={t.next}
|
|
249
271
|
href={anchorMode && !isLast ? getPageHref?.(current + 1) : undefined}
|
|
250
272
|
onClick={onPageChange ? () => onPageChange(current + 1) : undefined}
|
|
251
273
|
>
|
|
@@ -31,6 +31,7 @@ interface DatePickerProps extends Omit<React.ComponentProps<'div'>, 'defaultValu
|
|
|
31
31
|
onValueChange?: (value: string | undefined) => void;
|
|
32
32
|
min?: string;
|
|
33
33
|
max?: string;
|
|
34
|
+
/** @default `messages.datePicker.placeholder`, "Pick a date" */
|
|
34
35
|
placeholder?: React.ReactNode;
|
|
35
36
|
clearable?: boolean;
|
|
36
37
|
disabled?: boolean;
|
|
@@ -52,7 +53,7 @@ function DatePicker(allProps: DatePickerProps) {
|
|
|
52
53
|
onValueChange,
|
|
53
54
|
min,
|
|
54
55
|
max,
|
|
55
|
-
placeholder
|
|
56
|
+
placeholder,
|
|
56
57
|
clearable = true,
|
|
57
58
|
disabled,
|
|
58
59
|
invalid,
|
|
@@ -78,6 +79,7 @@ function DatePicker(allProps: DatePickerProps) {
|
|
|
78
79
|
const triggerId = id ?? generatedId;
|
|
79
80
|
const { locale } = useFormatSettings();
|
|
80
81
|
const t = useMessages('datePicker', { clear: clearLabel });
|
|
82
|
+
const placeholderText = placeholder !== undefined ? placeholder : t.placeholder;
|
|
81
83
|
const selected = parseCalendarDate(value);
|
|
82
84
|
const minDate = parseCalendarDate(min);
|
|
83
85
|
const maxDate = parseCalendarDate(max);
|
|
@@ -114,7 +116,7 @@ function DatePicker(allProps: DatePickerProps) {
|
|
|
114
116
|
data-placeholder={selected ? undefined : ''}
|
|
115
117
|
className={cn('truncate', !selected && 'text-faint-foreground')}
|
|
116
118
|
>
|
|
117
|
-
{selected ? formatDateLabel(selected, locale) :
|
|
119
|
+
{selected ? formatDateLabel(selected, locale) : placeholderText}
|
|
118
120
|
</span>
|
|
119
121
|
</PopoverTrigger>
|
|
120
122
|
<PopoverContent
|
|
@@ -42,6 +42,7 @@ interface DateRangePickerProps
|
|
|
42
42
|
/** Initial range when `value` is not passed. */
|
|
43
43
|
defaultValue?: DateRangeValue;
|
|
44
44
|
onValueChange?: (value: DateRangeValue | undefined) => void;
|
|
45
|
+
/** @default `messages.dateRangePicker.placeholder`, "Pick a date range" */
|
|
45
46
|
placeholder?: React.ReactNode;
|
|
46
47
|
clearable?: boolean;
|
|
47
48
|
disabled?: boolean;
|
|
@@ -63,7 +64,7 @@ function DateRangePicker(allProps: DateRangePickerProps) {
|
|
|
63
64
|
value: valueProp,
|
|
64
65
|
defaultValue,
|
|
65
66
|
onValueChange,
|
|
66
|
-
placeholder
|
|
67
|
+
placeholder,
|
|
67
68
|
clearable = true,
|
|
68
69
|
disabled,
|
|
69
70
|
invalid,
|
|
@@ -88,6 +89,7 @@ function DateRangePicker(allProps: DateRangePickerProps) {
|
|
|
88
89
|
const triggerId = generatedId;
|
|
89
90
|
const { locale } = useFormatSettings();
|
|
90
91
|
const t = useMessages('dateRangePicker', { clear: clearLabel });
|
|
92
|
+
const placeholderText = placeholder !== undefined ? placeholder : t.placeholder;
|
|
91
93
|
const selected: DateRange = {
|
|
92
94
|
from: parseCalendarDate(value?.from),
|
|
93
95
|
to: parseCalendarDate(value?.to),
|
|
@@ -132,7 +134,9 @@ function DateRangePicker(allProps: DateRangePickerProps) {
|
|
|
132
134
|
data-placeholder={hasValue ? undefined : ''}
|
|
133
135
|
className={cn('truncate', !hasValue && 'text-faint-foreground')}
|
|
134
136
|
>
|
|
135
|
-
{selected.from
|
|
137
|
+
{selected.from
|
|
138
|
+
? formatDateRangeLabel(selected.from, selected.to, locale)
|
|
139
|
+
: placeholderText}
|
|
136
140
|
</span>
|
|
137
141
|
</PopoverTrigger>
|
|
138
142
|
<PopoverContent
|
|
@@ -28,6 +28,7 @@ interface DateTimePickerProps
|
|
|
28
28
|
/** Initial instant when `value` is not passed. */
|
|
29
29
|
defaultValue?: string;
|
|
30
30
|
onValueChange?: (value: string | undefined) => void;
|
|
31
|
+
/** @default `messages.dateTimePicker.placeholder`, "Pick a date and time" */
|
|
31
32
|
placeholder?: React.ReactNode;
|
|
32
33
|
clearable?: boolean;
|
|
33
34
|
disabled?: boolean;
|
|
@@ -48,7 +49,7 @@ function DateTimePicker(allProps: DateTimePickerProps) {
|
|
|
48
49
|
value: valueProp,
|
|
49
50
|
defaultValue,
|
|
50
51
|
onValueChange,
|
|
51
|
-
placeholder
|
|
52
|
+
placeholder,
|
|
52
53
|
clearable = true,
|
|
53
54
|
disabled,
|
|
54
55
|
invalid,
|
|
@@ -75,6 +76,7 @@ function DateTimePicker(allProps: DateTimePickerProps) {
|
|
|
75
76
|
const triggerId = id ?? generatedId;
|
|
76
77
|
const { locale } = useFormatSettings();
|
|
77
78
|
const t = useMessages('dateTimePicker', { clear: clearLabel, time: timeLabel });
|
|
79
|
+
const placeholderText = placeholder !== undefined ? placeholder : t.placeholder;
|
|
78
80
|
const selected = parseInstant(value);
|
|
79
81
|
const timeValue = selected
|
|
80
82
|
? `${String(selected.getHours()).padStart(2, '0')}:${String(selected.getMinutes()).padStart(2, '0')}`
|
|
@@ -127,7 +129,7 @@ function DateTimePicker(allProps: DateTimePickerProps) {
|
|
|
127
129
|
data-placeholder={selected ? undefined : ''}
|
|
128
130
|
className={cn('truncate', !selected && 'text-faint-foreground')}
|
|
129
131
|
>
|
|
130
|
-
{selected ? formatDateLabel(selected, locale) :
|
|
132
|
+
{selected ? formatDateLabel(selected, locale) : placeholderText}
|
|
131
133
|
</span>
|
|
132
134
|
</PopoverTrigger>
|
|
133
135
|
<PopoverContent
|
|
@@ -60,9 +60,12 @@ interface FileDropzoneProps extends Omit<React.ComponentProps<'div'>, 'defaultVa
|
|
|
60
60
|
required?: boolean;
|
|
61
61
|
name?: string;
|
|
62
62
|
id?: string;
|
|
63
|
+
/** @default `messages.fileDropzone.label`, "Upload files" */
|
|
63
64
|
label?: React.ReactNode;
|
|
64
65
|
description?: React.ReactNode;
|
|
66
|
+
/** @default `messages.fileDropzone.empty`, "Drag and drop files here, or choose files" */
|
|
65
67
|
emptyLabel?: React.ReactNode;
|
|
68
|
+
/** @default `messages.fileDropzone.drag`, "Drop files to add them" */
|
|
66
69
|
dragLabel?: React.ReactNode;
|
|
67
70
|
renderFile?: (file: File, remove: () => void) => React.ReactNode;
|
|
68
71
|
/** The component's own texts: rejection messages, status text, remove button and size units. */
|
|
@@ -142,10 +145,10 @@ function FileDropzone(allProps: FileDropzoneProps) {
|
|
|
142
145
|
required,
|
|
143
146
|
name,
|
|
144
147
|
id: providedId,
|
|
145
|
-
label
|
|
148
|
+
label,
|
|
146
149
|
description,
|
|
147
|
-
emptyLabel
|
|
148
|
-
dragLabel
|
|
150
|
+
emptyLabel,
|
|
151
|
+
dragLabel,
|
|
149
152
|
renderFile,
|
|
150
153
|
labels,
|
|
151
154
|
className,
|
|
@@ -241,7 +244,7 @@ function FileDropzone(allProps: FileDropzoneProps) {
|
|
|
241
244
|
<div data-slot="file-dropzone" className={cn('flex flex-col gap-3', className)} {...props}>
|
|
242
245
|
<div>
|
|
243
246
|
<label htmlFor={id} className="text-sm font-medium">
|
|
244
|
-
{label}
|
|
247
|
+
{label !== undefined ? label : t.label}
|
|
245
248
|
{required ? <span className="text-destructive-text"> *</span> : null}
|
|
246
249
|
</label>
|
|
247
250
|
{description ? (
|
|
@@ -305,7 +308,15 @@ function FileDropzone(allProps: FileDropzoneProps) {
|
|
|
305
308
|
>
|
|
306
309
|
<UploadCloudIcon className="size-7" />
|
|
307
310
|
<span className="text-foreground text-sm font-medium">
|
|
308
|
-
{validating
|
|
311
|
+
{validating
|
|
312
|
+
? t.checking
|
|
313
|
+
: dragging
|
|
314
|
+
? dragLabel !== undefined
|
|
315
|
+
? dragLabel
|
|
316
|
+
: t.drag
|
|
317
|
+
: emptyLabel !== undefined
|
|
318
|
+
? emptyLabel
|
|
319
|
+
: t.empty}
|
|
309
320
|
</span>
|
|
310
321
|
{accept ? <span className="text-xs">{`${t.accepted} ${accept}`}</span> : null}
|
|
311
322
|
</label>
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
|
|
4
4
|
import { CopyButton, useCopyAction } from '@vendure-io/ui/components/molecules/copyable-text';
|
|
5
5
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
6
|
+
import { useMessages } from '../../lib/format-messages.ts';
|
|
6
7
|
import { ChipCopyTooltip, chipChromeClass, chipCopyButtonProps } from './id-chip-chrome.tsx';
|
|
7
8
|
|
|
8
9
|
type TruncateMode = 'middle' | 'start' | 'none';
|
|
@@ -58,10 +59,10 @@ interface IdChipProps {
|
|
|
58
59
|
* The tooltip text before copying, e.g. "Copy commit". Keep it short and
|
|
59
60
|
* leave the value out: the copy button's accessible name adds the shown
|
|
60
61
|
* text itself ("Copy commit 9f2c4e1"), so each button in a list has its own
|
|
61
|
-
* name. @default "Copy"
|
|
62
|
+
* name. @default `messages.idChip.copy`, "Copy"
|
|
62
63
|
*/
|
|
63
64
|
copyLabel?: string;
|
|
64
|
-
/** The tooltip text and the copy button's accessible name while the copied state is active. @default "Copied" */
|
|
65
|
+
/** The tooltip text and the copy button's accessible name while the copied state is active. @default `messages.idChip.copied`, "Copied" */
|
|
65
66
|
copiedLabel?: string;
|
|
66
67
|
/** How long the check-mark feedback stays visible, in ms. @default 2000 */
|
|
67
68
|
timeout?: number;
|
|
@@ -82,11 +83,12 @@ function IdChip({
|
|
|
82
83
|
className,
|
|
83
84
|
onCopied,
|
|
84
85
|
onCopyError,
|
|
85
|
-
copyLabel
|
|
86
|
-
copiedLabel
|
|
86
|
+
copyLabel,
|
|
87
|
+
copiedLabel,
|
|
87
88
|
timeout,
|
|
88
89
|
}: IdChipProps) {
|
|
89
90
|
const action = useCopyAction({ timeout, onCopied, onCopyError });
|
|
91
|
+
const t = useMessages('idChip', { copy: copyLabel, copied: copiedLabel });
|
|
90
92
|
const text = display ?? truncateId(value, truncate);
|
|
91
93
|
const shortened = text !== value;
|
|
92
94
|
const chip = (
|
|
@@ -103,8 +105,8 @@ function IdChip({
|
|
|
103
105
|
<CopyButton
|
|
104
106
|
value={value}
|
|
105
107
|
copyAction={action}
|
|
106
|
-
copyLabel={`${
|
|
107
|
-
copiedLabel={
|
|
108
|
+
copyLabel={`${t.copy} ${text}`}
|
|
109
|
+
copiedLabel={t.copied}
|
|
108
110
|
{...chipCopyButtonProps}
|
|
109
111
|
/>
|
|
110
112
|
) : null}
|
|
@@ -118,8 +120,8 @@ function IdChip({
|
|
|
118
120
|
<ChipCopyTooltip
|
|
119
121
|
chip={chip}
|
|
120
122
|
copied={action.copied}
|
|
121
|
-
copyLabel={
|
|
122
|
-
copiedLabel={
|
|
123
|
+
copyLabel={t.copy}
|
|
124
|
+
copiedLabel={t.copied}
|
|
123
125
|
/>
|
|
124
126
|
);
|
|
125
127
|
}
|
|
@@ -9,6 +9,7 @@ import { CopyStateIcon, useCopyAction } from '@vendure-io/ui/components/molecule
|
|
|
9
9
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
10
10
|
import type * as React from 'react';
|
|
11
11
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
12
|
+
import { fillMessage, useMessages } from '../../lib/format-messages.ts';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* The close guard of a dialog that holds a secret that was just issued. Before
|
|
@@ -61,21 +62,21 @@ interface IssuedSecretOwnProps {
|
|
|
61
62
|
name?: React.ReactNode;
|
|
62
63
|
/** Values of the issue that are not secret, for example a sign-in name. */
|
|
63
64
|
children?: React.ReactNode;
|
|
64
|
-
/** Text of the copy button when there is one value. @default `Copy
|
|
65
|
+
/** Text of the copy button when there is one value. @default `messages.issuedSecret.copy`, "Copy {secret}", with `{secret}` the `secretName` */
|
|
65
66
|
copyLabel?: string;
|
|
66
|
-
/** Text of a copy button just after a copy. @default "Copied" */
|
|
67
|
+
/** Text of a copy button just after a copy. @default `messages.issuedSecret.copied`, "Copied" */
|
|
67
68
|
copiedLabel?: string;
|
|
68
|
-
/** The line under the buttons. @default `You can copy the
|
|
69
|
+
/** The line under the buttons. @default `messages.issuedSecret.notice`, "You can copy the {secret} only now." */
|
|
69
70
|
notice?: React.ReactNode;
|
|
70
71
|
/** Label of the field that shows the value when the clipboard fails. @default secretName, capitalised */
|
|
71
72
|
fallbackLabel?: string;
|
|
72
|
-
/** @default `The clipboard is not available. Select the
|
|
73
|
+
/** @default `messages.issuedSecret.fallbackDescription`, "The clipboard is not available. Select the {secret} and copy it by hand." */
|
|
73
74
|
fallbackDescription?: React.ReactNode;
|
|
74
75
|
/** Classes for that field, for example a session replay mask class. */
|
|
75
76
|
fallbackInputClassName?: string;
|
|
76
|
-
/** @default `The
|
|
77
|
+
/** @default `messages.issuedSecret.warningTitle`, "The {secret} is not copied" */
|
|
77
78
|
warningTitle?: React.ReactNode;
|
|
78
|
-
/** @default "You cannot copy it after you close. Copy it now, or close without copying." */
|
|
79
|
+
/** @default `messages.issuedSecret.warningDescription`, "You cannot copy it after you close. Copy it now, or close without copying." */
|
|
79
80
|
warningDescription?: React.ReactNode;
|
|
80
81
|
/** Called after a copy by a button. Falls back to `CopyFeedbackProvider`. */
|
|
81
82
|
onCopied?: () => void;
|
|
@@ -112,25 +113,27 @@ function IssuedSecret({
|
|
|
112
113
|
children,
|
|
113
114
|
value,
|
|
114
115
|
formats,
|
|
115
|
-
copyLabel
|
|
116
|
-
copiedLabel
|
|
117
|
-
notice
|
|
116
|
+
copyLabel,
|
|
117
|
+
copiedLabel,
|
|
118
|
+
notice,
|
|
118
119
|
fallbackLabel = capitalize(secretName),
|
|
119
|
-
fallbackDescription
|
|
120
|
+
fallbackDescription,
|
|
120
121
|
fallbackInputClassName,
|
|
121
|
-
warningTitle
|
|
122
|
-
warningDescription
|
|
122
|
+
warningTitle,
|
|
123
|
+
warningDescription,
|
|
123
124
|
onCopied,
|
|
124
125
|
onCopyError,
|
|
125
126
|
className,
|
|
126
127
|
...props
|
|
127
128
|
}: IssuedSecretProps) {
|
|
129
|
+
const t = useMessages('issuedSecret', { copy: copyLabel, copied: copiedLabel });
|
|
130
|
+
const named = (text: string) => fillMessage(text, { secret: secretName });
|
|
128
131
|
// The text of the copy the clipboard refused. It contains the secret.
|
|
129
132
|
const [manual, setManual] = useState<string | null>(null);
|
|
130
133
|
const firstButton = useRef<HTMLButtonElement>(null);
|
|
131
134
|
const field = useRef<HTMLInputElement>(null);
|
|
132
135
|
const fieldId = useId();
|
|
133
|
-
const buttons = formats ?? [{ label:
|
|
136
|
+
const buttons = formats ?? [{ label: named(t.copy), value: value ?? '' }];
|
|
134
137
|
|
|
135
138
|
useEffect(() => {
|
|
136
139
|
firstButton.current?.focus();
|
|
@@ -172,7 +175,7 @@ function IssuedSecret({
|
|
|
172
175
|
key={format.label}
|
|
173
176
|
ref={index === 0 ? firstButton : undefined}
|
|
174
177
|
format={format}
|
|
175
|
-
copiedLabel={
|
|
178
|
+
copiedLabel={t.copied}
|
|
176
179
|
// One primary until the first copy; then Done takes it.
|
|
177
180
|
variant={index === 0 && !guard.copied ? 'default' : 'outline'}
|
|
178
181
|
onCopied={() => {
|
|
@@ -185,7 +188,7 @@ function IssuedSecret({
|
|
|
185
188
|
/>
|
|
186
189
|
))}
|
|
187
190
|
<p data-slot="issued-secret-notice" className="text-muted-foreground text-xs">
|
|
188
|
-
{notice}
|
|
191
|
+
{notice !== undefined ? notice : named(t.notice)}
|
|
189
192
|
</p>
|
|
190
193
|
</div>
|
|
191
194
|
{manual !== null ? (
|
|
@@ -202,13 +205,19 @@ function IssuedSecret({
|
|
|
202
205
|
onFocus={(event) => event.currentTarget.select()}
|
|
203
206
|
onCopy={guard.markCopied}
|
|
204
207
|
/>
|
|
205
|
-
<FieldDescription>
|
|
208
|
+
<FieldDescription>
|
|
209
|
+
{fallbackDescription !== undefined ? fallbackDescription : named(t.fallbackDescription)}
|
|
210
|
+
</FieldDescription>
|
|
206
211
|
</Field>
|
|
207
212
|
) : null}
|
|
208
213
|
{guard.warned ? (
|
|
209
214
|
<Alert data-slot="issued-secret-warning" tone="warning">
|
|
210
|
-
<AlertTitle>
|
|
211
|
-
|
|
215
|
+
<AlertTitle>
|
|
216
|
+
{warningTitle !== undefined ? warningTitle : named(t.warningTitle)}
|
|
217
|
+
</AlertTitle>
|
|
218
|
+
<AlertDescription>
|
|
219
|
+
{warningDescription !== undefined ? warningDescription : t.warningDescription}
|
|
220
|
+
</AlertDescription>
|
|
212
221
|
</Alert>
|
|
213
222
|
) : null}
|
|
214
223
|
</section>
|
|
@@ -266,9 +275,9 @@ interface IssuedSecretFooterProps
|
|
|
266
275
|
extends Omit<React.ComponentProps<typeof DialogFooter>, 'children'> {
|
|
267
276
|
/** The guard from `useIssuedSecretGuard`, shared with `IssuedSecret`. */
|
|
268
277
|
guard: IssuedSecretGuard;
|
|
269
|
-
/** @default "Done" */
|
|
278
|
+
/** @default `messages.issuedSecret.done`, "Done" */
|
|
270
279
|
doneLabel?: string;
|
|
271
|
-
/** The second action after the warning. @default "Close without copying" */
|
|
280
|
+
/** The second action after the warning. @default `messages.issuedSecret.closeAnyway`, "Close without copying" */
|
|
272
281
|
closeAnywayLabel?: string;
|
|
273
282
|
}
|
|
274
283
|
|
|
@@ -279,10 +288,11 @@ interface IssuedSecretFooterProps
|
|
|
279
288
|
*/
|
|
280
289
|
function IssuedSecretFooter({
|
|
281
290
|
guard,
|
|
282
|
-
doneLabel
|
|
283
|
-
closeAnywayLabel
|
|
291
|
+
doneLabel,
|
|
292
|
+
closeAnywayLabel,
|
|
284
293
|
...props
|
|
285
294
|
}: IssuedSecretFooterProps) {
|
|
295
|
+
const t = useMessages('issuedSecret', { done: doneLabel, closeAnyway: closeAnywayLabel });
|
|
286
296
|
return (
|
|
287
297
|
<DialogFooter data-slot="issued-secret-footer" {...props}>
|
|
288
298
|
{guard.warned ? (
|
|
@@ -293,7 +303,7 @@ function IssuedSecretFooter({
|
|
|
293
303
|
variant="destructive-outline"
|
|
294
304
|
onClick={guard.closeAnyway}
|
|
295
305
|
>
|
|
296
|
-
{
|
|
306
|
+
{t.closeAnyway}
|
|
297
307
|
</Button>
|
|
298
308
|
) : (
|
|
299
309
|
<Button
|
|
@@ -303,7 +313,7 @@ function IssuedSecretFooter({
|
|
|
303
313
|
variant={guard.copied ? 'default' : 'outline'}
|
|
304
314
|
onClick={guard.requestClose}
|
|
305
315
|
>
|
|
306
|
-
{
|
|
316
|
+
{t.done}
|
|
307
317
|
</Button>
|
|
308
318
|
)}
|
|
309
319
|
</DialogFooter>
|