@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.js CHANGED
@@ -6860,6 +6860,7 @@ function useDelayedState(initialState) {
6860
6860
  }, []);
6861
6861
  return [state, onStateChange];
6862
6862
  }
6863
+ const DEFAULT_TOOLTIP_PADDING = 4;
6863
6864
  const DEFAULT_FALLBACK_PLACEMENTS = {
6864
6865
  top: ["bottom", "left", "right"],
6865
6866
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -6943,9 +6944,14 @@ var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
6943
6944
  value: __freeze$e(raw || cooked.slice())
6944
6945
  }));
6945
6946
  var _a$e;
6946
- const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n"])));
6947
+ const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n max-width: ", "px;\n"])), _ref22 => {
6948
+ let {
6949
+ $maxWidth
6950
+ } = _ref22;
6951
+ return $maxWidth;
6952
+ });
6947
6953
  const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6948
- var _a2, _b, _c, _d, _e;
6954
+ var _a2, _b, _c, _d, _e, _f;
6949
6955
  const boundaryElementContext = useBoundaryElement();
6950
6956
  const theme = useTheme();
6951
6957
  const {
@@ -6956,7 +6962,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6956
6962
  fallbackPlacements: fallbackPlacementsProp = (_b = props.fallbackPlacements) != null ? _b : DEFAULT_FALLBACK_PLACEMENTS[(_a2 = props.placement) != null ? _a2 : "bottom"],
6957
6963
  padding,
6958
6964
  placement: placementProp = "bottom",
6959
- portal,
6965
+ portal: portalProp,
6960
6966
  scheme,
6961
6967
  shadow = 2,
6962
6968
  zOffset = (_c = theme.sanity.layer) == null ? void 0 : _c.tooltip.zOffset,
@@ -6968,38 +6974,27 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
6968
6974
  const [referenceElement, setReferenceElement] = react.useState(null);
6969
6975
  const arrowRef = react.useRef(null);
6970
6976
  const rootBoundary = "viewport";
6977
+ const portal = usePortal();
6978
+ const portalElement = typeof portalProp === "string" ? ((_d = portal.elements) == null ? void 0 : _d[portalProp]) || null : portal.element;
6979
+ const tooltipWidth = react.useMemo(() => {
6980
+ const availableWidths = [...(boundaryElement ? [boundaryElement.offsetWidth] : []), (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth];
6981
+ return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
6982
+ }, [boundaryElement, portalElement == null ? void 0 : portalElement.offsetWidth]);
6971
6983
  const middleware = react.useMemo(() => {
6972
6984
  const ret = [];
6973
6985
  ret.push(reactDom$1.flip({
6974
6986
  boundary: boundaryElement || void 0,
6975
6987
  fallbackPlacements,
6976
- padding: 4,
6977
- rootBoundary,
6978
- mainAxis: false
6988
+ padding: DEFAULT_TOOLTIP_PADDING,
6989
+ rootBoundary
6979
6990
  }));
6980
6991
  ret.push(reactDom$1.offset({
6981
6992
  mainAxis: 3
6982
6993
  }));
6983
- ret.push(reactDom$1.size({
6984
- apply(_ref22) {
6985
- let {
6986
- availableWidth,
6987
- availableHeight,
6988
- elements
6989
- } = _ref22;
6990
- Object.assign(elements.floating.style, {
6991
- maxWidth: "".concat(availableWidth - 4 * 2, "px"),
6992
- // the padding is `4px`
6993
- maxHeight: "".concat(availableHeight - 4 * 2, "px")
6994
- // the padding is `4px`
6995
- });
6996
- }
6997
- }));
6998
-
6999
6994
  ret.push(reactDom$1.shift({
7000
6995
  boundary: boundaryElement || void 0,
7001
6996
  rootBoundary,
7002
- padding: 4
6997
+ padding: DEFAULT_TOOLTIP_PADDING
7003
6998
  }));
7004
6999
  ret.push(reactDom$1.arrow({
7005
7000
  element: arrowRef,
@@ -7019,8 +7014,8 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7019
7014
  whileElementsMounted: reactDom$1.autoUpdate
7020
7015
  });
7021
7016
  const staticSide = placement && FLOATING_STATIC_SIDES[placement.split("-")[0]];
7022
- const arrowX = (_d = middlewareData.arrow) == null ? void 0 : _d.x;
7023
- const arrowY = (_e = middlewareData.arrow) == null ? void 0 : _e.y;
7017
+ const arrowX = (_e = middlewareData.arrow) == null ? void 0 : _e.x;
7018
+ const arrowY = (_f = middlewareData.arrow) == null ? void 0 : _f.y;
7024
7019
  const arrowStyle = react.useMemo(() => {
7025
7020
  const style = {
7026
7021
  left: arrowX !== null ? arrowX : void 0,
@@ -7057,10 +7052,36 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7057
7052
  setIsOpen(open, standaloneDelay);
7058
7053
  }
7059
7054
  }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
7060
- const handleBlur = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
7061
- const handleFocus = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
7062
- const handleMouseEnter = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
7063
- const handleMouseLeave = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
7055
+ const handleBlur = react.useCallback(e => {
7056
+ var _a3, _b2;
7057
+ handleIsOpenChange(false);
7058
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onBlur) == null ? void 0 : _b2.call(_a3, e);
7059
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
7060
+ const handleClick = react.useCallback(e => {
7061
+ var _a3, _b2;
7062
+ handleIsOpenChange(false, true);
7063
+ (_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onClick) == null ? void 0 : _b2.call(_a3, e);
7064
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
7065
+ const handleContextMenu = react.useCallback(e => {
7066
+ var _a3, _b2;
7067
+ handleIsOpenChange(false, true);
7068
+ (_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onContextMenu) == null ? void 0 : _b2.call(_a3, e);
7069
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
7070
+ const handleFocus = react.useCallback(e => {
7071
+ var _a3, _b2;
7072
+ handleIsOpenChange(true);
7073
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onFocus) == null ? void 0 : _b2.call(_a3, e);
7074
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
7075
+ const handleMouseEnter = react.useCallback(e => {
7076
+ var _a3, _b2;
7077
+ handleIsOpenChange(true);
7078
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseEnter) == null ? void 0 : _b2.call(_a3, e);
7079
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
7080
+ const handleMouseLeave = react.useCallback(e => {
7081
+ var _a3, _b2;
7082
+ handleIsOpenChange(false);
7083
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseLeave) == null ? void 0 : _b2.call(_a3, e);
7084
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
7064
7085
  react.useEffect(() => {
7065
7086
  if (!isOpen) return;
7066
7087
  function handleWindowMouseMove(event) {
@@ -7119,9 +7140,11 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7119
7140
  onFocus: handleFocus,
7120
7141
  onMouseEnter: handleMouseEnter,
7121
7142
  onMouseLeave: handleMouseLeave,
7143
+ onClick: handleClick,
7144
+ onContextMenu: handleContextMenu,
7122
7145
  ref: setReference
7123
7146
  });
7124
- }, [childProp, handleBlur, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
7147
+ }, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
7125
7148
  if (!child) return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {});
7126
7149
  if (disabled) return child;
7127
7150
  const root = /* @__PURE__ */jsxRuntime.jsx(Root$a, {
@@ -7130,6 +7153,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7130
7153
  ref: setFloating,
7131
7154
  style: floatingStyles,
7132
7155
  zOffset,
7156
+ $maxWidth: tooltipWidth,
7133
7157
  children: /* @__PURE__ */jsxRuntime.jsxs(Card, {
7134
7158
  "data-ui": "Tooltip__card",
7135
7159
  "data-placement": placement,
@@ -7145,8 +7169,8 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7145
7169
  });
7146
7170
  return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
7147
7171
  children: [child, showTooltip && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
7148
- children: portal ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
7149
- __unstable_name: typeof portal === "string" ? portal : void 0,
7172
+ children: portalProp ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
7173
+ __unstable_name: typeof portalProp === "string" ? portalProp : void 0,
7150
7174
  children: root
7151
7175
  }) : root
7152
7176
  })]