@cloud-ru/ds-tag 1.2.2 → 1.2.3
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 +8 -0
- package/dist/cjs/components/TagBase/TagBase.js +1 -1
- package/dist/cjs/helperComponents/TagList/TagList.js +1 -1
- package/dist/cjs/helperComponents/TagRowSimple/styles.module.css +3 -3
- package/dist/cjs/helperComponents/TagRowTruncated/TagRowTruncated.js +38 -27
- package/dist/cjs/helperComponents/TagRowTruncated/styles.module.css +9 -9
- package/dist/cjs/style.css +12 -12
- package/dist/esm/components/TagBase/TagBase.js +2 -2
- package/dist/esm/helperComponents/TagList/TagList.js +1 -1
- package/dist/esm/helperComponents/TagRowSimple/styles.module.css +3 -3
- package/dist/esm/helperComponents/TagRowTruncated/TagRowTruncated.js +38 -27
- package/dist/esm/helperComponents/TagRowTruncated/styles.module.css +9 -9
- package/dist/esm/style.css +12 -12
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-ru/ds-tag",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Пакет компактных меток — компонент Tag (опционально удаляемый или ссылочный) и контейнер TagRow для групп меток с обрезанием по строкам.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"classnames": "^2.5.1",
|
|
37
|
-
"@cloud-ru/ds-
|
|
38
|
-
"@cloud-ru/ds-
|
|
39
|
-
"@cloud-ru/ds-
|
|
40
|
-
"@cloud-ru/ds-
|
|
41
|
-
"@cloud-ru/ds-tooltip": "^1.0.
|
|
42
|
-
"@cloud-ru/ds-
|
|
43
|
-
"@cloud-ru/ds-utils": "^1.4.
|
|
37
|
+
"@cloud-ru/ds-materials": "^2.0.4",
|
|
38
|
+
"@cloud-ru/ds-dropdown": "^1.2.3",
|
|
39
|
+
"@cloud-ru/ds-icons": "^1.7.4",
|
|
40
|
+
"@cloud-ru/ds-truncate-string": "^1.0.21",
|
|
41
|
+
"@cloud-ru/ds-tooltip": "^1.0.20",
|
|
42
|
+
"@cloud-ru/ds-scroll": "^1.0.8",
|
|
43
|
+
"@cloud-ru/ds-utils": "^1.4.1"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CrossSVG } from '@cloud-ru/ds-icons/interface/system';
|
|
2
2
|
import { TruncateString } from '@cloud-ru/ds-truncate-string';
|
|
3
|
-
import {
|
|
3
|
+
import { withInnerRefSupport } from '@cloud-ru/ds-utils';
|
|
4
4
|
import cn from 'classnames';
|
|
5
5
|
|
|
6
6
|
import { APPEARANCE, SIZE, TEST_IDS } from '../../constants';
|
|
@@ -26,7 +26,7 @@ export function TagBase({
|
|
|
26
26
|
return (
|
|
27
27
|
<span
|
|
28
28
|
ref={innerRef}
|
|
29
|
-
{...
|
|
29
|
+
{...rest}
|
|
30
30
|
className={cn(styles.tag, className)}
|
|
31
31
|
data-size={size}
|
|
32
32
|
data-appearance={appearance}
|
|
@@ -20,7 +20,7 @@ function renderTag(size: Size, handleRemoveItem?: (item: TagRowItemInner) => OnD
|
|
|
20
20
|
return function TagRowItem(item: TagRowItemInner) {
|
|
21
21
|
return (
|
|
22
22
|
<div key={item.id ?? item.label} ref={setRef?.(item)} className={styles.tagWrapper}>
|
|
23
|
-
<Tag size={size} onDelete
|
|
23
|
+
<Tag size={size} {...(item.href ? {} : { onDelete: handleRemoveItem?.(item) })} {...item} />
|
|
24
24
|
</div>
|
|
25
25
|
);
|
|
26
26
|
};
|
|
@@ -78,44 +78,55 @@ function TagRowTruncatedInner({
|
|
|
78
78
|
|
|
79
79
|
const moreButtonWidth = hiddenMoreButtonRef.current?.offsetWidth || 0;
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
const measuredTags = [...tagsMapRef.current].map(([item, element]) => ({
|
|
82
|
+
item,
|
|
83
|
+
width: element?.offsetWidth || 0,
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
let rowWidth = 0;
|
|
87
|
+
let rowCount = 1;
|
|
88
|
+
let rowItems = 0;
|
|
89
|
+
|
|
90
|
+
const allTagsFit = measuredTags.every(({ width }) => {
|
|
91
|
+
const nextWidth = rowWidth + (rowItems ? gapWidth : 0) + width;
|
|
92
|
+
if (rowItems && nextWidth > maxWidth) {
|
|
93
|
+
rowCount++;
|
|
94
|
+
rowWidth = width;
|
|
95
|
+
rowItems = 1;
|
|
96
|
+
} else {
|
|
97
|
+
rowWidth = nextWidth;
|
|
98
|
+
rowItems++;
|
|
99
|
+
}
|
|
100
|
+
return rowCount <= rowLimit && width <= maxWidth;
|
|
101
|
+
});
|
|
84
102
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
rowWidth = 0;
|
|
104
|
+
rowCount = 1;
|
|
105
|
+
rowItems = 0;
|
|
88
106
|
|
|
89
|
-
|
|
90
|
-
|
|
107
|
+
measuredTags.forEach(({ item, width }) => {
|
|
108
|
+
if (allTagsFit) {
|
|
109
|
+
newVisibleTags.push(item);
|
|
91
110
|
return;
|
|
92
111
|
}
|
|
93
112
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
currentRowWidth = sumRowWidth;
|
|
103
|
-
newVisibleTags.push(tagRowItem);
|
|
104
|
-
currentRowVisibleTagAmount++;
|
|
105
|
-
return;
|
|
113
|
+
let nextWidth = rowWidth + (rowItems ? gapWidth : 0) + width;
|
|
114
|
+
if (rowCount < rowLimit && rowItems && nextWidth > maxWidth) {
|
|
115
|
+
rowCount++;
|
|
116
|
+
rowWidth = 0;
|
|
117
|
+
rowItems = 0;
|
|
118
|
+
nextWidth = width;
|
|
106
119
|
}
|
|
107
120
|
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
currentRowVisibleTagAmount = 0;
|
|
112
|
-
newVisibleTags.push(tagRowItem);
|
|
121
|
+
if (rowCount > rowLimit || (rowCount === rowLimit && nextWidth + gapWidth + moreButtonWidth > maxWidth)) {
|
|
122
|
+
rowCount = rowLimit + 1;
|
|
123
|
+
newHiddenTags.push(item);
|
|
113
124
|
return;
|
|
114
125
|
}
|
|
115
126
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
newVisibleTags.push(
|
|
127
|
+
rowWidth = nextWidth;
|
|
128
|
+
rowItems++;
|
|
129
|
+
newVisibleTags.push(item);
|
|
119
130
|
});
|
|
120
131
|
|
|
121
132
|
setVisibleTags(newVisibleTags);
|