@vendure-io/ui 3.0.0-next.5 → 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 +1 -1
- package/src/components/atoms/breadcrumb.tsx +31 -11
- package/src/components/atoms/carousel.tsx +33 -7
- package/src/components/atoms/combobox.tsx +23 -10
- 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/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 +6 -2
- 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/lib/format-messages.ts +176 -0
|
@@ -10,6 +10,7 @@ import { cn } from '@vendure-io/ui/lib/utils';
|
|
|
10
10
|
import { ChevronDown, X } from 'lucide-react';
|
|
11
11
|
import { AnimatePresence, LayoutGroup, motion, useIsPresent, useReducedMotion } from 'motion/react';
|
|
12
12
|
import * as React from 'react';
|
|
13
|
+
import { fillMessage, useMessages } from '../../../lib/format-messages.ts';
|
|
13
14
|
|
|
14
15
|
// What was taken from Stealth UI's Checklist: the two lists (open steps, then
|
|
15
16
|
// a "Completed" group) joined by a shared `layoutId`, so a finished step flies
|
|
@@ -166,22 +167,40 @@ type ChecklistProps = Omit<React.ComponentProps<'div'>, 'title' | 'children'> &
|
|
|
166
167
|
* hide itself: remove it in this callback.
|
|
167
168
|
*/
|
|
168
169
|
onDismiss?: () => void;
|
|
169
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Accessible name of the dismiss button.
|
|
172
|
+
* @default `messages.checklist.dismiss`, "Dismiss checklist"
|
|
173
|
+
*/
|
|
170
174
|
dismissLabel?: string;
|
|
171
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Label of the group of finished steps.
|
|
177
|
+
* @default `messages.checklist.completed`, "Completed"
|
|
178
|
+
*/
|
|
172
179
|
completedLabel?: string;
|
|
173
180
|
/** Whether the Completed group is open (controlled). */
|
|
174
181
|
completedOpen?: boolean;
|
|
175
182
|
/** Whether the Completed group starts open. Default `true`. */
|
|
176
183
|
defaultCompletedOpen?: boolean;
|
|
177
184
|
onCompletedOpenChange?: (open: boolean) => void;
|
|
178
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* What a screen reader hears after a done step's label in system mode.
|
|
187
|
+
* @default `messages.checklist.stepDone`, "done"
|
|
188
|
+
*/
|
|
179
189
|
stepDoneLabel?: string;
|
|
180
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* What a screen reader hears after an open step's label in system mode.
|
|
192
|
+
* @default `messages.checklist.stepOpen`, "not done"
|
|
193
|
+
*/
|
|
181
194
|
stepOpenLabel?: string;
|
|
182
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* The count beside the title.
|
|
197
|
+
* @default `messages.checklist.count`, "{done} of {total}"
|
|
198
|
+
*/
|
|
183
199
|
formatCount?: (done: number, total: number) => string;
|
|
184
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* What a screen reader hears when the count changes.
|
|
202
|
+
* @default `messages.checklist.announcement`, "{done} of {total} steps done"
|
|
203
|
+
*/
|
|
185
204
|
formatAnnouncement?: (done: number, total: number) => string;
|
|
186
205
|
/** The steps: ChecklistStep elements, as direct children (fragments and arrays are fine). */
|
|
187
206
|
children?: React.ReactNode;
|
|
@@ -219,19 +238,30 @@ function Checklist({
|
|
|
219
238
|
mode = 'system',
|
|
220
239
|
onStepCheckedChange,
|
|
221
240
|
onDismiss,
|
|
222
|
-
dismissLabel
|
|
223
|
-
completedLabel
|
|
224
|
-
stepDoneLabel
|
|
225
|
-
stepOpenLabel
|
|
241
|
+
dismissLabel,
|
|
242
|
+
completedLabel,
|
|
243
|
+
stepDoneLabel,
|
|
244
|
+
stepOpenLabel,
|
|
226
245
|
completedOpen: completedOpenProp,
|
|
227
246
|
defaultCompletedOpen = true,
|
|
228
247
|
onCompletedOpenChange,
|
|
229
|
-
formatCount
|
|
230
|
-
formatAnnouncement
|
|
248
|
+
formatCount: formatCountProp,
|
|
249
|
+
formatAnnouncement: formatAnnouncementProp,
|
|
231
250
|
className,
|
|
232
251
|
children,
|
|
233
252
|
...props
|
|
234
253
|
}: ChecklistProps) {
|
|
254
|
+
const t = useMessages('checklist', {
|
|
255
|
+
dismiss: dismissLabel,
|
|
256
|
+
completed: completedLabel,
|
|
257
|
+
stepDone: stepDoneLabel,
|
|
258
|
+
stepOpen: stepOpenLabel,
|
|
259
|
+
});
|
|
260
|
+
const formatCount =
|
|
261
|
+
formatCountProp ?? ((done: number, total: number) => fillMessage(t.count, { done, total }));
|
|
262
|
+
const formatAnnouncement =
|
|
263
|
+
formatAnnouncementProp ??
|
|
264
|
+
((done: number, total: number) => fillMessage(t.announcement, { done, total }));
|
|
235
265
|
const reduce = useReducedMotion() ?? false;
|
|
236
266
|
const groupId = React.useId();
|
|
237
267
|
const titleId = React.useId();
|
|
@@ -303,8 +333,8 @@ function Checklist({
|
|
|
303
333
|
isDone: (id) => doneById.get(id) ?? false,
|
|
304
334
|
isKnown: (id) => knownBefore.has(id),
|
|
305
335
|
justDone: (id) => knownBefore.get(id) === false && doneById.get(id) === true,
|
|
306
|
-
doneLabel:
|
|
307
|
-
openLabel:
|
|
336
|
+
doneLabel: t.stepDone,
|
|
337
|
+
openLabel: t.stepOpen,
|
|
308
338
|
toggle: (id, checked, input) => {
|
|
309
339
|
const from = checklistSection(!checked, holdsRef.current[id]);
|
|
310
340
|
setToggled((prev) => ({ ...prev, [id]: checked }));
|
|
@@ -405,7 +435,7 @@ function Checklist({
|
|
|
405
435
|
data-slot="checklist-dismiss"
|
|
406
436
|
variant="ghost"
|
|
407
437
|
size="icon-sm"
|
|
408
|
-
aria-label={
|
|
438
|
+
aria-label={t.dismiss}
|
|
409
439
|
onClick={onDismiss}
|
|
410
440
|
className="-me-1.5"
|
|
411
441
|
>
|
|
@@ -461,7 +491,7 @@ function Checklist({
|
|
|
461
491
|
onClick={() => setCompletedOpen(!completedOpen)}
|
|
462
492
|
className="group/checklist-completed text-foreground-secondary flex min-h-11 w-full cursor-pointer items-center gap-2 ps-(--card-ps) pe-(--card-px) text-start text-sm font-medium outline-none [transition:color_var(--transition-duration-fast)_var(--ease-default),background-color_var(--transition-duration-fast)_var(--ease-default),opacity_var(--transition-duration-moderate)_var(--ease-soft)] data-arrived:starting:opacity-0 hover:bg-muted focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
|
|
463
493
|
>
|
|
464
|
-
{
|
|
494
|
+
{t.completed}
|
|
465
495
|
<CardCount className="ms-0">{finished.length}</CardCount>
|
|
466
496
|
<ChevronDown
|
|
467
497
|
aria-hidden="true"
|
|
@@ -476,7 +506,7 @@ function Checklist({
|
|
|
476
506
|
<ul
|
|
477
507
|
id={completedId}
|
|
478
508
|
data-slot="checklist-completed-steps"
|
|
479
|
-
aria-label={
|
|
509
|
+
aria-label={t.completed}
|
|
480
510
|
className="relative flex flex-col"
|
|
481
511
|
>
|
|
482
512
|
<AnimatePresence initial={false} mode="popLayout">
|
|
@@ -164,7 +164,9 @@ function SelectedEdge({ edgeId, input }: { edgeId: string; input: ChoiceCardInpu
|
|
|
164
164
|
data-slot="choice-card-edge"
|
|
165
165
|
className="pointer-events-none absolute -inset-px z-10 rounded-[inherit]"
|
|
166
166
|
style={{
|
|
167
|
+
// biome-ignore lint/plugin/no-raw-shadow: the moving edge draws the same inset ring as the checked card
|
|
167
168
|
boxShadow: 'inset 0 0 0 2px var(--primary)',
|
|
169
|
+
// biome-ignore lint/plugin/no-raw-radius: motion measures the radius for the layout animation
|
|
168
170
|
...(radius !== undefined ? { borderRadius: radius } : null),
|
|
169
171
|
}}
|
|
170
172
|
initial={jump && input !== null ? { opacity: 0 } : false}
|
|
@@ -210,6 +212,7 @@ const choiceCardVariants = cva(
|
|
|
210
212
|
// (inset-0) its corners would take the outer radius and leave a gap
|
|
211
213
|
// between two strokes. So the card never clips its children: the media
|
|
212
214
|
// variant rounds the image itself to the padding box instead.
|
|
215
|
+
// biome-ignore lint/plugin/no-raw-shadow: the checked ring is an inset shadow on the card edge
|
|
213
216
|
'after:pointer-events-none after:absolute after:-inset-px after:z-10 after:rounded-[inherit] after:[transition:box-shadow_var(--transition-duration-fast)_var(--ease-soft)] data-[mode=multiple]:data-checked:border-primary data-[mode=multiple]:data-checked:hover:border-primary data-[mode=multiple]:data-checked:after:shadow-[inset_0_0_0_2px_var(--primary)]',
|
|
214
217
|
],
|
|
215
218
|
{
|
|
@@ -66,7 +66,9 @@ interface ConfirmDialogProps {
|
|
|
66
66
|
* A rejection leaves the dialog open so the user can retry.
|
|
67
67
|
*/
|
|
68
68
|
onConfirm: () => void | Promise<void>;
|
|
69
|
+
/** @default `messages.confirmDialog.confirm`, "Confirm" */
|
|
69
70
|
confirmLabel?: ReactNode;
|
|
71
|
+
/** @default `messages.confirmDialog.cancel`, "Cancel" */
|
|
70
72
|
cancelLabel?: ReactNode;
|
|
71
73
|
/**
|
|
72
74
|
* Screen-reader text of the spinner while `onConfirm` runs.
|
|
@@ -118,8 +120,8 @@ function ConfirmDialog({
|
|
|
118
120
|
description,
|
|
119
121
|
body,
|
|
120
122
|
onConfirm,
|
|
121
|
-
confirmLabel
|
|
122
|
-
cancelLabel
|
|
123
|
+
confirmLabel,
|
|
124
|
+
cancelLabel,
|
|
123
125
|
loadingLabel,
|
|
124
126
|
variant = 'default',
|
|
125
127
|
confirmDisabled = false,
|
|
@@ -222,7 +224,7 @@ function ConfirmDialog({
|
|
|
222
224
|
</p>
|
|
223
225
|
) : null}
|
|
224
226
|
<AlertDialogCancel ref={cancelRef} disabled={pending} className={focusRing}>
|
|
225
|
-
{cancelLabel}
|
|
227
|
+
{cancelLabel !== undefined ? cancelLabel : t.cancel}
|
|
226
228
|
</AlertDialogCancel>
|
|
227
229
|
{/* AlertDialogAction is a plain Button (not a Close), so closing stays
|
|
228
230
|
under our control — the promise decides when the dialog leaves. */}
|
|
@@ -238,7 +240,7 @@ function ConfirmDialog({
|
|
|
238
240
|
className={cn('relative', focusRing)}
|
|
239
241
|
>
|
|
240
242
|
<span data-slot="confirm-dialog-label" className={cn(pending && 'opacity-0')}>
|
|
241
|
-
{confirmLabel}
|
|
243
|
+
{confirmLabel !== undefined ? confirmLabel : t.confirm}
|
|
242
244
|
</span>
|
|
243
245
|
{pending ? (
|
|
244
246
|
<Spinner aria-label={t.loading} className="absolute inset-0 m-auto" />
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
13
13
|
import { ChevronLeftIcon, ListFilterIcon } from 'lucide-react';
|
|
14
14
|
import * as React from 'react';
|
|
15
|
-
import { useMessages } from '../../../lib/format-messages.ts';
|
|
15
|
+
import { fillMessage, useMessages } from '../../../lib/format-messages.ts';
|
|
16
16
|
|
|
17
17
|
// The two filter surfaces. `DataTableAddFilter` is the core-owned column picker
|
|
18
18
|
// + value editor (rendered only when `filters.columns` is declared).
|
|
@@ -53,6 +53,10 @@ function DefaultFilterInput<TData>({
|
|
|
53
53
|
interface DataTableAddFilterProps<TData> {
|
|
54
54
|
table: Table<TData>;
|
|
55
55
|
columns: DataTableFilterColumn<TData>[];
|
|
56
|
+
/**
|
|
57
|
+
* The trigger's text.
|
|
58
|
+
* @default `messages.dataTable.addFilter`, "Add filter"
|
|
59
|
+
*/
|
|
56
60
|
label?: string;
|
|
57
61
|
/**
|
|
58
62
|
* Placeholder and accessible name of the default value input.
|
|
@@ -64,10 +68,10 @@ interface DataTableAddFilterProps<TData> {
|
|
|
64
68
|
function DataTableAddFilter<TData>({
|
|
65
69
|
table,
|
|
66
70
|
columns,
|
|
67
|
-
label
|
|
71
|
+
label,
|
|
68
72
|
valueLabel,
|
|
69
73
|
}: DataTableAddFilterProps<TData>) {
|
|
70
|
-
const t = useMessages('dataTable', { filterValue: valueLabel });
|
|
74
|
+
const t = useMessages('dataTable', { filterValue: valueLabel, addFilter: label });
|
|
71
75
|
const [open, setOpen] = React.useState(false);
|
|
72
76
|
const [activeId, setActiveId] = React.useState<string | null>(null);
|
|
73
77
|
const active = columns.find((column) => column.id === activeId) ?? null;
|
|
@@ -86,11 +90,11 @@ function DataTableAddFilter<TData>({
|
|
|
86
90
|
render={
|
|
87
91
|
<Button variant="outline">
|
|
88
92
|
<ListFilterIcon />
|
|
89
|
-
{
|
|
93
|
+
{t.addFilter}
|
|
90
94
|
</Button>
|
|
91
95
|
}
|
|
92
96
|
/>
|
|
93
|
-
<PopoverContent align="start" className="w-64 gap-2 p-2" aria-label={
|
|
97
|
+
<PopoverContent align="start" className="w-64 gap-2 p-2" aria-label={t.addFilter}>
|
|
94
98
|
{active ? (
|
|
95
99
|
<div className="flex flex-col gap-2">
|
|
96
100
|
<button
|
|
@@ -196,7 +200,15 @@ interface DataTableAppliedFiltersProps<TData> {
|
|
|
196
200
|
table: Table<TData>;
|
|
197
201
|
columns?: DataTableFilterColumn<TData>[];
|
|
198
202
|
inlineChipLimit?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Accessible name of a chip's remove button.
|
|
205
|
+
* @default `messages.dataTable.removeFilter`, "Remove {column} filter"
|
|
206
|
+
*/
|
|
199
207
|
removeLabel?: (columnLabel: string) => string;
|
|
208
|
+
/**
|
|
209
|
+
* The chip that holds the filters past `inlineChipLimit`.
|
|
210
|
+
* @default `messages.dataTable.filtersCollapsed`, "{count} filters"
|
|
211
|
+
*/
|
|
200
212
|
collapsedLabel?: (count: number) => string;
|
|
201
213
|
}
|
|
202
214
|
|
|
@@ -204,9 +216,15 @@ function DataTableAppliedFilters<TData>({
|
|
|
204
216
|
table,
|
|
205
217
|
columns,
|
|
206
218
|
inlineChipLimit = Number.POSITIVE_INFINITY,
|
|
207
|
-
removeLabel
|
|
208
|
-
collapsedLabel
|
|
219
|
+
removeLabel: removeLabelProp,
|
|
220
|
+
collapsedLabel: collapsedLabelProp,
|
|
209
221
|
}: DataTableAppliedFiltersProps<TData>) {
|
|
222
|
+
const t = useMessages('dataTable');
|
|
223
|
+
const removeLabel =
|
|
224
|
+
removeLabelProp ??
|
|
225
|
+
((columnLabel: string) => fillMessage(t.removeFilter, { column: columnLabel }));
|
|
226
|
+
const collapsedLabel =
|
|
227
|
+
collapsedLabelProp ?? ((count: number) => fillMessage(t.filtersCollapsed, { count }));
|
|
210
228
|
const applied = table.getState().columnFilters;
|
|
211
229
|
if (applied.length === 0) return null;
|
|
212
230
|
|
|
@@ -315,28 +315,45 @@ export interface DataTableRowSelectProps {
|
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
export interface DataTableLabels {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
318
|
+
/** @default `messages.dataTable.empty`, "No results" */
|
|
319
|
+
empty?: string;
|
|
320
|
+
/** @default `messages.dataTable.selectAllRows`, "Select all rows" */
|
|
321
|
+
selectAllRows?: string;
|
|
322
|
+
/**
|
|
323
|
+
* Tooltip on the header checkbox while not every row on the page is selected.
|
|
324
|
+
* @default `messages.dataTable.selectAllOnPage`, "Select all on this page"
|
|
325
|
+
*/
|
|
326
|
+
selectAllOnPage?: string;
|
|
327
|
+
/**
|
|
328
|
+
* Tooltip on the header checkbox while every row on the page is selected.
|
|
329
|
+
* @default `messages.dataTable.clearPageSelection`, "Clear selection on this page"
|
|
330
|
+
*/
|
|
331
|
+
clearPageSelection?: string;
|
|
332
|
+
/** @default `messages.dataTable.selectRow`, "Select row {row}", with `{row}` the 1-based row number */
|
|
333
|
+
selectRow?: (index: number) => string;
|
|
334
|
+
/** @default `messages.dataTable.rowActions`, "Open row actions" */
|
|
335
|
+
rowActions?: string;
|
|
336
|
+
/** @default `messages.dataTable.columnsTrigger`, "Columns" */
|
|
337
|
+
columnsTrigger?: string;
|
|
338
|
+
/** @default `messages.dataTable.columnsHeading`, "Toggle columns" */
|
|
339
|
+
columnsHeading?: string;
|
|
340
|
+
/** @default `messages.dataTable.addFilter`, "Add filter" */
|
|
341
|
+
addFilter?: string;
|
|
329
342
|
/**
|
|
330
343
|
* Placeholder and accessible name of the filter editor's default value input.
|
|
331
344
|
* @default `messages.dataTable.filterValue`, "Value"
|
|
332
345
|
*/
|
|
333
346
|
filterValue?: string;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
347
|
+
/** @default `messages.dataTable.clearFilters`, "Clear filters" */
|
|
348
|
+
clearFilters?: string;
|
|
349
|
+
/** @default `messages.dataTable.removeFilter`, "Remove {column} filter" */
|
|
350
|
+
removeFilter?: (columnLabel: string) => string;
|
|
351
|
+
/** @default `messages.dataTable.sortLabel`, "Sort by {column}" */
|
|
352
|
+
sortLabel?: (columnLabel: string) => string;
|
|
353
|
+
/** @default `messages.dataTable.filtersCollapsed`, "{count} filters" */
|
|
354
|
+
filtersCollapsed?: (count: number) => string;
|
|
338
355
|
pagination?: {
|
|
339
|
-
//
|
|
356
|
+
// Forwarded to TablePagination, which resolves them against `messages.tablePagination`.
|
|
340
357
|
navLabel?: string;
|
|
341
358
|
previousLabel?: string;
|
|
342
359
|
nextLabel?: string;
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '@vendure-io/ui/components/atoms/dropdown-menu';
|
|
14
14
|
import { SlidersHorizontalIcon } from 'lucide-react';
|
|
15
15
|
// Relative: `data-table-helpers` is closed in the package exports.
|
|
16
|
+
import { useMessages } from '../../../lib/format-messages.ts';
|
|
16
17
|
import { getHideableLeafColumns } from './data-table-helpers.tsx';
|
|
17
18
|
|
|
18
19
|
// The column picker ("Columns" trigger). Lists only hideable columns (`getCanHide()`), so
|
|
@@ -22,7 +23,15 @@ import { getHideableLeafColumns } from './data-table-helpers.tsx';
|
|
|
22
23
|
|
|
23
24
|
interface DataTableViewOptionsProps<TData> {
|
|
24
25
|
table: Table<TData>;
|
|
26
|
+
/**
|
|
27
|
+
* The trigger's text.
|
|
28
|
+
* @default `messages.dataTable.columnsTrigger`, "Columns"
|
|
29
|
+
*/
|
|
25
30
|
triggerLabel?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The menu's heading.
|
|
33
|
+
* @default `messages.dataTable.columnsHeading`, "Toggle columns"
|
|
34
|
+
*/
|
|
26
35
|
heading?: string;
|
|
27
36
|
}
|
|
28
37
|
|
|
@@ -33,9 +42,10 @@ function columnLabel<TData>(column: Column<TData, unknown>): string {
|
|
|
33
42
|
|
|
34
43
|
function DataTableViewOptions<TData>({
|
|
35
44
|
table,
|
|
36
|
-
triggerLabel
|
|
37
|
-
heading
|
|
45
|
+
triggerLabel,
|
|
46
|
+
heading,
|
|
38
47
|
}: DataTableViewOptionsProps<TData>) {
|
|
48
|
+
const t = useMessages('dataTable', { columnsTrigger: triggerLabel, columnsHeading: heading });
|
|
39
49
|
const hideableColumns = getHideableLeafColumns(table);
|
|
40
50
|
|
|
41
51
|
return (
|
|
@@ -48,7 +58,7 @@ function DataTableViewOptions<TData>({
|
|
|
48
58
|
render={
|
|
49
59
|
<Button variant="outline">
|
|
50
60
|
<SlidersHorizontalIcon />
|
|
51
|
-
{
|
|
61
|
+
{t.columnsTrigger}
|
|
52
62
|
</Button>
|
|
53
63
|
}
|
|
54
64
|
/>
|
|
@@ -56,7 +66,7 @@ function DataTableViewOptions<TData>({
|
|
|
56
66
|
{/* Base UI ties `GroupLabel` to a `Group` via context: the heading names
|
|
57
67
|
the toggle group and errors if rendered outside one. */}
|
|
58
68
|
<DropdownMenuGroup>
|
|
59
|
-
<DropdownMenuLabel>{
|
|
69
|
+
<DropdownMenuLabel>{t.columnsHeading}</DropdownMenuLabel>
|
|
60
70
|
<DropdownMenuSeparator />
|
|
61
71
|
{hideableColumns.map((column) => (
|
|
62
72
|
<DropdownMenuCheckboxItem
|
|
@@ -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
|
>
|