lecom-ui 5.2.38 → 5.2.40

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.
@@ -20,34 +20,46 @@ const TagInput = ({
20
20
  const containerRef = React.useRef(null);
21
21
  const [visibleCount, setVisibleCount] = React.useState(value.length);
22
22
  const [hiddenCount, setHiddenCount] = React.useState(0);
23
+ const tagsToShow = visibleCount === 0 && value.length > 0 ? value : value.slice(0, visibleCount);
24
+ React.useEffect(() => {
25
+ setVisibleCount(value.length);
26
+ setHiddenCount(0);
27
+ }, [value.length]);
23
28
  React.useLayoutEffect(() => {
24
- if (!containerRef.current) return;
25
- const children = Array.from(containerRef.current.children).filter(
26
- (el) => el.dataset && el.dataset["tag"] === "true"
27
- );
28
- if (children.length === 0) {
29
- setVisibleCount(0);
30
- setHiddenCount(0);
31
- return;
32
- }
33
- const lines = [];
34
- children.forEach((child) => {
35
- const top = child.offsetTop;
36
- if (!lines.includes(top)) lines.push(top);
37
- });
38
- if (lines.length <= 2) {
39
- setVisibleCount(value.length);
40
- setHiddenCount(0);
41
- } else {
42
- const lastLine = lines[1];
43
- let count = 0;
44
- for (let i = 0; i < children.length; i++) {
45
- if (children[i].offsetTop > lastLine) break;
46
- count++;
29
+ const timer = setTimeout(() => {
30
+ if (!containerRef.current) {
31
+ setVisibleCount(value.length);
32
+ setHiddenCount(0);
33
+ return;
47
34
  }
48
- setVisibleCount(count);
49
- setHiddenCount(value.length - count);
50
- }
35
+ const children = Array.from(containerRef.current.children).filter(
36
+ (el) => el.dataset && el.dataset["tag"] === "true"
37
+ );
38
+ if (children.length === 0) {
39
+ setVisibleCount(value.length);
40
+ setHiddenCount(0);
41
+ return;
42
+ }
43
+ const lines = [];
44
+ children.forEach((child) => {
45
+ const top = child.offsetTop;
46
+ if (!lines.includes(top)) lines.push(top);
47
+ });
48
+ if (lines.length <= 2) {
49
+ setVisibleCount(value.length);
50
+ setHiddenCount(0);
51
+ } else {
52
+ const lastLine = lines[1];
53
+ let count = 0;
54
+ for (let i = 0; i < children.length; i++) {
55
+ if (children[i].offsetTop > lastLine) break;
56
+ count++;
57
+ }
58
+ setVisibleCount(count);
59
+ setHiddenCount(value.length - count);
60
+ }
61
+ }, 0);
62
+ return () => clearTimeout(timer);
51
63
  }, [value, size, variant, radius, className]);
52
64
  const handleRemoveHidden = () => {
53
65
  const hidden = value.slice(visibleCount);
@@ -68,7 +80,7 @@ const TagInput = ({
68
80
  ...props
69
81
  },
70
82
  value.length === 0 && /* @__PURE__ */ React.createElement(Typography, { variant: "body-small-400", className: "text-grey-400" }, placeholder),
71
- value.slice(0, visibleCount).map((item) => /* @__PURE__ */ React.createElement(Tag, { key: item.value, color: "blue", "data-tag": "true" }, /* @__PURE__ */ React.createElement(Typography, { variant: "body-small-400", className: "text-blue-600" }, item.label), !readOnly && /* @__PURE__ */ React.createElement(
83
+ tagsToShow.map((item) => /* @__PURE__ */ React.createElement(Tag, { key: item.value, color: "blue", "data-tag": "true" }, /* @__PURE__ */ React.createElement(Typography, { variant: "body-small-400", className: "text-blue-600" }, item.label), !readOnly && /* @__PURE__ */ React.createElement(
72
84
  X,
73
85
  {
74
86
  className: "w-4 h-4 cursor-pointer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lecom-ui",
3
- "version": "5.2.38",
3
+ "version": "5.2.40",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",