@sanity/ui 2.0.13 → 2.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -106,8 +106,8 @@
106
106
  },
107
107
  "dependencies": {
108
108
  "@floating-ui/react-dom": "^2.0.8",
109
- "@sanity/color": "^3.0.2",
110
- "@sanity/icons": "^2.11.4",
109
+ "@sanity/color": "^3.0.4",
110
+ "@sanity/icons": "^2.11.6",
111
111
  "csstype": "^3.1.3",
112
112
  "framer-motion": "11.0.8",
113
113
  "react-refractor": "^2.1.7"
@@ -120,9 +120,9 @@
120
120
  "@commitlint/cli": "^19.2.1",
121
121
  "@commitlint/config-conventional": "^19.1.0",
122
122
  "@juggle/resize-observer": "^3.4.0",
123
- "@sanity/pkg-utils": "^5.1.6",
123
+ "@sanity/pkg-utils": "^5.1.8",
124
124
  "@sanity/semantic-release-preset": "^4.1.7",
125
- "@sanity/ui-workshop": "^2.0.7",
125
+ "@sanity/ui-workshop": "^2.0.10",
126
126
  "@storybook/addon-a11y": "^8.0.5",
127
127
  "@storybook/addon-docs": "^8.0.5",
128
128
  "@storybook/addon-essentials": "^8.0.5",
@@ -143,7 +143,7 @@
143
143
  "@types/jest": "^29.5.12",
144
144
  "@types/jest-axe": "^3.5.9",
145
145
  "@types/node": "^20.5.9",
146
- "@types/react": "^18.2.73",
146
+ "@types/react": "^18.2.74",
147
147
  "@types/react-dom": "^18.2.23",
148
148
  "@types/react-is": "^18.2.4",
149
149
  "@types/refractor": "^3.4.1",
@@ -151,7 +151,7 @@
151
151
  "@typescript-eslint/eslint-plugin": "^7.5.0",
152
152
  "@typescript-eslint/parser": "^7.5.0",
153
153
  "commitizen": "^4.3.0",
154
- "cypress": "^13.7.1",
154
+ "cypress": "^13.7.2",
155
155
  "cypress-real-events": "^1.12.0",
156
156
  "cz-conventional-changelog": "^3.3.0",
157
157
  "eslint": "^8.57.0",
@@ -6,10 +6,10 @@ import {
6
6
  offset,
7
7
  shift,
8
8
  useFloating,
9
- Middleware,
10
- RootBoundary,
9
+ type Middleware,
10
+ type RootBoundary,
11
11
  } from '@floating-ui/react-dom'
12
- import {ThemeColorSchemeKey} from '@sanity/ui/theme'
12
+ import type {ThemeColorSchemeKey} from '@sanity/ui/theme'
13
13
  import {AnimatePresence} from 'framer-motion'
14
14
  import {
15
15
  cloneElement,
@@ -19,24 +19,25 @@ import {
19
19
  useMemo,
20
20
  useRef,
21
21
  useState,
22
- ForwardedRef,
22
+ type ForwardedRef,
23
23
  useId,
24
+ useSyncExternalStore,
24
25
  } from 'react'
25
26
  import {styled} from 'styled-components'
26
27
  import {useArrayProp, useForwardedRef, usePrefersReducedMotion} from '../../hooks'
27
28
  import {useDelayedState} from '../../hooks/useDelayedState'
28
29
  import {origin} from '../../middleware/origin'
29
30
  import {useTheme_v2} from '../../theme'
30
- import {Placement} from '../../types'
31
+ import type {Placement} from '../../types'
31
32
  import {
32
33
  ConditionalWrapper,
33
34
  Layer,
34
- LayerProps,
35
+ type LayerProps,
35
36
  Portal,
36
37
  useBoundaryElement,
37
38
  usePortal,
38
39
  } from '../../utils'
39
- import {Delay} from '../types'
40
+ import type {Delay} from '../types'
40
41
  import {
41
42
  DEFAULT_FALLBACK_PLACEMENTS,
42
43
  DEFAULT_TOOLTIP_DISTANCE,
@@ -131,17 +132,23 @@ export const Tooltip = forwardRef(function Tooltip(
131
132
  const portalElement =
132
133
  typeof portalProp === 'string' ? portal.elements?.[portalProp] || null : portal.element
133
134
 
135
+ const documentBodyOffsetWidth = useSyncExternalStore(
136
+ emptySubscribe,
137
+ () => document.body.offsetWidth,
138
+ // We don't actually know what the width of the body is during SSR, so we'll just assume it's 800px or larger
139
+ () => 800,
140
+ )
134
141
  // Get the maximum tooltip width (sans tooltip padding)
135
142
  // Tooltip width should never exceed the width of either any supplied boundary or portal element.
136
143
  // If both portal and boundary elements are provided, use the smaller width of the two.
137
144
  const tooltipWidth = useMemo(() => {
138
145
  const availableWidths = [
139
146
  ...(boundaryElement ? [boundaryElement.offsetWidth] : []),
140
- portalElement?.offsetWidth || document.body.offsetWidth,
147
+ portalElement?.offsetWidth || documentBodyOffsetWidth,
141
148
  ]
142
149
 
143
150
  return Math.min(...availableWidths) - DEFAULT_TOOLTIP_PADDING * 2
144
- }, [boundaryElement, portalElement?.offsetWidth])
151
+ }, [boundaryElement, documentBodyOffsetWidth, portalElement?.offsetWidth])
145
152
 
146
153
  const middleware = useMemo(() => {
147
154
  const ret: Middleware[] = []
@@ -242,14 +249,14 @@ export const Tooltip = forwardRef(function Tooltip(
242
249
  )
243
250
  const handleClick = useCallback(
244
251
  (e: MouseEvent) => {
245
- handleIsOpenChange(false, true), [handleIsOpenChange]
252
+ handleIsOpenChange(false, true)
246
253
  childProp?.props.onClick?.(e)
247
254
  },
248
255
  [childProp?.props, handleIsOpenChange],
249
256
  )
250
257
  const handleContextMenu = useCallback(
251
258
  (e: MouseEvent) => {
252
- handleIsOpenChange(false, true), [handleIsOpenChange]
259
+ handleIsOpenChange(false, true)
253
260
  childProp?.props.onContextMenu?.(e)
254
261
  },
255
262
  [childProp?.props, handleIsOpenChange],
@@ -446,3 +453,5 @@ export const Tooltip = forwardRef(function Tooltip(
446
453
  </>
447
454
  )
448
455
  })
456
+
457
+ const emptySubscribe = () => () => {}