@sanity/ui 2.0.0-alpha.20 → 2.0.0-alpha.21
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.js
CHANGED
|
@@ -7816,6 +7816,7 @@ function useDelayedState(initialState) {
|
|
|
7816
7816
|
}, []);
|
|
7817
7817
|
return [state, onStateChange];
|
|
7818
7818
|
}
|
|
7819
|
+
const DEFAULT_TOOLTIP_PADDING = 4;
|
|
7819
7820
|
const DEFAULT_FALLBACK_PLACEMENTS = {
|
|
7820
7821
|
top: ["bottom", "left", "right"],
|
|
7821
7822
|
"top-start": ["bottom-start", "left-start", "right-start"],
|
|
@@ -7899,9 +7900,14 @@ var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
|
|
|
7899
7900
|
value: __freeze$e(raw || cooked.slice())
|
|
7900
7901
|
}));
|
|
7901
7902
|
var _a$e;
|
|
7902
|
-
const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n"]))
|
|
7903
|
+
const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n max-width: ", "px;\n"])), _ref27 => {
|
|
7904
|
+
let {
|
|
7905
|
+
$maxWidth
|
|
7906
|
+
} = _ref27;
|
|
7907
|
+
return $maxWidth;
|
|
7908
|
+
});
|
|
7903
7909
|
const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
7904
|
-
var _a2, _b, _c, _d, _e;
|
|
7910
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
7905
7911
|
const boundaryElementContext = useBoundaryElement();
|
|
7906
7912
|
const theme = useTheme();
|
|
7907
7913
|
const {
|
|
@@ -7912,7 +7918,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
7912
7918
|
fallbackPlacements: fallbackPlacementsProp = (_b = props.fallbackPlacements) != null ? _b : DEFAULT_FALLBACK_PLACEMENTS[(_a2 = props.placement) != null ? _a2 : "bottom"],
|
|
7913
7919
|
padding = 3,
|
|
7914
7920
|
placement: placementProp = "bottom",
|
|
7915
|
-
portal,
|
|
7921
|
+
portal: portalProp,
|
|
7916
7922
|
scheme,
|
|
7917
7923
|
shadow = 2,
|
|
7918
7924
|
zOffset = (_c = theme.sanity.layer) == null ? void 0 : _c.tooltip.zOffset,
|
|
@@ -7924,38 +7930,27 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
7924
7930
|
const [referenceElement, setReferenceElement] = react.useState(null);
|
|
7925
7931
|
const arrowRef = react.useRef(null);
|
|
7926
7932
|
const rootBoundary = "viewport";
|
|
7933
|
+
const portal = usePortal();
|
|
7934
|
+
const portalElement = typeof portalProp === "string" ? ((_d = portal.elements) == null ? void 0 : _d[portalProp]) || null : portal.element;
|
|
7935
|
+
const tooltipWidth = react.useMemo(() => {
|
|
7936
|
+
const availableWidths = [...(boundaryElement ? [boundaryElement.offsetWidth] : []), (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth];
|
|
7937
|
+
return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
|
|
7938
|
+
}, [boundaryElement, portalElement == null ? void 0 : portalElement.offsetWidth]);
|
|
7927
7939
|
const middleware = react.useMemo(() => {
|
|
7928
7940
|
const ret = [];
|
|
7929
7941
|
ret.push(reactDom$1.flip({
|
|
7930
7942
|
boundary: boundaryElement || void 0,
|
|
7931
7943
|
fallbackPlacements,
|
|
7932
|
-
padding:
|
|
7933
|
-
rootBoundary
|
|
7934
|
-
mainAxis: false
|
|
7944
|
+
padding: DEFAULT_TOOLTIP_PADDING,
|
|
7945
|
+
rootBoundary
|
|
7935
7946
|
}));
|
|
7936
7947
|
ret.push(reactDom$1.offset({
|
|
7937
7948
|
mainAxis: 3
|
|
7938
7949
|
}));
|
|
7939
|
-
ret.push(reactDom$1.size({
|
|
7940
|
-
apply(_ref27) {
|
|
7941
|
-
let {
|
|
7942
|
-
availableWidth,
|
|
7943
|
-
availableHeight,
|
|
7944
|
-
elements
|
|
7945
|
-
} = _ref27;
|
|
7946
|
-
Object.assign(elements.floating.style, {
|
|
7947
|
-
maxWidth: "".concat(availableWidth - 4 * 2, "px"),
|
|
7948
|
-
// the padding is `4px`
|
|
7949
|
-
maxHeight: "".concat(availableHeight - 4 * 2, "px")
|
|
7950
|
-
// the padding is `4px`
|
|
7951
|
-
});
|
|
7952
|
-
}
|
|
7953
|
-
}));
|
|
7954
|
-
|
|
7955
7950
|
ret.push(reactDom$1.shift({
|
|
7956
7951
|
boundary: boundaryElement || void 0,
|
|
7957
7952
|
rootBoundary,
|
|
7958
|
-
padding:
|
|
7953
|
+
padding: DEFAULT_TOOLTIP_PADDING
|
|
7959
7954
|
}));
|
|
7960
7955
|
ret.push(reactDom$1.arrow({
|
|
7961
7956
|
element: arrowRef,
|
|
@@ -7975,8 +7970,8 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
7975
7970
|
whileElementsMounted: reactDom$1.autoUpdate
|
|
7976
7971
|
});
|
|
7977
7972
|
const staticSide = placement && FLOATING_STATIC_SIDES[placement.split("-")[0]];
|
|
7978
|
-
const arrowX = (
|
|
7979
|
-
const arrowY = (
|
|
7973
|
+
const arrowX = (_e = middlewareData.arrow) == null ? void 0 : _e.x;
|
|
7974
|
+
const arrowY = (_f = middlewareData.arrow) == null ? void 0 : _f.y;
|
|
7980
7975
|
const arrowStyle = react.useMemo(() => {
|
|
7981
7976
|
const style = {
|
|
7982
7977
|
left: arrowX !== null ? arrowX : void 0,
|
|
@@ -8013,10 +8008,36 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
8013
8008
|
setIsOpen(open, standaloneDelay);
|
|
8014
8009
|
}
|
|
8015
8010
|
}, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
|
|
8016
|
-
const handleBlur = react.useCallback(
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8011
|
+
const handleBlur = react.useCallback(e => {
|
|
8012
|
+
var _a3, _b2;
|
|
8013
|
+
handleIsOpenChange(false);
|
|
8014
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onBlur) == null ? void 0 : _b2.call(_a3, e);
|
|
8015
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
8016
|
+
const handleClick = react.useCallback(e => {
|
|
8017
|
+
var _a3, _b2;
|
|
8018
|
+
handleIsOpenChange(false, true);
|
|
8019
|
+
(_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onClick) == null ? void 0 : _b2.call(_a3, e);
|
|
8020
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
8021
|
+
const handleContextMenu = react.useCallback(e => {
|
|
8022
|
+
var _a3, _b2;
|
|
8023
|
+
handleIsOpenChange(false, true);
|
|
8024
|
+
(_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onContextMenu) == null ? void 0 : _b2.call(_a3, e);
|
|
8025
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
8026
|
+
const handleFocus = react.useCallback(e => {
|
|
8027
|
+
var _a3, _b2;
|
|
8028
|
+
handleIsOpenChange(true);
|
|
8029
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onFocus) == null ? void 0 : _b2.call(_a3, e);
|
|
8030
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
8031
|
+
const handleMouseEnter = react.useCallback(e => {
|
|
8032
|
+
var _a3, _b2;
|
|
8033
|
+
handleIsOpenChange(true);
|
|
8034
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseEnter) == null ? void 0 : _b2.call(_a3, e);
|
|
8035
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
8036
|
+
const handleMouseLeave = react.useCallback(e => {
|
|
8037
|
+
var _a3, _b2;
|
|
8038
|
+
handleIsOpenChange(false);
|
|
8039
|
+
(_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseLeave) == null ? void 0 : _b2.call(_a3, e);
|
|
8040
|
+
}, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
|
|
8020
8041
|
react.useEffect(() => {
|
|
8021
8042
|
if (!isOpen) return;
|
|
8022
8043
|
function handleWindowMouseMove(event) {
|
|
@@ -8075,9 +8096,11 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
8075
8096
|
onFocus: handleFocus,
|
|
8076
8097
|
onMouseEnter: handleMouseEnter,
|
|
8077
8098
|
onMouseLeave: handleMouseLeave,
|
|
8099
|
+
onClick: handleClick,
|
|
8100
|
+
onContextMenu: handleContextMenu,
|
|
8078
8101
|
ref: setReference
|
|
8079
8102
|
});
|
|
8080
|
-
}, [childProp, handleBlur, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
|
|
8103
|
+
}, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
|
|
8081
8104
|
if (!child) return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
8082
8105
|
if (disabled) return child;
|
|
8083
8106
|
const root = /* @__PURE__ */jsxRuntime.jsx(Root$a, {
|
|
@@ -8086,6 +8109,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
8086
8109
|
ref: setFloating,
|
|
8087
8110
|
style: floatingStyles,
|
|
8088
8111
|
zOffset,
|
|
8112
|
+
$maxWidth: tooltipWidth,
|
|
8089
8113
|
children: /* @__PURE__ */jsxRuntime.jsxs(Card, {
|
|
8090
8114
|
"data-ui": "Tooltip__card",
|
|
8091
8115
|
"data-placement": placement,
|
|
@@ -8101,8 +8125,8 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
|
|
|
8101
8125
|
});
|
|
8102
8126
|
return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
8103
8127
|
children: [child, showTooltip && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
8104
|
-
children:
|
|
8105
|
-
__unstable_name: typeof
|
|
8128
|
+
children: portalProp ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
|
|
8129
|
+
__unstable_name: typeof portalProp === "string" ? portalProp : void 0,
|
|
8106
8130
|
children: root
|
|
8107
8131
|
}) : root
|
|
8108
8132
|
})]
|