@sanity/ui 2.6.4-canary.0 → 2.6.4-canary.1

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.
Files changed (44) hide show
  1. package/dist/index.d.mts +9 -9
  2. package/dist/index.d.ts +9 -9
  3. package/dist/index.esm.js +46 -44
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +45 -44
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +46 -44
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/theme.d.mts +14 -14
  10. package/dist/theme.d.ts +14 -14
  11. package/dist/theme.esm.js.map +1 -1
  12. package/dist/theme.js.map +1 -1
  13. package/dist/theme.mjs.map +1 -1
  14. package/package.json +28 -27
  15. package/src/core/__workshop__/constants.ts +36 -36
  16. package/src/core/components/autocomplete/autocomplete.tsx +1 -1
  17. package/src/core/components/dialog/styles.ts +8 -8
  18. package/src/core/components/menu/menuButton.tsx +10 -10
  19. package/src/core/components/menu/useMenuController.ts +0 -1
  20. package/src/core/components/tab/tab.tsx +8 -8
  21. package/src/core/components/tab/tabPanel.tsx +1 -1
  22. package/src/core/components/toast/styles.ts +1 -2
  23. package/src/core/helpers/focus.ts +0 -1
  24. package/src/core/helpers/scroll.ts +0 -1
  25. package/src/core/hooks/useClickOutside.ts +0 -3
  26. package/src/core/hooks/useElementSize.ts +0 -1
  27. package/src/core/hooks/useMediaIndex/useMediaIndex.ts +0 -1
  28. package/src/core/hooks/usePrefersDark.ts +0 -3
  29. package/src/core/hooks/usePrefersReducedMotion.ts +0 -2
  30. package/src/core/primitives/avatar/styles.ts +42 -42
  31. package/src/core/primitives/badge/styles.ts +2 -2
  32. package/src/core/primitives/button/styles.ts +4 -4
  33. package/src/core/primitives/inline/styles.ts +2 -2
  34. package/src/core/primitives/popover/constants.ts +4 -4
  35. package/src/core/primitives/stack/styles.ts +2 -2
  36. package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +1 -1
  37. package/src/core/primitives/tooltip/constants.ts +4 -4
  38. package/src/core/primitives/tooltip/tooltip.tsx +66 -52
  39. package/src/core/styles/font/responsiveFont.ts +8 -8
  40. package/src/core/theme/__workshop__/debug/story.tsx +11 -11
  41. package/src/core/utils/portal/portalProvider.tsx +5 -11
  42. package/src/theme/build/buildColorTheme.test.ts +13 -13
  43. package/src/theme/config/tokens/color/types.ts +14 -14
  44. package/src/theme/defaults/colorTokens.ts +36 -36
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var theme = require("@sanity/ui/theme"), jsxRuntime = require("react/jsx-runtime"), react = require("react"), ReactIs = require("react-is"), styledComponents = require("styled-components"), icons = require("@sanity/icons"), Refractor = require("react-refractor"), reactDom$1 = require("@floating-ui/react-dom"), framerMotion = require("framer-motion"), reactDom = require("react-dom"), getTheme_v2 = require("./_chunks-cjs/getTheme_v2.js");
3
+ var theme = require("@sanity/ui/theme"), jsxRuntime = require("react/jsx-runtime"), react = require("react"), ReactIs = require("react-is"), styledComponents = require("styled-components"), icons = require("@sanity/icons"), Refractor = require("react-refractor"), reactDom$1 = require("@floating-ui/react-dom"), framerMotion = require("framer-motion"), reactDom = require("react-dom"), useEffectEvent = require("use-effect-event"), getTheme_v2 = require("./_chunks-cjs/getTheme_v2.js");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -3065,21 +3065,25 @@ function _isEqual(objA, objB) {
3065
3065
  const keysA = Object.keys(objA), keysB = Object.keys(objB);
3066
3066
  return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
3067
3067
  }
3068
+ function useMounted() {
3069
+ return react.useSyncExternalStore(
3070
+ subscribe,
3071
+ () => !0,
3072
+ () => !1
3073
+ );
3074
+ }
3075
+ const subscribe = () => () => {
3076
+ };
3068
3077
  function PortalProvider(props) {
3069
- const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(
3070
- emptySubscribe,
3071
- () => document.body,
3072
- () => null
3073
- ), value = react.useMemo(() => ({
3078
+ const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), mounted = useMounted(), value = react.useMemo(() => ({
3074
3079
  version: 0,
3075
3080
  boundaryElement: boundaryElement || null,
3076
- element: element || fallbackElement,
3081
+ element: element || mounted ? document.body : null,
3077
3082
  elements
3078
- }), [boundaryElement, element, elements, fallbackElement]);
3083
+ }), [boundaryElement, element, elements, mounted]);
3079
3084
  return /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children });
3080
3085
  }
3081
- const emptySubscribe = () => () => {
3082
- }, Root$i = styledComponents.styled.div`
3086
+ const Root$i = styledComponents.styled.div`
3083
3087
  display: block;
3084
3088
  width: 0;
3085
3089
  height: 0;
@@ -4334,6 +4338,7 @@ function TooltipDelayGroupProvider(props) {
4334
4338
  }
4335
4339
  const Root$a = styledComponents.styled(Layer)`
4336
4340
  pointer-events: none;
4341
+ max-width: ${({ $maxWidth }) => $maxWidth}px;
4337
4342
  `, Tooltip = react.forwardRef(function(props, forwardedRef) {
4338
4343
  var _a, _b, _c, _d, _e, _f, _g;
4339
4344
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
@@ -4355,21 +4360,18 @@ const Root$a = styledComponents.styled(Layer)`
4355
4360
  ...restProps
4356
4361
  } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = react.useRef(null), [referenceElement, setReferenceElement] = react.useState(null), arrowRef = react.useRef(null), rootBoundary = "viewport";
4357
4362
  react.useImperativeHandle(forwardedRef, () => ref.current);
4358
- const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, middleware = react.useMemo(() => {
4363
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, mounted = useMounted(), tooltipWidth = react.useMemo(() => {
4364
+ const availableWidths = [
4365
+ ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4366
+ portalElement != null && portalElement.offsetWidth || mounted ? document.body.offsetWidth : (
4367
+ // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
4368
+ 800
4369
+ )
4370
+ ];
4371
+ return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
4372
+ }, [boundaryElement, mounted, portalElement]), middleware = react.useMemo(() => {
4359
4373
  const ret = [];
4360
4374
  return ret.push(
4361
- reactDom$1.size({
4362
- apply({ elements }) {
4363
- const availableWidths = [
4364
- ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4365
- (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
4366
- ], tooltipWidth = Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
4367
- Object.assign(elements.floating.style, {
4368
- maxWidth: tooltipWidth > 0 ? `${tooltipWidth}px` : void 0
4369
- });
4370
- }
4371
- })
4372
- ), ret.push(
4373
4375
  reactDom$1.flip({
4374
4376
  boundary: boundaryElement || void 0,
4375
4377
  fallbackPlacements,
@@ -4383,7 +4385,7 @@ const Root$a = styledComponents.styled(Layer)`
4383
4385
  padding: DEFAULT_TOOLTIP_PADDING
4384
4386
  })
4385
4387
  ), arrowProp && ret.push(reactDom$1.arrow({ element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING })), animate && ret.push(origin), ret;
4386
- }, [animate, arrowProp, boundaryElement, fallbackPlacements, portalElement]), { floatingStyles, placement, middlewareData, refs, update } = reactDom$1.useFloating({
4388
+ }, [animate, arrowProp, boundaryElement, fallbackPlacements]), { floatingStyles, placement, middlewareData, refs, update } = reactDom$1.useFloating({
4387
4389
  middleware,
4388
4390
  placement: placementProp,
4389
4391
  whileElementsMounted: reactDom$1.autoUpdate
@@ -4439,14 +4441,6 @@ const Root$a = styledComponents.styled(Layer)`
4439
4441
  [childProp == null ? void 0 : childProp.props, handleIsOpenChange]
4440
4442
  );
4441
4443
  react.useEffect(() => {
4442
- if (!showTooltip) return;
4443
- function handleWindowMouseMove(event) {
4444
- referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || (handleIsOpenChange(!1), window.removeEventListener("mousemove", handleWindowMouseMove)));
4445
- }
4446
- return window.addEventListener("mousemove", handleWindowMouseMove), () => {
4447
- window.removeEventListener("mousemove", handleWindowMouseMove);
4448
- };
4449
- }, [showTooltip, referenceElement, handleIsOpenChange]), react.useEffect(() => {
4450
4444
  disabled && showTooltip && handleIsOpenChange(!1);
4451
4445
  }, [disabled, handleIsOpenChange, showTooltip]), react.useEffect(() => {
4452
4446
  !content && showTooltip && handleIsOpenChange(!1);
@@ -4458,7 +4452,7 @@ const Root$a = styledComponents.styled(Layer)`
4458
4452
  return window.addEventListener("keydown", handleWindowKeyDown), () => {
4459
4453
  window.removeEventListener("keydown", handleWindowKeyDown);
4460
4454
  };
4461
- }, [handleIsOpenChange, showTooltip]);
4455
+ }, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip });
4462
4456
  const setArrow = react.useCallback(
4463
4457
  (arrowEl) => {
4464
4458
  arrowRef.current = arrowEl, update();
@@ -4501,6 +4495,7 @@ const Root$a = styledComponents.styled(Layer)`
4501
4495
  ref: setFloating,
4502
4496
  style: floatingStyles,
4503
4497
  zOffset,
4498
+ $maxWidth: tooltipWidth,
4504
4499
  children: /* @__PURE__ */ jsxRuntime.jsx(
4505
4500
  TooltipCard,
4506
4501
  {
@@ -4541,7 +4536,21 @@ const Root$a = styledComponents.styled(Layer)`
4541
4536
  ),
4542
4537
  child
4543
4538
  ] });
4544
- }), Root$9 = styledComponents.styled.div`
4539
+ });
4540
+ function useCloseOnMouseLeave({
4541
+ handleIsOpenChange,
4542
+ referenceElement,
4543
+ showTooltip
4544
+ }) {
4545
+ const handleWindowMouseMove = useEffectEvent.useEffectEvent((event) => {
4546
+ referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || handleIsOpenChange(!1));
4547
+ });
4548
+ react.useEffect(() => {
4549
+ if (showTooltip)
4550
+ return window.addEventListener("mousemove", handleWindowMouseMove), () => window.removeEventListener("mousemove", handleWindowMouseMove);
4551
+ }, [handleWindowMouseMove, showTooltip]);
4552
+ }
4553
+ const Root$9 = styledComponents.styled.div`
4545
4554
  line-height: 0;
4546
4555
  `, ListBox = styledComponents.styled(Box)`
4547
4556
  & > ul {
@@ -6150,7 +6159,7 @@ const CustomInline = styledComponents.styled(Inline)`
6150
6159
  }
6151
6160
  100% {
6152
6161
  width: 100%;
6153
- }
6162
+ }
6154
6163
  `, LOADING_BAR_HEIGHT = 2;
6155
6164
  function rootStyles(props) {
6156
6165
  const { color } = getTheme_v2.getTheme_v2(props.theme), loadingBarColor = color.button.default[props.tone].enabled.bg;
@@ -6236,15 +6245,7 @@ function Toast(props) {
6236
6245
  }
6237
6246
  );
6238
6247
  }
6239
- function useMounted() {
6240
- return react.useSyncExternalStore(
6241
- subscribe,
6242
- () => !0,
6243
- () => !1
6244
- );
6245
- }
6246
- const subscribe = () => () => {
6247
- }, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
6248
+ const key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
6248
6249
  position: fixed;
6249
6250
  top: 0;
6250
6251
  left: 0;