@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
package/dist/esm/constants.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const COLUMN_ALIGN: {
|
|
|
10
10
|
export declare const COLUMN_SETTINGS_MODE: {
|
|
11
11
|
/** В меню настроек `Switch` заблокирован, колонка всегда видима */
|
|
12
12
|
readonly Locked: "locked";
|
|
13
|
-
/** В меню, по умолчанию
|
|
13
|
+
/** В меню, по умолчанию включена. Режим по умолчанию для любой колонки */
|
|
14
14
|
readonly DefaultVisible: "defaultVisible";
|
|
15
15
|
/** В меню, по умолчанию выключена */
|
|
16
16
|
readonly DefaultHidden: "defaultHidden";
|
package/dist/esm/constants.js
CHANGED
|
@@ -9,7 +9,7 @@ export const COLUMN_ALIGN = {
|
|
|
9
9
|
export const COLUMN_SETTINGS_MODE = {
|
|
10
10
|
/** В меню настроек `Switch` заблокирован, колонка всегда видима */
|
|
11
11
|
Locked: 'locked',
|
|
12
|
-
/** В меню, по умолчанию
|
|
12
|
+
/** В меню, по умолчанию включена. Режим по умолчанию для любой колонки */
|
|
13
13
|
DefaultVisible: 'defaultVisible',
|
|
14
14
|
/** В меню, по умолчанию выключена */
|
|
15
15
|
DefaultHidden: 'defaultHidden',
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Cell as TableCell } from '@tanstack/react-table';
|
|
2
|
+
import { ColumnOrder } from '../../../types.js';
|
|
2
3
|
import { CellProps } from '../Cell.js';
|
|
3
4
|
type BodyCellProps<TData> = Omit<CellProps, 'style' | 'children'> & {
|
|
4
5
|
cell: TableCell<TData, unknown>;
|
|
5
6
|
rowAutoHeight?: boolean;
|
|
6
7
|
isDraggable?: boolean;
|
|
8
|
+
columnOrder?: ColumnOrder;
|
|
7
9
|
};
|
|
8
|
-
export declare function BodyCell<TData>({ isDraggable, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function BodyCell<TData>({ isDraggable, columnOrder, ...props }: BodyCellProps<TData>): import("react/jsx-runtime").JSX.Element;
|
|
9
11
|
export {};
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useSortable } from '@dnd-kit/sortable';
|
|
3
2
|
import { flexRender } from '@tanstack/react-table';
|
|
4
3
|
import cn from 'classnames';
|
|
5
4
|
import { TEST_IDS } from '../../../constants.js';
|
|
6
|
-
import { useCellSizes } from '../../../hooks/index.js';
|
|
5
|
+
import { useCellSizes, useColumnDragTransform } from '../../../hooks/index.js';
|
|
7
6
|
import { Cell } from '../Cell.js';
|
|
8
7
|
import styles from './styles.module.css';
|
|
9
|
-
function BodyCellView({ cell, className, rowAutoHeight, style,
|
|
8
|
+
function BodyCellView({ cell, className, rowAutoHeight, style, isDragging, ...props }) {
|
|
10
9
|
const columnDef = cell.column.columnDef;
|
|
11
|
-
return (_jsx(Cell, { ...props,
|
|
10
|
+
return (_jsx(Cell, { ...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-dragging": isDragging || undefined, "data-test-id": TEST_IDS.bodyCell, children: flexRender(columnDef.cell, cell.getContext()) }));
|
|
12
11
|
}
|
|
13
12
|
function StaticBodyCell(props) {
|
|
14
13
|
const style = useCellSizes(props.cell);
|
|
15
14
|
return _jsx(BodyCellView, { ...props, style: style });
|
|
16
15
|
}
|
|
17
|
-
function DraggableBodyCell(props) {
|
|
18
|
-
const {
|
|
19
|
-
const style = useCellSizes(props.cell, { isDraggable: true,
|
|
20
|
-
return _jsx(BodyCellView, { ...props, style: style,
|
|
16
|
+
function DraggableBodyCell({ columnOrder, ...props }) {
|
|
17
|
+
const { transform, isDragging } = useColumnDragTransform(props.cell.column.id, columnOrder);
|
|
18
|
+
const style = useCellSizes(props.cell, { isDraggable: true, transform });
|
|
19
|
+
return _jsx(BodyCellView, { ...props, style: style, isDragging: isDragging });
|
|
21
20
|
}
|
|
22
|
-
export function BodyCell({ isDraggable, ...props }) {
|
|
23
|
-
if (isDraggable) {
|
|
24
|
-
return _jsx(DraggableBodyCell, { ...props });
|
|
21
|
+
export function BodyCell({ isDraggable, columnOrder, ...props }) {
|
|
22
|
+
if (isDraggable && columnOrder) {
|
|
23
|
+
return _jsx(DraggableBodyCell, { ...props, columnOrder: columnOrder });
|
|
25
24
|
}
|
|
26
25
|
return _jsx(StaticBodyCell, { ...props });
|
|
27
26
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useSortable } from '@dnd-kit/sortable';
|
|
3
|
+
import { DRAG_MODE, DragGhost } from '@cloud-ru/ds-drag-and-drop';
|
|
3
4
|
import { TruncateString } from '@cloud-ru/ds-truncate-string';
|
|
4
5
|
import { flexRender } from '@tanstack/react-table';
|
|
5
6
|
import cn from 'classnames';
|
|
@@ -20,8 +21,8 @@ export function HeaderCell({ header, pinPosition, className, rowAutoHeight, isDr
|
|
|
20
21
|
const columnSizingInfo = header.getContext().table.getState().columnSizingInfo;
|
|
21
22
|
const isSomeColumnResizing = columnSizingInfo.isResizingColumn;
|
|
22
23
|
const columnDef = header.column.columnDef;
|
|
23
|
-
const {
|
|
24
|
-
const style = useCellSizes(header, { isDraggable,
|
|
24
|
+
const { listeners, setNodeRef, isDragging, transform } = useSortable({ id: header.column.id });
|
|
25
|
+
const style = useCellSizes(header, { isDraggable, transform });
|
|
25
26
|
const sortingHandler = (e) => {
|
|
26
27
|
if (isSomeColumnResizing)
|
|
27
28
|
return;
|
|
@@ -32,12 +33,12 @@ export function HeaderCell({ header, pinPosition, className, rowAutoHeight, isDr
|
|
|
32
33
|
if (!isDraggable || DEFAULT_COLUMNS.includes(header.column.id)) {
|
|
33
34
|
return {};
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
-
}, [
|
|
37
|
-
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-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 => {
|
|
36
|
+
return listeners;
|
|
37
|
+
}, [header.column.id, isDraggable, listeners]);
|
|
38
|
+
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-header-id": header.id, "data-resizing": isResizing || undefined, "data-dragging": (isDraggable && isDragging) || undefined, "data-pin-position": pinPosition || undefined, "data-row-auto-height": rowAutoHeight || undefined, role: 'columnheader', className: cn(styles.tableHeaderCell, className, columnDef.headerClassName), ref: element => {
|
|
38
39
|
if (isDraggable) {
|
|
39
40
|
setNodeRef(element);
|
|
40
41
|
}
|
|
41
42
|
cellRef.current = element;
|
|
42
|
-
}, children: [_jsx(
|
|
43
|
+
}, children: [_jsx(DragGhost, { dragging: isDraggable && isDragging, mode: DRAG_MODE.Dynamic, className: styles.tableHeaderCellDragWrapper, ...draggableProps, children: _jsxs("div", { className: styles.tableHeaderCellMain, "data-align": columnDef.headerAlign || undefined, children: [columnDef.header && (_jsx("div", { className: styles.tableHeaderCellName, children: rowAutoHeight || typeof renderedHeader !== 'string' ? (renderedHeader) : (_jsx(TruncateString, { text: renderedHeader })) })), 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 })] }));
|
|
43
44
|
}
|
|
@@ -31,5 +31,5 @@ export function ResizeHandle({ header, cellRef }) {
|
|
|
31
31
|
resizeHandler(event);
|
|
32
32
|
};
|
|
33
33
|
const offset = isResizing ? getResizeIndicatorOffset({ header, cellRef }) : 0;
|
|
34
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", {
|
|
34
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { "aria-hidden": true, className: cn(styles.tableHeaderIcon, styles.tableHeaderResizeHandle), "data-resizing": isResizing || undefined, onMouseDown: handleMouseDown, onTouchStart: resizeHandler, onMouseUp: stopEventPropagation }), isResizing && (_jsx("div", { "data-test-id": TEST_IDS.headerResizeHandleMovingPart, className: styles.tableHeaderResizeIndicator, style: { '--offset': `${offset}px` } }))] }));
|
|
35
35
|
}
|
|
@@ -10,4 +10,7 @@
|
|
|
10
10
|
box-sizing:border-box;
|
|
11
11
|
width:100%;
|
|
12
12
|
background-color:transparent;
|
|
13
|
+
}
|
|
14
|
+
.tableCell[data-dragging]{
|
|
15
|
+
box-shadow:inset var(--sn-table-anatomy-content-tableLine-background-interaction-borderVerticalWidth, var(--sn-primitive-strokeWeight-strokeRegular, 1px)) 0 0 0 var(--sn-theme-color-available-borderColor, var(--sn-brand-color-state-neutralBorder-forLightMode-default-borderColor, rgba(159, 166, 198, 0.3019607843))), inset calc(-1 * var(--sn-table-anatomy-content-tableLine-background-interaction-borderVerticalWidth, var(--sn-primitive-strokeWeight-strokeRegular, 1px))) 0 0 0 var(--sn-theme-color-available-borderColor, var(--sn-brand-color-state-neutralBorder-forLightMode-default-borderColor, rgba(159, 166, 198, 0.3019607843)));
|
|
13
16
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable';
|
|
3
2
|
import { useState } from 'react';
|
|
4
3
|
import { RowAppearance } from '../../components/index.js';
|
|
5
4
|
import { COLUMN_PIN_POSITION, TEST_IDS } from '../../constants.js';
|
|
@@ -27,5 +26,5 @@ export function BodyRow({ row, onRowClick, rowAutoHeight, columnOrder, enableCol
|
|
|
27
26
|
};
|
|
28
27
|
const isSelected = row.getIsSelected() || (row.getIsSomeSelected() && !row.getCanMultiSelect() && !row.getIsExpanded());
|
|
29
28
|
const rowBackgroundColor = getRowBackgroundColor?.(row.original);
|
|
30
|
-
return (_jsx(RowContext.Provider, { value: { dropListOpened, setDropListOpen, disabledRowAppearance }, children: _jsxs(Row, { onClick: handleRowClick, clickable: Boolean(onRowClick) && !(disabled && disabledRowAppearance === RowAppearance.Disabled), "data-clickable": Boolean(onRowClick) || undefined, "data-disabled": disabled || undefined, "data-row-appearance": disabled ? disabledRowAppearance : undefined, "data-selected": isSelected || undefined, "data-actions-opened": dropListOpened || undefined, "data-test-id": TEST_IDS.bodyRow, "data-row-id": row.id, "data-row-bg-appearance": rowBackgroundColor && !disabled && !isSelected ? rowBackgroundColor : undefined, 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))) })), columnVirtualPadding && columnVirtualPadding.left > 0 && (_jsx("div", { "aria-hidden": true, style: { width: columnVirtualPadding.left, flexShrink: 0 } })),
|
|
29
|
+
return (_jsx(RowContext.Provider, { value: { dropListOpened, setDropListOpen, disabledRowAppearance }, children: _jsxs(Row, { onClick: handleRowClick, clickable: Boolean(onRowClick) && !(disabled && disabledRowAppearance === RowAppearance.Disabled), "data-clickable": Boolean(onRowClick) || undefined, "data-disabled": disabled || undefined, "data-row-appearance": disabled ? disabledRowAppearance : undefined, "data-selected": isSelected || undefined, "data-actions-opened": dropListOpened || undefined, "data-test-id": TEST_IDS.bodyRow, "data-row-id": row.id, "data-row-bg-appearance": rowBackgroundColor && !disabled && !isSelected ? rowBackgroundColor : undefined, 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))) })), columnVirtualPadding && columnVirtualPadding.left > 0 && (_jsx("div", { "aria-hidden": true, style: { width: columnVirtualPadding.left, flexShrink: 0 } })), unpinned.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight, isDraggable: enableColumnsOrderSortByDrag, columnOrder: columnOrder }, cell.id))), columnVirtualPadding && columnVirtualPadding.right > 0 && (_jsx("div", { "aria-hidden": true, style: { width: columnVirtualPadding.right, flexShrink: 0 } })), rightPinned && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: rightPinned.map(cell => (_jsx(BodyCell, { cell: cell, rowAutoHeight: rowAutoHeight, isDraggable: enableColumnsOrderSortByDrag }, cell.id))) }))] }) }));
|
|
31
30
|
}
|
|
@@ -43,6 +43,10 @@
|
|
|
43
43
|
width:var(--sn-table-anatomy-content-tableLine-background-interaction-borderVerticalWidth, var(--sn-primitive-strokeWeight-strokeRegular, 1px));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
.tableHeader .rowPinnedCells::after{
|
|
47
|
+
bottom:0;
|
|
48
|
+
}
|
|
49
|
+
|
|
46
50
|
.rowPinnedCells[data-position=left]{
|
|
47
51
|
left:0;
|
|
48
52
|
}
|
|
@@ -7,7 +7,6 @@ export function useEmptyState({ noDataState: noDataStateProp, noResultsState: no
|
|
|
7
7
|
const noDataState = {
|
|
8
8
|
icon: { icon: SearchSVG, appearance: 'neutral', background: true },
|
|
9
9
|
title: t('noData.title'),
|
|
10
|
-
content: t('noData.content'),
|
|
11
10
|
...noDataStateProp,
|
|
12
11
|
};
|
|
13
12
|
const noResultsState = {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
.tableEmptyStateWrapper{
|
|
2
|
+
position:sticky;
|
|
3
|
+
left:0;
|
|
2
4
|
display:flex;
|
|
3
5
|
flex:1 1 auto;
|
|
4
6
|
flex-direction:column;
|
|
5
7
|
align-items:center;
|
|
6
8
|
justify-content:center;
|
|
7
9
|
box-sizing:border-box;
|
|
8
|
-
width:100
|
|
10
|
+
width:var(--table-viewport-width, 100%);
|
|
9
11
|
min-height:304px;
|
|
10
12
|
padding:var(--sn-primitive-dimension-24, 24px);
|
|
11
13
|
}
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { Cell, Header } from '@tanstack/react-table';
|
|
|
3
3
|
import { CSSProperties } from 'react';
|
|
4
4
|
type CellSizesOptions = {
|
|
5
5
|
isDraggable?: boolean;
|
|
6
|
-
isDragging?: boolean;
|
|
7
6
|
transform?: Transform | null;
|
|
8
7
|
};
|
|
9
8
|
export declare function useCellSizes<TData>(element: Cell<TData, unknown> | Header<TData, unknown>, options?: CellSizesOptions): CSSProperties;
|
|
@@ -3,7 +3,6 @@ import { useMemo } from 'react';
|
|
|
3
3
|
import { TABLE_COLUMN_CSS_VARS } from '../constants.js';
|
|
4
4
|
export function useCellSizes(element, options) {
|
|
5
5
|
const column = element.column;
|
|
6
|
-
const isDragging = options?.isDragging ?? false;
|
|
7
6
|
const transform = options?.transform ?? null;
|
|
8
7
|
const minWidth = column.columnDef.minSize;
|
|
9
8
|
const maxWidth = column.columnDef.maxSize;
|
|
@@ -18,14 +17,12 @@ export function useCellSizes(element, options) {
|
|
|
18
17
|
flexShrink,
|
|
19
18
|
};
|
|
20
19
|
if (options?.isDraggable) {
|
|
21
|
-
styles.opacity = isDragging ? 0.8 : 1;
|
|
22
20
|
styles.position = 'relative';
|
|
23
21
|
styles.transform = CSS.Translate.toString(transform);
|
|
24
|
-
styles.zIndex = isDragging ? 1 : undefined;
|
|
25
22
|
if (isHeaderCell) {
|
|
26
23
|
styles.whiteSpace = 'nowrap';
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
return styles;
|
|
30
|
-
}, [options?.isDraggable, flexShrink,
|
|
27
|
+
}, [options?.isDraggable, flexShrink, isHeaderCell, maxWidth, minWidth, transform, width]);
|
|
31
28
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transform } from '@dnd-kit/utilities';
|
|
2
|
+
import { ColumnOrder } from '../types.js';
|
|
3
|
+
type ColumnDragState = {
|
|
4
|
+
transform: Transform | null;
|
|
5
|
+
isDragging: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
9
|
+
*
|
|
10
|
+
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
11
|
+
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
12
|
+
* драг переставал работать.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useColumnDragTransform(columnId: string, columnOrder: ColumnOrder): ColumnDragState;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useDndContext } from '@dnd-kit/core';
|
|
2
|
+
import { horizontalListSortingStrategy } from '@dnd-kit/sortable';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* Сдвиг ячейки тела за колонкой, которую тянут за шапку.
|
|
6
|
+
*
|
|
7
|
+
* Не `useSortable`: он зарегистрировал бы ячейку в реестре dnd-kit под id колонки — тем же, что у
|
|
8
|
+
* шапки. Реестр ключуется по id, поэтому размонтирование строк удаляло запись колонки целиком и
|
|
9
|
+
* драг переставал работать.
|
|
10
|
+
*/
|
|
11
|
+
export function useColumnDragTransform(columnId, columnOrder) {
|
|
12
|
+
const { active, over, activeNodeRect, droppableRects } = useDndContext();
|
|
13
|
+
const activeId = active ? String(active.id) : undefined;
|
|
14
|
+
const overId = over ? String(over.id) : undefined;
|
|
15
|
+
const transform = useMemo(() => {
|
|
16
|
+
if (!activeId) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const measured = columnOrder.filter(id => droppableRects.get(id));
|
|
20
|
+
const index = measured.indexOf(columnId);
|
|
21
|
+
const activeIndex = measured.indexOf(activeId);
|
|
22
|
+
if (index < 0 || activeIndex < 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const overIndex = overId ? measured.indexOf(overId) : -1;
|
|
26
|
+
return horizontalListSortingStrategy({
|
|
27
|
+
rects: measured.map(id => droppableRects.get(id)),
|
|
28
|
+
activeNodeRect,
|
|
29
|
+
activeIndex,
|
|
30
|
+
overIndex: overIndex < 0 ? activeIndex : overIndex,
|
|
31
|
+
index,
|
|
32
|
+
});
|
|
33
|
+
}, [activeId, overId, columnId, columnOrder, droppableRects, activeNodeRect]);
|
|
34
|
+
return { transform, isDragging: activeId === columnId };
|
|
35
|
+
}
|
|
@@ -13,7 +13,6 @@ declare const TABLE_MESSAGES: {
|
|
|
13
13
|
};
|
|
14
14
|
readonly noData: {
|
|
15
15
|
readonly title: "No data";
|
|
16
|
-
readonly content: "Try refreshing the page";
|
|
17
16
|
};
|
|
18
17
|
readonly noResults: {
|
|
19
18
|
readonly title: "Nothing found";
|
|
@@ -38,7 +37,6 @@ declare const TABLE_MESSAGES: {
|
|
|
38
37
|
};
|
|
39
38
|
readonly noData: {
|
|
40
39
|
readonly title: "Нет данных";
|
|
41
|
-
readonly content: "Обновите страницу";
|
|
42
40
|
};
|
|
43
41
|
readonly noResults: {
|
|
44
42
|
readonly title: "Ничего не найдено";
|
|
@@ -67,7 +65,6 @@ export declare const tableLocale: import("@cloud-ru/ds-locale").DefinedLocale<{
|
|
|
67
65
|
};
|
|
68
66
|
readonly noData: {
|
|
69
67
|
readonly title: "No data";
|
|
70
|
-
readonly content: "Try refreshing the page";
|
|
71
68
|
};
|
|
72
69
|
readonly noResults: {
|
|
73
70
|
readonly title: "Nothing found";
|
|
@@ -92,7 +89,6 @@ export declare const tableLocale: import("@cloud-ru/ds-locale").DefinedLocale<{
|
|
|
92
89
|
};
|
|
93
90
|
readonly noData: {
|
|
94
91
|
readonly title: "Нет данных";
|
|
95
|
-
readonly content: "Обновите страницу";
|
|
96
92
|
};
|
|
97
93
|
readonly noResults: {
|
|
98
94
|
readonly title: "Ничего не найдено";
|
package/dist/esm/locale/index.js
CHANGED
|
@@ -14,7 +14,6 @@ const TABLE_MESSAGES = defineMessages({
|
|
|
14
14
|
},
|
|
15
15
|
noData: {
|
|
16
16
|
title: 'No data',
|
|
17
|
-
content: 'Try refreshing the page',
|
|
18
17
|
},
|
|
19
18
|
noResults: {
|
|
20
19
|
title: 'Nothing found',
|
|
@@ -39,7 +38,6 @@ const TABLE_MESSAGES = defineMessages({
|
|
|
39
38
|
},
|
|
40
39
|
noData: {
|
|
41
40
|
title: 'Нет данных',
|
|
42
|
-
content: 'Обновите страницу',
|
|
43
41
|
},
|
|
44
42
|
noResults: {
|
|
45
43
|
title: 'Ничего не найдено',
|
package/dist/esm/style.css
CHANGED
|
@@ -442,7 +442,8 @@
|
|
|
442
442
|
flex:1 1 auto;
|
|
443
443
|
flex-direction:column;
|
|
444
444
|
width:100%;
|
|
445
|
-
min-width
|
|
445
|
+
min-width:-moz-max-content;
|
|
446
|
+
min-width:max-content;
|
|
446
447
|
min-height:100%;
|
|
447
448
|
}
|
|
448
449
|
|
|
@@ -576,6 +577,23 @@
|
|
|
576
577
|
width:100%;
|
|
577
578
|
max-width:100%;
|
|
578
579
|
}
|
|
580
|
+
|
|
581
|
+
.columnDragPreview{
|
|
582
|
+
display:flex;
|
|
583
|
+
align-items:center;
|
|
584
|
+
box-sizing:border-box;
|
|
585
|
+
height:var(--sn-table-anatomy-content-tableCell-minHeight, var(--sn-primitive-dimension-40, 40px));
|
|
586
|
+
padding:var(--sn-table-anatomy-content-tableHead-paddingTop, var(--sn-primitive-dimension-6, 6px)) var(--sn-table-anatomy-content-tableHead-paddingRight, var(--sn-primitive-dimension-12, 12px)) var(--sn-table-anatomy-content-tableHead-paddingBottom, var(--sn-primitive-dimension-6, 6px)) var(--sn-table-anatomy-content-tableHead-paddingLeft, var(--sn-primitive-dimension-12, 12px));
|
|
587
|
+
border-radius:var(--sn-table-anatomy-content-borderRadius, var(--sn-brand-anatomy-radius-table-m, var(--sn-primitive-dimension-4, 4px)));
|
|
588
|
+
color:var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078)));
|
|
589
|
+
white-space:nowrap;
|
|
590
|
+
font-family:var(--sn-regular-body-m-fontFamily, var(--sn-brand-font-fontFamily-regular-body, var(--sn-primitive-fontFamily-brandA-sans, SB Sans Interface)));
|
|
591
|
+
font-weight:var(--sn-regular-body-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-m, var(--sn-brand-font-fontWeight-light-regular-body-m, var(--sn-primitive-font-fontWeightValue-400, 400))));
|
|
592
|
+
line-height:var(--sn-regular-body-m-lineHeight, var(--sn-density-typography-roleBody-lineHeightM, var(--sn-primitive-font-lineHeight-by16, 24px)));
|
|
593
|
+
font-size:var(--sn-regular-body-m-fontSize, var(--sn-density-typography-roleBody-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px)));
|
|
594
|
+
letter-spacing:var(--sn-regular-body-m-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
|
|
595
|
+
paragraph-spacing:var(--sn-regular-body-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize14, 7px));
|
|
596
|
+
}
|
|
579
597
|
.tableBodyCell{
|
|
580
598
|
gap:var(--sn-table-anatomy-content-tableCell-contentWrapper-slot-gap, var(--sn-primitive-dimension-2, 2px));
|
|
581
599
|
padding:calc(var(--sn-table-anatomy-content-tableCell-paddingTop, var(--sn-primitive-dimension-6, 6px)) + var(--sn-table-anatomy-content-tableCell-contentWrapper-paddingTop, var(--sn-primitive-dimension-2, 2px))) var(--sn-table-anatomy-content-tableCell-paddingRight, var(--sn-primitive-dimension-12, 12px)) calc(var(--sn-table-anatomy-content-tableCell-paddingBottom, var(--sn-primitive-dimension-6, 6px)) + var(--sn-table-anatomy-content-tableCell-contentWrapper-paddingBottom, var(--sn-primitive-dimension-2, 2px))) var(--sn-table-anatomy-content-tableCell-paddingLeft, var(--sn-primitive-dimension-12, 12px));
|
|
@@ -1005,6 +1023,9 @@
|
|
|
1005
1023
|
width:100%;
|
|
1006
1024
|
background-color:transparent;
|
|
1007
1025
|
}
|
|
1026
|
+
.tableCell[data-dragging]{
|
|
1027
|
+
box-shadow:inset var(--sn-table-anatomy-content-tableLine-background-interaction-borderVerticalWidth, var(--sn-primitive-strokeWeight-strokeRegular, 1px)) 0 0 0 var(--sn-theme-color-available-borderColor, var(--sn-brand-color-state-neutralBorder-forLightMode-default-borderColor, rgba(159, 166, 198, 0.3019607843))), inset calc(-1 * var(--sn-table-anatomy-content-tableLine-background-interaction-borderVerticalWidth, var(--sn-primitive-strokeWeight-strokeRegular, 1px))) 0 0 0 var(--sn-theme-color-available-borderColor, var(--sn-brand-color-state-neutralBorder-forLightMode-default-borderColor, rgba(159, 166, 198, 0.3019607843)));
|
|
1028
|
+
}
|
|
1008
1029
|
@charset "UTF-8";
|
|
1009
1030
|
.surface{
|
|
1010
1031
|
isolation:isolate;
|
|
@@ -1277,6 +1298,10 @@
|
|
|
1277
1298
|
width:var(--sn-table-anatomy-content-tableLine-background-interaction-borderVerticalWidth, var(--sn-primitive-strokeWeight-strokeRegular, 1px));
|
|
1278
1299
|
}
|
|
1279
1300
|
|
|
1301
|
+
.tableHeader .rowPinnedCells::after{
|
|
1302
|
+
bottom:0;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1280
1305
|
.rowPinnedCells[data-position=left]{
|
|
1281
1306
|
left:0;
|
|
1282
1307
|
}
|
|
@@ -1525,13 +1550,15 @@
|
|
|
1525
1550
|
padding:0;
|
|
1526
1551
|
}
|
|
1527
1552
|
.tableEmptyStateWrapper{
|
|
1553
|
+
position:sticky;
|
|
1554
|
+
left:0;
|
|
1528
1555
|
display:flex;
|
|
1529
1556
|
flex:1 1 auto;
|
|
1530
1557
|
flex-direction:column;
|
|
1531
1558
|
align-items:center;
|
|
1532
1559
|
justify-content:center;
|
|
1533
1560
|
box-sizing:border-box;
|
|
1534
|
-
width:100
|
|
1561
|
+
width:var(--table-viewport-width, 100%);
|
|
1535
1562
|
min-height:304px;
|
|
1536
1563
|
padding:var(--sn-primitive-dimension-24, 24px);
|
|
1537
1564
|
}
|
package/dist/esm/types.d.ts
CHANGED