@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +5 -3
  3. package/dist/cjs/components/Table/Table.d.ts +1 -1
  4. package/dist/cjs/components/Table/Table.js +107 -48
  5. package/dist/cjs/components/Table/hooks/index.d.ts +1 -0
  6. package/dist/cjs/components/Table/hooks/index.js +2 -1
  7. package/dist/cjs/components/Table/hooks/useColumnOrderByDrag.d.ts +8 -0
  8. package/dist/cjs/components/Table/hooks/useColumnOrderByDrag.js +49 -0
  9. package/dist/cjs/components/Table/utils.d.ts +13 -0
  10. package/dist/cjs/components/Table/utils.js +71 -0
  11. package/dist/cjs/components/types.d.ts +12 -3
  12. package/dist/cjs/constants.d.ts +1 -0
  13. package/dist/cjs/constants.js +3 -2
  14. package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.d.ts +2 -1
  15. package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.js +13 -3
  16. package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.d.ts +2 -1
  17. package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.js +41 -17
  18. package/dist/cjs/helperComponents/Cells/HeaderCell/styles.module.css +10 -0
  19. package/dist/cjs/helperComponents/ColumnsSettings/ColumnsSettings.d.ts +8 -0
  20. package/dist/cjs/helperComponents/ColumnsSettings/ColumnsSettings.js +38 -0
  21. package/dist/cjs/helperComponents/ColumnsSettings/index.d.ts +1 -0
  22. package/dist/cjs/helperComponents/ColumnsSettings/index.js +25 -0
  23. package/dist/cjs/helperComponents/ColumnsSettings/styles.module.css +3 -0
  24. package/dist/cjs/helperComponents/Rows/BodyRow.d.ts +4 -1
  25. package/dist/cjs/helperComponents/Rows/BodyRow.js +20 -11
  26. package/dist/cjs/helperComponents/Rows/HeaderRow.d.ts +7 -1
  27. package/dist/cjs/helperComponents/Rows/HeaderRow.js +13 -5
  28. package/dist/cjs/helperComponents/hooks.d.ts +9 -9
  29. package/dist/cjs/helperComponents/hooks.js +39 -11
  30. package/dist/cjs/helperComponents/index.d.ts +1 -0
  31. package/dist/cjs/helperComponents/index.js +2 -1
  32. package/dist/cjs/types.d.ts +11 -3
  33. package/dist/esm/components/Table/Table.d.ts +1 -1
  34. package/dist/esm/components/Table/Table.js +40 -12
  35. package/dist/esm/components/Table/hooks/index.d.ts +1 -0
  36. package/dist/esm/components/Table/hooks/index.js +1 -0
  37. package/dist/esm/components/Table/hooks/useColumnOrderByDrag.d.ts +8 -0
  38. package/dist/esm/components/Table/hooks/useColumnOrderByDrag.js +39 -0
  39. package/dist/esm/components/Table/utils.d.ts +13 -0
  40. package/dist/esm/components/Table/utils.js +70 -0
  41. package/dist/esm/components/types.d.ts +12 -3
  42. package/dist/esm/constants.d.ts +1 -0
  43. package/dist/esm/constants.js +1 -0
  44. package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.d.ts +2 -1
  45. package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.js +7 -3
  46. package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.d.ts +2 -1
  47. package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.js +14 -4
  48. package/dist/esm/helperComponents/Cells/HeaderCell/styles.module.css +10 -0
  49. package/dist/esm/helperComponents/ColumnsSettings/ColumnsSettings.d.ts +8 -0
  50. package/dist/esm/helperComponents/ColumnsSettings/ColumnsSettings.js +12 -0
  51. package/dist/esm/helperComponents/ColumnsSettings/index.d.ts +1 -0
  52. package/dist/esm/helperComponents/ColumnsSettings/index.js +1 -0
  53. package/dist/esm/helperComponents/ColumnsSettings/styles.module.css +3 -0
  54. package/dist/esm/helperComponents/Rows/BodyRow.d.ts +4 -1
  55. package/dist/esm/helperComponents/Rows/BodyRow.js +4 -3
  56. package/dist/esm/helperComponents/Rows/HeaderRow.d.ts +7 -1
  57. package/dist/esm/helperComponents/Rows/HeaderRow.js +3 -2
  58. package/dist/esm/helperComponents/hooks.d.ts +9 -9
  59. package/dist/esm/helperComponents/hooks.js +32 -11
  60. package/dist/esm/helperComponents/index.d.ts +1 -0
  61. package/dist/esm/helperComponents/index.js +1 -0
  62. package/dist/esm/types.d.ts +11 -3
  63. package/package.json +9 -5
  64. package/src/components/Table/Table.tsx +147 -61
  65. package/src/components/Table/hooks/index.ts +1 -0
  66. package/src/components/Table/hooks/useColumnOrderByDrag.ts +67 -0
  67. package/src/components/Table/utils.ts +118 -0
  68. package/src/components/types.ts +13 -3
  69. package/src/constants.tsx +1 -0
  70. package/src/helperComponents/Cells/BodyCell/BodyCell.tsx +9 -2
  71. package/src/helperComponents/Cells/HeaderCell/HeaderCell.tsx +50 -23
  72. package/src/helperComponents/Cells/HeaderCell/styles.module.scss +15 -0
  73. package/src/helperComponents/ColumnsSettings/ColumnsSettings.tsx +28 -0
  74. package/src/helperComponents/ColumnsSettings/index.ts +1 -0
  75. package/src/helperComponents/ColumnsSettings/styles.module.scss +5 -0
  76. package/src/helperComponents/Rows/BodyRow.tsx +30 -8
  77. package/src/helperComponents/Rows/HeaderRow.tsx +21 -4
  78. package/src/helperComponents/hooks.ts +41 -11
  79. package/src/helperComponents/index.ts +1 -0
  80. package/src/types.ts +21 -3
@@ -10,9 +10,11 @@ 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
- import { useCallback, useEffect, useMemo, useRef } from 'react';
17
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
16
18
  import { useLocale } from '@snack-uikit/locale';
17
19
  import { Scroll } from '@snack-uikit/scroll';
18
20
  import { SkeletonContextProvider } from '@snack-uikit/skeleton';
@@ -21,19 +23,19 @@ import { TruncateString } from '@snack-uikit/truncate-string';
21
23
  import { extractSupportProps, useLayoutEffect } from '@snack-uikit/utils';
22
24
  import { DEFAULT_FILTER_VISIBILITY, DEFAULT_PAGE_SIZE, DEFAULT_ROW_SELECTION, DEFAULT_SORTING, TEST_IDS, } from '../../constants';
23
25
  import { CellAutoResizeContext, useCellAutoResizeController } from '../../contexts';
24
- import { BodyRow, ExportButton, getColumnId, getRowActionsColumnDef, getSelectionCellColumnDef, getStatusColumnDef, HeaderRow, STATUS_APPEARANCE, TableContext, TableEmptyState, TablePagination, useEmptyState, } from '../../helperComponents';
26
+ import { BodyRow, ColumnsSettings, 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 { customDateParser, 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 { useSaveTableSettings } from './hooks/useSaveTableSettings';
30
32
  import styles from './styles.module.css';
31
- import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth, getInitColumnSizeFromLocalStorage, saveStateToLocalStorage, } from './utils';
33
+ import { getColumnStyleVars, getCurrentlyConfiguredHeaderWidth, getInitColumnSizeFromLocalStorage, isFilterableColumn, prepareColumnsSettings, prepareColumnsSettingsMap, saveStateToLocalStorage, } from './utils';
32
34
  /** Компонент таблицы */
33
35
  export function Table(_a) {
34
36
  var { data, rowPinning = {
35
37
  top: [],
36
- }, 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, infiniteLoading = false, outline = false, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar = false, suppressSearch = false, toolbarAfter, suppressPagination = false, manualSorting = false, manualPagination: manualPaginationProp = false, manualFiltering = false, autoResetPageIndex = false, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, rowAutoHeight } = _a, rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "pageSize", "pageCount", "loading", "infiniteLoading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "suppressSearch", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState", "expanding", "bulkActions", "rowAutoHeight"]);
38
+ }, 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, infiniteLoading = false, outline = false, moreActions, exportSettings, dataFiltered, dataError, noDataState, noResultsState, errorDataState, suppressToolbar = false, suppressSearch = false, toolbarAfter, suppressPagination = false, manualSorting = false, manualPagination: manualPaginationProp = false, manualFiltering = false, autoResetPageIndex = false, scrollRef, scrollContainerRef, getRowId, enableFuzzySearch, savedState, expanding, bulkActions: bulkActionsProp, rowAutoHeight, columnsSettings: columnsSettingsProp } = _a, rest = __rest(_a, ["data", "rowPinning", "columnDefinitions", "keepPinnedRows", "copyPinnedRows", "enableSelectPinned", "rowSelection", "search", "sorting", "columnFilters", "pagination", "className", "onRowClick", "onRefresh", "pageSize", "pageCount", "loading", "infiniteLoading", "outline", "moreActions", "exportSettings", "dataFiltered", "dataError", "noDataState", "noResultsState", "errorDataState", "suppressToolbar", "suppressSearch", "toolbarAfter", "suppressPagination", "manualSorting", "manualPagination", "manualFiltering", "autoResetPageIndex", "scrollRef", "scrollContainerRef", "getRowId", "enableFuzzySearch", "savedState", "expanding", "bulkActions", "rowAutoHeight", "columnsSettings"]);
37
39
  const { setDataToStorages, defaultFilter } = useSaveTableSettings({
38
40
  options: savedState,
39
41
  filterSettings: columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.filters,
@@ -56,6 +58,7 @@ export function Table(_a) {
56
58
  initialState: [],
57
59
  onChange: columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.onVisibleFiltersChange,
58
60
  }, DEFAULT_FILTER_VISIBILITY);
61
+ const [areColumnFiltersOpen, setAreColumnFiltersOpen] = useState(true);
59
62
  useEffect(() => {
60
63
  setDataToStorages({ pagination, sorting, filter, search: globalFilter || '' });
61
64
  }, [pagination, sorting, filter, setDataToStorages, globalFilter]);
@@ -70,12 +73,23 @@ export function Table(_a) {
70
73
  // Только для первого рендера, чтобы проинициализировать фильтр
71
74
  // eslint-disable-next-line
72
75
  }, [defaultFilter]);
73
- const patchedFilter = useMemo(() => columnFilters
74
- ? Object.assign(Object.assign({}, columnFilters), { value: filter, onChange: setFilter, visibleFilters: filterVisibility, onVisibleFiltersChange: setFilterVisibility }) : undefined, [columnFilters, filter, setFilter, filterVisibility, setFilterVisibility]);
76
+ const patchedFilter = useMemo(() => {
77
+ if (!columnFilters) {
78
+ return undefined;
79
+ }
80
+ return Object.assign(Object.assign({}, columnFilters), { open: areColumnFiltersOpen, onOpenChange: setAreColumnFiltersOpen, value: filter, onChange: setFilter, visibleFilters: filterVisibility, onVisibleFiltersChange: setFilterVisibility });
81
+ }, [columnFilters, areColumnFiltersOpen, filter, setFilter, filterVisibility, setFilterVisibility]);
75
82
  const enableSelection = Boolean(rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.enable);
76
83
  const manualPagination = infiniteLoading || manualPaginationProp;
84
+ const [enabledColumns, setEnabledColumns] = useState(() => prepareColumnsSettingsMap(columnDefinitions));
85
+ const filteredColumnDefinitions = useMemo(() => columnDefinitions.filter(colDef => {
86
+ if (isFilterableColumn(colDef)) {
87
+ return enabledColumns.includes(colDef.id);
88
+ }
89
+ return true;
90
+ }), [columnDefinitions, enabledColumns]);
77
91
  const tableColumns = useMemo(() => {
78
- let cols = columnDefinitions;
92
+ let cols = filteredColumnDefinitions;
79
93
  if (enableSelection && !expanding) {
80
94
  cols = [getSelectionCellColumnDef(enableSelectPinned), ...cols];
81
95
  }
@@ -83,7 +97,18 @@ export function Table(_a) {
83
97
  cols = [getTreeColumnDef(expanding.expandingColumnDefinition), ...cols];
84
98
  }
85
99
  return cols;
86
- }, [columnDefinitions, enableSelection, enableSelectPinned, expanding]);
100
+ }, [filteredColumnDefinitions, enableSelection, enableSelectPinned, expanding]);
101
+ const { columnOrder, setColumnOrder, sensors, handleDragEnd } = useColumnOrderByDrag(tableColumns);
102
+ const filterableColumns = useMemo(() => columnDefinitions.filter(isFilterableColumn), [columnDefinitions]);
103
+ const areAllColumnsEnabled = filterableColumns.length === enabledColumns.length;
104
+ const { t } = useLocale('Table');
105
+ const columnsSettings = useMemo(() => prepareColumnsSettings({
106
+ columnDefinitions,
107
+ columnOrder,
108
+ areAllColumnsEnabled,
109
+ columnsSettingsHeader: columnsSettingsProp === null || columnsSettingsProp === void 0 ? void 0 : columnsSettingsProp.headerLabel,
110
+ t,
111
+ }), [areAllColumnsEnabled, columnDefinitions, columnOrder, columnsSettingsProp === null || columnsSettingsProp === void 0 ? void 0 : columnsSettingsProp.headerLabel, t]);
87
112
  const columnPinning = useMemo(() => {
88
113
  var _a;
89
114
  const pinningState = { left: [], right: [] };
@@ -110,6 +135,7 @@ export function Table(_a) {
110
135
  columns: tableColumns,
111
136
  state: {
112
137
  columnPinning,
138
+ columnOrder,
113
139
  globalFilter,
114
140
  rowSelection,
115
141
  sorting,
@@ -128,6 +154,7 @@ export function Table(_a) {
128
154
  return _jsx(TruncateString, { text: String(cell.getValue()), maxLines: 1 });
129
155
  },
130
156
  },
157
+ onColumnOrderChange: setColumnOrder,
131
158
  manualSorting,
132
159
  manualPagination,
133
160
  manualFiltering,
@@ -163,7 +190,7 @@ export function Table(_a) {
163
190
  }, [expanding, table]);
164
191
  const { loadingTable } = useLoadingTable({
165
192
  pageSize: Math.min(Math.max(pageSize, 5), DEFAULT_PAGE_SIZE),
166
- columnDefinitions: tableColumns,
193
+ columnDefinitions: filteredColumnDefinitions,
167
194
  columnPinning,
168
195
  });
169
196
  const handleOnRefresh = useCallback(() => {
@@ -261,7 +288,6 @@ export function Table(_a) {
261
288
  ? topRows.filter(tr => tableFilteredRowsIds.includes(tr.id))
262
289
  : topRows;
263
290
  const centerRows = copyPinnedRows ? tableRows : tableCenterRows;
264
- const { t } = useLocale('Table');
265
291
  const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
266
292
  usePageReset({
267
293
  manualPagination,
@@ -272,6 +298,8 @@ export function Table(_a) {
272
298
  });
273
299
  const { updateCellMap } = useCellAutoResizeController(table);
274
300
  const showToolbar = !suppressToolbar;
301
+ const showColumnsSettings = Boolean(columnsSettingsProp === null || columnsSettingsProp === void 0 ? void 0 : columnsSettingsProp.headerLabel);
302
+ const enableColumnsOrderSortByDrag = Boolean(columnsSettingsProp === null || columnsSettingsProp === void 0 ? void 0 : columnsSettingsProp.enableDrag);
275
303
  return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className) }, extractSupportProps(rest), { children: [showToolbar && (_jsx("div", { className: styles.header, children: _jsx(Toolbar, { search: suppressSearch
276
304
  ? undefined
277
305
  : {
@@ -279,7 +307,7 @@ export function Table(_a) {
279
307
  onChange: onGlobalFilterChange,
280
308
  loading: search === null || search === void 0 ? void 0 : search.loading,
281
309
  placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || t('searchPlaceholder'),
282
- }, 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: patchedFilter, "data-test-id": TEST_IDS.toolbar }) })), _jsxs(Scroll, { size: 's', className: styles.table, ref: scrollContainerRef, "data-outline": outline || undefined, children: [_jsx("div", { className: styles.tableContent, style: columnSizes.vars, children: _jsx(CellAutoResizeContext.Provider, { value: { updateCellMap }, children: _jsx(TableContext.Provider, { value: { table }, children: (!infiniteLoading || !data.length) && loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight }), loadingTableRows.map(row => (_jsx(BodyRow, { row: row, rowAutoHeight: rowAutoHeight }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? _jsx(HeaderRow, {}) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight }, row.id))) })) : null, centerRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight }, row.id))), data.length > 0 && infiniteLoading && loading && !dataError && (_jsx(SkeletonContextProvider, { loading: true, children: loadingTableRows.slice(0, 3).map(row => (_jsx(BodyRow, { row: row }, 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 })] }), !infiniteLoading && !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 }))] })));
310
+ }, 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 || showColumnsSettings ? (_jsxs(_Fragment, { children: [toolbarAfter, exportSettings && (_jsx(ExportButton, { settings: exportSettings, columnDefinitions: columnDefinitions, data: data, topRows: filteredTopRows, centerRows: centerRows })), showColumnsSettings && (_jsx(ColumnsSettings, { columnsSettings: columnsSettings, enabledColumns: enabledColumns, setEnabledColumns: setEnabledColumns }))] })) : undefined, moreActions: moreActions, filterRow: patchedFilter, "data-test-id": TEST_IDS.toolbar }) })), _jsxs(Scroll, { size: 's', className: styles.table, ref: scrollContainerRef, "data-outline": outline || undefined, children: [_jsx("div", { className: styles.tableContent, style: columnSizes.vars, children: _jsx(CellAutoResizeContext.Provider, { value: { updateCellMap }, children: _jsx(DndContext, { collisionDetection: closestCenter, modifiers: [restrictToHorizontalAxis], onDragEnd: handleDragEnd, sensors: sensors, children: _jsx(TableContext.Provider, { value: { table }, children: (!infiniteLoading || !data.length) && loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight, columnOrder: columnOrder }), loadingTableRows.map(row => (_jsx(BodyRow, { row: row, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder }, row.id)))] })) : (_jsxs(_Fragment, { children: [centerRows.length || filteredTopRows.length ? (_jsx(HeaderRow, { rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag })) : null, filteredTopRows.length ? (_jsx("div", { className: styles.topRowWrapper, children: filteredTopRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag }, row.id))) })) : null, centerRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick, rowAutoHeight: rowAutoHeight, columnOrder: columnOrder, enableColumnsOrderSortByDrag: enableColumnsOrderSortByDrag }, row.id))), data.length > 0 && infiniteLoading && loading && !dataError && (_jsx(SkeletonContextProvider, { loading: true, children: loadingTableRows.slice(0, 3).map(row => (_jsx(BodyRow, { row: row, columnOrder: columnOrder, 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 })] }), !infiniteLoading && !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 }))] })));
283
311
  }
284
312
  Table.getStatusColumnDef = getStatusColumnDef;
285
313
  Table.statusAppearances = STATUS_APPEARANCE;
@@ -1,2 +1,3 @@
1
1
  export * from './useLoadingTable';
2
2
  export * from './useStateControl';
3
+ export * from './useColumnOrderByDrag';
@@ -1,2 +1,3 @@
1
1
  export * from './useLoadingTable';
2
2
  export * from './useStateControl';
3
+ export * from './useColumnOrderByDrag';
@@ -0,0 +1,8 @@
1
+ import { DragEndEvent, SensorOptions } from '@dnd-kit/core';
2
+ import { ColumnDefinition } 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
+ handleDragEnd: ({ active, over }: DragEndEvent) => void;
7
+ sensors: import("@dnd-kit/core").SensorDescriptor<SensorOptions>[];
8
+ };
@@ -0,0 +1,39 @@
1
+ import { KeyboardSensor, MouseSensor, TouchSensor, useSensor, useSensors, } from '@dnd-kit/core';
2
+ import { arrayMove } from '@dnd-kit/sortable';
3
+ import { useCallback, useState } from 'react';
4
+ function prepareInitialState(tableColumns) {
5
+ return tableColumns.filter(column => column.pinned !== 'left' && column.pinned !== 'right').map(c => c.id);
6
+ }
7
+ const draggingOptions = {
8
+ activationConstraint: {
9
+ distance: 5, // Is required to differ click (sort) from drag
10
+ },
11
+ };
12
+ export function useColumnOrderByDrag(tableColumns) {
13
+ const [columnOrder, setColumnOrder] = useState(() => prepareInitialState(tableColumns));
14
+ const handleDragEnd = useCallback(({ active, over }) => {
15
+ if (!active || !over) {
16
+ return;
17
+ }
18
+ const activeId = active.id.toString();
19
+ const overId = over.id.toString();
20
+ if (activeId === overId) {
21
+ return;
22
+ }
23
+ if (!columnOrder.includes(overId)) {
24
+ return;
25
+ }
26
+ setColumnOrder(columnOrder => {
27
+ const oldIndex = columnOrder.indexOf(activeId);
28
+ const newIndex = columnOrder.indexOf(overId);
29
+ return arrayMove(columnOrder, oldIndex, newIndex);
30
+ });
31
+ }, [columnOrder]);
32
+ const sensors = useSensors(useSensor(MouseSensor, draggingOptions), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}));
33
+ return {
34
+ columnOrder,
35
+ setColumnOrder,
36
+ handleDragEnd,
37
+ sensors,
38
+ };
39
+ }
@@ -1,3 +1,6 @@
1
+ import { GroupSelectItemProps } from '@snack-uikit/list';
2
+ import { useLocale } from '@snack-uikit/locale';
3
+ import { ColumnDefinition, FilterableColumnDefinition } from '../../types';
1
4
  export declare function getCurrentlyConfiguredHeaderWidth(id: string): number;
2
5
  export declare function getColumnStyleVars(id: string): {
3
6
  sizeKey: string;
@@ -14,4 +17,14 @@ type SaveStateToLocalStorageProps = {
14
17
  size: string;
15
18
  };
16
19
  export declare function saveStateToLocalStorage({ id, columnId, size }: SaveStateToLocalStorageProps): void;
20
+ export declare function isFilterableColumn<TData extends object>(colDef: ColumnDefinition<TData>): colDef is FilterableColumnDefinition<TData>;
21
+ export declare function prepareColumnsSettingsMap<TData extends object>(columnDefinitions: ColumnDefinition<TData>[]): string[];
22
+ type PrepareColumnsSettingsProps<TData extends object> = {
23
+ columnDefinitions: ColumnDefinition<TData>[];
24
+ columnOrder: string[];
25
+ areAllColumnsEnabled: boolean;
26
+ columnsSettingsHeader?: string;
27
+ t: ReturnType<typeof useLocale<'Table'>>['t'];
28
+ };
29
+ export declare function prepareColumnsSettings<TData extends object>({ columnDefinitions, columnOrder, columnsSettingsHeader, areAllColumnsEnabled, t, }: PrepareColumnsSettingsProps<TData>): [GroupSelectItemProps];
17
30
  export {};
@@ -35,3 +35,73 @@ export function saveStateToLocalStorage({ id, columnId, size }) {
35
35
  newResizeState[`${RESIZED_KEY}-${columnId}`] = size;
36
36
  localStorage.setItem(id, JSON.stringify(Object.assign(Object.assign({}, (savedStateFromStorage || {})), { resizeState: newResizeState })));
37
37
  }
38
+ export function isFilterableColumn(colDef) {
39
+ return 'id' in colDef && 'headerConfigLabel' in colDef;
40
+ }
41
+ export function prepareColumnsSettingsMap(columnDefinitions) {
42
+ return columnDefinitions.filter(isFilterableColumn).map(colDef => colDef.id);
43
+ }
44
+ const sortColumnDefinitions = (columnOrder) => function sortColDefs(colDefA, colDefB) {
45
+ const indexItemA = columnOrder.findIndex(columnIndex => columnIndex === colDefA.id);
46
+ const indexItemB = columnOrder.findIndex(columnIndex => columnIndex === colDefB.id);
47
+ return indexItemA - indexItemB;
48
+ };
49
+ function createColumnsSettingsOption(columnDefinition) {
50
+ return {
51
+ id: columnDefinition.id,
52
+ content: {
53
+ option: columnDefinition.headerConfigLabel,
54
+ },
55
+ switch: true,
56
+ showSwitchIcon: true,
57
+ };
58
+ }
59
+ export function prepareColumnsSettings({ columnDefinitions, columnOrder, columnsSettingsHeader, areAllColumnsEnabled, t, }) {
60
+ const groupedItems = columnDefinitions
61
+ .filter(isFilterableColumn)
62
+ .sort(sortColumnDefinitions(columnOrder))
63
+ .reduce((accSettings, colDef) => {
64
+ const item = createColumnsSettingsOption(colDef);
65
+ switch (colDef.pinned) {
66
+ case 'left':
67
+ accSettings.pinTop.push(item);
68
+ break;
69
+ case 'right':
70
+ accSettings.pinBottom.push(item);
71
+ break;
72
+ default:
73
+ accSettings.unpinned.push(item);
74
+ }
75
+ return accSettings;
76
+ }, {
77
+ pinTop: [],
78
+ unpinned: [],
79
+ pinBottom: [],
80
+ });
81
+ return [
82
+ {
83
+ divider: false,
84
+ items: [
85
+ {
86
+ divider: false,
87
+ items: groupedItems.pinTop,
88
+ type: 'group',
89
+ },
90
+ {
91
+ divider: true,
92
+ items: groupedItems.unpinned,
93
+ type: 'group',
94
+ },
95
+ {
96
+ divider: true,
97
+ items: groupedItems.pinBottom,
98
+ type: 'group',
99
+ },
100
+ ],
101
+ selectButtonLabel: areAllColumnsEnabled ? t('groupSelectButton.hide') : t('groupSelectButton.show'),
102
+ label: columnsSettingsHeader || 'Display settings',
103
+ mode: 'primary',
104
+ type: 'group-select',
105
+ },
106
+ ];
107
+ }
@@ -1,7 +1,7 @@
1
1
  import { PaginationState, Row, RowPinningState, RowSelectionOptions, RowSelectionState, SortingState } from '@tanstack/react-table';
2
2
  import { ReactNode, RefObject } from 'react';
3
- import { ChipChoiceRowProps, FiltersState } from '@snack-uikit/chips';
4
- import { ToolbarProps } from '@snack-uikit/toolbar';
3
+ import { FiltersState } from '@snack-uikit/chips';
4
+ import { FilterRow, ToolbarProps } from '@snack-uikit/toolbar';
5
5
  import { WithSupportProps } from '@snack-uikit/utils';
6
6
  import { EmptyStateProps, ExportButtonProps, RowClickHandler } from '../helperComponents';
7
7
  import { TreeColumnDefinitionProps } from '../helperComponents/Cells/TreeCell';
@@ -30,6 +30,15 @@ type BaseTableProps<TData extends object, TFilters extends FiltersState = Record
30
30
  state?: SortingState;
31
31
  onChange?(state: SortingState): void;
32
32
  };
33
+ /** Параметры отвечают за настройки колонок <br>
34
+ * <strong>enableDrag</strong>: Включение сортировки порядка столбцов вручную перетаскиванием <br>
35
+ * <strong>headerLabel</strong>: Название меню настроек колонок. Наличие включает показ настроек <br>
36
+ * <strong>selectAllButtonLabels</strong>: Значения кнопки включения/отключения всех айтемов ([вкл, выкл]) <br>
37
+ * */
38
+ columnsSettings?: {
39
+ enableDrag?: boolean;
40
+ headerLabel?: string;
41
+ };
33
42
  /** Параметр отвечает за общие настройки раскрывающихся строк*/
34
43
  expanding?: {
35
44
  /** Метод отвечает за получение дочерних строк*/
@@ -80,7 +89,7 @@ type BaseTableProps<TData extends object, TFilters extends FiltersState = Record
80
89
  /** Внешний бордер для тулбара и таблицы */
81
90
  outline?: boolean;
82
91
  /** Фильтры */
83
- columnFilters?: ChipChoiceRowProps<TFilters>;
92
+ columnFilters?: FilterRow<TFilters>;
84
93
  /** Флаг, показывающий что данные были отфильтрованы при пустых данных */
85
94
  dataFiltered?: boolean;
86
95
  /** Флаг, показывающий что произошла ошибка запроса при пустых данных */
@@ -38,3 +38,4 @@ export declare const DEFAULT_PAGE_SIZE = 10;
38
38
  export declare const DEFAULT_SORTING: never[];
39
39
  export declare const DEFAULT_FILTER_VISIBILITY: never[];
40
40
  export declare const DEFAULT_ROW_SELECTION: {};
41
+ export declare const DEFAULT_COLUMNS: string[];
@@ -38,3 +38,4 @@ export const DEFAULT_PAGE_SIZE = 10;
38
38
  export const DEFAULT_SORTING = [];
39
39
  export const DEFAULT_FILTER_VISIBILITY = [];
40
40
  export const DEFAULT_ROW_SELECTION = {};
41
+ export const DEFAULT_COLUMNS = ['snack_predefined_statusColumn', 'selectionCell', 'rowActions'];
@@ -3,6 +3,7 @@ import { CellProps } from '../Cell';
3
3
  type BodyCellProps<TData> = Omit<CellProps, 'style' | 'children'> & {
4
4
  cell: TableCell<TData, unknown>;
5
5
  rowAutoHeight?: boolean;
6
+ isDraggable?: boolean;
6
7
  };
7
- export declare function BodyCell<TData>({ cell, className, rowAutoHeight, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
8
+ export declare function BodyCell<TData>({ cell, className, rowAutoHeight, isDraggable, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
8
9
  export {};
@@ -10,6 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useSortable } from '@dnd-kit/sortable';
13
14
  import { flexRender } from '@tanstack/react-table';
14
15
  import cn from 'classnames';
15
16
  import { TEST_IDS } from '../../../constants';
@@ -17,8 +18,11 @@ import { useCellSizes } from '../../hooks';
17
18
  import { Cell } from '../Cell';
18
19
  import styles from './styles.module.css';
19
20
  export function BodyCell(_a) {
20
- var { cell, className, rowAutoHeight } = _a, props = __rest(_a, ["cell", "className", "rowAutoHeight"]);
21
+ var { cell, className, rowAutoHeight, isDraggable } = _a, props = __rest(_a, ["cell", "className", "rowAutoHeight", "isDraggable"]);
21
22
  const columnDef = cell.column.columnDef;
22
- const style = useCellSizes(cell);
23
- return (_jsx(Cell, Object.assign({}, props, { style: style, className: cn(styles.tableBodyCell, className, columnDef.cellClassName), "data-row-auto-height": rowAutoHeight || undefined, "data-align": columnDef.align, "data-no-padding": columnDef.noBodyCellPadding || undefined, "data-column-id": cell.column.id, "data-test-id": TEST_IDS.bodyCell, children: flexRender(columnDef.cell, cell.getContext()) })));
23
+ const style = useCellSizes(cell, { isDraggable });
24
+ const { setNodeRef } = useSortable({
25
+ id: cell.column.id,
26
+ });
27
+ return (_jsx(Cell, Object.assign({}, props, { ref: setNodeRef, style: style, className: cn(styles.tableBodyCell, className, columnDef.cellClassName), "data-row-auto-height": rowAutoHeight || undefined, "data-align": columnDef.align, "data-no-padding": columnDef.noBodyCellPadding || undefined, "data-column-id": cell.column.id, "data-test-id": TEST_IDS.bodyCell, children: flexRender(columnDef.cell, cell.getContext()) })));
24
28
  }
@@ -5,6 +5,7 @@ type HeaderCellProps<TData> = Omit<CellProps, 'align' | 'children' | 'onClick' |
5
5
  header: Header<TData, unknown>;
6
6
  pinPosition?: ColumnPinPosition;
7
7
  rowAutoHeight?: boolean;
8
+ isDraggable?: boolean;
8
9
  };
9
- export declare function HeaderCell<TData>({ header, pinPosition, className, rowAutoHeight }: HeaderCellProps<TData>): import("react/jsx-runtime").JSX.Element;
10
+ export declare function HeaderCell<TData>({ header, pinPosition, className, rowAutoHeight, isDraggable, }: HeaderCellProps<TData>): import("react/jsx-runtime").JSX.Element;
10
11
  export {};
@@ -1,15 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useSortable } from '@dnd-kit/sortable';
2
3
  import { flexRender } from '@tanstack/react-table';
3
4
  import cn from 'classnames';
4
5
  import { useRef } from 'react';
5
6
  import { TruncateString } from '@snack-uikit/truncate-string';
6
- import { TEST_IDS } from '../../../constants';
7
+ import { DEFAULT_COLUMNS, TEST_IDS } from '../../../constants';
7
8
  import { useCellSizes } from '../../hooks';
8
9
  import { Cell } from '../Cell';
9
10
  import { getSortingIcon } from './helpers';
10
11
  import { ResizeHandle } from './ResizeHandle';
11
12
  import styles from './styles.module.css';
12
- export function HeaderCell({ header, pinPosition, className, rowAutoHeight }) {
13
+ export function HeaderCell({ header, pinPosition, className, rowAutoHeight, isDraggable, }) {
13
14
  const cellRef = useRef(null);
14
15
  const isSortable = header.column.getCanSort();
15
16
  const isResizable = header.column.getCanResize();
@@ -19,12 +20,21 @@ export function HeaderCell({ header, pinPosition, className, rowAutoHeight }) {
19
20
  const columnSizingInfo = header.getContext().table.getState().columnSizingInfo;
20
21
  const isSomeColumnResizing = columnSizingInfo.isResizingColumn;
21
22
  const columnDef = header.column.columnDef;
22
- const style = useCellSizes(header);
23
+ const style = useCellSizes(header, { isDraggable });
24
+ const { attributes, listeners, setNodeRef, isDragging } = useSortable({
25
+ id: header.column.id,
26
+ });
23
27
  const sortingHandler = (e) => {
24
28
  var _a;
25
29
  if (isSomeColumnResizing)
26
30
  return;
27
31
  return (_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(e);
28
32
  };
29
- return (_jsxs(Cell, { style: style, onClick: sortingHandler, "data-sortable": isSortable || undefined, "data-no-padding": columnDef.noHeaderCellPadding || undefined, "data-no-offset": columnDef.noHeaderCellBorderOffset || undefined, "data-test-id": TEST_IDS.headerCell, "data-align": columnDef.headerAlign || undefined, "data-header-id": header.id, "data-resizing": isResizing || undefined, "data-pin-position": pinPosition || undefined, "data-row-auto-height": rowAutoHeight || undefined, role: 'columnheader', className: cn(styles.tableHeaderCell, className, columnDef.headerClassName), ref: cellRef, children: [_jsxs("div", { className: styles.tableHeaderCellMain, children: [columnDef.header && (_jsx("div", { className: styles.tableHeaderCellName, children: rowAutoHeight ? (flexRender(columnDef.header, header.getContext())) : (_jsx(TruncateString, { text: flexRender(columnDef.header, header.getContext()) })) })), Boolean(sortIcon) && (_jsx("div", { className: styles.tableHeaderIcon, "data-sort-direction": sortDirection, "data-test-id": TEST_IDS.headerSortIndicator, children: sortIcon }))] }), Boolean(isResizable) && _jsx(ResizeHandle, { header: header, cellRef: cellRef })] }));
33
+ const isAvailableForDrag = !DEFAULT_COLUMNS.includes(header.column.id);
34
+ const dragAttributes = isAvailableForDrag ? attributes : {};
35
+ const listenersAttributes = isAvailableForDrag ? listeners : {};
36
+ return (_jsxs(Cell, { style: style, onClick: sortingHandler, "data-sortable": isSortable || undefined, "data-draggable": isDraggable || undefined, "data-no-padding": columnDef.noHeaderCellPadding || undefined, "data-no-offset": columnDef.noHeaderCellBorderOffset || undefined, "data-test-id": TEST_IDS.headerCell, "data-align": columnDef.headerAlign || undefined, "data-header-id": header.id, "data-resizing": isResizing || undefined, "data-pin-position": pinPosition || undefined, "data-row-auto-height": rowAutoHeight || undefined, role: 'columnheader', className: cn(styles.tableHeaderCell, className, columnDef.headerClassName), ref: element => {
37
+ setNodeRef(element);
38
+ return cellRef;
39
+ }, children: [_jsx("div", Object.assign({ className: styles.tableHeaderCellDragWrapper, "data-dragging": isDragging || undefined }, dragAttributes, listenersAttributes, { children: _jsxs("div", { className: styles.tableHeaderCellMain, children: [columnDef.header && (_jsx("div", { className: styles.tableHeaderCellName, children: rowAutoHeight ? (flexRender(columnDef.header, header.getContext())) : (_jsx(TruncateString, { text: flexRender(columnDef.header, header.getContext()) })) })), Boolean(sortIcon) && (_jsx("div", { className: styles.tableHeaderIcon, "data-sort-direction": sortDirection, "data-test-id": TEST_IDS.headerSortIndicator, children: sortIcon }))] }) })), Boolean(isResizable) && _jsx(ResizeHandle, { header: header, cellRef: cellRef })] }));
30
40
  }
@@ -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,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ButtonFunction } from '@snack-uikit/button';
3
+ import { FunctionSettingsSVG } from '@snack-uikit/icons';
4
+ import { Droplist } from '@snack-uikit/list';
5
+ import styles from './styles.module.css';
6
+ export function ColumnsSettings({ columnsSettings, enabledColumns, setEnabledColumns }) {
7
+ return (_jsx(Droplist, { className: styles.columnsSettings, items: columnsSettings, selection: {
8
+ value: enabledColumns,
9
+ onChange: setEnabledColumns,
10
+ mode: 'multiple',
11
+ }, placement: 'bottom-end', children: _jsx(ButtonFunction, { size: 'm', "data-test-id": 'table__column-settings', icon: _jsx(FunctionSettingsSVG, {}) }) }));
12
+ }
@@ -0,0 +1 @@
1
+ export * from './ColumnsSettings';
@@ -0,0 +1 @@
1
+ export * from './ColumnsSettings';
@@ -0,0 +1,3 @@
1
+ .columnsSettings{
2
+ min-width:256px;
3
+ }
@@ -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;
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable';
2
3
  import { useState } from 'react';
3
4
  import { COLUMN_PIN_POSITION, TEST_IDS } from '../../constants';
4
5
  import { BodyCell } from '../Cells';
@@ -7,8 +8,8 @@ import { useRowCells } from '../hooks';
7
8
  import { PinnedCells } from './PinnedCells';
8
9
  import { Row } from './Row';
9
10
  import styles from './styles.module.css';
10
- export function BodyRow({ row, onRowClick, rowAutoHeight }) {
11
- const { pinnedLeft, pinnedRight, unpinned } = useRowCells(row);
11
+ export function BodyRow({ row, onRowClick, rowAutoHeight, columnOrder, enableColumnsOrderSortByDrag, }) {
12
+ const { leftPinned, rightPinned, unpinned } = useRowCells(row);
12
13
  const [dropListOpened, setDropListOpen] = useState(false);
13
14
  const disabled = !row.getCanSelect();
14
15
  const handleRowClick = (e) => {
@@ -23,5 +24,5 @@ export function BodyRow({ row, onRowClick, rowAutoHeight }) {
23
24
  };
24
25
  return (_jsx(RowContext.Provider, { value: { dropListOpened, setDropListOpen }, children: _jsxs(Row, { onClick: handleRowClick, "data-clickable": Boolean(onRowClick) || undefined, "data-disabled": disabled || undefined, "data-selected": row.getIsSelected() ||
25
26
  (row.getIsSomeSelected() && !row.getCanMultiSelect() && !row.getIsExpanded()) ||
26
- undefined, "data-actions-opened": dropListOpened || undefined, "data-test-id": TEST_IDS.bodyRow, "data-row-id": row.id, className: styles.bodyRow, rowAutoHeight: rowAutoHeight, children: [pinnedLeft && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Left, children: pinnedLeft.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight }, cell.id))) })), unpinned.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight }, cell.id))), pinnedRight && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: pinnedRight.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight }, cell.id))) }))] }) }));
27
+ undefined, "data-actions-opened": dropListOpened || undefined, "data-test-id": TEST_IDS.bodyRow, "data-row-id": row.id, className: styles.bodyRow, rowAutoHeight: rowAutoHeight, children: [leftPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Left, children: leftPinned.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight }, cell.id))) })), unpinned.map(cell => (_jsx(SortableContext, { items: columnOrder, strategy: horizontalListSortingStrategy, children: _jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight, isDraggable: enableColumnsOrderSortByDrag }, cell.id) }, cell.id))), rightPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: rightPinned.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight, isDraggable: enableColumnsOrderSortByDrag }, cell.id))) }))] }) }));
27
28
  }
@@ -1,2 +1,8 @@
1
+ import { ColumnOrder } from '../../types';
1
2
  import { RowProps } from './Row';
2
- export declare function HeaderRow({ rowAutoHeight }: Pick<RowProps, 'rowAutoHeight'>): import("react/jsx-runtime").JSX.Element;
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 {};
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable';
2
3
  import { COLUMN_PIN_POSITION, TEST_IDS } from '../../constants';
3
4
  import { HeaderCell } from '../Cells';
4
5
  import { useHeaderGroups } from '../hooks';
5
6
  import { PinnedCells } from './PinnedCells';
6
7
  import { Row } from './Row';
7
8
  import styles from './styles.module.css';
8
- export function HeaderRow({ rowAutoHeight }) {
9
+ export function HeaderRow({ rowAutoHeight, columnOrder, enableColumnsOrderSortByDrag }) {
9
10
  const { leftPinned, unpinned, rightPinned } = useHeaderGroups();
10
- return (_jsxs(Row, { className: styles.tableHeader, "data-test-id": TEST_IDS.headerRow, rowAutoHeight: rowAutoHeight, children: [leftPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Left, children: leftPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (_jsx(HeaderCell, { header: header, rowAutoHeight: rowAutoHeight }, header.id)))) })), unpinned.map(headerGroup => headerGroup.headers.map(header => _jsx(HeaderCell, { header: header, rowAutoHeight: rowAutoHeight }, header.id))), rightPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: rightPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (_jsx(HeaderCell, { header: header, pinPosition: COLUMN_PIN_POSITION.Right, rowAutoHeight: rowAutoHeight }, header.id)))) }))] }));
11
+ return (_jsxs(Row, { className: styles.tableHeader, "data-test-id": TEST_IDS.headerRow, rowAutoHeight: rowAutoHeight, children: [leftPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Left, children: leftPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (_jsx(HeaderCell, { header: header, rowAutoHeight: rowAutoHeight }, header.id)))) })), _jsx(SortableContext, { items: columnOrder, strategy: horizontalListSortingStrategy, children: unpinned.map(headerGroup => headerGroup.headers.map(header => (_jsx(HeaderCell, { header: header, rowAutoHeight: rowAutoHeight, isDraggable: enableColumnsOrderSortByDrag && columnOrder.length > 1 }, header.id)))) }), rightPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: rightPinned.map(headerGroup => headerGroup.headers.map(header => header.isPlaceholder ? null : (_jsx(HeaderCell, { header: header, pinPosition: COLUMN_PIN_POSITION.Right, rowAutoHeight: rowAutoHeight }, header.id)))) }))] }));
11
12
  }
@@ -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
- pinnedLeft?: undefined;
14
- pinnedRight?: undefined;
14
+ leftPinned?: undefined;
15
+ rightPinned?: undefined;
15
16
  } | {
16
- pinnedLeft: Cell<TData, unknown>[] | undefined;
17
- pinnedRight: Cell<TData, unknown>[] | undefined;
17
+ leftPinned: Cell<TData, unknown>[] | undefined;
18
+ rightPinned: Cell<TData, unknown>[] | undefined;
18
19
  unpinned: Cell<TData, unknown>[];
19
20
  };
20
- export declare function useCellSizes<TData>(element: Cell<TData, unknown> | Header<TData, unknown>): {
21
- minWidth: number | undefined;
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 {};