@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.d.ts CHANGED
@@ -3426,6 +3426,7 @@ export declare interface ToastProps {
3426
3426
  closable?: boolean
3427
3427
  description?: React.ReactNode
3428
3428
  onClose?: () => void
3429
+ radius?: number | number[]
3429
3430
  title?: React.ReactNode
3430
3431
  status?: 'error' | 'warning' | 'success' | 'info'
3431
3432
  }
@@ -3541,6 +3542,7 @@ export declare interface TooltipDelayGroupProviderProps {
3541
3542
  export declare interface TooltipProps extends Omit<LayerProps, 'as'> {
3542
3543
  /** @deprecated Use `fallbackPlacements` instead. */
3543
3544
  allowedAutoPlacements?: Placement[]
3545
+ arrow?: boolean
3544
3546
  boundaryElement?: HTMLElement | null
3545
3547
  children?: React.ReactElement
3546
3548
  content?: React.ReactNode
package/dist/index.esm.js CHANGED
@@ -5,7 +5,7 @@ import styled, { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css,
5
5
  import { color as color$1, 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, size as size$2 } from '@floating-ui/react-dom';
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 = [];
@@ -5320,7 +5320,8 @@ function badgeStyle(props) {
5320
5320
  const palette = theme.sanity.color[$mode === "outline" ? "muted" : "solid"];
5321
5321
  const color = palette[$tone] || palette.default;
5322
5322
  return {
5323
- backgroundColor: color.enabled.bg,
5323
+ "--card-fg-color": color.enabled.fg,
5324
+ backgroundColor: color.enabled.bg2,
5324
5325
  color: color.enabled.fg,
5325
5326
  boxShadow: "inset 0 0 0 1px ".concat(color.enabled.border),
5326
5327
  cursor: "default",
@@ -7803,6 +7804,8 @@ function useDelayedState(initialState) {
7803
7804
  }, []);
7804
7805
  return [state, onStateChange];
7805
7806
  }
7807
+ const DEFAULT_TOOLTIP_DISTANCE = 4;
7808
+ const DEFAULT_TOOLTIP_PADDING = 4;
7806
7809
  const DEFAULT_FALLBACK_PLACEMENTS = {
7807
7810
  top: ["bottom", "left", "right"],
7808
7811
  "top-start": ["bottom-start", "left-start", "right-start"],
@@ -7886,12 +7889,18 @@ var __template$e = (cooked, raw) => __freeze$e(__defProp$e(cooked, "raw", {
7886
7889
  value: __freeze$e(raw || cooked.slice())
7887
7890
  }));
7888
7891
  var _a$e;
7889
- const Root$a = styled(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n"])));
7892
+ const Root$a = styled(Layer)(_a$e || (_a$e = __template$e(["\n pointer-events: none;\n max-width: ", "px;\n"])), _ref27 => {
7893
+ let {
7894
+ $maxWidth
7895
+ } = _ref27;
7896
+ return $maxWidth;
7897
+ });
7890
7898
  const Tooltip = forwardRef(function Tooltip2(props, ref) {
7891
- var _a2, _b, _c, _d, _e;
7899
+ var _a2, _b, _c, _d, _e, _f;
7892
7900
  const boundaryElementContext = useBoundaryElement();
7893
7901
  const theme = useTheme();
7894
7902
  const {
7903
+ arrow: arrowProp = true,
7895
7904
  boundaryElement = boundaryElementContext == null ? void 0 : boundaryElementContext.element,
7896
7905
  children: childProp,
7897
7906
  content,
@@ -7899,7 +7908,7 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
7899
7908
  fallbackPlacements: fallbackPlacementsProp = (_b = props.fallbackPlacements) != null ? _b : DEFAULT_FALLBACK_PLACEMENTS[(_a2 = props.placement) != null ? _a2 : "bottom"],
7900
7909
  padding = 3,
7901
7910
  placement: placementProp = "bottom",
7902
- portal,
7911
+ portal: portalProp,
7903
7912
  scheme,
7904
7913
  shadow = 2,
7905
7914
  zOffset = (_c = theme.sanity.layer) == null ? void 0 : _c.tooltip.zOffset,
@@ -7911,45 +7920,36 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
7911
7920
  const [referenceElement, setReferenceElement] = useState(null);
7912
7921
  const arrowRef = useRef(null);
7913
7922
  const rootBoundary = "viewport";
7923
+ const portal = usePortal();
7924
+ const portalElement = typeof portalProp === "string" ? ((_d = portal.elements) == null ? void 0 : _d[portalProp]) || null : portal.element;
7925
+ const tooltipWidth = useMemo(() => {
7926
+ const availableWidths = [...(boundaryElement ? [boundaryElement.offsetWidth] : []), (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth];
7927
+ return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
7928
+ }, [boundaryElement, portalElement == null ? void 0 : portalElement.offsetWidth]);
7914
7929
  const middleware = useMemo(() => {
7915
7930
  const ret = [];
7916
7931
  ret.push(flip({
7917
7932
  boundary: boundaryElement || void 0,
7918
7933
  fallbackPlacements,
7919
- padding: 4,
7920
- rootBoundary,
7921
- mainAxis: false
7934
+ padding: DEFAULT_TOOLTIP_PADDING,
7935
+ rootBoundary
7922
7936
  }));
7923
7937
  ret.push(offset({
7924
- mainAxis: 3
7938
+ mainAxis: DEFAULT_TOOLTIP_DISTANCE
7925
7939
  }));
7926
- ret.push(size$2({
7927
- apply(_ref27) {
7928
- let {
7929
- availableWidth,
7930
- availableHeight,
7931
- elements
7932
- } = _ref27;
7933
- Object.assign(elements.floating.style, {
7934
- maxWidth: "".concat(availableWidth - 4 * 2, "px"),
7935
- // the padding is `4px`
7936
- maxHeight: "".concat(availableHeight - 4 * 2, "px")
7937
- // the padding is `4px`
7938
- });
7939
- }
7940
- }));
7941
-
7942
7940
  ret.push(shift({
7943
7941
  boundary: boundaryElement || void 0,
7944
7942
  rootBoundary,
7945
- padding: 4
7946
- }));
7947
- ret.push(arrow({
7948
- element: arrowRef,
7949
- padding: 2
7943
+ padding: DEFAULT_TOOLTIP_PADDING
7950
7944
  }));
7945
+ if (arrowProp) {
7946
+ ret.push(arrow({
7947
+ element: arrowRef,
7948
+ padding: 2
7949
+ }));
7950
+ }
7951
7951
  return ret;
7952
- }, [boundaryElement, fallbackPlacements]);
7952
+ }, [arrowProp, boundaryElement, fallbackPlacements]);
7953
7953
  const {
7954
7954
  floatingStyles,
7955
7955
  placement,
@@ -7962,8 +7962,8 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
7962
7962
  whileElementsMounted: autoUpdate
7963
7963
  });
7964
7964
  const staticSide = placement && FLOATING_STATIC_SIDES[placement.split("-")[0]];
7965
- const arrowX = (_d = middlewareData.arrow) == null ? void 0 : _d.x;
7966
- const arrowY = (_e = middlewareData.arrow) == null ? void 0 : _e.y;
7965
+ const arrowX = (_e = middlewareData.arrow) == null ? void 0 : _e.x;
7966
+ const arrowY = (_f = middlewareData.arrow) == null ? void 0 : _f.y;
7967
7967
  const arrowStyle = useMemo(() => {
7968
7968
  const style = {
7969
7969
  left: arrowX !== null ? arrowX : void 0,
@@ -8000,10 +8000,36 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
8000
8000
  setIsOpen(open, standaloneDelay);
8001
8001
  }
8002
8002
  }, [isInsideGroup, delayGroupContext, openDelay, tooltipId, closeDelay, setIsOpen]);
8003
- const handleBlur = useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
8004
- const handleFocus = useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
8005
- const handleMouseEnter = useCallback(() => handleIsOpenChange(true), [handleIsOpenChange]);
8006
- const handleMouseLeave = useCallback(() => handleIsOpenChange(false), [handleIsOpenChange]);
8003
+ const handleBlur = useCallback(e => {
8004
+ var _a3, _b2;
8005
+ handleIsOpenChange(false);
8006
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onBlur) == null ? void 0 : _b2.call(_a3, e);
8007
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8008
+ const handleClick = useCallback(e => {
8009
+ var _a3, _b2;
8010
+ handleIsOpenChange(false, true);
8011
+ (_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onClick) == null ? void 0 : _b2.call(_a3, e);
8012
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8013
+ const handleContextMenu = useCallback(e => {
8014
+ var _a3, _b2;
8015
+ handleIsOpenChange(false, true);
8016
+ (_b2 = childProp == null ? void 0 : (_a3 = childProp.props).onContextMenu) == null ? void 0 : _b2.call(_a3, e);
8017
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8018
+ const handleFocus = useCallback(e => {
8019
+ var _a3, _b2;
8020
+ handleIsOpenChange(true);
8021
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onFocus) == null ? void 0 : _b2.call(_a3, e);
8022
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8023
+ const handleMouseEnter = useCallback(e => {
8024
+ var _a3, _b2;
8025
+ handleIsOpenChange(true);
8026
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseEnter) == null ? void 0 : _b2.call(_a3, e);
8027
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8028
+ const handleMouseLeave = useCallback(e => {
8029
+ var _a3, _b2;
8030
+ handleIsOpenChange(false);
8031
+ (_b2 = (_a3 = childProp == null ? void 0 : childProp.props) == null ? void 0 : _a3.onMouseLeave) == null ? void 0 : _b2.call(_a3, e);
8032
+ }, [childProp == null ? void 0 : childProp.props, handleIsOpenChange]);
8007
8033
  useEffect(() => {
8008
8034
  if (!isOpen) return;
8009
8035
  function handleWindowMouseMove(event) {
@@ -8062,9 +8088,11 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
8062
8088
  onFocus: handleFocus,
8063
8089
  onMouseEnter: handleMouseEnter,
8064
8090
  onMouseLeave: handleMouseLeave,
8091
+ onClick: handleClick,
8092
+ onContextMenu: handleContextMenu,
8065
8093
  ref: setReference
8066
8094
  });
8067
- }, [childProp, handleBlur, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
8095
+ }, [childProp, handleBlur, handleClick, handleContextMenu, handleFocus, handleMouseEnter, handleMouseLeave, setReference]);
8068
8096
  if (!child) return /* @__PURE__ */jsx(Fragment, {});
8069
8097
  if (disabled) return child;
8070
8098
  const root = /* @__PURE__ */jsx(Root$a, {
@@ -8073,6 +8101,7 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
8073
8101
  ref: setFloating,
8074
8102
  style: floatingStyles,
8075
8103
  zOffset,
8104
+ $maxWidth: tooltipWidth,
8076
8105
  children: /* @__PURE__ */jsxs(Card, {
8077
8106
  "data-ui": "Tooltip__card",
8078
8107
  "data-placement": placement,
@@ -8080,7 +8109,7 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
8080
8109
  radius: 3,
8081
8110
  scheme,
8082
8111
  shadow,
8083
- children: [content, /* @__PURE__ */jsx(TooltipArrow, {
8112
+ children: [content, arrowProp && /* @__PURE__ */jsx(TooltipArrow, {
8084
8113
  ref: setArrow,
8085
8114
  style: arrowStyle
8086
8115
  })]
@@ -8088,8 +8117,8 @@ const Tooltip = forwardRef(function Tooltip2(props, ref) {
8088
8117
  });
8089
8118
  return /* @__PURE__ */jsxs(Fragment, {
8090
8119
  children: [child, showTooltip && /* @__PURE__ */jsx(Fragment, {
8091
- children: portal ? /* @__PURE__ */jsx(Portal, {
8092
- __unstable_name: typeof portal === "string" ? portal : void 0,
8120
+ children: portalProp ? /* @__PURE__ */jsx(Portal, {
8121
+ __unstable_name: typeof portalProp === "string" ? portalProp : void 0,
8093
8122
  children: root
8094
8123
  }) : root
8095
8124
  })]
@@ -8225,7 +8254,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete2(props, ref) {
8225
8254
  padding: paddingProp = 3,
8226
8255
  popover = EMPTY_RECORD,
8227
8256
  prefix,
8228
- radius = 3,
8257
+ radius = 2,
8229
8258
  readOnly,
8230
8259
  relatedElements,
8231
8260
  renderOption: renderOptionProp,
@@ -10050,6 +10079,7 @@ function Toast(props) {
10050
10079
  closable,
10051
10080
  description,
10052
10081
  onClose,
10082
+ radius = 3,
10053
10083
  title,
10054
10084
  status,
10055
10085
  ...restProps
@@ -10061,7 +10091,7 @@ function Toast(props) {
10061
10091
  role,
10062
10092
  ...restProps,
10063
10093
  marginTop: 3,
10064
- radius: 2,
10094
+ radius,
10065
10095
  shadow: 2,
10066
10096
  tone: cardTone,
10067
10097
  children: /* @__PURE__ */jsxs(Flex, {
@@ -10072,7 +10102,8 @@ function Toast(props) {
10072
10102
  children: /* @__PURE__ */jsxs(Stack, {
10073
10103
  space: 3,
10074
10104
  children: [title && /* @__PURE__ */jsx(Text, {
10075
- weight: "semibold",
10105
+ size: 1,
10106
+ weight: "medium",
10076
10107
  children: title
10077
10108
  }), description && /* @__PURE__ */jsx(Text, {
10078
10109
  muted: true,