@vendure-io/ui 2.0.0-beta.2 → 2.0.0-beta.20
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/LICENSE.md +34 -0
- package/README.md +6 -3
- package/package.json +10 -9
- package/src/components/atoms/button.tsx +5 -1
- package/src/components/atoms/card.tsx +39 -4
- package/src/components/atoms/combobox.tsx +19 -4
- package/src/components/atoms/scroll-area.tsx +4 -2
- package/src/components/atoms/sidebar.tsx +27 -12
- package/src/components/atoms/table.tsx +1 -1
- package/src/components/atoms/tabs.tsx +64 -1
- package/src/components/atoms/toggle-group.tsx +1 -1
- package/src/components/atoms/toggle.tsx +5 -2
- package/src/components/molecules/anonymized-token.tsx +2 -2
- package/src/components/molecules/app-shell.tsx +110 -0
- package/src/components/molecules/code-block/file-type-icons.tsx +123 -0
- package/src/components/molecules/code-block/transform-command.tsx +177 -0
- package/src/components/molecules/code-block.tsx +634 -0
- package/src/components/molecules/combobox-free-text.tsx +18 -0
- package/src/components/molecules/copy-feedback-provider.tsx +33 -0
- package/src/components/molecules/copyable-text.tsx +30 -7
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +10 -9
- package/src/components/molecules/data-table/data-table-types.tsx +50 -2
- package/src/components/molecules/data-table/data-table.tsx +184 -91
- package/src/components/molecules/date-picker.tsx +119 -0
- package/src/components/molecules/date-range-picker.tsx +153 -0
- package/src/components/molecules/date-time-picker.tsx +133 -0
- package/src/components/molecules/file-dropzone.tsx +271 -0
- package/src/components/molecules/id-chip.tsx +1 -1
- package/src/components/molecules/page-header.tsx +7 -3
- package/src/components/molecules/skip-link.tsx +36 -0
- package/src/components/molecules/state-views/empty-state.tsx +12 -1
- package/src/components/molecules/state-views/loading-state.tsx +7 -3
- package/src/lib/date-value.ts +48 -0
- package/src/lib/highlight.ts +174 -0
- package/src/lib/utils.ts +0 -19
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { Button } from '@vendure-io/ui/components/atoms/button';
|
|
4
|
+
import { useCopyFeedback } from '@vendure-io/ui/components/molecules/copy-feedback-provider';
|
|
4
5
|
import { useCopy } from '@vendure-io/ui/hooks/use-copy';
|
|
5
6
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
6
7
|
import { CheckIcon, CopyIcon } from 'lucide-react';
|
|
@@ -11,9 +12,16 @@ interface CopyButtonProps extends Omit<React.ComponentProps<typeof Button>, 'val
|
|
|
11
12
|
value: string;
|
|
12
13
|
/** How long the check-mark feedback stays visible, in ms. @default 2000 */
|
|
13
14
|
timeout?: number;
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Called after a successful copy. Wire your toast here — the DS never toasts.
|
|
17
|
+
* Falls back to `CopyFeedbackProvider` when omitted (the RSC-safe path, since
|
|
18
|
+
* function props can't be passed from server components).
|
|
19
|
+
*/
|
|
15
20
|
onCopied?: () => void;
|
|
16
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Called when the clipboard write fails (e.g. permissions, insecure context).
|
|
23
|
+
* Falls back to `CopyFeedbackProvider` when omitted.
|
|
24
|
+
*/
|
|
17
25
|
onCopyError?: (error: Error) => void;
|
|
18
26
|
/** Accessible label before copying. @default "Copy" */
|
|
19
27
|
copyLabel?: string;
|
|
@@ -40,6 +48,7 @@ function CopyButton({
|
|
|
40
48
|
...props
|
|
41
49
|
}: CopyButtonProps) {
|
|
42
50
|
const { copied, copy } = useCopy({ timeout });
|
|
51
|
+
const copyFeedback = useCopyFeedback();
|
|
43
52
|
|
|
44
53
|
return (
|
|
45
54
|
<Button
|
|
@@ -53,8 +62,9 @@ function CopyButton({
|
|
|
53
62
|
onClick?.(event);
|
|
54
63
|
if (event.defaultPrevented) return;
|
|
55
64
|
const ok = await copy(value);
|
|
56
|
-
if (ok) onCopied?.();
|
|
57
|
-
else
|
|
65
|
+
if (ok) (onCopied ?? copyFeedback.onCopied)?.();
|
|
66
|
+
else
|
|
67
|
+
(onCopyError ?? copyFeedback.onCopyError)?.(new Error('Failed to copy to the clipboard'));
|
|
58
68
|
}}
|
|
59
69
|
{...props}
|
|
60
70
|
>
|
|
@@ -71,10 +81,14 @@ interface CopyableTextProps {
|
|
|
71
81
|
className?: string;
|
|
72
82
|
/** How long the check-mark feedback stays visible, in ms. @default 2000 */
|
|
73
83
|
timeout?: number;
|
|
74
|
-
/** Called after a successful copy. Wire your toast here — the DS never toasts. */
|
|
84
|
+
/** Called after a successful copy. Wire your toast here — the DS never toasts. Falls back to `CopyFeedbackProvider`. */
|
|
75
85
|
onCopied?: () => void;
|
|
76
|
-
/** Called when the clipboard write fails. */
|
|
86
|
+
/** Called when the clipboard write fails. Falls back to `CopyFeedbackProvider`. */
|
|
77
87
|
onCopyError?: (error: Error) => void;
|
|
88
|
+
/** Accessible label before copying, forwarded to the inner `CopyButton`. @default "Copy" */
|
|
89
|
+
copyLabel?: string;
|
|
90
|
+
/** Accessible label shown while the copied state is active, forwarded to the inner `CopyButton`. @default "Copied" */
|
|
91
|
+
copiedLabel?: string;
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
/**
|
|
@@ -89,11 +103,20 @@ function CopyableText({
|
|
|
89
103
|
timeout,
|
|
90
104
|
onCopied,
|
|
91
105
|
onCopyError,
|
|
106
|
+
copyLabel,
|
|
107
|
+
copiedLabel,
|
|
92
108
|
}: CopyableTextProps) {
|
|
93
109
|
return (
|
|
94
110
|
<span data-slot="copyable-text" className={cn('inline-flex items-center gap-1.5', className)}>
|
|
95
111
|
{children ?? value}
|
|
96
|
-
<CopyButton
|
|
112
|
+
<CopyButton
|
|
113
|
+
value={value}
|
|
114
|
+
timeout={timeout}
|
|
115
|
+
onCopied={onCopied}
|
|
116
|
+
onCopyError={onCopyError}
|
|
117
|
+
copyLabel={copyLabel}
|
|
118
|
+
copiedLabel={copiedLabel}
|
|
119
|
+
/>
|
|
97
120
|
</span>
|
|
98
121
|
);
|
|
99
122
|
}
|
|
@@ -9,11 +9,12 @@ import type { DataTableBulkActionContext } from '@vendure-io/ui/components/molec
|
|
|
9
9
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
10
10
|
import * as React from 'react';
|
|
11
11
|
|
|
12
|
-
// The selection
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
12
|
+
// The selection bar that replaces the controls row inside the header band
|
|
13
|
+
// while rows are selected (returns null with an empty selection; the core
|
|
14
|
+
// decides where it renders). The cross-page selection cache lives here (donor
|
|
15
|
+
// parity): `rows` only ever holds the current page, so we accumulate
|
|
16
|
+
// `row.original` by id as pages are seen, letting `bulkActions` receive every
|
|
17
|
+
// selected original — not just the ones still on screen.
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Accumulate `row.original` keyed by row id across page changes. Populated during
|
|
@@ -53,12 +54,12 @@ function DataTableBulkActions<TData>({
|
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
return (
|
|
57
|
+
// A plain band row, not a box: it takes the controls row's place inside
|
|
58
|
+
// the header band, so it carries no chrome of its own. min-h-9 matches
|
|
59
|
+
// the controls row's h-9 inputs so the swap holds the band height steady.
|
|
56
60
|
<div
|
|
57
61
|
data-slot="data-table-bulk-actions"
|
|
58
|
-
className={cn(
|
|
59
|
-
'bg-muted/50 flex flex-wrap items-center gap-2 rounded-md border px-3 py-2',
|
|
60
|
-
className,
|
|
61
|
-
)}
|
|
62
|
+
className={cn('flex min-h-9 flex-wrap items-center gap-2', className)}
|
|
62
63
|
{...props}
|
|
63
64
|
>
|
|
64
65
|
{render(ctx)}
|
|
@@ -182,7 +182,11 @@ export interface DataTableProps<TData> {
|
|
|
182
182
|
header?: React.ReactNode;
|
|
183
183
|
/** Controls row (search, faceted filters, custom buttons). Render-prop gets the live table. */
|
|
184
184
|
toolbar?: React.ReactNode | ((table: Table<TData>) => React.ReactNode);
|
|
185
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* Replaces the controls row inside the header band while selection is
|
|
187
|
+
* non-empty (title and applied-filter chips stay). Only meaningful with
|
|
188
|
+
* `rowSelection` wired.
|
|
189
|
+
*/
|
|
186
190
|
bulkActions?: (ctx: DataTableBulkActionContext<TData>) => React.ReactNode;
|
|
187
191
|
/**
|
|
188
192
|
* Per-row actions → appends an actions column. First arg is `row.original`
|
|
@@ -225,8 +229,52 @@ export interface DataTableProps<TData> {
|
|
|
225
229
|
*/
|
|
226
230
|
setTableOptions?: (options: TableOptions<TData>) => TableOptions<TData>;
|
|
227
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Receives the core's TanStack {@link Table} instance so consumers (saved-view
|
|
234
|
+
* controls, external toolbars) can drive it without rendering a slot to
|
|
235
|
+
* capture it — the supported alternative to reading `table` off the `toolbar`
|
|
236
|
+
* render-prop purely for its side effect.
|
|
237
|
+
*
|
|
238
|
+
* Fires from an effect after the first commit — never during render or SSR —
|
|
239
|
+
* so it is safe to call setState from here. `useReactTable` returns a
|
|
240
|
+
* referentially stable instance for the component's lifetime, so this fires
|
|
241
|
+
* once per mount (twice under React StrictMode in development, like any
|
|
242
|
+
* effect — keep the callback idempotent): never on a plain rerender, and not
|
|
243
|
+
* again when the callback prop's identity changes. Treat it as a "ready"
|
|
244
|
+
* capture, not a subscription — the latest callback as of that single fire is
|
|
245
|
+
* used (an inline function is fine), but a callback swapped in after mount is
|
|
246
|
+
* never invoked. TanStack mutates the instance in place as state changes, so
|
|
247
|
+
* the reference you capture here stays current — read live state through it
|
|
248
|
+
* (e.g. inside an event handler) rather than expecting a fresh object on each
|
|
249
|
+
* change.
|
|
250
|
+
*/
|
|
251
|
+
onTableReady?: (table: Table<TData>) => void;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The table's frame. `'card'` (default) renders the band anatomy on a real
|
|
255
|
+
* `Card`: a `CardHeader` (border-b) hosting the header/controls/chips zones,
|
|
256
|
+
* `CardTable` hosting the table flush to the card edges, and a `CardFooter`
|
|
257
|
+
* (border-t) hosting pagination when it is wired — no footer means the last
|
|
258
|
+
* row sits flush against the card's bottom edge. `'plain'` renders the same
|
|
259
|
+
* band structure without any card chrome, for a table embedded in an
|
|
260
|
+
* existing card (e.g. a dashboard widget): it MUST sit inside a `Card`,
|
|
261
|
+
* whose spacing variables (`--card-px`/`--card-gap`) drive the bands and
|
|
262
|
+
* edge-cell alignment — the host card is the frame.
|
|
263
|
+
*/
|
|
264
|
+
frame?: 'card' | 'plain';
|
|
265
|
+
/**
|
|
266
|
+
* Extra `<TableRow>`s appended inside `TableBody` after the data rows — e.g.
|
|
267
|
+
* an order table's subtotal/shipping/total rows. Rendered only alongside
|
|
268
|
+
* real rows, never with the skeleton or empty states, and has no interaction
|
|
269
|
+
* with selection, sorting, or pagination. Use the function form to receive
|
|
270
|
+
* `columnCount` for `colSpan`s — display columns (select, actions) are
|
|
271
|
+
* injected around your columns, so a hard-coded count desyncs. Rows are
|
|
272
|
+
* presentational: give them `hover:bg-transparent`.
|
|
273
|
+
*/
|
|
274
|
+
footerRows?: React.ReactNode | ((ctx: { columnCount: number }) => React.ReactNode);
|
|
275
|
+
|
|
228
276
|
labels?: DataTableLabels;
|
|
229
|
-
className?: string; //
|
|
277
|
+
className?: string; // the frame root (data-slot="data-table")
|
|
230
278
|
}
|
|
231
279
|
|
|
232
280
|
/**
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
useReactTable,
|
|
20
20
|
type VisibilityState,
|
|
21
21
|
} from '@tanstack/react-table';
|
|
22
|
+
import { Card, CardFooter, CardHeader, CardTable } from '@vendure-io/ui/components/atoms/card';
|
|
22
23
|
import { Checkbox } from '@vendure-io/ui/components/atoms/checkbox';
|
|
23
24
|
import {
|
|
24
25
|
ContextMenu,
|
|
@@ -45,6 +46,7 @@ import {
|
|
|
45
46
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-filters';
|
|
46
47
|
import {
|
|
47
48
|
buildDisplayColumns,
|
|
49
|
+
getSelectedRowIds,
|
|
48
50
|
resolveSlot,
|
|
49
51
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-helpers';
|
|
50
52
|
import type {
|
|
@@ -59,13 +61,17 @@ import {
|
|
|
59
61
|
} from '@vendure-io/ui/components/molecules/data-table/list-header';
|
|
60
62
|
import { TablePagination } from '@vendure-io/ui/components/molecules/data-table/table-pagination';
|
|
61
63
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
64
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
62
65
|
import * as React from 'react';
|
|
63
66
|
|
|
64
67
|
// The composition root. Owns the single `useReactTable` instance and the
|
|
65
|
-
// controlled/uncontrolled bridge, then lays out
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
68
|
+
// controlled/uncontrolled bridge, then lays out the card-framed table anatomy:
|
|
69
|
+
// a CardHeader band (header → controls → chips → bulk overlay), a CardTable
|
|
70
|
+
// hosting the Table flush to the card edges, and a CardFooter band for
|
|
71
|
+
// pagination. `frame="plain"` keeps the band structure without the card
|
|
72
|
+
// chrome. Every capability follows the Phase-1 rule verbatim: a feature
|
|
73
|
+
// renders only if its config is wired — no feature flags, no disabled
|
|
74
|
+
// placeholders. Only this folder imports TanStack; the composed
|
|
69
75
|
// ListHeader/TablePagination/Chip primitives stay TanStack-free.
|
|
70
76
|
|
|
71
77
|
/**
|
|
@@ -98,6 +104,16 @@ function headerLabelText<TData>(column: Column<TData, unknown>): string {
|
|
|
98
104
|
return typeof header === 'string' ? header : column.id;
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
// The controls/bulk replace-on-select swap: the outgoing row drifts slightly
|
|
108
|
+
// up as it fades, the incoming row rises in from below — a subtle vertical
|
|
109
|
+
// hand-off (4px) rather than a plain crossfade.
|
|
110
|
+
const bandRowFade = {
|
|
111
|
+
initial: { opacity: 0, y: 4 },
|
|
112
|
+
animate: { opacity: 1, y: 0 },
|
|
113
|
+
exit: { opacity: 0, y: -4 },
|
|
114
|
+
transition: { duration: 0.1, ease: 'easeOut' },
|
|
115
|
+
} as const;
|
|
116
|
+
|
|
101
117
|
function ariaSort<TData>(
|
|
102
118
|
hasSorting: boolean,
|
|
103
119
|
column: Column<TData, unknown>,
|
|
@@ -126,6 +142,9 @@ function DataTable<TData>({
|
|
|
126
142
|
emptyState,
|
|
127
143
|
renderRow,
|
|
128
144
|
setTableOptions,
|
|
145
|
+
onTableReady,
|
|
146
|
+
frame = 'card',
|
|
147
|
+
footerRows,
|
|
129
148
|
labels,
|
|
130
149
|
className,
|
|
131
150
|
}: DataTableProps<TData>) {
|
|
@@ -293,6 +312,16 @@ function DataTable<TData>({
|
|
|
293
312
|
|
|
294
313
|
const table = useReactTable(setTableOptions ? setTableOptions(baseOptions) : baseOptions);
|
|
295
314
|
|
|
315
|
+
// Hand the table instance to the consumer once it exists. A ref holds the
|
|
316
|
+
// latest callback so the effect can key on `table` alone — do NOT add
|
|
317
|
+
// `onTableReady` to the deps: that would re-fire the "ready" notification
|
|
318
|
+
// whenever an inline callback gets a new identity on rerender.
|
|
319
|
+
const onTableReadyRef = React.useRef(onTableReady);
|
|
320
|
+
onTableReadyRef.current = onTableReady;
|
|
321
|
+
React.useEffect(() => {
|
|
322
|
+
onTableReadyRef.current?.(table);
|
|
323
|
+
}, [table]);
|
|
324
|
+
|
|
296
325
|
const selectionCache = useSelectionCache(table);
|
|
297
326
|
|
|
298
327
|
const bodyRows = table.getRowModel().rows;
|
|
@@ -307,7 +336,11 @@ function DataTable<TData>({
|
|
|
307
336
|
? table.getVisibleLeafColumns().find((column) => column.id !== selectColumnId)?.id
|
|
308
337
|
: undefined;
|
|
309
338
|
const columnClass = (id: string): string | undefined => {
|
|
310
|
-
|
|
339
|
+
// `pl-0!`: the select cell is the first child, so CardTable's edge-cell
|
|
340
|
+
// padding would otherwise widen the zero-width cell and push the whole
|
|
341
|
+
// gutter arrangement out; important because CardTable's descendant rule
|
|
342
|
+
// out-specifies a plain utility on the cell.
|
|
343
|
+
if (id === selectColumnId) return 'relative w-0 p-0 pl-0!';
|
|
311
344
|
if (id === leadingColumnId) return 'pl-8';
|
|
312
345
|
// Actions cells drop vertical padding so a row-action button (taller than a
|
|
313
346
|
// text line) sits inside the natural row height rather than inflating every
|
|
@@ -327,47 +360,76 @@ function DataTable<TData>({
|
|
|
327
360
|
filters.showAppliedFilters !== false &&
|
|
328
361
|
table.getState().columnFilters.length > 0;
|
|
329
362
|
const showHeader = header != null || showControls || showChips;
|
|
330
|
-
|
|
363
|
+
// Unlike the other zones, the bulk bar exists only while rows are selected,
|
|
364
|
+
// so it opens the header band on its own only then — a controls-less
|
|
365
|
+
// selectable table must not render an empty band. (Deliberate trade-off:
|
|
366
|
+
// for a table with no header content at all, the band pops in on first
|
|
367
|
+
// selection rather than reserving empty space.)
|
|
368
|
+
const showBulk =
|
|
369
|
+
rowSelection != null &&
|
|
370
|
+
bulkActions != null &&
|
|
371
|
+
getSelectedRowIds(table.getState().rowSelection).length > 0;
|
|
331
372
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
{showHeader && (
|
|
335
|
-
<
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
373
|
+
const bands = (
|
|
374
|
+
<>
|
|
375
|
+
{(showHeader || showBulk) && (
|
|
376
|
+
<CardHeader className="border-b">
|
|
377
|
+
<ListHeader>
|
|
378
|
+
{header}
|
|
379
|
+
{/* Replace-on-select: while rows are selected the bulk bar takes
|
|
380
|
+
the controls row's place (title and applied-filter chips stay).
|
|
381
|
+
The swap fades out then in — one --transition-duration-fast
|
|
382
|
+
(100ms) per phase; mode="wait" keeps the rows sequential so
|
|
383
|
+
they never stack. */}
|
|
384
|
+
{(showControls || (rowSelection != null && bulkActions != null)) && (
|
|
385
|
+
<AnimatePresence initial={false} mode="wait">
|
|
386
|
+
{showBulk && bulkActions ? (
|
|
387
|
+
<motion.div key="bulk-actions" {...bandRowFade}>
|
|
388
|
+
<DataTableBulkActions
|
|
389
|
+
table={table}
|
|
390
|
+
cache={selectionCache}
|
|
391
|
+
render={bulkActions}
|
|
392
|
+
/>
|
|
393
|
+
</motion.div>
|
|
394
|
+
) : showControls ? (
|
|
395
|
+
<motion.div key="controls" {...bandRowFade}>
|
|
396
|
+
<ListHeaderControls>
|
|
397
|
+
{toolbarNode}
|
|
398
|
+
{hasFilterMenu && filters?.columns && (
|
|
399
|
+
<DataTableAddFilter
|
|
400
|
+
table={table}
|
|
401
|
+
columns={filters.columns}
|
|
402
|
+
label={l.addFilter}
|
|
403
|
+
/>
|
|
404
|
+
)}
|
|
405
|
+
{showViewOptions && (
|
|
406
|
+
<DataTableViewOptions
|
|
407
|
+
table={table}
|
|
408
|
+
triggerLabel={l.columnsTrigger}
|
|
409
|
+
heading={l.columnsHeading}
|
|
410
|
+
/>
|
|
411
|
+
)}
|
|
412
|
+
</ListHeaderControls>
|
|
413
|
+
</motion.div>
|
|
414
|
+
) : null}
|
|
415
|
+
</AnimatePresence>
|
|
416
|
+
)}
|
|
417
|
+
{showChips && (
|
|
418
|
+
<ListHeaderChips>
|
|
419
|
+
<DataTableAppliedFilters
|
|
345
420
|
table={table}
|
|
346
|
-
|
|
347
|
-
|
|
421
|
+
columns={filters?.columns}
|
|
422
|
+
inlineChipLimit={filters?.inlineChipLimit}
|
|
423
|
+
removeLabel={l.removeFilter}
|
|
424
|
+
collapsedLabel={l.filtersCollapsed}
|
|
348
425
|
/>
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
<ListHeaderChips>
|
|
354
|
-
<DataTableAppliedFilters
|
|
355
|
-
table={table}
|
|
356
|
-
columns={filters?.columns}
|
|
357
|
-
inlineChipLimit={filters?.inlineChipLimit}
|
|
358
|
-
removeLabel={l.removeFilter}
|
|
359
|
-
collapsedLabel={l.filtersCollapsed}
|
|
360
|
-
/>
|
|
361
|
-
</ListHeaderChips>
|
|
362
|
-
)}
|
|
363
|
-
</ListHeader>
|
|
364
|
-
)}
|
|
365
|
-
|
|
366
|
-
{showBulk && bulkActions && (
|
|
367
|
-
<DataTableBulkActions table={table} cache={selectionCache} render={bulkActions} />
|
|
426
|
+
</ListHeaderChips>
|
|
427
|
+
)}
|
|
428
|
+
</ListHeader>
|
|
429
|
+
</CardHeader>
|
|
368
430
|
)}
|
|
369
431
|
|
|
370
|
-
<
|
|
432
|
+
<CardTable>
|
|
371
433
|
<Table>
|
|
372
434
|
<TableHeader>
|
|
373
435
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
@@ -419,63 +481,94 @@ function DataTable<TData>({
|
|
|
419
481
|
</TableCell>
|
|
420
482
|
</TableRow>
|
|
421
483
|
) : (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
{
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
<
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
{
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
484
|
+
<>
|
|
485
|
+
{bodyRows.map((row) => {
|
|
486
|
+
const rowNode = (
|
|
487
|
+
<TableRow
|
|
488
|
+
className="group/row"
|
|
489
|
+
data-state={row.getIsSelected() ? 'selected' : undefined}
|
|
490
|
+
>
|
|
491
|
+
{row.getVisibleCells().map((cell) => (
|
|
492
|
+
<TableCell key={cell.id} className={columnClass(cell.column.id)}>
|
|
493
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
494
|
+
</TableCell>
|
|
495
|
+
))}
|
|
496
|
+
</TableRow>
|
|
497
|
+
);
|
|
498
|
+
// Right-click accelerator: the row itself is the context-menu
|
|
499
|
+
// trigger, so the consumer supplies only the items and the core
|
|
500
|
+
// owns the menu chrome.
|
|
501
|
+
const defaultRow = contextActions ? (
|
|
502
|
+
<ContextMenu>
|
|
503
|
+
<ContextMenuTrigger render={rowNode} />
|
|
504
|
+
<ContextMenuContent>
|
|
505
|
+
{contextActions(row.original, { row, table })}
|
|
506
|
+
</ContextMenuContent>
|
|
507
|
+
</ContextMenu>
|
|
508
|
+
) : (
|
|
509
|
+
rowNode
|
|
510
|
+
);
|
|
511
|
+
// Row-render seam: consumers can swap the default row for a
|
|
512
|
+
// full-width utility row or a per-row wrapper the cell grid can't
|
|
513
|
+
// express. Returning `defaultRow` keeps the built-in rendering.
|
|
514
|
+
return (
|
|
515
|
+
<React.Fragment key={row.id}>
|
|
516
|
+
{renderRow ? renderRow(row, { table, columnCount, defaultRow }) : defaultRow}
|
|
517
|
+
</React.Fragment>
|
|
518
|
+
);
|
|
519
|
+
})}
|
|
520
|
+
{typeof footerRows === 'function' ? footerRows({ columnCount }) : footerRows}
|
|
521
|
+
</>
|
|
457
522
|
)}
|
|
458
523
|
</TableBody>
|
|
459
524
|
</Table>
|
|
460
|
-
</
|
|
525
|
+
</CardTable>
|
|
461
526
|
|
|
462
527
|
{pagination && (
|
|
463
|
-
<
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
528
|
+
<CardFooter className="border-t">
|
|
529
|
+
<TablePagination
|
|
530
|
+
className="w-full"
|
|
531
|
+
page={pagination.page}
|
|
532
|
+
pageSize={pagination.pageSize}
|
|
533
|
+
totalItems={pagination.totalItems ?? table.getPrePaginationRowModel().rows.length}
|
|
534
|
+
onPageChange={pagination.onPageChange}
|
|
535
|
+
onPageSizeChange={pagination.onPageSizeChange}
|
|
536
|
+
pageSizeOptions={pagination.pageSizeOptions}
|
|
537
|
+
getPageHref={pagination.getPageHref}
|
|
538
|
+
formatRange={pagination.formatRange}
|
|
539
|
+
navLabel={l.pagination?.navLabel}
|
|
540
|
+
previousLabel={l.pagination?.previousLabel}
|
|
541
|
+
nextLabel={l.pagination?.nextLabel}
|
|
542
|
+
pageSizeLabel={l.pagination?.pageSizeLabel}
|
|
543
|
+
/>
|
|
544
|
+
</CardFooter>
|
|
545
|
+
)}
|
|
546
|
+
</>
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
// `plain` renders a chrome-less stack instead of a Card so the bands and
|
|
550
|
+
// CardTable consume the HOST card's spacing variables (--card-px /
|
|
551
|
+
// --card-gap): edge cells align with the host's padding regardless of its
|
|
552
|
+
// size, and a trailing CardTable's negative margin reaches through the
|
|
553
|
+
// host's bottom padding so the last row sits flush against the host's edge.
|
|
554
|
+
// With no header band the leading CardTable's negative margin would eat the
|
|
555
|
+
// host's flex gap too and press the rows against the preceding content, so
|
|
556
|
+
// the stack restores that one gap as padding.
|
|
557
|
+
return frame === 'plain' ? (
|
|
558
|
+
<div
|
|
559
|
+
data-slot="data-table"
|
|
560
|
+
className={cn(
|
|
561
|
+
'flex flex-col gap-(--card-gap)',
|
|
562
|
+
!(showHeader || showBulk) && 'pt-(--card-gap)',
|
|
563
|
+
className,
|
|
477
564
|
)}
|
|
565
|
+
>
|
|
566
|
+
{bands}
|
|
478
567
|
</div>
|
|
568
|
+
) : (
|
|
569
|
+
<Card data-slot="data-table" className={className}>
|
|
570
|
+
{bands}
|
|
571
|
+
</Card>
|
|
479
572
|
);
|
|
480
573
|
}
|
|
481
574
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Button } from '@vendure-io/ui/components/atoms/button';
|
|
4
|
+
import { Calendar } from '@vendure-io/ui/components/atoms/calendar';
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@vendure-io/ui/components/atoms/popover';
|
|
6
|
+
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
7
|
+
import {
|
|
8
|
+
formatCalendarDate,
|
|
9
|
+
formatDateLabel,
|
|
10
|
+
parseCalendarDate,
|
|
11
|
+
} from '@vendure-io/ui/lib/date-value';
|
|
12
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
13
|
+
import { CalendarIcon, XIcon } from 'lucide-react';
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
|
|
16
|
+
type CalendarProps = Omit<
|
|
17
|
+
React.ComponentProps<typeof Calendar>,
|
|
18
|
+
'mode' | 'selected' | 'onSelect' | 'disabled' | 'defaultMonth'
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
interface DatePickerProps extends Omit<React.ComponentProps<'div'>, 'defaultValue' | 'onChange'> {
|
|
22
|
+
/** Local calendar date (`YYYY-MM-DD`), never an instant. */
|
|
23
|
+
value?: string;
|
|
24
|
+
onValueChange?: (value: string | undefined) => void;
|
|
25
|
+
min?: string;
|
|
26
|
+
max?: string;
|
|
27
|
+
placeholder?: React.ReactNode;
|
|
28
|
+
clearable?: boolean;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
invalid?: boolean;
|
|
31
|
+
name?: string;
|
|
32
|
+
id?: string;
|
|
33
|
+
calendarProps?: CalendarProps;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Date-only picker whose value cannot shift when serialized across time zones. */
|
|
37
|
+
function DatePicker({
|
|
38
|
+
value,
|
|
39
|
+
onValueChange,
|
|
40
|
+
min,
|
|
41
|
+
max,
|
|
42
|
+
placeholder = 'Pick a date',
|
|
43
|
+
clearable = true,
|
|
44
|
+
disabled,
|
|
45
|
+
invalid,
|
|
46
|
+
name,
|
|
47
|
+
id,
|
|
48
|
+
calendarProps,
|
|
49
|
+
className,
|
|
50
|
+
...props
|
|
51
|
+
}: DatePickerProps) {
|
|
52
|
+
const [open, setOpen] = React.useState(false);
|
|
53
|
+
const { locale } = useFormatSettings();
|
|
54
|
+
const selected = parseCalendarDate(value);
|
|
55
|
+
const minDate = parseCalendarDate(min);
|
|
56
|
+
const maxDate = parseCalendarDate(max);
|
|
57
|
+
const disabledMatchers = [
|
|
58
|
+
...(minDate ? [{ before: minDate }] : []),
|
|
59
|
+
...(maxDate ? [{ after: maxDate }] : []),
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
data-slot="date-picker"
|
|
65
|
+
className={cn('flex min-w-0 items-center gap-1', className)}
|
|
66
|
+
{...props}
|
|
67
|
+
>
|
|
68
|
+
{name ? <input type="hidden" name={name} value={value ?? ''} /> : null}
|
|
69
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
70
|
+
<PopoverTrigger
|
|
71
|
+
render={
|
|
72
|
+
<Button
|
|
73
|
+
id={id}
|
|
74
|
+
type="button"
|
|
75
|
+
variant="outline"
|
|
76
|
+
disabled={disabled}
|
|
77
|
+
aria-invalid={invalid || undefined}
|
|
78
|
+
// Pickers sit in forms next to Inputs, so mirror the Input/Select
|
|
79
|
+
// trigger look (transparent bg) instead of the outline button fill.
|
|
80
|
+
className="min-w-0 flex-1 justify-start border-input bg-transparent font-normal hover:bg-transparent aria-expanded:bg-transparent"
|
|
81
|
+
/>
|
|
82
|
+
}
|
|
83
|
+
>
|
|
84
|
+
<CalendarIcon />
|
|
85
|
+
<span className={cn('truncate', !selected && 'text-muted-foreground')}>
|
|
86
|
+
{selected ? formatDateLabel(selected, locale) : placeholder}
|
|
87
|
+
</span>
|
|
88
|
+
</PopoverTrigger>
|
|
89
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
90
|
+
<Calendar
|
|
91
|
+
{...calendarProps}
|
|
92
|
+
mode="single"
|
|
93
|
+
selected={selected}
|
|
94
|
+
defaultMonth={selected ?? minDate}
|
|
95
|
+
disabled={disabledMatchers}
|
|
96
|
+
onSelect={(date) => {
|
|
97
|
+
onValueChange?.(date ? formatCalendarDate(date) : undefined);
|
|
98
|
+
if (date) setOpen(false);
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
</PopoverContent>
|
|
102
|
+
</Popover>
|
|
103
|
+
{clearable && selected ? (
|
|
104
|
+
<Button
|
|
105
|
+
type="button"
|
|
106
|
+
variant="ghost"
|
|
107
|
+
size="icon-sm"
|
|
108
|
+
disabled={disabled}
|
|
109
|
+
aria-label="Clear date"
|
|
110
|
+
onClick={() => onValueChange?.(undefined)}
|
|
111
|
+
>
|
|
112
|
+
<XIcon />
|
|
113
|
+
</Button>
|
|
114
|
+
) : null}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { DatePicker, type DatePickerProps };
|