@sanity/ui 2.0.0-alpha.20 → 2.0.0-alpha.22

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
@@ -5333,7 +5333,8 @@ function badgeStyle(props) {
5333
5333
  const palette = theme.sanity.color[$mode === "outline" ? "muted" : "solid"];
5334
5334
  const color = palette[$tone] || palette.default;
5335
5335
  return {
5336
- backgroundColor: color.enabled.bg,
5336
+ "--card-fg-color": color.enabled.fg,
5337
+ backgroundColor: color.enabled.bg2,
5337
5338
  color: color.enabled.fg,
5338
5339
  boxShadow: "inset 0 0 0 1px ".concat(color.enabled.border),
5339
5340
  cursor: "default",
@@ -7816,6 +7817,8 @@ function useDelayedState(initialState) {
7816
7817
  }, []);
7817
7818
  return [state, onStateChange];
7818
7819
  }
7820
+ const DEFAULT_TOOLTIP_DISTANCE = 4;
7821
+ const DEFAULT_TOOLTIP_PADDING = 4;
7819
7822
  const DEFAULT_FALLBACK_PLACEMENTS = {
7820
7823
  top: ["bottom", "left", "right"],
7821
7824
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -7899,12 +7902,18 @@ var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
7899
7902
  value: __freeze$e(raw || cooked.slice())
7900
7903
  }));
7901
7904
  var _a$e;
7902
- const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n"])));
7905
+ const Root$a = styled__default.default(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n max-width: ", "px;\n"])), _ref27 => {
7906
+ let {
7907
+ $maxWidth
7908
+ } = _ref27;
7909
+ return $maxWidth;
7910
+ });
7903
7911
  const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7904
- var _a2, _b, _c, _d, _e;
7912
+ var _a2, _b, _c, _d, _e, _f;
7905
7913
  const boundaryElementContext = useBoundaryElement();
7906
7914
  const theme = useTheme();
7907
7915
  const {
7916
+ arrow: arrowProp = true,
7908
7917
  boundaryElement = boundaryElementContext == null ? void 0 : boundaryElementContext.element,
7909
7918
  children: childProp,
7910
7919
  content,
@@ -7912,7 +7921,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7912
7921
  fallbackPlacements: fallbackPlacementsProp = (_b = props.fallbackPlacements) != null ? _b : DEFAULT_FALLBACK_PLACEMENTS[(_a2 = props.placement) != null ? _a2 : "bottom"],
7913
7922
  padding = 3,
7914
7923
  placement: placementProp = "bottom",
7915
- portal,
7924
+ portal: portalProp,
7916
7925
  scheme,
7917
7926
  shadow = 2,
7918
7927
  zOffset = (_c = theme.sanity.layer) == null ? void 0 : _c.tooltip.zOffset,
@@ -7924,45 +7933,36 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7924
7933
  const [referenceElement, setReferenceElement] = react.useState(null);
7925
7934
  const arrowRef = react.useRef(null);
7926
7935
  const rootBoundary = "viewport";
7936
+ const portal = usePortal();
7937
+ const portalElement = typeof portalProp === "string" ? ((_d = portal.elements) == null ? void 0 : _d[portalProp]) || null : portal.element;
7938
+ const tooltipWidth = react.useMemo(() => {
7939
+ const availableWidths = [...(boundaryElement ? [boundaryElement.offsetWidth] : []), (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth];
7940
+ return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
7941
+ }, [boundaryElement, portalElement == null ? void 0 : portalElement.offsetWidth]);
7927
7942
  const middleware = react.useMemo(() => {
7928
7943
  const ret = [];
7929
7944
  ret.push(reactDom$1.flip({
7930
7945
  boundary: boundaryElement || void 0,
7931
7946
  fallbackPlacements,
7932
- padding: 4,
7933
- rootBoundary,
7934
- mainAxis: false
7947
+ padding: DEFAULT_TOOLTIP_PADDING,
7948
+ rootBoundary
7935
7949
  }));
7936
7950
  ret.push(reactDom$1.offset({
7937
- mainAxis: 3
7951
+ mainAxis: DEFAULT_TOOLTIP_DISTANCE
7938
7952
  }));
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
7953
  ret.push(reactDom$1.shift({
7956
7954
  boundary: boundaryElement || void 0,
7957
7955
  rootBoundary,
7958
- padding: 4
7959
- }));
7960
- ret.push(reactDom$1.arrow({
7961
- element: arrowRef,
7962
- padding: 2
7956
+ padding: DEFAULT_TOOLTIP_PADDING
7963
7957
  }));
7958
+ if (arrowProp) {
7959
+ ret.push(reactDom$1.arrow({
7960
+ element: arrowRef,
7961
+ padding: 2
7962
+ }));
7963
+ }
7964
7964
  return ret;
7965
- }, [boundaryElement, fallbackPlacements]);
7965
+ }, [arrowProp, boundaryElement, fallbackPlacements]);
7966
7966
  const {
7967
7967
  floatingStyles,
7968
7968
  placement,
@@ -7975,8 +7975,8 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
7975
7975
  whileElementsMounted: reactDom$1.autoUpdate
7976
7976
  });
7977
7977
  const staticSide = placement && FLOATING_STATIC_SIDES[placement.split("-")[0]];
7978
- const arrowX = (_d = middlewareData.arrow) == null ? void 0 : _d.x;
7979
- const arrowY = (_e = middlewareData.arrow) == null ? void 0 : _e.y;
7978
+ const arrowX = (_e = middlewareData.arrow) == null ? void 0 : _e.x;
7979
+ const arrowY = (_f = middlewareData.arrow) == null ? void 0 : _f.y;
7980
7980
  const arrowStyle = react.useMemo(() => {
7981
7981
  const style = {
7982
7982
  left: arrowX !== null ? arrowX : void 0,
@@ -8013,10 +8013,36 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
8013
8013
  setIsOpen(open, standaloneDelay);
8014
8014
  }
8015
8015
  }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
8016
- const handleBlur = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
8017
- const handleFocus = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
8018
- const handleMouseEnter = react.useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
8019
- const handleMouseLeave = react.useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
8016
+ const handleBlur = react.useCallback(e => {
8017
+ var _a3, _b2;
8018
+ handleIsOpenChange(false);
8019
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onBlur) == null ? void 0 : _b2.call(_a3, e);
8020
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8021
+ const handleClick = react.useCallback(e => {
8022
+ var _a3, _b2;
8023
+ handleIsOpenChange(false, true);
8024
+ (_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onClick) == null ? void 0 : _b2.call(_a3, e);
8025
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8026
+ const handleContextMenu = react.useCallback(e => {
8027
+ var _a3, _b2;
8028
+ handleIsOpenChange(false, true);
8029
+ (_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onContextMenu) == null ? void 0 : _b2.call(_a3, e);
8030
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8031
+ const handleFocus = react.useCallback(e => {
8032
+ var _a3, _b2;
8033
+ handleIsOpenChange(true);
8034
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onFocus) == null ? void 0 : _b2.call(_a3, e);
8035
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8036
+ const handleMouseEnter = react.useCallback(e => {
8037
+ var _a3, _b2;
8038
+ handleIsOpenChange(true);
8039
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseEnter) == null ? void 0 : _b2.call(_a3, e);
8040
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8041
+ const handleMouseLeave = react.useCallback(e => {
8042
+ var _a3, _b2;
8043
+ handleIsOpenChange(false);
8044
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseLeave) == null ? void 0 : _b2.call(_a3, e);
8045
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8020
8046
  react.useEffect(() => {
8021
8047
  if (!isOpen) return;
8022
8048
  function handleWindowMouseMove(event) {
@@ -8075,9 +8101,11 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
8075
8101
  onFocus: handleFocus,
8076
8102
  onMouseEnter: handleMouseEnter,
8077
8103
  onMouseLeave: handleMouseLeave,
8104
+ onClick: handleClick,
8105
+ onContextMenu: handleContextMenu,
8078
8106
  ref: setReference
8079
8107
  });
8080
- }, [childProp, handleBlur, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
8108
+ }, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
8081
8109
  if (!child) return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {});
8082
8110
  if (disabled) return child;
8083
8111
  const root = /* @__PURE__ */jsxRuntime.jsx(Root$a, {
@@ -8086,6 +8114,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
8086
8114
  ref: setFloating,
8087
8115
  style: floatingStyles,
8088
8116
  zOffset,
8117
+ $maxWidth: tooltipWidth,
8089
8118
  children: /* @__PURE__ */jsxRuntime.jsxs(Card, {
8090
8119
  "data-ui": "Tooltip__card",
8091
8120
  "data-placement": placement,
@@ -8093,7 +8122,7 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
8093
8122
  radius: 3,
8094
8123
  scheme,
8095
8124
  shadow,
8096
- children: [content, /* @__PURE__ */jsxRuntime.jsx(TooltipArrow, {
8125
+ children: [content, arrowProp && /* @__PURE__ */jsxRuntime.jsx(TooltipArrow, {
8097
8126
  ref: setArrow,
8098
8127
  style: arrowStyle
8099
8128
  })]
@@ -8101,8 +8130,8 @@ const Tooltip = react.forwardRef(function Tooltip2(props, ref) {
8101
8130
  });
8102
8131
  return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
8103
8132
  children: [child, showTooltip && /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
8104
- children: portal ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
8105
- __unstable_name: typeof portal === "string" ? portal : void 0,
8133
+ children: portalProp ? /* @__PURE__ */jsxRuntime.jsx(Portal, {
8134
+ __unstable_name: typeof portalProp === "string" ? portalProp : void 0,
8106
8135
  children: root
8107
8136
  }) : root
8108
8137
  })]
@@ -8238,7 +8267,7 @@ const InnerAutocomplete = react.forwardRef(function InnerAutocomplete2(props, re
8238
8267
  padding: paddingProp = 3,
8239
8268
  popover = EMPTY_RECORD,
8240
8269
  prefix,
8241
- radius = 3,
8270
+ radius = 2,
8242
8271
  readOnly,
8243
8272
  relatedElements,
8244
8273
  renderOption: renderOptionProp,
@@ -10063,6 +10092,7 @@ function Toast(props) {
10063
10092
  closable,
10064
10093
  description,
10065
10094
  onClose,
10095
+ radius = 3,
10066
10096
  title,
10067
10097
  status,
10068
10098
  ...restProps
@@ -10074,7 +10104,7 @@ function Toast(props) {
10074
10104
  role,
10075
10105
  ...restProps,
10076
10106
  marginTop: 3,
10077
- radius: 2,
10107
+ radius,
10078
10108
  shadow: 2,
10079
10109
  tone: cardTone,
10080
10110
  children: /* @__PURE__ */jsxRuntime.jsxs(Flex, {
@@ -10085,7 +10115,8 @@ function Toast(props) {
10085
10115
  children: /* @__PURE__ */jsxRuntime.jsxs(Stack, {
10086
10116
  space: 3,
10087
10117
  children: [title && /* @__PURE__ */jsxRuntime.jsx(Text, {
10088
- weight: "semibold",
10118
+ size: 1,
10119
+ weight: "medium",
10089
10120
  children: title
10090
10121
  }), description && /* @__PURE__ */jsxRuntime.jsx(Text, {
10091
10122
  muted: true,