@tensor_1/react 2.59.0 → 2.61.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/components/Button.d.ts +15 -0
- package/dist/components/Button.js +11 -6
- package/dist/components/Checkbox.js +1 -1
- package/dist/components/Drawer.js +104 -1
- package/dist/components/Menu.js +10 -1
- package/dist/components/Popover.js +4 -1
- package/dist/components/Select.js +85 -11
- package/dist/components/Sidebar.js +29 -2
- package/dist/components/Tooltip.js +103 -16
- package/dist/emoji.cjs +263 -70
- package/dist/hooks/useArrivalBlur.d.ts +14 -0
- package/dist/hooks/useArrivalBlur.js +47 -0
- package/dist/hooks/useHoverGlide.d.ts +28 -0
- package/dist/hooks/useHoverGlide.js +137 -0
- package/dist/icons/Icon.d.ts +4 -2
- package/dist/icons/Icon.js +6 -2
- package/dist/icons/NamedIcon.js +1 -1
- package/dist/icons/types.d.ts +11 -0
- package/dist/icons.cjs +7 -3
- package/dist/icons.d.cts +2 -2
- package/dist/index.cjs +2933 -2327
- package/dist/index.d.cts +42 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/motion.d.ts +25 -1
- package/dist/motion.js +100 -0
- package/dist/rich-text.cjs +4 -1
- package/dist/{types-B593xJNf.d.cts → types-B7OIndwg.d.cts} +11 -0
- package/dist/usage-roles.d.ts +28 -0
- package/dist/usage-roles.js +28 -0
- package/package.json +1 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { cloneElement, isValidElement, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { flushSync } from "react-dom";
|
|
4
5
|
import { cx } from "../cx.js";
|
|
5
6
|
import { useAnchoredPosition } from "../hooks/useAnchoredPosition.js";
|
|
6
7
|
import { KbdCombo, isKeyShortcut, spokenKeys, useKbdPlatform } from "./Kbd.js";
|
|
7
|
-
import { markKeyOpened, tokenMs, watchInputModality } from "../motion.js";
|
|
8
|
-
|
|
8
|
+
import { blurIn, markKeyOpened, tokenEase, tokenMs, tokenPx, watchInputModality } from "../motion.js";
|
|
9
|
+
import { prefersReducedMotion } from "../hooks/useReducedMotion.js";
|
|
10
|
+
const group = { open: 0, lastClosed: -Infinity, current: null, bubble: null };
|
|
11
|
+
const MORPH_FALLBACK_MS = 1e3;
|
|
12
|
+
const MORPH_MAX_TRAVEL_PX = 320;
|
|
9
13
|
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
|
|
10
14
|
function Tooltip({ label, content, placement = "top", shortcut, className, children, ...props }) {
|
|
11
15
|
const triggerRef = useRef(null);
|
|
@@ -13,6 +17,7 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
13
17
|
const closeTimer = useRef(null);
|
|
14
18
|
const openTimer = useRef(null);
|
|
15
19
|
const shown = useRef(false);
|
|
20
|
+
const morphFrom = useRef(null);
|
|
16
21
|
const [open, setOpen] = useState(false);
|
|
17
22
|
const id = useId();
|
|
18
23
|
const platform = useKbdPlatform();
|
|
@@ -20,6 +25,78 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
20
25
|
const own = shortcut ?? (isKeyShortcut(childShortcut) ? childShortcut : void 0);
|
|
21
26
|
const keys = own && own.length > 0 ? own : null;
|
|
22
27
|
useAnchoredPosition(triggerRef, bubbleRef, { open, placement, offset: 6 });
|
|
28
|
+
useIsomorphicLayoutEffect(() => {
|
|
29
|
+
const from = morphFrom.current;
|
|
30
|
+
const b = bubbleRef.current;
|
|
31
|
+
morphFrom.current = null;
|
|
32
|
+
if (!open || !from || !b || prefersReducedMotion()) return void 0;
|
|
33
|
+
const to = b.getBoundingClientRect();
|
|
34
|
+
if (!to.width || !to.height) return void 0;
|
|
35
|
+
const was = from.rect;
|
|
36
|
+
const dx = was.left + was.width / 2 - (to.left + to.width / 2);
|
|
37
|
+
const dy = was.top + was.height / 2 - (to.top + to.height / 2);
|
|
38
|
+
if (Math.hypot(dx, dy) > MORPH_MAX_TRAVEL_PX) return void 0;
|
|
39
|
+
const alongX = Math.abs(dx) >= Math.abs(dy);
|
|
40
|
+
const way = Math.hypot(dx, dy) < 0.5 ? 0 : -Math.sign(alongX ? dx : dy);
|
|
41
|
+
b.setAttribute("data-uix-instant", "");
|
|
42
|
+
b.setAttribute("data-morph", "");
|
|
43
|
+
b.style.setProperty("--uix-swap-x", String(alongX ? way : 0));
|
|
44
|
+
b.style.setProperty("--uix-swap-y", String(alongX ? 0 : way));
|
|
45
|
+
b.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
46
|
+
b.style.setProperty("--uix-morph-sx", String(was.width / to.width));
|
|
47
|
+
b.style.setProperty("--uix-morph-sy", String(was.height / to.height));
|
|
48
|
+
const content2 = b.querySelector(".uix-tooltip__content");
|
|
49
|
+
const cs = window.getComputedStyle(b);
|
|
50
|
+
const px = parseFloat(cs.paddingLeft) || 0;
|
|
51
|
+
const py = parseFloat(cs.paddingTop) || 0;
|
|
52
|
+
const insetY = (to.height - was.height) / 2;
|
|
53
|
+
const insetX = (to.width - was.width) / 2;
|
|
54
|
+
if (content2) content2.style.clipPath = `inset(${insetY - py}px ${insetX - px}px)`;
|
|
55
|
+
let leaving = null;
|
|
56
|
+
if (from.label) {
|
|
57
|
+
leaving = document.createElement("span");
|
|
58
|
+
leaving.className = "uix-tooltip__content uix-tooltip__content--leaving";
|
|
59
|
+
leaving.setAttribute("aria-hidden", "true");
|
|
60
|
+
const old = from.label.cloneNode(true);
|
|
61
|
+
for (const el of [old, ...Array.from(old.querySelectorAll("[id]"))]) el.removeAttribute("id");
|
|
62
|
+
leaving.appendChild(old);
|
|
63
|
+
leaving.style.clipPath = `inset(${insetY}px ${insetX}px)`;
|
|
64
|
+
b.appendChild(leaving);
|
|
65
|
+
}
|
|
66
|
+
void b.offsetWidth;
|
|
67
|
+
b.removeAttribute("data-uix-instant");
|
|
68
|
+
b.setAttribute("data-morphing", "");
|
|
69
|
+
b.style.transform = "";
|
|
70
|
+
b.style.removeProperty("--uix-morph-sx");
|
|
71
|
+
b.style.removeProperty("--uix-morph-sy");
|
|
72
|
+
if (content2) content2.style.clipPath = `inset(${-py}px ${-px}px)`;
|
|
73
|
+
if (leaving) leaving.style.clipPath = "inset(0px)";
|
|
74
|
+
const blur = tokenPx("--uix-swap-blur", 6);
|
|
75
|
+
const label2 = content2?.querySelector(".uix-tooltip__label");
|
|
76
|
+
const stopIn = label2 ? blurIn([label2], { from: blur, duration: tokenMs("--uix-dur-swap-in", 340), ease: tokenEase("--uix-ease-enter") }) : () => {
|
|
77
|
+
};
|
|
78
|
+
const oldLabel = leaving?.firstElementChild instanceof HTMLElement ? leaving.firstElementChild : null;
|
|
79
|
+
const stopOut = oldLabel ? blurIn([oldLabel], { from: blur, duration: tokenMs("--uix-dur-swap-out", 130), ease: tokenEase("--uix-ease-leave"), leave: true }) : () => {
|
|
80
|
+
};
|
|
81
|
+
const end = () => {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
stopIn();
|
|
84
|
+
stopOut();
|
|
85
|
+
b.removeEventListener("transitionend", onEnd);
|
|
86
|
+
b.removeAttribute("data-morph");
|
|
87
|
+
b.removeAttribute("data-morphing");
|
|
88
|
+
b.style.removeProperty("--uix-swap-x");
|
|
89
|
+
b.style.removeProperty("--uix-swap-y");
|
|
90
|
+
if (content2) content2.style.clipPath = "";
|
|
91
|
+
leaving?.remove();
|
|
92
|
+
};
|
|
93
|
+
const onEnd = (event) => {
|
|
94
|
+
if (event.target === b && !event.pseudoElement && event.propertyName === "transform") end();
|
|
95
|
+
};
|
|
96
|
+
b.addEventListener("transitionend", onEnd);
|
|
97
|
+
const timer = setTimeout(end, MORPH_FALLBACK_MS);
|
|
98
|
+
return end;
|
|
99
|
+
}, [open]);
|
|
23
100
|
useEffect(() => {
|
|
24
101
|
watchInputModality();
|
|
25
102
|
}, []);
|
|
@@ -35,13 +112,17 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
35
112
|
openTimer.current = null;
|
|
36
113
|
}
|
|
37
114
|
};
|
|
38
|
-
const reveal = (
|
|
115
|
+
const reveal = (handOver) => {
|
|
39
116
|
cancelOpen();
|
|
117
|
+
const neighbour = group.current && group.current !== self && group.bubble?.matches(":popover-open") ? group.bubble : null;
|
|
118
|
+
const rect = neighbour?.getBoundingClientRect();
|
|
119
|
+
morphFrom.current = handOver && neighbour && rect && rect.width > 0 ? { rect, label: neighbour.querySelector(".uix-tooltip__content:not(.uix-tooltip__content--leaving) > .uix-tooltip__label") } : null;
|
|
40
120
|
if (group.current && group.current !== self) group.current.current(true);
|
|
41
121
|
group.current = self;
|
|
122
|
+
group.bubble = bubbleRef.current;
|
|
42
123
|
const b = bubbleRef.current;
|
|
43
124
|
if (b && !b.matches(":popover-open")) {
|
|
44
|
-
b.toggleAttribute("data-uix-instant",
|
|
125
|
+
b.toggleAttribute("data-uix-instant", handOver && !!neighbour);
|
|
45
126
|
markKeyOpened(b);
|
|
46
127
|
try {
|
|
47
128
|
b.showPopover();
|
|
@@ -52,14 +133,14 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
52
133
|
shown.current = true;
|
|
53
134
|
group.open += 1;
|
|
54
135
|
}
|
|
55
|
-
setOpen(true);
|
|
136
|
+
flushSync(() => setOpen(true));
|
|
56
137
|
};
|
|
57
138
|
const show = (via) => {
|
|
58
139
|
cancelClose();
|
|
59
|
-
if (shown.current) return;
|
|
140
|
+
if (shown.current || !hasText) return;
|
|
60
141
|
const warm = group.open > 0 || performance.now() - group.lastClosed < tokenMs("--uix-delay-tooltip-skip", 300);
|
|
61
142
|
if (via === "focus" || warm) {
|
|
62
|
-
reveal(via === "pointer");
|
|
143
|
+
reveal(via === "pointer" && group.open > 0);
|
|
63
144
|
return;
|
|
64
145
|
}
|
|
65
146
|
if (openTimer.current == null) openTimer.current = window.setTimeout(() => reveal(false), tokenMs("--uix-delay-tooltip", 400));
|
|
@@ -80,7 +161,12 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
80
161
|
group.open -= 1;
|
|
81
162
|
group.lastClosed = performance.now();
|
|
82
163
|
}
|
|
83
|
-
if (group.current === self)
|
|
164
|
+
if (group.current === self) {
|
|
165
|
+
group.current = null;
|
|
166
|
+
group.bubble = null;
|
|
167
|
+
}
|
|
168
|
+
morphFrom.current = null;
|
|
169
|
+
b?.querySelector(".uix-tooltip__content--leaving")?.remove();
|
|
84
170
|
setOpen(false);
|
|
85
171
|
};
|
|
86
172
|
const self = useRef(hide);
|
|
@@ -94,7 +180,7 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
94
180
|
} catch {
|
|
95
181
|
}
|
|
96
182
|
hide();
|
|
97
|
-
},
|
|
183
|
+
}, tokenMs("--uix-delay-tooltip-skip", 300));
|
|
98
184
|
};
|
|
99
185
|
useIsomorphicLayoutEffect(() => {
|
|
100
186
|
if (!open) return void 0;
|
|
@@ -102,7 +188,7 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
102
188
|
if (e.key !== "Escape") return;
|
|
103
189
|
e.preventDefault();
|
|
104
190
|
e.stopPropagation();
|
|
105
|
-
hide();
|
|
191
|
+
hide(true);
|
|
106
192
|
};
|
|
107
193
|
document.addEventListener("keydown", onKey, true);
|
|
108
194
|
return () => document.removeEventListener("keydown", onKey, true);
|
|
@@ -126,9 +212,10 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
126
212
|
}, []);
|
|
127
213
|
const bubbleAttr = { popover: "manual" };
|
|
128
214
|
const text = content ?? label;
|
|
215
|
+
const hasText = keys != null || text != null && text !== "";
|
|
129
216
|
const description = keys ? [text != null ? `${id}-text` : null, `${id}-keys`].filter(Boolean).join(" ") : id;
|
|
130
217
|
const single = isValidElement(children);
|
|
131
|
-
const child = single ? cloneElement(children, {
|
|
218
|
+
const child = single && hasText ? cloneElement(children, {
|
|
132
219
|
"aria-describedby": [children.props["aria-describedby"], description].filter(Boolean).join(" ")
|
|
133
220
|
}) : children;
|
|
134
221
|
return /* @__PURE__ */ jsxs(
|
|
@@ -136,12 +223,12 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
136
223
|
{
|
|
137
224
|
ref: triggerRef,
|
|
138
225
|
className: cx("uix-tooltip", className),
|
|
139
|
-
"aria-describedby": single ? void 0 : description,
|
|
140
|
-
tabIndex: single ? void 0 : 0,
|
|
226
|
+
"aria-describedby": single || !hasText ? void 0 : description,
|
|
227
|
+
tabIndex: single || !hasText ? void 0 : 0,
|
|
141
228
|
onMouseEnter: () => show("pointer"),
|
|
142
229
|
onMouseLeave: scheduleHide,
|
|
143
230
|
onFocus: () => show("focus"),
|
|
144
|
-
onBlur: () => hide(),
|
|
231
|
+
onBlur: () => hide(true),
|
|
145
232
|
...props,
|
|
146
233
|
children: [
|
|
147
234
|
child,
|
|
@@ -155,13 +242,13 @@ function Tooltip({ label, content, placement = "top", shortcut, className, child
|
|
|
155
242
|
onMouseEnter: cancelClose,
|
|
156
243
|
onMouseLeave: scheduleHide,
|
|
157
244
|
...bubbleAttr,
|
|
158
|
-
children: keys ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
245
|
+
children: /* @__PURE__ */ jsx("span", { className: "uix-tooltip__content", children: /* @__PURE__ */ jsx("span", { className: "uix-tooltip__label", children: keys ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
159
246
|
text != null && /* @__PURE__ */ jsx("span", { id: `${id}-text`, children: text }),
|
|
160
247
|
/* @__PURE__ */ jsxs("span", { className: "uix-tooltip__shortcut", children: [
|
|
161
248
|
/* @__PURE__ */ jsx("span", { id: `${id}-keys`, className: "uix-visually-hidden", children: spokenKeys(keys, platform) }),
|
|
162
249
|
/* @__PURE__ */ jsx(KbdCombo, { keys: [...keys], platform, "aria-hidden": "true" })
|
|
163
250
|
] })
|
|
164
|
-
] }) : text
|
|
251
|
+
] }) : text }) })
|
|
165
252
|
}
|
|
166
253
|
)
|
|
167
254
|
]
|