@sanity/ui 1.9.2 → 1.9.3
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 +57 -33
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +56 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/primitives/tooltip/__workshop__/customPortal.tsx +99 -0
- package/src/primitives/tooltip/__workshop__/index.ts +15 -0
- package/src/primitives/tooltip/__workshop__/overflowingBoundary.tsx +73 -0
- package/src/primitives/tooltip/__workshop__/resizableBoundary.tsx +85 -0
- package/src/primitives/tooltip/constants.ts +1 -0
- package/src/primitives/tooltip/tooltip.test.tsx +125 -0
- package/src/primitives/tooltip/tooltip.tsx +81 -28
package/dist/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import styled, { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css,
|
|
|
5
5
|
import { white as white$1, black as black$1, hues } from '@sanity/color';
|
|
6
6
|
import { SpinnerIcon, CheckmarkIcon, RemoveIcon, SelectIcon, CloseIcon, ChevronDownIcon, ChevronRightIcon, ToggleArrowRightIcon } from '@sanity/icons';
|
|
7
7
|
import Refractor from 'react-refractor';
|
|
8
|
-
import { detectOverflow, flip, offset, shift, arrow, hide, useFloating, autoUpdate
|
|
8
|
+
import { detectOverflow, flip, offset, shift, arrow, hide, useFloating, autoUpdate } from '@floating-ui/react-dom';
|
|
9
9
|
import { createPortal } from 'react-dom';
|
|
10
10
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
11
11
|
const EMPTY_ARRAY = [];
|
|
@@ -6847,6 +6847,7 @@ function useDelayedState(initialState) {
|
|
|
6847
6847
|
}, []);
|
|
6848
6848
|
return [state, onStateChange];
|
|
6849
6849
|
}
|
|
6850
|
+
const DEFAULT_TOOLTIP_PADDING = 4;
|
|
6850
6851
|
const DEFAULT_FALLBACK_PLACEMENTS = {
|
|
6851
6852
|
top: ["bottom", "left", "right"],
|
|
6852
6853
|
"top-start": ["bottom-start", "left-start", "right-start"],
|
|
@@ -6930,9 +6931,14 @@ var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
|
|
|
6930
6931
|
value: __freeze$e(raw || cooked.slice())
|
|
6931
6932
|
}));
|
|
6932
6933
|
var _a$e;
|
|
6933
|
-
const Root$a = styled(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n"]))
|
|
6934
|
+
const Root$a = styled(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n max-width: ", "px;\n"])), _ref22 => {
|
|
6935
|
+
let {
|
|
6936
|
+
$maxWidth
|
|
6937
|
+
} = _ref22;
|
|
6938
|
+
return $maxWidth;
|
|
6939
|
+
});
|
|
6934
6940
|
const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
6935
|
-
var _a2, _b, _c, _d, _e;
|
|
6941
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
6936
6942
|
const boundaryElementContext = useBoundaryElement();
|
|
6937
6943
|
const theme = useTheme();
|
|
6938
6944
|
const {
|
|
@@ -6943,7 +6949,7 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
6943
6949
|
fallbackPlacements: fallbackPlacementsProp = (_b = props.fallbackPlacements) != null ? _b : DEFAULT_FALLBACK_PLACEMENTS[(_a2 = props.placement) != null ? _a2 : "bottom"],
|
|
6944
6950
|
padding,
|
|
6945
6951
|
placement: placementProp = "bottom",
|
|
6946
|
-
portal,
|
|
6952
|
+
portal: portalProp,
|
|
6947
6953
|
scheme,
|
|
6948
6954
|
shadow = 2,
|
|
6949
6955
|
zOffset = (_c = theme.sanity.layer) == null ? void 0 : _c.tooltip.zOffset,
|
|
@@ -6955,38 +6961,27 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
6955
6961
|
const [referenceElement, setReferenceElement] = useState(null);
|
|
6956
6962
|
const arrowRef = useRef(null);
|
|
6957
6963
|
const rootBoundary = "viewport";
|
|
6964
|
+
const portal = usePortal();
|
|
6965
|
+
const portalElement = typeof portalProp === "string" ? ((_d = portal.elements) == null ? void 0 : _d[portalProp]) || null : portal.element;
|
|
6966
|
+
const tooltipWidth = useMemo(() => {
|
|
6967
|
+
const availableWidths = [...(boundaryElement ? [boundaryElement.offsetWidth] : []), (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth];
|
|
6968
|
+
return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
|
|
6969
|
+
}, [boundaryElement, portalElement == null ? void 0 : portalElement.offsetWidth]);
|
|
6958
6970
|
const middleware = useMemo(() => {
|
|
6959
6971
|
const ret = [];
|
|
6960
6972
|
ret.push(flip({
|
|
6961
6973
|
boundary: boundaryElement || void 0,
|
|
6962
6974
|
fallbackPlacements,
|
|
6963
|
-
padding:
|
|
6964
|
-
rootBoundary
|
|
6965
|
-
mainAxis: false
|
|
6975
|
+
padding: DEFAULT_TOOLTIP_PADDING,
|
|
6976
|
+
rootBoundary
|
|
6966
6977
|
}));
|
|
6967
6978
|
ret.push(offset({
|
|
6968
6979
|
mainAxis: 3
|
|
6969
6980
|
}));
|
|
6970
|
-
ret.push(size$2({
|
|
6971
|
-
apply(_ref22) {
|
|
6972
|
-
let {
|
|
6973
|
-
availableWidth,
|
|
6974
|
-
availableHeight,
|
|
6975
|
-
elements
|
|
6976
|
-
} = _ref22;
|
|
6977
|
-
Object.assign(elements.floating.style, {
|
|
6978
|
-
maxWidth: "".concat(availableWidth - 4 * 2, "px"),
|
|
6979
|
-
// the padding is `4px`
|
|
6980
|
-
maxHeight: "".concat(availableHeight - 4 * 2, "px")
|
|
6981
|
-
// the padding is `4px`
|
|
6982
|
-
});
|
|
6983
|
-
}
|
|
6984
|
-
}));
|
|
6985
|
-
|
|
6986
6981
|
ret.push(shift({
|
|
6987
6982
|
boundary: boundaryElement || void 0,
|
|
6988
6983
|
rootBoundary,
|
|
6989
|
-
padding:
|
|
6984
|
+
padding: DEFAULT_TOOLTIP_PADDING
|
|
6990
6985
|
}));
|
|
6991
6986
|
ret.push(arrow({
|
|
6992
6987
|
element: arrowRef,
|
|
@@ -7006,8 +7001,8 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
7006
7001
|
whileElementsMounted: autoUpdate
|
|
7007
7002
|
});
|
|
7008
7003
|
const staticSide = placement && FLOATING_STATIC_SIDES[placement.split("-")[0]];
|
|
7009
|
-
const arrowX = (
|
|
7010
|
-
const arrowY = (
|
|
7004
|
+
const arrowX = (_e = middlewareData.arrow) == null ? void 0 : _e.x;
|
|
7005
|
+
const arrowY = (_f = middlewareData.arrow) == null ? void 0 : _f.y;
|
|
7011
7006
|
const arrowStyle = useMemo(() => {
|
|
7012
7007
|
const style = {
|
|
7013
7008
|
left: arrowX !== null ? arrowX : void 0,
|
|
@@ -7044,10 +7039,36 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
7044
7039
|
setIsOpen(open, standaloneDelay);
|
|
7045
7040
|
}
|
|
7046
7041
|
}, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
|
|
7047
|
-
const handleBlur = useCallback(
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7042
|
+
const handleBlur = useCallback(e => {
|
|
7043
|
+
var _a3, _b2;
|
|
7044
|
+
handleIsOpenChange(false);
|
|
7045
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onBlur) == null ? void 0 : _b2.call(_a3, e);
|
|
7046
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
7047
|
+
const handleClick = useCallback(e => {
|
|
7048
|
+
var _a3, _b2;
|
|
7049
|
+
handleIsOpenChange(false, true);
|
|
7050
|
+
(_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onClick) == null ? void 0 : _b2.call(_a3, e);
|
|
7051
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
7052
|
+
const handleContextMenu = useCallback(e => {
|
|
7053
|
+
var _a3, _b2;
|
|
7054
|
+
handleIsOpenChange(false, true);
|
|
7055
|
+
(_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onContextMenu) == null ? void 0 : _b2.call(_a3, e);
|
|
7056
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
7057
|
+
const handleFocus = useCallback(e => {
|
|
7058
|
+
var _a3, _b2;
|
|
7059
|
+
handleIsOpenChange(true);
|
|
7060
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onFocus) == null ? void 0 : _b2.call(_a3, e);
|
|
7061
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
7062
|
+
const handleMouseEnter = useCallback(e => {
|
|
7063
|
+
var _a3, _b2;
|
|
7064
|
+
handleIsOpenChange(true);
|
|
7065
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseEnter) == null ? void 0 : _b2.call(_a3, e);
|
|
7066
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
7067
|
+
const handleMouseLeave = useCallback(e => {
|
|
7068
|
+
var _a3, _b2;
|
|
7069
|
+
handleIsOpenChange(false);
|
|
7070
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseLeave) == null ? void 0 : _b2.call(_a3, e);
|
|
7071
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
7051
7072
|
useEffect(() => {
|
|
7052
7073
|
if (!isOpen) return;
|
|
7053
7074
|
function handleWindowMouseMove(event) {
|
|
@@ -7106,9 +7127,11 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
7106
7127
|
onFocus: handleFocus,
|
|
7107
7128
|
onMouseEnter: handleMouseEnter,
|
|
7108
7129
|
onMouseLeave: handleMouseLeave,
|
|
7130
|
+
onClick: handleClick,
|
|
7131
|
+
onContextMenu: handleContextMenu,
|
|
7109
7132
|
ref: setReference
|
|
7110
7133
|
});
|
|
7111
|
-
}, [childProp, handleBlur, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
|
|
7134
|
+
}, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
|
|
7112
7135
|
if (!child) return /* @__PURE__ */jsx(Fragment, {});
|
|
7113
7136
|
if (disabled) return child;
|
|
7114
7137
|
const root = /* @__PURE__ */jsx(Root$a, {
|
|
@@ -7117,6 +7140,7 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
7117
7140
|
ref: setFloating,
|
|
7118
7141
|
style: floatingStyles,
|
|
7119
7142
|
zOffset,
|
|
7143
|
+
$maxWidth: tooltipWidth,
|
|
7120
7144
|
children: /* @__PURE__ */jsxs(Card, {
|
|
7121
7145
|
"data-ui": "Tooltip__card",
|
|
7122
7146
|
"data-placement": placement,
|
|
@@ -7132,8 +7156,8 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
|
|
|
7132
7156
|
});
|
|
7133
7157
|
return /* @__PURE__ */jsxs(Fragment, {
|
|
7134
7158
|
children: [child, showTooltip && /* @__PURE__ */jsx(Fragment, {
|
|
7135
|
-
children:
|
|
7136
|
-
__unstable_name: typeof
|
|
7159
|
+
children: portalProp ? /* @__PURE__ */jsx(Portal, {
|
|
7160
|
+
__unstable_name: typeof portalProp === "string" ? portalProp : void 0,
|
|
7137
7161
|
children: root
|
|
7138
7162
|
}) : root
|
|
7139
7163
|
})]
|