@cloud-ru/ds-tag 1.2.2-preview-90b10112.0 → 1.2.2-preview-e8fe6b56.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-tag",
3
- "version": "1.2.2-preview-90b10112.0",
3
+ "version": "1.2.2-preview-e8fe6b56.0",
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-dropdown": "1.2.2-preview-90b10112.0",
38
- "@cloud-ru/ds-icons": "1.7.3-preview-90b10112.0",
39
- "@cloud-ru/ds-materials": "2.0.3-preview-90b10112.0",
40
- "@cloud-ru/ds-tooltip": "1.0.19-preview-90b10112.0",
41
- "@cloud-ru/ds-truncate-string": "1.0.20-preview-90b10112.0",
42
- "@cloud-ru/ds-scroll": "1.0.7-preview-90b10112.0",
43
- "@cloud-ru/ds-utils": "1.3.1-preview-90b10112.0"
37
+ "@cloud-ru/ds-materials": "2.0.3-preview-e8fe6b56.0",
38
+ "@cloud-ru/ds-dropdown": "1.2.2-preview-e8fe6b56.0",
39
+ "@cloud-ru/ds-icons": "1.7.3-preview-e8fe6b56.0",
40
+ "@cloud-ru/ds-scroll": "1.0.7-preview-e8fe6b56.0",
41
+ "@cloud-ru/ds-tooltip": "1.0.19-preview-e8fe6b56.0",
42
+ "@cloud-ru/ds-truncate-string": "1.0.20-preview-e8fe6b56.0",
43
+ "@cloud-ru/ds-utils": "1.3.1-preview-e8fe6b56.0"
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 { withInnerRefSupport } from '@cloud-ru/ds-utils';
3
+ import { extractSupportProps, 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
- {...rest}
29
+ {...extractSupportProps(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} {...(item.href ? {} : { onDelete: handleRemoveItem?.(item) })} {...item} />
23
+ <Tag size={size} onDelete={handleRemoveItem?.(item)} {...item} />
24
24
  </div>
25
25
  );
26
26
  };
@@ -78,55 +78,44 @@ function TagRowTruncatedInner({
78
78
 
79
79
  const moreButtonWidth = hiddenMoreButtonRef.current?.offsetWidth || 0;
80
80
 
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
- });
81
+ let currentRowWidth = 0;
82
+ let currentRowCount = 1;
83
+ let currentRowVisibleTagAmount = 0;
102
84
 
103
- rowWidth = 0;
104
- rowCount = 1;
105
- rowItems = 0;
85
+ tagsMapRef.current.forEach((tagElement, tagRowItem) => {
86
+ const tagWidth = tagElement?.offsetWidth || 0;
87
+ const sumRowWidth = currentRowWidth + tagWidth + gapWidth;
106
88
 
107
- measuredTags.forEach(({ item, width }) => {
108
- if (allTagsFit) {
109
- newVisibleTags.push(item);
89
+ if (currentRowCount > rowLimit) {
90
+ newHiddenTags.push(tagRowItem);
110
91
  return;
111
92
  }
112
93
 
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;
94
+ if (currentRowCount === rowLimit) {
95
+ if (sumRowWidth + moreButtonWidth > maxWidth) {
96
+ currentRowCount++;
97
+ currentRowVisibleTagAmount = 0;
98
+ newHiddenTags.push(tagRowItem);
99
+ return;
100
+ }
101
+
102
+ currentRowWidth = sumRowWidth;
103
+ newVisibleTags.push(tagRowItem);
104
+ currentRowVisibleTagAmount++;
105
+ return;
119
106
  }
120
107
 
121
- if (rowCount > rowLimit || (rowCount === rowLimit && nextWidth + gapWidth + moreButtonWidth > maxWidth)) {
122
- rowCount = rowLimit + 1;
123
- newHiddenTags.push(item);
108
+ if (sumRowWidth > maxWidth) {
109
+ currentRowWidth = currentRowVisibleTagAmount ? tagWidth + gapWidth : 0;
110
+ currentRowCount++;
111
+ currentRowVisibleTagAmount = 0;
112
+ newVisibleTags.push(tagRowItem);
124
113
  return;
125
114
  }
126
115
 
127
- rowWidth = nextWidth;
128
- rowItems++;
129
- newVisibleTags.push(item);
116
+ currentRowVisibleTagAmount++;
117
+ currentRowWidth = sumRowWidth;
118
+ newVisibleTags.push(tagRowItem);
130
119
  });
131
120
 
132
121
  setVisibleTags(newVisibleTags);