@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.
- package/dist/_chunks-cjs/getTheme_v2.js +84 -28
- package/dist/_chunks-cjs/getTheme_v2.js.map +1 -1
- package/dist/_chunks-es/getTheme_v2.mjs +84 -28
- package/dist/_chunks-es/getTheme_v2.mjs.map +1 -1
- package/dist/_legacy/getTheme_v2.esm.js +84 -28
- package/dist/_legacy/getTheme_v2.esm.js.map +1 -1
- package/dist/index.esm.js +3398 -3050
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3399 -3052
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3398 -3050
- package/dist/index.mjs.map +1 -1
- package/dist/theme.esm.js +1197 -448
- package/dist/theme.esm.js.map +1 -1
- package/dist/theme.js +1197 -448
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +1197 -448
- package/dist/theme.mjs.map +1 -1
- package/package.json +27 -34
- package/src/core/components/autocomplete/autocomplete.tsx +42 -31
- package/src/core/components/dialog/dialog.tsx +4 -2
- package/src/core/components/menu/menu.tsx +3 -1
- package/src/core/components/menu/menuGroup.tsx +2 -1
- package/src/core/components/menu/menuItem.tsx +4 -2
- package/src/core/components/menu/useMenuController.ts +18 -21
- package/src/core/components/tree/treeItem.tsx +13 -13
- package/src/core/hooks/useArrayProp.ts +14 -9
- package/src/core/hooks/useMatchMedia.ts +12 -22
- package/src/core/primitives/avatar/avatarStack.tsx +2 -5
- package/src/core/primitives/popover/popover.tsx +22 -26
- package/src/core/primitives/tooltip/tooltip.tsx +7 -4
- package/src/core/theme/themeProvider.tsx +4 -6
- package/src/core/utils/elementQuery/elementQuery.tsx +2 -1
- 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
|
|
131
|
+
boundaryElement: _boundaryElement,
|
|
130
132
|
children: childProp,
|
|
131
133
|
constrainSize = false,
|
|
132
134
|
content,
|
|
133
135
|
disabled,
|
|
134
|
-
fallbackPlacements
|
|
135
|
-
DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
|
|
136
|
+
fallbackPlacements: _fallbackPlacements,
|
|
136
137
|
matchReferenceWidth,
|
|
137
|
-
floatingBoundary
|
|
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
|
|
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:
|
|
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
|
-
|
|
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 (
|
|
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
|
-
[
|
|
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
|
-
|
|
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
|
|
100
|
+
boundaryElement: _boundaryElement,
|
|
101
101
|
children: childProp,
|
|
102
102
|
content,
|
|
103
103
|
disabled,
|
|
104
|
-
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
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
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,
|
|
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
|
|
54
|
+
const [cachedValue, setCachedValue] = useState(value)
|
|
55
55
|
|
|
56
|
-
if (!_isEqual(
|
|
57
|
-
|
|
56
|
+
if (!_isEqual(cachedValue, value)) {
|
|
57
|
+
setCachedValue(value)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
return
|
|
60
|
+
return cachedValue
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function _isEqual(objA: Comparable, objB: Comparable): boolean {
|