@sanity/ui 2.8.13 → 2.9.0-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 (34) hide show
  1. package/dist/_chunks-cjs/getTheme_v2.js +84 -28
  2. package/dist/_chunks-cjs/getTheme_v2.js.map +1 -1
  3. package/dist/_chunks-es/getTheme_v2.mjs +84 -28
  4. package/dist/_chunks-es/getTheme_v2.mjs.map +1 -1
  5. package/dist/_legacy/getTheme_v2.esm.js +84 -28
  6. package/dist/_legacy/getTheme_v2.esm.js.map +1 -1
  7. package/dist/index.esm.js +3398 -3050
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/index.js +3399 -3052
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +3398 -3050
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/theme.esm.js +1197 -448
  14. package/dist/theme.esm.js.map +1 -1
  15. package/dist/theme.js +1197 -448
  16. package/dist/theme.js.map +1 -1
  17. package/dist/theme.mjs +1197 -448
  18. package/dist/theme.mjs.map +1 -1
  19. package/package.json +27 -34
  20. package/src/core/components/autocomplete/autocomplete.tsx +42 -31
  21. package/src/core/components/dialog/dialog.tsx +4 -2
  22. package/src/core/components/menu/menu.tsx +3 -1
  23. package/src/core/components/menu/menuGroup.tsx +2 -1
  24. package/src/core/components/menu/menuItem.tsx +4 -2
  25. package/src/core/components/menu/useMenuController.ts +18 -21
  26. package/src/core/components/tree/treeItem.tsx +13 -13
  27. package/src/core/hooks/useArrayProp.ts +14 -9
  28. package/src/core/hooks/useMatchMedia.ts +12 -22
  29. package/src/core/primitives/avatar/avatarStack.tsx +2 -5
  30. package/src/core/primitives/popover/popover.tsx +22 -26
  31. package/src/core/primitives/tooltip/tooltip.tsx +7 -4
  32. package/src/core/theme/themeProvider.tsx +4 -6
  33. package/src/core/utils/elementQuery/elementQuery.tsx +2 -1
  34. package/src/core/utils/portal/portalProvider.tsx +5 -5
@@ -21,8 +21,10 @@ import {
21
21
  useCallback,
22
22
  useEffect,
23
23
  useImperativeHandle,
24
+ useLayoutEffect,
24
25
  useMemo,
25
26
  useRef,
27
+ useState,
26
28
  } from 'react'
27
29
  import {useArrayProp, useElementSize, useMediaIndex, usePrefersReducedMotion} from '../../hooks'
28
30
  import {origin} from '../../middleware/origin'
@@ -126,15 +128,14 @@ export const Popover = memo(
126
128
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
127
129
  animate: _animate = false,
128
130
  arrow: arrowProp = false,
129
- boundaryElement = boundaryElementContext.element,
131
+ boundaryElement: _boundaryElement,
130
132
  children: childProp,
131
133
  constrainSize = false,
132
134
  content,
133
135
  disabled,
134
- fallbackPlacements = props.fallbackPlacements ??
135
- DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
136
+ fallbackPlacements: _fallbackPlacements,
136
137
  matchReferenceWidth,
137
- floatingBoundary = props.boundaryElement ?? boundaryElementContext.element,
138
+ floatingBoundary: _floatingBoundary,
138
139
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
140
  onActivate,
140
141
  open,
@@ -144,16 +145,23 @@ export const Popover = memo(
144
145
  portal,
145
146
  preventOverflow = true,
146
147
  radius: radiusProp = 3,
147
- referenceBoundary = props.boundaryElement ?? boundaryElementContext.element,
148
+ referenceBoundary: _referenceBoundary,
148
149
  referenceElement,
149
150
  scheme,
150
151
  shadow: shadowProp = 3,
151
152
  tone = 'inherit',
152
153
  width: widthProp = 'auto',
153
- zOffset: zOffsetProp = layer.popover.zOffset,
154
+ zOffset: _zOffsetProp,
154
155
  updateRef,
155
156
  ...restProps
156
157
  } = props
158
+ const boundaryElement = _boundaryElement ?? boundaryElementContext.element
159
+ const fallbackPlacements =
160
+ _fallbackPlacements ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom']
161
+ const floatingBoundary = _floatingBoundary ?? boundaryElement ?? boundaryElementContext.element
162
+ const referenceBoundary =
163
+ _referenceBoundary ?? boundaryElement ?? boundaryElementContext.element
164
+ const zOffsetProp = _zOffsetProp ?? layer.popover.zOffset
157
165
  const prefersReducedMotion = usePrefersReducedMotion()
158
166
  const animate = prefersReducedMotion ? false : _animate
159
167
  const boundarySize = useElementSize(boundaryElement)?.border
@@ -202,7 +210,7 @@ export const Popover = memo(
202
210
  const referenceWidthRef = useRef<number>()
203
211
 
204
212
  // Force apply width & max width to floating element
205
- useEffect(() => {
213
+ useLayoutEffect(() => {
206
214
  const floatingElement = ref.current
207
215
 
208
216
  if (!open || !floatingElement) return
@@ -210,7 +218,7 @@ export const Popover = memo(
210
218
  const referenceWidth = referenceWidthRef.current
211
219
 
212
220
  if (matchReferenceWidth) {
213
- if (referenceWidth !== undefined) {
221
+ if (referenceWidthRef.current !== undefined) {
214
222
  floatingElement.style.width = `${referenceWidth}px`
215
223
  }
216
224
  } else if (width !== undefined) {
@@ -350,36 +358,24 @@ export const Popover = memo(
350
358
  [refs],
351
359
  )
352
360
 
361
+ const [childElement, setChildElement] = useState<HTMLElement | null>(null)
353
362
  const setReference = useCallback(
354
363
  (node: HTMLElement | null) => {
355
364
  refs.setReference(node)
356
-
357
- const childRef = getElementRef(childProp as any)
358
-
359
- if (typeof childRef === 'function') {
360
- childRef(node)
361
- } else if (childRef) {
362
- childRef.current = node
363
- }
365
+ setChildElement(node)
364
366
  },
365
- [childProp, refs],
367
+ [refs],
366
368
  )
367
369
 
370
+ useImperativeHandle(getElementRef(childProp as any), () => childElement, [childElement])
371
+
368
372
  const child = useMemo(() => {
369
373
  if (!childProp || referenceElement) return null
370
374
 
371
375
  return cloneElement(childProp, {ref: setReference})
372
376
  }, [childProp, referenceElement, setReference])
373
377
 
374
- useEffect(() => {
375
- if (updateRef) {
376
- if (typeof updateRef === 'function') {
377
- updateRef(update)
378
- } else if (updateRef) {
379
- updateRef.current = update
380
- }
381
- }
382
- }, [update, updateRef])
378
+ useImperativeHandle(updateRef, () => update, [update])
383
379
 
384
380
  useEffect(() => {
385
381
  if (child) return
@@ -97,22 +97,25 @@ export const Tooltip = forwardRef(function Tooltip(
97
97
  const {
98
98
  animate: _animate = false,
99
99
  arrow: arrowProp = false,
100
- boundaryElement = boundaryElementContext?.element,
100
+ boundaryElement: _boundaryElement,
101
101
  children: childProp,
102
102
  content,
103
103
  disabled,
104
- fallbackPlacements: fallbackPlacementsProp = props.fallbackPlacements ??
105
- DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
104
+ fallbackPlacements: _fallbackPlacementsProp,
106
105
  padding = 2,
107
106
  placement: placementProp = 'bottom',
108
107
  portal: portalProp,
109
108
  radius = 2,
110
109
  scheme,
111
110
  shadow = 2,
112
- zOffset = layer.tooltip.zOffset,
111
+ zOffset: _zOffset,
113
112
  delay,
114
113
  ...restProps
115
114
  } = props
115
+ const boundaryElement = _boundaryElement ?? boundaryElementContext?.element
116
+ const fallbackPlacementsProp =
117
+ _fallbackPlacementsProp ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom']
118
+ const zOffset = _zOffset ?? layer.tooltip.zOffset
116
119
  const prefersReducedMotion = usePrefersReducedMotion()
117
120
  const animate = prefersReducedMotion ? false : _animate
118
121
  const fallbackPlacements = useArrayProp(fallbackPlacementsProp)
@@ -25,12 +25,10 @@ export interface ThemeProviderProps {
25
25
  */
26
26
  export function ThemeProvider(props: ThemeProviderProps): React.ReactElement {
27
27
  const parentTheme = useContext(ThemeContext)
28
- const {
29
- children,
30
- scheme = parentTheme?.scheme || 'light',
31
- theme: rootTheme = parentTheme?.theme || null,
32
- tone = parentTheme?.tone || 'default',
33
- } = props
28
+ const {children} = props
29
+ const scheme = props.scheme ?? (parentTheme?.scheme || 'light')
30
+ const rootTheme = props.theme ?? (parentTheme?.theme || null)
31
+ const tone = props.tone ?? (parentTheme?.tone || 'default')
34
32
 
35
33
  const themeContext: ThemeContextValue | null = useMemo(() => {
36
34
  if (!rootTheme) return null
@@ -21,7 +21,8 @@ export const ElementQuery = forwardRef(function ElementQuery(
21
21
  forwardedRef: React.ForwardedRef<HTMLDivElement>,
22
22
  ) {
23
23
  const theme = useTheme_v2()
24
- const {children, media = theme.media, ...restProps} = props
24
+ const {children, media: _media, ...restProps} = props
25
+ const media = _media ?? theme.media
25
26
 
26
27
  const ref = useRef<HTMLDivElement | null>(null)
27
28
  const [element, setElement] = useState<HTMLDivElement | null>(null)
@@ -1,4 +1,4 @@
1
- import {useMemo, useRef, useSyncExternalStore} from 'react'
1
+ import {useMemo, useState, useSyncExternalStore} from 'react'
2
2
  import {PortalContext} from './portalContext'
3
3
  import {PortalContextValue} from './types'
4
4
 
@@ -51,13 +51,13 @@ const emptySubscribe = () => () => {}
51
51
  * equality comparison (eg by identity), and only goes one level deep.
52
52
  */
53
53
  function useUnique<ValueType extends Comparable = Comparable>(value: ValueType): ValueType {
54
- const valueRef = useRef<ValueType>(value)
54
+ const [cachedValue, setCachedValue] = useState(value)
55
55
 
56
- if (!_isEqual(valueRef.current, value)) {
57
- valueRef.current = value
56
+ if (!_isEqual(cachedValue, value)) {
57
+ setCachedValue(value)
58
58
  }
59
59
 
60
- return valueRef.current
60
+ return cachedValue
61
61
  }
62
62
 
63
63
  function _isEqual(objA: Comparable, objB: Comparable): boolean {