@snack-uikit/toolbar 0.6.2 → 0.7.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 +20 -0
- package/README.md +1 -1
- package/dist/components/Toolbar/types.d.ts +2 -3
- package/dist/helperComponents/MoreActions/MoreActions.d.ts +8 -2
- package/dist/helperComponents/MoreActions/MoreActions.js +12 -16
- package/package.json +5 -4
- package/src/components/Toolbar/types.ts +2 -7
- package/src/helperComponents/MoreActions/MoreActions.tsx +24 -43
- package/dist/helperComponents/MoreActions/hooks.d.ts +0 -13
- package/dist/helperComponents/MoreActions/hooks.js +0 -28
- package/dist/helperComponents/MoreActions/styles.module.css +0 -4
- package/src/helperComponents/MoreActions/hooks.ts +0 -46
- package/src/helperComponents/MoreActions/styles.module.scss +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
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.7.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
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# 0.7.0 (2024-01-30)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
* **FF-4075:** change usage droplist to list package ([4ce6391](https://github.com/cloud-ru-tech/snack-uikit/commit/4ce63915e838a46a3776e8e21393695a37d2fdd3))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## 0.6.2 (2024-01-23)
|
|
7
27
|
|
|
8
28
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Toolbar
|
|
|
24
24
|
| onRefresh | `() => void` | - | Колбек обновления |
|
|
25
25
|
| before | `ReactNode` | - | Дополнительный слот в начале Тулбара |
|
|
26
26
|
| after | `ReactNode` | - | Дополнительный слот в конце тулбара |
|
|
27
|
-
| moreActions | `
|
|
27
|
+
| moreActions | `Action[]` | - | Элементы выпадающего списка кнопки с действиями |
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { DeleteActionProps } from '../../helperComponents';
|
|
2
|
+
import { DeleteActionProps, MoreActionsProps } from '../../helperComponents';
|
|
4
3
|
import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
|
|
5
4
|
type OptionalProps = {
|
|
6
5
|
/** Колбек обновления */
|
|
@@ -10,7 +9,7 @@ type OptionalProps = {
|
|
|
10
9
|
/** Дополнительный слот в конце тулбара */
|
|
11
10
|
after?: ReactNode;
|
|
12
11
|
/** Элементы выпадающего списка кнопки с действиями */
|
|
13
|
-
moreActions?:
|
|
12
|
+
moreActions?: MoreActionsProps['moreActions'];
|
|
14
13
|
};
|
|
15
14
|
export type CommonToolbarProps = {
|
|
16
15
|
/** Параметры отвечают за строку поиска <br>
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { BaseItemProps } from '@snack-uikit/list';
|
|
3
|
+
type Action = {
|
|
4
|
+
tagLabel?: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
} & Pick<BaseItemProps, 'content' | 'disabled' | 'onClick'>;
|
|
2
7
|
export type MoreActionsProps = {
|
|
3
|
-
moreActions:
|
|
8
|
+
moreActions: Action[];
|
|
4
9
|
};
|
|
5
10
|
export declare function MoreActions({ moreActions }: MoreActionsProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useRef, useState } from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
4
3
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
5
|
-
import { Droplist } from '@snack-uikit/droplist';
|
|
6
4
|
import { KebabSVG } from '@snack-uikit/icons';
|
|
5
|
+
import { Droplist } from '@snack-uikit/list';
|
|
6
|
+
import { Tag } from '@snack-uikit/tag';
|
|
7
7
|
import { TEST_IDS } from '../../constants';
|
|
8
|
-
import { useHandlers } from './hooks';
|
|
9
|
-
import styles from './styles.module.css';
|
|
10
8
|
export function MoreActions({ moreActions }) {
|
|
11
9
|
const [isOpen, setIsOpen] = useState(false);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const { onKeyDown, onFocusLeave, firstElementRefCallback } = useHandlers({
|
|
15
|
-
triggerRef,
|
|
16
|
-
setIsOpen,
|
|
17
|
-
needsFocus,
|
|
18
|
-
setNeedsFocus,
|
|
19
|
-
});
|
|
20
|
-
return (_jsx(Droplist, { open: isOpen, "data-test-id": TEST_IDS.droplist, onOpenChange: setIsOpen, placement: 'bottom-end', onFocusLeave: onFocusLeave, firstElementRefCallback: firstElementRefCallback, useScroll: true, triggerRef: triggerRef, triggerElement: _jsx(ButtonFunction, { icon: _jsx(KebabSVG, { size: 24 }), size: 'm', onKeyDown: onKeyDown, "data-test-id": TEST_IDS.moreActionsButton }), size: 's', children: moreActions.map(item => (_createElement(Droplist.ItemSingle, Object.assign({}, item, { key: item.option, className: styles.item, onClick: e => {
|
|
10
|
+
return (_jsx(Droplist, { trigger: 'clickAndFocusVisible', open: isOpen, "data-test-id": TEST_IDS.droplist, onOpenChange: setIsOpen, placement: 'bottom-end', scroll: true, size: 's', items: moreActions.map(item => ({
|
|
11
|
+
onClick: e => {
|
|
21
12
|
var _a;
|
|
22
13
|
(_a = item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, e);
|
|
23
14
|
setIsOpen(false);
|
|
24
|
-
setNeedsFocus(false);
|
|
25
15
|
e.stopPropagation();
|
|
26
|
-
},
|
|
16
|
+
},
|
|
17
|
+
disabled: item.disabled,
|
|
18
|
+
content: item.content,
|
|
19
|
+
beforeContent: item.icon,
|
|
20
|
+
afterContent: item.tagLabel ? _jsx(Tag, { label: item.tagLabel }) : undefined,
|
|
21
|
+
'data-test-id': TEST_IDS.option,
|
|
22
|
+
})), children: _jsx(ButtonFunction, { icon: _jsx(KebabSVG, { size: 24 }), size: 'm', "data-test-id": TEST_IDS.moreActionsButton }) }));
|
|
27
23
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Toolbar",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.7.1",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -33,12 +33,13 @@
|
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/button": "0.15.1",
|
|
36
|
-
"@snack-uikit/droplist": "0.12.5",
|
|
37
36
|
"@snack-uikit/icons": "0.20.0",
|
|
38
|
-
"@snack-uikit/
|
|
37
|
+
"@snack-uikit/list": "0.1.1",
|
|
38
|
+
"@snack-uikit/search-private": "0.1.2",
|
|
39
|
+
"@snack-uikit/tag": "0.6.4",
|
|
39
40
|
"@snack-uikit/toggles": "0.9.4",
|
|
40
41
|
"@snack-uikit/utils": "3.2.0",
|
|
41
42
|
"classnames": "2.3.2"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "54873fdb2f34f26a771f62568d3d6fcd62ea1694"
|
|
44
45
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { DeleteActionProps } from '../../helperComponents';
|
|
3
|
+
import { DeleteActionProps, MoreActionsProps } from '../../helperComponents';
|
|
6
4
|
import { NeverOrUndefined, RequireAtLeastOne } from './typesUtils';
|
|
7
5
|
|
|
8
6
|
type OptionalProps = {
|
|
@@ -13,10 +11,7 @@ type OptionalProps = {
|
|
|
13
11
|
/** Дополнительный слот в конце тулбара */
|
|
14
12
|
after?: ReactNode;
|
|
15
13
|
/** Элементы выпадающего списка кнопки с действиями */
|
|
16
|
-
moreActions?:
|
|
17
|
-
ItemSingleProps,
|
|
18
|
-
'tagLabel' | 'onClick' | 'option' | 'icon' | 'disabled' | 'description' | 'caption'
|
|
19
|
-
>[];
|
|
14
|
+
moreActions?: MoreActionsProps['moreActions'];
|
|
20
15
|
};
|
|
21
16
|
|
|
22
17
|
export type CommonToolbarProps = {
|
|
@@ -1,66 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
4
|
-
import { Droplist, ItemSingleProps } from '@snack-uikit/droplist';
|
|
5
4
|
import { KebabSVG } from '@snack-uikit/icons';
|
|
5
|
+
import { BaseItemProps, Droplist } from '@snack-uikit/list';
|
|
6
|
+
import { Tag } from '@snack-uikit/tag';
|
|
6
7
|
|
|
7
8
|
import { TEST_IDS } from '../../constants';
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
type Action = {
|
|
11
|
+
tagLabel?: string;
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
} & Pick<BaseItemProps, 'content' | 'disabled' | 'onClick'>;
|
|
10
14
|
|
|
11
15
|
export type MoreActionsProps = {
|
|
12
|
-
moreActions:
|
|
13
|
-
ItemSingleProps,
|
|
14
|
-
'tagLabel' | 'onClick' | 'option' | 'icon' | 'disabled' | 'description' | 'caption'
|
|
15
|
-
>[];
|
|
16
|
+
moreActions: Action[];
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
export function MoreActions({ moreActions }: MoreActionsProps) {
|
|
19
20
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
20
|
-
const [needsFocus, setNeedsFocus] = useState<boolean>(false);
|
|
21
|
-
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
22
|
-
|
|
23
|
-
const { onKeyDown, onFocusLeave, firstElementRefCallback } = useHandlers({
|
|
24
|
-
triggerRef,
|
|
25
|
-
setIsOpen,
|
|
26
|
-
needsFocus,
|
|
27
|
-
setNeedsFocus,
|
|
28
|
-
});
|
|
29
21
|
|
|
30
22
|
return (
|
|
31
23
|
<Droplist
|
|
24
|
+
trigger='clickAndFocusVisible'
|
|
32
25
|
open={isOpen}
|
|
33
26
|
data-test-id={TEST_IDS.droplist}
|
|
34
27
|
onOpenChange={setIsOpen}
|
|
35
28
|
placement='bottom-end'
|
|
36
|
-
|
|
37
|
-
firstElementRefCallback={firstElementRefCallback}
|
|
38
|
-
useScroll
|
|
39
|
-
triggerRef={triggerRef}
|
|
40
|
-
triggerElement={
|
|
41
|
-
<ButtonFunction
|
|
42
|
-
icon={<KebabSVG size={24} />}
|
|
43
|
-
size='m'
|
|
44
|
-
onKeyDown={onKeyDown}
|
|
45
|
-
data-test-id={TEST_IDS.moreActionsButton}
|
|
46
|
-
/>
|
|
47
|
-
}
|
|
29
|
+
scroll
|
|
48
30
|
size='s'
|
|
31
|
+
items={moreActions.map(item => ({
|
|
32
|
+
onClick: e => {
|
|
33
|
+
item.onClick?.(e);
|
|
34
|
+
setIsOpen(false);
|
|
35
|
+
e.stopPropagation();
|
|
36
|
+
},
|
|
37
|
+
disabled: item.disabled,
|
|
38
|
+
content: item.content,
|
|
39
|
+
beforeContent: item.icon,
|
|
40
|
+
afterContent: item.tagLabel ? <Tag label={item.tagLabel} /> : undefined,
|
|
41
|
+
'data-test-id': TEST_IDS.option,
|
|
42
|
+
}))}
|
|
49
43
|
>
|
|
50
|
-
{
|
|
51
|
-
<Droplist.ItemSingle
|
|
52
|
-
{...item}
|
|
53
|
-
key={item.option}
|
|
54
|
-
className={styles.item}
|
|
55
|
-
onClick={e => {
|
|
56
|
-
item.onClick?.(e);
|
|
57
|
-
setIsOpen(false);
|
|
58
|
-
setNeedsFocus(false);
|
|
59
|
-
e.stopPropagation();
|
|
60
|
-
}}
|
|
61
|
-
data-test-id={TEST_IDS.option}
|
|
62
|
-
/>
|
|
63
|
-
))}
|
|
44
|
+
<ButtonFunction icon={<KebabSVG size={24} />} size='m' data-test-id={TEST_IDS.moreActionsButton} />
|
|
64
45
|
</Droplist>
|
|
65
46
|
);
|
|
66
47
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Dispatch, KeyboardEvent, RefObject, SetStateAction } from 'react';
|
|
2
|
-
type UseHandlersProps = {
|
|
3
|
-
triggerRef: RefObject<HTMLButtonElement>;
|
|
4
|
-
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
5
|
-
setNeedsFocus: Dispatch<SetStateAction<boolean>>;
|
|
6
|
-
needsFocus: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare function useHandlers({ triggerRef, setIsOpen, setNeedsFocus, needsFocus }: UseHandlersProps): {
|
|
9
|
-
onFocusLeave: (direction: 'common' | 'top' | 'bottom' | 'left' | 'right') => void;
|
|
10
|
-
onKeyDown: (e: KeyboardEvent<HTMLButtonElement>) => void;
|
|
11
|
-
firstElementRefCallback: (el: HTMLButtonElement | null) => void;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { TRIGGER_CLOSE_DROPLIST_KEY_CODES, TRIGGER_OPEN_DROPLIST_KEY_KEYS } from './constants';
|
|
3
|
-
export function useHandlers({ triggerRef, setIsOpen, setNeedsFocus, needsFocus }) {
|
|
4
|
-
const onKeyDown = useCallback((e) => {
|
|
5
|
-
if (TRIGGER_OPEN_DROPLIST_KEY_KEYS.includes(e.key)) {
|
|
6
|
-
e.preventDefault();
|
|
7
|
-
setNeedsFocus(true);
|
|
8
|
-
setIsOpen(true);
|
|
9
|
-
}
|
|
10
|
-
if (TRIGGER_CLOSE_DROPLIST_KEY_CODES.includes(e.code)) {
|
|
11
|
-
setNeedsFocus(false);
|
|
12
|
-
setIsOpen(false);
|
|
13
|
-
}
|
|
14
|
-
}, [setIsOpen, setNeedsFocus]);
|
|
15
|
-
const firstElementRefCallback = (el) => {
|
|
16
|
-
needsFocus && (el === null || el === void 0 ? void 0 : el.focus());
|
|
17
|
-
setNeedsFocus(false);
|
|
18
|
-
};
|
|
19
|
-
const onFocusLeave = useCallback((direction) => {
|
|
20
|
-
var _a;
|
|
21
|
-
if (direction === 'top') {
|
|
22
|
-
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
23
|
-
setIsOpen(false);
|
|
24
|
-
setNeedsFocus(false);
|
|
25
|
-
}
|
|
26
|
-
}, [triggerRef, setIsOpen, setNeedsFocus]);
|
|
27
|
-
return { onFocusLeave, onKeyDown, firstElementRefCallback };
|
|
28
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Dispatch, KeyboardEvent, RefObject, SetStateAction, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { TRIGGER_CLOSE_DROPLIST_KEY_CODES, TRIGGER_OPEN_DROPLIST_KEY_KEYS } from './constants';
|
|
4
|
-
|
|
5
|
-
type UseHandlersProps = {
|
|
6
|
-
triggerRef: RefObject<HTMLButtonElement>;
|
|
7
|
-
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
8
|
-
setNeedsFocus: Dispatch<SetStateAction<boolean>>;
|
|
9
|
-
needsFocus: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function useHandlers({ triggerRef, setIsOpen, setNeedsFocus, needsFocus }: UseHandlersProps) {
|
|
13
|
-
const onKeyDown = useCallback(
|
|
14
|
-
(e: KeyboardEvent<HTMLButtonElement>) => {
|
|
15
|
-
if (TRIGGER_OPEN_DROPLIST_KEY_KEYS.includes(e.key)) {
|
|
16
|
-
e.preventDefault();
|
|
17
|
-
setNeedsFocus(true);
|
|
18
|
-
setIsOpen(true);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (TRIGGER_CLOSE_DROPLIST_KEY_CODES.includes(e.code)) {
|
|
22
|
-
setNeedsFocus(false);
|
|
23
|
-
setIsOpen(false);
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
[setIsOpen, setNeedsFocus],
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const firstElementRefCallback = (el: HTMLButtonElement | null) => {
|
|
30
|
-
needsFocus && el?.focus();
|
|
31
|
-
setNeedsFocus(false);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const onFocusLeave = useCallback(
|
|
35
|
-
(direction: 'common' | 'top' | 'bottom' | 'left' | 'right') => {
|
|
36
|
-
if (direction === 'top') {
|
|
37
|
-
triggerRef.current?.focus();
|
|
38
|
-
setIsOpen(false);
|
|
39
|
-
setNeedsFocus(false);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
[triggerRef, setIsOpen, setNeedsFocus],
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
return { onFocusLeave, onKeyDown, firstElementRefCallback };
|
|
46
|
-
}
|