@sanity/ui 2.6.7 → 2.6.8

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 (34) hide show
  1. package/dist/index.d.mts +9 -9
  2. package/dist/index.d.ts +9 -9
  3. package/dist/index.esm.js +36 -31
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +35 -31
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +36 -31
  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 +25 -24
  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/tab/tab.tsx +8 -8
  20. package/src/core/components/tab/tabPanel.tsx +1 -1
  21. package/src/core/primitives/avatar/styles.ts +42 -42
  22. package/src/core/primitives/badge/styles.ts +2 -2
  23. package/src/core/primitives/button/styles.ts +4 -4
  24. package/src/core/primitives/inline/styles.ts +2 -2
  25. package/src/core/primitives/popover/constants.ts +4 -4
  26. package/src/core/primitives/stack/styles.ts +2 -2
  27. package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +1 -1
  28. package/src/core/primitives/tooltip/constants.ts +4 -4
  29. package/src/core/primitives/tooltip/tooltip.tsx +68 -49
  30. package/src/core/styles/font/responsiveFont.ts +8 -8
  31. package/src/core/theme/__workshop__/debug/story.tsx +11 -11
  32. package/src/theme/build/buildColorTheme.test.ts +13 -13
  33. package/src/theme/config/tokens/color/types.ts +14 -14
  34. package/src/theme/defaults/colorTokens.ts +36 -36
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { buildTheme, createColorTheme as createColorTheme$1, hexToRgb as hexToRgb$1, hslToRgb as hslToRgb$1, multiply as multiply$1, parseColor as parseColor$1, rgbToHex as rgbToHex$1, rgbToHsl as rgbToHsl$1, rgba as rgba$1, screen as screen$1, getTheme_v2, getScopedTheme } from "@sanity/ui/theme";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, Children, isValidElement, cloneElement, Component, memo, useReducer, Fragment as Fragment$1, startTransition } from "react";
3
+ import { useMemo, useState, useRef, useEffect, createContext, useContext, useSyncExternalStore, useImperativeHandle, forwardRef, useId, useCallback, Children, isValidElement, cloneElement, Component, memo, useLayoutEffect, useReducer, Fragment as Fragment$1, startTransition } from "react";
4
4
  import ReactIs, { isValidElementType } from "react-is";
5
5
  import { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, styled, keyframes } from "styled-components";
6
6
  import { SpinnerIcon, CheckmarkIcon, RemoveIcon, ChevronDownIcon, CloseIcon, ChevronRightIcon, ToggleArrowRightIcon } from "@sanity/icons";
@@ -8,6 +8,7 @@ import Refractor from "react-refractor";
8
8
  import { detectOverflow, flip, offset, shift, arrow, hide, useFloating, autoUpdate } from "@floating-ui/react-dom";
9
9
  import { motion, AnimatePresence } from "framer-motion";
10
10
  import { createPortal } from "react-dom";
11
+ import { useEffectEvent } from "use-effect-event";
11
12
  import { getTheme_v2 as getTheme_v2$1 } from "./_chunks-es/getTheme_v2.mjs";
12
13
  const createColorTheme = createColorTheme$1, hexToRgb = hexToRgb$1, hslToRgb = hslToRgb$1, multiply = multiply$1, parseColor = parseColor$1, rgbToHex = rgbToHex$1, rgbToHsl = rgbToHsl$1, rgba = rgba$1, screen = screen$1, studioTheme = buildTheme(), EMPTY_ARRAY = [], EMPTY_RECORD = {}, POPOVER_MOTION_CONTENT_OPACITY_PROPERTY = "--motion-content-opacity", POPOVER_MOTION_PROPS = {
13
14
  initial: {
@@ -3071,7 +3072,7 @@ function _isEqual(objA, objB) {
3071
3072
  }
3072
3073
  function PortalProvider(props) {
3073
3074
  const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = useSyncExternalStore(
3074
- emptySubscribe$1,
3075
+ emptySubscribe,
3075
3076
  () => document.body,
3076
3077
  () => null
3077
3078
  ), value = useMemo(() => ({
@@ -3082,7 +3083,7 @@ function PortalProvider(props) {
3082
3083
  }), [boundaryElement, element, elements, fallbackElement]);
3083
3084
  return /* @__PURE__ */ jsx(PortalContext.Provider, { value, children });
3084
3085
  }
3085
- const emptySubscribe$1 = () => () => {
3086
+ const emptySubscribe = () => () => {
3086
3087
  }, Root$i = styled.div`
3087
3088
  display: block;
3088
3089
  width: 0;
@@ -4338,7 +4339,6 @@ function TooltipDelayGroupProvider(props) {
4338
4339
  }
4339
4340
  const Root$a = styled(Layer)`
4340
4341
  pointer-events: none;
4341
- max-width: ${({ $maxWidth }) => $maxWidth}px;
4342
4342
  `, Tooltip = forwardRef(function(props, forwardedRef) {
4343
4343
  var _a, _b, _c, _d, _e, _f, _g;
4344
4344
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
@@ -4358,20 +4358,9 @@ const Root$a = styled(Layer)`
4358
4358
  zOffset = layer.tooltip.zOffset,
4359
4359
  delay,
4360
4360
  ...restProps
4361
- } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport";
4361
+ } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport", [tooltipMaxWidth, setTooltipMaxWidth] = useState(0);
4362
4362
  useImperativeHandle(forwardedRef, () => ref.current);
4363
- const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, documentBodyOffsetWidth = useSyncExternalStore(
4364
- emptySubscribe,
4365
- () => document.body.offsetWidth,
4366
- // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
4367
- () => 800
4368
- ), tooltipWidth = useMemo(() => {
4369
- const availableWidths = [
4370
- ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4371
- (portalElement == null ? void 0 : portalElement.offsetWidth) || documentBodyOffsetWidth
4372
- ];
4373
- return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
4374
- }, [boundaryElement, documentBodyOffsetWidth, portalElement == null ? void 0 : portalElement.offsetWidth]), middleware = useMemo(() => {
4363
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, middleware = useMemo(() => {
4375
4364
  const ret = [];
4376
4365
  return ret.push(
4377
4366
  flip({
@@ -4442,15 +4431,7 @@ const Root$a = styled(Layer)`
4442
4431
  },
4443
4432
  [childProp == null ? void 0 : childProp.props, handleIsOpenChange]
4444
4433
  );
4445
- useEffect(() => {
4446
- if (!showTooltip) return;
4447
- function handleWindowMouseMove(event) {
4448
- referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || (handleIsOpenChange(!1), window.removeEventListener("mousemove", handleWindowMouseMove)));
4449
- }
4450
- return window.addEventListener("mousemove", handleWindowMouseMove), () => {
4451
- window.removeEventListener("mousemove", handleWindowMouseMove);
4452
- };
4453
- }, [showTooltip, referenceElement, handleIsOpenChange]), useEffect(() => {
4434
+ useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip }), useEffect(() => {
4454
4435
  disabled && showTooltip && handleIsOpenChange(!1);
4455
4436
  }, [disabled, handleIsOpenChange, showTooltip]), useEffect(() => {
4456
4437
  !content && showTooltip && handleIsOpenChange(!1);
@@ -4462,7 +4443,13 @@ const Root$a = styled(Layer)`
4462
4443
  return window.addEventListener("keydown", handleWindowKeyDown), () => {
4463
4444
  window.removeEventListener("keydown", handleWindowKeyDown);
4464
4445
  };
4465
- }, [handleIsOpenChange, showTooltip]);
4446
+ }, [handleIsOpenChange, showTooltip]), useLayoutEffect(() => {
4447
+ const availableWidths = [
4448
+ ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4449
+ (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
4450
+ ];
4451
+ setTooltipMaxWidth(Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2);
4452
+ }, [boundaryElement, portalElement]);
4466
4453
  const setArrow = useCallback(
4467
4454
  (arrowEl) => {
4468
4455
  arrowRef.current = arrowEl, update();
@@ -4503,9 +4490,11 @@ const Root$a = styled(Layer)`
4503
4490
  "data-ui": "Tooltip",
4504
4491
  ...restProps,
4505
4492
  ref: setFloating,
4506
- style: floatingStyles,
4493
+ style: {
4494
+ ...floatingStyles,
4495
+ maxWidth: tooltipMaxWidth > 0 ? `${tooltipMaxWidth}px` : void 0
4496
+ },
4507
4497
  zOffset,
4508
- $maxWidth: tooltipWidth,
4509
4498
  children: /* @__PURE__ */ jsx(
4510
4499
  TooltipCard,
4511
4500
  {
@@ -4546,8 +4535,24 @@ const Root$a = styled(Layer)`
4546
4535
  ),
4547
4536
  child
4548
4537
  ] });
4549
- }), emptySubscribe = () => () => {
4550
- }, Root$9 = styled.div`
4538
+ });
4539
+ function useCloseOnMouseLeave({
4540
+ handleIsOpenChange,
4541
+ referenceElement,
4542
+ showTooltip
4543
+ }) {
4544
+ const onMouseMove = useEffectEvent((target, teardown) => {
4545
+ referenceElement && (referenceElement === target || target instanceof Node && referenceElement.contains(target) || (handleIsOpenChange(!1), teardown()));
4546
+ });
4547
+ useEffect(() => {
4548
+ if (!showTooltip) return;
4549
+ const handleMouseMove = (event) => {
4550
+ onMouseMove(event.target, () => window.removeEventListener("mousemove", handleMouseMove));
4551
+ };
4552
+ return window.addEventListener("mousemove", handleMouseMove), () => window.removeEventListener("mousemove", handleMouseMove);
4553
+ }, [onMouseMove, showTooltip]);
4554
+ }
4555
+ const Root$9 = styled.div`
4551
4556
  line-height: 0;
4552
4557
  `, ListBox = styled(Box)`
4553
4558
  & > ul {