@box/blueprint-web 9.1.2 → 9.1.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.
@@ -1,16 +1,15 @@
1
- import { type MutableRefObject, type ReactNode } from 'react';
2
- export declare const useFullTextTooltip: ({ ref, children, textValue, skipOverflowCheck, }: {
3
- ref: MutableRefObject<null> | MutableRefObject<HTMLSpanElement>;
4
- children?: ReactNode;
5
- textValue?: string;
6
- skipOverflowCheck?: boolean;
7
- }) => {
8
- Wrapper: ((props: import("../tooltip").TooltipProps) => import("react/jsx-runtime").JSX.Element) | import("react").ExoticComponent<{
9
- children?: ReactNode | undefined;
10
- }>;
11
- wrapperProps: {
12
- content: ReactNode;
13
- } | {
14
- content?: undefined;
1
+ import { type ComponentType, type MutableRefObject, type ReactNode } from 'react';
2
+ import { type TooltipProps } from '../tooltip';
3
+ interface UseFullTextTooltip {
4
+ (args: {
5
+ ref: MutableRefObject<HTMLSpanElement | null>;
6
+ children?: ReactNode;
7
+ textValue?: string;
8
+ skipOverflowCheck?: boolean;
9
+ }): {
10
+ Wrapper: ComponentType<TooltipProps>;
11
+ wrapperProps: Record<symbol, never>;
15
12
  };
16
- };
13
+ }
14
+ export declare const useFullTextTooltip: UseFullTextTooltip;
15
+ export {};
@@ -1,48 +1,23 @@
1
- import { useState, useEffect, Fragment } from 'react';
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Fragment } from 'react';
2
3
  import { Tooltip } from '../tooltip/tooltip.js';
3
- import { debounce } from './debounce.js';
4
+ import { useIsEllipsized } from './useIsEllipsized.js';
4
5
 
5
6
  const useFullTextTooltip = ({
6
7
  ref,
7
8
  children,
8
9
  textValue,
9
- skipOverflowCheck
10
+ skipOverflowCheck = false
10
11
  }) => {
11
- const [isOverflowing, setIsOverflowing] = useState(false);
12
- useEffect(() => {
13
- const checkIfOverflowing = () => {
14
- const element = ref?.current;
15
- if (element && !skipOverflowCheck) {
16
- setIsOverflowing(element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth);
17
- }
18
- };
19
- // Create debounced version of checkIfOverflowing
20
- const debouncedCheckIfOverflowing = debounce(checkIfOverflowing, 100);
21
- const element = ref?.current;
22
- let resizeObserver = null;
23
- if (element) {
24
- // Create a ResizeObserver to observe the size of the element
25
- resizeObserver = new ResizeObserver(debouncedCheckIfOverflowing);
26
- resizeObserver.observe(element);
27
- }
28
- // Initial check
29
- debouncedCheckIfOverflowing();
30
- // Cleanup function to disconnect the observer and clear debounced timeouts
31
- return () => {
32
- if (resizeObserver && element) {
33
- resizeObserver.unobserve(element);
34
- resizeObserver.disconnect();
35
- }
36
- debouncedCheckIfOverflowing.clear();
37
- };
38
- }, [ref, skipOverflowCheck, textValue, children]);
39
- const Wrapper = isOverflowing ? Tooltip : Fragment;
40
- const wrapperProps = isOverflowing ? {
12
+ const isEllipsized = useIsEllipsized(ref);
13
+ const shouldWrapInTooltip = isEllipsized && !skipOverflowCheck;
14
+ const Wrapper = shouldWrapInTooltip ? props => jsx(Tooltip, {
15
+ ...props,
41
16
  content: textValue ?? children
42
- } : {};
17
+ }) : Fragment;
43
18
  return {
44
19
  Wrapper,
45
- wrapperProps
20
+ wrapperProps: {}
46
21
  };
47
22
  };
48
23
 
@@ -0,0 +1 @@
1
+ export declare const useIsEllipsized: (ref: React.RefObject<HTMLElement>) => boolean;
@@ -0,0 +1,28 @@
1
+ import { useState, useEffect } from 'react';
2
+ import noop from 'lodash/noop';
3
+
4
+ const useIsEllipsized = ref => {
5
+ const [isEllipsized, setIsEllipsized] = useState(false);
6
+ useEffect(() => {
7
+ const element = ref.current;
8
+ if (!element) {
9
+ return noop;
10
+ }
11
+ let rafID;
12
+ const checkIfEllipsized = () => {
13
+ rafID = requestAnimationFrame(() => {
14
+ const isOverflowing = element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
15
+ setIsEllipsized(isOverflowing);
16
+ });
17
+ };
18
+ const observer = new ResizeObserver(checkIfEllipsized);
19
+ observer.observe(element);
20
+ return () => {
21
+ observer.disconnect();
22
+ cancelAnimationFrame(rafID);
23
+ };
24
+ }, [ref, isEllipsized]);
25
+ return isEllipsized;
26
+ };
27
+
28
+ export { useIsEllipsized };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/blueprint-web",
3
- "version": "9.1.2",
3
+ "version": "9.1.3",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "publishConfig": {
@@ -63,7 +63,7 @@
63
63
  "react-stately": "^3.31.1",
64
64
  "tsx": "^4.16.5"
65
65
  },
66
- "gitHead": "422c5a76116e547d351ab83cdab9d97b4d7ce621",
66
+ "gitHead": "9a853cf5c13b885475cc76128d6eebeb1de4788a",
67
67
  "module": "lib-esm/index.js",
68
68
  "main": "lib-esm/index.js",
69
69
  "exports": {