@wallarm-org/design-system 1.16.0 → 1.17.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/dist/components/Table/EditableCell/EditableSelectCell.js +15 -9
- package/dist/components/Table/StickyGroupParent.d.ts +7 -0
- package/dist/components/Table/StickyGroupParent.js +124 -0
- package/dist/components/Table/TableBody/TableBody.js +16 -13
- package/dist/components/Table/TableBody/TableBodyCell.d.ts +4 -1
- package/dist/components/Table/TableBody/TableBodyCell.js +4 -2
- package/dist/components/Table/TableBody/TableBodyRowDndContext.d.ts +6 -0
- package/dist/components/Table/TableBody/TableBodyRowDndContext.js +68 -0
- package/dist/components/Table/TableBody/TableBodyVirtualizedCore.js +42 -39
- package/dist/components/Table/TableBody/TableRowOverlay.d.ts +8 -0
- package/dist/components/Table/TableBody/TableRowOverlay.js +36 -0
- package/dist/components/Table/TableColGroup.js +3 -2
- package/dist/components/Table/TableContext/TableProvider.js +15 -4
- package/dist/components/Table/TableContext/types.d.ts +4 -1
- package/dist/components/Table/TableInner/TableInnerContainer.js +8 -1
- package/dist/components/Table/TableInner/TableInnerWindow.js +8 -1
- package/dist/components/Table/TableRow.js +28 -9
- package/dist/components/Table/TableRowExpanded.d.ts +4 -1
- package/dist/components/Table/TableRowExpanded.js +2 -1
- package/dist/components/Table/TableSettingsMenu/TableSettingsMenu.js +2 -2
- package/dist/components/Table/hooks/index.d.ts +1 -0
- package/dist/components/Table/hooks/index.js +1 -0
- package/dist/components/Table/hooks/useStickyGroupParent.d.ts +19 -0
- package/dist/components/Table/hooks/useStickyGroupParent.js +147 -0
- package/dist/components/Table/index.d.ts +1 -1
- package/dist/components/Table/lib/constants.d.ts +2 -0
- package/dist/components/Table/lib/constants.js +3 -1
- package/dist/components/Table/lib/createDragHandleColumn.d.ts +8 -0
- package/dist/components/Table/lib/createDragHandleColumn.js +23 -0
- package/dist/components/Table/lib/index.d.ts +3 -1
- package/dist/components/Table/lib/index.js +3 -1
- package/dist/components/Table/lib/useRowDnd.d.ts +15 -0
- package/dist/components/Table/lib/useRowDnd.js +32 -0
- package/dist/components/Table/types.d.ts +11 -0
- package/dist/metadata/components.json +28 -4
- package/package.json +1 -1
|
@@ -6,13 +6,14 @@ import { ScrollArea, ScrollAreaCorner, ScrollAreaScrollbar, ScrollAreaViewport }
|
|
|
6
6
|
import { tableContainerVariants } from "../classes.js";
|
|
7
7
|
import { useInfiniteScroll } from "../hooks/index.js";
|
|
8
8
|
import { useContainerWidth } from "../lib/index.js";
|
|
9
|
+
import { StickyGroupParent } from "../StickyGroupParent.js";
|
|
9
10
|
import { TableBody } from "../TableBody/index.js";
|
|
10
11
|
import { TableColGroup } from "../TableColGroup.js";
|
|
11
12
|
import { useTableContext } from "../TableContext/index.js";
|
|
12
13
|
import { TableHead } from "../TableHead.js";
|
|
13
14
|
import { TableSettingsMenuSlot } from "../TableSettingsMenu/index.js";
|
|
14
15
|
const TableInnerContainer = ({ isEmpty, virtualized, showSettings, hasConsumerSettingsMenu, ariaLabel, children })=>{
|
|
15
|
-
const { containerRef, table, virtualizerRef, tbodyRef, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
|
|
16
|
+
const { containerRef, table, virtualizerRef, tbodyRef, hasSubRowGrouping, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
|
|
16
17
|
const testId = useTestId('container');
|
|
17
18
|
const scrollRootRef = useRef(null);
|
|
18
19
|
const containerWidth = useContainerWidth(containerRef);
|
|
@@ -46,6 +47,8 @@ const TableInnerContainer = ({ isEmpty, virtualized, showSettings, hasConsumerSe
|
|
|
46
47
|
]);
|
|
47
48
|
const totalSize = table.getTotalSize();
|
|
48
49
|
const tableWidth = Math.max(containerWidth, totalSize);
|
|
50
|
+
const hasTextDescription = table.getAllLeafColumns().some((col)=>col.columnDef.meta?.description?.type === 'text');
|
|
51
|
+
const headerHeight = hasTextDescription ? 48 : 32;
|
|
49
52
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
50
53
|
children: [
|
|
51
54
|
/*#__PURE__*/ jsxs(ScrollArea, {
|
|
@@ -60,6 +63,10 @@ const TableInnerContainer = ({ isEmpty, virtualized, showSettings, hasConsumerSe
|
|
|
60
63
|
"data-table-scroll-container": true,
|
|
61
64
|
tabIndex: -1,
|
|
62
65
|
children: [
|
|
66
|
+
hasSubRowGrouping && /*#__PURE__*/ jsx(StickyGroupParent, {
|
|
67
|
+
tableWidth: tableWidth,
|
|
68
|
+
headerHeight: headerHeight
|
|
69
|
+
}),
|
|
63
70
|
/*#__PURE__*/ jsxs("table", {
|
|
64
71
|
className: "table-fixed border-separate border-spacing-0 overflow-clip",
|
|
65
72
|
style: {
|
|
@@ -4,13 +4,14 @@ import { useTestId } from "../../../utils/testId.js";
|
|
|
4
4
|
import { ScrollArea, ScrollAreaScrollbar, ScrollAreaViewport } from "../../ScrollArea/index.js";
|
|
5
5
|
import { useInfiniteScroll } from "../hooks/index.js";
|
|
6
6
|
import { useContainerWidth } from "../lib/index.js";
|
|
7
|
+
import { StickyGroupParent } from "../StickyGroupParent.js";
|
|
7
8
|
import { TableBody } from "../TableBody/index.js";
|
|
8
9
|
import { TableColGroup } from "../TableColGroup.js";
|
|
9
10
|
import { useTableContext } from "../TableContext/index.js";
|
|
10
11
|
import { TableHead } from "../TableHead.js";
|
|
11
12
|
import { TableSettingsMenuSlot } from "../TableSettingsMenu/index.js";
|
|
12
13
|
const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, ariaLabel, children })=>{
|
|
13
|
-
const { table, virtualizerRef, tbodyRef, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
|
|
14
|
+
const { table, virtualizerRef, tbodyRef, hasSubRowGrouping, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
|
|
14
15
|
const testId = useTestId('window');
|
|
15
16
|
const rootRef = useRef(null);
|
|
16
17
|
const scrollRef = useRef(null);
|
|
@@ -40,6 +41,8 @@ const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, aria
|
|
|
40
41
|
}, []);
|
|
41
42
|
const totalSize = table.getTotalSize();
|
|
42
43
|
const tableWidth = Math.max(containerWidth, totalSize);
|
|
44
|
+
const hasTextDescription = table.getAllLeafColumns().some((col)=>col.columnDef.meta?.description?.type === 'text');
|
|
45
|
+
const headerHeight = hasTextDescription ? 48 : 32;
|
|
43
46
|
const tableStyles = 'table-fixed border-separate border-spacing-0';
|
|
44
47
|
return /*#__PURE__*/ jsxs("div", {
|
|
45
48
|
ref: rootRef,
|
|
@@ -73,6 +76,10 @@ const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, aria
|
|
|
73
76
|
]
|
|
74
77
|
})
|
|
75
78
|
}),
|
|
79
|
+
hasSubRowGrouping && /*#__PURE__*/ jsx(StickyGroupParent, {
|
|
80
|
+
tableWidth: tableWidth,
|
|
81
|
+
headerHeight: headerHeight
|
|
82
|
+
}),
|
|
76
83
|
/*#__PURE__*/ jsxs("table", {
|
|
77
84
|
className: tableStyles,
|
|
78
85
|
style: {
|
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from "react";
|
|
2
|
+
import { memo, useCallback } from "react";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
4
|
import { useTestId } from "../../utils/testId.js";
|
|
5
|
-
import { TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID } from "./lib/index.js";
|
|
5
|
+
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, useRowDnd } from "./lib/index.js";
|
|
6
6
|
import { Td, Tr } from "./primitives/index.js";
|
|
7
7
|
import { TableBodyCell } from "./TableBody/TableBodyCell.js";
|
|
8
8
|
import { useTableContext } from "./TableContext/index.js";
|
|
9
9
|
import { TableRowExpanded } from "./TableRowExpanded.js";
|
|
10
10
|
const SYSTEM_COLUMN_IDS = new Set([
|
|
11
11
|
TABLE_EXPAND_COLUMN_ID,
|
|
12
|
-
TABLE_SELECT_COLUMN_ID
|
|
12
|
+
TABLE_SELECT_COLUMN_ID,
|
|
13
|
+
TABLE_DRAG_HANDLE_COLUMN_ID
|
|
13
14
|
]);
|
|
14
15
|
const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
15
16
|
const { expandingEnabled, activeRowId } = useTableContext();
|
|
16
17
|
const testId = useTestId('row');
|
|
18
|
+
const { canDnd, isDragging, setNodeRef, style: dndStyle, attributes, listeners } = useRowDnd(row);
|
|
17
19
|
const isGroupParent = row.subRows.length > 0;
|
|
18
20
|
const isSelected = isGroupParent ? row.getIsAllSubRowsSelected() : row.getIsSelected();
|
|
19
21
|
const isPreviewActive = activeRowId === row.id;
|
|
22
|
+
const composedRef = useCallback((node)=>{
|
|
23
|
+
if (canDnd) setNodeRef(node);
|
|
24
|
+
if ('function' == typeof ref) ref(node);
|
|
25
|
+
else if (ref) ref.current = node;
|
|
26
|
+
}, [
|
|
27
|
+
canDnd,
|
|
28
|
+
setNodeRef,
|
|
29
|
+
ref
|
|
30
|
+
]);
|
|
20
31
|
if (isGroupParent) {
|
|
21
32
|
const cells = row.getVisibleCells();
|
|
22
33
|
const systemCells = cells.filter((c)=>SYSTEM_COLUMN_IDS.has(c.column.id));
|
|
@@ -25,7 +36,7 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
25
36
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
26
37
|
children: [
|
|
27
38
|
/*#__PURE__*/ jsxs(Tr, {
|
|
28
|
-
ref:
|
|
39
|
+
ref: composedRef,
|
|
29
40
|
"data-index": dataIndex,
|
|
30
41
|
"data-row-id": row.id,
|
|
31
42
|
"data-testid": testId,
|
|
@@ -61,21 +72,29 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
|
|
|
61
72
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
62
73
|
children: [
|
|
63
74
|
/*#__PURE__*/ jsx(Tr, {
|
|
64
|
-
ref:
|
|
75
|
+
ref: composedRef,
|
|
65
76
|
"data-index": dataIndex,
|
|
66
77
|
"data-row-id": row.id,
|
|
67
78
|
"data-testid": testId,
|
|
68
79
|
className: "group/row",
|
|
69
80
|
"data-selected": isSelected || void 0,
|
|
70
81
|
"data-preview-active": isPreviewActive || void 0,
|
|
82
|
+
"data-dragging": isDragging || void 0,
|
|
71
83
|
"aria-selected": isSelected || void 0,
|
|
72
84
|
"data-depth": row.depth > 0 ? row.depth : void 0,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
style: dndStyle,
|
|
86
|
+
children: row.getVisibleCells().map((cell)=>{
|
|
87
|
+
const isDragHandle = cell.column.id === TABLE_DRAG_HANDLE_COLUMN_ID;
|
|
88
|
+
return /*#__PURE__*/ jsx(TableBodyCell, {
|
|
89
|
+
cell: cell,
|
|
90
|
+
dragListeners: isDragHandle ? listeners : void 0,
|
|
91
|
+
dragAttributes: isDragHandle ? attributes : void 0
|
|
92
|
+
}, cell.id);
|
|
93
|
+
})
|
|
76
94
|
}),
|
|
77
95
|
expandingEnabled && /*#__PURE__*/ jsx(TableRowExpanded, {
|
|
78
|
-
row: row
|
|
96
|
+
row: row,
|
|
97
|
+
dndStyle: dndStyle
|
|
79
98
|
})
|
|
80
99
|
]
|
|
81
100
|
});
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
import type { Row, RowData } from '@tanstack/react-table';
|
|
2
3
|
import { type DSTableFeatures } from './lib';
|
|
3
4
|
interface TableRowExpandedProps<T extends RowData> {
|
|
4
5
|
row: Row<DSTableFeatures, T>;
|
|
6
|
+
/** When row DnD is active, pass the same transform style so expanded content moves with its parent row. */
|
|
7
|
+
dndStyle?: CSSProperties;
|
|
5
8
|
}
|
|
6
|
-
export declare function TableRowExpanded<T extends RowData>({ row }: TableRowExpandedProps<T>): import("react").JSX.Element | null;
|
|
9
|
+
export declare function TableRowExpanded<T extends RowData>({ row, dndStyle, }: TableRowExpandedProps<T>): import("react").JSX.Element | null;
|
|
7
10
|
export declare namespace TableRowExpanded {
|
|
8
11
|
var displayName: string;
|
|
9
12
|
}
|
|
@@ -3,7 +3,7 @@ import { useTestId } from "../../utils/testId.js";
|
|
|
3
3
|
import { TABLE_EXPAND_COLUMN_ID } from "./lib/index.js";
|
|
4
4
|
import { Td, Tr } from "./primitives/index.js";
|
|
5
5
|
import { useTableContext } from "./TableContext/index.js";
|
|
6
|
-
const TableRowExpanded = ({ row })=>{
|
|
6
|
+
const TableRowExpanded = ({ row, dndStyle })=>{
|
|
7
7
|
const { table, renderExpandedRow } = useTableContext();
|
|
8
8
|
const testId = useTestId('row-expanded');
|
|
9
9
|
if (!row.getIsExpanded() || !renderExpandedRow) return null;
|
|
@@ -12,6 +12,7 @@ const TableRowExpanded = ({ row })=>{
|
|
|
12
12
|
const contentColSpan = hasExpandColumn ? visibleColumns.length - 1 : visibleColumns.length;
|
|
13
13
|
return /*#__PURE__*/ jsxs(Tr, {
|
|
14
14
|
"data-testid": testId,
|
|
15
|
+
style: dndStyle,
|
|
15
16
|
children: [
|
|
16
17
|
hasExpandColumn && /*#__PURE__*/ jsx(Td, {
|
|
17
18
|
className: "border-b-0 border-r border-border-primary-light bg-bg-surface-2 sticky left-0"
|
|
@@ -11,7 +11,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuFooter, DropdownMenuLabe
|
|
|
11
11
|
import { Separator } from "../../Separator/index.js";
|
|
12
12
|
import { VStack } from "../../Stack/index.js";
|
|
13
13
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../../Tooltip/index.js";
|
|
14
|
-
import { TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, collectDirectChildren } from "../lib/index.js";
|
|
14
|
+
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, collectDirectChildren } from "../lib/index.js";
|
|
15
15
|
import { useTableContext } from "../TableContext/index.js";
|
|
16
16
|
import { TableSettingsMenuContentProvider } from "./TableSettingsMenuContentContext.js";
|
|
17
17
|
import { useTableSettingsMenuContext } from "./TableSettingsMenuContext.js";
|
|
@@ -47,7 +47,7 @@ const TableSettingsMenu = ({ 'data-testid': testIdProp, children, ...rest })=>{
|
|
|
47
47
|
}, [
|
|
48
48
|
menuOpen
|
|
49
49
|
]);
|
|
50
|
-
const allColumns = table.getAllLeafColumns().filter((col)=>col.id !== TABLE_SELECT_COLUMN_ID && col.id !== TABLE_EXPAND_COLUMN_ID);
|
|
50
|
+
const allColumns = table.getAllLeafColumns().filter((col)=>col.id !== TABLE_SELECT_COLUMN_ID && col.id !== TABLE_EXPAND_COLUMN_ID && col.id !== TABLE_DRAG_HANDLE_COLUMN_ID);
|
|
51
51
|
const filteredColumns = useMemo(()=>{
|
|
52
52
|
if (!search) return allColumns;
|
|
53
53
|
const lower = search.toLowerCase();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useInfiniteScroll } from './infiniteScroll';
|
|
2
2
|
export { useHorizontalScrollState } from './useHorizontalScrollState';
|
|
3
3
|
export { useMasterCell } from './useMasterCell';
|
|
4
|
+
export { useStickyGroupParent } from './useStickyGroupParent';
|
|
4
5
|
export { useTableState } from './useTableState';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useInfiniteScroll } from "./infiniteScroll/index.js";
|
|
2
2
|
export { useHorizontalScrollState } from "./useHorizontalScrollState.js";
|
|
3
3
|
export { useMasterCell } from "./useMasterCell.js";
|
|
4
|
+
export { useStickyGroupParent } from "./useStickyGroupParent.js";
|
|
4
5
|
export { useTableState } from "./useTableState.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { ReactTable, Row, RowData } from '@tanstack/react-table';
|
|
3
|
+
import type { DSTableFeatures } from '../lib';
|
|
4
|
+
import type { TableVirtualizerInstance } from '../TableContext/types';
|
|
5
|
+
export interface StickyGroupParentResult<T extends RowData> {
|
|
6
|
+
stickyRow: Row<DSTableFeatures, T> | null;
|
|
7
|
+
pushUpOffset: number;
|
|
8
|
+
}
|
|
9
|
+
interface UseStickyGroupParentOptions {
|
|
10
|
+
table: ReactTable<DSTableFeatures, RowData>;
|
|
11
|
+
scrollElementRef: RefObject<HTMLElement | null>;
|
|
12
|
+
useWindowScroll: boolean;
|
|
13
|
+
headerHeight: number;
|
|
14
|
+
tbodyRef: RefObject<HTMLTableSectionElement | null>;
|
|
15
|
+
virtualizerRef: RefObject<TableVirtualizerInstance | null>;
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const useStickyGroupParent: <T extends RowData>(options: UseStickyGroupParentOptions) => StickyGroupParentResult<T>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
const buildGroupRanges = (table)=>{
|
|
3
|
+
const rows = table.getRowModel().rows;
|
|
4
|
+
const ranges = [];
|
|
5
|
+
for(let i = 0; i < rows.length; i++){
|
|
6
|
+
const row = rows[i];
|
|
7
|
+
if (0 === row.depth && row.subRows.length > 0 && row.getIsExpanded()) {
|
|
8
|
+
let lastChildIndex = i;
|
|
9
|
+
for(let j = i + 1; j < rows.length; j++)if (rows[j].depth > 0) lastChildIndex = j;
|
|
10
|
+
else break;
|
|
11
|
+
ranges.push({
|
|
12
|
+
row,
|
|
13
|
+
parentIndex: i,
|
|
14
|
+
lastChildIndex
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return ranges;
|
|
19
|
+
};
|
|
20
|
+
const getRowBounds = (index, virt, tbodyScrollOffset, tbodyEl, scrollTop, scrollContainerTop)=>{
|
|
21
|
+
if (virt) {
|
|
22
|
+
const m = virt.measurementsCache[index];
|
|
23
|
+
if (m) return {
|
|
24
|
+
top: tbodyScrollOffset + m.start,
|
|
25
|
+
bottom: tbodyScrollOffset + m.start + m.size,
|
|
26
|
+
height: m.size
|
|
27
|
+
};
|
|
28
|
+
const size = virt.options.estimateSize(index);
|
|
29
|
+
let start = 0;
|
|
30
|
+
for(let i = 0; i < index; i++){
|
|
31
|
+
const mi = virt.measurementsCache[i];
|
|
32
|
+
start += mi ? mi.size : virt.options.estimateSize(i);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
top: tbodyScrollOffset + start,
|
|
36
|
+
bottom: tbodyScrollOffset + start + size,
|
|
37
|
+
height: size
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (!tbodyEl) return null;
|
|
41
|
+
const rowEls = tbodyEl.querySelectorAll('[data-row-id]');
|
|
42
|
+
const rowEl = rowEls[index];
|
|
43
|
+
if (!rowEl) return null;
|
|
44
|
+
const rect = rowEl.getBoundingClientRect();
|
|
45
|
+
const top = rect.top - scrollContainerTop + scrollTop;
|
|
46
|
+
return {
|
|
47
|
+
top,
|
|
48
|
+
bottom: top + rect.height,
|
|
49
|
+
height: rect.height
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const useStickyGroupParent = (options)=>{
|
|
53
|
+
const { table, scrollElementRef, useWindowScroll, headerHeight, tbodyRef, virtualizerRef, enabled } = options;
|
|
54
|
+
const [stickyRow, setStickyRow] = useState(null);
|
|
55
|
+
const [pushUpOffset, setPushUpOffset] = useState(0);
|
|
56
|
+
const rafRef = useRef(0);
|
|
57
|
+
const prevStickyRowIdRef = useRef(null);
|
|
58
|
+
const compute = useCallback(()=>{
|
|
59
|
+
if (!enabled) {
|
|
60
|
+
if (null !== prevStickyRowIdRef.current) {
|
|
61
|
+
setStickyRow(null);
|
|
62
|
+
setPushUpOffset(0);
|
|
63
|
+
prevStickyRowIdRef.current = null;
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const scrollElement = scrollElementRef.current;
|
|
68
|
+
if (!scrollElement) return;
|
|
69
|
+
const scrollTop = useWindowScroll ? window.scrollY : scrollElement.scrollTop;
|
|
70
|
+
const headerBottom = scrollTop + headerHeight;
|
|
71
|
+
const tbodyEl = tbodyRef.current;
|
|
72
|
+
const virt = virtualizerRef.current;
|
|
73
|
+
let tbodyScrollOffset = 0;
|
|
74
|
+
let scrollContainerTop = 0;
|
|
75
|
+
if (tbodyEl) if (useWindowScroll) {
|
|
76
|
+
tbodyScrollOffset = tbodyEl.getBoundingClientRect().top + window.scrollY;
|
|
77
|
+
scrollContainerTop = 0;
|
|
78
|
+
} else {
|
|
79
|
+
const scrollRect = scrollElement.getBoundingClientRect();
|
|
80
|
+
scrollContainerTop = scrollRect.top;
|
|
81
|
+
tbodyScrollOffset = tbodyEl.getBoundingClientRect().top - scrollRect.top + scrollTop;
|
|
82
|
+
}
|
|
83
|
+
const ranges = buildGroupRanges(table);
|
|
84
|
+
let foundRow = null;
|
|
85
|
+
let offset = 0;
|
|
86
|
+
for(let i = 0; i < ranges.length; i++){
|
|
87
|
+
const range = ranges[i];
|
|
88
|
+
const parentBounds = getRowBounds(range.parentIndex, virt, tbodyScrollOffset, tbodyEl, scrollTop, scrollContainerTop);
|
|
89
|
+
if (!parentBounds) continue;
|
|
90
|
+
const lastChildBounds = getRowBounds(range.lastChildIndex, virt, tbodyScrollOffset, tbodyEl, scrollTop, scrollContainerTop);
|
|
91
|
+
if (lastChildBounds) {
|
|
92
|
+
if (parentBounds.top < headerBottom && lastChildBounds.bottom > headerBottom) {
|
|
93
|
+
foundRow = range.row;
|
|
94
|
+
const remaining = lastChildBounds.bottom - headerBottom;
|
|
95
|
+
offset = remaining < parentBounds.height ? -(parentBounds.height - remaining) : 0;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const newId = foundRow?.id ?? null;
|
|
101
|
+
if (newId !== prevStickyRowIdRef.current || 0 !== offset) {
|
|
102
|
+
prevStickyRowIdRef.current = newId;
|
|
103
|
+
setStickyRow(foundRow);
|
|
104
|
+
setPushUpOffset(offset);
|
|
105
|
+
}
|
|
106
|
+
}, [
|
|
107
|
+
enabled,
|
|
108
|
+
scrollElementRef,
|
|
109
|
+
useWindowScroll,
|
|
110
|
+
headerHeight,
|
|
111
|
+
table,
|
|
112
|
+
virtualizerRef,
|
|
113
|
+
tbodyRef
|
|
114
|
+
]);
|
|
115
|
+
useEffect(()=>{
|
|
116
|
+
if (!enabled) return;
|
|
117
|
+
const scrollTarget = useWindowScroll ? window : scrollElementRef.current;
|
|
118
|
+
if (!scrollTarget) return;
|
|
119
|
+
const handleScroll = ()=>{
|
|
120
|
+
cancelAnimationFrame(rafRef.current);
|
|
121
|
+
rafRef.current = requestAnimationFrame(compute);
|
|
122
|
+
};
|
|
123
|
+
compute();
|
|
124
|
+
scrollTarget.addEventListener('scroll', handleScroll, {
|
|
125
|
+
passive: true
|
|
126
|
+
});
|
|
127
|
+
return ()=>{
|
|
128
|
+
scrollTarget.removeEventListener('scroll', handleScroll);
|
|
129
|
+
cancelAnimationFrame(rafRef.current);
|
|
130
|
+
};
|
|
131
|
+
}, [
|
|
132
|
+
enabled,
|
|
133
|
+
useWindowScroll,
|
|
134
|
+
scrollElementRef,
|
|
135
|
+
compute
|
|
136
|
+
]);
|
|
137
|
+
useEffect(()=>{
|
|
138
|
+
compute();
|
|
139
|
+
}, [
|
|
140
|
+
compute
|
|
141
|
+
]);
|
|
142
|
+
return {
|
|
143
|
+
stickyRow,
|
|
144
|
+
pushUpOffset
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
export { useStickyGroupParent };
|
|
@@ -10,4 +10,4 @@ export { TableEmptyState } from './TableEmptyState';
|
|
|
10
10
|
export { TableScrollHandler, TableScrollHandlerLeft, type TableScrollHandlerLeftProps, type TableScrollHandlerProps, TableScrollHandlerRight, type TableScrollHandlerRightProps, } from './TableScrollHandler';
|
|
11
11
|
export { TableSettingsMenu, TableSettingsMenuItem, type TableSettingsMenuItemProps, type TableSettingsMenuProps, TableSettingsMenuReset, type TableSettingsMenuResetProps, TableSettingsMenuSearch, type TableSettingsMenuSearchProps, } from './TableSettingsMenu';
|
|
12
12
|
export { TableSortTrigger, type TableSortTriggerProps } from './TableSortTrigger';
|
|
13
|
-
export type { TableAccessorColumnDef, TableCellContext, TableColumnBase, TableColumnDef, TableColumnGroup, TableColumnMeta, TableColumnPinningState, TableColumnSizingState, TableDisplayColumnDef, TableExpandedState, TableGroupingState, TableHandle, TableOnChangeFn, TableProps, TableRow, TableRowSelectionState, TableScrollToRowOptions, TableSortingState, TableUpdater, TableVirtualized, TableVisibilityState, } from './types';
|
|
13
|
+
export type { TableAccessorColumnDef, TableCellContext, TableColumnBase, TableColumnDef, TableColumnGroup, TableColumnMeta, TableColumnPinningState, TableColumnSizingState, TableDisplayColumnDef, TableExpandedState, TableGroupingState, TableHandle, TableOnChangeFn, TableProps, TableRow, TableRowReorderEvent, TableRowSelectionState, TableScrollToRowOptions, TableSortingState, TableUpdater, TableVirtualized, TableVisibilityState, } from './types';
|
|
@@ -7,6 +7,8 @@ export declare const TABLE_SELECT_COLUMN_ID = "_selection";
|
|
|
7
7
|
export declare const TABLE_SELECT_COLUMN_WIDTH = 33;
|
|
8
8
|
export declare const TABLE_EXPAND_COLUMN_ID = "_expand";
|
|
9
9
|
export declare const TABLE_EXPAND_COLUMN_WIDTH = 33;
|
|
10
|
+
export declare const TABLE_DRAG_HANDLE_COLUMN_ID = "_dragHandle";
|
|
11
|
+
export declare const TABLE_DRAG_HANDLE_COLUMN_WIDTH = 33;
|
|
10
12
|
export declare const TABLE_END_REACHED_THRESHOLD = 200;
|
|
11
13
|
export declare const TABLE_START_REACHED_THRESHOLD = 200;
|
|
12
14
|
/** Minimum time (ms) between successive edge-reached callbacks. */
|
|
@@ -6,6 +6,8 @@ const TABLE_SELECT_COLUMN_ID = '_selection';
|
|
|
6
6
|
const TABLE_SELECT_COLUMN_WIDTH = 33;
|
|
7
7
|
const TABLE_EXPAND_COLUMN_ID = '_expand';
|
|
8
8
|
const TABLE_EXPAND_COLUMN_WIDTH = 33;
|
|
9
|
+
const TABLE_DRAG_HANDLE_COLUMN_ID = '_dragHandle';
|
|
10
|
+
const TABLE_DRAG_HANDLE_COLUMN_WIDTH = 33;
|
|
9
11
|
const TABLE_END_REACHED_THRESHOLD = 200;
|
|
10
12
|
const TABLE_START_REACHED_THRESHOLD = 200;
|
|
11
13
|
const SCROLL_EDGE_COOLDOWN_MS = 200;
|
|
@@ -59,4 +61,4 @@ const SORT_LABELS = {
|
|
|
59
61
|
'Smallest on top'
|
|
60
62
|
]
|
|
61
63
|
};
|
|
62
|
-
export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass };
|
|
64
|
+
export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ColumnDef, RowData } from '@tanstack/react-table';
|
|
2
|
+
import type { DSTableFeatures } from './dsTableFeatures';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a drag-handle column for row reordering.
|
|
5
|
+
* Automatically injected by Table when `onRowReorder` is provided.
|
|
6
|
+
* The actual drag listeners are applied by `TableRow` on the cell, not here.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createDragHandleColumn: <T extends RowData>() => ColumnDef<DSTableFeatures, T, unknown>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { GripVertical } from "../../../icons/index.js";
|
|
3
|
+
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH } from "./constants.js";
|
|
4
|
+
const createDragHandleColumn = ()=>({
|
|
5
|
+
id: TABLE_DRAG_HANDLE_COLUMN_ID,
|
|
6
|
+
size: TABLE_DRAG_HANDLE_COLUMN_WIDTH,
|
|
7
|
+
minSize: TABLE_DRAG_HANDLE_COLUMN_WIDTH,
|
|
8
|
+
maxSize: TABLE_DRAG_HANDLE_COLUMN_WIDTH,
|
|
9
|
+
enableSorting: false,
|
|
10
|
+
enableResizing: false,
|
|
11
|
+
enableHiding: false,
|
|
12
|
+
enablePinning: false,
|
|
13
|
+
meta: {
|
|
14
|
+
headerClassName: 'px-8 py-4',
|
|
15
|
+
cellClassName: 'px-8 py-8'
|
|
16
|
+
},
|
|
17
|
+
header: ()=>null,
|
|
18
|
+
cell: ()=>/*#__PURE__*/ jsx(GripVertical, {
|
|
19
|
+
size: "sm",
|
|
20
|
+
className: "text-text-tertiary"
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
export { createDragHandleColumn };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { collectDirectChildren } from './collectDirectChildren';
|
|
2
|
-
export { getAlignClass, getExpandBorderClass, SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, } from './constants';
|
|
2
|
+
export { getAlignClass, getExpandBorderClass, SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, } from './constants';
|
|
3
3
|
export { containsDirectChild } from './containsDirectChild';
|
|
4
|
+
export { createDragHandleColumn } from './createDragHandleColumn';
|
|
4
5
|
export { createExpandColumn } from './createExpandColumn';
|
|
5
6
|
export { createSelectionColumn } from './createSelectionColumn';
|
|
6
7
|
export { createTableColumnHelper } from './createTableColumnHelper';
|
|
@@ -12,3 +13,4 @@ export { getRowKey } from './getRowKey';
|
|
|
12
13
|
export { isLastPinnedLeft } from './isLastPinnedLeft';
|
|
13
14
|
export { useColumnDnd } from './useColumnDnd';
|
|
14
15
|
export { useContainerWidth } from './useContainerWidth';
|
|
16
|
+
export { useRowDnd } from './useRowDnd';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { collectDirectChildren } from "./collectDirectChildren.js";
|
|
2
|
-
export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass } from "./constants.js";
|
|
2
|
+
export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass } from "./constants.js";
|
|
3
3
|
export { containsDirectChild } from "./containsDirectChild.js";
|
|
4
|
+
export { createDragHandleColumn } from "./createDragHandleColumn.js";
|
|
4
5
|
export { createExpandColumn } from "./createExpandColumn.js";
|
|
5
6
|
export { createSelectionColumn } from "./createSelectionColumn.js";
|
|
6
7
|
export { createTableColumnHelper } from "./createTableColumnHelper.js";
|
|
@@ -12,3 +13,4 @@ export { getRowKey } from "./getRowKey.js";
|
|
|
12
13
|
export { isLastPinnedLeft } from "./isLastPinnedLeft.js";
|
|
13
14
|
export { useColumnDnd } from "./useColumnDnd.js";
|
|
14
15
|
export { useContainerWidth } from "./useContainerWidth.js";
|
|
16
|
+
export { useRowDnd } from "./useRowDnd.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
3
|
+
import type { Row, RowData } from '@tanstack/react-table';
|
|
4
|
+
import type { DSTableFeatures } from './dsTableFeatures';
|
|
5
|
+
type UseSortableReturn = ReturnType<typeof useSortable>;
|
|
6
|
+
export interface UseRowDndResult {
|
|
7
|
+
canDnd: boolean;
|
|
8
|
+
isDragging: boolean;
|
|
9
|
+
setNodeRef: UseSortableReturn['setNodeRef'];
|
|
10
|
+
style: CSSProperties;
|
|
11
|
+
attributes: UseSortableReturn['attributes'];
|
|
12
|
+
listeners: UseSortableReturn['listeners'];
|
|
13
|
+
}
|
|
14
|
+
export declare const useRowDnd: <T extends RowData>(row: Row<DSTableFeatures, T>) => UseRowDndResult;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
2
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
3
|
+
import { useTableContext } from "../TableContext/useTableContext.js";
|
|
4
|
+
const useRowDnd = (row)=>{
|
|
5
|
+
const { rowDndEnabled } = useTableContext();
|
|
6
|
+
const canDnd = rowDndEnabled && 0 === row.subRows.length;
|
|
7
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
8
|
+
id: row.id,
|
|
9
|
+
disabled: !canDnd
|
|
10
|
+
});
|
|
11
|
+
const style = canDnd ? {
|
|
12
|
+
transform: CSS.Translate.toString(transform ? {
|
|
13
|
+
...transform,
|
|
14
|
+
x: 0
|
|
15
|
+
} : null),
|
|
16
|
+
transition,
|
|
17
|
+
...isDragging && {
|
|
18
|
+
opacity: 0.5,
|
|
19
|
+
position: 'relative',
|
|
20
|
+
zIndex: 100
|
|
21
|
+
}
|
|
22
|
+
} : {};
|
|
23
|
+
return {
|
|
24
|
+
canDnd,
|
|
25
|
+
isDragging,
|
|
26
|
+
setNodeRef,
|
|
27
|
+
style,
|
|
28
|
+
attributes,
|
|
29
|
+
listeners
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export { useRowDnd };
|
|
@@ -55,6 +55,11 @@ export interface TableColumnGroup {
|
|
|
55
55
|
label: string;
|
|
56
56
|
columns: string[];
|
|
57
57
|
}
|
|
58
|
+
/** Event fired when a row is dragged to a new position */
|
|
59
|
+
export interface TableRowReorderEvent {
|
|
60
|
+
activeRowId: string;
|
|
61
|
+
overRowId: string;
|
|
62
|
+
}
|
|
58
63
|
/** State updater — value or functional update */
|
|
59
64
|
export type TableUpdater<T> = T | ((prev: T) => T);
|
|
60
65
|
/** Options for the imperative `scrollToRow` method */
|
|
@@ -236,6 +241,12 @@ export interface TableProps<T> extends TestableProps {
|
|
|
236
241
|
* scroll settles. Use for deep-linking into the middle of a dataset.
|
|
237
242
|
*/
|
|
238
243
|
initialScrollToRowId?: string;
|
|
244
|
+
/**
|
|
245
|
+
* Callback fired when a row is dragged to a new position. When provided,
|
|
246
|
+
* a drag-handle column is auto-injected and row DnD is enabled.
|
|
247
|
+
* Disabled when `getSubRows` grouping is active.
|
|
248
|
+
*/
|
|
249
|
+
onRowReorder?: (event: TableRowReorderEvent) => void;
|
|
239
250
|
/** Callback fired when the master cell is clicked. Receives the row ID. */
|
|
240
251
|
onMasterCellClick?: (rowId: string) => void;
|
|
241
252
|
/** ID of the currently active (highlighted) row, or null. Controls row highlighting via data-preview-active attribute. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
3
|
-
"generatedAt": "2026-09-
|
|
2
|
+
"version": "1.16.0",
|
|
3
|
+
"generatedAt": "2026-09-07T14:31:27.423Z",
|
|
4
4
|
"components": [
|
|
5
5
|
{
|
|
6
6
|
"name": "Accordion",
|
|
@@ -85227,9 +85227,33 @@
|
|
|
85227
85227
|
"description": "Grouping, expansion, selection, pinning, virtualization and the action bar in one table —\nthe honest test of whether the features cooperate rather than merely exist."
|
|
85228
85228
|
},
|
|
85229
85229
|
{
|
|
85230
|
-
"name": "
|
|
85231
|
-
"code": "() => {\n const [data, setData] = useState
|
|
85230
|
+
"name": "RowReordering",
|
|
85231
|
+
"code": "() => {\n const [data, setData] = useState(() => securityEvents.slice(0, 6));\n\n const handleRowReorder = useCallback((event: TableRowReorderEvent) => {\n setData(prev => {\n const oldIndex = prev.findIndex(row => row.id === event.activeRowId);\n const newIndex = prev.findIndex(row => row.id === event.overRowId);\n if (oldIndex === -1 || newIndex === -1) return prev;\n return arrayMove(prev, oldIndex, newIndex);\n });\n }, []);\n\n return (\n <Table\n data={data}\n columns={securityColumns}\n getRowId={row => row.id}\n onRowReorder={handleRowReorder}\n data-testid='row-reorder-table'\n />\n );\n}",
|
|
85232
85232
|
"description": "`EditableTextCell` and `EditableSelectCell` in the plain columns, with the master column\ndeliberately read-only — editing in place suits a value the user owns, not one the system\nreports. Hovering highlights the whole cell, clicking opens it without the content shifting,\nand Enter or blur commits while Escape reverts."
|
|
85233
|
+
},
|
|
85234
|
+
{
|
|
85235
|
+
"name": "RowReorderingWithSelection",
|
|
85236
|
+
"code": "() => {\n const [data, setData] = useState(() => securityEvents.slice(0, 6));\n const [rowSelection, setRowSelection] = useState<TableRowSelectionState>({});\n\n const handleRowReorder = useCallback((event: TableRowReorderEvent) => {\n setData(prev => {\n const oldIndex = prev.findIndex(row => row.id === event.activeRowId);\n const newIndex = prev.findIndex(row => row.id === event.overRowId);\n if (oldIndex === -1 || newIndex === -1) return prev;\n return arrayMove(prev, oldIndex, newIndex);\n });\n }, []);\n\n return (\n <Table\n data={data}\n columns={securityColumns}\n getRowId={row => row.id}\n onRowReorder={handleRowReorder}\n rowSelection={rowSelection}\n onRowSelectionChange={setRowSelection}\n />\n );\n}",
|
|
85237
|
+
"description": "Row reordering coexists with row selection — each feature has its own column and they\ndon't interfere with each other."
|
|
85238
|
+
},
|
|
85239
|
+
{
|
|
85240
|
+
"name": "RowReorderingVirtualized",
|
|
85241
|
+
"code": "() => {\n const [data, setData] = useState(() => createLargeSecurityEvents(100));\n\n const handleRowReorder = useCallback((event: TableRowReorderEvent) => {\n setData(prev => {\n const oldIndex = prev.findIndex(row => row.id === event.activeRowId);\n const newIndex = prev.findIndex(row => row.id === event.overRowId);\n if (oldIndex === -1 || newIndex === -1) return prev;\n return arrayMove(prev, oldIndex, newIndex);\n });\n }, []);\n\n return (\n <Table\n data={data}\n columns={securityColumns}\n getRowId={row => row.id}\n onRowReorder={handleRowReorder}\n virtualized='container'\n estimateRowHeight={() => 40}\n />\n );\n}",
|
|
85242
|
+
"description": "Row drag-and-drop with container virtualization — the `DragOverlay` renders the dragged row\noutside the virtualizer so it stays visible even when scrolled out of the virtual window."
|
|
85243
|
+
},
|
|
85244
|
+
{
|
|
85245
|
+
"name": "InlineCellEditing",
|
|
85246
|
+
"code": "() => {\n const [data, setData] = useState<SecurityEvent[]>(() => securityEvents.slice(0, 6));\n // Category starts unselected for every row, so the select shows its placeholder.\n const [categories, setCategories] = useState<Record<string, string>>({});\n\n const updateCell = useCallback(\n <K extends keyof SecurityEvent>(rowId: string, key: K, value: SecurityEvent[K]) => {\n setData(prev => prev.map(row => (row.id === rowId ? { ...row, [key]: value } : row)));\n },\n [],\n );\n\n const columns = useMemo<TableColumnDef<SecurityEvent>[]>(\n () => [\n // The first column is the Table's pinned \"master\" column — keep it\n // read-only; editable cells live in the plain columns after it.\n securityColumnHelper.accessor('sourceIp', {\n header: 'Source',\n size: 200,\n meta: { resizeType: 'cut' as const },\n cell: ({ getValue }) => <Text size='sm'>{getValue()}</Text>,\n }),\n securityColumnHelper.accessor('objectName', {\n header: 'Object name',\n size: 400,\n meta: EDITABLE_CELL_COLUMN_META,\n cell: ({ row, getValue }) => (\n <EditableTextCell\n value={getValue()}\n aria-label='Edit object name'\n onCommit={value => updateCell(row.id, 'objectName', value)}\n />\n ),\n }),\n securityColumnHelper.accessor('status', {\n header: 'Status',\n size: 200,\n meta: EDITABLE_CELL_COLUMN_META,\n cell: ({ row, getValue }) => (\n <EditableSelectCell\n value={getValue()}\n items={statusItems}\n onCommit={value => updateCell(row.id, 'status', value as SecurityEvent['status'])}\n >\n <StatusBadge value={getValue()} />\n </EditableSelectCell>\n ),\n }),\n // Empty-by-default select: consumer supplies the `placeholder` text.\n securityColumnHelper.display({\n id: 'category',\n header: 'Category',\n size: 200,\n meta: EDITABLE_CELL_COLUMN_META,\n cell: ({ row }) => {\n const value = categories[row.id] ?? '';\n return (\n <EditableSelectCell\n value={value}\n items={categoryItems}\n placeholder='Select…'\n aria-label='Edit category'\n onCommit={next => setCategories(prev => ({ ...prev, [row.id]: next }))}\n >\n {categoryItems.find(item => item.value === value)?.label}\n </EditableSelectCell>\n );\n },\n }),\n securityColumnHelper.accessor('parameter', {\n header: 'Parameters',\n size: 240,\n meta: { resizeType: 'cut' as const },\n cell: ({ getValue }) => <InlineCodeSnippet code={getValue()} size='sm' copyable={false} />,\n }),\n ],\n [updateCell, categories],\n );\n\n return (\n <VStack gap={12} align='stretch'>\n <span className='sb-annotation'>click a cell to edit it</span>\n <Table data={data} columns={columns} getRowId={row => row.id} />\n </VStack>\n );\n}"
|
|
85247
|
+
},
|
|
85248
|
+
{
|
|
85249
|
+
"name": "StickyGroupParentStory",
|
|
85250
|
+
"code": "() => {\n const data = useMemo(() => createLargeGroupedData(4, 20), []);\n const [expanded, setExpanded] = useState<TableExpandedState>({\n 'group-0': true,\n 'group-1': true,\n 'group-2': true,\n 'group-3': true,\n });\n const [sorting, setSorting] = useState<TableSortingState>([{ id: 'lastEdited', desc: true }]);\n const [rowSelection, setRowSelection] = useState<TableRowSelectionState>({});\n\n return (\n <Table<SecurityHeaderEntry>\n className='h-300'\n data={data}\n columns={headerColumns}\n getRowId={row => row.id}\n getSubRows={row => row.children}\n expanded={expanded}\n onExpandedChange={setExpanded}\n sorting={sorting}\n onSortingChange={setSorting}\n rowSelection={rowSelection}\n onRowSelectionChange={setRowSelection}\n data-testid='sticky-group-parent-table'\n />\n );\n}",
|
|
85251
|
+
"description": "The group parent row sticks below the header while its children scroll — scroll through\na group to see the parent pin in place, then release when the group boundary passes."
|
|
85252
|
+
},
|
|
85253
|
+
{
|
|
85254
|
+
"name": "StickyGroupParentVirtualized",
|
|
85255
|
+
"code": "() => {\n const data = useMemo(() => createLargeGroupedData(12, 50), []);\n const [expanded, setExpanded] = useState<TableExpandedState>({\n 'group-0': true,\n 'group-1': true,\n 'group-2': true,\n });\n const [sorting, setSorting] = useState<TableSortingState>([{ id: 'lastEdited', desc: true }]);\n const [rowSelection, setRowSelection] = useState<TableRowSelectionState>({});\n\n return (\n <Table<SecurityHeaderEntry>\n className='h-500'\n data={data}\n columns={headerColumns}\n getRowId={row => row.id}\n getSubRows={row => row.children}\n expanded={expanded}\n onExpandedChange={setExpanded}\n sorting={sorting}\n onSortingChange={setSorting}\n rowSelection={rowSelection}\n onRowSelectionChange={setRowSelection}\n virtualized='container'\n data-testid='sticky-group-parent-virt-table'\n />\n );\n}",
|
|
85256
|
+
"description": "The same sticky-parent behavior under container virtualization with large grouped data —\nthe overlay stays in the DOM even when the real parent row is unmounted by the virtualizer."
|
|
85233
85257
|
}
|
|
85234
85258
|
]
|
|
85235
85259
|
},
|