lecom-ui 5.2.95 → 5.2.97

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.
@@ -35,7 +35,7 @@ function HiddenCountTag({
35
35
  },
36
36
  [onRemoveHidden]
37
37
  );
38
- return /* @__PURE__ */ React.createElement(Tag, { color: "grey", "data-tag": "true" }, /* @__PURE__ */ React.createElement(Typography, { variant: "body-small-400", className: "text-grey-600" }, "+", count), !readOnly && /* @__PURE__ */ React.createElement(
38
+ return /* @__PURE__ */ React.createElement(Tag, { color: "blue", "data-tag": "true" }, /* @__PURE__ */ React.createElement(Typography, { variant: "body-small-400", className: "text-blue-600" }, "+", count), !readOnly && /* @__PURE__ */ React.createElement(
39
39
  X,
40
40
  {
41
41
  className: "w-4 h-4 cursor-pointer",
@@ -46,18 +46,20 @@ function HiddenCountTag({
46
46
  ));
47
47
  }
48
48
  function useTagVisibility(ref, value) {
49
+ const getInitialEstimate = React.useCallback((totalTags) => {
50
+ if (totalTags <= 3) return totalTags;
51
+ if (totalTags <= 4) return totalTags;
52
+ return Math.min(5, totalTags);
53
+ }, []);
49
54
  const [maxVisibleCount, setMaxVisibleCount] = React.useState(
50
- null
55
+ () => getInitialEstimate(value.length)
51
56
  );
52
57
  const [hiddenCount, setHiddenCount] = React.useState(0);
53
58
  const calculateVisibleTags = React.useCallback(
54
59
  (children, totalTags) => {
55
- if (children.length === 0 || totalTags === 0) {
60
+ if (children.length === 0 || totalTags === 0)
56
61
  return { visibleCount: 0, hiddenCount: 0 };
57
- }
58
- if (totalTags <= 3) {
59
- return { visibleCount: totalTags, hiddenCount: 0 };
60
- }
62
+ if (totalTags <= 3) return { visibleCount: totalTags, hiddenCount: 0 };
61
63
  const offsetTops = [...new Set(children.map((c) => c.offsetTop))].sort(
62
64
  (a, b) => a - b
63
65
  );
@@ -77,13 +79,9 @@ function useTagVisibility(ref, value) {
77
79
  }
78
80
  const maxSecondLineVisible = Math.min(secondLineCount, 2);
79
81
  const visibleCount = firstLineCount + maxSecondLineVisible;
80
- if (visibleCount >= totalTags) {
81
- return { visibleCount: totalTags, hiddenCount: 0 };
82
- }
83
- const hiddenCount2 = totalTags - visibleCount;
84
82
  return {
85
83
  visibleCount,
86
- hiddenCount: hiddenCount2
84
+ hiddenCount: Math.max(totalTags - visibleCount, 0)
87
85
  };
88
86
  },
89
87
  []
@@ -102,7 +100,11 @@ function useTagVisibility(ref, value) {
102
100
  setHiddenCount(newHiddenCount);
103
101
  }, [ref, calculateVisibleTags, value.length]);
104
102
  React.useLayoutEffect(() => {
105
- calculateMaxVisible();
103
+ requestAnimationFrame(() => {
104
+ requestAnimationFrame(() => {
105
+ calculateMaxVisible();
106
+ });
107
+ });
106
108
  const resizeObserver = new ResizeObserver(() => {
107
109
  calculateMaxVisible();
108
110
  });
@@ -114,13 +116,11 @@ function useTagVisibility(ref, value) {
114
116
  };
115
117
  }, [value, calculateMaxVisible, ref]);
116
118
  React.useEffect(() => {
117
- if (ref.current) {
118
- const timeoutId = setTimeout(() => {
119
- calculateMaxVisible();
120
- }, 0);
121
- return () => clearTimeout(timeoutId);
122
- }
123
- }, [value.length, calculateMaxVisible, ref]);
119
+ const timeout = setTimeout(() => {
120
+ calculateMaxVisible();
121
+ }, 150);
122
+ return () => clearTimeout(timeout);
123
+ }, [value.length, calculateMaxVisible]);
124
124
  return { maxVisibleCount, hiddenCount };
125
125
  }
126
126
  function TagInput(props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lecom-ui",
3
- "version": "5.2.95",
3
+ "version": "5.2.97",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",