@canonical/react-ds-global 0.49.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.
- package/dist/esm/lib/_work_in_progress/Announcement/styles.css +4 -4
- package/dist/esm/lib/_work_in_progress/Label/styles.css +1 -7
- package/dist/esm/lib/component/Accordion/common/Item/styles.css +5 -6
- package/dist/esm/lib/component/Accordion/styles.css +3 -9
- package/dist/esm/lib/component/Breadcrumbs/common/Item/styles.css +6 -14
- package/dist/esm/lib/component/Breadcrumbs/styles.css +2 -9
- package/dist/esm/lib/component/Button/styles.css +1 -1
- package/dist/esm/lib/component/Card/common/Content/styles.css +4 -5
- package/dist/esm/lib/component/Card/common/Header/styles.css +1 -2
- package/dist/esm/lib/component/Card/styles.css +1 -2
- package/dist/esm/lib/component/ContextualMenu/common/Item/styles.css +6 -9
- package/dist/esm/lib/component/ContextualMenu/styles.css +6 -7
- package/dist/esm/lib/component/Icon/styles.css +3 -7
- package/dist/esm/lib/component/InlineCode/styles.css +2 -3
- package/dist/esm/lib/component/KeyboardKey/styles.css +6 -8
- package/dist/esm/lib/component/Tabs/common/Item/styles.css +1 -1
- package/dist/esm/lib/component/Tabs/styles.css +4 -8
- package/dist/esm/lib/component/Tile/common/Content/styles.css +2 -5
- package/dist/esm/lib/component/Tile/common/Header/styles.css +3 -6
- package/dist/esm/lib/component/Tile/styles.css +1 -5
- package/dist/esm/lib/component/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/lib/component/Tooltip/TooltipEngine.js +91 -15
- package/dist/esm/lib/component/Tooltip/TooltipEngine.js.map +1 -1
- package/dist/esm/lib/component/Tooltip/hooks/useTooltipState.js +89 -0
- package/dist/esm/lib/component/Tooltip/hooks/useTooltipState.js.map +1 -0
- package/dist/esm/lib/component/Tooltip/styles.css +151 -80
- package/dist/esm/lib/component/Tooltip/withTooltip.js +3 -3
- package/dist/esm/lib/group/KeyboardKeys/styles.css +1 -1
- package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js +172 -173
- package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js.map +1 -1
- package/dist/esm/lib/pattern/Modal/common/Content/styles.css +3 -6
- package/dist/esm/lib/pattern/Modal/common/Footer/styles.css +1 -1
- package/dist/esm/lib/pattern/Modal/common/Header/styles.css +3 -9
- package/dist/esm/lib/pattern/Modal/styles.css +14 -20
- package/dist/esm/lib/pattern/Timeline/common/Content/styles.css +1 -4
- package/dist/esm/lib/pattern/Timeline/common/Event/styles.css +6 -13
- package/dist/esm/lib/pattern/Timeline/styles.css +1 -4
- package/dist/types/lib/component/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/TooltipEngine.d.ts +6 -4
- package/dist/types/lib/component/Tooltip/TooltipEngine.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/hooks/useTooltipState.d.ts +17 -0
- package/dist/types/lib/component/Tooltip/hooks/useTooltipState.d.ts.map +1 -0
- package/dist/types/lib/component/Tooltip/types.d.ts +27 -2
- package/dist/types/lib/component/Tooltip/types.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/withTooltip.d.ts +3 -3
- package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts +22 -1
- package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -1
- package/package.json +23 -14
|
@@ -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 {
|
|
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
|
-
*
|
|
10
|
-
*
|
|
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,
|
|
18
|
-
const
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
isOpen: open ?? props.isOpen,
|
|
26
|
-
mode: "hover",
|
|
42
|
+
isOpen,
|
|
27
43
|
});
|
|
28
|
-
|
|
29
|
-
|
|
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,
|
|
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
|
|
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:
|
|
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":";
|
|
1
|
+
{"version":3,"file":"TooltipEngine.js","sourceRoot":"","sources":["../../../../../src/lib/component/Tooltip/TooltipEngine.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,YAAY,EAEZ,cAAc,EAGd,WAAW,EACX,SAAS,EACT,KAAK,EACL,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAA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iB;QACjB,MAAM,EAAE,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,YAEtC,OAAO,GACA,CACX,CAAC;IAEF,OAAO,CAEL,gBACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,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":"","sources":["../../../../../../src/lib/component/Tooltip/hooks/useTooltipState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOjE;;;GAGG;AACH,IAAI,WAAW,GAAuB,IAAI,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,eAAe,GAAG,CAAC,EACvB,aAAa,GAAG,GAAG,EACnB,eAAe,GAAG,GAAG,EACrB,MAAM,EACN,MAAM,GACe,EAAyB,EAAE;IAChD,MAAM,CAAC,MAAM,EAAE,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,EAAE;QACb,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,OAAO,GAAG,EAAE;YACV,UAAU,EAAE,CAAC;YACb,IAAI,WAAW,KAAK,OAAO;gBAAE,WAAW,GAAG,IAAI,CAAC;QAClD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AACtE,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -25,35 +25,39 @@
|
|
|
25
25
|
element below, NOT via a :root intermediate (which would see them unset and
|
|
26
26
|
fall back to the base colour). */
|
|
27
27
|
:root {
|
|
28
|
-
--tooltip-border-radius:
|
|
28
|
+
--tooltip-border-radius: var(--dimension-radius-small);
|
|
29
|
+
--tooltip-border-width: var(--dimension-stroke-thickness-medium);
|
|
29
30
|
--tooltip-margin-left: 0;
|
|
30
31
|
--tooltip-margin-bottom: 0;
|
|
31
|
-
/* Figma: py = dimension-100 (8px), px = dimension-200 (16px). */
|
|
32
32
|
--tooltip-padding-vertical: var(--dimension-100);
|
|
33
33
|
--tooltip-padding-horizontal: var(--dimension-200);
|
|
34
|
-
--tooltip-
|
|
35
|
-
|
|
36
|
-
--tooltip-font-
|
|
37
|
-
--tooltip-
|
|
38
|
-
--tooltip-line-height: var(--line-height
|
|
34
|
+
--tooltip-font-family: var(--typography-text-secondary-font-family);
|
|
35
|
+
--tooltip-font-size: var(--typography-text-secondary-font-size, 14px);
|
|
36
|
+
--tooltip-font-weight: var(--typography-text-secondary-font-weight);
|
|
37
|
+
--tooltip-letter-spacing: var(--typography-text-secondary-letter-spacing);
|
|
38
|
+
--tooltip-line-height: var(--typography-text-secondary-line-height, 20px);
|
|
39
39
|
--tooltip-max-width: 284px;
|
|
40
|
-
/* Gap between an optional leading icon and the text
|
|
40
|
+
/* Gap between an optional leading icon and the text. */
|
|
41
41
|
--tooltip-gap: var(--dimension-100);
|
|
42
42
|
|
|
43
|
-
/* Arrow geometry, independent of `distance` (the gap to the trigger)
|
|
44
|
-
|
|
43
|
+
/* Arrow geometry, independent of `distance` (the gap to the trigger):
|
|
44
|
+
14px across the edge, 8px deep pointing out. */
|
|
45
45
|
--tooltip-arrow-width: var(--dimension-175, 14px);
|
|
46
46
|
--tooltip-arrow-depth: var(--dimension-100, 8px);
|
|
47
47
|
|
|
48
|
-
/*
|
|
49
|
-
--tooltip-motion-duration: 0.
|
|
48
|
+
/* Open and close transition: a fade and a slight scale from the arrow. */
|
|
49
|
+
--tooltip-motion-duration: 0.4s;
|
|
50
|
+
--tooltip-motion-easing: cubic-bezier(0.22, 1, 0.36, 1);
|
|
51
|
+
--tooltip-motion-scale: 0.96;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
/* component variables
|
|
53
55
|
--tooltip-color-background: background color of the tooltip
|
|
54
56
|
--tooltip-color-text: text color of the tooltip
|
|
55
|
-
--tooltip-color-border: border color of the tooltip
|
|
57
|
+
--tooltip-color-border: border color of the tooltip and its arrow
|
|
56
58
|
|
|
59
|
+
--tooltip-border-radius: corner radius of the tooltip
|
|
60
|
+
--tooltip-border-width: border width of the tooltip and its arrow
|
|
57
61
|
--tooltip-margin-left: left margin of the tooltip
|
|
58
62
|
--tooltip-margin-bottom: bottom margin of the tooltip
|
|
59
63
|
--tooltip-padding-vertical: vertical padding of the tooltip
|
|
@@ -62,83 +66,97 @@
|
|
|
62
66
|
--tooltip-font-weight: font weight of the tooltip
|
|
63
67
|
--tooltip-line-height: line height of the tooltip
|
|
64
68
|
|
|
65
|
-
--tooltip-
|
|
66
|
-
|
|
69
|
+
--tooltip-arrow-width: width of the arrow base (independent of `distance`)
|
|
70
|
+
--tooltip-arrow-depth: depth of the arrow (independent of `distance`)
|
|
67
71
|
--tooltip-arrow-offset-left: offset of the arrow along the x-axis (top/bottom placements)
|
|
68
72
|
--tooltip-arrow-offset-top: offset of the arrow along the y-axis (left/right placements)
|
|
73
|
+
|
|
74
|
+
--tooltip-motion-duration: duration of the open/close transition
|
|
75
|
+
--tooltip-motion-easing: easing of the open/close transition
|
|
76
|
+
--tooltip-motion-scale: scale the tooltip opens from
|
|
69
77
|
*/
|
|
70
78
|
|
|
71
79
|
.ds.tooltip {
|
|
72
|
-
/* The tooltip's own
|
|
73
|
-
|
|
80
|
+
/* The tooltip's own colours, read from the contrasted surface on this
|
|
81
|
+
element (so the arrow, which reuses them, is coloured correctly too). The
|
|
82
|
+
contrasted surface has no border channel, so the border matches the
|
|
83
|
+
background. */
|
|
74
84
|
--tooltip-color-background: var(
|
|
75
85
|
--surface-color-background,
|
|
76
86
|
var(--color-background)
|
|
77
87
|
);
|
|
78
88
|
--tooltip-color-text: var(--surface-color-text, var(--color-text));
|
|
89
|
+
--tooltip-color-border: var(--tooltip-color-background);
|
|
79
90
|
|
|
80
|
-
/*
|
|
81
|
-
|
|
91
|
+
/* The arrow is two CSS border-triangles: an outer one in the border colour
|
|
92
|
+
and an inner one in the background colour, inset by the border width so
|
|
93
|
+
a border-width outline remains along its slanted edges. The base is built
|
|
94
|
+
from two half-width transparent borders; the depth from the coloured
|
|
82
95
|
border on the pointing side. */
|
|
83
96
|
--tooltip-arrow-half-width: calc(var(--tooltip-arrow-width) / 2);
|
|
84
97
|
/* Centre of the edge. `left`/`top` positions the ZERO-width pseudo-element's
|
|
85
98
|
origin, but its two half-width side borders render the triangle from that
|
|
86
99
|
origin OUTWARD, so the visible apex sits half-a-width past `left`. To centre
|
|
87
100
|
the apex on the box we therefore pull the origin back by half-width:
|
|
88
|
-
`50% - half-width`.
|
|
89
|
-
apex +7px off-centre.) The magnetic offset then shifts from this centre. */
|
|
101
|
+
`50% - half-width`. The magnetic offset then shifts from this centre. */
|
|
90
102
|
--tooltip-arrow-middle: calc(50% - var(--tooltip-arrow-half-width));
|
|
91
|
-
|
|
103
|
+
/* Absolute offsets resolve against the padding box, inside the border.
|
|
104
|
+
The outer triangle starts at the outer border edge; the inner one starts
|
|
105
|
+
at the inner border edge, covering the border where the arrow meets the
|
|
106
|
+
box. */
|
|
107
|
+
--tooltip-arrow-edge-outer: calc(
|
|
108
|
+
-1 *
|
|
109
|
+
(var(--tooltip-arrow-depth) + var(--tooltip-border-width))
|
|
110
|
+
);
|
|
111
|
+
--tooltip-arrow-edge-inner: calc(-1 * var(--tooltip-arrow-depth));
|
|
92
112
|
--tooltip-arrow-offset-left: 0px;
|
|
93
113
|
--tooltip-arrow-offset-top: 0px;
|
|
94
114
|
|
|
95
115
|
color: var(--tooltip-color-text);
|
|
96
116
|
background-color: var(--tooltip-color-background);
|
|
97
|
-
border
|
|
98
|
-
border-style: solid;
|
|
117
|
+
border: var(--tooltip-border-width) solid var(--tooltip-color-border);
|
|
99
118
|
border-radius: var(--tooltip-border-radius);
|
|
100
|
-
|
|
101
|
-
font-size: var(--tooltip-font-size
|
|
102
|
-
font-weight: var(--tooltip-font-weight
|
|
103
|
-
|
|
119
|
+
font-family: var(--tooltip-font-family);
|
|
120
|
+
font-size: var(--tooltip-font-size);
|
|
121
|
+
font-weight: var(--tooltip-font-weight);
|
|
122
|
+
letter-spacing: var(--tooltip-letter-spacing);
|
|
123
|
+
line-height: var(--tooltip-line-height);
|
|
104
124
|
margin-block-end: var(--tooltip-margin-bottom, 0);
|
|
105
125
|
margin-inline-end: var(--tooltip-margin-left, 0);
|
|
106
|
-
padding-block: var(--tooltip-padding-vertical
|
|
107
|
-
padding-inline: var(--tooltip-padding-horizontal
|
|
126
|
+
padding-block: var(--tooltip-padding-vertical);
|
|
127
|
+
padding-inline: var(--tooltip-padding-horizontal);
|
|
108
128
|
text-align: left;
|
|
109
129
|
text-decoration: initial;
|
|
110
130
|
pointer-events: auto;
|
|
111
131
|
/* The box stays `inline-block` — it is the positioning context for the arrow
|
|
112
|
-
|
|
113
|
-
icon+text layout lives in an inner `.content` flex row so the
|
|
114
|
-
|
|
132
|
+
pseudo-elements, and their `50%` centring must resolve against this box.
|
|
133
|
+
The icon+text layout lives in an inner `.content` flex row so the
|
|
134
|
+
pseudo-elements are never flex items (which would shift the arrow and
|
|
135
|
+
reserve gap for it). */
|
|
115
136
|
display: inline-block;
|
|
116
137
|
max-width: var(--tooltip-max-width);
|
|
117
138
|
position: fixed;
|
|
118
|
-
/* MUST stay `visible`: the arrow is
|
|
119
|
-
|
|
120
|
-
|
|
139
|
+
/* MUST stay `visible`: the arrow is positioned just outside the box (e.g.
|
|
140
|
+
bottom: -8px). Any `overflow: auto | hidden | clip` clips it and the
|
|
141
|
+
triangle disappears entirely. */
|
|
121
142
|
overflow: visible;
|
|
122
143
|
/* Above the overlay tier, so a tooltip inside a popover or menu is not covered by it. */
|
|
123
144
|
z-index: var(--z-index-overlay, 1000);
|
|
124
145
|
|
|
125
146
|
/* Inner row: optional leading icon before the text, top-aligned with the
|
|
126
|
-
first line
|
|
147
|
+
first line. Without an icon it is just the text. */
|
|
127
148
|
& > .content {
|
|
128
149
|
display: flex;
|
|
129
150
|
align-items: flex-start;
|
|
130
151
|
gap: var(--tooltip-gap);
|
|
131
152
|
}
|
|
132
153
|
|
|
133
|
-
/* Leading icon: fixed 16px box,
|
|
134
|
-
decorative (the text carries the meaning). */
|
|
154
|
+
/* Leading icon: fixed 16px box, nudged down to sit on the first text line,
|
|
155
|
+
purely decorative (the text carries the meaning). */
|
|
135
156
|
& .icon {
|
|
136
157
|
flex: 0 0 auto;
|
|
137
158
|
display: inline-flex;
|
|
138
|
-
align-items: center;
|
|
139
|
-
justify-content: center;
|
|
140
159
|
inline-size: var(--dimension-200, 16px);
|
|
141
|
-
block-size: var(--tooltip-line-height, 20px);
|
|
142
160
|
|
|
143
161
|
& > svg {
|
|
144
162
|
inline-size: var(--dimension-200, 16px);
|
|
@@ -146,21 +164,26 @@
|
|
|
146
164
|
}
|
|
147
165
|
}
|
|
148
166
|
|
|
149
|
-
/* The text wraps at max-width
|
|
150
|
-
|
|
167
|
+
/* The text wraps at max-width while honouring any explicit newlines in the
|
|
168
|
+
message. */
|
|
151
169
|
& .text {
|
|
152
170
|
white-space: pre-wrap;
|
|
153
171
|
}
|
|
154
172
|
|
|
155
173
|
/*
|
|
156
|
-
CSS-only enter/exit
|
|
174
|
+
CSS-only enter/exit transition: the tooltip fades in and scales up from
|
|
175
|
+
its arrow, and fades out. `allow-discrete` lets `visibility` (a discrete
|
|
157
176
|
property) transition alongside `opacity`, and `@starting-style` gives the
|
|
158
|
-
opening frame
|
|
177
|
+
opening frame its starting values so the transition runs. No JavaScript
|
|
178
|
+
timing. The closed tooltip is never scaled, so it is measured at its true
|
|
179
|
+
size when it is positioned before opening.
|
|
159
180
|
*/
|
|
160
181
|
opacity: 0;
|
|
161
182
|
visibility: hidden;
|
|
183
|
+
transform-origin: center;
|
|
162
184
|
transition:
|
|
163
|
-
opacity var(--tooltip-motion-duration)
|
|
185
|
+
opacity var(--tooltip-motion-duration) var(--tooltip-motion-easing),
|
|
186
|
+
transform var(--tooltip-motion-duration) var(--tooltip-motion-easing),
|
|
164
187
|
visibility var(--tooltip-motion-duration) allow-discrete;
|
|
165
188
|
|
|
166
189
|
&[aria-hidden="false"] {
|
|
@@ -170,6 +193,7 @@
|
|
|
170
193
|
|
|
171
194
|
@starting-style {
|
|
172
195
|
opacity: 0;
|
|
196
|
+
transform: scale(var(--tooltip-motion-scale));
|
|
173
197
|
}
|
|
174
198
|
}
|
|
175
199
|
|
|
@@ -179,18 +203,18 @@
|
|
|
179
203
|
visibility: hidden;
|
|
180
204
|
}
|
|
181
205
|
|
|
182
|
-
|
|
206
|
+
/* Closed because another tooltip opened in its place: no exit transition. */
|
|
207
|
+
&[data-transition="none"] {
|
|
183
208
|
transition: none;
|
|
184
209
|
}
|
|
185
210
|
|
|
186
|
-
/*
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
&::before {
|
|
211
|
+
/* Reduced motion keeps the fade and drops the scale. */
|
|
212
|
+
@media (prefers-reduced-motion: reduce) {
|
|
213
|
+
--tooltip-motion-scale: 1;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
&::before,
|
|
217
|
+
&::after {
|
|
194
218
|
content: "";
|
|
195
219
|
width: 0;
|
|
196
220
|
height: 0;
|
|
@@ -200,39 +224,86 @@
|
|
|
200
224
|
}
|
|
201
225
|
|
|
202
226
|
/* Placed above the trigger → arrow points down, on the tooltip's bottom edge. */
|
|
203
|
-
&.top
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
227
|
+
&.top {
|
|
228
|
+
transform-origin: calc(50% + var(--tooltip-arrow-offset-left)) 100%;
|
|
229
|
+
|
|
230
|
+
&::before,
|
|
231
|
+
&::after {
|
|
232
|
+
border-inline: var(--tooltip-arrow-half-width) solid transparent;
|
|
233
|
+
left: var(--tooltip-arrow-middle);
|
|
234
|
+
}
|
|
235
|
+
&::before {
|
|
236
|
+
border-top: var(--tooltip-arrow-depth) solid var(--tooltip-color-border);
|
|
237
|
+
bottom: var(--tooltip-arrow-edge-outer);
|
|
238
|
+
}
|
|
239
|
+
&::after {
|
|
240
|
+
border-top: var(--tooltip-arrow-depth) solid
|
|
241
|
+
var(--tooltip-color-background);
|
|
242
|
+
bottom: var(--tooltip-arrow-edge-inner);
|
|
243
|
+
}
|
|
209
244
|
}
|
|
210
245
|
|
|
211
246
|
/* Placed below → arrow points up, on the top edge. */
|
|
212
|
-
&.bottom
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
247
|
+
&.bottom {
|
|
248
|
+
transform-origin: calc(50% + var(--tooltip-arrow-offset-left)) 0;
|
|
249
|
+
|
|
250
|
+
&::before,
|
|
251
|
+
&::after {
|
|
252
|
+
border-inline: var(--tooltip-arrow-half-width) solid transparent;
|
|
253
|
+
left: var(--tooltip-arrow-middle);
|
|
254
|
+
}
|
|
255
|
+
&::before {
|
|
256
|
+
border-bottom: var(--tooltip-arrow-depth) solid
|
|
257
|
+
var(--tooltip-color-border);
|
|
258
|
+
top: var(--tooltip-arrow-edge-outer);
|
|
259
|
+
}
|
|
260
|
+
&::after {
|
|
261
|
+
border-bottom: var(--tooltip-arrow-depth) solid
|
|
262
|
+
var(--tooltip-color-background);
|
|
263
|
+
top: var(--tooltip-arrow-edge-inner);
|
|
264
|
+
}
|
|
218
265
|
}
|
|
219
266
|
|
|
220
267
|
/* Placed left → arrow points right, on the right edge. */
|
|
221
|
-
&.left
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
268
|
+
&.left {
|
|
269
|
+
transform-origin: 100% calc(50% + var(--tooltip-arrow-offset-top));
|
|
270
|
+
|
|
271
|
+
&::before,
|
|
272
|
+
&::after {
|
|
273
|
+
border-block: var(--tooltip-arrow-half-width) solid transparent;
|
|
274
|
+
top: var(--tooltip-arrow-middle);
|
|
275
|
+
}
|
|
276
|
+
&::before {
|
|
277
|
+
border-left: var(--tooltip-arrow-depth) solid
|
|
278
|
+
var(--tooltip-color-border);
|
|
279
|
+
right: var(--tooltip-arrow-edge-outer);
|
|
280
|
+
}
|
|
281
|
+
&::after {
|
|
282
|
+
border-left: var(--tooltip-arrow-depth) solid
|
|
283
|
+
var(--tooltip-color-background);
|
|
284
|
+
right: var(--tooltip-arrow-edge-inner);
|
|
285
|
+
}
|
|
227
286
|
}
|
|
228
287
|
|
|
229
288
|
/* Placed right → arrow points left, on the left edge. */
|
|
230
|
-
&.right
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
289
|
+
&.right {
|
|
290
|
+
transform-origin: 0 calc(50% + var(--tooltip-arrow-offset-top));
|
|
291
|
+
|
|
292
|
+
&::before,
|
|
293
|
+
&::after {
|
|
294
|
+
border-block: var(--tooltip-arrow-half-width) solid transparent;
|
|
295
|
+
top: var(--tooltip-arrow-middle);
|
|
296
|
+
}
|
|
297
|
+
&::before {
|
|
298
|
+
border-right: var(--tooltip-arrow-depth) solid
|
|
299
|
+
var(--tooltip-color-border);
|
|
300
|
+
left: var(--tooltip-arrow-edge-outer);
|
|
301
|
+
}
|
|
302
|
+
&::after {
|
|
303
|
+
border-right: var(--tooltip-arrow-depth) solid
|
|
304
|
+
var(--tooltip-color-background);
|
|
305
|
+
left: var(--tooltip-arrow-edge-inner);
|
|
306
|
+
}
|
|
236
307
|
}
|
|
237
308
|
}
|
|
238
309
|
}
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import TooltipEngine from "./TooltipEngine.js";
|
|
3
3
|
/**
|
|
4
4
|
* A higher-order component that wraps a component with a tooltip. It is the
|
|
5
|
-
* single public tooltip primitive: it owns the engine (hover
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* single public tooltip primitive: it owns the engine (hover and focus
|
|
6
|
+
* behaviour, client-only portal, arrow positioning) and renders the wrapped
|
|
7
|
+
* component as the tooltip target.
|
|
8
8
|
*
|
|
9
9
|
* `Message` is fixed at wrap time — not reactive to the wrapped component's
|
|
10
10
|
* props. When the message must follow prop state (e.g. a toggle whose
|