@sanity/ui 1.0.0-next.3 → 1.0.0
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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/{types/src/index.d.ts → index.d.ts} +4450 -4398
- package/dist/{sanity-ui.esm.js → index.esm.js} +888 -2678
- package/dist/index.esm.js.map +1 -0
- package/dist/{sanity-ui.js → index.js} +882 -2688
- package/dist/index.js.map +1 -0
- package/package.json +112 -23
- package/src/components/autocomplete/__workshop__/example.tsx +1 -1
- package/src/components/autocomplete/__workshop__/index.ts +36 -32
- package/src/components/autocomplete/autocomplete.styles.tsx +22 -28
- package/src/components/autocomplete/autocomplete.tsx +1 -2
- package/src/components/autocomplete/constants.ts +3 -8
- package/src/components/breadcrumbs/__workshop__/index.ts +11 -7
- package/src/components/breadcrumbs/breadcrumbs.styles.ts +13 -18
- package/src/components/dialog/__workshop__/index.ts +13 -9
- package/src/components/dialog/dialog.tsx +53 -67
- package/src/components/hotkeys/__workshop__/index.ts +11 -3
- package/src/components/hotkeys/hotkeys.tsx +12 -16
- package/src/components/menu/__workshop__/index.ts +71 -67
- package/src/components/menu/menu.tsx +5 -7
- package/src/components/menu/menuButton.tsx +16 -14
- package/src/components/menu/menuDivider.ts +8 -10
- package/src/components/skeleton/__workshop__/index.ts +8 -4
- package/src/components/skeleton/skeleton.tsx +4 -6
- package/src/components/skeleton/styles.ts +13 -9
- package/src/components/skeleton/textSkeleton.tsx +12 -14
- package/src/components/tab/__workshop__/index.ts +11 -3
- package/src/components/toast/__workshop__/index.ts +16 -4
- package/src/components/toast/toast.tsx +6 -11
- package/src/components/toast/toastProvider.tsx +18 -22
- package/src/components/tree/__workshop__/basic.perf.ts +1 -14
- package/src/components/tree/__workshop__/basic.tsx +1 -1
- package/src/components/tree/__workshop__/index.ts +12 -8
- package/src/components/tree/style.ts +78 -76
- package/src/components/tree/treeItem.tsx +7 -12
- package/src/hooks/useElementRect/__workshop__/index.ts +11 -3
- package/src/hooks/useMediaIndex/__workshop__/index.ts +11 -3
- package/src/primitives/_selectable/selectable.tsx +4 -7
- package/src/primitives/_selectable/style.ts +85 -82
- package/src/primitives/avatar/__workshop__/index.ts +16 -12
- package/src/primitives/avatar/avatar.tsx +9 -12
- package/src/primitives/avatar/avatarCounter.tsx +22 -24
- package/src/primitives/avatar/avatarStack.tsx +16 -14
- package/src/primitives/avatar/styles.ts +1 -1
- package/src/primitives/badge/__workshop__/index.ts +16 -12
- package/src/primitives/badge/__workshop__/tones.tsx +1 -1
- package/src/primitives/badge/badge.tsx +6 -5
- package/src/primitives/box/__workshop__/index.ts +16 -4
- package/src/primitives/box/box.tsx +21 -49
- package/src/primitives/button/__workshop__/index.ts +51 -47
- package/src/primitives/button/__workshop__/sanityUploadButton.tsx +19 -20
- package/src/primitives/button/__workshop__/styled1.tsx +6 -6
- package/src/primitives/button/button.tsx +20 -26
- package/src/primitives/button/styles.ts +30 -29
- package/src/primitives/card/__workshop__/index.ts +15 -11
- package/src/primitives/card/card.tsx +9 -25
- package/src/primitives/card/styles.ts +119 -114
- package/src/primitives/checkbox/__workshop__/index.ts +10 -6
- package/src/primitives/checkbox/checkbox.tsx +4 -4
- package/src/primitives/checkbox/styles.ts +71 -69
- package/src/primitives/code/__workshop__/index.ts +16 -12
- package/src/primitives/code/code.tsx +3 -5
- package/src/primitives/code/styles.ts +20 -18
- package/src/primitives/container/__workshop__/index.ts +5 -3
- package/src/primitives/container/container.tsx +5 -4
- package/src/primitives/flex/__workshop__/index.ts +8 -4
- package/src/primitives/flex/flex.tsx +7 -23
- package/src/primitives/grid/__workshop__/index.ts +7 -3
- package/src/primitives/grid/grid.tsx +4 -27
- package/src/primitives/heading/__workshop__/index.ts +16 -12
- package/src/primitives/heading/heading.tsx +10 -17
- package/src/primitives/heading/styles.ts +45 -36
- package/src/primitives/inline/__workshop__/index.ts +5 -3
- package/src/primitives/inline/inline.tsx +3 -5
- package/src/primitives/kbd/__workshop__/index.ts +5 -3
- package/src/primitives/kbd/kbd.tsx +12 -13
- package/src/primitives/label/__workshop__/index.ts +16 -12
- package/src/primitives/label/label.tsx +13 -18
- package/src/primitives/label/styles.ts +24 -18
- package/src/primitives/popover/__workshop__/PlainStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/TestStory.tsx +0 -1
- package/src/primitives/popover/__workshop__/index.ts +36 -32
- package/src/primitives/popover/constants.ts +0 -3
- package/src/primitives/popover/floating-ui/size.ts +40 -25
- package/src/primitives/popover/popover.tsx +220 -196
- package/src/primitives/popover/popoverArrow.tsx +42 -48
- package/src/primitives/popover/popoverCard.tsx +12 -22
- package/src/primitives/radio/__workshop__/index.ts +8 -4
- package/src/primitives/radio/radio.tsx +3 -3
- package/src/primitives/radio/styles.ts +73 -73
- package/src/primitives/select/__workshop__/index.ts +8 -4
- package/src/primitives/select/select.tsx +9 -11
- package/src/primitives/select/styles.ts +77 -77
- package/src/primitives/spinner/__workshop__/index.ts +11 -7
- package/src/primitives/spinner/spinner.tsx +2 -5
- package/src/primitives/stack/__workshop__/index.ts +11 -7
- package/src/primitives/stack/stack.tsx +3 -5
- package/src/primitives/switch/__workshop__/index.ts +8 -4
- package/src/primitives/switch/styles.ts +119 -112
- package/src/primitives/switch/switch.tsx +6 -6
- package/src/primitives/text/__workshop__/index.ts +21 -17
- package/src/primitives/text/styles.ts +51 -45
- package/src/primitives/text/text.tsx +11 -16
- package/src/primitives/textArea/__workshop__/index.ts +11 -7
- package/src/primitives/textArea/textArea.tsx +15 -22
- package/src/primitives/textInput/__workshop__/index.ts +46 -42
- package/src/primitives/textInput/__workshop__/plain.tsx +2 -1
- package/src/primitives/textInput/textInput.tsx +49 -69
- package/src/primitives/tooltip/__workshop__/index.ts +11 -7
- package/src/primitives/tooltip/tooltip.tsx +3 -6
- package/src/primitives/tooltip/tooltipArrow.tsx +69 -59
- package/src/styles/border/borderStyle.ts +10 -18
- package/src/styles/box/boxStyle.ts +14 -18
- package/src/styles/flex/flexItemStyle.ts +7 -1
- package/src/styles/flex/flexStyle.ts +14 -9
- package/src/styles/grid/gridItemStyle.ts +18 -30
- package/src/styles/grid/gridStyle.ts +25 -33
- package/src/styles/helpers.ts +2 -2
- package/src/styles/index.ts +0 -1
- package/src/styles/input/textInputStyle.ts +127 -123
- package/src/styles/margin/marginStyle.ts +11 -10
- package/src/styles/margin/marginsStyle.test.ts +12 -10
- package/src/styles/padding/paddingStyle.test.ts +12 -10
- package/src/styles/padding/paddingStyle.ts +9 -10
- package/src/theme/__workshop__/index.ts +26 -22
- package/src/theme/{ThemeContext.ts → themeContext.ts} +0 -0
- package/src/utils/boundaryElement/__workshop__/index.ts +11 -7
- package/src/utils/elementQuery/__workshop__/index.ts +11 -7
- package/src/utils/layer/__workshop__/index.ts +21 -17
- package/src/utils/layer/layer.tsx +4 -6
- package/src/utils/portal/__workshop__/index.ts +11 -7
- package/src/utils/srOnly/srOnly.tsx +8 -10
- package/src/utils/virtualList/__workshop__/index.ts +26 -22
- package/src/utils/virtualList/virtualList.tsx +10 -14
- package/dist/sanity-ui.esm.js.map +0 -1
- package/dist/sanity-ui.js.map +0 -1
- package/src/__workshop__/color/overview.tsx +0 -101
- package/src/__workshop__/index.ts +0 -10
- package/src/icons/__workshop__/.eslintrc +0 -5
- package/src/icons/__workshop__/index.tsx +0 -6
- package/src/icons/__workshop__/overview.tsx +0 -76
- package/src/styles/compose.ts +0 -35
- package/src/utils/srOnly/__workshop__/.eslintrc +0 -5
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import {Middleware, detectOverflow} from '@floating-ui/react-dom'
|
|
1
|
+
import {Elements, Middleware, detectOverflow} from '@floating-ui/react-dom'
|
|
2
|
+
import {PopoverMargins} from '../../../types'
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
|
|
4
|
+
export interface SizeMiddlewareApplyOptions {
|
|
5
|
+
availableWidth: number
|
|
6
|
+
availableHeight: number
|
|
7
|
+
elements: Elements
|
|
8
|
+
referenceWidth: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function size(options: {
|
|
12
|
+
apply: (args: SizeMiddlewareApplyOptions) => void
|
|
13
|
+
boundaryElement?: HTMLElement | null
|
|
5
14
|
constrainSize: boolean
|
|
15
|
+
margins: PopoverMargins
|
|
6
16
|
matchReferenceWidth?: boolean
|
|
7
17
|
padding?: number
|
|
8
|
-
setAvailableWidth: (v: number) => void
|
|
9
|
-
setAvailableHeight: (v: number) => void
|
|
10
|
-
setReferenceWidth: (v: number) => void
|
|
11
18
|
}): Middleware {
|
|
12
|
-
const {padding = 0} =
|
|
19
|
+
const {apply, margins, padding = 0} = options
|
|
13
20
|
|
|
14
21
|
return {
|
|
15
22
|
name: '@sanity/ui/size',
|
|
16
23
|
async fn(args) {
|
|
17
|
-
const {placement, rects} = args
|
|
24
|
+
const {elements, placement, platform, rects} = args
|
|
18
25
|
const {floating, reference} = rects
|
|
19
26
|
|
|
20
27
|
const overflow = await detectOverflow(args, {
|
|
21
28
|
altBoundary: true,
|
|
22
|
-
boundary:
|
|
29
|
+
boundary: options.boundaryElement || undefined,
|
|
23
30
|
elementContext: 'floating',
|
|
24
31
|
padding,
|
|
25
32
|
rootBoundary: 'viewport',
|
|
@@ -28,36 +35,44 @@ export function size(scope: {
|
|
|
28
35
|
let maxWidth = Infinity
|
|
29
36
|
let maxHeight = Infinity
|
|
30
37
|
|
|
38
|
+
const floatingW = floating.width
|
|
39
|
+
const floatingH = floating.height
|
|
40
|
+
|
|
31
41
|
if (placement.includes('top')) {
|
|
32
|
-
maxWidth =
|
|
33
|
-
maxHeight =
|
|
42
|
+
maxWidth = floatingW - (overflow.left + overflow.right)
|
|
43
|
+
maxHeight = floatingH - overflow.top
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
if (placement.includes('right')) {
|
|
37
|
-
maxWidth =
|
|
38
|
-
maxHeight =
|
|
47
|
+
maxWidth = floatingW - overflow.right
|
|
48
|
+
maxHeight = floatingH - (overflow.top + overflow.bottom)
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
if (placement.includes('bottom')) {
|
|
42
|
-
maxWidth =
|
|
43
|
-
maxHeight =
|
|
52
|
+
maxWidth = floatingW - (overflow.left + overflow.right)
|
|
53
|
+
maxHeight = floatingH - overflow.bottom
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
if (placement.includes('left')) {
|
|
47
|
-
maxWidth =
|
|
48
|
-
maxHeight =
|
|
57
|
+
maxWidth = floatingW - overflow.left
|
|
58
|
+
maxHeight = floatingH - (overflow.top + overflow.bottom)
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
// IMPORTANT – APPLY ELEMENT STYLES HERE
|
|
62
|
+
// Elements need to be resized BEFORE the `platform.getDimensions` call below
|
|
63
|
+
apply({
|
|
64
|
+
availableWidth: maxWidth - margins[1] - margins[3],
|
|
65
|
+
availableHeight: maxHeight - margins[0] - margins[2],
|
|
66
|
+
elements,
|
|
67
|
+
referenceWidth: reference.width - margins[1] - margins[3],
|
|
68
|
+
})
|
|
55
69
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
const nextDimensions = await platform.getDimensions(elements.floating)
|
|
71
|
+
|
|
72
|
+
const targetH = nextDimensions.height
|
|
73
|
+
const targetW = nextDimensions.width
|
|
59
74
|
|
|
60
|
-
if (
|
|
75
|
+
if (floatingW !== targetW || floatingH !== targetH) {
|
|
61
76
|
return {reset: {rects: true}}
|
|
62
77
|
}
|
|
63
78
|
|
|
@@ -8,14 +8,19 @@ import {
|
|
|
8
8
|
offset,
|
|
9
9
|
shift,
|
|
10
10
|
useFloating,
|
|
11
|
+
UseFloatingProps,
|
|
11
12
|
} from '@floating-ui/react-dom'
|
|
12
|
-
import {cloneElement, forwardRef, useCallback, useEffect, useMemo, useRef
|
|
13
|
+
import {cloneElement, forwardRef, memo, useCallback, useEffect, useMemo, useRef} from 'react'
|
|
13
14
|
import {useForwardedRef, useArrayProp, useElementSize} from '../../hooks'
|
|
14
15
|
import {ThemeColorSchemeKey, useTheme} from '../../theme'
|
|
15
16
|
import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
|
|
16
17
|
import {LayerProps, LayerProvider, Portal, useBoundaryElement} from '../../utils'
|
|
17
18
|
import {ResponsiveRadiusProps, ResponsiveShadowProps, ResponsiveWidthProps} from '../types'
|
|
18
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
DEFAULT_POPOVER_DISTANCE,
|
|
21
|
+
DEFAULT_POPOVER_MARGINS,
|
|
22
|
+
DEFAULT_POPOVER_PADDING,
|
|
23
|
+
} from './constants'
|
|
19
24
|
import {size} from './floating-ui/size'
|
|
20
25
|
import {PopoverCard} from './popoverCard'
|
|
21
26
|
|
|
@@ -51,231 +56,250 @@ export interface PopoverProps
|
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
/** @public */
|
|
54
|
-
export const Popover =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
export const Popover = memo(
|
|
60
|
+
forwardRef(function Popover(
|
|
61
|
+
props: PopoverProps &
|
|
62
|
+
Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'children' | 'content' | 'width'>,
|
|
63
|
+
ref: React.ForwardedRef<HTMLDivElement>
|
|
64
|
+
): React.ReactElement {
|
|
65
|
+
const theme = useTheme()
|
|
66
|
+
const boundaryElementContext = useBoundaryElement()
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const forwardedRef = useForwardedRef(ref)
|
|
97
|
-
const arrowRef = useRef<HTMLDivElement | null>(null)
|
|
98
|
-
const rootBoundary: RootBoundary = 'viewport'
|
|
68
|
+
const {
|
|
69
|
+
__unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
|
|
70
|
+
arrow: arrowProp = true,
|
|
71
|
+
boundaryElement = boundaryElementContext.element,
|
|
72
|
+
children: childProp,
|
|
73
|
+
constrainSize = false,
|
|
74
|
+
content,
|
|
75
|
+
disabled,
|
|
76
|
+
fallbackPlacements,
|
|
77
|
+
matchReferenceWidth: matchReferenceWidthProp,
|
|
78
|
+
open,
|
|
79
|
+
overflow = 'hidden',
|
|
80
|
+
padding: paddingProp,
|
|
81
|
+
placement: placementProp = 'bottom',
|
|
82
|
+
portal,
|
|
83
|
+
preventOverflow = true,
|
|
84
|
+
radius: radiusProp = 3,
|
|
85
|
+
referenceElement,
|
|
86
|
+
scheme,
|
|
87
|
+
shadow: shadowProp = 3,
|
|
88
|
+
tone = 'inherit',
|
|
89
|
+
width: widthProp = 'auto',
|
|
90
|
+
zOffset: zOffsetProp = theme.sanity.layer?.popover.zOffset,
|
|
91
|
+
...restProps
|
|
92
|
+
} = props
|
|
93
|
+
const boundarySize = useElementSize(boundaryElement)?.border
|
|
94
|
+
const padding = useArrayProp(paddingProp)
|
|
95
|
+
const radius = useArrayProp(radiusProp)
|
|
96
|
+
const shadow = useArrayProp(shadowProp)
|
|
97
|
+
const width = useArrayProp(widthProp)
|
|
98
|
+
const zOffset = useArrayProp(zOffsetProp)
|
|
99
|
+
const forwardedRef = useForwardedRef(ref)
|
|
100
|
+
const arrowRef = useRef<HTMLDivElement | null>(null)
|
|
101
|
+
const rootBoundary: RootBoundary = 'viewport'
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
const middleware = useMemo(() => {
|
|
104
|
+
const ret: Middleware[] = []
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
// Flip the floating element when leaving the boundary box
|
|
107
|
+
if (constrainSize || preventOverflow) {
|
|
108
|
+
ret.push(
|
|
109
|
+
flip({
|
|
110
|
+
boundary: boundaryElement || undefined,
|
|
111
|
+
fallbackPlacements,
|
|
112
|
+
padding: DEFAULT_POPOVER_PADDING,
|
|
113
|
+
rootBoundary,
|
|
114
|
+
})
|
|
115
|
+
)
|
|
116
|
+
}
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
if (constrainSize || matchReferenceWidthProp) {
|
|
118
|
+
// Define distance between reference and floating element
|
|
117
119
|
ret.push(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
constrainSize,
|
|
121
|
-
matchReferenceWidth: matchReferenceWidthProp,
|
|
122
|
-
padding: DEFAULT_POPOVER_PADDING,
|
|
123
|
-
setAvailableHeight,
|
|
124
|
-
setAvailableWidth,
|
|
125
|
-
setReferenceWidth,
|
|
120
|
+
offset({
|
|
121
|
+
mainAxis: arrowProp ? DEFAULT_POPOVER_DISTANCE : 0,
|
|
126
122
|
})
|
|
127
123
|
)
|
|
128
|
-
}
|
|
129
124
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
125
|
+
// Track sizes
|
|
126
|
+
if (constrainSize || matchReferenceWidthProp) {
|
|
127
|
+
ret.push(
|
|
128
|
+
size({
|
|
129
|
+
apply({availableWidth, availableHeight, elements, referenceWidth}) {
|
|
130
|
+
if (matchReferenceWidthProp) {
|
|
131
|
+
elements.floating.style.width = `${referenceWidth}px`
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (constrainSize) {
|
|
135
|
+
elements.floating.style.maxWidth = `${availableWidth}px`
|
|
136
|
+
elements.floating.style.maxHeight = `${availableHeight}px`
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
boundaryElement,
|
|
140
|
+
constrainSize,
|
|
141
|
+
margins,
|
|
142
|
+
matchReferenceWidth: matchReferenceWidthProp,
|
|
143
|
+
padding: DEFAULT_POPOVER_PADDING,
|
|
144
|
+
})
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Shift the popover so its sits within the boundary eleement
|
|
149
|
+
if (preventOverflow) {
|
|
150
|
+
ret.push(
|
|
151
|
+
shift({
|
|
152
|
+
boundary: boundaryElement || undefined,
|
|
153
|
+
rootBoundary,
|
|
154
|
+
padding: DEFAULT_POPOVER_PADDING,
|
|
155
|
+
})
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Place arrow
|
|
160
|
+
if (arrowProp) {
|
|
161
|
+
ret.push(
|
|
162
|
+
arrow({
|
|
163
|
+
element: arrowRef,
|
|
164
|
+
padding: DEFAULT_POPOVER_PADDING,
|
|
165
|
+
})
|
|
166
|
+
)
|
|
167
|
+
}
|
|
136
168
|
|
|
137
|
-
// Shift the popover so its sits with the boundary eleement
|
|
138
|
-
if (preventOverflow) {
|
|
139
169
|
ret.push(
|
|
140
|
-
|
|
170
|
+
hide({
|
|
141
171
|
boundary: boundaryElement || undefined,
|
|
142
|
-
rootBoundary,
|
|
143
172
|
padding: DEFAULT_POPOVER_PADDING,
|
|
173
|
+
strategy: 'referenceHidden',
|
|
144
174
|
})
|
|
145
175
|
)
|
|
146
|
-
}
|
|
147
176
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
177
|
+
return ret
|
|
178
|
+
}, [
|
|
179
|
+
arrowProp,
|
|
180
|
+
boundaryElement,
|
|
181
|
+
constrainSize,
|
|
182
|
+
fallbackPlacements,
|
|
183
|
+
margins,
|
|
184
|
+
matchReferenceWidthProp,
|
|
185
|
+
preventOverflow,
|
|
186
|
+
])
|
|
157
187
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
})
|
|
188
|
+
const floatingProps: UseFloatingProps = useMemo(
|
|
189
|
+
() => ({
|
|
190
|
+
middleware,
|
|
191
|
+
placement: placementProp,
|
|
192
|
+
whileElementsMounted: autoUpdate,
|
|
193
|
+
}),
|
|
194
|
+
[middleware, placementProp]
|
|
164
195
|
)
|
|
165
196
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const {x, y, placement, reference, floating, middlewareData, strategy} = useFloating({
|
|
177
|
-
middleware,
|
|
178
|
-
placement: placementProp,
|
|
179
|
-
whileElementsMounted: autoUpdate,
|
|
180
|
-
})
|
|
197
|
+
const {
|
|
198
|
+
x,
|
|
199
|
+
y,
|
|
200
|
+
placement,
|
|
201
|
+
reference: referenceRef,
|
|
202
|
+
floating: floatingRef,
|
|
203
|
+
middlewareData,
|
|
204
|
+
strategy,
|
|
205
|
+
} = useFloating(floatingProps)
|
|
181
206
|
|
|
182
|
-
|
|
207
|
+
const referenceHidden = middlewareData.hide?.referenceHidden
|
|
183
208
|
|
|
184
|
-
|
|
185
|
-
|
|
209
|
+
const arrowX = middlewareData.arrow?.x
|
|
210
|
+
const arrowY = middlewareData.arrow?.y
|
|
186
211
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
212
|
+
const setArrow = useCallback((arrowEl: HTMLDivElement | null) => {
|
|
213
|
+
arrowRef.current = arrowEl
|
|
214
|
+
}, [])
|
|
190
215
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
216
|
+
const setFloating = useCallback(
|
|
217
|
+
(node: HTMLDivElement | null) => {
|
|
218
|
+
forwardedRef.current = node
|
|
219
|
+
floatingRef(node)
|
|
220
|
+
},
|
|
221
|
+
[floatingRef, forwardedRef]
|
|
222
|
+
)
|
|
198
223
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
224
|
+
const setReference = useCallback(
|
|
225
|
+
(node: HTMLElement | null) => {
|
|
226
|
+
referenceRef(node)
|
|
202
227
|
|
|
203
|
-
|
|
228
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
|
+
const childRef = (childProp as any)?.ref
|
|
204
230
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
231
|
+
if (typeof childRef === 'function') {
|
|
232
|
+
childRef(node)
|
|
233
|
+
} else if (childRef) {
|
|
234
|
+
childRef.current = node
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
[childProp, referenceRef]
|
|
238
|
+
)
|
|
213
239
|
|
|
214
|
-
|
|
215
|
-
|
|
240
|
+
const child = useMemo(() => {
|
|
241
|
+
if (!childProp || referenceElement) return null
|
|
216
242
|
|
|
217
|
-
|
|
218
|
-
|
|
243
|
+
return cloneElement(childProp, {ref: setReference})
|
|
244
|
+
}, [childProp, referenceElement, setReference])
|
|
219
245
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
referenceRef(referenceElement || null)
|
|
248
|
+
}, [referenceRef, referenceElement])
|
|
223
249
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
250
|
+
if (disabled) {
|
|
251
|
+
return childProp || <></>
|
|
252
|
+
}
|
|
227
253
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
>
|
|
255
|
-
|
|
256
|
-
</PopoverCard>
|
|
257
|
-
</LayerProvider>
|
|
258
|
-
)
|
|
254
|
+
const popover = (
|
|
255
|
+
<LayerProvider zOffset={zOffset}>
|
|
256
|
+
<PopoverCard
|
|
257
|
+
{...restProps}
|
|
258
|
+
__unstable_margins={margins}
|
|
259
|
+
arrow={arrowProp}
|
|
260
|
+
arrowRef={setArrow}
|
|
261
|
+
arrowX={arrowX}
|
|
262
|
+
arrowY={arrowY}
|
|
263
|
+
boundaryWidth={preventOverflow ? boundarySize?.width : undefined}
|
|
264
|
+
hidden={referenceHidden}
|
|
265
|
+
overflow={overflow}
|
|
266
|
+
padding={padding}
|
|
267
|
+
placement={placement}
|
|
268
|
+
radius={radius}
|
|
269
|
+
ref={setFloating}
|
|
270
|
+
scheme={scheme}
|
|
271
|
+
shadow={shadow}
|
|
272
|
+
strategy={strategy}
|
|
273
|
+
tone={tone}
|
|
274
|
+
x={x}
|
|
275
|
+
y={y}
|
|
276
|
+
width={width}
|
|
277
|
+
>
|
|
278
|
+
{content}
|
|
279
|
+
</PopoverCard>
|
|
280
|
+
</LayerProvider>
|
|
281
|
+
)
|
|
259
282
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
283
|
+
return (
|
|
284
|
+
<>
|
|
285
|
+
{/* the popover */}
|
|
286
|
+
{open && (
|
|
287
|
+
<>
|
|
288
|
+
{portal ? (
|
|
289
|
+
<Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
|
|
290
|
+
{popover}
|
|
291
|
+
</Portal>
|
|
292
|
+
) : (
|
|
293
|
+
popover
|
|
294
|
+
)}
|
|
295
|
+
</>
|
|
296
|
+
)}
|
|
274
297
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
})
|
|
298
|
+
{/* the referred element */}
|
|
299
|
+
{child}
|
|
300
|
+
</>
|
|
301
|
+
)
|
|
302
|
+
})
|
|
303
|
+
)
|
|
280
304
|
|
|
281
305
|
Popover.displayName = 'Popover'
|