@snack-uikit/card 0.20.8 → 0.20.9-preview-ac7bb67c.0
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/dist/cjs/components/FunctionBadge/FunctionBadge.d.ts +3 -3
- package/dist/cjs/components/FunctionBadge/FunctionBadge.js +33 -20
- package/dist/esm/components/FunctionBadge/FunctionBadge.d.ts +3 -3
- package/dist/esm/components/FunctionBadge/FunctionBadge.js +22 -8
- package/package.json +2 -2
- package/src/components/FunctionBadge/FunctionBadge.tsx +44 -14
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type Option = {
|
|
2
|
+
import { DroplistProps } from '@snack-uikit/list';
|
|
3
|
+
type Option = DroplistProps['items'][number] & {
|
|
4
4
|
tagLabel?: string;
|
|
5
5
|
icon?: ReactElement;
|
|
6
|
-
}
|
|
6
|
+
};
|
|
7
7
|
export type FunctionBadgeProps = {
|
|
8
8
|
/** Иконка */
|
|
9
9
|
icon?: ReactNode;
|
|
@@ -43,6 +43,38 @@ function FunctionBadge(_ref) {
|
|
|
43
43
|
e.stopPropagation();
|
|
44
44
|
setIsOpen(isOpen => !isOpen);
|
|
45
45
|
}, []);
|
|
46
|
+
const processItem = (0, react_1.useCallback)(option => {
|
|
47
|
+
var _a;
|
|
48
|
+
const {
|
|
49
|
+
icon,
|
|
50
|
+
tagLabel
|
|
51
|
+
} = option,
|
|
52
|
+
item = __rest(option, ["icon", "tagLabel"]);
|
|
53
|
+
// GroupItem и GroupSelectItem не имеют beforeContent, afterContent, onClick
|
|
54
|
+
if ('type' in item && (item.type === 'group' || item.type === 'group-select')) {
|
|
55
|
+
return item;
|
|
56
|
+
}
|
|
57
|
+
// BaseItem, AccordionItem, NextListItem имеют beforeContent, afterContent, onClick
|
|
58
|
+
const baseItem = item;
|
|
59
|
+
const itemOnClick = baseItem.onClick;
|
|
60
|
+
// Рекурсивно обрабатываем вложенные items для next-list и collapse
|
|
61
|
+
const processedItems = 'items' in item && 'type' in item && (item.type === 'next-list' || item.type === 'collapse') ? (_a = item.items) === null || _a === void 0 ? void 0 : _a.map(nestedItem => processItem(nestedItem)) : undefined;
|
|
62
|
+
return Object.assign(Object.assign(Object.assign({}, item), processedItems ? {
|
|
63
|
+
items: processedItems
|
|
64
|
+
} : {}), {
|
|
65
|
+
className: styles_module_scss_1.default.item,
|
|
66
|
+
beforeContent: icon !== null && icon !== void 0 ? icon : baseItem.beforeContent,
|
|
67
|
+
afterContent: tagLabel ? (0, jsx_runtime_1.jsx)(tag_1.Tag, {
|
|
68
|
+
label: tagLabel
|
|
69
|
+
}) : baseItem.afterContent,
|
|
70
|
+
onClick: e => {
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
setIsOpen(false);
|
|
73
|
+
itemOnClick === null || itemOnClick === void 0 ? void 0 : itemOnClick(e);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}, []);
|
|
77
|
+
const items = options.map(option => processItem(option));
|
|
46
78
|
return (0, jsx_runtime_1.jsx)("span", {
|
|
47
79
|
className: styles_module_scss_1.default.wrapper,
|
|
48
80
|
children: (0, jsx_runtime_1.jsx)(list_1.Droplist, {
|
|
@@ -54,26 +86,7 @@ function FunctionBadge(_ref) {
|
|
|
54
86
|
"data-test-id": constants_1.TEST_IDS.droplist,
|
|
55
87
|
placement: 'bottom-end',
|
|
56
88
|
triggerElemRef: buttonRef,
|
|
57
|
-
items:
|
|
58
|
-
var {
|
|
59
|
-
icon,
|
|
60
|
-
tagLabel,
|
|
61
|
-
onClick
|
|
62
|
-
} = _a,
|
|
63
|
-
item = __rest(_a, ["icon", "tagLabel", "onClick"]);
|
|
64
|
-
return Object.assign(Object.assign({}, item), {
|
|
65
|
-
className: styles_module_scss_1.default.item,
|
|
66
|
-
beforeContent: icon,
|
|
67
|
-
afterContent: tagLabel ? (0, jsx_runtime_1.jsx)(tag_1.Tag, {
|
|
68
|
-
label: tagLabel
|
|
69
|
-
}) : undefined,
|
|
70
|
-
onClick: e => {
|
|
71
|
-
e.stopPropagation();
|
|
72
|
-
setIsOpen(false);
|
|
73
|
-
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}),
|
|
89
|
+
items: items,
|
|
77
90
|
children: (0, jsx_runtime_1.jsx)("button", {
|
|
78
91
|
type: 'button',
|
|
79
92
|
"data-test-id": constants_1.TEST_IDS.functionBadge,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type Option = {
|
|
2
|
+
import { DroplistProps } from '@snack-uikit/list';
|
|
3
|
+
type Option = DroplistProps['items'][number] & {
|
|
4
4
|
tagLabel?: string;
|
|
5
5
|
icon?: ReactElement;
|
|
6
|
-
}
|
|
6
|
+
};
|
|
7
7
|
export type FunctionBadgeProps = {
|
|
8
8
|
/** Иконка */
|
|
9
9
|
icon?: ReactNode;
|
|
@@ -29,12 +29,26 @@ export function FunctionBadge({ icon, options }) {
|
|
|
29
29
|
e.stopPropagation();
|
|
30
30
|
setIsOpen(isOpen => !isOpen);
|
|
31
31
|
}, []);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
const processItem = useCallback((option) => {
|
|
33
|
+
var _a;
|
|
34
|
+
const { icon, tagLabel } = option, item = __rest(option, ["icon", "tagLabel"]);
|
|
35
|
+
// GroupItem и GroupSelectItem не имеют beforeContent, afterContent, onClick
|
|
36
|
+
if ('type' in item && (item.type === 'group' || item.type === 'group-select')) {
|
|
37
|
+
return item;
|
|
38
|
+
}
|
|
39
|
+
// BaseItem, AccordionItem, NextListItem имеют beforeContent, afterContent, onClick
|
|
40
|
+
const baseItem = item;
|
|
41
|
+
const itemOnClick = baseItem.onClick;
|
|
42
|
+
// Рекурсивно обрабатываем вложенные items для next-list и collapse
|
|
43
|
+
const processedItems = 'items' in item && 'type' in item && (item.type === 'next-list' || item.type === 'collapse')
|
|
44
|
+
? (_a = item.items) === null || _a === void 0 ? void 0 : _a.map(nestedItem => processItem(nestedItem))
|
|
45
|
+
: undefined;
|
|
46
|
+
return Object.assign(Object.assign(Object.assign({}, item), (processedItems ? { items: processedItems } : {})), { className: styles.item, beforeContent: icon !== null && icon !== void 0 ? icon : baseItem.beforeContent, afterContent: tagLabel ? _jsx(Tag, { label: tagLabel }) : baseItem.afterContent, onClick: (e) => {
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
setIsOpen(false);
|
|
49
|
+
itemOnClick === null || itemOnClick === void 0 ? void 0 : itemOnClick(e);
|
|
50
|
+
} });
|
|
51
|
+
}, []);
|
|
52
|
+
const items = options.map(option => processItem(option));
|
|
53
|
+
return (_jsx("span", { className: styles.wrapper, children: _jsx(Droplist, { trigger: 'clickAndFocusVisible', open: isOpen, onOpenChange: setIsOpen, widthStrategy: 'gte', scroll: true, "data-test-id": TEST_IDS.droplist, placement: 'bottom-end', triggerElemRef: buttonRef, items: items, children: _jsx("button", { type: 'button', "data-test-id": TEST_IDS.functionBadge, className: styles.button, onClick: onClick, ref: buttonRef, children: icon || _jsx(KebabSVG, {}) }) }) }));
|
|
40
54
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Card",
|
|
7
|
-
"version": "0.20.
|
|
7
|
+
"version": "0.20.9-preview-ac7bb67c.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"classnames": "2.5.1",
|
|
49
49
|
"merge-refs": "1.3.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "cd872b7343e3a29567c9cf7840344a8831512d6a"
|
|
52
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MouseEvent, ReactElement, ReactNode, useCallback, useContext, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { KebabSVG } from '@snack-uikit/icons';
|
|
4
|
-
import {
|
|
4
|
+
import { Droplist, DroplistProps } from '@snack-uikit/list';
|
|
5
5
|
import { Tag } from '@snack-uikit/tag';
|
|
6
6
|
import { useLayoutEffect } from '@snack-uikit/utils';
|
|
7
7
|
|
|
@@ -9,10 +9,10 @@ import { TEST_IDS } from '../../constants';
|
|
|
9
9
|
import { FunctionBadgeContext } from '../../context';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
11
11
|
|
|
12
|
-
type Option = {
|
|
12
|
+
type Option = DroplistProps['items'][number] & {
|
|
13
13
|
tagLabel?: string;
|
|
14
14
|
icon?: ReactElement;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
export type FunctionBadgeProps = {
|
|
18
18
|
/** Иконка */
|
|
@@ -36,6 +36,46 @@ export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
|
|
|
36
36
|
setIsOpen(isOpen => !isOpen);
|
|
37
37
|
}, []);
|
|
38
38
|
|
|
39
|
+
const processItem = useCallback((option: Option): typeof option => {
|
|
40
|
+
const { icon, tagLabel, ...item } = option;
|
|
41
|
+
|
|
42
|
+
// GroupItem и GroupSelectItem не имеют beforeContent, afterContent, onClick
|
|
43
|
+
if ('type' in item && (item.type === 'group' || item.type === 'group-select')) {
|
|
44
|
+
return item;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// BaseItem, AccordionItem, NextListItem имеют beforeContent, afterContent, onClick
|
|
48
|
+
const baseItem = item as {
|
|
49
|
+
beforeContent?: ReactNode;
|
|
50
|
+
afterContent?: ReactNode;
|
|
51
|
+
onClick?: (e: MouseEvent<HTMLElement>) => void;
|
|
52
|
+
items?: Option[];
|
|
53
|
+
type?: string;
|
|
54
|
+
};
|
|
55
|
+
const itemOnClick = baseItem.onClick;
|
|
56
|
+
|
|
57
|
+
// Рекурсивно обрабатываем вложенные items для next-list и collapse
|
|
58
|
+
const processedItems =
|
|
59
|
+
'items' in item && 'type' in item && (item.type === 'next-list' || item.type === 'collapse')
|
|
60
|
+
? item.items?.map(nestedItem => processItem(nestedItem as Option))
|
|
61
|
+
: undefined;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
...item,
|
|
65
|
+
...(processedItems ? { items: processedItems } : {}),
|
|
66
|
+
className: styles.item,
|
|
67
|
+
beforeContent: icon ?? baseItem.beforeContent,
|
|
68
|
+
afterContent: tagLabel ? <Tag label={tagLabel} /> : baseItem.afterContent,
|
|
69
|
+
onClick: (e: MouseEvent<HTMLElement>) => {
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
setIsOpen(false);
|
|
72
|
+
itemOnClick?.(e);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
const items = options.map(option => processItem(option));
|
|
78
|
+
|
|
39
79
|
return (
|
|
40
80
|
<span className={styles.wrapper}>
|
|
41
81
|
<Droplist
|
|
@@ -47,17 +87,7 @@ export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
|
|
|
47
87
|
data-test-id={TEST_IDS.droplist}
|
|
48
88
|
placement='bottom-end'
|
|
49
89
|
triggerElemRef={buttonRef}
|
|
50
|
-
items={
|
|
51
|
-
...item,
|
|
52
|
-
className: styles.item,
|
|
53
|
-
beforeContent: icon,
|
|
54
|
-
afterContent: tagLabel ? <Tag label={tagLabel} /> : undefined,
|
|
55
|
-
onClick: e => {
|
|
56
|
-
e.stopPropagation();
|
|
57
|
-
setIsOpen(false);
|
|
58
|
-
onClick?.(e);
|
|
59
|
-
},
|
|
60
|
-
}))}
|
|
90
|
+
items={items}
|
|
61
91
|
>
|
|
62
92
|
<button
|
|
63
93
|
type='button'
|