@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.d.mts CHANGED
@@ -2069,7 +2069,7 @@ export declare interface TabPanelProps extends BoxProps {
2069
2069
  * The `id` of the correlating `Tab` component.
2070
2070
  */
2071
2071
  'aria-labelledby': string
2072
- id: string
2072
+ 'id': string
2073
2073
  }
2074
2074
 
2075
2075
  /**
@@ -2080,14 +2080,14 @@ export declare interface TabProps {
2080
2080
  * The `id` of the correlating `TabPanel` component.
2081
2081
  */
2082
2082
  'aria-controls': string
2083
- id: string
2084
- icon?: React.ElementType | React.ReactNode
2085
- focused?: boolean
2086
- fontSize?: number | number[]
2087
- label?: React.ReactNode
2088
- padding?: number | number[]
2089
- selected?: boolean
2090
- tone?: ButtonTone
2083
+ 'id': string
2084
+ 'icon'?: React.ElementType | React.ReactNode
2085
+ 'focused'?: boolean
2086
+ 'fontSize'?: number | number[]
2087
+ 'label'?: React.ReactNode
2088
+ 'padding'?: number | number[]
2089
+ 'selected'?: boolean
2090
+ 'tone'?: ButtonTone
2091
2091
  }
2092
2092
 
2093
2093
  /**
package/dist/index.d.ts CHANGED
@@ -2069,7 +2069,7 @@ export declare interface TabPanelProps extends BoxProps {
2069
2069
  * The `id` of the correlating `Tab` component.
2070
2070
  */
2071
2071
  'aria-labelledby': string
2072
- id: string
2072
+ 'id': string
2073
2073
  }
2074
2074
 
2075
2075
  /**
@@ -2080,14 +2080,14 @@ export declare interface TabProps {
2080
2080
  * The `id` of the correlating `TabPanel` component.
2081
2081
  */
2082
2082
  'aria-controls': string
2083
- id: string
2084
- icon?: React.ElementType | React.ReactNode
2085
- focused?: boolean
2086
- fontSize?: number | number[]
2087
- label?: React.ReactNode
2088
- padding?: number | number[]
2089
- selected?: boolean
2090
- tone?: ButtonTone
2083
+ 'id': string
2084
+ 'icon'?: React.ElementType | React.ReactNode
2085
+ 'focused'?: boolean
2086
+ 'fontSize'?: number | number[]
2087
+ 'label'?: React.ReactNode
2088
+ 'padding'?: number | number[]
2089
+ 'selected'?: boolean
2090
+ 'tone'?: ButtonTone
2091
2091
  }
2092
2092
 
2093
2093
  /**
package/dist/index.esm.js CHANGED
@@ -5,9 +5,10 @@ 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";
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 { 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 "./_legacy/getTheme_v2.esm.js";
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: {
@@ -3069,21 +3070,25 @@ function _isEqual(objA, objB) {
3069
3070
  const keysA = Object.keys(objA), keysB = Object.keys(objB);
3070
3071
  return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
3071
3072
  }
3073
+ function useMounted() {
3074
+ return useSyncExternalStore(
3075
+ subscribe,
3076
+ () => !0,
3077
+ () => !1
3078
+ );
3079
+ }
3080
+ const subscribe = () => () => {
3081
+ };
3072
3082
  function PortalProvider(props) {
3073
- const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = useSyncExternalStore(
3074
- emptySubscribe,
3075
- () => document.body,
3076
- () => null
3077
- ), value = useMemo(() => ({
3083
+ const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), mounted = useMounted(), value = useMemo(() => ({
3078
3084
  version: 0,
3079
3085
  boundaryElement: boundaryElement || null,
3080
- element: element || fallbackElement,
3086
+ element: element || mounted ? document.body : null,
3081
3087
  elements
3082
- }), [boundaryElement, element, elements, fallbackElement]);
3088
+ }), [boundaryElement, element, elements, mounted]);
3083
3089
  return /* @__PURE__ */ jsx(PortalContext.Provider, { value, children });
3084
3090
  }
3085
- const emptySubscribe = () => () => {
3086
- }, Root$i = styled.div`
3091
+ const Root$i = styled.div`
3087
3092
  display: block;
3088
3093
  width: 0;
3089
3094
  height: 0;
@@ -4338,6 +4343,7 @@ function TooltipDelayGroupProvider(props) {
4338
4343
  }
4339
4344
  const Root$a = styled(Layer)`
4340
4345
  pointer-events: none;
4346
+ max-width: ${({ $maxWidth }) => $maxWidth}px;
4341
4347
  `, Tooltip = forwardRef(function(props, forwardedRef) {
4342
4348
  var _a, _b, _c, _d, _e, _f, _g;
4343
4349
  const boundaryElementContext = useBoundaryElement(), { layer } = useTheme_v2(), {
@@ -4359,21 +4365,18 @@ const Root$a = styled(Layer)`
4359
4365
  ...restProps
4360
4366
  } = props, animate = usePrefersReducedMotion() ? !1 : _animate, fallbackPlacements = useArrayProp(fallbackPlacementsProp), ref = useRef(null), [referenceElement, setReferenceElement] = useState(null), arrowRef = useRef(null), rootBoundary = "viewport";
4361
4367
  useImperativeHandle(forwardedRef, () => ref.current);
4362
- const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, middleware = useMemo(() => {
4368
+ const portal = usePortal(), portalElement = typeof portalProp == "string" ? ((_c = portal.elements) == null ? void 0 : _c[portalProp]) || null : portal.element, mounted = useMounted(), tooltipWidth = useMemo(() => {
4369
+ const availableWidths = [
4370
+ ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4371
+ portalElement != null && portalElement.offsetWidth || mounted ? document.body.offsetWidth : (
4372
+ // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
4373
+ 800
4374
+ )
4375
+ ];
4376
+ return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
4377
+ }, [boundaryElement, mounted, portalElement]), middleware = useMemo(() => {
4363
4378
  const ret = [];
4364
4379
  return ret.push(
4365
- size$2({
4366
- apply({ elements }) {
4367
- const availableWidths = [
4368
- ...boundaryElement ? [boundaryElement.offsetWidth] : [],
4369
- (portalElement == null ? void 0 : portalElement.offsetWidth) || document.body.offsetWidth
4370
- ], tooltipWidth = Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2;
4371
- Object.assign(elements.floating.style, {
4372
- maxWidth: tooltipWidth > 0 ? `${tooltipWidth}px` : void 0
4373
- });
4374
- }
4375
- })
4376
- ), ret.push(
4377
4380
  flip({
4378
4381
  boundary: boundaryElement || void 0,
4379
4382
  fallbackPlacements,
@@ -4387,7 +4390,7 @@ const Root$a = styled(Layer)`
4387
4390
  padding: DEFAULT_TOOLTIP_PADDING
4388
4391
  })
4389
4392
  ), arrowProp && ret.push(arrow({ element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING })), animate && ret.push(origin), ret;
4390
- }, [animate, arrowProp, boundaryElement, fallbackPlacements, portalElement]), { floatingStyles, placement, middlewareData, refs, update } = useFloating({
4393
+ }, [animate, arrowProp, boundaryElement, fallbackPlacements]), { floatingStyles, placement, middlewareData, refs, update } = useFloating({
4391
4394
  middleware,
4392
4395
  placement: placementProp,
4393
4396
  whileElementsMounted: autoUpdate
@@ -4443,14 +4446,6 @@ const Root$a = styled(Layer)`
4443
4446
  [childProp == null ? void 0 : childProp.props, handleIsOpenChange]
4444
4447
  );
4445
4448
  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(() => {
4454
4449
  disabled && showTooltip && handleIsOpenChange(!1);
4455
4450
  }, [disabled, handleIsOpenChange, showTooltip]), useEffect(() => {
4456
4451
  !content && showTooltip && handleIsOpenChange(!1);
@@ -4462,7 +4457,7 @@ const Root$a = styled(Layer)`
4462
4457
  return window.addEventListener("keydown", handleWindowKeyDown), () => {
4463
4458
  window.removeEventListener("keydown", handleWindowKeyDown);
4464
4459
  };
4465
- }, [handleIsOpenChange, showTooltip]);
4460
+ }, [handleIsOpenChange, showTooltip]), useCloseOnMouseLeave({ handleIsOpenChange, referenceElement, showTooltip });
4466
4461
  const setArrow = useCallback(
4467
4462
  (arrowEl) => {
4468
4463
  arrowRef.current = arrowEl, update();
@@ -4505,6 +4500,7 @@ const Root$a = styled(Layer)`
4505
4500
  ref: setFloating,
4506
4501
  style: floatingStyles,
4507
4502
  zOffset,
4503
+ $maxWidth: tooltipWidth,
4508
4504
  children: /* @__PURE__ */ jsx(
4509
4505
  TooltipCard,
4510
4506
  {
@@ -4545,7 +4541,21 @@ const Root$a = styled(Layer)`
4545
4541
  ),
4546
4542
  child
4547
4543
  ] });
4548
- }), Root$9 = styled.div`
4544
+ });
4545
+ function useCloseOnMouseLeave({
4546
+ handleIsOpenChange,
4547
+ referenceElement,
4548
+ showTooltip
4549
+ }) {
4550
+ const handleWindowMouseMove = useEffectEvent((event) => {
4551
+ referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || handleIsOpenChange(!1));
4552
+ });
4553
+ useEffect(() => {
4554
+ if (showTooltip)
4555
+ return window.addEventListener("mousemove", handleWindowMouseMove), () => window.removeEventListener("mousemove", handleWindowMouseMove);
4556
+ }, [handleWindowMouseMove, showTooltip]);
4557
+ }
4558
+ const Root$9 = styled.div`
4549
4559
  line-height: 0;
4550
4560
  `, ListBox = styled(Box)`
4551
4561
  & > ul {
@@ -6154,7 +6164,7 @@ const CustomInline = styled(Inline)`
6154
6164
  }
6155
6165
  100% {
6156
6166
  width: 100%;
6157
- }
6167
+ }
6158
6168
  `, LOADING_BAR_HEIGHT = 2;
6159
6169
  function rootStyles(props) {
6160
6170
  const { color } = getTheme_v2$1(props.theme), loadingBarColor = color.button.default[props.tone].enabled.bg;
@@ -6240,15 +6250,7 @@ function Toast(props) {
6240
6250
  }
6241
6251
  );
6242
6252
  }
6243
- function useMounted() {
6244
- return useSyncExternalStore(
6245
- subscribe,
6246
- () => !0,
6247
- () => !1
6248
- );
6249
- }
6250
- const subscribe = () => () => {
6251
- }, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styled(Layer)`
6253
+ const key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styled(Layer)`
6252
6254
  position: fixed;
6253
6255
  top: 0;
6254
6256
  left: 0;