@snack-uikit/table 0.10.2 → 0.11.1
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 +21 -0
- package/README.md +1 -1
- package/dist/helperComponents/Cells/RowActionsCell/RowActionsCell.d.ts +5 -3
- package/dist/helperComponents/Cells/RowActionsCell/RowActionsCell.js +16 -5
- package/dist/helperComponents/ExportButton/ExportButton.js +7 -9
- package/package.json +6 -5
- package/src/helperComponents/Cells/RowActionsCell/RowActionsCell.tsx +27 -36
- package/src/helperComponents/ExportButton/ExportButton.tsx +11 -30
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
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.11.1 (2024-01-30)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/list@0.1.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
|
|
10
|
+
* [@snack-uikit/toolbar@0.7.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/toolbar/CHANGELOG.md)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# 0.11.0 (2024-01-30)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### BREAKING CHANGES
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
* **FF-4075:** change usage droplist to list package ([4ce6391](https://github.com/cloud-ru-tech/snack-uikit/commit/4ce63915e838a46a3776e8e21393695a37d2fdd3))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
6
27
|
## 0.10.2 (2024-01-23)
|
|
7
28
|
|
|
8
29
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
|
|
|
119
119
|
| outline | `boolean` | - | Внешний бордер для тулбара и таблицы |
|
|
120
120
|
| columnFilters | `ReactNode` | - | Фильтры |
|
|
121
121
|
| exportFileName | `string` | - | Название файла при экспорте CSV/XLSX |
|
|
122
|
-
| moreActions | `
|
|
122
|
+
| moreActions | `Action[]` | - | Элементы выпадающего списка кнопки с действиями |
|
|
123
123
|
| noDataState | `TableEmptyStateProps` | { icon: CrossSVG, appearance: 'red', title: 'Data collection error', description: 'Try refreshing the page', } as const | Экран при отстутствии данных |
|
|
124
124
|
| noResultsState | `TableEmptyStateProps` | { icon: SearchSVG, appearance: 'neutral', title: 'Not found', description: 'Try entering another query', } as const | Экран при отстутствии результатов поиска |
|
|
125
125
|
| suppressToolbar | `boolean` | - | Отключение тулбара |
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { CellContext } from '@tanstack/react-table';
|
|
2
|
-
import { MouseEvent } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import { MouseEvent, ReactElement } from 'react';
|
|
3
|
+
import { BaseItemProps } from '@snack-uikit/list';
|
|
4
4
|
import { ColumnDefinition } from '../../../types';
|
|
5
5
|
export type RowActionInfo<TData> = {
|
|
6
6
|
rowId: string;
|
|
7
7
|
data: TData;
|
|
8
8
|
itemId?: string;
|
|
9
9
|
};
|
|
10
|
-
export type RowActionProps<TData> = Pick<
|
|
10
|
+
export type RowActionProps<TData> = Pick<BaseItemProps, 'content' | 'disabled'> & {
|
|
11
|
+
icon?: ReactElement;
|
|
12
|
+
tagLabel?: string;
|
|
11
13
|
id?: string;
|
|
12
14
|
hidden?: boolean;
|
|
13
15
|
onClick(row: RowActionInfo<TData>, e: MouseEvent<HTMLButtonElement>): void;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useMemo } from 'react';
|
|
2
|
+
import { useMemo, useRef } from 'react';
|
|
4
3
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
5
|
-
import { Droplist } from '@snack-uikit/droplist';
|
|
6
4
|
import { MoreSVG } from '@snack-uikit/icons';
|
|
5
|
+
import { Droplist } from '@snack-uikit/list';
|
|
6
|
+
import { Tag } from '@snack-uikit/tag';
|
|
7
7
|
import { COLUMN_PIN_POSITION, TEST_IDS } from '../../../constants';
|
|
8
8
|
import { useRowContext } from '../../contexts';
|
|
9
9
|
import styles from './styles.module.css';
|
|
10
10
|
function RowActionsCell({ row, actions }) {
|
|
11
11
|
const { droplistOpened, setDroplistOpen } = useRowContext();
|
|
12
|
-
const
|
|
12
|
+
const triggerRef = useRef(null);
|
|
13
13
|
const handleItemClick = (item) => (e) => {
|
|
14
14
|
item.onClick({ rowId: row.id, itemId: item.id, data: row.original }, e);
|
|
15
15
|
};
|
|
@@ -20,7 +20,18 @@ function RowActionsCell({ row, actions }) {
|
|
|
20
20
|
const visibleActions = useMemo(() => actions.filter(item => !(item === null || item === void 0 ? void 0 : item.hidden)), [actions]);
|
|
21
21
|
return (
|
|
22
22
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
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',
|
|
23
|
+
_jsx("div", { onClick: stopPropagationClick, className: styles.rowActionsCellWrap, "data-open": droplistOpened || undefined, children: !disabled && Boolean(visibleActions.length) && (_jsx(Droplist, { trigger: 'clickAndFocusVisible', open: droplistOpened, onOpenChange: setDroplistOpen, placement: 'bottom-end', size: 'm', "data-test-id": TEST_IDS.rowActions.droplist, triggerElemRef: triggerRef, items: actions.map(item => ({
|
|
24
|
+
id: item.id,
|
|
25
|
+
onClick: e => {
|
|
26
|
+
handleItemClick(item)(e);
|
|
27
|
+
setDroplistOpen(false);
|
|
28
|
+
},
|
|
29
|
+
disabled: item.disabled,
|
|
30
|
+
content: item.content,
|
|
31
|
+
beforeContent: item.icon,
|
|
32
|
+
afterContent: item.tagLabel ? _jsx(Tag, { label: item.tagLabel }) : undefined,
|
|
33
|
+
'data-test-id': TEST_IDS.rowActions.option,
|
|
34
|
+
})), children: _jsx("span", { className: styles.rowActionsCellTrigger, children: _jsx(ButtonFunction, { icon: _jsx(MoreSVG, { size: 24 }), "data-test-id": TEST_IDS.rowActions.droplistTrigger, ref: triggerRef }) }) })) }));
|
|
24
35
|
}
|
|
25
36
|
/** Вспомогательная функция для создания ячейки с дополнительными действиями у строки */
|
|
26
37
|
export function getRowActionsColumnDef({ actionsGenerator, pinned, }) {
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
4
|
-
import { Droplist } from '@snack-uikit/droplist';
|
|
5
4
|
import { DownloadSVG } from '@snack-uikit/icons';
|
|
5
|
+
import { Droplist } from '@snack-uikit/list';
|
|
6
6
|
import { exportToCSV, exportToXLSX } from '../../exportTable';
|
|
7
7
|
export function ExportButton({ fileName, data, columnDefinitions }) {
|
|
8
8
|
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
-
|
|
10
|
-
return (_jsx(Droplist, { firstElementRefCallback: firstElementRefCallback, triggerRef: triggerElementRef, onFocusLeave: handleDroplistFocusLeave, open: isOpen, onOpenChange: setIsOpen, useScroll: true, placement: 'bottom-end', triggerElement: _jsx(ButtonFunction, { size: 'm', onKeyDown: handleTriggerKeyDown, icon: _jsx(DownloadSVG, {}) }), children: [
|
|
9
|
+
return (_jsx(Droplist, { trigger: 'clickAndFocusVisible', open: isOpen, onOpenChange: setIsOpen, scroll: true, placement: 'bottom-end', items: [
|
|
11
10
|
{
|
|
12
|
-
option: 'Export to CSV',
|
|
11
|
+
content: { option: 'Export to CSV' },
|
|
13
12
|
onClick: () => {
|
|
14
13
|
exportToCSV({ fileName, columnDefinitions, data });
|
|
14
|
+
setIsOpen(false);
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
option: 'Export to XLSX',
|
|
18
|
+
content: { option: 'Export to XLSX' },
|
|
19
19
|
onClick: () => {
|
|
20
20
|
exportToXLSX({ fileName, columnDefinitions, data });
|
|
21
|
+
setIsOpen(false);
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
|
-
]
|
|
24
|
-
handleDroplistItemClick(e);
|
|
25
|
-
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
26
|
-
} }, option))) }));
|
|
24
|
+
], children: _jsx(ButtonFunction, { size: 'm', icon: _jsx(DownloadSVG, {}) }) }));
|
|
27
25
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Table",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.11.1",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -33,15 +33,16 @@
|
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/button": "0.15.1",
|
|
36
|
-
"@snack-uikit/chips": "0.10.
|
|
37
|
-
"@snack-uikit/droplist": "0.12.5",
|
|
36
|
+
"@snack-uikit/chips": "0.10.6",
|
|
38
37
|
"@snack-uikit/icon-predefined": "0.4.1",
|
|
39
38
|
"@snack-uikit/icons": "0.20.0",
|
|
39
|
+
"@snack-uikit/list": "0.1.1",
|
|
40
40
|
"@snack-uikit/pagination": "0.6.1",
|
|
41
41
|
"@snack-uikit/scroll": "0.5.0",
|
|
42
42
|
"@snack-uikit/skeleton": "0.3.2",
|
|
43
|
+
"@snack-uikit/tag": "0.6.4",
|
|
43
44
|
"@snack-uikit/toggles": "0.9.4",
|
|
44
|
-
"@snack-uikit/toolbar": "0.
|
|
45
|
+
"@snack-uikit/toolbar": "0.7.1",
|
|
45
46
|
"@snack-uikit/truncate-string": "0.4.5",
|
|
46
47
|
"@snack-uikit/typography": "0.6.1",
|
|
47
48
|
"@snack-uikit/utils": "3.2.0",
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"uncontrollable": "8.0.0",
|
|
52
53
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "54873fdb2f34f26a771f62568d3d6fcd62ea1694"
|
|
55
56
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CellContext, Row } from '@tanstack/react-table';
|
|
2
|
-
import { MouseEvent, useMemo } from 'react';
|
|
2
|
+
import { MouseEvent, ReactElement, useMemo, useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
5
|
-
import { Droplist, ItemSingleProps } from '@snack-uikit/droplist';
|
|
6
5
|
import { MoreSVG } from '@snack-uikit/icons';
|
|
6
|
+
import { BaseItemProps, Droplist } from '@snack-uikit/list';
|
|
7
|
+
import { Tag } from '@snack-uikit/tag';
|
|
7
8
|
|
|
8
9
|
import { COLUMN_PIN_POSITION, TEST_IDS } from '../../../constants';
|
|
9
10
|
import { ColumnDefinition } from '../../../types';
|
|
@@ -16,10 +17,9 @@ export type RowActionInfo<TData> = {
|
|
|
16
17
|
itemId?: string;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export type RowActionProps<TData> = Pick<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
> & {
|
|
20
|
+
export type RowActionProps<TData> = Pick<BaseItemProps, 'content' | 'disabled'> & {
|
|
21
|
+
icon?: ReactElement;
|
|
22
|
+
tagLabel?: string;
|
|
23
23
|
id?: string;
|
|
24
24
|
hidden?: boolean;
|
|
25
25
|
onClick(row: RowActionInfo<TData>, e: MouseEvent<HTMLButtonElement>): void;
|
|
@@ -32,15 +32,7 @@ type RowActionsCellProps<TData> = {
|
|
|
32
32
|
|
|
33
33
|
function RowActionsCell<TData>({ row, actions }: RowActionsCellProps<TData>) {
|
|
34
34
|
const { droplistOpened, setDroplistOpen } = useRowContext();
|
|
35
|
-
|
|
36
|
-
const {
|
|
37
|
-
triggerElementRef,
|
|
38
|
-
handleDroplistFocusLeave,
|
|
39
|
-
handleDroplistItemKeyDown,
|
|
40
|
-
handleTriggerKeyDown,
|
|
41
|
-
handleDroplistItemClick,
|
|
42
|
-
firstElementRefCallback,
|
|
43
|
-
} = Droplist.useKeyboardNavigation<HTMLButtonElement>({ setDroplistOpen });
|
|
35
|
+
const triggerRef = useRef(null);
|
|
44
36
|
|
|
45
37
|
const handleItemClick = (item: RowActionProps<TData>) => (e: MouseEvent<HTMLButtonElement>) => {
|
|
46
38
|
item.onClick({ rowId: row.id, itemId: item.id, data: row.original }, e);
|
|
@@ -59,34 +51,33 @@ function RowActionsCell<TData>({ row, actions }: RowActionsCellProps<TData>) {
|
|
|
59
51
|
<div onClick={stopPropagationClick} className={styles.rowActionsCellWrap} data-open={droplistOpened || undefined}>
|
|
60
52
|
{!disabled && Boolean(visibleActions.length) && (
|
|
61
53
|
<Droplist
|
|
54
|
+
trigger='clickAndFocusVisible'
|
|
62
55
|
open={droplistOpened}
|
|
63
56
|
onOpenChange={setDroplistOpen}
|
|
64
57
|
placement='bottom-end'
|
|
65
|
-
firstElementRefCallback={firstElementRefCallback}
|
|
66
|
-
onFocusLeave={handleDroplistFocusLeave}
|
|
67
|
-
triggerElement={
|
|
68
|
-
<span>
|
|
69
|
-
<ButtonFunction
|
|
70
|
-
icon={<MoreSVG size={24} />}
|
|
71
|
-
data-test-id={TEST_IDS.rowActions.droplistTrigger}
|
|
72
|
-
onKeyDown={handleTriggerKeyDown}
|
|
73
|
-
ref={triggerElementRef}
|
|
74
|
-
/>
|
|
75
|
-
</span>
|
|
76
|
-
}
|
|
77
|
-
triggerClassName={styles.rowActionsCellTrigger}
|
|
78
58
|
size='m'
|
|
79
59
|
data-test-id={TEST_IDS.rowActions.droplist}
|
|
60
|
+
triggerElemRef={triggerRef}
|
|
61
|
+
items={actions.map(item => ({
|
|
62
|
+
id: item.id,
|
|
63
|
+
onClick: e => {
|
|
64
|
+
handleItemClick(item)(e);
|
|
65
|
+
setDroplistOpen(false);
|
|
66
|
+
},
|
|
67
|
+
disabled: item.disabled,
|
|
68
|
+
content: item.content,
|
|
69
|
+
beforeContent: item.icon,
|
|
70
|
+
afterContent: item.tagLabel ? <Tag label={item.tagLabel} /> : undefined,
|
|
71
|
+
'data-test-id': TEST_IDS.rowActions.option,
|
|
72
|
+
}))}
|
|
80
73
|
>
|
|
81
|
-
{
|
|
82
|
-
<
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
data-test-id={TEST_IDS.rowActions.option}
|
|
87
|
-
onKeyDown={handleDroplistItemKeyDown}
|
|
74
|
+
<span className={styles.rowActionsCellTrigger}>
|
|
75
|
+
<ButtonFunction
|
|
76
|
+
icon={<MoreSVG size={24} />}
|
|
77
|
+
data-test-id={TEST_IDS.rowActions.droplistTrigger}
|
|
78
|
+
ref={triggerRef}
|
|
88
79
|
/>
|
|
89
|
-
|
|
80
|
+
</span>
|
|
90
81
|
</Droplist>
|
|
91
82
|
)}
|
|
92
83
|
</div>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
4
|
-
import { Droplist } from '@snack-uikit/droplist';
|
|
5
4
|
import { DownloadSVG } from '@snack-uikit/icons';
|
|
5
|
+
import { Droplist } from '@snack-uikit/list';
|
|
6
6
|
|
|
7
7
|
import { exportToCSV, exportToXLSX } from '../../exportTable';
|
|
8
8
|
import { ColumnDefinition } from '../../types';
|
|
@@ -19,50 +19,31 @@ type ExportButtonProps<TData extends object> = {
|
|
|
19
19
|
export function ExportButton<TData extends object>({ fileName, data, columnDefinitions }: ExportButtonProps<TData>) {
|
|
20
20
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
21
21
|
|
|
22
|
-
const {
|
|
23
|
-
firstElementRefCallback,
|
|
24
|
-
handleDroplistFocusLeave,
|
|
25
|
-
handleTriggerKeyDown,
|
|
26
|
-
handleDroplistItemKeyDown,
|
|
27
|
-
handleDroplistItemClick,
|
|
28
|
-
triggerElementRef,
|
|
29
|
-
} = Droplist.useKeyboardNavigation<HTMLButtonElement>({ setDroplistOpen: setIsOpen });
|
|
30
|
-
|
|
31
22
|
return (
|
|
32
23
|
<Droplist
|
|
33
|
-
|
|
34
|
-
triggerRef={triggerElementRef}
|
|
35
|
-
onFocusLeave={handleDroplistFocusLeave}
|
|
24
|
+
trigger='clickAndFocusVisible'
|
|
36
25
|
open={isOpen}
|
|
37
26
|
onOpenChange={setIsOpen}
|
|
38
|
-
|
|
27
|
+
scroll
|
|
39
28
|
placement='bottom-end'
|
|
40
|
-
|
|
41
|
-
>
|
|
42
|
-
{[
|
|
29
|
+
items={[
|
|
43
30
|
{
|
|
44
|
-
option: 'Export to CSV',
|
|
31
|
+
content: { option: 'Export to CSV' },
|
|
45
32
|
onClick: () => {
|
|
46
33
|
exportToCSV<TData>({ fileName, columnDefinitions, data });
|
|
34
|
+
setIsOpen(false);
|
|
47
35
|
},
|
|
48
36
|
},
|
|
49
37
|
{
|
|
50
|
-
option: 'Export to XLSX',
|
|
38
|
+
content: { option: 'Export to XLSX' },
|
|
51
39
|
onClick: () => {
|
|
52
40
|
exportToXLSX<TData>({ fileName, columnDefinitions, data });
|
|
41
|
+
setIsOpen(false);
|
|
53
42
|
},
|
|
54
43
|
},
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
onKeyDown={handleDroplistItemKeyDown}
|
|
59
|
-
key={option}
|
|
60
|
-
onClick={e => {
|
|
61
|
-
handleDroplistItemClick(e);
|
|
62
|
-
onClick?.();
|
|
63
|
-
}}
|
|
64
|
-
/>
|
|
65
|
-
))}
|
|
44
|
+
]}
|
|
45
|
+
>
|
|
46
|
+
<ButtonFunction size='m' icon={<DownloadSVG />} />
|
|
66
47
|
</Droplist>
|
|
67
48
|
);
|
|
68
49
|
}
|