@canonical/react-ds-global 0.48.0 → 0.50.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.
Files changed (54) hide show
  1. package/dist/esm/lib/_work_in_progress/Announcement/styles.css +4 -4
  2. package/dist/esm/lib/_work_in_progress/Label/styles.css +1 -7
  3. package/dist/esm/lib/component/Accordion/common/Item/styles.css +5 -6
  4. package/dist/esm/lib/component/Accordion/styles.css +3 -9
  5. package/dist/esm/lib/component/Breadcrumbs/common/Item/styles.css +6 -14
  6. package/dist/esm/lib/component/Breadcrumbs/styles.css +2 -9
  7. package/dist/esm/lib/component/Button/Button.js +28 -12
  8. package/dist/esm/lib/component/Button/Button.js.map +1 -1
  9. package/dist/esm/lib/component/Button/styles.css +48 -18
  10. package/dist/esm/lib/component/Card/common/Content/styles.css +4 -5
  11. package/dist/esm/lib/component/Card/common/Header/styles.css +1 -2
  12. package/dist/esm/lib/component/Card/styles.css +1 -2
  13. package/dist/esm/lib/component/ContextualMenu/common/Item/styles.css +6 -9
  14. package/dist/esm/lib/component/ContextualMenu/styles.css +6 -7
  15. package/dist/esm/lib/component/Icon/styles.css +3 -7
  16. package/dist/esm/lib/component/InlineCode/styles.css +2 -3
  17. package/dist/esm/lib/component/KeyboardKey/styles.css +6 -8
  18. package/dist/esm/lib/component/Tabs/common/Item/styles.css +1 -1
  19. package/dist/esm/lib/component/Tabs/styles.css +4 -8
  20. package/dist/esm/lib/component/Tile/common/Content/styles.css +2 -5
  21. package/dist/esm/lib/component/Tile/common/Header/styles.css +3 -6
  22. package/dist/esm/lib/component/Tile/styles.css +1 -5
  23. package/dist/esm/lib/component/Tooltip/Tooltip.js.map +1 -1
  24. package/dist/esm/lib/component/Tooltip/TooltipEngine.js +91 -15
  25. package/dist/esm/lib/component/Tooltip/TooltipEngine.js.map +1 -1
  26. package/dist/esm/lib/component/Tooltip/hooks/useTooltipState.js +89 -0
  27. package/dist/esm/lib/component/Tooltip/hooks/useTooltipState.js.map +1 -0
  28. package/dist/esm/lib/component/Tooltip/styles.css +151 -80
  29. package/dist/esm/lib/component/Tooltip/withTooltip.js +3 -3
  30. package/dist/esm/lib/group/KeyboardKeys/styles.css +1 -1
  31. package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js +172 -173
  32. package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js.map +1 -1
  33. package/dist/esm/lib/pattern/Modal/common/Content/styles.css +3 -6
  34. package/dist/esm/lib/pattern/Modal/common/Footer/styles.css +1 -1
  35. package/dist/esm/lib/pattern/Modal/common/Header/styles.css +3 -9
  36. package/dist/esm/lib/pattern/Modal/styles.css +14 -20
  37. package/dist/esm/lib/pattern/Timeline/common/Content/styles.css +1 -4
  38. package/dist/esm/lib/pattern/Timeline/common/Event/styles.css +6 -13
  39. package/dist/esm/lib/pattern/Timeline/styles.css +1 -4
  40. package/dist/types/lib/component/Button/Button.d.ts +4 -1
  41. package/dist/types/lib/component/Button/Button.d.ts.map +1 -1
  42. package/dist/types/lib/component/Button/types.d.ts +15 -4
  43. package/dist/types/lib/component/Button/types.d.ts.map +1 -1
  44. package/dist/types/lib/component/Tooltip/Tooltip.d.ts.map +1 -1
  45. package/dist/types/lib/component/Tooltip/TooltipEngine.d.ts +6 -4
  46. package/dist/types/lib/component/Tooltip/TooltipEngine.d.ts.map +1 -1
  47. package/dist/types/lib/component/Tooltip/hooks/useTooltipState.d.ts +17 -0
  48. package/dist/types/lib/component/Tooltip/hooks/useTooltipState.d.ts.map +1 -0
  49. package/dist/types/lib/component/Tooltip/types.d.ts +27 -2
  50. package/dist/types/lib/component/Tooltip/types.d.ts.map +1 -1
  51. package/dist/types/lib/component/Tooltip/withTooltip.d.ts +3 -3
  52. package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts +22 -1
  53. package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -1
  54. package/package.json +23 -14
@@ -5,12 +5,8 @@
5
5
  * Tabs styles
6
6
  * @implements ds:global.component.tabs
7
7
  *
8
- * DSL anatomy mapping:
9
- * - layout.type: stack, layout.direction: horizontal -> flex row of tabs
10
- * - edges: tabs-tab (1..*), slot default -> the <li> children of .tabs-list
11
- *
12
- * Figma (node 4388-106316): a horizontal strip of tabs with no gap between
13
- * them, over a full-width muted bottom border; the strip fills its container
8
+ * A horizontal strip of one or more tabs (the <li> children of .tabs-list)
9
+ * with no gap between them, over a full-width muted bottom border; the strip fills its container
14
10
  * and scrolls horizontally on overflow.
15
11
  */
16
12
  :root {
@@ -24,7 +20,7 @@
24
20
  .ds.tabs .tabs-list {
25
21
  display: flex;
26
22
  flex-direction: row;
27
- /* No gap between tabs (Figma). */
23
+ /* No gap between tabs. */
28
24
  gap: 0;
29
25
  margin: 0;
30
26
  padding: 0;
@@ -35,7 +31,7 @@
35
31
  border-bottom: var(--tabs-border-width) solid var(--color-border-muted);
36
32
 
37
33
  /* Overflow: the strip scrolls horizontally when the tabs exceed the
38
- container width (Figma "Overflow"). */
34
+ container width. */
39
35
  overflow-x: auto;
40
36
  }
41
37
  }
@@ -5,11 +5,8 @@
5
5
  * Tile.Content styles
6
6
  * @implements ds:global.subcomponent.tile-content
7
7
  *
8
- * DSL anatomy mapping:
9
- * - layout.type: stack, layout.direction: vertical -> flex column
10
- * - spacing.padding.top: dimension/100, spacing.padding.bottom: dimension/200,
11
- * spacing.internal.horizontal: dimension/200 -> top 100, bottom 200,
12
- * sides 200. With a header above (padding-bottom 100), the two sections read
8
+ * A vertical stack padded top 100, bottom 200 and sides 200. With a header
9
+ * above (padding-bottom 100), the two sections read
13
10
  * as top 100 / sides 200 / bottom 200 with the sections meeting in between.
14
11
  */
15
12
  :root {
@@ -5,12 +5,9 @@
5
5
  * Tile.Header styles
6
6
  * @implements ds:global.subcomponent.tile-header
7
7
  *
8
- * DSL anatomy mapping:
9
- * - layout.type: flow, layout.direction: horizontal -> flex row
10
- * - layout.align: center -> align-items: center
11
- * - spacing.internal.vertical: dimension/100, spacing.internal.horizontal:
12
- * dimension/200 -> padding 100 (block) / 200 (inline). The header's block
13
- * padding is 100 top and bottom; the content below adds its own top padding.
8
+ * A row with its items centred, padded 100 (block) and 200 (inline). The
9
+ * header's block padding is 100 top and bottom; the content below adds its
10
+ * own top padding.
14
11
  */
15
12
  :root {
16
13
  --tile-header-padding-block: var(--dimension-100);
@@ -10,11 +10,7 @@
10
10
  * nest). It paints that background so it stands out on the page (dashboards,
11
11
  * bento layouts). It shares the Card radius and has no border of its own. It is
12
12
  * a static container — no cursor, hover, or focus affordance.
13
- *
14
- * DSL anatomy mapping:
15
- * - layout.type: stack, layout.direction: vertical -> flex column
16
- * - appearance.background: color/surface/tile -> the surface background channel
17
- * - appearance.radius: radius/card -> shared card radius (--dimension-radius-medium)
13
+ * Its sections stack vertically.
18
14
  */
19
15
  :root {
20
16
  /* Shared with Card. --dimension-radius-medium is currently 0; intended 9. */
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../../src/lib/component/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AACA,OAAO,cAAc,CAAC;AAGtB,8EAA8E;AAC9E,4CAA4C;AAC5C,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,GAAG,CAAC,EACf,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,KAAK,EACL,MAAM,GAAG,KAAK,EACd,MAAM,EACN,GAAG,KAAK,EACK,EAAsB,EAAE;IACrC,OAAO,CAIL,iBACM,KAAK,EACT,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACvE,IAAI,EAAC,SAAS,iBACD,CAAC,MAAM,EACpB,KAAK,EAAE;YACL,GAAG,KAAK;YACR,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ;YACzC,MAAM;SACP,YAID,gBAAM,SAAS,EAAC,SAAS,aAEtB,IAAI,CAAC,CAAC,CAAC,CACN,eAAM,SAAS,EAAC,MAAM,iBAAa,MAAM,YACtC,IAAI,GACA,CACR,CAAC,CAAC,CAAC,IAAI,EACR,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,IACnC,GACH,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../../src/lib/component/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AACA,OAAO,cAAc,CAAC;AAGtB,8EAA8E;AAC9E,4CAA4C;AAC5C,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,GAAG,CAAC,EACf,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,KAAK,EACL,MAAM,GAAG,KAAK,EACd,MAAM,EACN,GAAG,KAAK,EACK,EAAsB,EAAE;IACrC,OAAO,CAIL,iBACM,KAAK,EACT,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACvE,IAAI,EAAC,SAAS,iBACD,CAAC,MAAM,EACpB,KAAK,EAAE;YACL,GAAG,KAAK;YACR,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ;YACzC,MAAM;SACP,YAKD,gBAAM,SAAS,EAAC,SAAS,aAEtB,IAAI,CAAC,CAAC,CAAC,CACN,eAAM,SAAS,EAAC,MAAM,iBAAa,MAAM,YACtC,IAAI,GACA,CACR,CAAC,CAAC,CAAC,IAAI,EACR,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,IACnC,GACH,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -1,32 +1,95 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cloneElement, isValidElement, useCallback, useEffect, useId, useRef, } from "react";
2
3
  import { createPortal } from "react-dom";
3
- import { useDisclosure, useIsMounted } from "../../hooks/index.js";
4
+ import { useIsMounted, useWindowFitment, } from "../../hooks/index.js";
5
+ import useTooltipState from "./hooks/useTooltipState.js";
4
6
  import Tooltip from "./Tooltip.js";
5
7
  import "./styles.css";
6
8
  const componentCssClassName = "ds tooltip-area";
9
+ const isDisabled = (event) => Boolean(event.target?.disabled);
7
10
  /**
8
11
  * The tooltip engine: wraps a target element with a hover/focus tooltip. It
9
- * drives {@link useDisclosure} in `hover` mode, portals the message to the
10
- * client only, positions it against the target span, and points the arrow.
12
+ * opens after a delay on hover or keyboard focus, closes on pointer leave,
13
+ * blur or Escape, keeps only one tooltip open at a time, portals the message
14
+ * to the client only, positions it against the target span, and points the
15
+ * arrow. Touch input never opens it.
11
16
  * {@link withTooltip} builds on this; render it directly when the message
12
17
  * must follow prop state (e.g. a toggle whose tooltip names the current
13
18
  * action).
14
19
  *
15
20
  * `import { TooltipEngine } from "@canonical/react-ds-global";`
16
21
  */
17
- const TooltipEngine = ({ children, style, className, Message, icon, open, distance = "16px", targetElementId, targetElementClassName, targetElementStyle, messageElementClassName, messageElementStyle, parentElement, autoFit, ...props }) => {
18
- const { targetRef, popupRef, popupPositionStyle, popupId, isOpen, bestPosition, arrowOffset, getToggleProps, getContentProps,
19
- // `open` is the public alias for the hook's controlled `isOpen`; when set it
22
+ const TooltipEngine = ({ children, style, className, Message, icon, open: openProp, isOpen: isOpenProp, activateDelay, deactivateDelay, onShow, onHide, onEnter, onLeave, onFocus, onBlur, closeOnEscape = true, closeOnOutsideClick: _closeOnOutsideClick, returnFocus: _returnFocus, distance = "16px", gutter = "24px", maxWidth = "284px", autoFit = true, targetElementId, targetElementClassName, targetElementStyle, messageElementClassName, messageElementStyle, parentElement, ...props }) => {
23
+ const isServer = typeof window === "undefined";
24
+ const popupId = useId();
25
+ const { isOpen: isOpenInternal, skipTransition, scheduleShow, scheduleHide, hide, } = useTooltipState({
26
+ activateDelay,
27
+ deactivateDelay,
28
+ onShow,
29
+ onHide,
30
+ });
31
+ // `open` (or the `isOpen` alias) makes the tooltip controlled: a boolean
20
32
  // overrides hover/focus so the tooltip stays in the given state.
21
- } = useDisclosure({
33
+ const controlledOpen = openProp ?? isOpenProp;
34
+ const isControlled = typeof controlledOpen === "boolean";
35
+ const isOpen = isControlled ? controlledOpen : isOpenInternal;
36
+ const { targetRef, popupRef, popupPositionStyle, bestPosition, arrowOffset } = useWindowFitment({
37
+ ...props,
22
38
  distance,
39
+ gutter,
40
+ maxWidth,
23
41
  autoFit,
24
- ...props,
25
- isOpen: open ?? props.isOpen,
26
- mode: "hover",
42
+ isOpen,
27
43
  });
28
- const triggerProps = getToggleProps();
29
- const contentProps = getContentProps();
44
+ // The pointer that last pressed the trigger. A tap focuses the trigger, and
45
+ // touch input must not open the tooltip, so focus that follows a touch press
46
+ // is ignored until the trigger blurs.
47
+ const lastPointerType = useRef(null);
48
+ const handlePointerDown = useCallback((event) => {
49
+ lastPointerType.current = event.pointerType;
50
+ }, []);
51
+ const handlePointerEnter = useCallback((event) => {
52
+ if (isServer || event.pointerType === "touch" || isDisabled(event)) {
53
+ return;
54
+ }
55
+ if (!isControlled)
56
+ scheduleShow();
57
+ onEnter?.(event);
58
+ }, [isServer, isControlled, scheduleShow, onEnter]);
59
+ const handlePointerLeave = useCallback((event) => {
60
+ if (isServer || event.pointerType === "touch" || isDisabled(event)) {
61
+ return;
62
+ }
63
+ if (!isControlled)
64
+ scheduleHide();
65
+ onLeave?.(event);
66
+ }, [isServer, isControlled, scheduleHide, onLeave]);
67
+ const handleFocus = useCallback((event) => {
68
+ if (isServer)
69
+ return;
70
+ if (!isControlled && lastPointerType.current !== "touch")
71
+ scheduleShow();
72
+ onFocus?.(event);
73
+ }, [isServer, isControlled, scheduleShow, onFocus]);
74
+ const handleBlur = useCallback((event) => {
75
+ if (isServer)
76
+ return;
77
+ lastPointerType.current = null;
78
+ if (!isControlled)
79
+ scheduleHide();
80
+ onBlur?.(event);
81
+ }, [isServer, isControlled, scheduleHide, onBlur]);
82
+ // Escape closes the tooltip without moving focus.
83
+ useEffect(() => {
84
+ if (isServer || isControlled || !closeOnEscape || !isOpen)
85
+ return;
86
+ const handleEscape = (event) => {
87
+ if (event.key === "Escape")
88
+ hide();
89
+ };
90
+ document.addEventListener("keydown", handleEscape);
91
+ return () => document.removeEventListener("keydown", handleEscape);
92
+ }, [isServer, isControlled, closeOnEscape, isOpen, hide]);
30
93
  // The message is portalled to the client only. Rendering it on the server (or
31
94
  // on the first client render) would differ from the post-mount portal output
32
95
  // and force a hydration mismatch + full re-mount — which resets the fitment
@@ -43,9 +106,21 @@ const TooltipEngine = ({ children, style, className, Message, icon, open, distan
43
106
  : "--tooltip-arrow-offset-top"]: `${arrowOffset.offset}px`,
44
107
  }
45
108
  : {};
109
+ // The description is announced from the focusable trigger itself, so a
110
+ // single element child is given the reference directly, merged with any it
111
+ // already carries.
112
+ const target = isValidElement(children)
113
+ ? cloneElement(children, {
114
+ "aria-describedby": [children.props["aria-describedby"], popupId]
115
+ .filter(Boolean)
116
+ .join(" "),
117
+ })
118
+ : children;
46
119
  const TooltipMessageElement = (_jsx(Tooltip, { id: popupId, className: [bestPosition?.positionName, messageElementClassName]
47
120
  .filter(Boolean)
48
- .join(" "), icon: icon, onPointerEnter: contentProps.onPointerEnter, ref: popupRef, style: {
121
+ .join(" "), icon: icon, "data-transition": skipTransition && !isOpen ? "none" : undefined,
122
+ // Moving the pointer onto the tooltip keeps it open.
123
+ onPointerEnter: handlePointerEnter, onPointerLeave: handlePointerLeave, ref: popupRef, style: {
49
124
  ...messageElementStyle,
50
125
  ...popupPositionStyle,
51
126
  ...arrowStyle,
@@ -54,9 +129,10 @@ const TooltipEngine = ({ children, style, className, Message, icon, open, distan
54
129
  // exists the popup would render at the fallback top:0/left:0 with no
55
130
  // placement class (and so no arrow); gating the reveal on it means that
56
131
  // unpositioned frame stays `visibility:hidden` and never paints — no
57
- // visible 0,0 flash, and the open fade always runs from an anchored spot.
132
+ // visible 0,0 flash, and the open transition always runs from an
133
+ // anchored spot.
58
134
  isOpen: isOpen && Boolean(bestPosition), children: Message }));
59
- return (_jsxs("span", { className: [componentCssClassName, className].filter(Boolean).join(" "), style: style, onFocus: triggerProps.onFocus, onBlur: triggerProps.onBlur, onPointerEnter: triggerProps.onPointerEnter, onPointerLeave: triggerProps.onPointerLeave, children: [_jsx("span", { id: targetElementId, style: targetElementStyle, className: ["target", targetElementClassName].filter(Boolean).join(" "), ref: targetRef, "aria-describedby": popupId, children: children }), mounted
135
+ return (_jsxs("span", { className: [componentCssClassName, className].filter(Boolean).join(" "), style: style, onFocus: handleFocus, onBlur: handleBlur, onPointerDown: handlePointerDown, onPointerEnter: handlePointerEnter, onPointerLeave: handlePointerLeave, children: [_jsx("span", { id: targetElementId, style: targetElementStyle, className: ["target", targetElementClassName].filter(Boolean).join(" "), ref: targetRef, "aria-describedby": popupId, children: target }), mounted
60
136
  ? createPortal(TooltipMessageElement, parentElement || document.body)
61
137
  : null] }));
62
138
  };
@@ -1 +1 @@
1
- {"version":3,"file":"TooltipEngine.js","sourceRoot":"","sources":["../../../../../src/lib/component/Tooltip/TooltipEngine.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAEhD;;;;;;;;;GASG;AACH,MAAM,aAAa,GAAG,CAAC,EACrB,QAAQ,EACR,KAAK,EACL,SAAS,EACT,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,QAAQ,GAAG,MAAM,EACjB,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAm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AAI,CAAC,GAAG,CAAC,EACvE,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,iBAAiB,EAChC,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,aAElC,eACE,EAAE,EAAE,eAAe,EACnB,KAAK,EAAE,kBAAkB,EACzB,SAAS,EAAE,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACvE,GAAG,EAAE,SAAS,sBACI,OAAO,YAExB,MAAM,GACF,EAMN,OAAO;gBACN,CAAC,CAAC,YAAY,CAAC,qBAAqB,EAAE,aAAa,IAAI,QAAQ,CAAC,IAAI,CAAC;gBACrE,CAAC,CAAC,IAAI,IACH,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ /**
3
+ * The tooltip that is currently open, shared by every tooltip on the page.
4
+ * Only one is open at a time: opening another dismisses this one at once.
5
+ */
6
+ let openTooltip = null;
7
+ /**
8
+ * Manages the open state of one hover/focus tooltip.
9
+ *
10
+ * Opening and closing are delayed, and a close scheduled before the open
11
+ * delay elapses cancels the open. While another tooltip is open, a new one
12
+ * opens immediately and the previous one closes without its exit transition,
13
+ * so moving the pointer from one trigger to the next feels continuous.
14
+ *
15
+ * @param activateDelay Delay in milliseconds before opening. Defaults to 400.
16
+ * @param deactivateDelay Delay in milliseconds before closing. Defaults to 400.
17
+ * @param onShow Called when the tooltip opens.
18
+ * @param onHide Called when the tooltip closes.
19
+ */
20
+ const useTooltipState = ({ activateDelay = 400, deactivateDelay = 400, onShow, onHide, }) => {
21
+ const [isOpen, setIsOpen] = useState(false);
22
+ const [skipTransition, setSkipTransition] = useState(false);
23
+ const isOpenRef = useRef(false);
24
+ const timer = useRef(undefined);
25
+ const callbacks = useRef({ onShow, onHide });
26
+ callbacks.current = { onShow, onHide };
27
+ const clearTimer = useCallback(() => {
28
+ if (timer.current)
29
+ clearTimeout(timer.current);
30
+ timer.current = undefined;
31
+ }, []);
32
+ const setOpen = useCallback((next) => {
33
+ if (isOpenRef.current === next)
34
+ return;
35
+ isOpenRef.current = next;
36
+ setIsOpen(next);
37
+ if (next)
38
+ callbacks.current.onShow?.();
39
+ else
40
+ callbacks.current.onHide?.();
41
+ }, []);
42
+ const entry = useRef({ dismiss: () => { } });
43
+ entry.current.dismiss = () => {
44
+ clearTimer();
45
+ setSkipTransition(true);
46
+ setOpen(false);
47
+ };
48
+ const show = useCallback(() => {
49
+ clearTimer();
50
+ if (openTooltip && openTooltip !== entry.current)
51
+ openTooltip.dismiss();
52
+ openTooltip = entry.current;
53
+ setSkipTransition(false);
54
+ setOpen(true);
55
+ }, [clearTimer, setOpen]);
56
+ const hide = useCallback(() => {
57
+ clearTimer();
58
+ if (openTooltip === entry.current)
59
+ openTooltip = null;
60
+ setOpen(false);
61
+ }, [clearTimer, setOpen]);
62
+ const scheduleShow = useCallback(() => {
63
+ clearTimer();
64
+ if (isOpenRef.current)
65
+ return;
66
+ if (openTooltip && openTooltip !== entry.current) {
67
+ show();
68
+ return;
69
+ }
70
+ timer.current = setTimeout(show, activateDelay);
71
+ }, [activateDelay, clearTimer, show]);
72
+ const scheduleHide = useCallback(() => {
73
+ clearTimer();
74
+ if (!isOpenRef.current)
75
+ return;
76
+ timer.current = setTimeout(hide, deactivateDelay);
77
+ }, [deactivateDelay, clearTimer, hide]);
78
+ useEffect(() => {
79
+ const current = entry.current;
80
+ return () => {
81
+ clearTimer();
82
+ if (openTooltip === current)
83
+ openTooltip = null;
84
+ };
85
+ }, [clearTimer]);
86
+ return { isOpen, skipTransition, scheduleShow, scheduleHide, hide };
87
+ };
88
+ export default useTooltipState;
89
+ //# sourceMappingURL=useTooltipState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTooltipState.js","sourceRoot":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