@cloud-ru/ds-truncate-string 1.0.6-preview-a2208aeb.0 → 1.0.6-preview-94b5bdf7.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.
@@ -18,21 +18,29 @@ function TruncateStringEnd({ text, className, tooltipClassName, hideTooltip, max
18
18
  setShowTooltip((0, helpers_1.isEllipsisActive)(textElementRef.current));
19
19
  }, []);
20
20
  (0, utils_1.useLayoutEffect)(() => {
21
- if (textElementRef.current) {
22
- toggleShowTooltip();
21
+ if (hideTooltip || !textElementRef.current) {
22
+ return;
23
23
  }
24
- }, [text, toggleShowTooltip]);
24
+ toggleShowTooltip();
25
+ }, [text, toggleShowTooltip, hideTooltip]);
25
26
  (0, react_1.useEffect)(() => {
27
+ if (hideTooltip) {
28
+ return;
29
+ }
26
30
  const throttledToggleShowTooltip = (0, utils_1.throttle)(() => {
27
31
  toggleShowTooltip();
28
32
  }, 50);
29
- const observer = new ResizeObserver(throttledToggleShowTooltip);
30
- if (textElementRef.current) {
31
- toggleShowTooltip();
33
+ let observer;
34
+ const rafId = requestAnimationFrame(() => {
35
+ if (!textElementRef.current) {
36
+ return;
37
+ }
38
+ observer = new ResizeObserver(throttledToggleShowTooltip);
32
39
  observer.observe(textElementRef.current);
33
- }
40
+ });
34
41
  return () => {
35
- observer.disconnect();
42
+ cancelAnimationFrame(rafId);
43
+ observer?.disconnect();
36
44
  };
37
45
  }, [showTooltip, hideTooltip, toggleShowTooltip]);
38
46
  const textElement = ((0, jsx_runtime_1.jsx)("span", { ref: textElementRef, className: (0, classnames_1.default)(maxLines > 1 ? styles_module_scss_1.default.text2AndMoreLines : styles_module_scss_1.default.text1Line, className), style: { '--max-lines': maxLines }, ...(0, utils_1.extractSupportProps)(rest), children: text }));
@@ -18,6 +18,9 @@ function TruncateStringMiddle({ text, className, tooltipClassName, hideTooltip,
18
18
  const textElementRef = (0, react_1.useRef)(null);
19
19
  const truncatedTextElementRef = (0, react_1.useRef)(null);
20
20
  (0, react_1.useEffect)(() => {
21
+ if (hideTooltip) {
22
+ return;
23
+ }
21
24
  const setTruncate = (0, utils_1.throttle)(() => {
22
25
  setTruncatedString((0, helpers_1.truncateStringMiddle)({
23
26
  element: textElementRef.current,
@@ -27,12 +30,17 @@ function TruncateStringMiddle({ text, className, tooltipClassName, hideTooltip,
27
30
  setShowTooltip((0, helpers_1.isEllipsisActive)(textElementRef.current));
28
31
  }, 50);
29
32
  setTruncate();
30
- const observer = new ResizeObserver(setTruncate);
31
- if (textElementRef.current) {
33
+ let observer;
34
+ const rafId = requestAnimationFrame(() => {
35
+ if (!textElementRef.current) {
36
+ return;
37
+ }
38
+ observer = new ResizeObserver(setTruncate);
32
39
  observer.observe(textElementRef.current);
33
- }
40
+ });
34
41
  return () => {
35
- observer.disconnect();
42
+ cancelAnimationFrame(rafId);
43
+ observer?.disconnect();
36
44
  };
37
45
  }, [showTooltip, text, hideTooltip]);
38
46
  const textElement = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { ref: textElementRef, className: styles_module_scss_1.default.fullText, "data-test-id": constants_1.TEST_IDS.fullText, children: text }), (0, jsx_runtime_1.jsx)("span", { ref: truncatedTextElementRef, className: styles_module_scss_1.default.truncatedText, "data-test-id": constants_1.TEST_IDS.truncatedText, children: truncatedString })] }));
@@ -12,21 +12,29 @@ export function TruncateStringEnd({ text, className, tooltipClassName, hideToolt
12
12
  setShowTooltip(isEllipsisActive(textElementRef.current));
13
13
  }, []);
14
14
  useLayoutEffect(() => {
15
- if (textElementRef.current) {
16
- toggleShowTooltip();
15
+ if (hideTooltip || !textElementRef.current) {
16
+ return;
17
17
  }
18
- }, [text, toggleShowTooltip]);
18
+ toggleShowTooltip();
19
+ }, [text, toggleShowTooltip, hideTooltip]);
19
20
  useEffect(() => {
21
+ if (hideTooltip) {
22
+ return;
23
+ }
20
24
  const throttledToggleShowTooltip = throttle(() => {
21
25
  toggleShowTooltip();
22
26
  }, 50);
23
- const observer = new ResizeObserver(throttledToggleShowTooltip);
24
- if (textElementRef.current) {
25
- toggleShowTooltip();
27
+ let observer;
28
+ const rafId = requestAnimationFrame(() => {
29
+ if (!textElementRef.current) {
30
+ return;
31
+ }
32
+ observer = new ResizeObserver(throttledToggleShowTooltip);
26
33
  observer.observe(textElementRef.current);
27
- }
34
+ });
28
35
  return () => {
29
- observer.disconnect();
36
+ cancelAnimationFrame(rafId);
37
+ observer?.disconnect();
30
38
  };
31
39
  }, [showTooltip, hideTooltip, toggleShowTooltip]);
32
40
  const textElement = (_jsx("span", { ref: textElementRef, className: cn(maxLines > 1 ? styles.text2AndMoreLines : styles.text1Line, className), style: { '--max-lines': maxLines }, ...extractSupportProps(rest), children: text }));
@@ -12,6 +12,9 @@ export function TruncateStringMiddle({ text, className, tooltipClassName, hideTo
12
12
  const textElementRef = useRef(null);
13
13
  const truncatedTextElementRef = useRef(null);
14
14
  useEffect(() => {
15
+ if (hideTooltip) {
16
+ return;
17
+ }
15
18
  const setTruncate = throttle(() => {
16
19
  setTruncatedString(truncateStringMiddle({
17
20
  element: textElementRef.current,
@@ -21,12 +24,17 @@ export function TruncateStringMiddle({ text, className, tooltipClassName, hideTo
21
24
  setShowTooltip(isEllipsisActive(textElementRef.current));
22
25
  }, 50);
23
26
  setTruncate();
24
- const observer = new ResizeObserver(setTruncate);
25
- if (textElementRef.current) {
27
+ let observer;
28
+ const rafId = requestAnimationFrame(() => {
29
+ if (!textElementRef.current) {
30
+ return;
31
+ }
32
+ observer = new ResizeObserver(setTruncate);
26
33
  observer.observe(textElementRef.current);
27
- }
34
+ });
28
35
  return () => {
29
- observer.disconnect();
36
+ cancelAnimationFrame(rafId);
37
+ observer?.disconnect();
30
38
  };
31
39
  }, [showTooltip, text, hideTooltip]);
32
40
  const textElement = (_jsxs(_Fragment, { children: [_jsx("span", { ref: textElementRef, className: styles.fullText, "data-test-id": TEST_IDS.fullText, children: text }), _jsx("span", { ref: truncatedTextElementRef, className: styles.truncatedText, "data-test-id": TEST_IDS.truncatedText, children: truncatedString })] }));