@sanity/ui 3.0.11 → 3.0.12-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/_visual-editing.js +1124 -628
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +1127 -631
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/_visual-editing.d.mts +3 -7
- package/dist/_visual-editing.d.ts +3 -7
- package/dist/index.d.mts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.js +252 -295
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -297
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -40
- package/src/core/components/autocomplete/autocomplete.tsx +2 -2
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +70 -40
- package/src/core/components/dialog/dialog.tsx +10 -14
- package/src/core/components/hotkeys/hotkeys.tsx +2 -2
- package/src/core/components/menu/menuGroup.tsx +2 -2
- package/src/core/components/menu/menuItem.tsx +4 -4
- package/src/core/components/skeleton/skeleton.tsx +2 -2
- package/src/core/components/skeleton/textSkeleton.tsx +5 -5
- package/src/core/components/tree/tree.tsx +176 -182
- package/src/core/components/tree/treeGroup.tsx +2 -4
- package/src/core/components/tree/treeItem.tsx +5 -5
- package/src/core/hooks/index.ts +1 -1
- package/src/core/hooks/useArrayProp.ts +5 -17
- package/src/core/primitives/avatar/avatar.tsx +14 -16
- package/src/core/primitives/avatar/avatarCounter.tsx +14 -16
- package/src/core/primitives/avatar/avatarStack.tsx +2 -2
- package/src/core/primitives/badge/badge.tsx +3 -3
- package/src/core/primitives/box/box.tsx +26 -26
- package/src/core/primitives/button/button.tsx +11 -11
- package/src/core/primitives/card/card.tsx +8 -8
- package/src/core/primitives/code/code.tsx +2 -2
- package/src/core/primitives/container/container.tsx +2 -2
- package/src/core/primitives/flex/flex.tsx +6 -6
- package/src/core/primitives/grid/grid.tsx +9 -9
- package/src/core/primitives/heading/heading.tsx +3 -3
- package/src/core/primitives/inline/inline.tsx +2 -2
- package/src/core/primitives/kbd/kbd.tsx +2 -2
- package/src/core/primitives/label/label.tsx +3 -3
- package/src/core/primitives/popover/floating-ui/size.ts +32 -16
- package/src/core/primitives/popover/popover.tsx +355 -328
- package/src/core/primitives/popover/popoverCard.tsx +123 -125
- package/src/core/primitives/select/select.tsx +6 -5
- package/src/core/primitives/stack/stack.tsx +2 -2
- package/src/core/primitives/text/text.tsx +3 -3
- package/src/core/primitives/textArea/textArea.tsx +6 -5
- package/src/core/primitives/textInput/textInput.tsx +6 -5
- package/src/core/primitives/tooltip/tooltip.tsx +73 -44
- package/src/core/primitives/tooltip/tooltipCard.tsx +83 -85
- package/src/core/utils/layer/layerProvider.tsx +3 -2
- package/src/core/utils/virtualList/virtualList.tsx +48 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Strategy} from '@floating-ui/react-dom'
|
|
2
2
|
import {ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
3
3
|
import {motion, type MotionProps} from 'framer-motion'
|
|
4
|
-
import React, {CSSProperties, forwardRef,
|
|
4
|
+
import React, {CSSProperties, forwardRef, useMemo} from 'react'
|
|
5
5
|
import {styled} from 'styled-components'
|
|
6
6
|
|
|
7
7
|
import {POPOVER_MOTION_PROPS} from '../../constants'
|
|
@@ -33,136 +33,134 @@ const MotionFlex = styled(motion.create(Flex))`
|
|
|
33
33
|
/**
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
36
|
-
export const PopoverCard =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} = props
|
|
36
|
+
export const PopoverCard = forwardRef(function PopoverCard(
|
|
37
|
+
props: {
|
|
38
|
+
/** @beta*/
|
|
39
|
+
__unstable_margins?: PopoverMargins
|
|
40
|
+
animate?: boolean
|
|
41
|
+
arrow: boolean
|
|
42
|
+
arrowRef: React.Ref<HTMLDivElement>
|
|
43
|
+
arrowX?: number
|
|
44
|
+
arrowY?: number
|
|
45
|
+
originX?: number
|
|
46
|
+
originY?: number
|
|
47
|
+
overflow?: BoxOverflow
|
|
48
|
+
padding?: number | number[]
|
|
49
|
+
placement: Placement
|
|
50
|
+
radius?: Radius | Radius[]
|
|
51
|
+
scheme?: ThemeColorSchemeKey
|
|
52
|
+
shadow?: number | number[]
|
|
53
|
+
strategy: Strategy
|
|
54
|
+
tone: CardTone
|
|
55
|
+
width: number | undefined
|
|
56
|
+
x: number | null
|
|
57
|
+
y: number | null
|
|
58
|
+
} & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'height' | 'width'>,
|
|
59
|
+
ref: React.ForwardedRef<HTMLDivElement>,
|
|
60
|
+
) {
|
|
61
|
+
const {
|
|
62
|
+
__unstable_margins: marginsProp,
|
|
63
|
+
animate,
|
|
64
|
+
arrow,
|
|
65
|
+
arrowRef,
|
|
66
|
+
arrowX,
|
|
67
|
+
arrowY,
|
|
68
|
+
children,
|
|
69
|
+
padding,
|
|
70
|
+
placement,
|
|
71
|
+
originX,
|
|
72
|
+
originY,
|
|
73
|
+
overflow,
|
|
74
|
+
radius,
|
|
75
|
+
scheme,
|
|
76
|
+
shadow,
|
|
77
|
+
strategy,
|
|
78
|
+
style,
|
|
79
|
+
tone,
|
|
80
|
+
width,
|
|
81
|
+
x: xProp,
|
|
82
|
+
y: yProp,
|
|
83
|
+
...restProps
|
|
84
|
+
} = props
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
const {zIndex} = useLayer()
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
// Get margins: [top, right, bottom, left]
|
|
89
|
+
const margins: PopoverMargins = useMemo(
|
|
90
|
+
() => marginsProp || DEFAULT_POPOVER_MARGINS,
|
|
91
|
+
[marginsProp],
|
|
92
|
+
)
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
// Translate according to margins
|
|
95
|
+
const x = (xProp ?? 0) + margins[3]
|
|
96
|
+
const y = (yProp ?? 0) + margins[0]
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
const rootStyle: CSSProperties = useMemo(
|
|
99
|
+
() => ({
|
|
100
|
+
left: x,
|
|
101
|
+
originX,
|
|
102
|
+
originY,
|
|
103
|
+
position: strategy,
|
|
104
|
+
top: y,
|
|
105
|
+
width,
|
|
106
|
+
zIndex,
|
|
107
|
+
willChange: animate ? 'transform' : undefined,
|
|
108
|
+
...style,
|
|
109
|
+
}),
|
|
110
|
+
[animate, originX, originY, strategy, style, width, x, y, zIndex],
|
|
111
|
+
)
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
const arrowStyle: CSSProperties = useMemo(
|
|
114
|
+
() => ({
|
|
115
|
+
left: arrowX !== null ? arrowX : undefined,
|
|
116
|
+
top: arrowY !== null ? arrowY : undefined,
|
|
117
|
+
right: undefined,
|
|
118
|
+
bottom: undefined,
|
|
119
|
+
}),
|
|
120
|
+
[arrowX, arrowY],
|
|
121
|
+
)
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
return (
|
|
124
|
+
<MotionCard
|
|
125
|
+
data-ui="Popover"
|
|
126
|
+
{...(restProps as CardProps & MotionProps)}
|
|
127
|
+
data-placement={placement}
|
|
128
|
+
radius={radius}
|
|
129
|
+
ref={ref}
|
|
130
|
+
scheme={scheme}
|
|
131
|
+
shadow={shadow}
|
|
132
|
+
sizing="border"
|
|
133
|
+
style={rootStyle}
|
|
134
|
+
tone={tone}
|
|
135
|
+
variants={POPOVER_MOTION_PROPS.card}
|
|
136
|
+
transition={POPOVER_MOTION_PROPS.transition}
|
|
137
|
+
initial={animate ? ['hidden', 'initial'] : undefined}
|
|
138
|
+
animate={animate ? ['visible', 'scaleIn'] : undefined}
|
|
139
|
+
exit={animate ? ['hidden', 'scaleOut'] : undefined}
|
|
140
|
+
>
|
|
141
|
+
<MotionFlex
|
|
142
|
+
data-ui="Popover__wrapper"
|
|
143
|
+
direction="column"
|
|
144
|
+
flex={1}
|
|
145
|
+
overflow={overflow}
|
|
146
|
+
variants={POPOVER_MOTION_PROPS.children}
|
|
137
147
|
transition={POPOVER_MOTION_PROPS.transition}
|
|
138
|
-
initial={animate ? ['hidden', 'initial'] : undefined}
|
|
139
|
-
animate={animate ? ['visible', 'scaleIn'] : undefined}
|
|
140
|
-
exit={animate ? ['hidden', 'scaleOut'] : undefined}
|
|
141
148
|
>
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
overflow={overflow}
|
|
147
|
-
variants={POPOVER_MOTION_PROPS.children}
|
|
148
|
-
transition={POPOVER_MOTION_PROPS.transition}
|
|
149
|
-
>
|
|
150
|
-
<Flex direction="column" flex={1} padding={padding}>
|
|
151
|
-
{children}
|
|
152
|
-
</Flex>
|
|
153
|
-
</MotionFlex>
|
|
149
|
+
<Flex direction="column" flex={1} padding={padding}>
|
|
150
|
+
{children}
|
|
151
|
+
</Flex>
|
|
152
|
+
</MotionFlex>
|
|
154
153
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
168
|
-
PopoverCard.displayName = 'Memo(ForwardRef(PopoverCard))'
|
|
154
|
+
{arrow && (
|
|
155
|
+
<Arrow
|
|
156
|
+
ref={arrowRef}
|
|
157
|
+
style={arrowStyle}
|
|
158
|
+
width={DEFAULT_POPOVER_ARROW_WIDTH}
|
|
159
|
+
height={DEFAULT_POPOVER_ARROW_HEIGHT}
|
|
160
|
+
radius={DEFAULT_POPOVER_ARROW_RADIUS}
|
|
161
|
+
/>
|
|
162
|
+
)}
|
|
163
|
+
</MotionCard>
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
PopoverCard.displayName = 'ForwardRef(PopoverCard)'
|
|
@@ -2,7 +2,8 @@ import {ChevronDownIcon} from '@sanity/icons'
|
|
|
2
2
|
import {forwardRef, useImperativeHandle, useRef} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {useCustomValidity} from '../../hooks'
|
|
6
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
6
7
|
import {Radius} from '../../types'
|
|
7
8
|
import {Box} from '../box'
|
|
8
9
|
import {Text} from '../text'
|
|
@@ -66,10 +67,10 @@ export const Select = forwardRef(function Select(
|
|
|
66
67
|
data-read-only={!disabled && readOnly ? '' : undefined}
|
|
67
68
|
data-ui="Select"
|
|
68
69
|
{...restProps}
|
|
69
|
-
$fontSize={
|
|
70
|
-
$padding={
|
|
71
|
-
$radius={
|
|
72
|
-
$space={
|
|
70
|
+
$fontSize={getArrayProp(fontSize)}
|
|
71
|
+
$padding={getArrayProp(padding)}
|
|
72
|
+
$radius={getArrayProp(radius)}
|
|
73
|
+
$space={getArrayProp(space)}
|
|
73
74
|
disabled={disabled || readOnly}
|
|
74
75
|
ref={ref}
|
|
75
76
|
>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {forwardRef} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
5
5
|
import {Box, BoxProps} from '../box'
|
|
6
6
|
import {responsiveStackSpaceStyle, ResponsiveStackSpaceStyleProps, stackBaseStyle} from './styles'
|
|
7
7
|
|
|
@@ -34,7 +34,7 @@ export const Stack = forwardRef(function Stack(
|
|
|
34
34
|
data-as={typeof as === 'string' ? as : undefined}
|
|
35
35
|
data-ui="Stack"
|
|
36
36
|
{...restProps}
|
|
37
|
-
$space={
|
|
37
|
+
$space={getArrayProp(space)}
|
|
38
38
|
forwardedAs={as}
|
|
39
39
|
ref={ref}
|
|
40
40
|
/>
|
|
@@ -2,7 +2,7 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
|
2
2
|
import {forwardRef} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
6
6
|
import {
|
|
7
7
|
ResponsiveFontStyleProps,
|
|
8
8
|
responsiveTextAlignStyle,
|
|
@@ -68,10 +68,10 @@ export const Text = forwardRef(function Text(
|
|
|
68
68
|
data-ui="Text"
|
|
69
69
|
{...restProps}
|
|
70
70
|
$accent={accent}
|
|
71
|
-
$align={
|
|
71
|
+
$align={getArrayProp(align)}
|
|
72
72
|
$muted={muted}
|
|
73
73
|
ref={ref}
|
|
74
|
-
$size={
|
|
74
|
+
$size={getArrayProp(size)}
|
|
75
75
|
$weight={weight}
|
|
76
76
|
>
|
|
77
77
|
<span>{children}</span>
|
|
@@ -2,7 +2,8 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
|
|
|
2
2
|
import {forwardRef, useImperativeHandle, useRef} from 'react'
|
|
3
3
|
import {styled} from 'styled-components'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {useCustomValidity} from '../../hooks'
|
|
6
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
6
7
|
import {
|
|
7
8
|
responsiveInputPaddingStyle,
|
|
8
9
|
responsiveRadiusStyle,
|
|
@@ -94,17 +95,17 @@ export const TextArea = forwardRef(function TextArea(
|
|
|
94
95
|
data-scheme={rootTheme.scheme}
|
|
95
96
|
data-tone={rootTheme.tone}
|
|
96
97
|
{...restProps}
|
|
97
|
-
$fontSize={
|
|
98
|
-
$padding={
|
|
98
|
+
$fontSize={getArrayProp(fontSize)}
|
|
99
|
+
$padding={getArrayProp(padding)}
|
|
99
100
|
$scheme={rootTheme.scheme}
|
|
100
|
-
$space={
|
|
101
|
+
$space={getArrayProp(0)}
|
|
101
102
|
$tone={rootTheme.tone}
|
|
102
103
|
$weight={weight}
|
|
103
104
|
disabled={disabled}
|
|
104
105
|
ref={ref}
|
|
105
106
|
/>
|
|
106
107
|
<Presentation
|
|
107
|
-
$radius={
|
|
108
|
+
$radius={getArrayProp(radius)}
|
|
108
109
|
$unstableDisableFocusRing={__unstable_disableFocusRing}
|
|
109
110
|
$scheme={rootTheme.scheme}
|
|
110
111
|
$tone={rootTheme.tone}
|
|
@@ -5,7 +5,8 @@ import {isValidElementType} from 'react-is'
|
|
|
5
5
|
import {styled} from 'styled-components'
|
|
6
6
|
|
|
7
7
|
import {EMPTY_RECORD} from '../../constants'
|
|
8
|
-
import {
|
|
8
|
+
import {useCustomValidity} from '../../hooks'
|
|
9
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
9
10
|
import {
|
|
10
11
|
responsiveInputPaddingStyle,
|
|
11
12
|
responsiveRadiusStyle,
|
|
@@ -179,10 +180,10 @@ export const TextInput = forwardRef(function TextInput(
|
|
|
179
180
|
|
|
180
181
|
const rootTheme = useRootTheme()
|
|
181
182
|
|
|
182
|
-
const fontSize =
|
|
183
|
-
const padding =
|
|
184
|
-
const radius =
|
|
185
|
-
const space =
|
|
183
|
+
const fontSize = getArrayProp(fontSizeProp)
|
|
184
|
+
const padding = getArrayProp(paddingProp)
|
|
185
|
+
const radius = getArrayProp(radiusProp)
|
|
186
|
+
const space = getArrayProp(spaceProp)
|
|
186
187
|
|
|
187
188
|
// Transient properties
|
|
188
189
|
const $hasClearButton = Boolean(clearButton)
|
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
import {styled} from 'styled-components'
|
|
26
26
|
import {useEffectEvent} from 'use-effect-event'
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import {usePrefersReducedMotion} from '../../hooks'
|
|
29
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
29
30
|
import {useDelayedState} from '../../hooks/useDelayedState'
|
|
30
31
|
import {origin} from '../../middleware/origin'
|
|
31
32
|
import {useTheme_v2} from '../../theme'
|
|
@@ -98,25 +99,28 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
98
99
|
const {
|
|
99
100
|
animate: _animate = false,
|
|
100
101
|
arrow: arrowProp = false,
|
|
101
|
-
boundaryElement
|
|
102
|
+
boundaryElement: _boundaryElement,
|
|
102
103
|
children: childProp,
|
|
103
104
|
content,
|
|
104
105
|
disabled,
|
|
105
|
-
fallbackPlacements:
|
|
106
|
-
DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom'],
|
|
106
|
+
fallbackPlacements: _fallbackPlacementsProp,
|
|
107
107
|
padding = 2,
|
|
108
108
|
placement: placementProp = 'bottom',
|
|
109
109
|
portal: portalProp,
|
|
110
110
|
radius = 2,
|
|
111
111
|
scheme,
|
|
112
112
|
shadow = 2,
|
|
113
|
-
zOffset
|
|
113
|
+
zOffset: _zOffset,
|
|
114
114
|
delay,
|
|
115
115
|
...restProps
|
|
116
116
|
} = props
|
|
117
|
+
const boundaryElement = _boundaryElement ?? boundaryElementContext?.element
|
|
118
|
+
const fallbackPlacementsProp =
|
|
119
|
+
_fallbackPlacementsProp ?? DEFAULT_FALLBACK_PLACEMENTS[props.placement ?? 'bottom']
|
|
120
|
+
const zOffset = _zOffset ?? layer.tooltip.zOffset
|
|
117
121
|
const prefersReducedMotion = usePrefersReducedMotion()
|
|
118
122
|
const animate = prefersReducedMotion ? false : _animate
|
|
119
|
-
const fallbackPlacements =
|
|
123
|
+
const fallbackPlacements = getArrayProp(fallbackPlacementsProp)
|
|
120
124
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
121
125
|
const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null)
|
|
122
126
|
const arrowRef = useRef<HTMLDivElement | null>(null)
|
|
@@ -129,44 +133,14 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
129
133
|
const portalElement =
|
|
130
134
|
typeof portalProp === 'string' ? portal.elements?.[portalProp] || null : portal.element
|
|
131
135
|
|
|
132
|
-
const middleware =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
padding: DEFAULT_TOOLTIP_PADDING,
|
|
141
|
-
rootBoundary,
|
|
142
|
-
}),
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
// Define distance between reference and floating element
|
|
146
|
-
ret.push(offset({mainAxis: DEFAULT_TOOLTIP_DISTANCE}))
|
|
147
|
-
|
|
148
|
-
// Shift the tooltip so its sits with the boundary element
|
|
149
|
-
ret.push(
|
|
150
|
-
shift({
|
|
151
|
-
boundary: boundaryElement || undefined,
|
|
152
|
-
rootBoundary,
|
|
153
|
-
padding: DEFAULT_TOOLTIP_PADDING,
|
|
154
|
-
}),
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
// Place arrow
|
|
158
|
-
if (arrowProp) {
|
|
159
|
-
ret.push(arrow({element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING}))
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Determine the origin to scale from.
|
|
163
|
-
// Must be placed after `@sanity/ui/size` and `shift` middleware.
|
|
164
|
-
if (animate) {
|
|
165
|
-
ret.push(origin)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return ret
|
|
169
|
-
}, [animate, arrowProp, boundaryElement, fallbackPlacements])
|
|
136
|
+
const middleware = useMiddleware({
|
|
137
|
+
animate,
|
|
138
|
+
arrowProp,
|
|
139
|
+
arrowRef,
|
|
140
|
+
boundaryElement,
|
|
141
|
+
fallbackPlacements,
|
|
142
|
+
rootBoundary,
|
|
143
|
+
})
|
|
170
144
|
|
|
171
145
|
const {floatingStyles, placement, middlewareData, refs, update} = useFloating({
|
|
172
146
|
middleware,
|
|
@@ -417,6 +391,61 @@ export const Tooltip = forwardRef(function Tooltip(
|
|
|
417
391
|
})
|
|
418
392
|
Tooltip.displayName = 'ForwardRef(Tooltip)'
|
|
419
393
|
|
|
394
|
+
function useMiddleware({
|
|
395
|
+
animate,
|
|
396
|
+
arrowProp,
|
|
397
|
+
arrowRef,
|
|
398
|
+
boundaryElement,
|
|
399
|
+
fallbackPlacements,
|
|
400
|
+
rootBoundary,
|
|
401
|
+
}: {
|
|
402
|
+
animate: boolean
|
|
403
|
+
arrowProp: boolean
|
|
404
|
+
arrowRef: React.RefObject<HTMLDivElement | null>
|
|
405
|
+
boundaryElement: HTMLElement | null
|
|
406
|
+
fallbackPlacements: Placement[]
|
|
407
|
+
rootBoundary: RootBoundary
|
|
408
|
+
}) {
|
|
409
|
+
return useMemo(() => {
|
|
410
|
+
const ret: Middleware[] = []
|
|
411
|
+
|
|
412
|
+
// Flip the floating element when leaving the boundary box
|
|
413
|
+
ret.push(
|
|
414
|
+
flip({
|
|
415
|
+
boundary: boundaryElement || undefined,
|
|
416
|
+
fallbackPlacements,
|
|
417
|
+
padding: DEFAULT_TOOLTIP_PADDING,
|
|
418
|
+
rootBoundary,
|
|
419
|
+
}),
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
// Define distance between reference and floating element
|
|
423
|
+
ret.push(offset({mainAxis: DEFAULT_TOOLTIP_DISTANCE}))
|
|
424
|
+
|
|
425
|
+
// Shift the tooltip so its sits with the boundary element
|
|
426
|
+
ret.push(
|
|
427
|
+
shift({
|
|
428
|
+
boundary: boundaryElement || undefined,
|
|
429
|
+
rootBoundary,
|
|
430
|
+
padding: DEFAULT_TOOLTIP_PADDING,
|
|
431
|
+
}),
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
// Place arrow
|
|
435
|
+
if (arrowProp) {
|
|
436
|
+
ret.push(arrow({element: arrowRef, padding: DEFAULT_TOOLTIP_PADDING}))
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Determine the origin to scale from.
|
|
440
|
+
// Must be placed after `@sanity/ui/size` and `shift` middleware.
|
|
441
|
+
if (animate) {
|
|
442
|
+
ret.push(origin)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return ret
|
|
446
|
+
}, [animate, arrowProp, arrowRef, boundaryElement, fallbackPlacements, rootBoundary])
|
|
447
|
+
}
|
|
448
|
+
|
|
420
449
|
/**
|
|
421
450
|
* As `useEffectEvent` should never be passed to other components or hooks, this custom hook groups together the `useEffectEvent` and the `useEffect` hook using it.
|
|
422
451
|
* @see https://19.react.dev/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events:~:text=Never%20pass%20them%20to%20other%20components%20or%20Hooks
|