@snack-uikit/table 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/components/Table/Table.js +2 -1
- package/dist/components/Table/styles.module.css +4 -0
- package/dist/helperComponents/Cells/RowActionsCell/RowActionsCell.d.ts +1 -0
- package/dist/helperComponents/Cells/RowActionsCell/RowActionsCell.js +3 -1
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/Table/Table.tsx +2 -1
- package/src/components/Table/styles.module.scss +4 -0
- package/src/helperComponents/Cells/RowActionsCell/RowActionsCell.tsx +5 -2
- package/src/types.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.8.5 (2023-12-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-4014:** fix infinite width without limits & export some types ([4dc82d3](https://github.com/cloud-ru-tech/snack-uikit/commit/4dc82d334f1cbb0b604d31687e60cfe338c4e679))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.8.4 (2023-12-25)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -11,6 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
13
|
import { getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from '@tanstack/react-table';
|
|
14
|
+
import cn from 'classnames';
|
|
14
15
|
import { useCallback, useMemo } from 'react';
|
|
15
16
|
import { Scroll } from '@snack-uikit/scroll';
|
|
16
17
|
import { SkeletonContextProvider } from '@snack-uikit/skeleton';
|
|
@@ -113,7 +114,7 @@ export function Table(_a) {
|
|
|
113
114
|
const tableRows = table.getRowModel().rows;
|
|
114
115
|
const loadingTableRows = loadingTable.getRowModel().rows;
|
|
115
116
|
const tablePagination = table.getState().pagination;
|
|
116
|
-
return (_jsx(_Fragment, { children: _jsxs("div", Object.assign({ style: { '--page-size': !suppressPagination ? tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize : pageSize }, className: className }, extractSupportProps(rest), { children: [!suppressToolbar && (_jsxs("div", { className: styles.header, children: [_jsx(Toolbar, { value: globalFilter, onChange: onGlobalFilterChange, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), className: styles.toolbar, onRefresh: onRefresh ? handleOnRefresh : undefined, onDelete: enableSelection && onDelete ? handleOnDelete : undefined, onCheck: enableSelection ? handleOnCheck : undefined, outline: outline, loading: search === null || search === void 0 ? void 0 : search.loading, placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || 'Search', selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', actions: exportFileName ? (_jsx(ExportButton, { fileName: exportFileName, columnDefinitions: columnDefinitions, data: data })) : undefined, moreActions: moreActions }), columnFiltersProp && _jsxs("div", { className: styles.filtersWrapper, children: [" ", columnFiltersProp, " "] })] })), _jsx("div", { className: styles.scrollWrapper, "data-outline": outline || undefined, children: _jsx(Scroll, { size: 's', className: styles.table, children: _jsx("div", { className: styles.tableContent, children: _jsx(TableContext.Provider, { value: { table }, children: loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, {}), loadingTableRows.map(row => (_jsx(BodyRow, { row: row }, row.id)))] })) : (_jsxs(_Fragment, { children: [tableRows.length ? _jsx(HeaderRow, {}) : null, tableRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick }, row.id))), !tableRows.length && globalFilter && _jsx(TableEmptyState, Object.assign({}, noResultsState)), !tableRows.length && !globalFilter && _jsx(TableEmptyState, Object.assign({}, noDataState))] })) }) }) }) }), !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 }))] })) }));
|
|
117
|
+
return (_jsx(_Fragment, { children: _jsxs("div", Object.assign({ style: { '--page-size': !suppressPagination ? tablePagination === null || tablePagination === void 0 ? void 0 : tablePagination.pageSize : pageSize }, className: cn(styles.wrapper, className) }, extractSupportProps(rest), { children: [!suppressToolbar && (_jsxs("div", { className: styles.header, children: [_jsx(Toolbar, { value: globalFilter, onChange: onGlobalFilterChange, checked: table.getIsAllPageRowsSelected(), indeterminate: table.getIsSomePageRowsSelected(), className: styles.toolbar, onRefresh: onRefresh ? handleOnRefresh : undefined, onDelete: enableSelection && onDelete ? handleOnDelete : undefined, onCheck: enableSelection ? handleOnCheck : undefined, outline: outline, loading: search === null || search === void 0 ? void 0 : search.loading, placeholder: (search === null || search === void 0 ? void 0 : search.placeholder) || 'Search', selectionMode: (rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow) ? 'multiple' : 'single', actions: exportFileName ? (_jsx(ExportButton, { fileName: exportFileName, columnDefinitions: columnDefinitions, data: data })) : undefined, moreActions: moreActions }), columnFiltersProp && _jsxs("div", { className: styles.filtersWrapper, children: [" ", columnFiltersProp, " "] })] })), _jsx("div", { className: styles.scrollWrapper, "data-outline": outline || undefined, children: _jsx(Scroll, { size: 's', className: styles.table, children: _jsx("div", { className: styles.tableContent, children: _jsx(TableContext.Provider, { value: { table }, children: loading ? (_jsxs(SkeletonContextProvider, { loading: true, children: [_jsx(HeaderRow, {}), loadingTableRows.map(row => (_jsx(BodyRow, { row: row }, row.id)))] })) : (_jsxs(_Fragment, { children: [tableRows.length ? _jsx(HeaderRow, {}) : null, tableRows.map(row => (_jsx(BodyRow, { row: row, onRowClick: onRowClick }, row.id))), !tableRows.length && globalFilter && _jsx(TableEmptyState, Object.assign({}, noResultsState)), !tableRows.length && !globalFilter && _jsx(TableEmptyState, Object.assign({}, noDataState))] })) }) }) }) }), !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 }))] })) }));
|
|
117
118
|
}
|
|
118
119
|
Table.getStatusColumnDef = getStatusColumnDef;
|
|
119
120
|
Table.statusAppearances = STATUS_APPEARANCE;
|
|
@@ -9,6 +9,7 @@ export type RowActionInfo<TData> = {
|
|
|
9
9
|
};
|
|
10
10
|
export type RowActionProps<TData> = Pick<ItemSingleProps, 'option' | 'disabled' | 'icon' | 'description' | 'caption' | 'tagLabel'> & {
|
|
11
11
|
id?: string;
|
|
12
|
+
hidden?: boolean;
|
|
12
13
|
onClick(row: RowActionInfo<TData>, e: MouseEvent<HTMLButtonElement>): void;
|
|
13
14
|
};
|
|
14
15
|
export type ActionsGenerator<TData> = (cell: CellContext<TData, unknown>) => RowActionProps<TData>[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as _createElement } from "react";
|
|
3
|
+
import { useMemo } from 'react';
|
|
3
4
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
4
5
|
import { Droplist } from '@snack-uikit/droplist';
|
|
5
6
|
import { MoreSVG } from '@snack-uikit/icons';
|
|
@@ -16,9 +17,10 @@ function RowActionsCell({ row, actions }) {
|
|
|
16
17
|
const stopPropagationClick = (e) => {
|
|
17
18
|
e.stopPropagation();
|
|
18
19
|
};
|
|
20
|
+
const visibleActions = useMemo(() => actions.filter(item => !(item === null || item === void 0 ? void 0 : item.hidden)), [actions]);
|
|
19
21
|
return (
|
|
20
22
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
21
|
-
_jsx("div", { onClick: stopPropagationClick, className: styles.rowActionsCellWrap, "data-open": droplistOpened || undefined, children: !disabled && Boolean(
|
|
23
|
+
_jsx("div", { onClick: stopPropagationClick, className: styles.rowActionsCellWrap, "data-open": droplistOpened || undefined, children: !disabled && Boolean(visibleActions.length) && (_jsx(Droplist, { open: droplistOpened, onOpenChange: setDroplistOpen, placement: 'bottom-end', firstElementRefCallback: firstElementRefCallback, onFocusLeave: handleDroplistFocusLeave, triggerElement: _jsx("span", { children: _jsx(ButtonFunction, { icon: _jsx(MoreSVG, { size: 24 }), "data-test-id": TEST_IDS.rowActions.droplistTrigger, onKeyDown: handleTriggerKeyDown, ref: triggerElementRef }) }), triggerClassName: styles.rowActionsCellTrigger, size: 's', "data-test-id": TEST_IDS.rowActions.droplist, children: actions.map(item => (_createElement(Droplist.ItemSingle, Object.assign({}, item, { key: `${row.id}-${item.id || item.option}`, onClick: e => handleDroplistItemClick(e, handleItemClick(item)), "data-test-id": TEST_IDS.rowActions.option, onKeyDown: handleDroplistItemKeyDown })))) })) }));
|
|
22
24
|
}
|
|
23
25
|
/** Вспомогательная функция для создания ячейки с дополнительными действиями у строки */
|
|
24
26
|
export function getRowActionsColumnDef({ actionsGenerator, pinned, }) {
|
package/dist/types.d.ts
CHANGED
|
@@ -37,5 +37,5 @@ type PinnedColumnDefinition<TData> = BaseColumnDefinition<TData> & {
|
|
|
37
37
|
size: number;
|
|
38
38
|
};
|
|
39
39
|
export type ColumnDefinition<TData> = NormalColumnDefinition<TData> | PinnedColumnDefinition<TData>;
|
|
40
|
-
export type { RowActionInfo, RowActionProps, RowActionsColumnDefProps, StatusColumnDefinitionProps, RowInfo, RowClickHandler, } from './helperComponents';
|
|
40
|
+
export type { RowActionInfo, RowActionProps, RowActionsColumnDefProps, StatusColumnDefinitionProps, RowInfo, RowClickHandler, ActionsGenerator, } from './helperComponents';
|
|
41
41
|
export type { PaginationState, SortingState, RowSelectionState, RowSelectionOptions, TableEmptyStateProps, ToolbarProps, HeaderContext, CellContext, };
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Table",
|
|
7
|
-
"version": "0.8.
|
|
7
|
+
"version": "0.8.5",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"uncontrollable": "8.0.0",
|
|
56
56
|
"xlsx": "file:vendor/xlsx-0.20.1.tgz"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "d37c0e8836f2c384fb4044cca33450359a4d940e"
|
|
59
59
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
SortingState,
|
|
12
12
|
useReactTable,
|
|
13
13
|
} from '@tanstack/react-table';
|
|
14
|
+
import cn from 'classnames';
|
|
14
15
|
import { ReactNode, useCallback, useMemo } from 'react';
|
|
15
16
|
|
|
16
17
|
import { Scroll } from '@snack-uikit/scroll';
|
|
@@ -303,7 +304,7 @@ export function Table<TData extends object>({
|
|
|
303
304
|
<>
|
|
304
305
|
<div
|
|
305
306
|
style={{ '--page-size': !suppressPagination ? tablePagination?.pageSize : pageSize }}
|
|
306
|
-
className={className}
|
|
307
|
+
className={cn(styles.wrapper, className)}
|
|
307
308
|
{...extractSupportProps(rest)}
|
|
308
309
|
>
|
|
309
310
|
{!suppressToolbar && (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CellContext, Row } from '@tanstack/react-table';
|
|
2
|
-
import { MouseEvent } from 'react';
|
|
2
|
+
import { MouseEvent, useMemo } from 'react';
|
|
3
3
|
|
|
4
4
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
5
5
|
import { Droplist, ItemSingleProps } from '@snack-uikit/droplist';
|
|
@@ -21,6 +21,7 @@ export type RowActionProps<TData> = Pick<
|
|
|
21
21
|
'option' | 'disabled' | 'icon' | 'description' | 'caption' | 'tagLabel'
|
|
22
22
|
> & {
|
|
23
23
|
id?: string;
|
|
24
|
+
hidden?: boolean;
|
|
24
25
|
onClick(row: RowActionInfo<TData>, e: MouseEvent<HTMLButtonElement>): void;
|
|
25
26
|
};
|
|
26
27
|
|
|
@@ -51,10 +52,12 @@ function RowActionsCell<TData>({ row, actions }: RowActionsCellProps<TData>) {
|
|
|
51
52
|
e.stopPropagation();
|
|
52
53
|
};
|
|
53
54
|
|
|
55
|
+
const visibleActions: RowActionProps<TData>[] = useMemo(() => actions.filter(item => !item?.hidden), [actions]);
|
|
56
|
+
|
|
54
57
|
return (
|
|
55
58
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
56
59
|
<div onClick={stopPropagationClick} className={styles.rowActionsCellWrap} data-open={droplistOpened || undefined}>
|
|
57
|
-
{!disabled && Boolean(
|
|
60
|
+
{!disabled && Boolean(visibleActions.length) && (
|
|
58
61
|
<Droplist
|
|
59
62
|
open={droplistOpened}
|
|
60
63
|
onOpenChange={setDroplistOpen}
|