@snack-uikit/table 0.33.4 → 0.34.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 +5 -3
- package/dist/cjs/components/Table/Table.d.ts +1 -1
- package/dist/cjs/components/Table/Table.js +107 -48
- 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 +8 -0
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag.js +49 -0
- package/dist/cjs/components/Table/utils.d.ts +13 -0
- package/dist/cjs/components/Table/utils.js +71 -0
- package/dist/cjs/components/types.d.ts +12 -3
- 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/HeaderCell.d.ts +2 -1
- package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.js +41 -17
- package/dist/cjs/helperComponents/Cells/HeaderCell/styles.module.css +10 -0
- package/dist/cjs/helperComponents/ColumnsSettings/ColumnsSettings.d.ts +8 -0
- package/dist/cjs/helperComponents/ColumnsSettings/ColumnsSettings.js +38 -0
- package/dist/cjs/helperComponents/ColumnsSettings/index.d.ts +1 -0
- package/dist/cjs/helperComponents/ColumnsSettings/index.js +25 -0
- package/dist/cjs/helperComponents/ColumnsSettings/styles.module.css +3 -0
- package/dist/cjs/helperComponents/Rows/BodyRow.d.ts +4 -1
- package/dist/cjs/helperComponents/Rows/BodyRow.js +20 -11
- package/dist/cjs/helperComponents/Rows/HeaderRow.d.ts +7 -1
- package/dist/cjs/helperComponents/Rows/HeaderRow.js +13 -5
- package/dist/cjs/helperComponents/hooks.d.ts +9 -9
- package/dist/cjs/helperComponents/hooks.js +39 -11
- package/dist/cjs/helperComponents/index.d.ts +1 -0
- package/dist/cjs/helperComponents/index.js +2 -1
- package/dist/cjs/types.d.ts +11 -3
- package/dist/esm/components/Table/Table.d.ts +1 -1
- package/dist/esm/components/Table/Table.js +40 -12
- 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 +8 -0
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag.js +39 -0
- package/dist/esm/components/Table/utils.d.ts +13 -0
- package/dist/esm/components/Table/utils.js +70 -0
- package/dist/esm/components/types.d.ts +12 -3
- 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/HeaderCell.d.ts +2 -1
- package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.js +14 -4
- package/dist/esm/helperComponents/Cells/HeaderCell/styles.module.css +10 -0
- package/dist/esm/helperComponents/ColumnsSettings/ColumnsSettings.d.ts +8 -0
- package/dist/esm/helperComponents/ColumnsSettings/ColumnsSettings.js +12 -0
- package/dist/esm/helperComponents/ColumnsSettings/index.d.ts +1 -0
- package/dist/esm/helperComponents/ColumnsSettings/index.js +1 -0
- package/dist/esm/helperComponents/ColumnsSettings/styles.module.css +3 -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 +3 -2
- package/dist/esm/helperComponents/hooks.d.ts +9 -9
- package/dist/esm/helperComponents/hooks.js +32 -11
- package/dist/esm/helperComponents/index.d.ts +1 -0
- package/dist/esm/helperComponents/index.js +1 -0
- package/dist/esm/types.d.ts +11 -3
- package/package.json +9 -5
- package/src/components/Table/Table.tsx +147 -61
- package/src/components/Table/hooks/index.ts +1 -0
- package/src/components/Table/hooks/useColumnOrderByDrag.ts +67 -0
- package/src/components/Table/utils.ts +118 -0
- package/src/components/types.ts +13 -3
- package/src/constants.tsx +1 -0
- package/src/helperComponents/Cells/BodyCell/BodyCell.tsx +9 -2
- package/src/helperComponents/Cells/HeaderCell/HeaderCell.tsx +50 -23
- package/src/helperComponents/Cells/HeaderCell/styles.module.scss +15 -0
- package/src/helperComponents/ColumnsSettings/ColumnsSettings.tsx +28 -0
- package/src/helperComponents/ColumnsSettings/index.ts +1 -0
- package/src/helperComponents/ColumnsSettings/styles.module.scss +5 -0
- package/src/helperComponents/Rows/BodyRow.tsx +30 -8
- package/src/helperComponents/Rows/HeaderRow.tsx +21 -4
- package/src/helperComponents/hooks.ts +41 -11
- package/src/helperComponents/index.ts +1 -0
- package/src/types.ts +21 -3
|
@@ -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");
|
|
@@ -25,7 +26,8 @@ function HeaderCell(_ref) {
|
|
|
25
26
|
header,
|
|
26
27
|
pinPosition,
|
|
27
28
|
className,
|
|
28
|
-
rowAutoHeight
|
|
29
|
+
rowAutoHeight,
|
|
30
|
+
isDraggable
|
|
29
31
|
} = _ref;
|
|
30
32
|
const cellRef = (0, react_1.useRef)(null);
|
|
31
33
|
const isSortable = header.column.getCanSort();
|
|
@@ -36,16 +38,30 @@ function HeaderCell(_ref) {
|
|
|
36
38
|
const columnSizingInfo = header.getContext().table.getState().columnSizingInfo;
|
|
37
39
|
const isSomeColumnResizing = columnSizingInfo.isResizingColumn;
|
|
38
40
|
const columnDef = header.column.columnDef;
|
|
39
|
-
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
|
+
isDragging
|
|
49
|
+
} = (0, sortable_1.useSortable)({
|
|
50
|
+
id: header.column.id
|
|
51
|
+
});
|
|
40
52
|
const sortingHandler = e => {
|
|
41
53
|
var _a;
|
|
42
54
|
if (isSomeColumnResizing) return;
|
|
43
55
|
return (_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(e);
|
|
44
56
|
};
|
|
57
|
+
const isAvailableForDrag = !constants_1.DEFAULT_COLUMNS.includes(header.column.id);
|
|
58
|
+
const dragAttributes = isAvailableForDrag ? attributes : {};
|
|
59
|
+
const listenersAttributes = isAvailableForDrag ? listeners : {};
|
|
45
60
|
return (0, jsx_runtime_1.jsxs)(Cell_1.Cell, {
|
|
46
61
|
style: style,
|
|
47
62
|
onClick: sortingHandler,
|
|
48
63
|
"data-sortable": isSortable || undefined,
|
|
64
|
+
"data-draggable": isDraggable || undefined,
|
|
49
65
|
"data-no-padding": columnDef.noHeaderCellPadding || undefined,
|
|
50
66
|
"data-no-offset": columnDef.noHeaderCellBorderOffset || undefined,
|
|
51
67
|
"data-test-id": constants_1.TEST_IDS.headerCell,
|
|
@@ -56,21 +72,29 @@ function HeaderCell(_ref) {
|
|
|
56
72
|
"data-row-auto-height": rowAutoHeight || undefined,
|
|
57
73
|
role: 'columnheader',
|
|
58
74
|
className: (0, classnames_1.default)(styles_module_scss_1.default.tableHeaderCell, className, columnDef.headerClassName),
|
|
59
|
-
ref:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
className: styles_module_scss_1.default.
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
ref: element => {
|
|
76
|
+
setNodeRef(element);
|
|
77
|
+
return cellRef;
|
|
78
|
+
},
|
|
79
|
+
children: [(0, jsx_runtime_1.jsx)("div", Object.assign({
|
|
80
|
+
className: styles_module_scss_1.default.tableHeaderCellDragWrapper,
|
|
81
|
+
"data-dragging": isDragging || undefined
|
|
82
|
+
}, dragAttributes, listenersAttributes, {
|
|
83
|
+
children: (0, jsx_runtime_1.jsxs)("div", {
|
|
84
|
+
className: styles_module_scss_1.default.tableHeaderCellMain,
|
|
85
|
+
children: [columnDef.header && (0, jsx_runtime_1.jsx)("div", {
|
|
86
|
+
className: styles_module_scss_1.default.tableHeaderCellName,
|
|
87
|
+
children: rowAutoHeight ? (0, react_table_1.flexRender)(columnDef.header, header.getContext()) : (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
|
|
88
|
+
text: (0, react_table_1.flexRender)(columnDef.header, header.getContext())
|
|
89
|
+
})
|
|
90
|
+
}), Boolean(sortIcon) && (0, jsx_runtime_1.jsx)("div", {
|
|
91
|
+
className: styles_module_scss_1.default.tableHeaderIcon,
|
|
92
|
+
"data-sort-direction": sortDirection,
|
|
93
|
+
"data-test-id": constants_1.TEST_IDS.headerSortIndicator,
|
|
94
|
+
children: sortIcon
|
|
95
|
+
})]
|
|
96
|
+
})
|
|
97
|
+
})), Boolean(isResizable) && (0, jsx_runtime_1.jsx)(ResizeHandle_1.ResizeHandle, {
|
|
74
98
|
header: header,
|
|
75
99
|
cellRef: cellRef
|
|
76
100
|
})]
|
|
@@ -71,6 +71,9 @@
|
|
|
71
71
|
.tableHeaderCell:hover .tableHeaderResizeHandle:not([data-resizing]){
|
|
72
72
|
opacity:1;
|
|
73
73
|
}
|
|
74
|
+
.tableHeaderCell[data-draggable]{
|
|
75
|
+
cursor:grab;
|
|
76
|
+
}
|
|
74
77
|
.tableHeaderCell[data-sortable]{
|
|
75
78
|
cursor:pointer;
|
|
76
79
|
}
|
|
@@ -111,6 +114,13 @@
|
|
|
111
114
|
padding-bottom:0;
|
|
112
115
|
}
|
|
113
116
|
|
|
117
|
+
.tableHeaderCellDragWrapper{
|
|
118
|
+
width:100%;
|
|
119
|
+
}
|
|
120
|
+
.tableHeaderCellDragWrapper[data-dragging]:active{
|
|
121
|
+
cursor:grabbing;
|
|
122
|
+
}
|
|
123
|
+
|
|
114
124
|
.tableHeaderCellMain{
|
|
115
125
|
overflow:auto;
|
|
116
126
|
display:flex;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GroupSelectItemProps } from '@snack-uikit/list';
|
|
2
|
+
type ColumnsSettingsProps = {
|
|
3
|
+
enabledColumns: string[];
|
|
4
|
+
setEnabledColumns(enabledColumns: string[]): void;
|
|
5
|
+
columnsSettings: [GroupSelectItemProps];
|
|
6
|
+
};
|
|
7
|
+
export declare function ColumnsSettings({ columnsSettings, enabledColumns, setEnabledColumns }: ColumnsSettingsProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : {
|
|
5
|
+
"default": mod
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
exports.ColumnsSettings = ColumnsSettings;
|
|
12
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const button_1 = require("@snack-uikit/button");
|
|
14
|
+
const icons_1 = require("@snack-uikit/icons");
|
|
15
|
+
const list_1 = require("@snack-uikit/list");
|
|
16
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
17
|
+
function ColumnsSettings(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
columnsSettings,
|
|
20
|
+
enabledColumns,
|
|
21
|
+
setEnabledColumns
|
|
22
|
+
} = _ref;
|
|
23
|
+
return (0, jsx_runtime_1.jsx)(list_1.Droplist, {
|
|
24
|
+
className: styles_module_scss_1.default.columnsSettings,
|
|
25
|
+
items: columnsSettings,
|
|
26
|
+
selection: {
|
|
27
|
+
value: enabledColumns,
|
|
28
|
+
onChange: setEnabledColumns,
|
|
29
|
+
mode: 'multiple'
|
|
30
|
+
},
|
|
31
|
+
placement: 'bottom-end',
|
|
32
|
+
children: (0, jsx_runtime_1.jsx)(button_1.ButtonFunction, {
|
|
33
|
+
size: 'm',
|
|
34
|
+
"data-test-id": 'table__column-settings',
|
|
35
|
+
icon: (0, jsx_runtime_1.jsx)(icons_1.FunctionSettingsSVG, {})
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ColumnsSettings';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./ColumnsSettings"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Row as TableRow } from '@tanstack/react-table';
|
|
2
2
|
import { MouseEvent } from 'react';
|
|
3
|
+
import { ColumnOrder } from '../../types';
|
|
3
4
|
import { RowProps } from './Row';
|
|
4
5
|
export type RowInfo<TData> = {
|
|
5
6
|
id: string;
|
|
@@ -11,5 +12,7 @@ export type RowClickHandler<TData> = (e: MouseEvent<HTMLDivElement>, row: RowInf
|
|
|
11
12
|
export type BodyRowProps<TData> = Pick<RowProps, 'rowAutoHeight'> & {
|
|
12
13
|
row: TableRow<TData>;
|
|
13
14
|
onRowClick?: RowClickHandler<TData>;
|
|
15
|
+
columnOrder: ColumnOrder;
|
|
16
|
+
enableColumnsOrderSortByDrag?: boolean;
|
|
14
17
|
};
|
|
15
|
-
export declare function BodyRow<TData>({ row, onRowClick, rowAutoHeight }: BodyRowProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export declare function BodyRow<TData>({ row, onRowClick, rowAutoHeight, columnOrder, 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");
|
|
@@ -22,11 +23,13 @@ function BodyRow(_ref) {
|
|
|
22
23
|
let {
|
|
23
24
|
row,
|
|
24
25
|
onRowClick,
|
|
25
|
-
rowAutoHeight
|
|
26
|
+
rowAutoHeight,
|
|
27
|
+
columnOrder,
|
|
28
|
+
enableColumnsOrderSortByDrag
|
|
26
29
|
} = _ref;
|
|
27
30
|
const {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
leftPinned,
|
|
32
|
+
rightPinned,
|
|
30
33
|
unpinned
|
|
31
34
|
} = (0, hooks_1.useRowCells)(row);
|
|
32
35
|
const [dropListOpened, setDropListOpen] = (0, react_1.useState)(false);
|
|
@@ -55,20 +58,26 @@ function BodyRow(_ref) {
|
|
|
55
58
|
"data-row-id": row.id,
|
|
56
59
|
className: styles_module_scss_1.default.bodyRow,
|
|
57
60
|
rowAutoHeight: rowAutoHeight,
|
|
58
|
-
children: [
|
|
61
|
+
children: [leftPinned && (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
59
62
|
position: constants_1.COLUMN_PIN_POSITION.Left,
|
|
60
|
-
children:
|
|
63
|
+
children: leftPinned.map(cell => (0, jsx_runtime_1.jsx)(Cells_1.BodyCell, {
|
|
61
64
|
cell: cell,
|
|
62
65
|
rowAutoHeight: rowAutoHeight
|
|
63
66
|
}, cell.id))
|
|
64
|
-
}), unpinned.map(cell => (0, jsx_runtime_1.jsx)(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
}), unpinned.map(cell => (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
68
|
+
items: columnOrder,
|
|
69
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
70
|
+
children: (0, jsx_runtime_1.jsx)(Cells_1.BodyCell, {
|
|
71
|
+
cell: cell,
|
|
72
|
+
rowAutoHeight: rowAutoHeight,
|
|
73
|
+
isDraggable: enableColumnsOrderSortByDrag
|
|
74
|
+
}, cell.id)
|
|
75
|
+
}, cell.id)), rightPinned && (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
68
76
|
position: constants_1.COLUMN_PIN_POSITION.Right,
|
|
69
|
-
children:
|
|
77
|
+
children: rightPinned.map(cell => (0, jsx_runtime_1.jsx)(Cells_1.BodyCell, {
|
|
70
78
|
cell: cell,
|
|
71
|
-
rowAutoHeight: rowAutoHeight
|
|
79
|
+
rowAutoHeight: rowAutoHeight,
|
|
80
|
+
isDraggable: enableColumnsOrderSortByDrag
|
|
72
81
|
}, cell.id))
|
|
73
82
|
})]
|
|
74
83
|
})
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { ColumnOrder } from '../../types';
|
|
1
2
|
import { RowProps } from './Row';
|
|
2
|
-
|
|
3
|
+
type Props = Pick<RowProps, 'rowAutoHeight'> & {
|
|
4
|
+
columnOrder: ColumnOrder;
|
|
5
|
+
enableColumnsOrderSortByDrag?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function HeaderRow({ rowAutoHeight, columnOrder, enableColumnsOrderSortByDrag }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -10,6 +10,7 @@ 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");
|
|
@@ -18,7 +19,9 @@ const Row_1 = require("./Row");
|
|
|
18
19
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
19
20
|
function HeaderRow(_ref) {
|
|
20
21
|
let {
|
|
21
|
-
rowAutoHeight
|
|
22
|
+
rowAutoHeight,
|
|
23
|
+
columnOrder,
|
|
24
|
+
enableColumnsOrderSortByDrag
|
|
22
25
|
} = _ref;
|
|
23
26
|
const {
|
|
24
27
|
leftPinned,
|
|
@@ -35,10 +38,15 @@ function HeaderRow(_ref) {
|
|
|
35
38
|
header: header,
|
|
36
39
|
rowAutoHeight: rowAutoHeight
|
|
37
40
|
}, header.id)))
|
|
38
|
-
}),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
}), (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, {
|
|
42
|
+
items: columnOrder,
|
|
43
|
+
strategy: sortable_1.horizontalListSortingStrategy,
|
|
44
|
+
children: unpinned.map(headerGroup => headerGroup.headers.map(header => (0, jsx_runtime_1.jsx)(Cells_1.HeaderCell, {
|
|
45
|
+
header: header,
|
|
46
|
+
rowAutoHeight: rowAutoHeight,
|
|
47
|
+
isDraggable: enableColumnsOrderSortByDrag && columnOrder.length > 1
|
|
48
|
+
}, header.id)))
|
|
49
|
+
}), rightPinned && (0, jsx_runtime_1.jsx)(PinnedCells_1.PinnedCells, {
|
|
42
50
|
position: constants_1.COLUMN_PIN_POSITION.Right,
|
|
43
51
|
children: rightPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (0, jsx_runtime_1.jsx)(Cells_1.HeaderCell, {
|
|
44
52
|
header: header,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Cell, Header, HeaderGroup, Row } from '@tanstack/react-table';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
2
3
|
export declare function useHeaderGroups(): {
|
|
3
4
|
unpinned: HeaderGroup<any>[];
|
|
4
5
|
leftPinned?: undefined;
|
|
@@ -10,16 +11,15 @@ export declare function useHeaderGroups(): {
|
|
|
10
11
|
};
|
|
11
12
|
export declare function useRowCells<TData>(row: Row<TData>): {
|
|
12
13
|
unpinned: Cell<TData, unknown>[];
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
leftPinned?: undefined;
|
|
15
|
+
rightPinned?: undefined;
|
|
15
16
|
} | {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
leftPinned: Cell<TData, unknown>[] | undefined;
|
|
18
|
+
rightPinned: Cell<TData, unknown>[] | undefined;
|
|
18
19
|
unpinned: Cell<TData, unknown>[];
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
width: string;
|
|
23
|
-
maxWidth: number | undefined;
|
|
24
|
-
flexShrink: string;
|
|
21
|
+
type CellSizesOptions = {
|
|
22
|
+
isDraggable?: boolean;
|
|
25
23
|
};
|
|
24
|
+
export declare function useCellSizes<TData>(element: Cell<TData, unknown> | Header<TData, unknown>, options?: CellSizesOptions): CSSProperties;
|
|
25
|
+
export {};
|
|
@@ -6,6 +6,8 @@ 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) {
|
|
@@ -17,6 +19,9 @@ function useHeaderGroups() {
|
|
|
17
19
|
} = (0, contexts_1.useTableContext)();
|
|
18
20
|
const columnDefs = table._getColumnDefs();
|
|
19
21
|
const pinEnabled = table.getIsSomeColumnsPinned();
|
|
22
|
+
const {
|
|
23
|
+
columnOrder
|
|
24
|
+
} = table.getState();
|
|
20
25
|
return (0, react_1.useMemo)(() => {
|
|
21
26
|
if (!pinEnabled) {
|
|
22
27
|
return {
|
|
@@ -32,7 +37,7 @@ function useHeaderGroups() {
|
|
|
32
37
|
};
|
|
33
38
|
// need to rebuild if columnDefinitions has changed
|
|
34
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
}, [table, pinEnabled, columnDefs]);
|
|
40
|
+
}, [table, pinEnabled, columnDefs, columnOrder]);
|
|
36
41
|
}
|
|
37
42
|
function useRowCells(row) {
|
|
38
43
|
const {
|
|
@@ -40,6 +45,9 @@ function useRowCells(row) {
|
|
|
40
45
|
} = (0, contexts_1.useTableContext)();
|
|
41
46
|
const pinEnabled = table.getIsSomeColumnsPinned();
|
|
42
47
|
const columnDefs = table._getColumnDefs();
|
|
48
|
+
const {
|
|
49
|
+
columnOrder
|
|
50
|
+
} = table.getState();
|
|
43
51
|
return (0, react_1.useMemo)(() => {
|
|
44
52
|
if (!pinEnabled) {
|
|
45
53
|
return {
|
|
@@ -49,24 +57,44 @@ function useRowCells(row) {
|
|
|
49
57
|
const left = row.getLeftVisibleCells();
|
|
50
58
|
const right = row.getRightVisibleCells();
|
|
51
59
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
leftPinned: left.length ? left : undefined,
|
|
61
|
+
rightPinned: right.length ? right : undefined,
|
|
54
62
|
unpinned: row.getCenterVisibleCells()
|
|
55
63
|
};
|
|
56
64
|
// need to rebuild if columnDefinitions has changed
|
|
57
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
}, [row, pinEnabled, columnDefs]);
|
|
66
|
+
}, [row, pinEnabled, columnDefs, columnOrder]);
|
|
59
67
|
}
|
|
60
|
-
function useCellSizes(element) {
|
|
68
|
+
function useCellSizes(element, options) {
|
|
61
69
|
const column = element.column;
|
|
70
|
+
const {
|
|
71
|
+
isDragging,
|
|
72
|
+
transform
|
|
73
|
+
} = (0, sortable_1.useSortable)({
|
|
74
|
+
id: column.id
|
|
75
|
+
});
|
|
62
76
|
const minWidth = column.columnDef.minSize;
|
|
63
77
|
const maxWidth = column.columnDef.maxSize;
|
|
64
78
|
const width = `var(--table-column-${column.id}-size)`;
|
|
65
79
|
const flexShrink = `var(--table-column-${column.id}-flex)`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
const isHeaderCell = 'headerGroup' in element;
|
|
81
|
+
return (0, react_1.useMemo)(() => {
|
|
82
|
+
const styles = {
|
|
83
|
+
minWidth,
|
|
84
|
+
width,
|
|
85
|
+
maxWidth,
|
|
86
|
+
flexShrink
|
|
87
|
+
};
|
|
88
|
+
if (options === null || options === void 0 ? void 0 : options.isDraggable) {
|
|
89
|
+
styles.opacity = isDragging ? 0.8 : 1;
|
|
90
|
+
styles.position = 'relative';
|
|
91
|
+
styles.transform = utilities_1.CSS.Translate.toString(transform);
|
|
92
|
+
styles.transition = 'width transform 0.2s ease-in-out';
|
|
93
|
+
styles.zIndex = isDragging ? 1 : undefined;
|
|
94
|
+
if (isHeaderCell) {
|
|
95
|
+
styles.whiteSpace = 'nowrap';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return styles;
|
|
99
|
+
}, [options === null || options === void 0 ? void 0 : options.isDraggable, flexShrink, isDragging, isHeaderCell, maxWidth, minWidth, transform, width]);
|
|
72
100
|
}
|
|
@@ -30,4 +30,5 @@ __exportStar(require("./helpers"), exports);
|
|
|
30
30
|
__exportStar(require("./hooks"), exports);
|
|
31
31
|
__exportStar(require("./types"), exports);
|
|
32
32
|
__exportStar(require("./TableEmptyState"), exports);
|
|
33
|
-
__exportStar(require("./TablePagination"), exports);
|
|
33
|
+
__exportStar(require("./TablePagination"), exports);
|
|
34
|
+
__exportStar(require("./ColumnsSettings"), exports);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { ToolbarProps } from '@snack-uikit/toolbar';
|
|
4
4
|
import { ValueOf } from '@snack-uikit/utils';
|
|
5
5
|
import { COLUMN_ALIGN, COLUMN_PIN_POSITION } from './constants';
|
|
6
|
-
import { Except } from './helperComponents';
|
|
7
|
-
import { EmptyStateProps } from './helperComponents/TableEmptyState';
|
|
6
|
+
import { EmptyStateProps, Except } from './helperComponents';
|
|
8
7
|
type ColumnAlign = ValueOf<typeof COLUMN_ALIGN>;
|
|
9
8
|
type ColumnPinPosition = ValueOf<typeof COLUMN_PIN_POSITION>;
|
|
10
9
|
type BaseColumnDefinition<TData> = Except<ColumnDef<TData>, 'footer' | 'enablePinning' | 'enableGrouping' | 'enableColumnFilter' | 'filterFn' | 'enableGlobalFilter' | 'enableMultiSort' | 'enableHiding'> & {
|
|
@@ -39,6 +38,15 @@ type PinnedColumnDefinition<TData> = BaseColumnDefinition<TData> & {
|
|
|
39
38
|
/** Размер ячейки */
|
|
40
39
|
size: number;
|
|
41
40
|
};
|
|
42
|
-
|
|
41
|
+
type FilterableProps = {
|
|
42
|
+
id: string;
|
|
43
|
+
/** Название колонки в настройках таблицы */
|
|
44
|
+
headerConfigLabel?: string;
|
|
45
|
+
};
|
|
46
|
+
type FilterableNormalColumnDefinition<TData> = NormalColumnDefinition<TData> & FilterableProps;
|
|
47
|
+
type FilterablePinnedColumnDefinition<TData> = PinnedColumnDefinition<TData> & FilterableProps;
|
|
48
|
+
export type FilterableColumnDefinition<TData> = FilterableNormalColumnDefinition<TData> | FilterablePinnedColumnDefinition<TData>;
|
|
49
|
+
export type ColumnDefinition<TData> = NormalColumnDefinition<TData> | PinnedColumnDefinition<TData> | FilterableColumnDefinition<TData>;
|
|
50
|
+
export type ColumnOrder = string[];
|
|
43
51
|
export type { RowActionsColumnDefProps, StatusColumnDefinitionProps, RowInfo, RowClickHandler, ActionsGenerator, CopyCellProps, MapStatusToAppearanceFnType, } from './helperComponents';
|
|
44
52
|
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, infiniteLoading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, suppressSearch, toolbarAfter, suppressPagination, manualSorting, manualPagination: manualPaginationProp, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, rowAutoHeight, ...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, infiniteLoading, outline, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar, suppressSearch, toolbarAfter, suppressPagination, manualSorting, manualPagination: manualPaginationProp, manualFiltering, autoResetPageIndex, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, rowAutoHeight, columnsSettings: columnsSettingsProp, ...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>;
|