@cloud-ru/ds-table 1.0.2 → 1.0.3
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 +7 -0
- package/README.md +3 -3
- package/dist/cjs/components/Table/Table.js +12 -4
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.d.ts +2 -0
- package/dist/cjs/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.js +20 -3
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.d.ts +2 -2
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.js +2 -2
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.d.ts +8 -0
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.js +15 -0
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/index.d.ts +1 -0
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/index.js +1 -0
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/isColumnEnabledInitially.js +3 -4
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.js +3 -15
- package/dist/cjs/components/Table/hooks/useColumnSettings/utils/isFilterableColumn.js +4 -2
- package/dist/cjs/components/Table/hooks/useTableScroll.js +15 -1
- package/dist/cjs/components/Table/styles.module.css +19 -1
- package/dist/cjs/components/Table/utils/alignOverlayToHeader.d.ts +6 -0
- package/dist/cjs/components/Table/utils/alignOverlayToHeader.js +28 -0
- package/dist/cjs/components/Table/utils/index.d.ts +1 -0
- package/dist/cjs/components/Table/utils/index.js +1 -0
- package/dist/cjs/constants.d.ts +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.d.ts +3 -1
- package/dist/cjs/helperComponents/Cells/BodyCell/BodyCell.js +9 -10
- package/dist/cjs/helperComponents/Cells/HeaderCell/HeaderCell.js +7 -6
- package/dist/cjs/helperComponents/Cells/HeaderCell/ResizeHandle.js +1 -1
- package/dist/cjs/helperComponents/Cells/styles.module.css +3 -0
- package/dist/cjs/helperComponents/Rows/BodyRow.js +1 -2
- package/dist/cjs/helperComponents/Rows/styles.module.css +4 -0
- package/dist/cjs/helperComponents/TableEmptyState/hooks.js +0 -1
- package/dist/cjs/helperComponents/TableEmptyState/styles.module.css +3 -1
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useCellSizes.d.ts +0 -1
- package/dist/cjs/hooks/useCellSizes.js +1 -4
- package/dist/cjs/hooks/useColumnDragTransform.d.ts +15 -0
- package/dist/cjs/hooks/useColumnDragTransform.js +38 -0
- package/dist/cjs/locale/index.d.ts +0 -4
- package/dist/cjs/locale/index.js +0 -2
- package/dist/cjs/style.css +29 -2
- package/dist/cjs/types.d.ts +1 -0
- package/dist/esm/components/Table/Table.js +15 -7
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.d.ts +2 -0
- package/dist/esm/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.js +21 -4
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.d.ts +2 -2
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.js +2 -2
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.d.ts +8 -0
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.js +11 -0
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/index.d.ts +1 -0
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/index.js +1 -0
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/isColumnEnabledInitially.js +3 -4
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.js +3 -15
- package/dist/esm/components/Table/hooks/useColumnSettings/utils/isFilterableColumn.js +4 -2
- package/dist/esm/components/Table/hooks/useTableScroll.js +15 -1
- package/dist/esm/components/Table/styles.module.css +19 -1
- package/dist/esm/components/Table/utils/alignOverlayToHeader.d.ts +6 -0
- package/dist/esm/components/Table/utils/alignOverlayToHeader.js +24 -0
- package/dist/esm/components/Table/utils/index.d.ts +1 -0
- package/dist/esm/components/Table/utils/index.js +1 -0
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.d.ts +3 -1
- package/dist/esm/helperComponents/Cells/BodyCell/BodyCell.js +10 -11
- package/dist/esm/helperComponents/Cells/HeaderCell/HeaderCell.js +7 -6
- package/dist/esm/helperComponents/Cells/HeaderCell/ResizeHandle.js +1 -1
- package/dist/esm/helperComponents/Cells/styles.module.css +3 -0
- package/dist/esm/helperComponents/Rows/BodyRow.js +1 -2
- package/dist/esm/helperComponents/Rows/styles.module.css +4 -0
- package/dist/esm/helperComponents/TableEmptyState/hooks.js +0 -1
- package/dist/esm/helperComponents/TableEmptyState/styles.module.css +3 -1
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useCellSizes.d.ts +0 -1
- package/dist/esm/hooks/useCellSizes.js +1 -4
- package/dist/esm/hooks/useColumnDragTransform.d.ts +15 -0
- package/dist/esm/hooks/useColumnDragTransform.js +35 -0
- package/dist/esm/locale/index.d.ts +0 -4
- package/dist/esm/locale/index.js +0 -2
- package/dist/esm/style.css +29 -2
- package/dist/esm/types.d.ts +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/src/components/Table/Table.tsx +53 -26
- package/src/components/Table/hooks/useColumnOrderByDrag/useColumnOrderByDrag.ts +31 -7
- package/src/components/Table/hooks/useColumnSettings/utils/createColumnsSettingsOption.ts +2 -2
- package/src/components/Table/hooks/useColumnSettings/utils/getColumnSettingsMode.ts +18 -0
- package/src/components/Table/hooks/useColumnSettings/utils/index.ts +1 -0
- package/src/components/Table/hooks/useColumnSettings/utils/isColumnEnabledInitially.ts +3 -5
- package/src/components/Table/hooks/useColumnSettings/utils/isColumnVisibilityConfigurable.ts +3 -18
- package/src/components/Table/hooks/useColumnSettings/utils/isFilterableColumn.ts +4 -2
- package/src/components/Table/hooks/useTableScroll.ts +21 -1
- package/src/components/Table/styles.module.scss +23 -1
- package/src/components/Table/utils/alignOverlayToHeader.ts +36 -0
- package/src/components/Table/utils/index.ts +1 -0
- package/src/constants.ts +1 -1
- package/src/helperComponents/Cells/BodyCell/BodyCell.tsx +18 -15
- package/src/helperComponents/Cells/HeaderCell/HeaderCell.tsx +10 -7
- package/src/helperComponents/Cells/HeaderCell/ResizeHandle.tsx +1 -2
- package/src/helperComponents/Cells/styles.module.scss +11 -0
- package/src/helperComponents/Rows/BodyRow.tsx +9 -10
- package/src/helperComponents/Rows/styles.module.scss +5 -0
- package/src/helperComponents/TableEmptyState/hooks.ts +0 -1
- package/src/helperComponents/TableEmptyState/styles.module.scss +5 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useCellSizes.ts +1 -5
- package/src/hooks/useColumnDragTransform.ts +52 -0
- package/src/locale/index.ts +0 -2
- package/src/types.ts +3 -5
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
2
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/components/table.module' as table;
|
|
3
|
+
|
|
4
|
+
// Та же толщина, что у строковых разделителей таблицы.
|
|
5
|
+
$drag-rail: base.simple-var(table.$table, 'anatomy', 'content', 'tableLine', 'background', 'interaction', 'width');
|
|
2
6
|
|
|
3
7
|
.tableCell {
|
|
4
8
|
@include base.composite-var(base.$sn-regular-body-m);
|
|
@@ -10,4 +14,11 @@
|
|
|
10
14
|
width: 100%;
|
|
11
15
|
|
|
12
16
|
background-color: transparent;
|
|
17
|
+
|
|
18
|
+
// `box-shadow`, а не `border`: ширина ячейки не должна меняться в момент захвата.
|
|
19
|
+
&[data-dragging] {
|
|
20
|
+
box-shadow:
|
|
21
|
+
inset #{$drag-rail} 0 0 0 base.$sn-theme-color-available-borderColor,
|
|
22
|
+
inset calc(-1 * #{$drag-rail}) 0 0 0 base.$sn-theme-color-available-borderColor;
|
|
23
|
+
}
|
|
13
24
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable';
|
|
2
1
|
import { Row as TableRow } from '@tanstack/react-table';
|
|
3
2
|
import { CSSProperties, MouseEvent, useState } from 'react';
|
|
4
3
|
|
|
@@ -86,15 +85,15 @@ export function BodyRow<TData>({
|
|
|
86
85
|
{columnVirtualPadding && columnVirtualPadding.left > 0 && (
|
|
87
86
|
<div aria-hidden style={{ width: columnVirtualPadding.left, flexShrink: 0 } as CSSProperties} />
|
|
88
87
|
)}
|
|
89
|
-
{
|
|
90
|
-
<
|
|
91
|
-
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)}
|
|
88
|
+
{unpinned.map(cell => (
|
|
89
|
+
<BodyCell
|
|
90
|
+
key={cell.id}
|
|
91
|
+
cell={cell}
|
|
92
|
+
rowAutoHeight={rowAutoHeight}
|
|
93
|
+
isDraggable={enableColumnsOrderSortByDrag}
|
|
94
|
+
columnOrder={columnOrder}
|
|
95
|
+
/>
|
|
96
|
+
))}
|
|
98
97
|
{columnVirtualPadding && columnVirtualPadding.right > 0 && (
|
|
99
98
|
<div aria-hidden style={{ width: columnVirtualPadding.right, flexShrink: 0 } as CSSProperties} />
|
|
100
99
|
)}
|
|
@@ -116,6 +116,11 @@ $row-bg-tones: (
|
|
|
116
116
|
width: $pinned-border;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
// Под шапкой строк нет — продолжать разделитель нечем, обрезаем хвост.
|
|
120
|
+
.tableHeader .rowPinnedCells::after {
|
|
121
|
+
bottom: 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
119
124
|
.rowPinnedCells[data-position='left'] {
|
|
120
125
|
left: 0;
|
|
121
126
|
}
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
@use '@cloud-ru/ds-figma-variables/build/scss/components/table.module' as table;
|
|
4
4
|
|
|
5
5
|
.tableEmptyStateWrapper {
|
|
6
|
+
// Живёт внутри горизонтального скролла колонок: без sticky уезжает вместе с ними.
|
|
7
|
+
position: sticky;
|
|
8
|
+
left: 0;
|
|
9
|
+
|
|
6
10
|
display: flex;
|
|
7
11
|
flex: 1 1 auto;
|
|
8
12
|
flex-direction: column;
|
|
@@ -10,7 +14,7 @@
|
|
|
10
14
|
justify-content: center;
|
|
11
15
|
|
|
12
16
|
box-sizing: border-box;
|
|
13
|
-
width: 100
|
|
17
|
+
width: var(--table-viewport-width, 100%);
|
|
14
18
|
min-height: base.simple-var(table.$table, 'anatomy', 'content', 'body', 'min-height'); // 304px
|
|
15
19
|
padding: base.$sn-primitive-dimension-24;
|
|
16
20
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { TABLE_COLUMN_CSS_VARS } from '../constants';
|
|
|
6
6
|
|
|
7
7
|
type CellSizesOptions = {
|
|
8
8
|
isDraggable?: boolean;
|
|
9
|
-
isDragging?: boolean;
|
|
10
9
|
transform?: Transform | null;
|
|
11
10
|
};
|
|
12
11
|
|
|
@@ -15,7 +14,6 @@ export function useCellSizes<TData>(
|
|
|
15
14
|
options?: CellSizesOptions,
|
|
16
15
|
): CSSProperties {
|
|
17
16
|
const column = element.column;
|
|
18
|
-
const isDragging = options?.isDragging ?? false;
|
|
19
17
|
const transform = options?.transform ?? null;
|
|
20
18
|
|
|
21
19
|
const minWidth = column.columnDef.minSize;
|
|
@@ -33,10 +31,8 @@ export function useCellSizes<TData>(
|
|
|
33
31
|
};
|
|
34
32
|
|
|
35
33
|
if (options?.isDraggable) {
|
|
36
|
-
styles.opacity = isDragging ? 0.8 : 1;
|
|
37
34
|
styles.position = 'relative';
|
|
38
35
|
styles.transform = CSS.Translate.toString(transform);
|
|
39
|
-
styles.zIndex = isDragging ? 1 : undefined;
|
|
40
36
|
|
|
41
37
|
if (isHeaderCell) {
|
|
42
38
|
styles.whiteSpace = 'nowrap';
|
|
@@ -44,5 +40,5 @@ export function useCellSizes<TData>(
|
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
return styles;
|
|
47
|
-
}, [options?.isDraggable, flexShrink,
|
|
43
|
+
}, [options?.isDraggable, flexShrink, isHeaderCell, maxWidth, minWidth, transform, width]);
|
|
48
44
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ClientRect, useDndContext } from '@dnd-kit/core';
|
|
2
|
+
import { horizontalListSortingStrategy } from '@dnd-kit/sortable';
|
|
3
|
+
import { Transform } from '@dnd-kit/utilities';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
|
|
6
|
+
import { ColumnOrder } from '../types';
|
|
7
|
+
|
|
8
|
+
type ColumnDragState = {
|
|
9
|
+
transform: Transform | null;
|
|
10
|
+
isDragging: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
15
|
+
*
|
|
16
|
+
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
17
|
+
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
18
|
+
* драг переставал работать.
|
|
19
|
+
*/
|
|
20
|
+
export function useColumnDragTransform(columnId: string, columnOrder: ColumnOrder): ColumnDragState {
|
|
21
|
+
const { active, over, activeNodeRect, droppableRects } = useDndContext();
|
|
22
|
+
|
|
23
|
+
const activeId = active ? String(active.id) : undefined;
|
|
24
|
+
const overId = over ? String(over.id) : undefined;
|
|
25
|
+
|
|
26
|
+
const transform = useMemo(() => {
|
|
27
|
+
if (!activeId) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const measured = columnOrder.filter(id => droppableRects.get(id));
|
|
32
|
+
|
|
33
|
+
const index = measured.indexOf(columnId);
|
|
34
|
+
const activeIndex = measured.indexOf(activeId);
|
|
35
|
+
|
|
36
|
+
if (index < 0 || activeIndex < 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const overIndex = overId ? measured.indexOf(overId) : -1;
|
|
41
|
+
|
|
42
|
+
return horizontalListSortingStrategy({
|
|
43
|
+
rects: measured.map(id => droppableRects.get(id) as ClientRect),
|
|
44
|
+
activeNodeRect,
|
|
45
|
+
activeIndex,
|
|
46
|
+
overIndex: overIndex < 0 ? activeIndex : overIndex,
|
|
47
|
+
index,
|
|
48
|
+
});
|
|
49
|
+
}, [activeId, overId, columnId, columnOrder, droppableRects, activeNodeRect]);
|
|
50
|
+
|
|
51
|
+
return { transform, isDragging: activeId === columnId };
|
|
52
|
+
}
|
package/src/locale/index.ts
CHANGED
|
@@ -15,7 +15,6 @@ const TABLE_MESSAGES = defineMessages({
|
|
|
15
15
|
},
|
|
16
16
|
noData: {
|
|
17
17
|
title: 'No data',
|
|
18
|
-
content: 'Try refreshing the page',
|
|
19
18
|
},
|
|
20
19
|
noResults: {
|
|
21
20
|
title: 'Nothing found',
|
|
@@ -40,7 +39,6 @@ const TABLE_MESSAGES = defineMessages({
|
|
|
40
39
|
},
|
|
41
40
|
noData: {
|
|
42
41
|
title: 'Нет данных',
|
|
43
|
-
content: 'Обновите страницу',
|
|
44
42
|
},
|
|
45
43
|
noResults: {
|
|
46
44
|
title: 'Ничего не найдено',
|
package/src/types.ts
CHANGED
|
@@ -69,6 +69,7 @@ type FilterableProps = {
|
|
|
69
69
|
columnSettings?: {
|
|
70
70
|
/** Название колонки в настройках таблицы */
|
|
71
71
|
label?: string;
|
|
72
|
+
/** Поведение колонки в меню настроек. По умолчанию `defaultVisible` */
|
|
72
73
|
mode?: ColumnSettingsMode;
|
|
73
74
|
};
|
|
74
75
|
} & ({ id: string } | { accessorKey: string });
|
|
@@ -77,13 +78,10 @@ type FilterableNormalColumnDefinition<TData> = NormalColumnDefinition<TData> & F
|
|
|
77
78
|
type FilterablePinnedColumnDefinition<TData> = PinnedColumnDefinition<TData> & FilterableProps;
|
|
78
79
|
|
|
79
80
|
export type FilterableColumnDefinition<TData> =
|
|
80
|
-
|
|
|
81
|
-
| FilterablePinnedColumnDefinition<TData>;
|
|
81
|
+
FilterableNormalColumnDefinition<TData> | FilterablePinnedColumnDefinition<TData>;
|
|
82
82
|
|
|
83
83
|
export type ColumnDefinition<TData> =
|
|
84
|
-
|
|
|
85
|
-
| PinnedColumnDefinition<TData>
|
|
86
|
-
| FilterableColumnDefinition<TData>;
|
|
84
|
+
NormalColumnDefinition<TData> | PinnedColumnDefinition<TData> | FilterableColumnDefinition<TData>;
|
|
87
85
|
|
|
88
86
|
export type ColumnOrder = string[];
|
|
89
87
|
|