@vendure-io/ui 2.0.0-beta.8 → 2.0.0-rc.0
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/package.json +8 -6
- package/src/components/atoms/alert-dialog.tsx +1 -1
- package/src/components/atoms/alert.tsx +1 -1
- package/src/components/atoms/badge.tsx +1 -1
- package/src/components/atoms/button.tsx +2 -2
- package/src/components/atoms/card.tsx +39 -4
- package/src/components/atoms/checkbox.tsx +1 -1
- package/src/components/atoms/combobox.tsx +24 -5
- package/src/components/atoms/command.tsx +16 -5
- package/src/components/atoms/context-menu.tsx +1 -1
- package/src/components/atoms/dialog.tsx +1 -1
- package/src/components/atoms/drawer.tsx +134 -35
- package/src/components/atoms/dropdown-menu.tsx +1 -1
- package/src/components/atoms/field.tsx +2 -2
- package/src/components/atoms/input.tsx +1 -1
- package/src/components/atoms/item.tsx +4 -1
- package/src/components/atoms/menubar.tsx +1 -1
- package/src/components/atoms/native-select.tsx +1 -1
- package/src/components/atoms/navigation-menu.tsx +8 -2
- package/src/components/atoms/progress.tsx +1 -1
- package/src/components/atoms/radio-group.tsx +1 -1
- package/src/components/atoms/scroll-area.tsx +1 -2
- package/src/components/atoms/select.tsx +1 -1
- package/src/components/atoms/sheet.tsx +1 -1
- package/src/components/atoms/sidebar.tsx +6 -4
- package/src/components/atoms/slider.tsx +2 -2
- package/src/components/atoms/switch.tsx +1 -1
- package/src/components/atoms/table.tsx +34 -2
- package/src/components/atoms/tabs.tsx +64 -1
- package/src/components/atoms/textarea.tsx +1 -1
- package/src/components/atoms/toggle-group.tsx +1 -1
- package/src/components/atoms/toggle.tsx +5 -2
- package/src/components/molecules/chip.tsx +7 -2
- package/src/components/molecules/code-block/file-type-icons.tsx +123 -0
- package/src/components/molecules/code-block/process-code.ts +60 -0
- package/src/components/molecules/code-block/transform-command.tsx +177 -0
- package/src/components/molecules/code-block.tsx +29 -575
- package/src/components/molecules/combobox-free-text.tsx +23 -2
- package/src/components/molecules/copyable-text.tsx +14 -1
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +12 -13
- package/src/components/molecules/data-table/data-table-types.tsx +50 -2
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -1
- package/src/components/molecules/data-table/data-table.tsx +188 -96
- package/src/components/molecules/date-picker.tsx +3 -1
- package/src/components/molecules/date-range-picker.tsx +3 -1
- package/src/components/molecules/date-time-picker.tsx +3 -1
- package/src/components/molecules/file-dropzone.tsx +15 -5
- package/src/components/molecules/illustrations/empty-database.tsx +8 -5
- package/src/components/molecules/illustrations/error.tsx +19 -17
- package/src/components/molecules/illustrations/expired.tsx +55 -0
- package/src/components/molecules/illustrations/first-run.tsx +3 -1
- package/src/components/molecules/illustrations/no-activity.tsx +35 -14
- package/src/components/molecules/illustrations/no-customers.tsx +66 -0
- package/src/components/molecules/illustrations/no-documents.tsx +4 -3
- package/src/components/molecules/illustrations/no-invoices.tsx +45 -0
- package/src/components/molecules/illustrations/no-notifications.tsx +7 -8
- package/src/components/molecules/illustrations/no-orders.tsx +25 -17
- package/src/components/molecules/illustrations/no-plugins.tsx +21 -31
- package/src/components/molecules/illustrations/no-products.tsx +53 -0
- package/src/components/molecules/illustrations/no-projects.tsx +54 -0
- package/src/components/molecules/illustrations/no-promotions.tsx +49 -0
- package/src/components/molecules/illustrations/no-subscription.tsx +72 -0
- package/src/components/molecules/illustrations/not-found.tsx +17 -15
- package/src/components/molecules/illustrations/offline.tsx +12 -10
- package/src/components/molecules/illustrations/payment-failed.tsx +53 -0
- package/src/components/molecules/illustrations/success.tsx +43 -0
- package/src/components/molecules/inline-code.tsx +26 -0
- package/src/components/molecules/page-header.tsx +7 -3
- package/src/components/molecules/stat-card.tsx +13 -12
- 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/highlight.ts +177 -0
- package/src/lib/state-dictionary.ts +18 -5
- package/src/lib/utils.ts +0 -19
|
@@ -52,6 +52,8 @@ export interface ComboboxFreeTextProps<T extends ComboboxFreeTextItem = Combobox
|
|
|
52
52
|
*/
|
|
53
53
|
items: readonly T[];
|
|
54
54
|
/** Async state of the suggestion source. Shows a trailing spinner while true. */
|
|
55
|
+
isLoading?: boolean;
|
|
56
|
+
/** @deprecated Use `isLoading`. Kept as an alias until the next major. */
|
|
55
57
|
loading?: boolean;
|
|
56
58
|
/** Render a suggestion row. Defaults to `label` over `description`. */
|
|
57
59
|
renderItem?: (item: T) => React.ReactNode;
|
|
@@ -92,7 +94,8 @@ function ComboboxFreeText<T extends ComboboxFreeTextItem = ComboboxFreeTextItem>
|
|
|
92
94
|
onValueChange,
|
|
93
95
|
onSelectItem,
|
|
94
96
|
items,
|
|
95
|
-
|
|
97
|
+
isLoading,
|
|
98
|
+
loading,
|
|
96
99
|
renderItem = defaultRenderItem,
|
|
97
100
|
id,
|
|
98
101
|
placeholder,
|
|
@@ -137,8 +140,26 @@ function ComboboxFreeText<T extends ComboboxFreeTextItem = ComboboxFreeTextItem>
|
|
|
137
140
|
placeholder={placeholder}
|
|
138
141
|
disabled={disabled}
|
|
139
142
|
aria-invalid={invalid || undefined}
|
|
143
|
+
// Base UI only requests open on a keystroke; for pick-or-create
|
|
144
|
+
// fields the suggestions should also show on focus/click so a small
|
|
145
|
+
// known option set is discoverable without typing. The
|
|
146
|
+
// `items.length > 0` gate on `open` keeps an empty popup from
|
|
147
|
+
// flashing when there is nothing to pick.
|
|
148
|
+
onFocus={() => setOpen(true)}
|
|
149
|
+
onClick={() => setOpen(true)}
|
|
150
|
+
// Enter has a local meaning here — commit the highlighted suggestion
|
|
151
|
+
// or keep the typed text — so it must never double as the browser's
|
|
152
|
+
// implicit form submission (Base UI deliberately lets Enter fall
|
|
153
|
+
// through to submit when nothing is highlighted). preventDefault
|
|
154
|
+
// cancels only the native submit; Base UI's own Enter handling runs
|
|
155
|
+
// regardless, since merged handlers ignore defaultPrevented.
|
|
156
|
+
onKeyDown={(event) => {
|
|
157
|
+
if (event.key === 'Enter') {
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
}
|
|
160
|
+
}}
|
|
140
161
|
/>
|
|
141
|
-
{loading ? (
|
|
162
|
+
{(isLoading ?? loading) ? (
|
|
142
163
|
<InputGroupAddon align="inline-end">
|
|
143
164
|
<Spinner />
|
|
144
165
|
</InputGroupAddon>
|
|
@@ -85,6 +85,10 @@ interface CopyableTextProps {
|
|
|
85
85
|
onCopied?: () => void;
|
|
86
86
|
/** Called when the clipboard write fails. Falls back to `CopyFeedbackProvider`. */
|
|
87
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;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
/**
|
|
@@ -99,11 +103,20 @@ function CopyableText({
|
|
|
99
103
|
timeout,
|
|
100
104
|
onCopied,
|
|
101
105
|
onCopyError,
|
|
106
|
+
copyLabel,
|
|
107
|
+
copiedLabel,
|
|
102
108
|
}: CopyableTextProps) {
|
|
103
109
|
return (
|
|
104
110
|
<span data-slot="copyable-text" className={cn('inline-flex items-center gap-1.5', className)}>
|
|
105
111
|
{children ?? value}
|
|
106
|
-
<CopyButton
|
|
112
|
+
<CopyButton
|
|
113
|
+
value={value}
|
|
114
|
+
timeout={timeout}
|
|
115
|
+
onCopied={onCopied}
|
|
116
|
+
onCopyError={onCopyError}
|
|
117
|
+
copyLabel={copyLabel}
|
|
118
|
+
copiedLabel={copiedLabel}
|
|
119
|
+
/>
|
|
107
120
|
</span>
|
|
108
121
|
);
|
|
109
122
|
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import type { Table } from '@tanstack/react-table';
|
|
4
|
-
import {
|
|
5
|
-
getSelectedOriginals,
|
|
6
|
-
getSelectedRowIds,
|
|
7
|
-
} from '@vendure-io/ui/components/molecules/data-table/data-table-helpers';
|
|
8
4
|
import type { DataTableBulkActionContext } from '@vendure-io/ui/components/molecules/data-table/data-table-types';
|
|
9
5
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
10
6
|
import * as React from 'react';
|
|
7
|
+
// Relative: `data-table-helpers` is closed in the package exports.
|
|
8
|
+
import { getSelectedOriginals, getSelectedRowIds } from './data-table-helpers.tsx';
|
|
11
9
|
|
|
12
|
-
// The selection
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
10
|
+
// The selection bar that replaces the controls row inside the header band
|
|
11
|
+
// while rows are selected (returns null with an empty selection; the core
|
|
12
|
+
// decides where it renders). The cross-page selection cache lives here (donor
|
|
13
|
+
// parity): `rows` only ever holds the current page, so we accumulate
|
|
14
|
+
// `row.original` by id as pages are seen, letting `bulkActions` receive every
|
|
15
|
+
// selected original — not just the ones still on screen.
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Accumulate `row.original` keyed by row id across page changes. Populated during
|
|
@@ -53,12 +52,12 @@ function DataTableBulkActions<TData>({
|
|
|
53
52
|
};
|
|
54
53
|
|
|
55
54
|
return (
|
|
55
|
+
// A plain band row, not a box: it takes the controls row's place inside
|
|
56
|
+
// the header band, so it carries no chrome of its own. min-h-9 matches
|
|
57
|
+
// the controls row's h-9 inputs so the swap holds the band height steady.
|
|
56
58
|
<div
|
|
57
59
|
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
|
-
)}
|
|
60
|
+
className={cn('flex min-h-9 flex-wrap items-center gap-2', className)}
|
|
62
61
|
{...props}
|
|
63
62
|
>
|
|
64
63
|
{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
|
/**
|
|
@@ -11,8 +11,9 @@ import {
|
|
|
11
11
|
DropdownMenuSeparator,
|
|
12
12
|
DropdownMenuTrigger,
|
|
13
13
|
} from '@vendure-io/ui/components/atoms/dropdown-menu';
|
|
14
|
-
import { getHideableLeafColumns } from '@vendure-io/ui/components/molecules/data-table/data-table-helpers';
|
|
15
14
|
import { SlidersHorizontalIcon } from 'lucide-react';
|
|
15
|
+
// Relative: `data-table-helpers` is closed in the package exports.
|
|
16
|
+
import { getHideableLeafColumns } from './data-table-helpers.tsx';
|
|
16
17
|
|
|
17
18
|
// The column-visibility gear. Lists only hideable columns (`getCanHide()`), so
|
|
18
19
|
// the always-on `select`/`actions` display columns never appear here. Labels
|
|
@@ -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,
|
|
@@ -43,10 +44,6 @@ import {
|
|
|
43
44
|
DataTableAddFilter,
|
|
44
45
|
DataTableAppliedFilters,
|
|
45
46
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-filters';
|
|
46
|
-
import {
|
|
47
|
-
buildDisplayColumns,
|
|
48
|
-
resolveSlot,
|
|
49
|
-
} from '@vendure-io/ui/components/molecules/data-table/data-table-helpers';
|
|
50
47
|
import type {
|
|
51
48
|
ControlledState,
|
|
52
49
|
DataTableProps,
|
|
@@ -59,13 +56,19 @@ import {
|
|
|
59
56
|
} from '@vendure-io/ui/components/molecules/data-table/list-header';
|
|
60
57
|
import { TablePagination } from '@vendure-io/ui/components/molecules/data-table/table-pagination';
|
|
61
58
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
59
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
62
60
|
import * as React from 'react';
|
|
61
|
+
// Relative: `data-table-helpers` is closed in the package exports.
|
|
62
|
+
import { buildDisplayColumns, getSelectedRowIds, resolveSlot } from './data-table-helpers.tsx';
|
|
63
63
|
|
|
64
64
|
// The composition root. Owns the single `useReactTable` instance and the
|
|
65
|
-
// controlled/uncontrolled bridge, then lays out
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
65
|
+
// controlled/uncontrolled bridge, then lays out the card-framed table anatomy:
|
|
66
|
+
// a CardHeader band (header → controls → chips → bulk overlay), a CardTable
|
|
67
|
+
// hosting the Table flush to the card edges, and a CardFooter band for
|
|
68
|
+
// pagination. `frame="plain"` keeps the band structure without the card
|
|
69
|
+
// chrome. Every capability follows the Phase-1 rule verbatim: a feature
|
|
70
|
+
// renders only if its config is wired — no feature flags, no disabled
|
|
71
|
+
// placeholders. Only this folder imports TanStack; the composed
|
|
69
72
|
// ListHeader/TablePagination/Chip primitives stay TanStack-free.
|
|
70
73
|
|
|
71
74
|
/**
|
|
@@ -98,6 +101,16 @@ function headerLabelText<TData>(column: Column<TData, unknown>): string {
|
|
|
98
101
|
return typeof header === 'string' ? header : column.id;
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
// The controls/bulk replace-on-select swap: the outgoing row drifts slightly
|
|
105
|
+
// up as it fades, the incoming row rises in from below — a subtle vertical
|
|
106
|
+
// hand-off (4px) rather than a plain crossfade.
|
|
107
|
+
const bandRowFade = {
|
|
108
|
+
initial: { opacity: 0, y: 4 },
|
|
109
|
+
animate: { opacity: 1, y: 0 },
|
|
110
|
+
exit: { opacity: 0, y: -4 },
|
|
111
|
+
transition: { duration: 0.1, ease: 'easeOut' },
|
|
112
|
+
} as const;
|
|
113
|
+
|
|
101
114
|
function ariaSort<TData>(
|
|
102
115
|
hasSorting: boolean,
|
|
103
116
|
column: Column<TData, unknown>,
|
|
@@ -126,6 +139,9 @@ function DataTable<TData>({
|
|
|
126
139
|
emptyState,
|
|
127
140
|
renderRow,
|
|
128
141
|
setTableOptions,
|
|
142
|
+
onTableReady,
|
|
143
|
+
frame = 'card',
|
|
144
|
+
footerRows,
|
|
129
145
|
labels,
|
|
130
146
|
className,
|
|
131
147
|
}: DataTableProps<TData>) {
|
|
@@ -293,6 +309,16 @@ function DataTable<TData>({
|
|
|
293
309
|
|
|
294
310
|
const table = useReactTable(setTableOptions ? setTableOptions(baseOptions) : baseOptions);
|
|
295
311
|
|
|
312
|
+
// Hand the table instance to the consumer once it exists. A ref holds the
|
|
313
|
+
// latest callback so the effect can key on `table` alone — do NOT add
|
|
314
|
+
// `onTableReady` to the deps: that would re-fire the "ready" notification
|
|
315
|
+
// whenever an inline callback gets a new identity on rerender.
|
|
316
|
+
const onTableReadyRef = React.useRef(onTableReady);
|
|
317
|
+
onTableReadyRef.current = onTableReady;
|
|
318
|
+
React.useEffect(() => {
|
|
319
|
+
onTableReadyRef.current?.(table);
|
|
320
|
+
}, [table]);
|
|
321
|
+
|
|
296
322
|
const selectionCache = useSelectionCache(table);
|
|
297
323
|
|
|
298
324
|
const bodyRows = table.getRowModel().rows;
|
|
@@ -307,7 +333,11 @@ function DataTable<TData>({
|
|
|
307
333
|
? table.getVisibleLeafColumns().find((column) => column.id !== selectColumnId)?.id
|
|
308
334
|
: undefined;
|
|
309
335
|
const columnClass = (id: string): string | undefined => {
|
|
310
|
-
|
|
336
|
+
// `pl-0!`: the select cell is the first child, so CardTable's edge-cell
|
|
337
|
+
// padding would otherwise widen the zero-width cell and push the whole
|
|
338
|
+
// gutter arrangement out; important because CardTable's descendant rule
|
|
339
|
+
// out-specifies a plain utility on the cell.
|
|
340
|
+
if (id === selectColumnId) return 'relative w-0 p-0 pl-0!';
|
|
311
341
|
if (id === leadingColumnId) return 'pl-8';
|
|
312
342
|
// Actions cells drop vertical padding so a row-action button (taller than a
|
|
313
343
|
// text line) sits inside the natural row height rather than inflating every
|
|
@@ -327,47 +357,76 @@ function DataTable<TData>({
|
|
|
327
357
|
filters.showAppliedFilters !== false &&
|
|
328
358
|
table.getState().columnFilters.length > 0;
|
|
329
359
|
const showHeader = header != null || showControls || showChips;
|
|
330
|
-
|
|
360
|
+
// Unlike the other zones, the bulk bar exists only while rows are selected,
|
|
361
|
+
// so it opens the header band on its own only then — a controls-less
|
|
362
|
+
// selectable table must not render an empty band. (Deliberate trade-off:
|
|
363
|
+
// for a table with no header content at all, the band pops in on first
|
|
364
|
+
// selection rather than reserving empty space.)
|
|
365
|
+
const showBulk =
|
|
366
|
+
rowSelection != null &&
|
|
367
|
+
bulkActions != null &&
|
|
368
|
+
getSelectedRowIds(table.getState().rowSelection).length > 0;
|
|
331
369
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
{showHeader && (
|
|
335
|
-
<
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
370
|
+
const bands = (
|
|
371
|
+
<>
|
|
372
|
+
{(showHeader || showBulk) && (
|
|
373
|
+
<CardHeader className="border-b">
|
|
374
|
+
<ListHeader>
|
|
375
|
+
{header}
|
|
376
|
+
{/* Replace-on-select: while rows are selected the bulk bar takes
|
|
377
|
+
the controls row's place (title and applied-filter chips stay).
|
|
378
|
+
The swap fades out then in — one --transition-duration-fast
|
|
379
|
+
(100ms) per phase; mode="wait" keeps the rows sequential so
|
|
380
|
+
they never stack. */}
|
|
381
|
+
{(showControls || (rowSelection != null && bulkActions != null)) && (
|
|
382
|
+
<AnimatePresence initial={false} mode="wait">
|
|
383
|
+
{showBulk && bulkActions ? (
|
|
384
|
+
<motion.div key="bulk-actions" {...bandRowFade}>
|
|
385
|
+
<DataTableBulkActions
|
|
386
|
+
table={table}
|
|
387
|
+
cache={selectionCache}
|
|
388
|
+
render={bulkActions}
|
|
389
|
+
/>
|
|
390
|
+
</motion.div>
|
|
391
|
+
) : showControls ? (
|
|
392
|
+
<motion.div key="controls" {...bandRowFade}>
|
|
393
|
+
<ListHeaderControls>
|
|
394
|
+
{toolbarNode}
|
|
395
|
+
{hasFilterMenu && filters?.columns && (
|
|
396
|
+
<DataTableAddFilter
|
|
397
|
+
table={table}
|
|
398
|
+
columns={filters.columns}
|
|
399
|
+
label={l.addFilter}
|
|
400
|
+
/>
|
|
401
|
+
)}
|
|
402
|
+
{showViewOptions && (
|
|
403
|
+
<DataTableViewOptions
|
|
404
|
+
table={table}
|
|
405
|
+
triggerLabel={l.columnsTrigger}
|
|
406
|
+
heading={l.columnsHeading}
|
|
407
|
+
/>
|
|
408
|
+
)}
|
|
409
|
+
</ListHeaderControls>
|
|
410
|
+
</motion.div>
|
|
411
|
+
) : null}
|
|
412
|
+
</AnimatePresence>
|
|
413
|
+
)}
|
|
414
|
+
{showChips && (
|
|
415
|
+
<ListHeaderChips>
|
|
416
|
+
<DataTableAppliedFilters
|
|
345
417
|
table={table}
|
|
346
|
-
|
|
347
|
-
|
|
418
|
+
columns={filters?.columns}
|
|
419
|
+
inlineChipLimit={filters?.inlineChipLimit}
|
|
420
|
+
removeLabel={l.removeFilter}
|
|
421
|
+
collapsedLabel={l.filtersCollapsed}
|
|
348
422
|
/>
|
|
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} />
|
|
423
|
+
</ListHeaderChips>
|
|
424
|
+
)}
|
|
425
|
+
</ListHeader>
|
|
426
|
+
</CardHeader>
|
|
368
427
|
)}
|
|
369
428
|
|
|
370
|
-
<
|
|
429
|
+
<CardTable>
|
|
371
430
|
<Table>
|
|
372
431
|
<TableHeader>
|
|
373
432
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
@@ -419,63 +478,94 @@ function DataTable<TData>({
|
|
|
419
478
|
</TableCell>
|
|
420
479
|
</TableRow>
|
|
421
480
|
) : (
|
|
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
|
-
|
|
481
|
+
<>
|
|
482
|
+
{bodyRows.map((row) => {
|
|
483
|
+
const rowNode = (
|
|
484
|
+
<TableRow
|
|
485
|
+
className="group/row"
|
|
486
|
+
data-state={row.getIsSelected() ? 'selected' : undefined}
|
|
487
|
+
>
|
|
488
|
+
{row.getVisibleCells().map((cell) => (
|
|
489
|
+
<TableCell key={cell.id} className={columnClass(cell.column.id)}>
|
|
490
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
491
|
+
</TableCell>
|
|
492
|
+
))}
|
|
493
|
+
</TableRow>
|
|
494
|
+
);
|
|
495
|
+
// Right-click accelerator: the row itself is the context-menu
|
|
496
|
+
// trigger, so the consumer supplies only the items and the core
|
|
497
|
+
// owns the menu chrome.
|
|
498
|
+
const defaultRow = contextActions ? (
|
|
499
|
+
<ContextMenu>
|
|
500
|
+
<ContextMenuTrigger render={rowNode} />
|
|
501
|
+
<ContextMenuContent>
|
|
502
|
+
{contextActions(row.original, { row, table })}
|
|
503
|
+
</ContextMenuContent>
|
|
504
|
+
</ContextMenu>
|
|
505
|
+
) : (
|
|
506
|
+
rowNode
|
|
507
|
+
);
|
|
508
|
+
// Row-render seam: consumers can swap the default row for a
|
|
509
|
+
// full-width utility row or a per-row wrapper the cell grid can't
|
|
510
|
+
// express. Returning `defaultRow` keeps the built-in rendering.
|
|
511
|
+
return (
|
|
512
|
+
<React.Fragment key={row.id}>
|
|
513
|
+
{renderRow ? renderRow(row, { table, columnCount, defaultRow }) : defaultRow}
|
|
514
|
+
</React.Fragment>
|
|
515
|
+
);
|
|
516
|
+
})}
|
|
517
|
+
{typeof footerRows === 'function' ? footerRows({ columnCount }) : footerRows}
|
|
518
|
+
</>
|
|
457
519
|
)}
|
|
458
520
|
</TableBody>
|
|
459
521
|
</Table>
|
|
460
|
-
</
|
|
522
|
+
</CardTable>
|
|
461
523
|
|
|
462
524
|
{pagination && (
|
|
463
|
-
<
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
525
|
+
<CardFooter className="border-t">
|
|
526
|
+
<TablePagination
|
|
527
|
+
className="w-full"
|
|
528
|
+
page={pagination.page}
|
|
529
|
+
pageSize={pagination.pageSize}
|
|
530
|
+
totalItems={pagination.totalItems ?? table.getPrePaginationRowModel().rows.length}
|
|
531
|
+
onPageChange={pagination.onPageChange}
|
|
532
|
+
onPageSizeChange={pagination.onPageSizeChange}
|
|
533
|
+
pageSizeOptions={pagination.pageSizeOptions}
|
|
534
|
+
getPageHref={pagination.getPageHref}
|
|
535
|
+
formatRange={pagination.formatRange}
|
|
536
|
+
navLabel={l.pagination?.navLabel}
|
|
537
|
+
previousLabel={l.pagination?.previousLabel}
|
|
538
|
+
nextLabel={l.pagination?.nextLabel}
|
|
539
|
+
pageSizeLabel={l.pagination?.pageSizeLabel}
|
|
540
|
+
/>
|
|
541
|
+
</CardFooter>
|
|
477
542
|
)}
|
|
543
|
+
</>
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
// `plain` renders a chrome-less stack instead of a Card so the bands and
|
|
547
|
+
// CardTable consume the HOST card's spacing variables (--card-px /
|
|
548
|
+
// --card-gap): edge cells align with the host's padding regardless of its
|
|
549
|
+
// size, and a trailing CardTable's negative margin reaches through the
|
|
550
|
+
// host's bottom padding so the last row sits flush against the host's edge.
|
|
551
|
+
// With no header band the leading CardTable's negative margin would eat the
|
|
552
|
+
// host's flex gap too and press the rows against the preceding content, so
|
|
553
|
+
// the stack restores that one gap as padding.
|
|
554
|
+
return frame === 'plain' ? (
|
|
555
|
+
<div
|
|
556
|
+
data-slot="data-table"
|
|
557
|
+
className={cn(
|
|
558
|
+
'flex flex-col gap-(--card-gap)',
|
|
559
|
+
!(showHeader || showBulk) && 'pt-(--card-gap)',
|
|
560
|
+
className,
|
|
561
|
+
)}
|
|
562
|
+
>
|
|
563
|
+
{bands}
|
|
478
564
|
</div>
|
|
565
|
+
) : (
|
|
566
|
+
<Card data-slot="data-table" className={className}>
|
|
567
|
+
{bands}
|
|
568
|
+
</Card>
|
|
479
569
|
);
|
|
480
570
|
}
|
|
481
571
|
|
|
@@ -493,7 +583,9 @@ export type {
|
|
|
493
583
|
Row,
|
|
494
584
|
RowSelectionState,
|
|
495
585
|
SortingState,
|
|
496
|
-
Table
|
|
586
|
+
// Not `Table`: that name is the Table atom. This is the TanStack instance
|
|
587
|
+
// type, as `onTableReady` hands it over.
|
|
588
|
+
Table as TableInstance,
|
|
497
589
|
TableOptions,
|
|
498
590
|
VisibilityState,
|
|
499
591
|
} from '@tanstack/react-table';
|
|
@@ -75,7 +75,9 @@ function DatePicker({
|
|
|
75
75
|
variant="outline"
|
|
76
76
|
disabled={disabled}
|
|
77
77
|
aria-invalid={invalid || undefined}
|
|
78
|
-
|
|
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"
|
|
79
81
|
/>
|
|
80
82
|
}
|
|
81
83
|
>
|
|
@@ -92,7 +92,9 @@ function DateRangePicker({
|
|
|
92
92
|
variant="outline"
|
|
93
93
|
disabled={disabled}
|
|
94
94
|
aria-invalid={invalid || undefined}
|
|
95
|
-
|
|
95
|
+
// Pickers sit in forms next to Inputs, so mirror the Input/Select
|
|
96
|
+
// trigger look (transparent bg) instead of the outline button fill.
|
|
97
|
+
className="min-w-0 flex-1 justify-start border-input bg-transparent font-normal hover:bg-transparent aria-expanded:bg-transparent"
|
|
96
98
|
/>
|
|
97
99
|
}
|
|
98
100
|
>
|
|
@@ -84,7 +84,9 @@ function DateTimePicker({
|
|
|
84
84
|
variant="outline"
|
|
85
85
|
disabled={disabled}
|
|
86
86
|
aria-invalid={invalid || undefined}
|
|
87
|
-
|
|
87
|
+
// Pickers sit in forms next to Inputs, so mirror the Input/Select
|
|
88
|
+
// trigger look (transparent bg) instead of the outline button fill.
|
|
89
|
+
className="min-w-0 flex-1 justify-start border-input bg-transparent font-normal hover:bg-transparent aria-expanded:bg-transparent"
|
|
88
90
|
/>
|
|
89
91
|
}
|
|
90
92
|
>
|