@snack-uikit/table 0.29.0 → 0.30.1-preview-9a03a1c9.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/CHANGELOG.md +11 -0
- package/README.md +2 -0
- package/dist/cjs/components/Table/Table.d.ts +1 -1
- package/dist/cjs/components/Table/Table.js +141 -104
- package/dist/cjs/components/Table/hooks/index.d.ts +1 -0
- package/dist/cjs/components/Table/hooks/index.js +2 -1
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag.d.ts +9 -0
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag.js +76 -0
- package/dist/cjs/components/Table/utils.js +6 -3
- package/dist/cjs/components/types.d.ts +2 -0
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +3 -2
- package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.d.ts +2 -1
- package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.js +13 -3
- package/dist/cjs/helperComponents/Cells/HeaderCell/DragHandle.d.ts +6 -0
- package/dist/cjs/helperComponents/Cells/HeaderCell/DragHandle.js +27 -0
- package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.d.ts +2 -1
- package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.js +22 -2
- package/dist/cjs/helperComponents/Cells/HeaderCell/styles.module.css +11 -0
- package/dist/cjs/helperComponents/Rows/BodyRow.d.ts +4 -1
- package/dist/cjs/helperComponents/Rows/BodyRow.js +30 -12
- package/dist/cjs/helperComponents/Rows/HeaderRow.d.ts +7 -1
- package/dist/cjs/helperComponents/Rows/HeaderRow.js +33 -13
- package/dist/cjs/helperComponents/hooks.d.ts +22 -13
- package/dist/cjs/helperComponents/hooks.js +63 -15
- package/dist/cjs/types.d.ts +5 -0
- package/dist/esm/components/Table/Table.d.ts +1 -1
- package/dist/esm/components/Table/Table.js +34 -25
- package/dist/esm/components/Table/hooks/index.d.ts +1 -0
- package/dist/esm/components/Table/hooks/index.js +1 -0
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag.d.ts +9 -0
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag.js +66 -0
- package/dist/esm/components/Table/utils.js +6 -3
- package/dist/esm/components/types.d.ts +2 -0
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.d.ts +2 -1
- package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.js +7 -3
- package/dist/esm/helperComponents/Cells/HeaderCell/DragHandle.d.ts +6 -0
- package/dist/esm/helperComponents/Cells/HeaderCell/DragHandle.js +6 -0
- package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.d.ts +2 -1
- package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.js +13 -4
- package/dist/esm/helperComponents/Cells/HeaderCell/styles.module.css +11 -0
- package/dist/esm/helperComponents/Rows/BodyRow.d.ts +4 -1
- package/dist/esm/helperComponents/Rows/BodyRow.js +4 -3
- package/dist/esm/helperComponents/Rows/HeaderRow.d.ts +7 -1
- package/dist/esm/helperComponents/Rows/HeaderRow.js +4 -3
- package/dist/esm/helperComponents/hooks.d.ts +22 -13
- package/dist/esm/helperComponents/hooks.js +58 -15
- package/dist/esm/types.d.ts +5 -0
- package/package.json +6 -2
- package/src/components/Table/Table.tsx +151 -117
- package/src/components/Table/hooks/index.ts +1 -0
- package/src/components/Table/hooks/useColumnOrderByDrag.ts +100 -0
- package/src/components/Table/utils.ts +8 -3
- package/src/components/types.ts +3 -0
- package/src/constants.tsx +2 -0
- package/src/helperComponents/Cells/BodyCell/BodyCell.tsx +9 -2
- package/src/helperComponents/Cells/HeaderCell/DragHandle.tsx +18 -0
- package/src/helperComponents/Cells/HeaderCell/HeaderCell.tsx +19 -4
- package/src/helperComponents/Cells/HeaderCell/styles.module.scss +15 -4
- package/src/helperComponents/Rows/BodyRow.tsx +36 -9
- package/src/helperComponents/Rows/HeaderRow.tsx +51 -18
- package/src/helperComponents/Rows/styles.module.scss +2 -2
- package/src/helperComponents/hooks.ts +78 -15
- package/src/types.ts +6 -0
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
10
10
|
});
|
|
11
11
|
exports.HeaderCell = HeaderCell;
|
|
12
12
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
13
14
|
const react_table_1 = require("@tanstack/react-table");
|
|
14
15
|
const classnames_1 = __importDefault(require("classnames"));
|
|
15
16
|
const react_1 = require("react");
|
|
@@ -17,6 +18,7 @@ const truncate_string_1 = require("@snack-uikit/truncate-string");
|
|
|
17
18
|
const constants_1 = require("../../../constants");
|
|
18
19
|
const hooks_1 = require("../../hooks");
|
|
19
20
|
const Cell_1 = require("../Cell");
|
|
21
|
+
const DragHandle_1 = require("./DragHandle");
|
|
20
22
|
const helpers_1 = require("./helpers");
|
|
21
23
|
const ResizeHandle_1 = require("./ResizeHandle");
|
|
22
24
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
@@ -24,6 +26,7 @@ function HeaderCell(_ref) {
|
|
|
24
26
|
let {
|
|
25
27
|
header,
|
|
26
28
|
pinPosition,
|
|
29
|
+
isDraggable,
|
|
27
30
|
className
|
|
28
31
|
} = _ref;
|
|
29
32
|
const cellRef = (0, react_1.useRef)(null);
|
|
@@ -35,16 +38,27 @@ function HeaderCell(_ref) {
|
|
|
35
38
|
const columnSizingInfo = header.getContext().table.getState().columnSizingInfo;
|
|
36
39
|
const isSomeColumnResizing = columnSizingInfo.isResizingColumn;
|
|
37
40
|
const columnDef = header.column.columnDef;
|
|
38
|
-
const style = (0, hooks_1.useCellSizes)(header
|
|
41
|
+
const style = (0, hooks_1.useCellSizes)(header, {
|
|
42
|
+
isDraggable
|
|
43
|
+
});
|
|
44
|
+
const {
|
|
45
|
+
attributes,
|
|
46
|
+
listeners,
|
|
47
|
+
setNodeRef
|
|
48
|
+
} = (0, sortable_1.useSortable)({
|
|
49
|
+
id: header.column.id
|
|
50
|
+
});
|
|
39
51
|
const sortingHandler = e => {
|
|
40
52
|
var _a;
|
|
41
53
|
if (isSomeColumnResizing) return;
|
|
42
54
|
return (_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(e);
|
|
43
55
|
};
|
|
56
|
+
const isAvailableForDrag = !constants_1.UNDRAGGABLE_COLUMNS.includes(header.column.id);
|
|
44
57
|
return (0, jsx_runtime_1.jsxs)(Cell_1.Cell, {
|
|
45
58
|
style: style,
|
|
46
59
|
onClick: sortingHandler,
|
|
47
60
|
"data-sortable": isSortable || undefined,
|
|
61
|
+
"data-draggable": isDraggable || undefined,
|
|
48
62
|
"data-no-padding": columnDef.noHeaderCellPadding || undefined,
|
|
49
63
|
"data-no-offset": columnDef.noHeaderCellBorderOffset || undefined,
|
|
50
64
|
"data-test-id": constants_1.TEST_IDS.headerCell,
|
|
@@ -54,7 +68,10 @@ function HeaderCell(_ref) {
|
|
|
54
68
|
"data-pin-position": pinPosition || undefined,
|
|
55
69
|
role: 'columnheader',
|
|
56
70
|
className: (0, classnames_1.default)(styles_module_scss_1.default.tableHeaderCell, className, columnDef.headerClassName),
|
|
57
|
-
ref:
|
|
71
|
+
ref: element => {
|
|
72
|
+
setNodeRef(element);
|
|
73
|
+
return cellRef;
|
|
74
|
+
},
|
|
58
75
|
children: [(0, jsx_runtime_1.jsxs)("div", {
|
|
59
76
|
className: styles_module_scss_1.default.tableHeaderCellMain,
|
|
60
77
|
children: [columnDef.header && (0, jsx_runtime_1.jsx)("div", {
|
|
@@ -68,6 +85,9 @@ function HeaderCell(_ref) {
|
|
|
68
85
|
"data-test-id": constants_1.TEST_IDS.headerSortIndicator,
|
|
69
86
|
children: sortIcon
|
|
70
87
|
})]
|
|
88
|
+
}), isAvailableForDrag && Boolean(isDraggable) && (0, jsx_runtime_1.jsx)(DragHandle_1.DragHandle, {
|
|
89
|
+
attributes: attributes,
|
|
90
|
+
listeners: listeners
|
|
71
91
|
}), Boolean(isResizable) && (0, jsx_runtime_1.jsx)(ResizeHandle_1.ResizeHandle, {
|
|
72
92
|
header: header,
|
|
73
93
|
cellRef: cellRef
|
|
@@ -129,4 +129,15 @@
|
|
|
129
129
|
.tableHeaderIcon svg{
|
|
130
130
|
width:var(--size-icon-container-xs, 16px) !important;
|
|
131
131
|
height:var(--size-icon-container-xs, 16px) !important;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.dragHandle{
|
|
135
|
+
cursor:pointer;
|
|
136
|
+
display:flex;
|
|
137
|
+
flex-direction:row;
|
|
138
|
+
gap:2px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.dragIcon{
|
|
142
|
+
color:var(--sys-neutral-text-light, #8b8e9b);
|
|
132
143
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Row as TableRow } from '@tanstack/react-table';
|
|
2
2
|
import { MouseEvent } from 'react';
|
|
3
|
+
import { GroupedColumnOrderState } from '../../types';
|
|
3
4
|
export type RowInfo<TData> = {
|
|
4
5
|
id: string;
|
|
5
6
|
data: TData;
|
|
@@ -10,5 +11,7 @@ export type RowClickHandler<TData> = (e: MouseEvent<HTMLDivElement>, row: RowInf
|
|
|
10
11
|
export type BodyRowProps<TData> = {
|
|
11
12
|
row: TableRow<TData>;
|
|
12
13
|
onRowClick?: RowClickHandler<TData>;
|
|
14
|
+
groupedColumnOrderState: GroupedColumnOrderState;
|
|
15
|
+
enableColumnsOrderSortByDrag?: boolean;
|
|
13
16
|
};
|
|
14
|
-
export declare function BodyRow<TData>({ row, onRowClick }: BodyRowProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare function BodyRow<TData>({ row, onRowClick, groupedColumnOrderState, enableColumnsOrderSortByDrag, }: BodyRowProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
10
10
|
});
|
|
11
11
|
exports.BodyRow = BodyRow;
|
|
12
12
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
13
14
|
const react_1 = require("react");
|
|
14
15
|
const constants_1 = require("../../constants");
|
|
15
16
|
const Cells_1 = require("../Cells");
|
|
@@ -21,13 +22,15 @@ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
|
21
22
|
function BodyRow(_ref) {
|
|
22
23
|
let {
|
|
23
24
|
row,
|
|
24
|
-
onRowClick
|
|
25
|
+
onRowClick,
|
|
26
|
+
groupedColumnOrderState,
|
|
27
|
+
enableColumnsOrderSortByDrag
|
|
25
28
|
} = _ref;
|
|
26
29
|
const {
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
leftPinned,
|
|
31
|
+
rightPinned,
|
|
29
32
|
unpinned
|
|
30
|
-
} = (0, hooks_1.useRowCells)(row);
|
|
33
|
+
} = (0, hooks_1.useRowCells)(row, groupedColumnOrderState);
|
|
31
34
|
const [dropListOpened, setDropListOpen] = (0, react_1.useState)(false);
|
|
32
35
|
const disabled = !row.getCanSelect();
|
|
33
36
|
const handleRowClick = e => {
|
|
@@ -53,17 +56,32 @@ function BodyRow(_ref) {
|
|
|
53
56
|
"data-test-id": constants_1.TEST_IDS.bodyRow,
|
|
54
57
|
"data-row-id": row.id,
|
|
55
58
|
className: styles_module_scss_1.default.bodyRow,
|
|
56
|
-
children: [
|
|
59
|
+
children: [leftPinned && (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
57
60
|
position: constants_1.COLUMN_PIN_POSITION.Left,
|
|
58
|
-
children:
|
|
59
|
-
|
|
61
|
+
children: leftPinned.map(cell => (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
62
|
+
items: groupedColumnOrderState.leftPinned,
|
|
63
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
64
|
+
children: (0, jsx_runtime_1.jsx)(Cells_1.BodyCell, {
|
|
65
|
+
cell: cell,
|
|
66
|
+
isDraggable: enableColumnsOrderSortByDrag
|
|
67
|
+
}, cell.id)
|
|
60
68
|
}, cell.id))
|
|
61
|
-
}), unpinned.map(cell => (0, jsx_runtime_1.jsx)(
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
}), unpinned.map(cell => (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
70
|
+
items: groupedColumnOrderState.unpinned,
|
|
71
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
72
|
+
children: (0, jsx_runtime_1.jsx)(Cells_1.BodyCell, {
|
|
73
|
+
cell: cell,
|
|
74
|
+
isDraggable: enableColumnsOrderSortByDrag
|
|
75
|
+
}, cell.id)
|
|
76
|
+
}, cell.id)), rightPinned && (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
64
77
|
position: constants_1.COLUMN_PIN_POSITION.Right,
|
|
65
|
-
children:
|
|
66
|
-
|
|
78
|
+
children: rightPinned.map(cell => (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
79
|
+
items: groupedColumnOrderState.rightPinned,
|
|
80
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
81
|
+
children: (0, jsx_runtime_1.jsx)(Cells_1.BodyCell, {
|
|
82
|
+
cell: cell,
|
|
83
|
+
isDraggable: enableColumnsOrderSortByDrag
|
|
84
|
+
}, cell.id)
|
|
67
85
|
}, cell.id))
|
|
68
86
|
})]
|
|
69
87
|
})
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { GroupedColumnOrderState } from '../../types';
|
|
2
|
+
type Props = {
|
|
3
|
+
groupedColumnOrderState: GroupedColumnOrderState;
|
|
4
|
+
enableColumnsOrderSortByDrag?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function HeaderRow({ groupedColumnOrderState, enableColumnsOrderSortByDrag }: Props): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -10,34 +10,54 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
10
10
|
});
|
|
11
11
|
exports.HeaderRow = HeaderRow;
|
|
12
12
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
13
14
|
const constants_1 = require("../../constants");
|
|
14
15
|
const Cells_1 = require("../Cells");
|
|
15
16
|
const hooks_1 = require("../hooks");
|
|
16
17
|
const PinnedCells_1 = require("./PinnedCells");
|
|
17
18
|
const Row_1 = require("./Row");
|
|
18
19
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
19
|
-
function HeaderRow() {
|
|
20
|
+
function HeaderRow(_ref) {
|
|
21
|
+
let {
|
|
22
|
+
groupedColumnOrderState,
|
|
23
|
+
enableColumnsOrderSortByDrag
|
|
24
|
+
} = _ref;
|
|
20
25
|
const {
|
|
21
26
|
leftPinned,
|
|
22
27
|
unpinned,
|
|
23
28
|
rightPinned
|
|
24
|
-
} = (0, hooks_1.useHeaderGroups)();
|
|
29
|
+
} = (0, hooks_1.useHeaderGroups)(groupedColumnOrderState);
|
|
25
30
|
return (0, jsx_runtime_1.jsxs)(Row_1.Row, {
|
|
26
31
|
className: styles_module_scss_1.default.tableHeader,
|
|
27
32
|
"data-test-id": constants_1.TEST_IDS.headerRow,
|
|
28
|
-
children: [leftPinned && (0, jsx_runtime_1.jsx)(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
children: [leftPinned && (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
34
|
+
items: groupedColumnOrderState.leftPinned,
|
|
35
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
36
|
+
children: (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
37
|
+
position: constants_1.COLUMN_PIN_POSITION.Left,
|
|
38
|
+
children: leftPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (0, jsx_runtime_1.jsx)(Cells_1.HeaderCell, {
|
|
39
|
+
header: header,
|
|
40
|
+
isDraggable: enableColumnsOrderSortByDrag && groupedColumnOrderState.leftPinned.length > 1
|
|
41
|
+
}, header.id)))
|
|
42
|
+
})
|
|
43
|
+
}), (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
44
|
+
items: groupedColumnOrderState.unpinned,
|
|
45
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
46
|
+
children: unpinned.map(headerGroup => headerGroup.headers.map(header => (0, jsx_runtime_1.jsx)(Cells_1.HeaderCell, {
|
|
38
47
|
header: header,
|
|
39
|
-
|
|
48
|
+
isDraggable: enableColumnsOrderSortByDrag && groupedColumnOrderState.unpinned.length > 1
|
|
40
49
|
}, header.id)))
|
|
50
|
+
}), rightPinned && (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
51
|
+
items: groupedColumnOrderState.rightPinned,
|
|
52
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
53
|
+
children: (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
54
|
+
position: constants_1.COLUMN_PIN_POSITION.Right,
|
|
55
|
+
children: rightPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (0, jsx_runtime_1.jsx)(Cells_1.HeaderCell, {
|
|
56
|
+
header: header,
|
|
57
|
+
pinPosition: constants_1.COLUMN_PIN_POSITION.Right,
|
|
58
|
+
isDraggable: enableColumnsOrderSortByDrag && groupedColumnOrderState.rightPinned.length > 1
|
|
59
|
+
}, header.id)))
|
|
60
|
+
})
|
|
41
61
|
})]
|
|
42
62
|
});
|
|
43
63
|
}
|
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
import { Cell, Header, HeaderGroup, Row } from '@tanstack/react-table';
|
|
2
|
-
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
import { GroupedColumnOrderState } from '../types';
|
|
4
|
+
export declare function useHeaderGroups(groupedColumnOrderState: GroupedColumnOrderState): {
|
|
3
5
|
unpinned: HeaderGroup<any>[];
|
|
4
6
|
leftPinned?: undefined;
|
|
5
7
|
rightPinned?: undefined;
|
|
6
8
|
} | {
|
|
7
|
-
leftPinned:
|
|
8
|
-
|
|
9
|
+
leftPinned: {
|
|
10
|
+
headers: Header<unknown, unknown>[];
|
|
11
|
+
depth: number;
|
|
12
|
+
id: string;
|
|
13
|
+
}[] | undefined;
|
|
14
|
+
rightPinned: {
|
|
15
|
+
headers: Header<unknown, unknown>[];
|
|
16
|
+
depth: number;
|
|
17
|
+
id: string;
|
|
18
|
+
}[] | undefined;
|
|
9
19
|
unpinned: HeaderGroup<any>[];
|
|
10
20
|
};
|
|
11
|
-
export declare function useRowCells<TData>(row: Row<TData
|
|
21
|
+
export declare function useRowCells<TData>(row: Row<TData>, groupedColumnOrderState: GroupedColumnOrderState): {
|
|
12
22
|
unpinned: Cell<TData, unknown>[];
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
leftPinned?: undefined;
|
|
24
|
+
rightPinned?: undefined;
|
|
15
25
|
} | {
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
leftPinned: Cell<TData, unknown>[] | undefined;
|
|
27
|
+
rightPinned: Cell<TData, unknown>[] | undefined;
|
|
18
28
|
unpinned: Cell<TData, unknown>[];
|
|
19
29
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
width: string;
|
|
23
|
-
maxWidth: number | undefined;
|
|
24
|
-
flexShrink: string;
|
|
30
|
+
type CellSizesOptions = {
|
|
31
|
+
isDraggable?: boolean;
|
|
25
32
|
};
|
|
33
|
+
export declare function useCellSizes<TData>(element: Cell<TData, unknown> | Header<TData, unknown>, options?: CellSizesOptions): CSSProperties;
|
|
34
|
+
export {};
|
|
@@ -6,17 +6,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useHeaderGroups = useHeaderGroups;
|
|
7
7
|
exports.useRowCells = useRowCells;
|
|
8
8
|
exports.useCellSizes = useCellSizes;
|
|
9
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
10
|
+
const utilities_1 = require("@dnd-kit/utilities");
|
|
9
11
|
const react_1 = require("react");
|
|
10
12
|
const contexts_1 = require("./contexts");
|
|
11
13
|
function hasHeaders(groups) {
|
|
12
14
|
return groups.some(group => group.headers.length);
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
const sortHeaderGroup = (groups, groupOrder) => groups.map(group => Object.assign(Object.assign({}, group), {
|
|
17
|
+
headers: group.headers.sort((a, b) => {
|
|
18
|
+
const indexA = groupOrder.findIndex(columnId => columnId === a.id);
|
|
19
|
+
const indexB = groupOrder.findIndex(columnId => columnId === b.id);
|
|
20
|
+
if (indexA > -1 && indexB > -1) {
|
|
21
|
+
return indexA - indexB;
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
})
|
|
25
|
+
}));
|
|
26
|
+
function useHeaderGroups(groupedColumnOrderState) {
|
|
15
27
|
const {
|
|
16
28
|
table
|
|
17
29
|
} = (0, contexts_1.useTableContext)();
|
|
18
30
|
const columnDefs = table._getColumnDefs();
|
|
19
31
|
const pinEnabled = table.getIsSomeColumnsPinned();
|
|
32
|
+
const {
|
|
33
|
+
columnOrder
|
|
34
|
+
} = table.getState();
|
|
20
35
|
return (0, react_1.useMemo)(() => {
|
|
21
36
|
if (!pinEnabled) {
|
|
22
37
|
return {
|
|
@@ -26,20 +41,33 @@ function useHeaderGroups() {
|
|
|
26
41
|
const left = table.getLeftHeaderGroups();
|
|
27
42
|
const right = table.getRightHeaderGroups();
|
|
28
43
|
return {
|
|
29
|
-
leftPinned: hasHeaders(left) ? left : undefined,
|
|
30
|
-
rightPinned: hasHeaders(right) ? right : undefined,
|
|
44
|
+
leftPinned: hasHeaders(left) ? sortHeaderGroup(left, groupedColumnOrderState.leftPinned) : undefined,
|
|
45
|
+
rightPinned: hasHeaders(right) ? sortHeaderGroup(right, groupedColumnOrderState.rightPinned) : undefined,
|
|
31
46
|
unpinned: table.getCenterHeaderGroups()
|
|
32
47
|
};
|
|
33
48
|
// need to rebuild if columnDefinitions has changed
|
|
34
49
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
}, [table, pinEnabled, columnDefs]);
|
|
50
|
+
}, [table, pinEnabled, columnDefs, columnOrder, groupedColumnOrderState]);
|
|
36
51
|
}
|
|
37
|
-
function
|
|
52
|
+
function sortPinnedColumnsByOrderState(groupOrder) {
|
|
53
|
+
return (a, b) => {
|
|
54
|
+
const indexA = groupOrder.findIndex(columnId => columnId === a.column.id);
|
|
55
|
+
const indexB = groupOrder.findIndex(columnId => columnId === b.column.id);
|
|
56
|
+
if (indexA > -1 && indexB > -1) {
|
|
57
|
+
return indexA - indexB;
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function useRowCells(row, groupedColumnOrderState) {
|
|
38
63
|
const {
|
|
39
64
|
table
|
|
40
65
|
} = (0, contexts_1.useTableContext)();
|
|
41
66
|
const pinEnabled = table.getIsSomeColumnsPinned();
|
|
42
67
|
const columnDefs = table._getColumnDefs();
|
|
68
|
+
const {
|
|
69
|
+
columnOrder
|
|
70
|
+
} = table.getState();
|
|
43
71
|
return (0, react_1.useMemo)(() => {
|
|
44
72
|
if (!pinEnabled) {
|
|
45
73
|
return {
|
|
@@ -49,24 +77,44 @@ function useRowCells(row) {
|
|
|
49
77
|
const left = row.getLeftVisibleCells();
|
|
50
78
|
const right = row.getRightVisibleCells();
|
|
51
79
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
leftPinned: left.length ? left.slice().sort(sortPinnedColumnsByOrderState(groupedColumnOrderState.leftPinned)) : undefined,
|
|
81
|
+
rightPinned: right.length ? right.slice().sort(sortPinnedColumnsByOrderState(groupedColumnOrderState.rightPinned)) : undefined,
|
|
54
82
|
unpinned: row.getCenterVisibleCells()
|
|
55
83
|
};
|
|
56
84
|
// need to rebuild if columnDefinitions has changed
|
|
57
85
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
}, [row, pinEnabled, columnDefs]);
|
|
86
|
+
}, [row, pinEnabled, columnDefs, columnOrder, groupedColumnOrderState]);
|
|
59
87
|
}
|
|
60
|
-
function useCellSizes(element) {
|
|
88
|
+
function useCellSizes(element, options) {
|
|
61
89
|
const column = element.column;
|
|
90
|
+
const {
|
|
91
|
+
isDragging,
|
|
92
|
+
transform
|
|
93
|
+
} = (0, sortable_1.useSortable)({
|
|
94
|
+
id: column.id
|
|
95
|
+
});
|
|
62
96
|
const minWidth = column.columnDef.minSize;
|
|
63
97
|
const maxWidth = column.columnDef.maxSize;
|
|
64
98
|
const width = `var(--table-column-${column.id}-size)`;
|
|
65
99
|
const flexShrink = `var(--table-column-${column.id}-flex)`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
100
|
+
const isHeaderCell = 'headerGroup' in element;
|
|
101
|
+
return (0, react_1.useMemo)(() => {
|
|
102
|
+
const styles = {
|
|
103
|
+
minWidth,
|
|
104
|
+
width,
|
|
105
|
+
maxWidth,
|
|
106
|
+
flexShrink
|
|
107
|
+
};
|
|
108
|
+
if (options === null || options === void 0 ? void 0 : options.isDraggable) {
|
|
109
|
+
styles.opacity = isDragging ? 0.8 : 1;
|
|
110
|
+
styles.position = 'relative';
|
|
111
|
+
styles.transform = utilities_1.CSS.Translate.toString(transform);
|
|
112
|
+
styles.transition = 'width transform 0.2s ease-in-out';
|
|
113
|
+
styles.zIndex = isDragging ? 1 : 0;
|
|
114
|
+
if (isHeaderCell) {
|
|
115
|
+
styles.whiteSpace = 'nowrap';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return styles;
|
|
119
|
+
}, [options === null || options === void 0 ? void 0 : options.isDraggable, flexShrink, isDragging, isHeaderCell, maxWidth, minWidth, transform, width]);
|
|
72
120
|
}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -40,5 +40,10 @@ type PinnedColumnDefinition<TData> = BaseColumnDefinition<TData> & {
|
|
|
40
40
|
size: number;
|
|
41
41
|
};
|
|
42
42
|
export type ColumnDefinition<TData> = NormalColumnDefinition<TData> | PinnedColumnDefinition<TData>;
|
|
43
|
+
export type GroupedColumnOrderState = {
|
|
44
|
+
leftPinned: string[];
|
|
45
|
+
rightPinned: string[];
|
|
46
|
+
unpinned: string[];
|
|
47
|
+
};
|
|
43
48
|
export type { RowActionsColumnDefProps, StatusColumnDefinitionProps, RowInfo, RowClickHandler, ActionsGenerator, CopyCellProps, MapStatusToAppearanceFnType, } from './helperComponents';
|
|
44
49
|
export type { ColumnPinPosition, PaginationState, SortingState, RowSelectionState, RowSelectionOptions, EmptyStateProps, ToolbarProps, HeaderContext, CellContext, };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FiltersState } from '@snack-uikit/chips';
|
|
2
2
|
import { TableProps } from '../types';
|
|
3
3
|
/** Компонент таблицы */
|
|
4
|
-
export declare function Table<TData extends object, TFilters extends FiltersState = Record<string, unknown>>({ data, rowPinning, columnDefinitions, keepPinnedRows, copyPinnedRows, enableSelectPinned, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, pageSize, pageCount, loading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, suppressSearch, toolbarAfter, suppressPagination, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, ...rest }: TableProps<TData, TFilters>): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare function Table<TData extends object, TFilters extends FiltersState = Record<string, unknown>>({ data, rowPinning, columnDefinitions, keepPinnedRows, copyPinnedRows, enableSelectPinned, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, pageSize, pageCount, loading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, suppressSearch, toolbarAfter, suppressPagination, manualSorting, manualPagination, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, enableColumnsOrderSortByDrag, ...rest }: TableProps<TData, TFilters>): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export declare namespace Table {
|
|
6
6
|
var getStatusColumnDef: typeof import("../../helperComponents").getStatusColumnDef;
|
|
7
7
|
var statusAppearances: Record<string, string>;
|
|
@@ -10,6 +10,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { closestCenter, DndContext } from '@dnd-kit/core';
|
|
14
|
+
import { restrictToHorizontalAxis } from '@dnd-kit/modifiers';
|
|
13
15
|
import { getCoreRowModel, getExpandedRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from '@tanstack/react-table';
|
|
14
16
|
import cn from 'classnames';
|
|
15
17
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
@@ -24,7 +26,7 @@ import { CellAutoResizeContext, useCellAutoResizeController } from '../../contex
|
|
|
24
26
|
import { BodyRow, ExportButton, getColumnId, getRowActionsColumnDef, getSelectionCellColumnDef, getStatusColumnDef, HeaderRow, STATUS_APPEARANCE, TableContext, TableEmptyState, TablePagination, useEmptyState, } from '../../helperComponents';
|
|
25
27
|
import { getTreeColumnDef } from '../../helperComponents/Cells/TreeCell';
|
|
26
28
|
import { fuzzyFilter } from '../../utils';
|
|
27
|
-
import { useLoadingTable, useStateControl } from './hooks';
|
|
29
|
+
import { useColumnOrderByDrag, useLoadingTable, useStateControl } from './hooks';
|
|
28
30
|
import { usePageReset } from './hooks/usePageReset';
|
|
29
31
|
import styles from './styles.module.css';
|
|
30
32
|
import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth, getInitColumnSizeFromLocalStorage, saveStateToLocalStorage, } from './utils';
|
|
@@ -32,7 +34,7 @@ import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth, getInitColumnSiz
|
|
|
32
34
|
export function Table(_a) {
|
|
33
35
|
var { data, rowPinning = {
|
|
34
36
|
top: [],
|
|
35
|
-
}, columnDefinitions, keepPinnedRows = false, copyPinnedRows = false, enableSelectPinned = false, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, pageSize = DEFAULT_PAGE_SIZE, pageCount, loading = false, outline = false, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar = false, suppressSearch = false, toolbarAfter, suppressPagination = false, manualSorting = false, manualPagination = false, manualFiltering = false, autoResetPageIndex = false, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp } = _a, rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "pageSize", "pageCount", "loading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "suppressSearch", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState", "expanding", "bulkActions"]);
|
|
37
|
+
}, columnDefinitions, keepPinnedRows = false, copyPinnedRows = false, enableSelectPinned = false, rowSelection: rowSelectionProp, search, sorting: sortingProp, columnFilters, pagination: paginationProp, className, onRowClick, onRefresh, pageSize = DEFAULT_PAGE_SIZE, pageCount, loading = false, outline = false, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar = false, suppressSearch = false, toolbarAfter, suppressPagination = false, manualSorting = false, manualPagination = false, manualFiltering = false, autoResetPageIndex = false, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, enableColumnsOrderSortByDrag } = _a, rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "pageSize", "pageCount", "loading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "suppressSearch", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState", "expanding", "bulkActions", "enableColumnsOrderSortByDrag"]);
|
|
36
38
|
const { state: globalFilter, onStateChange: onGlobalFilterChange } = useStateControl(search, '');
|
|
37
39
|
const { state: rowSelection, onStateChange: onRowSelectionChange } = useStateControl(rowSelectionProp, {});
|
|
38
40
|
const defaultPaginationState = useMemo(() => ({
|
|
@@ -52,6 +54,7 @@ export function Table(_a) {
|
|
|
52
54
|
}
|
|
53
55
|
return cols;
|
|
54
56
|
}, [columnDefinitions, enableSelection, enableSelectPinned, expanding]);
|
|
57
|
+
const { columnOrder, setColumnOrder, groupedColumnOrderState, sensors, handleDragEnd } = useColumnOrderByDrag(tableColumns);
|
|
55
58
|
const columnPinning = useMemo(() => {
|
|
56
59
|
var _a;
|
|
57
60
|
const pinningState = { left: [], right: [] };
|
|
@@ -78,6 +81,7 @@ export function Table(_a) {
|
|
|
78
81
|
columns: tableColumns,
|
|
79
82
|
state: {
|
|
80
83
|
columnPinning,
|
|
84
|
+
columnOrder,
|
|
81
85
|
globalFilter,
|
|
82
86
|
rowSelection,
|
|
83
87
|
sorting,
|
|
@@ -91,6 +95,7 @@ export function Table(_a) {
|
|
|
91
95
|
minSize: 40,
|
|
92
96
|
cell: (cell) => _jsx(TruncateString, { text: String(cell.getValue()), maxLines: 1 }),
|
|
93
97
|
},
|
|
98
|
+
onColumnOrderChange: setColumnOrder,
|
|
94
99
|
manualSorting,
|
|
95
100
|
manualPagination,
|
|
96
101
|
manualFiltering,
|
|
@@ -155,17 +160,19 @@ export function Table(_a) {
|
|
|
155
160
|
}, [loading, rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow, table, enableSelectPinned]);
|
|
156
161
|
const columnSizeVarsRef = useRef();
|
|
157
162
|
const headers = table.getFlatHeaders();
|
|
158
|
-
const
|
|
163
|
+
const columnSizes = useMemo(() => {
|
|
159
164
|
var _a;
|
|
160
165
|
const originalColumnDefs = table._getColumnDefs();
|
|
161
|
-
const
|
|
166
|
+
const vars = {};
|
|
167
|
+
const realSizes = {};
|
|
168
|
+
const resizedColumnIndex = headers.findIndex(({ column }) => column.getIsResizing());
|
|
162
169
|
for (let i = 0; i < headers.length; i++) {
|
|
163
170
|
const header = headers[i];
|
|
164
171
|
const { sizeKey, flexKey } = getColumnStyleVars(header.id);
|
|
165
172
|
const originalColDef = originalColumnDefs.find(col => getColumnId(header) === col.id);
|
|
166
173
|
if (header.id === 'snack_predefined_statusColumn' && !(originalColDef === null || originalColDef === void 0 ? void 0 : originalColDef.header) && !(originalColDef === null || originalColDef === void 0 ? void 0 : originalColDef.enableSorting)) {
|
|
167
|
-
|
|
168
|
-
|
|
174
|
+
vars[sizeKey] = 'var(--size-table-cell-status-indicator-horizontal)';
|
|
175
|
+
vars[flexKey] = '100%';
|
|
169
176
|
}
|
|
170
177
|
else {
|
|
171
178
|
const originalColumnDefSize = originalColDef === null || originalColDef === void 0 ? void 0 : originalColDef.size;
|
|
@@ -182,21 +189,20 @@ export function Table(_a) {
|
|
|
182
189
|
if (header.column.getCanResize()) {
|
|
183
190
|
const currentSize = header.getSize();
|
|
184
191
|
const colDefSize = header.column.columnDef.size;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
table.setColumnSizing(old => (Object.assign(Object.assign({}, old), { [header.id]: realSize })));
|
|
192
|
+
if (currentSize !== colDefSize || (i < resizedColumnIndex && prevSize === '100%')) {
|
|
193
|
+
const realSize = prevSize === '100%' ? getCurrentlyConfiguredHeaderWidth(header.id) : currentSize;
|
|
194
|
+
realSizes[header.id] = realSize;
|
|
189
195
|
size = `${realSize}px`;
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
if (isResizeSavedToStore) {
|
|
193
199
|
saveStateToLocalStorage({ id: savedState.id, columnId: header.id, size });
|
|
194
200
|
}
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
vars[sizeKey] = size;
|
|
202
|
+
vars[flexKey] = size === '100%' ? 'unset' : '0';
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
|
-
return
|
|
205
|
+
return { vars, realSizes };
|
|
200
206
|
/*
|
|
201
207
|
effect must be called only on columnSizingInfo.isResizingColumn changes
|
|
202
208
|
to reduce unnecessary recalculations
|
|
@@ -208,8 +214,11 @@ export function Table(_a) {
|
|
|
208
214
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
209
215
|
}, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize()]);
|
|
210
216
|
useEffect(() => {
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
if (Object.keys(columnSizes.realSizes).length) {
|
|
218
|
+
table.setColumnSizing(old => (Object.assign(Object.assign({}, old), columnSizes.realSizes)));
|
|
219
|
+
}
|
|
220
|
+
columnSizeVarsRef.current = columnSizes.vars;
|
|
221
|
+
}, [columnSizes, table]);
|
|
213
222
|
const tableRows = table.getRowModel().rows;
|
|
214
223
|
const tableCenterRows = table.getCenterRows();
|
|
215
224
|
const tableFilteredRows = table.getFilteredRowModel().rows;
|
|
@@ -236,16 +245,16 @@ export function Table(_a) {
|
|
|
236
245
|
});
|
|
237
246
|
const { updateCellMap } = useCellAutoResizeController(table);
|
|
238
247
|
const showToolbar = !suppressToolbar;
|
|
239
|
-
return (_jsx(CellAutoResizeContext.Provider, { value: { updateCellMap }, children: _jsxs("div", Object.assign({ style: {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
return (_jsx(DndContext, { collisionDetection: closestCenter, modifiers: [restrictToHorizontalAxis], onDragEnd: handleDragEnd, sensors: sensors, children: _jsx(CellAutoResizeContext.Provider, { value: { updateCellMap }, children: _jsxs("div", Object.assign({ style: {
|
|
249
|
+
'--page-size': cssPageSize,
|
|
250
|
+
}, className: cn(styles.wrapper, className) }, extractSupportProps(rest), { children: [showToolbar && (_jsx("div", { className: styles.header, children: _jsx(Toolbar, { search: suppressSearch
|
|
251
|
+
? undefined
|
|
252
|
+
: {
|
|
253
|
+
value: globalFilter,
|
|
254
|
+
onChange: onGlobalFilterChange,
|
|
255
|
+
loading: search === null || search === void 0 ? void 0 : search.loading,
|
|
256
|
+
placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || t('searchPlaceholder'),
|
|
257
|
+
}, className: styles.toolbar, onRefresh: onRefresh ? handleOnRefresh : undefined, bulkActions: bulkActions, selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), onCheck: enableSelection ? handleOnToolbarCheck : undefined, outline: outline, after: toolbarAfter || exportSettings ? (_jsxs(_Fragment, { children: [toolbarAfter, exportSettings && (_jsx(ExportButton, { settings: exportSettings, columnDefinitions: columnDefinitions, data: data, topRows: filteredTopRows, centerRows: centerRows }))] })) : undefined, moreActions: moreActions, filterRow: columnFilters, "data-test-id": TEST_IDS.toolbar }) })), _jsx("div", { className: styles.scrollWrapper, "data-outline": outline || undefined, children: _jsxs(Scroll, { size: 's', className: styles.table, ref: scrollContainerRef, children: [_jsx("div", { className: styles.tableContent, style: columnSizes.vars, children: _jsx(TableContext.Provider, { value: { table }, children: loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, { groupedColumnOrderState: groupedColumnOrderState }), loadingTableRows.map(row => (_jsx(BodyRow, { row: row, groupedColumnOrderState: groupedColumnOrderState }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? (_jsx(HeaderRow, { groupedColumnOrderState: groupedColumnOrderState, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag })) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, groupedColumnOrderState: groupedColumnOrderState }, row.id))) })) : null, centerRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, groupedColumnOrderState: groupedColumnOrderState, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag }, row.id))), _jsx(TableEmptyState, { emptyStates: emptyStates, dataError: dataError, dataFiltered: dataFiltered || Boolean(table.getState().globalFilter), tableRowsLength: tableRows.length + filteredTopRows.length })] })) }) }), _jsx("div", { className: styles.scrollStub, ref: scrollRef })] }) }), !suppressPagination && (_jsx(TablePagination, { table: table, options: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.options, optionsLabel: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsLabel, pageCount: pageCount, optionsRender: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsRender }))] })) }) }));
|
|
249
258
|
}
|
|
250
259
|
Table.getStatusColumnDef = getStatusColumnDef;
|
|
251
260
|
Table.statusAppearances = STATUS_APPEARANCE;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DragEndEvent } from '@dnd-kit/core';
|
|
2
|
+
import { ColumnDefinition, GroupedColumnOrderState } from '../../../types';
|
|
3
|
+
export declare function useColumnOrderByDrag<TData extends object>(tableColumns: ColumnDefinition<TData>[]): {
|
|
4
|
+
columnOrder: string[];
|
|
5
|
+
setColumnOrder: import("react").Dispatch<import("react").SetStateAction<string[]>>;
|
|
6
|
+
groupedColumnOrderState: GroupedColumnOrderState;
|
|
7
|
+
handleDragEnd: ({ active, over }: DragEndEvent) => void;
|
|
8
|
+
sensors: import("@dnd-kit/core").SensorDescriptor<import("@dnd-kit/core").SensorOptions>[];
|
|
9
|
+
};
|