@box/blueprint-web 9.1.2 → 9.2.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.
@@ -0,0 +1,3 @@
1
+ import { type FocusableProps } from '@ariakit/react';
2
+ import React from 'react';
3
+ export declare const Focusable: React.ForwardRefExoticComponent<Omit<FocusableProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,35 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Focusable as Focusable$1 } from '@ariakit/react';
3
+ import { forwardRef, isValidElement } from 'react';
4
+ import { isProduction } from '../utils/is-production.js';
5
+ import { disabledFromProps } from '../utils/disabledFromProps.js';
6
+
7
+ const Focusable = /*#__PURE__*/forwardRef((props, forwardedRef) => {
8
+ const {
9
+ children,
10
+ focusable = true,
11
+ ...restProps
12
+ } = props;
13
+ if (! /*#__PURE__*/isValidElement(children)) {
14
+ if (!isProduction()) {
15
+ /* eslint-disable-next-line no-console */
16
+ console.error('Focusable children must be a valid React element.');
17
+ }
18
+ return children;
19
+ }
20
+ const isChildDisabled = disabledFromProps(children.props);
21
+ const renderProps = isChildDisabled ? {
22
+ children
23
+ } : {
24
+ render: children
25
+ };
26
+ return jsx(Focusable$1, {
27
+ ref: forwardedRef,
28
+ focusable: focusable,
29
+ tabIndex: focusable ? 0 : undefined,
30
+ ...restProps,
31
+ ...renderProps
32
+ });
33
+ });
34
+
35
+ export { Focusable };
@@ -0,0 +1 @@
1
+ export { Focusable } from './focusable';
@@ -17,6 +17,7 @@ export * from './data-table/data-table';
17
17
  export * from './date-picker';
18
18
  export * from './divider';
19
19
  export * from './empty-state';
20
+ export * from './focusable';
20
21
  export * from './ghost';
21
22
  export * from './grid-list-item';
22
23
  export * from './guided-tooltip';
package/lib-esm/index.js CHANGED
@@ -20,6 +20,7 @@ export { DataTableWrapper, StickyCell } from './data-table/data-table.js';
20
20
  export { DatePicker } from './date-picker/date-picker.js';
21
21
  export { Divider } from './divider/divider.js';
22
22
  export { EmptyState } from './empty-state/empty-state.js';
23
+ export { Focusable } from './focusable/focusable.js';
23
24
  export { Ghost } from './ghost/ghost.js';
24
25
  export { GridList } from './grid-list-item/index.js';
25
26
  export { GuidedTooltip } from './guided-tooltip/guided-tooltip.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks whether something is disabled or not based on its props.
3
+ * Provided by ariakit https://github.com/ariakit/ariakit/blob/main/packages/ariakit-core/src/utils/misc.ts
4
+ */
5
+ export declare function disabledFromProps(props: {
6
+ disabled?: boolean;
7
+ 'aria-disabled'?: boolean | 'true' | 'false';
8
+ }): boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Checks whether something is disabled or not based on its props.
3
+ * Provided by ariakit https://github.com/ariakit/ariakit/blob/main/packages/ariakit-core/src/utils/misc.ts
4
+ */
5
+ function disabledFromProps(props) {
6
+ return props.disabled || props['aria-disabled'] === true || props['aria-disabled'] === 'true';
7
+ }
8
+
9
+ export { disabledFromProps };
@@ -0,0 +1 @@
1
+ export declare const isProduction: () => boolean;
@@ -0,0 +1,3 @@
1
+ const isProduction = () => process.env.NODE_ENV === 'production';
2
+
3
+ export { isProduction };
@@ -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.2.0",
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": "aea7aacd8bd8226934231748787d65edac379e02",
67
67
  "module": "lib-esm/index.js",
68
68
  "main": "lib-esm/index.js",
69
69
  "exports": {