@sanity/ui 2.6.4 → 2.6.5
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 +22 -21
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +21 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/primitives/tooltip/tooltip.tsx +29 -27
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildTheme, createColorTheme as createColorTheme$1, hexToRgb as hexToRgb$1, hslToRgb as hslToRgb$1, multiply as multiply$1, parseColor as parseColor$1, rgbToHex as rgbToHex$1, rgbToHsl as rgbToHsl$1, rgba as rgba$1, screen as screen$1, getTheme_v2, getScopedTheme } from "@sanity/ui/theme";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, Children, isValidElement, cloneElement, Component, memo, useReducer, Fragment as Fragment$1, startTransition } from "react";
|
|
3
|
+
import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, Children, isValidElement, cloneElement, Component, memo, useLayoutEffect, useReducer, Fragment as Fragment$1, startTransition } from "react";
|
|
4
4
|
import ReactIs, { isValidElementType } from "react-is";
|
|
5
5
|
import { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, styled, keyframes } from "styled-components";
|
|
6
6
|
import { SpinnerIcon, CheckmarkIcon, RemoveIcon, ChevronDownIcon, CloseIcon, ChevronRightIcon, ToggleArrowRightIcon } from "@sanity/icons";
|
|
@@ -4343,7 +4343,6 @@ function TooltipDelayGroupProvider(props) {
|
|
|
4343
4343
|
}
|
|
4344
4344
|
const Root$a = styled(Layer)`
|
|
4345
4345
|
pointer-events: none;
|
|
4346
|
-
max-width: ${({ $maxWidth }) => $maxWidth}px;
|
|
4347
4346
|
`, Tooltip = forwardRef(function(props, forwardedRef) {
|
|
4348
4347
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4349
4348
|
const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
|
|
@@ -4363,18 +4362,9 @@ const Root$a = styled(Layer)`
|
|
|
4363
4362
|
zOffset = layer.tooltip.zOffset,
|
|
4364
4363
|
delay,
|
|
4365
4364
|
...restProps
|
|
4366
|
-
} = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport";
|
|
4365
|
+
} = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport", [tooltipMaxWidth, setTooltipMaxWidth] = useState(0);
|
|
4367
4366
|
useImperativeHandle(forwardedRef, () => ref.current);
|
|
4368
|
-
const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element,
|
|
4369
|
-
const availableWidths = [
|
|
4370
|
-
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4371
|
-
portalElement != null && portalElement.offsetWidth || mounted ? document.body.offsetWidth : (
|
|
4372
|
-
// We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
|
|
4373
|
-
800
|
|
4374
|
-
)
|
|
4375
|
-
];
|
|
4376
|
-
return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
|
|
4377
|
-
}, [boundaryElement, mounted, portalElement]), middleware = useMemo(() => {
|
|
4367
|
+
const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, middleware = useMemo(() => {
|
|
4378
4368
|
const ret = [];
|
|
4379
4369
|
return ret.push(
|
|
4380
4370
|
flip({
|
|
@@ -4457,7 +4447,13 @@ const Root$a = styled(Layer)`
|
|
|
4457
4447
|
return window.addEventListener("keydown", handleWindowKeyDown), () => {
|
|
4458
4448
|
window.removeEventListener("keydown", handleWindowKeyDown);
|
|
4459
4449
|
};
|
|
4460
|
-
}, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip })
|
|
4450
|
+
}, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip }), useLayoutEffect(() => {
|
|
4451
|
+
const availableWidths = [
|
|
4452
|
+
...boundaryElement ? [boundaryElement.offsetWidth] : [],
|
|
4453
|
+
(portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
|
|
4454
|
+
];
|
|
4455
|
+
setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
|
|
4456
|
+
}, [boundaryElement, portalElement]);
|
|
4461
4457
|
const setArrow = useCallback(
|
|
4462
4458
|
(arrowEl) => {
|
|
4463
4459
|
arrowRef.current = arrowEl, update();
|
|
@@ -4498,9 +4494,11 @@ const Root$a = styled(Layer)`
|
|
|
4498
4494
|
"data-ui": "Tooltip",
|
|
4499
4495
|
...restProps,
|
|
4500
4496
|
ref: setFloating,
|
|
4501
|
-
style:
|
|
4497
|
+
style: {
|
|
4498
|
+
...floatingStyles,
|
|
4499
|
+
maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
|
|
4500
|
+
},
|
|
4502
4501
|
zOffset,
|
|
4503
|
-
$maxWidth: tooltipWidth,
|
|
4504
4502
|
children: /* @__PURE__ */ jsx(
|
|
4505
4503
|
TooltipCard,
|
|
4506
4504
|
{
|
|
@@ -4547,13 +4545,16 @@ function useCloseOnMouseLeave({
|
|
|
4547
4545
|
referenceElement,
|
|
4548
4546
|
showTooltip
|
|
4549
4547
|
}) {
|
|
4550
|
-
const
|
|
4551
|
-
referenceElement && (referenceElement ===
|
|
4548
|
+
const onMouseMove = useEffectEvent((target) => {
|
|
4549
|
+
referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || handleIsOpenChange(!1));
|
|
4552
4550
|
});
|
|
4553
4551
|
useEffect(() => {
|
|
4554
|
-
if (showTooltip)
|
|
4555
|
-
|
|
4556
|
-
|
|
4552
|
+
if (!showTooltip) return;
|
|
4553
|
+
const handleMouseMove = (event) => {
|
|
4554
|
+
onMouseMove(event.target);
|
|
4555
|
+
};
|
|
4556
|
+
return window.addEventListener("mousemove", handleMouseMove), () => window.removeEventListener("mousemove", handleMouseMove);
|
|
4557
|
+
}, [onMouseMove, showTooltip]);
|
|
4557
4558
|
}
|
|
4558
4559
|
const Root$9 = styled.div`
|
|
4559
4560
|
line-height: 0;
|