@vendure-io/ui 2.2.0 → 3.0.0-next.1
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 +19 -5
- package/src/components/atoms/accordion.tsx +21 -6
- package/src/components/atoms/alert-dialog.tsx +31 -6
- package/src/components/atoms/alert.tsx +72 -18
- package/src/components/atoms/avatar.tsx +12 -4
- package/src/components/atoms/badge.tsx +7 -2
- package/src/components/atoms/breadcrumb.tsx +493 -4
- package/src/components/atoms/button-group.tsx +30 -6
- package/src/components/atoms/button.tsx +128 -18
- package/src/components/atoms/calendar.tsx +6 -6
- package/src/components/atoms/card.tsx +130 -16
- package/src/components/atoms/carousel.tsx +16 -9
- package/src/components/atoms/chart.tsx +87 -1
- package/src/components/atoms/checkbox.tsx +85 -7
- package/src/components/atoms/collapsible.tsx +2 -1
- package/src/components/atoms/combobox.tsx +358 -29
- package/src/components/atoms/command.tsx +336 -13
- package/src/components/atoms/context-menu.tsx +28 -23
- package/src/components/atoms/dialog.tsx +173 -29
- package/src/components/atoms/direction.tsx +23 -2
- package/src/components/atoms/drawer.tsx +15 -10
- package/src/components/atoms/dropdown-menu.tsx +43 -28
- package/src/components/atoms/empty.tsx +5 -1
- package/src/components/atoms/field.tsx +41 -15
- package/src/components/atoms/hover-card.tsx +61 -8
- package/src/components/atoms/input-group.tsx +19 -11
- package/src/components/atoms/input-otp.tsx +6 -6
- package/src/components/atoms/input.tsx +7 -1
- package/src/components/atoms/item.tsx +3 -3
- package/src/components/atoms/kbd.tsx +32 -3
- package/src/components/atoms/label-swap.tsx +113 -0
- package/src/components/atoms/label.tsx +1 -1
- package/src/components/atoms/menubar.tsx +28 -26
- package/src/components/atoms/native-select.tsx +3 -2
- package/src/components/atoms/navigation-menu.tsx +13 -8
- package/src/components/atoms/pagination.tsx +2 -2
- package/src/components/atoms/popover.tsx +29 -6
- package/src/components/atoms/progress.tsx +46 -33
- package/src/components/atoms/radio-group.tsx +9 -4
- package/src/components/atoms/resizable.tsx +1 -1
- package/src/components/atoms/scroll-area.tsx +2 -2
- package/src/components/atoms/select.tsx +258 -19
- package/src/components/atoms/sheet.tsx +76 -23
- package/src/components/atoms/sidebar.tsx +405 -23
- package/src/components/atoms/skeleton.tsx +1 -1
- package/src/components/atoms/slider.tsx +1 -1
- package/src/components/atoms/sonner.tsx +128 -38
- package/src/components/atoms/spinner.tsx +1 -1
- package/src/components/atoms/switch.tsx +10 -5
- package/src/components/atoms/table.tsx +147 -7
- package/src/components/atoms/tabs.tsx +3 -3
- package/src/components/atoms/textarea.tsx +3 -1
- package/src/components/atoms/toggle-group.tsx +4 -2
- package/src/components/atoms/toggle.tsx +28 -6
- package/src/components/atoms/tooltip.tsx +85 -15
- package/src/components/molecules/anonymized-token.tsx +24 -8
- package/src/components/molecules/app-shell.tsx +53 -20
- package/src/components/molecules/arrow-link.tsx +40 -0
- package/src/components/molecules/chip.tsx +43 -4
- package/src/components/molecules/code-block.tsx +54 -31
- package/src/components/molecules/collapsible-section.tsx +129 -0
- package/src/components/molecules/confirm-dialog.tsx +122 -9
- package/src/components/molecules/copyable-text.tsx +75 -11
- package/src/components/molecules/count-badge.tsx +115 -0
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +32 -4
- package/src/components/molecules/data-table/data-table-column-header.tsx +20 -3
- package/src/components/molecules/data-table/data-table-filters.tsx +62 -22
- package/src/components/molecules/data-table/data-table-helpers.tsx +88 -1
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
- package/src/components/molecules/data-table/data-table-types.tsx +160 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +869 -81
- package/src/components/molecules/data-table/table-pagination.tsx +2 -2
- package/src/components/molecules/date-picker.tsx +13 -7
- package/src/components/molecules/date-range-picker.tsx +13 -6
- package/src/components/molecules/date-time-picker.tsx +13 -7
- package/src/components/molecules/date-time.tsx +8 -1
- package/src/components/molecules/direction-link.tsx +130 -0
- package/src/components/molecules/elapsed-time.tsx +223 -0
- package/src/components/molecules/file-dropzone.tsx +2 -2
- package/src/components/molecules/id-chip.tsx +169 -32
- package/src/components/molecules/inline-code.tsx +4 -0
- package/src/components/molecules/issued-secret.tsx +318 -0
- package/src/components/molecules/list-row.tsx +349 -0
- package/src/components/molecules/live-indicator.tsx +83 -0
- package/src/components/molecules/page-header.tsx +117 -5
- package/src/components/molecules/password-input.tsx +2 -2
- package/src/components/molecules/relative-time.tsx +85 -56
- package/src/components/molecules/search-trigger.tsx +111 -0
- package/src/components/molecules/secret-value.tsx +29 -9
- package/src/components/molecules/skip-link.tsx +1 -1
- package/src/components/molecules/stat-card.tsx +4 -4
- package/src/components/molecules/state-views/empty-state.tsx +35 -17
- package/src/components/molecules/state-views/error-state.tsx +32 -14
- package/src/components/molecules/status-badge.tsx +415 -49
- package/src/components/molecules/time-tooltip.tsx +140 -0
- package/src/components/molecules/timeline.tsx +246 -0
- package/src/components/molecules/visibility-icon.tsx +89 -0
- package/src/hooks/use-active-label-size.ts +66 -0
- package/src/hooks/use-apple-platform.ts +26 -0
- package/src/hooks/use-pinned-height.ts +55 -0
- package/src/hooks/use-scrolled.ts +27 -0
- package/src/lib/content-inset.ts +17 -0
- package/src/lib/control-name.ts +55 -0
- package/src/lib/dialog-padding.ts +48 -0
- package/src/lib/field-surface.ts +31 -0
- package/src/lib/format-elapsed.ts +67 -0
- package/src/lib/format-relative.ts +29 -1
- package/src/lib/highlight.ts +3 -3
- package/src/lib/menu-item.tsx +72 -0
- package/src/lib/outline-edge.ts +21 -0
- package/src/lib/popup-align.ts +67 -0
- package/src/lib/popup-direction.ts +22 -0
- package/src/lib/popup-motion.ts +19 -0
- package/src/lib/state-dictionary.ts +42 -6
- package/src/lib/syntax-colors.ts +8 -0
- package/src/lib/tint-recipes.ts +68 -0
- package/src/lib/tone-icons.ts +24 -0
- package/src/lib/trigger-slot.ts +16 -0
- package/src/lib/utils.ts +97 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
4
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
3
5
|
import {
|
|
4
6
|
type Column,
|
|
5
7
|
type ColumnDef,
|
|
@@ -12,13 +14,16 @@ import {
|
|
|
12
14
|
getSortedRowModel,
|
|
13
15
|
type OnChangeFn,
|
|
14
16
|
type PaginationState,
|
|
17
|
+
type Row,
|
|
15
18
|
type RowSelectionState,
|
|
16
19
|
type SortingState,
|
|
17
20
|
type TableOptions,
|
|
18
21
|
type TableState,
|
|
22
|
+
type Table as TanStackTable,
|
|
19
23
|
useReactTable,
|
|
20
24
|
type VisibilityState,
|
|
21
25
|
} from '@tanstack/react-table';
|
|
26
|
+
import { Button } from '@vendure-io/ui/components/atoms/button';
|
|
22
27
|
import { Card, CardFooter, CardHeader, CardTable } from '@vendure-io/ui/components/atoms/card';
|
|
23
28
|
import { Checkbox } from '@vendure-io/ui/components/atoms/checkbox';
|
|
24
29
|
import {
|
|
@@ -35,6 +40,7 @@ import {
|
|
|
35
40
|
TableHeader,
|
|
36
41
|
TableRow,
|
|
37
42
|
} from '@vendure-io/ui/components/atoms/table';
|
|
43
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
|
|
38
44
|
import {
|
|
39
45
|
DataTableBulkActions,
|
|
40
46
|
useSelectionCache,
|
|
@@ -47,6 +53,9 @@ import {
|
|
|
47
53
|
import type {
|
|
48
54
|
ControlledState,
|
|
49
55
|
DataTableProps,
|
|
56
|
+
DataTableRowCellProps,
|
|
57
|
+
DataTableRowRipple,
|
|
58
|
+
DataTableRowSelectProps,
|
|
50
59
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-types';
|
|
51
60
|
import { DataTableViewOptions } from '@vendure-io/ui/components/molecules/data-table/data-table-view-options';
|
|
52
61
|
import {
|
|
@@ -55,11 +64,23 @@ import {
|
|
|
55
64
|
ListHeaderControls,
|
|
56
65
|
} from '@vendure-io/ui/components/molecules/data-table/list-header';
|
|
57
66
|
import { TablePagination } from '@vendure-io/ui/components/molecules/data-table/table-pagination';
|
|
67
|
+
import { ListRowChevron } from '@vendure-io/ui/components/molecules/list-row';
|
|
58
68
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
59
|
-
import {
|
|
69
|
+
import { ChevronRight } from 'lucide-react';
|
|
70
|
+
import { AnimatePresence, MotionConfig, motion, useReducedMotion } from 'motion/react';
|
|
60
71
|
import * as React from 'react';
|
|
61
72
|
// Relative: `data-table-helpers` is closed in the package exports.
|
|
62
|
-
import {
|
|
73
|
+
import {
|
|
74
|
+
buildDisplayColumns,
|
|
75
|
+
columnAlign,
|
|
76
|
+
getSelectedRowIds,
|
|
77
|
+
measureColumnIndents,
|
|
78
|
+
resolveClearFilters,
|
|
79
|
+
resolveSlot,
|
|
80
|
+
sameIndents,
|
|
81
|
+
} from './data-table-helpers.tsx';
|
|
82
|
+
// Relative: `data-table-selection-storage` is closed in the package exports.
|
|
83
|
+
import { useSelectionStorage } from './data-table-selection-storage.tsx';
|
|
63
84
|
|
|
64
85
|
// Id of the generated row-actions column. Public: it is the `skeletonCells` key
|
|
65
86
|
// for the actions cell.
|
|
@@ -84,6 +105,152 @@ function DataTableSkeletonLine({ className, ...props }: React.ComponentProps<'di
|
|
|
84
105
|
);
|
|
85
106
|
}
|
|
86
107
|
|
|
108
|
+
// The row link is a stretched link, like ListRowLink: one real link per row,
|
|
109
|
+
// whose ::after covers the row (the row is `relative`), so a click on any point
|
|
110
|
+
// of the row opens it, while keyboard and screen reader users get one tab stop
|
|
111
|
+
// and one accessible name (the item name). The link itself is never positioned
|
|
112
|
+
// or transformed: a link with `position`, `transform` or `scale` (a pressed
|
|
113
|
+
// Button) becomes the containing block of its ::after, which then shrinks to
|
|
114
|
+
// the link text. The ::after takes z-index 1: cell content with its own
|
|
115
|
+
// stacking context (opacity below 1, as a `reveal="row"` StatusBadge at rest
|
|
116
|
+
// or mid-fade) would otherwise paint over it and swallow the click.
|
|
117
|
+
|
|
118
|
+
// Interactive elements of a linked row stack above the stretched ::after, so
|
|
119
|
+
// they keep their own click and their own tab stop: buttons and secondary
|
|
120
|
+
// links, Tooltip triggers and the copy chips (IdChip, AnonymizedToken,
|
|
121
|
+
// CopyableText: the whole chip stays the copy target, so their inner button
|
|
122
|
+
// stays static). The select checkbox is already positioned above it. Any other element that must stay
|
|
123
|
+
// clickable above the link takes `data-table-row-control`. The rules sit on
|
|
124
|
+
// the table, not on the built-in row, so a row from `renderRow` gets them too.
|
|
125
|
+
// The class names stay literal so Tailwind can scan them.
|
|
126
|
+
const LINKED_ROW_CLASS = cn(
|
|
127
|
+
'[&_tr:has([data-slot=data-table-row-link])]:relative [&_tr:has([data-slot=data-table-row-link])]:cursor-pointer',
|
|
128
|
+
// While rows are selected, a click selects: the row does not look like a link.
|
|
129
|
+
// Keyed on its own attribute, which a press on the select-all checkbox sets
|
|
130
|
+
// before the click (useSelectAllRipple): the cursor is inherited, so its
|
|
131
|
+
// change restyles every cell of every row.
|
|
132
|
+
'[&[data-selecting-cursor]_tr]:cursor-default!',
|
|
133
|
+
'[&_tr:has([data-slot=data-table-row-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]):not([data-slot=data-table-row-link],[data-slot=checkbox],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:relative',
|
|
134
|
+
'[&_tr:has([data-slot=data-table-row-link])_:is(a,button,input,select,textarea,[role=button],[tabindex],[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]):not([data-slot=data-table-row-link],[data-slot=checkbox],[data-slot=id-chip]_*,[data-slot=anonymized-token]_*,[data-slot=copyable-text]_*)]:z-10',
|
|
135
|
+
// Only the first row link of a row stretches. A later one (a variant's
|
|
136
|
+
// Product, rendered by the same link component) is a plain link above it,
|
|
137
|
+
// underlined on hover, without a chevron.
|
|
138
|
+
'[&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:relative [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:z-10 [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:underline-offset-4 [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-link]]:hover:underline [&_td:has([data-slot=data-table-row-link])~td_[data-slot=data-table-row-chevron]]:hidden',
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// A table with a row link keeps a slot for the row chevron after the last
|
|
142
|
+
// cell of every row, header included, so the chevron never covers a cell and
|
|
143
|
+
// a row without a link lines up with the others. The chevron is 15px and sits
|
|
144
|
+
// one 12px gap after the last cell, like ListRowChevron. Important: CardTable
|
|
145
|
+
// sets the edge padding with a descendant rule.
|
|
146
|
+
const ROW_CHEVRON_SLOT_CLASS =
|
|
147
|
+
'[&:has([data-slot=data-table-row-link])_tr>*:last-child]:pe-[calc(var(--card-px)+--spacing(7))]!';
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Opens the row's item from any point of the row. Render it in the cell that
|
|
151
|
+
* names the item, around the name: its children are the accessible name of
|
|
152
|
+
* the row. Only the first one of a row stretches; one in a later cell (the
|
|
153
|
+
* variant's Product) is a plain link above it. Pass `href`, or `render={<Link to="…" />}` for a
|
|
154
|
+
* router link. Do not render it as a Button.
|
|
155
|
+
*
|
|
156
|
+
* Its ::after stretches over the row. Buttons, links, inputs, Tooltip
|
|
157
|
+
* triggers, the select checkbox and the copy chips (IdChip, AnonymizedToken,
|
|
158
|
+
* CopyableText) in the row sit above it and keep their own action; mark any other control
|
|
159
|
+
* with `data-table-row-control`. Keyboard focus draws an inset ring around the
|
|
160
|
+
* row. While the row is hovered or holds keyboard focus, a chevron appears at
|
|
161
|
+
* the end of the row: it fades in and slides 3px toward the end (fade only
|
|
162
|
+
* under reduced motion). It is decorative: the link carries the name.
|
|
163
|
+
*
|
|
164
|
+
* While rows are selected, a click on a built-in row selects it, and only
|
|
165
|
+
* the name opens the item. A row from `renderRow` does the same when it
|
|
166
|
+
* spreads `ctx.selectProps`; without it, its link keeps covering the row. The link stops stretching over the row and the row-end
|
|
167
|
+
* chevron hides. Hovering the row shows a small chevron after the name;
|
|
168
|
+
* hovering or focusing the name colours it and the chevron blue, and the
|
|
169
|
+
* chevron moves 2px toward the end. The blue is `brand-text`, the brand
|
|
170
|
+
* step that reads as text: `brand-indicator` is a mark colour and reads below
|
|
171
|
+
* 3:1 as text on a light selected row. The chevron overlays the
|
|
172
|
+
* cell's padding, so the name and the column do not move. The name stays a
|
|
173
|
+
* tab stop and a link, and its focus ring is drawn around the name.
|
|
174
|
+
*
|
|
175
|
+
* A link with no visible text (its children are `sr-only`, as when the cell
|
|
176
|
+
* shows the item's code as a copy chip) has no name to click. While rows are
|
|
177
|
+
* selected its target is the row-end chevron: it covers the chevron slot at
|
|
178
|
+
* the end of the row, the full row height, the chevron stays on row hover and
|
|
179
|
+
* turns blue on the target's hover or focus, and the focus ring goes around
|
|
180
|
+
* the slot. A click anywhere else on the row selects it.
|
|
181
|
+
*/
|
|
182
|
+
function DataTableRowLink({
|
|
183
|
+
className,
|
|
184
|
+
render,
|
|
185
|
+
children,
|
|
186
|
+
...props
|
|
187
|
+
}: useRender.ComponentProps<'a'>) {
|
|
188
|
+
// A link whose text is all screen-reader only (a code shown as a copy chip
|
|
189
|
+
// next to it) has no visible name to click while rows are selected. Then its
|
|
190
|
+
// target is the row-end chevron instead.
|
|
191
|
+
const linkRef = React.useRef<HTMLAnchorElement>(null);
|
|
192
|
+
const [nameless, setNameless] = React.useState(false);
|
|
193
|
+
React.useLayoutEffect(() => {
|
|
194
|
+
const link = linkRef.current;
|
|
195
|
+
if (link) setNameless(link.getBoundingClientRect().width < 1);
|
|
196
|
+
});
|
|
197
|
+
return useRender({
|
|
198
|
+
defaultTagName: 'a',
|
|
199
|
+
render,
|
|
200
|
+
ref: linkRef,
|
|
201
|
+
props: mergeProps<'a'>(
|
|
202
|
+
{
|
|
203
|
+
className: cn(
|
|
204
|
+
'group/row-link cursor-pointer font-medium text-foreground outline-none',
|
|
205
|
+
'after:absolute after:inset-0 after:z-1 focus-visible:after:outline-2 focus-visible:after:-outline-offset-2 focus-visible:after:outline-ring focus-visible:after:outline-solid',
|
|
206
|
+
// While rows are selected only the name is the link (see above).
|
|
207
|
+
'in-data-click-selects:after:hidden in-data-click-selects:rounded-sm in-data-click-selects:transition-colors in-data-click-selects:duration-quick in-data-click-selects:ease-soft',
|
|
208
|
+
'in-data-click-selects:hover:text-brand-text in-data-click-selects:focus-visible:text-brand-text',
|
|
209
|
+
'in-data-click-selects:focus-visible:outline-2 in-data-click-selects:focus-visible:outline-offset-2 in-data-click-selects:focus-visible:outline-ring in-data-click-selects:focus-visible:outline-solid',
|
|
210
|
+
// Without a visible name, the link covers the row-end chevron slot
|
|
211
|
+
// instead: the full row height, as wide as the slot. Its focus ring
|
|
212
|
+
// is drawn around that slot.
|
|
213
|
+
'in-data-click-selects:data-nameless:after:block in-data-click-selects:data-nameless:after:start-auto in-data-click-selects:data-nameless:after:w-[calc(var(--card-px)+--spacing(7))] in-data-click-selects:data-nameless:after:rounded-md',
|
|
214
|
+
'in-data-click-selects:data-nameless:focus-visible:outline-none',
|
|
215
|
+
className,
|
|
216
|
+
),
|
|
217
|
+
children: (
|
|
218
|
+
<>
|
|
219
|
+
{children}
|
|
220
|
+
{/* An empty inline box at the end of the name, so the chevron after
|
|
221
|
+
the name is placed without taking any space. */}
|
|
222
|
+
<span aria-hidden="true" data-slot="data-table-row-link-mark" className="relative">
|
|
223
|
+
<ChevronRight
|
|
224
|
+
strokeWidth={1.75}
|
|
225
|
+
className={cn(
|
|
226
|
+
'pointer-events-none absolute start-1 top-1/2 size-3.75 -translate-y-1/2 opacity-0 rtl:-scale-x-100',
|
|
227
|
+
'[transition:opacity_var(--transition-duration-moderate)_var(--ease-soft),translate_var(--transition-duration-normal)_var(--ease-out)]',
|
|
228
|
+
'in-data-click-selects:group-hover/row:opacity-45 in-data-click-selects:group-hover/row-link:opacity-100 in-data-click-selects:group-focus-visible/row-link:opacity-100',
|
|
229
|
+
'in-data-click-selects:group-hover/row-link:translate-x-0.5 in-data-click-selects:group-focus-visible/row-link:translate-x-0.5 rtl:in-data-click-selects:group-hover/row-link:-translate-x-0.5 rtl:in-data-click-selects:group-focus-visible/row-link:-translate-x-0.5',
|
|
230
|
+
'motion-reduce:translate-x-0!',
|
|
231
|
+
)}
|
|
232
|
+
/>
|
|
233
|
+
</span>
|
|
234
|
+
<ListRowChevron
|
|
235
|
+
data-slot="data-table-row-chevron"
|
|
236
|
+
className={cn(
|
|
237
|
+
'pointer-events-none absolute end-(--card-px) top-1/2 -translate-y-1/2 in-data-selecting:hidden',
|
|
238
|
+
// The target of a link without a visible name while rows are
|
|
239
|
+
// selected: shown on row hover, blue on its own hover or focus.
|
|
240
|
+
'in-data-click-selects:group-data-nameless/row-link:block in-data-click-selects:group-data-nameless/row-link:transition-[opacity,translate,color]',
|
|
241
|
+
'in-data-click-selects:group-data-nameless/row-link:group-hover/row-link:text-brand-text in-data-click-selects:group-data-nameless/row-link:group-focus-visible/row-link:text-brand-text',
|
|
242
|
+
)}
|
|
243
|
+
/>
|
|
244
|
+
</>
|
|
245
|
+
),
|
|
246
|
+
},
|
|
247
|
+
props,
|
|
248
|
+
),
|
|
249
|
+
// `nameless` renders as `data-nameless` while true.
|
|
250
|
+
state: { slot: 'data-table-row-link', nameless },
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
87
254
|
// The composition root. Owns the single `useReactTable` instance and the
|
|
88
255
|
// controlled/uncontrolled bridge, then lays out the card-framed table anatomy:
|
|
89
256
|
// a CardHeader band (header → controls → chips → bulk overlay), a CardTable
|
|
@@ -134,6 +301,323 @@ const bandRowFade = {
|
|
|
134
301
|
transition: { duration: 0.1, ease: 'easeOut' },
|
|
135
302
|
} as const;
|
|
136
303
|
|
|
304
|
+
// The bulk bar enters after what it replaces has faded out: `bandRowFade`
|
|
305
|
+
// after one --transition-duration-fast. It covers the controls row's place, or
|
|
306
|
+
// with no controls row (no header, or a title only) the column header row, so
|
|
307
|
+
// it never opens a row of its own and the table never moves.
|
|
308
|
+
const bulkBarFade = {
|
|
309
|
+
...bandRowFade,
|
|
310
|
+
animate: { ...bandRowFade.animate, transition: { ...bandRowFade.transition, delay: 0.1 } },
|
|
311
|
+
} as const;
|
|
312
|
+
|
|
313
|
+
// The controls row while the bulk bar takes its place: faded out, then hidden;
|
|
314
|
+
// back only after the bar has left.
|
|
315
|
+
const controlsSwap = {
|
|
316
|
+
hidden: {
|
|
317
|
+
...bandRowFade.exit,
|
|
318
|
+
transition: bandRowFade.transition,
|
|
319
|
+
transitionEnd: { visibility: 'hidden' },
|
|
320
|
+
},
|
|
321
|
+
shown: {
|
|
322
|
+
...bandRowFade.animate,
|
|
323
|
+
visibility: 'visible',
|
|
324
|
+
transition: { ...bandRowFade.transition, delay: 0.1 },
|
|
325
|
+
},
|
|
326
|
+
} as const;
|
|
327
|
+
|
|
328
|
+
// The labels under a covering bulk bar: hidden (so their sort controls leave
|
|
329
|
+
// the tab order) once they have faded out, and back only after the bar left.
|
|
330
|
+
const HEADER_LABEL_UNDER_BULK_CLASS =
|
|
331
|
+
'transition-[opacity,visibility] duration-fast ease-soft delay-(--transition-duration-fast) in-data-bulk-over-header:invisible in-data-bulk-over-header:opacity-0 in-data-bulk-over-header:delay-0';
|
|
332
|
+
|
|
333
|
+
// While rows are selected, a click on a row selects it instead of opening it.
|
|
334
|
+
// These elements in a row keep their own click: the same list the linked row
|
|
335
|
+
// lifts above its stretched link, plus the select checkbox and menu items. The
|
|
336
|
+
// row link is not one of them: while rows are selected it does not stretch,
|
|
337
|
+
// and the click handler lets a click on the name through. Only a
|
|
338
|
+
// control inside the row counts: an ancestor of the table that matches (an app
|
|
339
|
+
// shell's `<main tabindex="-1">`, the skip link target) is not a row control.
|
|
340
|
+
const ROW_CONTROL_SELECTOR =
|
|
341
|
+
'[data-slot=data-table-select-area],a:not([data-slot=data-table-row-link]),button,input,select,textarea,[role=button],[role=checkbox],[role=menuitem],[tabindex]:not([data-slot=data-table-row-link]),[data-tooltip-trigger],[data-slot=id-chip],[data-slot=anonymized-token],[data-slot=copyable-text],[data-table-row-control]';
|
|
342
|
+
|
|
343
|
+
// The select gutter is `--spacing(10)`, 40px: the checkbox (8px in, 16px wide,
|
|
344
|
+
// ending at 24px), a 5px gap, then the 11px `--content-inset` of a sortable
|
|
345
|
+
// header (DataTableColumnHeader pulls its pill back by that much so its label
|
|
346
|
+
// starts with the cell text). A narrower gutter puts the hovered or sorted
|
|
347
|
+
// header pill over the select-all checkbox. Every rule that uses the gutter
|
|
348
|
+
// (the select area, the leading cell, the bulk bar over the header) writes
|
|
349
|
+
// `--spacing(10)`; change them together.
|
|
350
|
+
//
|
|
351
|
+
// The click area of a select checkbox is its whole cell: the full height of
|
|
352
|
+
// the row, from the table's start edge to where the leading cell's content
|
|
353
|
+
// starts (its gutter plus its indent). The select cell is
|
|
354
|
+
// zero-width, so the area is floated over that gutter, under the checkbox and
|
|
355
|
+
// above the row link's stretched ::after. It is not focusable: keyboard focus
|
|
356
|
+
// and the focus ring stay on the checkbox. The checkbox's own enlarged hit
|
|
357
|
+
// area is turned off here, since it reached past the gutter into the content.
|
|
358
|
+
const SELECT_AREA_CLASS =
|
|
359
|
+
'absolute inset-y-0 start-0 z-10 w-[calc(var(--spacing)*10+var(--column-indent,0px))]';
|
|
360
|
+
const SELECT_CHECKBOX_HIT_CLASS = 'after:hidden';
|
|
361
|
+
|
|
362
|
+
// Select all and clear all from the header checkbox ripple down the page: the
|
|
363
|
+
// change starts at the header checkbox and travels down, row by row. A row's
|
|
364
|
+
// fill, bar and checkbox move together, each with its own transition, only
|
|
365
|
+
// delayed. The selection itself changes at once, so a click during the ripple
|
|
366
|
+
// lands on the final state; only the look lags behind, for at most the
|
|
367
|
+
// ripple's length plus a row's own transition.
|
|
368
|
+
//
|
|
369
|
+
// The table carries `data-select-ripple` (select or clear) while it runs.
|
|
370
|
+
// `--select-ripple-length` is when the last row starts: `normal` (200ms) for
|
|
371
|
+
// select all, `fast` (100ms) for clear all and for the keyboard
|
|
372
|
+
// (`data-select-ripple-quick`). It does not grow with the number of rows: 50
|
|
373
|
+
// rows take as long as 10, each row gets a shorter share (see
|
|
374
|
+
// SELECT_RIPPLE_ROWS). The rows start on an
|
|
375
|
+
// ease-out (sine) curve: a row's start is `asin(index / rows)` of the length,
|
|
376
|
+
// so the first rows below the header follow each other fastest and the ripple
|
|
377
|
+
// settles towards the bottom. Each row carries its start and its share as
|
|
378
|
+
// fractions (`--ripple-at`, `--ripple-span`, see rippleTiming).
|
|
379
|
+
//
|
|
380
|
+
// The bar reads as one line that grows down from the header: each row's two
|
|
381
|
+
// halves grow from the row's top edge, linearly, over the row's share, so the
|
|
382
|
+
// next row picks up exactly where this one ends. Clearing retracts the line
|
|
383
|
+
// from the top in the same order. Each row's bar also fades in and widens as
|
|
384
|
+
// it does alone (see the bar in atoms/table), from the row's delay, so the
|
|
385
|
+
// newest part of the line is the faintest and thinnest; clearing fades it in
|
|
386
|
+
// `fast`. A row the select ripple has not reached yet
|
|
387
|
+
// starts from its top edge with no transition, so it does not first slide
|
|
388
|
+
// from its middle; that start is set, and the style flushed, before the
|
|
389
|
+
// selection changes (useSelectAllRipple). Only `clip-path`, `opacity`, `scale` and the
|
|
390
|
+
// row's existing colour transition move; nothing changes layout.
|
|
391
|
+
const SELECT_RIPPLE_TABLE_CLASS =
|
|
392
|
+
'[--select-ripple-length:var(--transition-duration-fast)] data-[select-ripple=select]:[--select-ripple-length:var(--transition-duration-normal)] data-select-ripple-quick:[--select-ripple-length:var(--transition-duration-fast)]!';
|
|
393
|
+
const SELECT_RIPPLE_ROW_CLASS = cn(
|
|
394
|
+
'[--row-ripple-delay:calc(var(--select-ripple-length)*var(--ripple-at,0))] [--row-ripple-span:calc(var(--select-ripple-length)*var(--ripple-span,0))]',
|
|
395
|
+
'in-data-select-ripple:[transition-delay:var(--row-ripple-delay)]',
|
|
396
|
+
'in-data-[select-ripple=select]:before:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-moderate)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-moderate)_var(--ease-out)_var(--row-ripple-delay)]! in-data-[select-ripple=select]:after:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-moderate)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-moderate)_var(--ease-out)_var(--row-ripple-delay)]!',
|
|
397
|
+
'in-data-[select-ripple=clear]:before:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay)]! in-data-[select-ripple=clear]:after:[transition:clip-path_var(--row-ripple-span)_linear_var(--row-ripple-delay),opacity_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay),scale_var(--transition-duration-fast)_var(--ease-soft)_var(--row-ripple-delay)]!',
|
|
398
|
+
'in-data-[select-ripple=select]:not-data-[state=selected]:before:[clip-path:inset(0_0_100%_0)]! in-data-[select-ripple=select]:not-data-[state=selected]:after:[clip-path:inset(0_0_100%_0)]!',
|
|
399
|
+
'in-data-[select-ripple=select]:not-data-[state=selected]:before:[transition:none]! in-data-[select-ripple=select]:not-data-[state=selected]:after:[transition:none]!',
|
|
400
|
+
'in-data-[select-ripple=clear]:not-data-[state=selected]:before:[clip-path:inset(100%_0_0_0)]! in-data-[select-ripple=clear]:not-data-[state=selected]:after:[clip-path:inset(100%_0_0_0)]!',
|
|
401
|
+
);
|
|
402
|
+
// The row checkbox keeps its own transitions (the fill, the mark revealed with
|
|
403
|
+
// it, the fade in) and only takes the row's delay. Row checkboxes are never
|
|
404
|
+
// indeterminate, so their mark never swaps and needs no delay.
|
|
405
|
+
const SELECT_RIPPLE_CHECKBOX_CLASS =
|
|
406
|
+
'in-data-select-ripple:[transition-delay:var(--row-ripple-delay)]! in-data-select-ripple:before:[transition-delay:var(--row-ripple-delay)]! in-data-select-ripple:[&>[data-slot=checkbox-indicator]]:[transition-delay:var(--row-ripple-delay)]!';
|
|
407
|
+
// Long enough for the last row to start (`normal`) and finish its slowest
|
|
408
|
+
// transition (the checkbox fill and mark, under 400ms).
|
|
409
|
+
const SELECT_RIPPLE_SETTLE_MS = 700;
|
|
410
|
+
|
|
411
|
+
// The ripple spreads over at most this many rows, about two screens of rows.
|
|
412
|
+
// Spread over all 50 rows of a long page, the rows on screen would pass in a
|
|
413
|
+
// few milliseconds and the page would look like it changed at once; this way
|
|
414
|
+
// the rows on screen ripple the same on a page of 20 or of 50. Rows below it
|
|
415
|
+
// start together at the end of the ripple, usually out of view.
|
|
416
|
+
const SELECT_RIPPLE_ROWS = 20;
|
|
417
|
+
|
|
418
|
+
/** Where a row starts in the ripple and its share of it, as fractions of the length. */
|
|
419
|
+
function rippleTiming(index: number, count: number): React.CSSProperties {
|
|
420
|
+
const rows = Math.min(count, SELECT_RIPPLE_ROWS);
|
|
421
|
+
const at = (position: number) => Math.asin(Math.min(position / rows, 1)) / (Math.PI / 2);
|
|
422
|
+
const start = Math.min(index, rows - 1);
|
|
423
|
+
return {
|
|
424
|
+
'--ripple-at': at(start).toFixed(4),
|
|
425
|
+
'--ripple-span': (at(start + 1) - at(start)).toFixed(4),
|
|
426
|
+
} as React.CSSProperties;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Select all and clear all with the ripple. While a ripple runs, the next one
|
|
431
|
+
* takes over from wherever each row is: the transitions retarget, nothing
|
|
432
|
+
* restarts from zero. Reduced motion: no ripple, the rows change together.
|
|
433
|
+
* Any other selection change (a row click) ends the ripple first, so it is
|
|
434
|
+
* not delayed.
|
|
435
|
+
*
|
|
436
|
+
* It also owns `data-selecting-cursor`, the row cursor while rows are
|
|
437
|
+
* selected. A press on the select-all checkbox prepares the click in the
|
|
438
|
+
* frames between press and release, where nothing else happens: it sets the
|
|
439
|
+
* ripple's start and the row cursor the click will need. The click then
|
|
440
|
+
* changes only the rows' selection. The pointer is on the header meanwhile,
|
|
441
|
+
* so no row shows its cursor early. A press that ends without a click puts
|
|
442
|
+
* both back. A click without a prepared frame (Space, a fast synthetic click)
|
|
443
|
+
* does the same work in its own frame.
|
|
444
|
+
*/
|
|
445
|
+
function useSelectAllRipple(
|
|
446
|
+
tableRef: React.RefObject<HTMLTableElement | null>,
|
|
447
|
+
/** Whether rows are selected, as of the last render. */
|
|
448
|
+
selectingRef: React.RefObject<boolean>,
|
|
449
|
+
) {
|
|
450
|
+
const reduceMotion = useReducedMotion();
|
|
451
|
+
const reduceMotionRef = React.useRef(reduceMotion);
|
|
452
|
+
reduceMotionRef.current = reduceMotion;
|
|
453
|
+
const timer = React.useRef<number | undefined>(undefined);
|
|
454
|
+
const prepared = React.useRef<SelectAllPrep | null>(null);
|
|
455
|
+
React.useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
456
|
+
// Every commit puts the cursor in line with the selection, unless a press
|
|
457
|
+
// is waiting for its click.
|
|
458
|
+
React.useLayoutEffect(() => {
|
|
459
|
+
if (prepared.current == null) {
|
|
460
|
+
tableRef.current?.toggleAttribute('data-selecting-cursor', selectingRef.current);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
return React.useMemo(() => {
|
|
464
|
+
const end = () => {
|
|
465
|
+
window.clearTimeout(timer.current);
|
|
466
|
+
const element = tableRef.current;
|
|
467
|
+
if (!element) return;
|
|
468
|
+
delete element.dataset.selectRipple;
|
|
469
|
+
delete element.dataset.selectRippleQuick;
|
|
470
|
+
};
|
|
471
|
+
const setRipple = (element: HTMLElement, value: boolean, quick: boolean) => {
|
|
472
|
+
element.dataset.selectRipple = value ? 'select' : 'clear';
|
|
473
|
+
if (quick) element.dataset.selectRippleQuick = '';
|
|
474
|
+
else delete element.dataset.selectRippleQuick;
|
|
475
|
+
};
|
|
476
|
+
// `quick` asks for the keyboard's ripple. A click after a pointer press is
|
|
477
|
+
// never quick: Base UI hands the checkbox's click over as its hidden
|
|
478
|
+
// input's click, with detail 0, which reads as the keyboard.
|
|
479
|
+
const toggleAll = <TData,>(table: TanStackTable<TData>, value: boolean, keyboard: boolean) => {
|
|
480
|
+
const prep = prepared.current;
|
|
481
|
+
prepared.current = null;
|
|
482
|
+
const quick = keyboard && prep == null;
|
|
483
|
+
const element = tableRef.current;
|
|
484
|
+
if (!element || reduceMotionRef.current) {
|
|
485
|
+
end();
|
|
486
|
+
table.toggleAllPageRowsSelected(value);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
// Prepared for this click, and a frame has shown the start: nothing to
|
|
490
|
+
// flush. Otherwise a fresh select ripple lets the rows take their start
|
|
491
|
+
// (the bar at the top edge) before the selection changes, or they would
|
|
492
|
+
// transition from their middle. A running ripple is not flushed: its
|
|
493
|
+
// rows retarget from where they are.
|
|
494
|
+
const ready = prep?.shown === true && prep.value === value;
|
|
495
|
+
const running = !ready && element.dataset.selectRipple != null;
|
|
496
|
+
setRipple(element, value, quick);
|
|
497
|
+
if (!ready && !running) void element.offsetHeight;
|
|
498
|
+
table.toggleAllPageRowsSelected(value);
|
|
499
|
+
window.clearTimeout(timer.current);
|
|
500
|
+
timer.current = window.setTimeout(end, SELECT_RIPPLE_SETTLE_MS);
|
|
501
|
+
};
|
|
502
|
+
// A press on the select-all checkbox: `value` is what its click will set,
|
|
503
|
+
// `selectingAfter` whether rows stay selected after it.
|
|
504
|
+
const prepare = (value: boolean, selectingAfter: boolean) => {
|
|
505
|
+
const element = tableRef.current;
|
|
506
|
+
if (!element || prepared.current != null) return;
|
|
507
|
+
const prep: SelectAllPrep = {
|
|
508
|
+
value,
|
|
509
|
+
shown: false,
|
|
510
|
+
ripple: element.dataset.selectRipple,
|
|
511
|
+
};
|
|
512
|
+
prepared.current = prep;
|
|
513
|
+
// After the frame that shows the press, so the press stays quick.
|
|
514
|
+
requestAnimationFrame(() =>
|
|
515
|
+
window.setTimeout(() => {
|
|
516
|
+
if (prepared.current !== prep) return;
|
|
517
|
+
element.toggleAttribute('data-selecting-cursor', selectingAfter);
|
|
518
|
+
if (!reduceMotionRef.current && prep.ripple == null) setRipple(element, value, false);
|
|
519
|
+
requestAnimationFrame(() =>
|
|
520
|
+
window.setTimeout(() => {
|
|
521
|
+
if (prepared.current === prep) prep.shown = true;
|
|
522
|
+
}),
|
|
523
|
+
);
|
|
524
|
+
}),
|
|
525
|
+
);
|
|
526
|
+
// The click, if there is one, comes in the same task as the release.
|
|
527
|
+
const release = () => {
|
|
528
|
+
window.removeEventListener('pointerup', release, true);
|
|
529
|
+
window.removeEventListener('pointercancel', release, true);
|
|
530
|
+
window.setTimeout(() => {
|
|
531
|
+
if (prepared.current !== prep) return;
|
|
532
|
+
prepared.current = null;
|
|
533
|
+
if (prep.ripple == null) {
|
|
534
|
+
delete element.dataset.selectRipple;
|
|
535
|
+
delete element.dataset.selectRippleQuick;
|
|
536
|
+
}
|
|
537
|
+
element.toggleAttribute('data-selecting-cursor', selectingRef.current);
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
window.addEventListener('pointerup', release, true);
|
|
541
|
+
window.addEventListener('pointercancel', release, true);
|
|
542
|
+
};
|
|
543
|
+
return { toggleAll, end, prepare };
|
|
544
|
+
}, [tableRef, selectingRef]);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
type SelectAllPrep = {
|
|
548
|
+
value: boolean;
|
|
549
|
+
/** A frame has shown the prepared start since the press. */
|
|
550
|
+
shown: boolean;
|
|
551
|
+
/** A running ripple at the press; without one, a press with no click removes the prepared start. */
|
|
552
|
+
ripple: string | undefined;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* A press on the select-all checkbox: its click selects the whole page unless
|
|
557
|
+
* all of it is selected, and rows stay selected after it unless it clears the
|
|
558
|
+
* last of them (rows selected on other pages stay).
|
|
559
|
+
*/
|
|
560
|
+
function prepareSelectAll<TData>(
|
|
561
|
+
table: TanStackTable<TData>,
|
|
562
|
+
ripple: { prepare: (value: boolean, selectingAfter: boolean) => void },
|
|
563
|
+
) {
|
|
564
|
+
const value = !table.getIsAllPageRowsSelected();
|
|
565
|
+
const pageIds = new Set(table.getRowModel().rows.map((row) => row.id));
|
|
566
|
+
const otherPages = getSelectedRowIds(table.getState().rowSelection).some(
|
|
567
|
+
(id) => !pageIds.has(id),
|
|
568
|
+
);
|
|
569
|
+
ripple.prepare(value, value || otherPages);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** A checkbox toggled with Space: a keyboard event, or a click with no pointer (detail 0). */
|
|
573
|
+
function fromKeyboard(event: Event | undefined): boolean {
|
|
574
|
+
return (
|
|
575
|
+
(typeof KeyboardEvent !== 'undefined' && event instanceof KeyboardEvent) ||
|
|
576
|
+
(typeof MouseEvent !== 'undefined' && event instanceof MouseEvent && event.detail === 0)
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// How far a press may move before release and still count as a click on the row.
|
|
581
|
+
const ROW_PRESS_SLOP = 4;
|
|
582
|
+
|
|
583
|
+
function isRowControl(target: Element, row: Element): boolean {
|
|
584
|
+
const control = target.closest(ROW_CONTROL_SELECTOR);
|
|
585
|
+
return control != null && row.contains(control);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Toggles a row from a click on it or on its checkbox. With `extend` (Shift),
|
|
590
|
+
* when the last clicked row is on this page, every row between the two takes
|
|
591
|
+
* the clicked row's new state. The clicked row becomes the next anchor.
|
|
592
|
+
*/
|
|
593
|
+
function selectFromClick<TData>(
|
|
594
|
+
table: TanStackTable<TData>,
|
|
595
|
+
row: Row<TData>,
|
|
596
|
+
extend: boolean,
|
|
597
|
+
anchor: React.MutableRefObject<string | null>,
|
|
598
|
+
value = !row.getIsSelected(),
|
|
599
|
+
) {
|
|
600
|
+
const pageRows = table.getRowModel().rows;
|
|
601
|
+
const from =
|
|
602
|
+
extend && anchor.current != null ? pageRows.findIndex((r) => r.id === anchor.current) : -1;
|
|
603
|
+
const to = pageRows.findIndex((r) => r.id === row.id);
|
|
604
|
+
anchor.current = row.id;
|
|
605
|
+
if (from < 0 || to < 0) {
|
|
606
|
+
row.toggleSelected(value);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const range = pageRows.slice(Math.min(from, to), Math.max(from, to) + 1);
|
|
610
|
+
table.setRowSelection((old) => {
|
|
611
|
+
const next = { ...old };
|
|
612
|
+
for (const r of range) {
|
|
613
|
+
if (!r.getCanSelect()) continue;
|
|
614
|
+
if (value) next[r.id] = true;
|
|
615
|
+
else delete next[r.id];
|
|
616
|
+
}
|
|
617
|
+
return next;
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
|
|
137
621
|
function ariaSort<TData>(
|
|
138
622
|
hasSorting: boolean,
|
|
139
623
|
column: Column<TData, unknown>,
|
|
@@ -155,6 +639,7 @@ function DataTable<TData>({
|
|
|
155
639
|
filters,
|
|
156
640
|
columnVisibility,
|
|
157
641
|
rowSelection,
|
|
642
|
+
selectionStorageKey,
|
|
158
643
|
header,
|
|
159
644
|
toolbar,
|
|
160
645
|
bulkActions,
|
|
@@ -185,17 +670,19 @@ function DataTable<TData>({
|
|
|
185
670
|
);
|
|
186
671
|
}
|
|
187
672
|
|
|
188
|
-
// Resolve labels once per `labels` identity
|
|
189
|
-
// deps for the display-column memo below.
|
|
673
|
+
// Resolve labels once per `labels` identity.
|
|
190
674
|
const l = React.useMemo(
|
|
191
675
|
() => ({
|
|
192
676
|
empty: labels?.empty ?? 'No results',
|
|
193
677
|
selectAllRows: labels?.selectAllRows ?? 'Select all rows',
|
|
678
|
+
selectAllOnPage: labels?.selectAllOnPage ?? 'Select all on this page',
|
|
679
|
+
clearPageSelection: labels?.clearPageSelection ?? 'Clear selection on this page',
|
|
194
680
|
selectRow: labels?.selectRow ?? ((index: number) => `Select row ${index + 1}`),
|
|
195
681
|
rowActions: labels?.rowActions ?? 'Open row actions',
|
|
196
682
|
columnsTrigger: labels?.columnsTrigger ?? 'Columns',
|
|
197
683
|
columnsHeading: labels?.columnsHeading ?? 'Toggle columns',
|
|
198
684
|
addFilter: labels?.addFilter ?? 'Add filter',
|
|
685
|
+
clearFilters: labels?.clearFilters ?? 'Clear filters',
|
|
199
686
|
removeFilter:
|
|
200
687
|
labels?.removeFilter ?? ((columnLabel: string) => `Remove ${columnLabel} filter`),
|
|
201
688
|
sortLabel: labels?.sortLabel ?? ((columnLabel: string) => `Sort by ${columnLabel}`),
|
|
@@ -214,17 +701,34 @@ function DataTable<TData>({
|
|
|
214
701
|
columnVisibility,
|
|
215
702
|
{},
|
|
216
703
|
);
|
|
704
|
+
const storedRowSelection = useSelectionStorage(selectionStorageKey, rowSelection);
|
|
217
705
|
const [selectionState, onRowSelectionChange] = useControlledTableState<RowSelectionState>(
|
|
218
|
-
|
|
706
|
+
storedRowSelection,
|
|
219
707
|
{},
|
|
220
708
|
);
|
|
221
709
|
const selectColumnId = rowSelection?.selectColumnId ?? 'select';
|
|
222
710
|
|
|
711
|
+
// The display-column cells read labels and `rowActions` through this ref, so
|
|
712
|
+
// the column defs below depend only on which display columns exist. A new
|
|
713
|
+
// cell function is a new component type to React: it remounts the cell, and
|
|
714
|
+
// a checkbox toggled from the keyboard loses focus. Consumers pass
|
|
715
|
+
// `rowSelection`, `rowActions` and `labels` inline, so those identities
|
|
716
|
+
// change on every selection change.
|
|
717
|
+
// The last row a click selected or deselected: the start of a Shift+click range.
|
|
718
|
+
const selectionAnchor = React.useRef<string | null>(null);
|
|
719
|
+
const tableRef = React.useRef<HTMLTableElement>(null);
|
|
720
|
+
const selectingRef = React.useRef(false);
|
|
721
|
+
const selectAllRipple = useSelectAllRipple(tableRef, selectingRef);
|
|
722
|
+
const displayProps = React.useRef({ l, rowActions });
|
|
723
|
+
displayProps.current = { l, rowActions };
|
|
724
|
+
const hasRowSelection = rowSelection != null;
|
|
725
|
+
const hasRowActions = rowActions != null;
|
|
726
|
+
|
|
223
727
|
// Inject the select/actions display columns around the data columns. `meta` on
|
|
224
728
|
// the consumer's columns is never touched — it's the dashboard's field-info seam.
|
|
225
729
|
const displayColumns = React.useMemo(() => {
|
|
226
730
|
// biome-ignore lint/suspicious/noExplicitAny: matches TanStack's ColumnDef value-type convention
|
|
227
|
-
const selectColumn: ColumnDef<TData, any> | undefined =
|
|
731
|
+
const selectColumn: ColumnDef<TData, any> | undefined = hasRowSelection
|
|
228
732
|
? {
|
|
229
733
|
id: selectColumnId,
|
|
230
734
|
enableSorting: false,
|
|
@@ -236,47 +740,105 @@ function DataTable<TData>({
|
|
|
236
740
|
// floated absolutely over the (zero-width) select cell so an empty
|
|
237
741
|
// selection reserves no gutter — no left gap to read as a bug.
|
|
238
742
|
header: ({ table }) => (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
743
|
+
<>
|
|
744
|
+
<span
|
|
745
|
+
aria-hidden
|
|
746
|
+
data-slot="data-table-select-area"
|
|
747
|
+
className={SELECT_AREA_CLASS}
|
|
748
|
+
onPointerDown={() => prepareSelectAll(table, selectAllRipple)}
|
|
749
|
+
onClick={() =>
|
|
750
|
+
selectAllRipple.toggleAll(table, !table.getIsAllPageRowsSelected(), false)
|
|
751
|
+
}
|
|
752
|
+
/>
|
|
753
|
+
{/* The tooltip says what a press does now. Some rows selected
|
|
754
|
+
(indeterminate) is not all: a press selects the rest of the
|
|
755
|
+
page, as with none selected. All selected: a press clears
|
|
756
|
+
this page only; rows selected on other pages stay. The
|
|
757
|
+
accessible name stays `selectAllRows`. */}
|
|
758
|
+
<Tooltip>
|
|
759
|
+
<TooltipTrigger
|
|
760
|
+
render={
|
|
761
|
+
<Checkbox
|
|
762
|
+
data-slot="checkbox"
|
|
763
|
+
checked={table.getIsAllPageRowsSelected()}
|
|
764
|
+
indeterminate={
|
|
765
|
+
table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected()
|
|
766
|
+
}
|
|
767
|
+
onPointerDown={() => prepareSelectAll(table, selectAllRipple)}
|
|
768
|
+
onCheckedChange={(checked, details) =>
|
|
769
|
+
selectAllRipple.toggleAll(table, checked, fromKeyboard(details.event))
|
|
770
|
+
}
|
|
771
|
+
aria-label={displayProps.current.l.selectAllRows}
|
|
772
|
+
className={cn(
|
|
773
|
+
'absolute top-1/2 start-2 z-10 -translate-y-1/2 opacity-0 group-hover/header-row:opacity-100 focus-visible:opacity-100 data-checked:opacity-100 data-indeterminate:opacity-100',
|
|
774
|
+
SELECT_CHECKBOX_HIT_CLASS,
|
|
775
|
+
)}
|
|
776
|
+
/>
|
|
777
|
+
}
|
|
778
|
+
/>
|
|
779
|
+
<TooltipContent>
|
|
780
|
+
{table.getIsAllPageRowsSelected()
|
|
781
|
+
? displayProps.current.l.clearPageSelection
|
|
782
|
+
: displayProps.current.l.selectAllOnPage}
|
|
783
|
+
</TooltipContent>
|
|
784
|
+
</Tooltip>
|
|
785
|
+
</>
|
|
246
786
|
),
|
|
247
|
-
cell: ({ row }) => (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
787
|
+
cell: ({ row, table }) => (
|
|
788
|
+
<>
|
|
789
|
+
{row.getCanSelect() && (
|
|
790
|
+
<span
|
|
791
|
+
aria-hidden
|
|
792
|
+
data-slot="data-table-select-area"
|
|
793
|
+
className={SELECT_AREA_CLASS}
|
|
794
|
+
onClick={(event) => {
|
|
795
|
+
selectAllRipple.end();
|
|
796
|
+
selectFromClick(table, row, event.shiftKey, selectionAnchor);
|
|
797
|
+
}}
|
|
798
|
+
// Shift+press would also extend the page's text selection.
|
|
799
|
+
onMouseDown={(event) => {
|
|
800
|
+
if (event.shiftKey) event.preventDefault();
|
|
801
|
+
}}
|
|
802
|
+
/>
|
|
803
|
+
)}
|
|
804
|
+
<Checkbox
|
|
805
|
+
checked={row.getIsSelected()}
|
|
806
|
+
disabled={!row.getCanSelect()}
|
|
807
|
+
onCheckedChange={(checked, details) => {
|
|
808
|
+
selectAllRipple.end();
|
|
809
|
+
selectFromClick(
|
|
810
|
+
table,
|
|
811
|
+
row,
|
|
812
|
+
Boolean((details.event as MouseEvent | KeyboardEvent | undefined)?.shiftKey),
|
|
813
|
+
selectionAnchor,
|
|
814
|
+
checked,
|
|
815
|
+
);
|
|
816
|
+
}}
|
|
817
|
+
aria-label={displayProps.current.l.selectRow(row.index)}
|
|
818
|
+
className={cn(
|
|
819
|
+
'absolute top-1/2 start-2 z-10 -translate-y-1/2 opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100 data-checked:opacity-100',
|
|
820
|
+
SELECT_CHECKBOX_HIT_CLASS,
|
|
821
|
+
SELECT_RIPPLE_CHECKBOX_CLASS,
|
|
822
|
+
)}
|
|
823
|
+
/>
|
|
824
|
+
</>
|
|
255
825
|
),
|
|
256
826
|
}
|
|
257
827
|
: undefined;
|
|
258
828
|
|
|
259
829
|
// biome-ignore lint/suspicious/noExplicitAny: matches TanStack's ColumnDef value-type convention
|
|
260
|
-
const actionsColumn: ColumnDef<TData, any> | undefined =
|
|
830
|
+
const actionsColumn: ColumnDef<TData, any> | undefined = hasRowActions
|
|
261
831
|
? {
|
|
262
832
|
id: ACTIONS_COLUMN_ID,
|
|
263
833
|
enableSorting: false,
|
|
264
834
|
enableHiding: false,
|
|
265
|
-
header: () => <span className="sr-only">{l.rowActions}</span>,
|
|
266
|
-
cell: ({ row, table }) => rowActions(row.original, { row, table }),
|
|
835
|
+
header: () => <span className="sr-only">{displayProps.current.l.rowActions}</span>,
|
|
836
|
+
cell: ({ row, table }) => displayProps.current.rowActions?.(row.original, { row, table }),
|
|
267
837
|
}
|
|
268
838
|
: undefined;
|
|
269
839
|
|
|
270
840
|
return buildDisplayColumns(columns, { select: selectColumn, actions: actionsColumn });
|
|
271
|
-
}, [
|
|
272
|
-
columns,
|
|
273
|
-
rowSelection,
|
|
274
|
-
rowActions,
|
|
275
|
-
selectColumnId,
|
|
276
|
-
l.selectAllRows,
|
|
277
|
-
l.selectRow,
|
|
278
|
-
l.rowActions,
|
|
279
|
-
]);
|
|
841
|
+
}, [columns, hasRowSelection, hasRowActions, selectColumnId, selectAllRipple]);
|
|
280
842
|
|
|
281
843
|
const state: Partial<TableState> = {};
|
|
282
844
|
if (sorting) state.sorting = sortingState;
|
|
@@ -363,20 +925,90 @@ function DataTable<TData>({
|
|
|
363
925
|
if (rowActions != null && id === ACTIONS_COLUMN_ID) return 'actions';
|
|
364
926
|
return undefined;
|
|
365
927
|
};
|
|
366
|
-
|
|
928
|
+
// Columns whose `meta.align` is `'end'`: their header, sort control and
|
|
929
|
+
// cells line up on the end side, so the digits of a number column line up.
|
|
930
|
+
const endColumnIds = new Set(
|
|
931
|
+
table
|
|
932
|
+
.getVisibleLeafColumns()
|
|
933
|
+
.filter((column) => columnAlign(column.columnDef.meta) === 'end')
|
|
934
|
+
.map((column) => column.id),
|
|
935
|
+
);
|
|
936
|
+
const columnClass = (id: string): string | undefined =>
|
|
937
|
+
cn(startColumnClass(id), endColumnIds.has(id) && 'text-end');
|
|
938
|
+
const startColumnClass = (id: string): string | undefined => {
|
|
367
939
|
const generated = generatedColumn(id);
|
|
368
|
-
// `
|
|
940
|
+
// `ps-0!`: the select cell is the first child, so CardTable's edge-cell
|
|
369
941
|
// padding would otherwise widen the zero-width cell and push the whole
|
|
370
942
|
// gutter arrangement out; important because CardTable's descendant rule
|
|
371
943
|
// out-specifies a plain utility on the cell.
|
|
372
|
-
if (generated === 'select') return 'relative w-0 p-0
|
|
373
|
-
|
|
944
|
+
if (generated === 'select') return 'relative w-0 p-0 ps-0!';
|
|
945
|
+
// Every other cell adds its column's indent (`--column-indent`, see
|
|
946
|
+
// `columnIndents`) to its start padding. CardTable's edge-cell padding
|
|
947
|
+
// adds it too.
|
|
948
|
+
if (id === leadingColumnId) return 'ps-[calc(var(--spacing)*10+var(--column-indent,0px))]';
|
|
374
949
|
// Actions cells drop vertical padding so a row-action button (taller than a
|
|
375
950
|
// text line) sits inside the natural row height rather than inflating every
|
|
376
951
|
// row; `align-middle` on the cell keeps it centred.
|
|
377
|
-
|
|
378
|
-
|
|
952
|
+
return cn(
|
|
953
|
+
'ps-[calc(var(--spacing)*2+var(--column-indent,0px))]',
|
|
954
|
+
generated === 'actions' && 'py-0',
|
|
955
|
+
);
|
|
379
956
|
};
|
|
957
|
+
// The cell text lines up with the header text. A styled cell content (a
|
|
958
|
+
// Badge, a StatusBadge chip, a Button, an IdChip) sets `--content-inset` to
|
|
959
|
+
// the distance from its box to its first letter, and the cell pulls its
|
|
960
|
+
// first element back by that much (`contentInsetPull` in the atoms covers
|
|
961
|
+
// content one wrapper deep). The rule has zero specificity, so a margin the
|
|
962
|
+
// content sets itself still wins. The cell resets the variable, so a plain
|
|
963
|
+
// wrapper element does not inherit one.
|
|
964
|
+
// A cell with a two-line status (StatusBadge `appearance="icon"` with a
|
|
965
|
+
// `detail`) drops to 6px vertical padding, so its 33px block fits the 48px
|
|
966
|
+
// row minimum and the row stays 48px, the same as a one-line row.
|
|
967
|
+
// An end-aligned cell pulls its last element forward by the same inset, so
|
|
968
|
+
// the content's last letter lines up with the header's.
|
|
969
|
+
const bodyCellClass = '[--content-inset:0px] has-[[data-slot=status-badge][data-detail]]:py-1.5';
|
|
970
|
+
const startPullClass = '[:where(&>:first-child)]:-ms-(--content-inset)';
|
|
971
|
+
const endPullClass = '[:where(&>:last-child)]:-me-(--content-inset)';
|
|
972
|
+
|
|
973
|
+
// A pull-back that reaches past the cell's start padding indents the whole
|
|
974
|
+
// column instead (see measureColumnIndents), so no content leaves its cell.
|
|
975
|
+
// Measured before paint, whenever the rows or the visible columns change.
|
|
976
|
+
const [columnIndents, setColumnIndents] = React.useState<Record<string, number>>({});
|
|
977
|
+
const visibleColumnKey = table
|
|
978
|
+
.getVisibleLeafColumns()
|
|
979
|
+
.map((column) => column.id)
|
|
980
|
+
.join(' ');
|
|
981
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the rows and visible columns are what change the cell content
|
|
982
|
+
React.useLayoutEffect(() => {
|
|
983
|
+
if (!tableRef.current) return;
|
|
984
|
+
const next = measureColumnIndents(tableRef.current);
|
|
985
|
+
setColumnIndents((current) => (sameIndents(current, next) ? current : next));
|
|
986
|
+
}, [bodyRows, visibleColumnKey, isLoading]);
|
|
987
|
+
const columnIndentStyle = (columnId: string): React.CSSProperties | undefined => {
|
|
988
|
+
// The select cell's click area ends where the leading cell's content
|
|
989
|
+
// starts, so it takes the leading column's indent.
|
|
990
|
+
const id =
|
|
991
|
+
generatedColumn(columnId) === 'select' && leadingColumnId != null
|
|
992
|
+
? leadingColumnId
|
|
993
|
+
: columnId;
|
|
994
|
+
return columnIndents[id]
|
|
995
|
+
? ({ '--column-indent': `${columnIndents[id]}px` } as React.CSSProperties)
|
|
996
|
+
: undefined;
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
// What a built-in body cell of this column carries. Handed to `renderRow` as
|
|
1000
|
+
// `ctx.cellProps`, so a row a consumer renders itself takes the select cell's
|
|
1001
|
+
// and the leading cell's classes from here instead of copying them.
|
|
1002
|
+
const bodyCellProps = (columnId: string): DataTableRowCellProps => ({
|
|
1003
|
+
'data-column-id': columnId,
|
|
1004
|
+
'data-content-inset-cell': '',
|
|
1005
|
+
className: cn(
|
|
1006
|
+
columnClass(columnId),
|
|
1007
|
+
bodyCellClass,
|
|
1008
|
+
endColumnIds.has(columnId) ? endPullClass : startPullClass,
|
|
1009
|
+
),
|
|
1010
|
+
style: columnIndentStyle(columnId),
|
|
1011
|
+
});
|
|
380
1012
|
|
|
381
1013
|
// Loading cells follow the real column layout (same ids, same cell classes),
|
|
382
1014
|
// so a consumer's `skeletonCells` entry can match its loaded cell's height.
|
|
@@ -426,39 +1058,113 @@ function DataTable<TData>({
|
|
|
426
1058
|
filters.showAppliedFilters !== false &&
|
|
427
1059
|
table.getState().columnFilters.length > 0;
|
|
428
1060
|
const showHeader = header != null || showControls || showChips;
|
|
429
|
-
//
|
|
430
|
-
//
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
1061
|
+
// "Clear filters" after the chips. With no rows (and not loading) the empty
|
|
1062
|
+
// state has the only one.
|
|
1063
|
+
const clearFilters = resolveClearFilters(
|
|
1064
|
+
filters?.clearFilters,
|
|
1065
|
+
table,
|
|
1066
|
+
!(isLoading && rows.length === 0) && bodyRows.length === 0,
|
|
1067
|
+
);
|
|
1068
|
+
// The bulk bar exists only while rows are selected. It takes the controls
|
|
1069
|
+
// row's place, or, with no controls row, covers the column header row (see
|
|
1070
|
+
// `bulkBarFade`): it never opens a band of its own, so the table never
|
|
1071
|
+
// moves when the first row is selected or the last one cleared.
|
|
1072
|
+
const selecting =
|
|
1073
|
+
rowSelection != null && getSelectedRowIds(table.getState().rowSelection).length > 0;
|
|
1074
|
+
selectingRef.current = selecting;
|
|
1075
|
+
const showBulk = selecting && bulkActions != null;
|
|
1076
|
+
|
|
1077
|
+
// While rows are selected, a plain click on a row selects or deselects it
|
|
1078
|
+
// and does not open the item: capture phase, so a router link never sees the
|
|
1079
|
+
// click. Clicks that still open the item: a click on the name (the row link,
|
|
1080
|
+
// which no longer stretches over the row), the keyboard (Enter fires a click
|
|
1081
|
+
// with detail 0), Cmd/Ctrl/Alt+click, and the middle button (auxclick). Row controls keep their own click, and a
|
|
1082
|
+
// click inside a portal (an open row menu) is not the row's.
|
|
1083
|
+
// A press that starts on a row control (a drag handle) or moves before it is
|
|
1084
|
+
// released is not a click on the row: a drag never selects.
|
|
1085
|
+
const rowPress = React.useRef<{ x: number; y: number; onControl: boolean } | null>(null);
|
|
1086
|
+
const onRowPointerDown = (event: React.PointerEvent<HTMLElement>) => {
|
|
1087
|
+
rowPress.current = {
|
|
1088
|
+
x: event.clientX,
|
|
1089
|
+
y: event.clientY,
|
|
1090
|
+
onControl: isRowControl(event.target as Element, event.currentTarget),
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
const onRowClickCapture = (row: Row<TData>) => (event: React.MouseEvent<HTMLElement>) => {
|
|
1094
|
+
const press = rowPress.current;
|
|
1095
|
+
rowPress.current = null;
|
|
1096
|
+
if (!selecting || !row.getCanSelect()) return;
|
|
1097
|
+
if (event.button !== 0 || event.detail === 0) return;
|
|
1098
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
1099
|
+
if (
|
|
1100
|
+
press != null &&
|
|
1101
|
+
(press.onControl ||
|
|
1102
|
+
Math.hypot(event.clientX - press.x, event.clientY - press.y) > ROW_PRESS_SLOP)
|
|
1103
|
+
) {
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
const target = event.target as Element;
|
|
1107
|
+
if (!event.currentTarget.contains(target) || isRowControl(target, event.currentTarget)) return;
|
|
1108
|
+
// The name: the row link does not stretch while rows are selected, so a
|
|
1109
|
+
// click that lands in it was on the name, and opens the item. Shift+click
|
|
1110
|
+
// on it still extends the selection.
|
|
1111
|
+
if (!event.shiftKey && target.closest('[data-slot=data-table-row-link]')) return;
|
|
1112
|
+
event.preventDefault();
|
|
1113
|
+
event.stopPropagation();
|
|
1114
|
+
selectAllRipple.end();
|
|
1115
|
+
selectFromClick(table, row, event.shiftKey, selectionAnchor);
|
|
1116
|
+
};
|
|
1117
|
+
// Shift+press would also extend the page's text selection across the rows.
|
|
1118
|
+
const onRowMouseDown = (event: React.MouseEvent<HTMLElement>) => {
|
|
1119
|
+
if (
|
|
1120
|
+
selecting &&
|
|
1121
|
+
event.shiftKey &&
|
|
1122
|
+
!isRowControl(event.target as Element, event.currentTarget)
|
|
1123
|
+
) {
|
|
1124
|
+
event.preventDefault();
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
// Click-to-select for one row: the built-in row spreads it, and `renderRow`
|
|
1128
|
+
// hands the same props over as `ctx.selectProps`.
|
|
1129
|
+
const rowSelectProps = (row: Row<TData>): DataTableRowSelectProps => ({
|
|
1130
|
+
// DataTableRowLink keys its look on this attribute: only the name opens
|
|
1131
|
+
// the item while a click on the row selects it.
|
|
1132
|
+
'data-click-selects': selecting && row.getCanSelect() ? '' : undefined,
|
|
1133
|
+
onClickCapture: onRowClickCapture(row),
|
|
1134
|
+
onMouseDown: onRowMouseDown,
|
|
1135
|
+
onPointerDown: onRowPointerDown,
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
// No controls row for the bulk bar to replace: it covers the column header row.
|
|
1139
|
+
const bulkOverHeader = !showControls && rowSelection != null && bulkActions != null;
|
|
1140
|
+
const bulkRender = showBulk ? bulkActions : undefined;
|
|
438
1141
|
|
|
439
1142
|
const bands = (
|
|
440
1143
|
<>
|
|
441
|
-
{
|
|
1144
|
+
{showHeader && (
|
|
442
1145
|
<CardHeader className="border-b">
|
|
443
1146
|
<ListHeader>
|
|
444
1147
|
{header}
|
|
445
1148
|
{/* Replace-on-select: while rows are selected the bulk bar takes
|
|
446
1149
|
the controls row's place (title and applied-filter chips stay).
|
|
447
|
-
|
|
448
|
-
(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
1150
|
+
Both share one grid cell, and the controls row stays mounted
|
|
1151
|
+
(faded, hidden and inert), so the cell keeps the row's height
|
|
1152
|
+
from the first frame, with nothing to measure. The bar is
|
|
1153
|
+
centred in it; -my-1 lets a bar up to 8px taller (a 32px bar
|
|
1154
|
+
over a 28px row) overhang the band's padding instead of growing
|
|
1155
|
+
the band. Only a bar that wraps grows it. The swap fades out
|
|
1156
|
+
then in, one --transition-duration-fast (100ms) per phase.
|
|
1157
|
+
Under reduced motion MotionConfig drops the 4px rise and keeps
|
|
1158
|
+
the fade. */}
|
|
1159
|
+
{showControls && (
|
|
1160
|
+
<MotionConfig reducedMotion="user">
|
|
1161
|
+
<div className="grid">
|
|
1162
|
+
<motion.div
|
|
1163
|
+
className="[grid-area:1/1]"
|
|
1164
|
+
initial={false}
|
|
1165
|
+
animate={bulkRender ? controlsSwap.hidden : controlsSwap.shown}
|
|
1166
|
+
inert={bulkRender ? true : undefined}
|
|
1167
|
+
>
|
|
462
1168
|
<ListHeaderControls>
|
|
463
1169
|
{toolbarNode}
|
|
464
1170
|
{hasFilterMenu && filters?.columns && (
|
|
@@ -477,11 +1183,30 @@ function DataTable<TData>({
|
|
|
477
1183
|
)}
|
|
478
1184
|
</ListHeaderControls>
|
|
479
1185
|
</motion.div>
|
|
480
|
-
|
|
481
|
-
|
|
1186
|
+
<AnimatePresence initial={false}>
|
|
1187
|
+
{bulkRender && (
|
|
1188
|
+
<motion.div
|
|
1189
|
+
key="bulk-actions"
|
|
1190
|
+
{...bulkBarFade}
|
|
1191
|
+
className="-my-1 self-center [grid-area:1/1]"
|
|
1192
|
+
>
|
|
1193
|
+
<DataTableBulkActions
|
|
1194
|
+
table={table}
|
|
1195
|
+
cache={selectionCache}
|
|
1196
|
+
render={bulkRender}
|
|
1197
|
+
className="min-h-0"
|
|
1198
|
+
/>
|
|
1199
|
+
</motion.div>
|
|
1200
|
+
)}
|
|
1201
|
+
</AnimatePresence>
|
|
1202
|
+
</div>
|
|
1203
|
+
</MotionConfig>
|
|
482
1204
|
)}
|
|
483
1205
|
{showChips && (
|
|
484
|
-
|
|
1206
|
+
// With "Clear filters" on, the line keeps the button's height
|
|
1207
|
+
// (Button sm, h-7; a Chip is h-6), so the table does not move
|
|
1208
|
+
// when the button shows or hides.
|
|
1209
|
+
<ListHeaderChips className={clearFilters ? 'min-h-7' : undefined}>
|
|
485
1210
|
<DataTableAppliedFilters
|
|
486
1211
|
table={table}
|
|
487
1212
|
columns={filters?.columns}
|
|
@@ -489,14 +1214,53 @@ function DataTable<TData>({
|
|
|
489
1214
|
removeLabel={l.removeFilter}
|
|
490
1215
|
collapsedLabel={l.filtersCollapsed}
|
|
491
1216
|
/>
|
|
1217
|
+
{clearFilters && !clearFilters.hidden && (
|
|
1218
|
+
<Button
|
|
1219
|
+
data-slot="data-table-clear-filters"
|
|
1220
|
+
variant="ghost"
|
|
1221
|
+
size="sm"
|
|
1222
|
+
onClick={clearFilters.onClear}
|
|
1223
|
+
>
|
|
1224
|
+
{l.clearFilters}
|
|
1225
|
+
</Button>
|
|
1226
|
+
)}
|
|
492
1227
|
</ListHeaderChips>
|
|
493
1228
|
)}
|
|
494
1229
|
</ListHeader>
|
|
495
1230
|
</CardHeader>
|
|
496
1231
|
)}
|
|
497
1232
|
|
|
498
|
-
<CardTable>
|
|
499
|
-
|
|
1233
|
+
<CardTable className={bulkOverHeader ? 'relative isolate' : undefined}>
|
|
1234
|
+
{bulkOverHeader && (
|
|
1235
|
+
// Over the column header row (h-10, as TableHead), after the select
|
|
1236
|
+
// slot: the bar starts where the leading column's label starts, and
|
|
1237
|
+
// the wrapper lets the pointer through to the select-all checkbox.
|
|
1238
|
+
// First in the DOM, so the bar comes before the rows in tab order.
|
|
1239
|
+
<MotionConfig reducedMotion="user">
|
|
1240
|
+
<AnimatePresence initial={false}>
|
|
1241
|
+
{bulkRender && (
|
|
1242
|
+
<motion.div
|
|
1243
|
+
key="bulk-over-header"
|
|
1244
|
+
{...bulkBarFade}
|
|
1245
|
+
className="pointer-events-none absolute inset-x-0 top-0 z-20 flex h-10 items-center ps-10 pe-(--card-px)"
|
|
1246
|
+
>
|
|
1247
|
+
<DataTableBulkActions
|
|
1248
|
+
table={table}
|
|
1249
|
+
cache={selectionCache}
|
|
1250
|
+
render={bulkRender}
|
|
1251
|
+
className="pointer-events-auto min-h-0 flex-nowrap"
|
|
1252
|
+
/>
|
|
1253
|
+
</motion.div>
|
|
1254
|
+
)}
|
|
1255
|
+
</AnimatePresence>
|
|
1256
|
+
</MotionConfig>
|
|
1257
|
+
)}
|
|
1258
|
+
<Table
|
|
1259
|
+
ref={tableRef}
|
|
1260
|
+
className={cn(LINKED_ROW_CLASS, ROW_CHEVRON_SLOT_CLASS, SELECT_RIPPLE_TABLE_CLASS)}
|
|
1261
|
+
data-selecting={selecting ? '' : undefined}
|
|
1262
|
+
data-bulk-over-header={bulkOverHeader && showBulk ? '' : undefined}
|
|
1263
|
+
>
|
|
500
1264
|
<TableHeader>
|
|
501
1265
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
502
1266
|
<TableRow key={headerGroup.id} className="group/header-row">
|
|
@@ -508,12 +1272,19 @@ function DataTable<TData>({
|
|
|
508
1272
|
<TableHead
|
|
509
1273
|
key={headerCell.id}
|
|
510
1274
|
aria-sort={ariaSort(sorting != null, headerCell.column)}
|
|
511
|
-
|
|
1275
|
+
data-column-id={headerCell.column.id}
|
|
1276
|
+
className={cn(
|
|
1277
|
+
columnClass(headerCell.column.id),
|
|
1278
|
+
generatedColumn(headerCell.column.id) !== 'select' &&
|
|
1279
|
+
HEADER_LABEL_UNDER_BULK_CLASS,
|
|
1280
|
+
)}
|
|
1281
|
+
style={columnIndentStyle(headerCell.column.id)}
|
|
512
1282
|
>
|
|
513
1283
|
{sorting != null && !headerCell.isPlaceholder ? (
|
|
514
1284
|
<DataTableColumnHeader
|
|
515
1285
|
column={headerCell.column}
|
|
516
1286
|
sortLabel={l.sortLabel(headerLabelText(headerCell.column))}
|
|
1287
|
+
align={endColumnIds.has(headerCell.column.id) ? 'end' : 'start'}
|
|
517
1288
|
>
|
|
518
1289
|
{content}
|
|
519
1290
|
</DataTableColumnHeader>
|
|
@@ -536,7 +1307,12 @@ function DataTable<TData>({
|
|
|
536
1307
|
</TableCell>
|
|
537
1308
|
) : (
|
|
538
1309
|
table.getVisibleLeafColumns().map((column) => (
|
|
539
|
-
<TableCell
|
|
1310
|
+
<TableCell
|
|
1311
|
+
key={column.id}
|
|
1312
|
+
data-column-id={column.id}
|
|
1313
|
+
className={columnClass(column.id)}
|
|
1314
|
+
style={columnIndentStyle(column.id)}
|
|
1315
|
+
>
|
|
540
1316
|
{skeletonCell(column.id)}
|
|
541
1317
|
</TableCell>
|
|
542
1318
|
))
|
|
@@ -554,14 +1330,21 @@ function DataTable<TData>({
|
|
|
554
1330
|
</TableRow>
|
|
555
1331
|
) : (
|
|
556
1332
|
<>
|
|
557
|
-
{bodyRows.map((row) => {
|
|
1333
|
+
{bodyRows.map((row, rowIndex) => {
|
|
1334
|
+
const ripple: DataTableRowRipple = {
|
|
1335
|
+
className: SELECT_RIPPLE_ROW_CLASS,
|
|
1336
|
+
style: rippleTiming(rowIndex, bodyRows.length),
|
|
1337
|
+
};
|
|
1338
|
+
const selectProps = rowSelectProps(row);
|
|
558
1339
|
const rowNode = (
|
|
559
1340
|
<TableRow
|
|
560
|
-
className=
|
|
1341
|
+
className={cn('group/row', ripple.className)}
|
|
1342
|
+
style={ripple.style}
|
|
561
1343
|
data-state={row.getIsSelected() ? 'selected' : undefined}
|
|
1344
|
+
{...selectProps}
|
|
562
1345
|
>
|
|
563
1346
|
{row.getVisibleCells().map((cell) => (
|
|
564
|
-
<TableCell key={cell.id}
|
|
1347
|
+
<TableCell key={cell.id} {...bodyCellProps(cell.column.id)}>
|
|
565
1348
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
566
1349
|
</TableCell>
|
|
567
1350
|
))}
|
|
@@ -585,7 +1368,16 @@ function DataTable<TData>({
|
|
|
585
1368
|
// express. Returning `defaultRow` keeps the built-in rendering.
|
|
586
1369
|
return (
|
|
587
1370
|
<React.Fragment key={row.id}>
|
|
588
|
-
{renderRow
|
|
1371
|
+
{renderRow
|
|
1372
|
+
? renderRow(row, {
|
|
1373
|
+
table,
|
|
1374
|
+
columnCount,
|
|
1375
|
+
defaultRow,
|
|
1376
|
+
ripple,
|
|
1377
|
+
cellProps: bodyCellProps,
|
|
1378
|
+
selectProps,
|
|
1379
|
+
})
|
|
1380
|
+
: defaultRow}
|
|
589
1381
|
</React.Fragment>
|
|
590
1382
|
);
|
|
591
1383
|
})}
|
|
@@ -629,11 +1421,7 @@ function DataTable<TData>({
|
|
|
629
1421
|
return frame === 'plain' ? (
|
|
630
1422
|
<div
|
|
631
1423
|
data-slot="data-table"
|
|
632
|
-
className={cn(
|
|
633
|
-
'flex flex-col gap-(--card-gap)',
|
|
634
|
-
!(showHeader || showBulk) && 'pt-(--card-gap)',
|
|
635
|
-
className,
|
|
636
|
-
)}
|
|
1424
|
+
className={cn('flex flex-col gap-(--card-gap)', !showHeader && 'pt-(--card-gap)', className)}
|
|
637
1425
|
>
|
|
638
1426
|
{bands}
|
|
639
1427
|
</div>
|
|
@@ -644,7 +1432,7 @@ function DataTable<TData>({
|
|
|
644
1432
|
);
|
|
645
1433
|
}
|
|
646
1434
|
|
|
647
|
-
export { DataTable, DataTableSkeletonLine };
|
|
1435
|
+
export { DataTable, DataTableRowLink, DataTableSkeletonLine };
|
|
648
1436
|
|
|
649
1437
|
// Re-export the consumer-facing TanStack types so columns can be authored from
|
|
650
1438
|
// the same import as `DataTable` — no direct `@tanstack/react-table` dependency
|