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