@sanity/ui 2.6.4 → 2.6.6
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/index.esm.js +23 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +22 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/primitives/tooltip/tooltip.tsx +33 -29
package/dist/index.js
CHANGED
|
@@ -4338,7 +4338,6 @@ function TooltipDelayGroupProvider(props) {
|
|
|
4338
4338
|
}
|
|
4339
4339
|
const Root$a = styledComponents.styled(Layer)`
|
|
4340
4340
|
pointer-events: none;
|
|
4341
|
-
max-width: ${({ $maxWidth }) => $maxWidth}px;
|
|
4342
4341
|
`, Tooltip = react.forwardRef(function(props, forwardedRef) {
|
|
4343
4342
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4344
4343
|
const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
|
|
@@ -4358,18 +4357,9 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4358
4357
|
zOffset = layer.tooltip.zOffset,
|
|
4359
4358
|
delay,
|
|
4360
4359
|
...restProps
|
|
4361
|
-
} = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
|
|
4360
|
+
} = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport", [tooltipMaxWidth, setTooltipMaxWidth] = react.useState(0);
|
|
4362
4361
|
react.useImperativeHandle(forwardedRef, () => ref.current);
|
|
4363
|
-
const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element,
|
|
4364
|
-
const availableWidths = [
|
|
4365
|
-
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4366
|
-
portalElement != null && portalElement.offsetWidth || mounted ? document.body.offsetWidth : (
|
|
4367
|
-
// We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
|
|
4368
|
-
800
|
|
4369
|
-
)
|
|
4370
|
-
];
|
|
4371
|
-
return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
|
|
4372
|
-
}, [boundaryElement, mounted, portalElement]), middleware = react.useMemo(() => {
|
|
4362
|
+
const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, middleware = react.useMemo(() => {
|
|
4373
4363
|
const ret = [];
|
|
4374
4364
|
return ret.push(
|
|
4375
4365
|
reactDom$1.flip({
|
|
@@ -4440,7 +4430,7 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4440
4430
|
},
|
|
4441
4431
|
[childProp == null ? void 0 : childProp.props, handleIsOpenChange]
|
|
4442
4432
|
);
|
|
4443
|
-
react.useEffect(() => {
|
|
4433
|
+
useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip }), react.useEffect(() => {
|
|
4444
4434
|
disabled && showTooltip && handleIsOpenChange(!1);
|
|
4445
4435
|
}, [disabled, handleIsOpenChange, showTooltip]), react.useEffect(() => {
|
|
4446
4436
|
!content && showTooltip && handleIsOpenChange(!1);
|
|
@@ -4452,7 +4442,13 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4452
4442
|
return window.addEventListener("keydown", handleWindowKeyDown), () => {
|
|
4453
4443
|
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
4454
4444
|
};
|
|
4455
|
-
}, [handleIsOpenChange, showTooltip]),
|
|
4445
|
+
}, [handleIsOpenChange, showTooltip]), react.useLayoutEffect(() => {
|
|
4446
|
+
const availableWidths = [
|
|
4447
|
+
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4448
|
+
(portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
|
|
4449
|
+
];
|
|
4450
|
+
setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
|
|
4451
|
+
}, [boundaryElement, portalElement]);
|
|
4456
4452
|
const setArrow = react.useCallback(
|
|
4457
4453
|
(arrowEl) => {
|
|
4458
4454
|
arrowRef.current = arrowEl, update();
|
|
@@ -4493,9 +4489,11 @@ const Root$a = styledComponents.styled(Layer)`
|
|
|
4493
4489
|
"data-ui": "Tooltip",
|
|
4494
4490
|
...restProps,
|
|
4495
4491
|
ref: setFloating,
|
|
4496
|
-
style:
|
|
4492
|
+
style: {
|
|
4493
|
+
...floatingStyles,
|
|
4494
|
+
maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
|
|
4495
|
+
},
|
|
4497
4496
|
zOffset,
|
|
4498
|
-
$maxWidth: tooltipWidth,
|
|
4499
4497
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4500
4498
|
TooltipCard,
|
|
4501
4499
|
{
|
|
@@ -4542,13 +4540,16 @@ function useCloseOnMouseLeave({
|
|
|
4542
4540
|
referenceElement,
|
|
4543
4541
|
showTooltip
|
|
4544
4542
|
}) {
|
|
4545
|
-
const
|
|
4546
|
-
referenceElement && (referenceElement ===
|
|
4543
|
+
const onMouseMove = useEffectEvent.useEffectEvent((target, teardown) => {
|
|
4544
|
+
referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || (handleIsOpenChange(!1), teardown()));
|
|
4547
4545
|
});
|
|
4548
4546
|
react.useEffect(() => {
|
|
4549
|
-
if (showTooltip)
|
|
4550
|
-
|
|
4551
|
-
|
|
4547
|
+
if (!showTooltip) return;
|
|
4548
|
+
const handleMouseMove = (event) => {
|
|
4549
|
+
onMouseMove(event.target, () => window.removeEventListener("mousemove", handleMouseMove));
|
|
4550
|
+
};
|
|
4551
|
+
return window.addEventListener("mousemove", handleMouseMove), () => window.removeEventListener("mousemove", handleMouseMove);
|
|
4552
|
+
}, [onMouseMove, showTooltip]);
|
|
4552
4553
|
}
|
|
4553
4554
|
const Root$9 = styledComponents.styled.div`
|
|
4554
4555
|
line-height: 0;
|