@cloud-ru/ds-tag 1.2.2-preview-de7dadcf.0 → 1.2.2-preview-2e992735.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/TagBase/TagBase.js +1 -1
- package/dist/cjs/helperComponents/TagList/TagList.js +1 -1
- package/dist/cjs/helperComponents/TagRowTruncated/TagRowTruncated.js +38 -27
- package/dist/esm/components/TagBase/TagBase.js +2 -2
- package/dist/esm/helperComponents/TagList/TagList.js +1 -1
- package/dist/esm/helperComponents/TagRowTruncated/TagRowTruncated.js +38 -27
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/components/TagBase/TagBase.tsx +2 -2
- package/src/helperComponents/TagList/TagList.tsx +1 -1
- package/src/helperComponents/TagRowTruncated/TagRowTruncated.tsx +39 -28
|
@@ -14,6 +14,6 @@ const constants_2 = require("./constants");
|
|
|
14
14
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
15
15
|
function TagBase({ label, truncateVariant, size = constants_1.SIZE.S, appearance = constants_1.APPEARANCE.Neutral, onDelete, className, tabIndex, innerRef, changeRestrictTooltipState, hideTruncateTooltip, ...rest }) {
|
|
16
16
|
const isRemovable = Boolean(onDelete);
|
|
17
|
-
return ((0, jsx_runtime_1.jsxs)("span", { ref: innerRef, ...
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)("span", { ref: innerRef, ...rest, className: (0, classnames_1.default)(styles_module_scss_1.default.tag, className), "data-size": size, "data-appearance": appearance, "data-removable": isRemovable, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.textWrapper, children: (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { className: styles_module_scss_1.default.label, text: label, variant: truncateVariant, hideTooltip: hideTruncateTooltip }) }), isRemovable && ((0, jsx_runtime_1.jsx)("button", { type: 'button', className: styles_module_scss_1.default.tagButton, onClick: onDelete, onMouseEnter: () => changeRestrictTooltipState?.(true), onMouseLeave: () => changeRestrictTooltipState?.(false), "data-test-id": constants_1.TEST_IDS.tag.removeButton, tabIndex: tabIndex, children: (0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.icon, children: (0, jsx_runtime_1.jsx)(system_1.CrossSVG, { size: constants_2.ICON_SIZE[size] }) }) }))] }));
|
|
18
18
|
}
|
|
19
19
|
(0, utils_1.withInnerRefSupport)(TagBase);
|
|
@@ -10,7 +10,7 @@ const constants_1 = require("../../constants");
|
|
|
10
10
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
11
11
|
function renderTag(size, handleRemoveItem, setRef) {
|
|
12
12
|
return function TagRowItem(item) {
|
|
13
|
-
return ((0, jsx_runtime_1.jsx)("div", { ref: setRef?.(item), className: styles_module_scss_1.default.tagWrapper, children: (0, jsx_runtime_1.jsx)(Tag_1.Tag, { size: size, onDelete: handleRemoveItem?.(item), ...item }) }, item.id ?? item.label));
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: setRef?.(item), className: styles_module_scss_1.default.tagWrapper, children: (0, jsx_runtime_1.jsx)(Tag_1.Tag, { size: size, ...(item.href ? {} : { onDelete: handleRemoveItem?.(item) }), ...item }) }, item.id ?? item.label));
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
function TagList({ items, size = constants_1.SIZE.S, onItemRemove, setTagRef }) {
|
|
@@ -50,38 +50,49 @@ function TagRowTruncatedInner({ items, rowLimit, size, moreButtonLabel = '', cla
|
|
|
50
50
|
const newVisibleTags = [];
|
|
51
51
|
const newHiddenTags = [];
|
|
52
52
|
const moreButtonWidth = hiddenMoreButtonRef.current?.offsetWidth || 0;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
const measuredTags = [...tagsMapRef.current].map(([item, element]) => ({
|
|
54
|
+
item,
|
|
55
|
+
width: element?.offsetWidth || 0,
|
|
56
|
+
}));
|
|
57
|
+
let rowWidth = 0;
|
|
58
|
+
let rowCount = 1;
|
|
59
|
+
let rowItems = 0;
|
|
60
|
+
const allTagsFit = measuredTags.every(({ width }) => {
|
|
61
|
+
const nextWidth = rowWidth + (rowItems ? gapWidth : 0) + width;
|
|
62
|
+
if (rowItems && nextWidth > maxWidth) {
|
|
63
|
+
rowCount++;
|
|
64
|
+
rowWidth = width;
|
|
65
|
+
rowItems = 1;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
rowWidth = nextWidth;
|
|
69
|
+
rowItems++;
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
newVisibleTags.push(tagRowItem);
|
|
72
|
-
currentRowVisibleTagAmount++;
|
|
71
|
+
return rowCount <= rowLimit && width <= maxWidth;
|
|
72
|
+
});
|
|
73
|
+
rowWidth = 0;
|
|
74
|
+
rowCount = 1;
|
|
75
|
+
rowItems = 0;
|
|
76
|
+
measuredTags.forEach(({ item, width }) => {
|
|
77
|
+
if (allTagsFit) {
|
|
78
|
+
newVisibleTags.push(item);
|
|
73
79
|
return;
|
|
74
80
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
let nextWidth = rowWidth + (rowItems ? gapWidth : 0) + width;
|
|
82
|
+
if (rowCount < rowLimit && rowItems && nextWidth > maxWidth) {
|
|
83
|
+
rowCount++;
|
|
84
|
+
rowWidth = 0;
|
|
85
|
+
rowItems = 0;
|
|
86
|
+
nextWidth = width;
|
|
87
|
+
}
|
|
88
|
+
if (rowCount > rowLimit || (rowCount === rowLimit && nextWidth + gapWidth + moreButtonWidth > maxWidth)) {
|
|
89
|
+
rowCount = rowLimit + 1;
|
|
90
|
+
newHiddenTags.push(item);
|
|
80
91
|
return;
|
|
81
92
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
newVisibleTags.push(
|
|
93
|
+
rowWidth = nextWidth;
|
|
94
|
+
rowItems++;
|
|
95
|
+
newVisibleTags.push(item);
|
|
85
96
|
});
|
|
86
97
|
setVisibleTags(newVisibleTags);
|
|
87
98
|
setHiddenTags(newHiddenTags);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CrossSVG } from '@cloud-ru/ds-icons/interface/system';
|
|
3
3
|
import { TruncateString } from '@cloud-ru/ds-truncate-string';
|
|
4
|
-
import {
|
|
4
|
+
import { withInnerRefSupport } from '@cloud-ru/ds-utils';
|
|
5
5
|
import cn from 'classnames';
|
|
6
6
|
import { APPEARANCE, SIZE, TEST_IDS } from '../../constants.js';
|
|
7
7
|
import { ICON_SIZE } from './constants.js';
|
|
8
8
|
import styles from './styles.module.css';
|
|
9
9
|
export function TagBase({ label, truncateVariant, size = SIZE.S, appearance = APPEARANCE.Neutral, onDelete, className, tabIndex, innerRef, changeRestrictTooltipState, hideTruncateTooltip, ...rest }) {
|
|
10
10
|
const isRemovable = Boolean(onDelete);
|
|
11
|
-
return (_jsxs("span", { ref: innerRef, ...
|
|
11
|
+
return (_jsxs("span", { ref: innerRef, ...rest, className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, "data-removable": isRemovable, children: [_jsx("span", { className: styles.textWrapper, children: _jsx(TruncateString, { className: styles.label, text: label, variant: truncateVariant, hideTooltip: hideTruncateTooltip }) }), isRemovable && (_jsx("button", { type: 'button', className: styles.tagButton, onClick: onDelete, onMouseEnter: () => changeRestrictTooltipState?.(true), onMouseLeave: () => changeRestrictTooltipState?.(false), "data-test-id": TEST_IDS.tag.removeButton, tabIndex: tabIndex, children: _jsx("span", { className: styles.icon, children: _jsx(CrossSVG, { size: ICON_SIZE[size] }) }) }))] }));
|
|
12
12
|
}
|
|
13
13
|
withInnerRefSupport(TagBase);
|
|
@@ -4,7 +4,7 @@ import { SIZE } from '../../constants.js';
|
|
|
4
4
|
import styles from './styles.module.css';
|
|
5
5
|
function renderTag(size, handleRemoveItem, setRef) {
|
|
6
6
|
return function TagRowItem(item) {
|
|
7
|
-
return (_jsx("div", { ref: setRef?.(item), className: styles.tagWrapper, children: _jsx(Tag, { size: size, onDelete: handleRemoveItem?.(item), ...item }) }, item.id ?? item.label));
|
|
7
|
+
return (_jsx("div", { ref: setRef?.(item), className: styles.tagWrapper, children: _jsx(Tag, { size: size, ...(item.href ? {} : { onDelete: handleRemoveItem?.(item) }), ...item }) }, item.id ?? item.label));
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
export function TagList({ items, size = SIZE.S, onItemRemove, setTagRef }) {
|
|
@@ -44,38 +44,49 @@ function TagRowTruncatedInner({ items, rowLimit, size, moreButtonLabel = '', cla
|
|
|
44
44
|
const newVisibleTags = [];
|
|
45
45
|
const newHiddenTags = [];
|
|
46
46
|
const moreButtonWidth = hiddenMoreButtonRef.current?.offsetWidth || 0;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
const measuredTags = [...tagsMapRef.current].map(([item, element]) => ({
|
|
48
|
+
item,
|
|
49
|
+
width: element?.offsetWidth || 0,
|
|
50
|
+
}));
|
|
51
|
+
let rowWidth = 0;
|
|
52
|
+
let rowCount = 1;
|
|
53
|
+
let rowItems = 0;
|
|
54
|
+
const allTagsFit = measuredTags.every(({ width }) => {
|
|
55
|
+
const nextWidth = rowWidth + (rowItems ? gapWidth : 0) + width;
|
|
56
|
+
if (rowItems && nextWidth > maxWidth) {
|
|
57
|
+
rowCount++;
|
|
58
|
+
rowWidth = width;
|
|
59
|
+
rowItems = 1;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
rowWidth = nextWidth;
|
|
63
|
+
rowItems++;
|
|
56
64
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
newVisibleTags.push(tagRowItem);
|
|
66
|
-
currentRowVisibleTagAmount++;
|
|
65
|
+
return rowCount <= rowLimit && width <= maxWidth;
|
|
66
|
+
});
|
|
67
|
+
rowWidth = 0;
|
|
68
|
+
rowCount = 1;
|
|
69
|
+
rowItems = 0;
|
|
70
|
+
measuredTags.forEach(({ item, width }) => {
|
|
71
|
+
if (allTagsFit) {
|
|
72
|
+
newVisibleTags.push(item);
|
|
67
73
|
return;
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
let nextWidth = rowWidth + (rowItems ? gapWidth : 0) + width;
|
|
76
|
+
if (rowCount < rowLimit && rowItems && nextWidth > maxWidth) {
|
|
77
|
+
rowCount++;
|
|
78
|
+
rowWidth = 0;
|
|
79
|
+
rowItems = 0;
|
|
80
|
+
nextWidth = width;
|
|
81
|
+
}
|
|
82
|
+
if (rowCount > rowLimit || (rowCount === rowLimit && nextWidth + gapWidth + moreButtonWidth > maxWidth)) {
|
|
83
|
+
rowCount = rowLimit + 1;
|
|
84
|
+
newHiddenTags.push(item);
|
|
74
85
|
return;
|
|
75
86
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
newVisibleTags.push(
|
|
87
|
+
rowWidth = nextWidth;
|
|
88
|
+
rowItems++;
|
|
89
|
+
newVisibleTags.push(item);
|
|
79
90
|
});
|
|
80
91
|
setVisibleTags(newVisibleTags);
|
|
81
92
|
setHiddenTags(newHiddenTags);
|