@snack-uikit/table 0.30.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/README.md +2 -0
- package/dist/cjs/components/Table/Table.d.ts +1 -1
- package/dist/cjs/components/Table/Table.js +116 -89
- 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/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 +17 -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 +9 -0
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag.js +66 -0
- 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 +133 -102
- package/src/components/Table/hooks/index.ts +1 -0
- package/src/components/Table/hooks/useColumnOrderByDrag.ts +100 -0
- 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 +11 -0
- package/src/helperComponents/Rows/BodyRow.tsx +36 -9
- package/src/helperComponents/Rows/HeaderRow.tsx +51 -18
- package/src/helperComponents/hooks.ts +78 -15
- package/src/types.ts +6 -0
package/README.md
CHANGED
|
@@ -115,6 +115,7 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
115
115
|
| copyPinnedRows | `boolean` | - | Параметр отвечает за сохранение закрепленных строк в теле таблицы |
|
|
116
116
|
| enableSelectPinned | `boolean` | - | Параметр отвечает за чекбокс выбора закрепленных строк |
|
|
117
117
|
| sorting | `{ initialState?: SortingState; state?: SortingState; onChange?(state: SortingState): void; }` | - | Параметры отвечают за возможность сортировки, их стоит использовать если нужно отслеживать состояние <br> <strong>initialState</strong>: Начальное состояние сортировки <br> <strong>state</strong>: Состояние сортировки, жестко устанавливаемое снаружи <br> <strong>onChange</strong>: Колбэк на изменение сортировки |
|
|
118
|
+
| enableColumnsOrderSortByDrag | `boolean` | - | Включение сортировки порядка столбцов вручную перетаскиванием |
|
|
118
119
|
| expanding | `{ getSubRows: (element: TData) => TData[]; expandingColumnDefinition: TreeColumnDefinitionProps<TData>; }` | - | Параметр отвечает за общие настройки раскрывающихся строк |
|
|
119
120
|
| rowSelection | `{ initialState?: RowSelectionState; state?: RowSelectionState; enable?: boolean \| ((row: Row<TData>) => boolean); multiRow?: boolean; onChange?(state: RowSelectionState): void; }` | - | Параметры отвечают за возможность выбора строк <br> <strong>initialState</strong>: Начальное состояние выбора строк <br> <strong>state</strong>: Состояние выбора строк, жестко устанавливаемое снаружи <br> <strong>enable</strong>: Колбэк определяющий можно ли выбрать строку <br> <strong>multiRow</strong>: Мульти-выбор строк (включен по-умолчанию, когда включается выбор) <br> <strong>onChange</strong>: Колбэк на выбор строк |
|
|
120
121
|
| search | `{ initialState?: string; state?: string; placeholder?: string; loading?: boolean; onChange?(value: string): void; }` | 'Search'<br> <strong>loading</strong>: Состояние загрузки в строке поиска <br> <strong>onChange</strong>: Колбэк на изменение данных в строке поиска | Параметры отвечают за глобальный поиск в таблице <br> <strong>initialState</strong>: Начальное состояние строки поиска <br> <strong>state</strong>: Состояние строки поиска, жестко устанавливаемое снаружи <br> <strong>placeholder</strong>: Placeholder строки поиска |
|
|
@@ -180,6 +181,7 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
180
181
|
| copyPinnedRows | `boolean` | false | Параметр отвечает за сохранение закрепленных строк в теле таблицы |
|
|
181
182
|
| enableSelectPinned | `boolean` | - | Параметр отвечает за чекбокс выбора закрепленных строк |
|
|
182
183
|
| sorting | `{ initialState?: SortingState; state?: SortingState; onChange?(state: SortingState): void; }` | - | Параметры отвечают за возможность сортировки, их стоит использовать если нужно отслеживать состояние <br> <strong>initialState</strong>: Начальное состояние сортировки <br> <strong>state</strong>: Состояние сортировки, жестко устанавливаемое снаружи <br> <strong>onChange</strong>: Колбэк на изменение сортировки |
|
|
184
|
+
| enableColumnsOrderSortByDrag | `boolean` | - | Включение сортировки порядка столбцов вручную перетаскиванием |
|
|
183
185
|
| expanding | `{ getSubRows: (element: TData) => TData[]; expandingColumnDefinition: TreeColumnDefinitionProps<TData>; }` | - | Параметр отвечает за общие настройки раскрывающихся строк |
|
|
184
186
|
| rowSelection | `{ initialState?: RowSelectionState; state?: RowSelectionState; enable?: boolean \| ((row: Row<TData>) => boolean); multiRow?: boolean; onChange?(state: RowSelectionState): void; }` | - | Параметры отвечают за возможность выбора строк <br> <strong>initialState</strong>: Начальное состояние выбора строк <br> <strong>state</strong>: Состояние выбора строк, жестко устанавливаемое снаружи <br> <strong>enable</strong>: Колбэк определяющий можно ли выбрать строку <br> <strong>multiRow</strong>: Мульти-выбор строк (включен по-умолчанию, когда включается выбор) <br> <strong>onChange</strong>: Колбэк на выбор строк |
|
|
185
187
|
| enableFuzzySearch | `boolean` | - | Включить нечеткий поиск |
|
|
@@ -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>;
|
|
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
18
18
|
});
|
|
19
19
|
exports.Table = Table;
|
|
20
20
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
|
+
const core_1 = require("@dnd-kit/core");
|
|
22
|
+
const modifiers_1 = require("@dnd-kit/modifiers");
|
|
21
23
|
const react_table_1 = require("@tanstack/react-table");
|
|
22
24
|
const classnames_1 = __importDefault(require("classnames"));
|
|
23
25
|
const react_1 = require("react");
|
|
@@ -80,9 +82,10 @@ function Table(_a) {
|
|
|
80
82
|
enableFuzzySearch,
|
|
81
83
|
savedState,
|
|
82
84
|
expanding,
|
|
83
|
-
bulkActions: bulkActionsProp
|
|
85
|
+
bulkActions: bulkActionsProp,
|
|
86
|
+
enableColumnsOrderSortByDrag
|
|
84
87
|
} = _a,
|
|
85
|
-
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"]);
|
|
88
|
+
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"]);
|
|
86
89
|
const {
|
|
87
90
|
state: globalFilter,
|
|
88
91
|
onStateChange: onGlobalFilterChange
|
|
@@ -114,6 +117,13 @@ function Table(_a) {
|
|
|
114
117
|
}
|
|
115
118
|
return cols;
|
|
116
119
|
}, [columnDefinitions, enableSelection, enableSelectPinned, expanding]);
|
|
120
|
+
const {
|
|
121
|
+
columnOrder,
|
|
122
|
+
setColumnOrder,
|
|
123
|
+
groupedColumnOrderState,
|
|
124
|
+
sensors,
|
|
125
|
+
handleDragEnd
|
|
126
|
+
} = (0, hooks_1.useColumnOrderByDrag)(tableColumns);
|
|
117
127
|
const columnPinning = (0, react_1.useMemo)(() => {
|
|
118
128
|
var _a;
|
|
119
129
|
const pinningState = {
|
|
@@ -142,6 +152,7 @@ function Table(_a) {
|
|
|
142
152
|
columns: tableColumns,
|
|
143
153
|
state: {
|
|
144
154
|
columnPinning,
|
|
155
|
+
columnOrder,
|
|
145
156
|
globalFilter,
|
|
146
157
|
rowSelection,
|
|
147
158
|
sorting,
|
|
@@ -160,6 +171,7 @@ function Table(_a) {
|
|
|
160
171
|
maxLines: 1
|
|
161
172
|
})
|
|
162
173
|
},
|
|
174
|
+
onColumnOrderChange: setColumnOrder,
|
|
163
175
|
manualSorting,
|
|
164
176
|
manualPagination,
|
|
165
177
|
manualFiltering,
|
|
@@ -335,96 +347,111 @@ function Table(_a) {
|
|
|
335
347
|
updateCellMap
|
|
336
348
|
} = (0, contexts_1.useCellAutoResizeController)(table);
|
|
337
349
|
const showToolbar = !suppressToolbar;
|
|
338
|
-
return (0, jsx_runtime_1.jsx)(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
350
|
+
return (0, jsx_runtime_1.jsx)(core_1.DndContext, {
|
|
351
|
+
collisionDetection: core_1.closestCenter,
|
|
352
|
+
modifiers: [modifiers_1.restrictToHorizontalAxis],
|
|
353
|
+
onDragEnd: handleDragEnd,
|
|
354
|
+
sensors: sensors,
|
|
355
|
+
children: (0, jsx_runtime_1.jsx)(contexts_1.CellAutoResizeContext.Provider, {
|
|
356
|
+
value: {
|
|
357
|
+
updateCellMap
|
|
345
358
|
},
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
className: styles_module_scss_1.default.
|
|
384
|
-
|
|
385
|
-
children:
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
children:
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
359
|
+
children: (0, jsx_runtime_1.jsxs)("div", Object.assign({
|
|
360
|
+
style: {
|
|
361
|
+
'--page-size': cssPageSize
|
|
362
|
+
},
|
|
363
|
+
className: (0, classnames_1.default)(styles_module_scss_1.default.wrapper, className)
|
|
364
|
+
}, (0, utils_1.extractSupportProps)(rest), {
|
|
365
|
+
children: [showToolbar && (0, jsx_runtime_1.jsx)("div", {
|
|
366
|
+
className: styles_module_scss_1.default.header,
|
|
367
|
+
children: (0, jsx_runtime_1.jsx)(toolbar_1.Toolbar, {
|
|
368
|
+
search: suppressSearch ? undefined : {
|
|
369
|
+
value: globalFilter,
|
|
370
|
+
onChange: onGlobalFilterChange,
|
|
371
|
+
loading: search === null || search === void 0 ? void 0 : search.loading,
|
|
372
|
+
placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || t('searchPlaceholder')
|
|
373
|
+
},
|
|
374
|
+
className: styles_module_scss_1.default.toolbar,
|
|
375
|
+
onRefresh: onRefresh ? handleOnRefresh : undefined,
|
|
376
|
+
bulkActions: bulkActions,
|
|
377
|
+
selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single',
|
|
378
|
+
checked: table.getIsAllPageRowsSelected(),
|
|
379
|
+
indeterminate: table.getIsSomePageRowsSelected(),
|
|
380
|
+
onCheck: enableSelection ? handleOnToolbarCheck : undefined,
|
|
381
|
+
outline: outline,
|
|
382
|
+
after: toolbarAfter || exportSettings ? (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
383
|
+
children: [toolbarAfter, exportSettings && (0, jsx_runtime_1.jsx)(helperComponents_1.ExportButton, {
|
|
384
|
+
settings: exportSettings,
|
|
385
|
+
columnDefinitions: columnDefinitions,
|
|
386
|
+
data: data,
|
|
387
|
+
topRows: filteredTopRows,
|
|
388
|
+
centerRows: centerRows
|
|
389
|
+
})]
|
|
390
|
+
}) : undefined,
|
|
391
|
+
moreActions: moreActions,
|
|
392
|
+
filterRow: columnFilters,
|
|
393
|
+
"data-test-id": constants_1.TEST_IDS.toolbar
|
|
394
|
+
})
|
|
395
|
+
}), (0, jsx_runtime_1.jsx)("div", {
|
|
396
|
+
className: styles_module_scss_1.default.scrollWrapper,
|
|
397
|
+
"data-outline": outline || undefined,
|
|
398
|
+
children: (0, jsx_runtime_1.jsxs)(scroll_1.Scroll, {
|
|
399
|
+
size: 's',
|
|
400
|
+
className: styles_module_scss_1.default.table,
|
|
401
|
+
ref: scrollContainerRef,
|
|
402
|
+
children: [(0, jsx_runtime_1.jsx)("div", {
|
|
403
|
+
className: styles_module_scss_1.default.tableContent,
|
|
404
|
+
style: columnSizes.vars,
|
|
405
|
+
children: (0, jsx_runtime_1.jsx)(helperComponents_1.TableContext.Provider, {
|
|
406
|
+
value: {
|
|
407
|
+
table
|
|
408
|
+
},
|
|
409
|
+
children: loading ? (0, jsx_runtime_1.jsxs)(skeleton_1.SkeletonContextProvider, {
|
|
410
|
+
loading: true,
|
|
411
|
+
children: [(0, jsx_runtime_1.jsx)(helperComponents_1.HeaderRow, {
|
|
412
|
+
groupedColumnOrderState: groupedColumnOrderState
|
|
413
|
+
}), loadingTableRows.map(row => (0, jsx_runtime_1.jsx)(helperComponents_1.BodyRow, {
|
|
401
414
|
row: row,
|
|
402
|
-
|
|
403
|
-
}, row.id))
|
|
404
|
-
}) :
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
415
|
+
groupedColumnOrderState: groupedColumnOrderState
|
|
416
|
+
}, row.id))]
|
|
417
|
+
}) : (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
418
|
+
children: [centerRows.length || filteredTopRows.length ? (0, jsx_runtime_1.jsx)(helperComponents_1.HeaderRow, {
|
|
419
|
+
groupedColumnOrderState: groupedColumnOrderState,
|
|
420
|
+
enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag
|
|
421
|
+
}) : null, filteredTopRows.length ? (0, jsx_runtime_1.jsx)("div", {
|
|
422
|
+
className: styles_module_scss_1.default.topRowWrapper,
|
|
423
|
+
children: filteredTopRows.map(row => (0, jsx_runtime_1.jsx)(helperComponents_1.BodyRow, {
|
|
424
|
+
row: row,
|
|
425
|
+
onRowClick: onRowClick,
|
|
426
|
+
groupedColumnOrderState: groupedColumnOrderState
|
|
427
|
+
}, row.id))
|
|
428
|
+
}) : null, centerRows.map(row => (0, jsx_runtime_1.jsx)(helperComponents_1.BodyRow, {
|
|
429
|
+
row: row,
|
|
430
|
+
onRowClick: onRowClick,
|
|
431
|
+
groupedColumnOrderState: groupedColumnOrderState,
|
|
432
|
+
enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag
|
|
433
|
+
}, row.id)), (0, jsx_runtime_1.jsx)(helperComponents_1.TableEmptyState, {
|
|
434
|
+
emptyStates: emptyStates,
|
|
435
|
+
dataError: dataError,
|
|
436
|
+
dataFiltered: dataFiltered || Boolean(table.getState().globalFilter),
|
|
437
|
+
tableRowsLength: tableRows.length + filteredTopRows.length
|
|
438
|
+
})]
|
|
439
|
+
})
|
|
413
440
|
})
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
})
|
|
419
|
-
})
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
})
|
|
427
|
-
})
|
|
441
|
+
}), (0, jsx_runtime_1.jsx)("div", {
|
|
442
|
+
className: styles_module_scss_1.default.scrollStub,
|
|
443
|
+
ref: scrollRef
|
|
444
|
+
})]
|
|
445
|
+
})
|
|
446
|
+
}), !suppressPagination && (0, jsx_runtime_1.jsx)(helperComponents_1.TablePagination, {
|
|
447
|
+
table: table,
|
|
448
|
+
options: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.options,
|
|
449
|
+
optionsLabel: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsLabel,
|
|
450
|
+
pageCount: pageCount,
|
|
451
|
+
optionsRender: paginationProp === null || paginationProp === void 0 ? void 0 : paginationProp.optionsRender
|
|
452
|
+
})]
|
|
453
|
+
}))
|
|
454
|
+
})
|
|
428
455
|
});
|
|
429
456
|
}
|
|
430
457
|
Table.getStatusColumnDef = helperComponents_1.getStatusColumnDef;
|
|
@@ -23,4 +23,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
23
23
|
value: true
|
|
24
24
|
});
|
|
25
25
|
__exportStar(require("./useLoadingTable"), exports);
|
|
26
|
-
__exportStar(require("./useStateControl"), exports);
|
|
26
|
+
__exportStar(require("./useStateControl"), exports);
|
|
27
|
+
__exportStar(require("./useColumnOrderByDrag"), exports);
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useColumnOrderByDrag = useColumnOrderByDrag;
|
|
7
|
+
const core_1 = require("@dnd-kit/core");
|
|
8
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const constants_1 = require("../../../constants");
|
|
11
|
+
function preparePinnedColumnsMap(tableColumns) {
|
|
12
|
+
return tableColumns.reduce((accMap, columnDefinition) => {
|
|
13
|
+
switch (columnDefinition.pinned) {
|
|
14
|
+
case 'left':
|
|
15
|
+
accMap[columnDefinition.id] = 'leftPinned';
|
|
16
|
+
break;
|
|
17
|
+
case 'right':
|
|
18
|
+
accMap[columnDefinition.id] = 'rightPinned';
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
}
|
|
22
|
+
return accMap;
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
function prepareInitialState(tableColumns) {
|
|
26
|
+
return tableColumns.map(c => c.id).filter(id => !constants_1.UNDRAGGABLE_COLUMNS.includes(id));
|
|
27
|
+
}
|
|
28
|
+
function prepareGroupedColumnOrderState(columnOrder, pinnedColumnsMap) {
|
|
29
|
+
return columnOrder.reduce((accState, columnId) => {
|
|
30
|
+
var _a;
|
|
31
|
+
if (constants_1.UNDRAGGABLE_COLUMNS.includes(columnId)) {
|
|
32
|
+
return accState;
|
|
33
|
+
}
|
|
34
|
+
const groupName = (_a = pinnedColumnsMap[columnId]) !== null && _a !== void 0 ? _a : 'unpinned';
|
|
35
|
+
accState[groupName].push(columnId);
|
|
36
|
+
return accState;
|
|
37
|
+
}, {
|
|
38
|
+
leftPinned: [],
|
|
39
|
+
unpinned: [],
|
|
40
|
+
rightPinned: []
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function useColumnOrderByDrag(tableColumns) {
|
|
44
|
+
const [columnOrder, setColumnOrder] = (0, react_1.useState)(() => prepareInitialState(tableColumns));
|
|
45
|
+
const pinnedColumnsMap = (0, react_1.useMemo)(() => preparePinnedColumnsMap(tableColumns), [tableColumns]);
|
|
46
|
+
const groupedColumnOrderState = (0, react_1.useMemo)(() => prepareGroupedColumnOrderState(columnOrder, pinnedColumnsMap), [columnOrder, pinnedColumnsMap]);
|
|
47
|
+
const handleDragEnd = (0, react_1.useCallback)(_ref => {
|
|
48
|
+
let {
|
|
49
|
+
active,
|
|
50
|
+
over
|
|
51
|
+
} = _ref;
|
|
52
|
+
if (active && over && active.id !== over.id) {
|
|
53
|
+
if (constants_1.UNDRAGGABLE_COLUMNS.includes(over.id.toString())) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const activeGroup = pinnedColumnsMap[active.id.toString()];
|
|
57
|
+
const overGroup = pinnedColumnsMap[over.id.toString()];
|
|
58
|
+
if (activeGroup !== overGroup) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setColumnOrder(columnOrder => {
|
|
62
|
+
const oldIndex = columnOrder.indexOf(active.id.toString());
|
|
63
|
+
const newIndex = columnOrder.indexOf(over.id.toString());
|
|
64
|
+
return (0, sortable_1.arrayMove)(columnOrder, oldIndex, newIndex);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}, [pinnedColumnsMap]);
|
|
68
|
+
const sensors = (0, core_1.useSensors)((0, core_1.useSensor)(core_1.MouseSensor, {}), (0, core_1.useSensor)(core_1.TouchSensor, {}), (0, core_1.useSensor)(core_1.KeyboardSensor, {}));
|
|
69
|
+
return {
|
|
70
|
+
columnOrder,
|
|
71
|
+
setColumnOrder,
|
|
72
|
+
groupedColumnOrderState,
|
|
73
|
+
handleDragEnd,
|
|
74
|
+
sensors
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -30,6 +30,8 @@ export type TableProps<TData extends object, TFilters extends FiltersState = Rec
|
|
|
30
30
|
state?: SortingState;
|
|
31
31
|
onChange?(state: SortingState): void;
|
|
32
32
|
};
|
|
33
|
+
/** Включение сортировки порядка столбцов вручную перетаскиванием */
|
|
34
|
+
enableColumnsOrderSortByDrag?: boolean;
|
|
33
35
|
/** Параметр отвечает за общие настройки раскрывающихся строк*/
|
|
34
36
|
expanding?: {
|
|
35
37
|
/** Метод отвечает за получение дочерних строк*/
|
package/dist/cjs/constants.d.ts
CHANGED
package/dist/cjs/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DEFAULT_PAGE_SIZE = exports.SORT_FN = exports.TEST_IDS = exports.COLUMN_ALIGN = exports.COLUMN_PIN_POSITION = void 0;
|
|
6
|
+
exports.UNDRAGGABLE_COLUMNS = exports.DEFAULT_PAGE_SIZE = exports.SORT_FN = exports.TEST_IDS = exports.COLUMN_ALIGN = exports.COLUMN_PIN_POSITION = void 0;
|
|
7
7
|
exports.COLUMN_PIN_POSITION = {
|
|
8
8
|
Left: 'left',
|
|
9
9
|
Right: 'right'
|
|
@@ -40,4 +40,5 @@ exports.SORT_FN = {
|
|
|
40
40
|
DateTime: 'datetime',
|
|
41
41
|
AlphaNumeric: 'alphanumeric'
|
|
42
42
|
};
|
|
43
|
-
exports.DEFAULT_PAGE_SIZE = 10;
|
|
43
|
+
exports.DEFAULT_PAGE_SIZE = 10;
|
|
44
|
+
exports.UNDRAGGABLE_COLUMNS = ['snack_predefined_statusColumn', 'selectionCell', 'rowActions'];
|
|
@@ -2,6 +2,7 @@ import { Cell as TableCell } from '@tanstack/react-table';
|
|
|
2
2
|
import { CellProps } from '../Cell';
|
|
3
3
|
type BodyCellProps<TData> = Omit<CellProps, 'style' | 'children'> & {
|
|
4
4
|
cell: TableCell<TData, unknown>;
|
|
5
|
+
isDraggable?: boolean;
|
|
5
6
|
};
|
|
6
|
-
export declare function BodyCell<TData>({ cell, className, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function BodyCell<TData>({ cell, className, isDraggable, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
18
18
|
});
|
|
19
19
|
exports.BodyCell = BodyCell;
|
|
20
20
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
|
+
const sortable_1 = require("@dnd-kit/sortable");
|
|
21
22
|
const react_table_1 = require("@tanstack/react-table");
|
|
22
23
|
const classnames_1 = __importDefault(require("classnames"));
|
|
23
24
|
const constants_1 = require("../../../constants");
|
|
@@ -27,12 +28,21 @@ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
|
27
28
|
function BodyCell(_a) {
|
|
28
29
|
var {
|
|
29
30
|
cell,
|
|
30
|
-
className
|
|
31
|
+
className,
|
|
32
|
+
isDraggable
|
|
31
33
|
} = _a,
|
|
32
|
-
props = __rest(_a, ["cell", "className"]);
|
|
34
|
+
props = __rest(_a, ["cell", "className", "isDraggable"]);
|
|
33
35
|
const columnDef = cell.column.columnDef;
|
|
34
|
-
const style = (0, hooks_1.useCellSizes)(cell
|
|
36
|
+
const style = (0, hooks_1.useCellSizes)(cell, {
|
|
37
|
+
isDraggable
|
|
38
|
+
});
|
|
39
|
+
const {
|
|
40
|
+
setNodeRef
|
|
41
|
+
} = (0, sortable_1.useSortable)({
|
|
42
|
+
id: cell.column.id
|
|
43
|
+
});
|
|
35
44
|
return (0, jsx_runtime_1.jsx)(Cell_1.Cell, Object.assign({}, props, {
|
|
45
|
+
ref: setNodeRef,
|
|
36
46
|
style: style,
|
|
37
47
|
className: (0, classnames_1.default)(styles_module_scss_1.default.tableBodyCell, className, columnDef.cellClassName),
|
|
38
48
|
"data-align": columnDef.align,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
export type DragHandleProps = Pick<ReturnType<typeof useSortable>, 'attributes' | 'listeners'> & {
|
|
4
|
+
style?: CSSProperties;
|
|
5
|
+
};
|
|
6
|
+
export declare function DragHandle({ attributes, listeners }: DragHandleProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
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.DragHandle = DragHandle;
|
|
12
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const icons_1 = require("@snack-uikit/icons");
|
|
14
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
15
|
+
function DragHandle(_ref) {
|
|
16
|
+
let {
|
|
17
|
+
attributes,
|
|
18
|
+
listeners
|
|
19
|
+
} = _ref;
|
|
20
|
+
return (0, jsx_runtime_1.jsx)("div", Object.assign({
|
|
21
|
+
className: styles_module_scss_1.default.dragHandle
|
|
22
|
+
}, attributes, listeners, {
|
|
23
|
+
children: (0, jsx_runtime_1.jsx)(icons_1.KebabSVG, {
|
|
24
|
+
className: styles_module_scss_1.default.dragIcon
|
|
25
|
+
})
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
@@ -4,6 +4,7 @@ import { CellProps } from '../Cell';
|
|
|
4
4
|
type HeaderCellProps<TData> = Omit<CellProps, 'align' | 'children' | 'onClick' | 'style'> & {
|
|
5
5
|
header: Header<TData, unknown>;
|
|
6
6
|
pinPosition?: ColumnPinPosition;
|
|
7
|
+
isDraggable?: boolean;
|
|
7
8
|
};
|
|
8
|
-
export declare function HeaderCell<TData>({ header, pinPosition, className }: HeaderCellProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function HeaderCell<TData>({ header, pinPosition, isDraggable, className }: HeaderCellProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -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;
|