@tamagui/popper 1.68.6 → 1.69.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/cjs/Popper.js +88 -86
- package/dist/cjs/Popper.js.map +1 -1
- package/dist/cjs/Popper.native.js +88 -86
- package/dist/cjs/Popper.native.js.map +1 -1
- package/dist/esm/Popper.js +86 -85
- package/dist/esm/Popper.js.map +1 -1
- package/dist/jsx/Popper.js +77 -76
- package/dist/jsx/Popper.js.map +1 -1
- package/dist/jsx/Popper.native.js +78 -77
- package/dist/jsx/Popper.native.js.map +1 -1
- package/package.json +8 -8
- package/src/Popper.tsx +142 -134
- package/types/Popper.d.ts +15 -4
- package/types/Popper.d.ts.map +1 -1
|
@@ -20,7 +20,7 @@ import { getSpace } from "@tamagui/get-token";
|
|
|
20
20
|
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
21
21
|
import * as React from "react";
|
|
22
22
|
import { Keyboard, useWindowDimensions } from "react-native";
|
|
23
|
-
const PopperContext = createStyledContext({}), usePopperContext
|
|
23
|
+
const PopperContext = createStyledContext({}), { useStyledContext: usePopperContext, Provider: PopperProvider } = PopperContext;
|
|
24
24
|
function Popper(props) {
|
|
25
25
|
const {
|
|
26
26
|
children,
|
|
@@ -29,7 +29,8 @@ function Popper(props) {
|
|
|
29
29
|
placement = "bottom",
|
|
30
30
|
stayInFrame,
|
|
31
31
|
allowFlip,
|
|
32
|
-
offset
|
|
32
|
+
offset,
|
|
33
|
+
__scopePopper
|
|
33
34
|
} = props, [isMounted, setIsMounted] = React.useState(!1);
|
|
34
35
|
useIsomorphicLayoutEffect(() => {
|
|
35
36
|
setIsMounted(!0);
|
|
@@ -80,23 +81,26 @@ function Popper(props) {
|
|
|
80
81
|
arrowStyle: middlewareData.arrow,
|
|
81
82
|
onArrowSize: setArrowSize,
|
|
82
83
|
isMounted,
|
|
84
|
+
scope: __scopePopper,
|
|
83
85
|
...floating
|
|
84
86
|
};
|
|
85
|
-
return <
|
|
87
|
+
return <PopperProvider {...popperContext}>{children}</PopperProvider>;
|
|
86
88
|
}
|
|
87
89
|
const PopperAnchor = YStack.extractable(
|
|
88
|
-
React.forwardRef(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
React.forwardRef(
|
|
91
|
+
function(props, forwardedRef) {
|
|
92
|
+
const { virtualRef, __scopePopper, ...anchorProps } = props, { anchorRef, getReferenceProps } = usePopperContext(__scopePopper), ref = React.useRef(null), composedRefs = useComposedRefs(forwardedRef, ref, anchorRef);
|
|
93
|
+
if (virtualRef)
|
|
94
|
+
return null;
|
|
95
|
+
const stackProps = {
|
|
96
|
+
ref: composedRefs,
|
|
97
|
+
...anchorProps
|
|
98
|
+
};
|
|
99
|
+
return <TamaguiView
|
|
100
|
+
{...getReferenceProps ? getReferenceProps(stackProps) : stackProps}
|
|
101
|
+
/>;
|
|
102
|
+
}
|
|
103
|
+
)
|
|
100
104
|
), PopperContentFrame = styled(ThemeableStack, {
|
|
101
105
|
name: "PopperContent",
|
|
102
106
|
variants: {
|
|
@@ -118,29 +122,27 @@ const PopperAnchor = YStack.extractable(
|
|
|
118
122
|
defaultVariants: {
|
|
119
123
|
unstyled: !1
|
|
120
124
|
}
|
|
121
|
-
}), PopperContent = React.forwardRef(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
), PopperArrowFrame = styled(YStack, {
|
|
125
|
+
}), PopperContent = React.forwardRef(function(props, forwardedRef) {
|
|
126
|
+
const { __scopePopper, ...rest } = props, { strategy, placement, refs, x, y, getFloatingProps, size, isMounted, update } = usePopperContext(__scopePopper), contentRefs = useComposedRefs(refs.setFloating, forwardedRef), contents = React.useMemo(() => <PopperContentFrame
|
|
127
|
+
key="popper-content-frame"
|
|
128
|
+
data-placement={placement}
|
|
129
|
+
data-strategy={strategy}
|
|
130
|
+
contain="layout"
|
|
131
|
+
size={size}
|
|
132
|
+
{...rest}
|
|
133
|
+
/>, [placement, strategy, props]);
|
|
134
|
+
if (useIsomorphicLayoutEffect(() => {
|
|
135
|
+
isMounted && update();
|
|
136
|
+
}, [isMounted]), !isMounted)
|
|
137
|
+
return null;
|
|
138
|
+
const frameProps = {
|
|
139
|
+
ref: contentRefs,
|
|
140
|
+
x: x || 0,
|
|
141
|
+
y: y || 0,
|
|
142
|
+
position: strategy
|
|
143
|
+
};
|
|
144
|
+
return <YStack {...getFloatingProps ? getFloatingProps(frameProps) : frameProps}>{contents}</YStack>;
|
|
145
|
+
}), PopperArrowFrame = styled(YStack, {
|
|
144
146
|
name: "PopperArrow",
|
|
145
147
|
variants: {
|
|
146
148
|
unstyled: {
|
|
@@ -176,48 +178,46 @@ const PopperAnchor = YStack.extractable(
|
|
|
176
178
|
right: "left",
|
|
177
179
|
bottom: "top",
|
|
178
180
|
left: "right"
|
|
179
|
-
}, PopperArrow = PopperArrowFrame.styleable(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0);
|
|
192
|
-
}
|
|
193
|
-
return useIsomorphicLayoutEffect(() => {
|
|
181
|
+
}, PopperArrow = PopperArrowFrame.styleable(function(propsIn, forwardedRef) {
|
|
182
|
+
var _a, _b;
|
|
183
|
+
const { __scopePopper, ...rest } = propsIn, props = useProps(rest), { offset, size: sizeProp, borderWidth = 0, ...arrowProps } = props, context = usePopperContext(__scopePopper), sizeVal = sizeProp ?? context.size, size = +getVariableValue(
|
|
184
|
+
getSpace(sizeVal, {
|
|
185
|
+
shift: -2,
|
|
186
|
+
bounds: [2]
|
|
187
|
+
})
|
|
188
|
+
), { placement } = context, refs = useComposedRefs(context.arrowRef, forwardedRef), x = ((_a = context.arrowStyle) == null ? void 0 : _a.x) || 0, y = ((_b = context.arrowStyle) == null ? void 0 : _b.y) || 0, primaryPlacement = placement ? placement.split("-")[0] : "top", arrowStyle = { x, y, width: size, height: size }, innerArrowStyle = {}, isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
189
|
+
if (primaryPlacement) {
|
|
190
|
+
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
191
|
+
const oppSide = opposites[primaryPlacement];
|
|
192
|
+
oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0), useIsomorphicLayoutEffect(() => {
|
|
194
193
|
var _a2;
|
|
195
194
|
(_a2 = context.onArrowSize) == null || _a2.call(context, size);
|
|
196
|
-
}, [size, context.onArrowSize])
|
|
197
|
-
width={size}
|
|
198
|
-
height={size}
|
|
199
|
-
{...arrowProps}
|
|
200
|
-
{...innerArrowStyle}
|
|
201
|
-
rotate="45deg"
|
|
202
|
-
{...primaryPlacement === "bottom" && {
|
|
203
|
-
borderLeftWidth: borderWidth,
|
|
204
|
-
borderTopWidth: borderWidth
|
|
205
|
-
}}
|
|
206
|
-
{...primaryPlacement === "top" && {
|
|
207
|
-
borderBottomWidth: borderWidth,
|
|
208
|
-
borderRightWidth: borderWidth
|
|
209
|
-
}}
|
|
210
|
-
{...primaryPlacement === "right" && {
|
|
211
|
-
borderLeftWidth: borderWidth,
|
|
212
|
-
borderBottomWidth: borderWidth
|
|
213
|
-
}}
|
|
214
|
-
{...primaryPlacement === "left" && {
|
|
215
|
-
borderTopWidth: borderWidth,
|
|
216
|
-
borderRightWidth: borderWidth
|
|
217
|
-
}}
|
|
218
|
-
/></PopperArrowOuterFrame>;
|
|
195
|
+
}, [size, context.onArrowSize]);
|
|
219
196
|
}
|
|
220
|
-
|
|
197
|
+
return <PopperArrowOuterFrame ref={refs} {...arrowStyle}><PopperArrowFrame
|
|
198
|
+
width={size}
|
|
199
|
+
height={size}
|
|
200
|
+
{...arrowProps}
|
|
201
|
+
{...innerArrowStyle}
|
|
202
|
+
rotate="45deg"
|
|
203
|
+
{...primaryPlacement === "bottom" && {
|
|
204
|
+
borderLeftWidth: borderWidth,
|
|
205
|
+
borderTopWidth: borderWidth
|
|
206
|
+
}}
|
|
207
|
+
{...primaryPlacement === "top" && {
|
|
208
|
+
borderBottomWidth: borderWidth,
|
|
209
|
+
borderRightWidth: borderWidth
|
|
210
|
+
}}
|
|
211
|
+
{...primaryPlacement === "right" && {
|
|
212
|
+
borderLeftWidth: borderWidth,
|
|
213
|
+
borderBottomWidth: borderWidth
|
|
214
|
+
}}
|
|
215
|
+
{...primaryPlacement === "left" && {
|
|
216
|
+
borderTopWidth: borderWidth,
|
|
217
|
+
borderRightWidth: borderWidth
|
|
218
|
+
}}
|
|
219
|
+
/></PopperArrowOuterFrame>;
|
|
220
|
+
});
|
|
221
221
|
export {
|
|
222
222
|
Popper,
|
|
223
223
|
PopperAnchor,
|
|
@@ -225,6 +225,7 @@ export {
|
|
|
225
225
|
PopperContent,
|
|
226
226
|
PopperContentFrame,
|
|
227
227
|
PopperContext,
|
|
228
|
+
PopperProvider,
|
|
228
229
|
usePopperContext
|
|
229
230
|
};
|
|
230
231
|
//# sourceMappingURL=Popper.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3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,kBAAkB;AAAA,IACpB;AAAA,EACF,EACF,EAxBC;AA0BL,CAAC;",
|
|
5
5
|
"names": ["_a"]
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/popper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.1",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -31,19 +31,19 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/compose-refs": "1.
|
|
35
|
-
"@tamagui/core": "1.
|
|
36
|
-
"@tamagui/floating": "1.
|
|
37
|
-
"@tamagui/get-token": "1.
|
|
38
|
-
"@tamagui/stacks": "1.
|
|
39
|
-
"@tamagui/use-controllable-state": "1.
|
|
34
|
+
"@tamagui/compose-refs": "1.69.1",
|
|
35
|
+
"@tamagui/core": "1.69.1",
|
|
36
|
+
"@tamagui/floating": "1.69.1",
|
|
37
|
+
"@tamagui/get-token": "1.69.1",
|
|
38
|
+
"@tamagui/stacks": "1.69.1",
|
|
39
|
+
"@tamagui/use-controllable-state": "1.69.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "*",
|
|
43
43
|
"react-native": "*"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@tamagui/build": "1.
|
|
46
|
+
"@tamagui/build": "1.69.1",
|
|
47
47
|
"react": "^18.2.0",
|
|
48
48
|
"react-native": "^0.72.1"
|
|
49
49
|
},
|
package/src/Popper.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
useIsomorphicLayoutEffect,
|
|
13
13
|
useProps,
|
|
14
14
|
} from '@tamagui/core'
|
|
15
|
+
import type { ScopedProps } from '@tamagui/core'
|
|
15
16
|
import {
|
|
16
17
|
Coords,
|
|
17
18
|
OffsetOptions,
|
|
@@ -51,7 +52,8 @@ export type PopperContextValue = UseFloatingReturn & {
|
|
|
51
52
|
|
|
52
53
|
export const PopperContext = createStyledContext<PopperContextValue>({} as any)
|
|
53
54
|
|
|
54
|
-
export const usePopperContext
|
|
55
|
+
export const { useStyledContext: usePopperContext, Provider: PopperProvider } =
|
|
56
|
+
PopperContext
|
|
55
57
|
|
|
56
58
|
export type PopperProps = {
|
|
57
59
|
size?: SizeTokens
|
|
@@ -63,7 +65,9 @@ export type PopperProps = {
|
|
|
63
65
|
offset?: OffsetOptions
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
type ScopedPopperProps<P> = ScopedProps<P, 'Popper'>
|
|
69
|
+
|
|
70
|
+
export function Popper(props: ScopedPopperProps<PopperProps>) {
|
|
67
71
|
const {
|
|
68
72
|
children,
|
|
69
73
|
size,
|
|
@@ -72,6 +76,7 @@ export function Popper(props: PopperProps) {
|
|
|
72
76
|
stayInFrame,
|
|
73
77
|
allowFlip,
|
|
74
78
|
offset,
|
|
79
|
+
__scopePopper,
|
|
75
80
|
} = props
|
|
76
81
|
|
|
77
82
|
const [isMounted, setIsMounted] = React.useState(false)
|
|
@@ -152,10 +157,11 @@ export function Popper(props: PopperProps) {
|
|
|
152
157
|
arrowStyle: middlewareData.arrow,
|
|
153
158
|
onArrowSize: setArrowSize,
|
|
154
159
|
isMounted,
|
|
160
|
+
scope: __scopePopper,
|
|
155
161
|
...floating,
|
|
156
162
|
}
|
|
157
163
|
|
|
158
|
-
return <
|
|
164
|
+
return <PopperProvider {...popperContext}>{children}</PopperProvider>
|
|
159
165
|
}
|
|
160
166
|
|
|
161
167
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -169,27 +175,26 @@ export type PopperAnchorProps = YStackProps & {
|
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
export const PopperAnchor = YStack.extractable(
|
|
172
|
-
React.forwardRef<PopperAnchorRef, PopperAnchorProps
|
|
173
|
-
props: PopperAnchorProps
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
React.forwardRef<PopperAnchorRef, ScopedPopperProps<PopperAnchorProps>>(
|
|
179
|
+
function PopperAnchor(props: ScopedPopperProps<PopperAnchorProps>, forwardedRef) {
|
|
180
|
+
const { virtualRef, __scopePopper, ...anchorProps } = props
|
|
181
|
+
const { anchorRef, getReferenceProps } = usePopperContext(__scopePopper)
|
|
182
|
+
const ref = React.useRef<PopperAnchorRef>(null)
|
|
183
|
+
const composedRefs = useComposedRefs(forwardedRef, ref, anchorRef)
|
|
184
|
+
if (virtualRef) {
|
|
185
|
+
return null
|
|
186
|
+
}
|
|
187
|
+
const stackProps = {
|
|
188
|
+
ref: composedRefs,
|
|
189
|
+
...anchorProps,
|
|
190
|
+
}
|
|
191
|
+
return (
|
|
192
|
+
<TamaguiView
|
|
193
|
+
{...(getReferenceProps ? getReferenceProps(stackProps) : stackProps)}
|
|
194
|
+
/>
|
|
195
|
+
)
|
|
186
196
|
}
|
|
187
|
-
|
|
188
|
-
<TamaguiView
|
|
189
|
-
{...(getReferenceProps ? getReferenceProps(stackProps) : stackProps)}
|
|
190
|
-
/>
|
|
191
|
-
)
|
|
192
|
-
})
|
|
197
|
+
)
|
|
193
198
|
)
|
|
194
199
|
|
|
195
200
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -228,51 +233,53 @@ export const PopperContentFrame = styled(ThemeableStack, {
|
|
|
228
233
|
},
|
|
229
234
|
})
|
|
230
235
|
|
|
231
|
-
export const PopperContent = React.forwardRef<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
export const PopperContent = React.forwardRef<
|
|
237
|
+
PopperContentElement,
|
|
238
|
+
ScopedPopperProps<PopperContentProps>
|
|
239
|
+
>(function PopperContent(props: ScopedPopperProps<PopperContentProps>, forwardedRef) {
|
|
240
|
+
const { __scopePopper, ...rest } = props
|
|
241
|
+
const { strategy, placement, refs, x, y, getFloatingProps, size, isMounted, update } =
|
|
242
|
+
usePopperContext(__scopePopper)
|
|
243
|
+
const contentRefs = useComposedRefs<any>(refs.setFloating, forwardedRef)
|
|
236
244
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
useIsomorphicLayoutEffect(() => {
|
|
251
|
-
if (isMounted) {
|
|
252
|
-
update()
|
|
253
|
-
}
|
|
254
|
-
}, [isMounted])
|
|
245
|
+
const contents = React.useMemo(() => {
|
|
246
|
+
return (
|
|
247
|
+
<PopperContentFrame
|
|
248
|
+
key="popper-content-frame"
|
|
249
|
+
data-placement={placement}
|
|
250
|
+
data-strategy={strategy}
|
|
251
|
+
contain="layout"
|
|
252
|
+
size={size}
|
|
253
|
+
{...rest}
|
|
254
|
+
/>
|
|
255
|
+
)
|
|
256
|
+
}, [placement, strategy, props])
|
|
255
257
|
|
|
256
|
-
|
|
257
|
-
if (
|
|
258
|
-
|
|
258
|
+
useIsomorphicLayoutEffect(() => {
|
|
259
|
+
if (isMounted) {
|
|
260
|
+
update()
|
|
259
261
|
}
|
|
262
|
+
}, [isMounted])
|
|
260
263
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
position: strategy,
|
|
266
|
-
}
|
|
264
|
+
// all poppers hidden on ssr by default
|
|
265
|
+
if (!isMounted) {
|
|
266
|
+
return null
|
|
267
|
+
}
|
|
267
268
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
)
|
|
269
|
+
const frameProps = {
|
|
270
|
+
ref: contentRefs,
|
|
271
|
+
x: x || 0,
|
|
272
|
+
y: y || 0,
|
|
273
|
+
position: strategy,
|
|
274
274
|
}
|
|
275
|
-
|
|
275
|
+
|
|
276
|
+
// outer frame because we explicitly dont want animation to apply to this
|
|
277
|
+
return (
|
|
278
|
+
<YStack {...(getFloatingProps ? getFloatingProps(frameProps) : frameProps)}>
|
|
279
|
+
{contents}
|
|
280
|
+
</YStack>
|
|
281
|
+
)
|
|
282
|
+
})
|
|
276
283
|
|
|
277
284
|
/* -------------------------------------------------------------------------------------------------
|
|
278
285
|
* PopperArrow
|
|
@@ -331,84 +338,85 @@ const opposites = {
|
|
|
331
338
|
|
|
332
339
|
type Sides = keyof typeof opposites
|
|
333
340
|
|
|
334
|
-
export const PopperArrow = PopperArrowFrame.styleable<
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
341
|
+
export const PopperArrow = PopperArrowFrame.styleable<
|
|
342
|
+
ScopedPopperProps<PopperArrowProps>
|
|
343
|
+
>(function PopperArrow(propsIn: ScopedPopperProps<PopperArrowProps>, forwardedRef) {
|
|
344
|
+
const { __scopePopper, ...rest } = propsIn
|
|
345
|
+
const props = useProps(rest)
|
|
346
|
+
const { offset, size: sizeProp, borderWidth = 0, ...arrowProps } = props
|
|
347
|
+
|
|
348
|
+
const context = usePopperContext(__scopePopper)
|
|
349
|
+
const sizeVal = sizeProp ?? context.size
|
|
350
|
+
const sizeValResolved = getVariableValue(
|
|
351
|
+
getSpace(sizeVal, {
|
|
352
|
+
shift: -2,
|
|
353
|
+
bounds: [2],
|
|
354
|
+
})
|
|
355
|
+
)
|
|
356
|
+
const size = +sizeValResolved
|
|
357
|
+
const { placement } = context
|
|
358
|
+
const refs = useComposedRefs(context.arrowRef, forwardedRef)
|
|
359
|
+
|
|
360
|
+
// Sometimes floating-ui can return NaN during orientation or screen size changes on native
|
|
361
|
+
// so we explictly force the x,y position types as a number
|
|
362
|
+
const x = (context.arrowStyle?.x as number) || 0
|
|
363
|
+
const y = (context.arrowStyle?.y as number) || 0
|
|
364
|
+
|
|
365
|
+
const primaryPlacement = (placement ? placement.split('-')[0] : 'top') as Sides
|
|
366
|
+
|
|
367
|
+
const arrowStyle: StackProps = { x, y, width: size, height: size }
|
|
368
|
+
const innerArrowStyle: StackProps = {}
|
|
369
|
+
const isVertical = primaryPlacement === 'bottom' || primaryPlacement === 'top'
|
|
370
|
+
|
|
371
|
+
if (primaryPlacement) {
|
|
372
|
+
// allows for extra diagonal size
|
|
373
|
+
arrowStyle[isVertical ? 'width' : 'height'] = size * 2
|
|
374
|
+
const oppSide = opposites[primaryPlacement]
|
|
375
|
+
if (oppSide) {
|
|
376
|
+
arrowStyle[oppSide] = -size
|
|
377
|
+
innerArrowStyle[oppSide] = size / 2
|
|
378
|
+
}
|
|
379
|
+
if (oppSide === 'top' || oppSide === 'bottom') {
|
|
380
|
+
arrowStyle.left = 0
|
|
381
|
+
}
|
|
382
|
+
if (oppSide === 'left' || oppSide === 'right') {
|
|
383
|
+
arrowStyle.top = 0
|
|
376
384
|
}
|
|
377
385
|
|
|
378
386
|
// send the Arrow's offset up to Popper
|
|
379
387
|
useIsomorphicLayoutEffect(() => {
|
|
380
388
|
context.onArrowSize?.(size)
|
|
381
389
|
}, [size, context.onArrowSize])
|
|
382
|
-
|
|
383
|
-
// outer frame to cut off for ability to have nicer shadows/borders
|
|
384
|
-
return (
|
|
385
|
-
<PopperArrowOuterFrame ref={refs} {...arrowStyle}>
|
|
386
|
-
<PopperArrowFrame
|
|
387
|
-
width={size}
|
|
388
|
-
height={size}
|
|
389
|
-
{...arrowProps}
|
|
390
|
-
{...innerArrowStyle}
|
|
391
|
-
rotate="45deg"
|
|
392
|
-
{...(primaryPlacement === 'bottom' && {
|
|
393
|
-
borderLeftWidth: borderWidth,
|
|
394
|
-
borderTopWidth: borderWidth,
|
|
395
|
-
})}
|
|
396
|
-
{...(primaryPlacement === 'top' && {
|
|
397
|
-
borderBottomWidth: borderWidth,
|
|
398
|
-
borderRightWidth: borderWidth,
|
|
399
|
-
})}
|
|
400
|
-
{...(primaryPlacement === 'right' && {
|
|
401
|
-
borderLeftWidth: borderWidth,
|
|
402
|
-
borderBottomWidth: borderWidth,
|
|
403
|
-
})}
|
|
404
|
-
{...(primaryPlacement === 'left' && {
|
|
405
|
-
borderTopWidth: borderWidth,
|
|
406
|
-
borderRightWidth: borderWidth,
|
|
407
|
-
})}
|
|
408
|
-
/>
|
|
409
|
-
</PopperArrowOuterFrame>
|
|
410
|
-
)
|
|
411
390
|
}
|
|
412
|
-
|
|
391
|
+
|
|
392
|
+
// outer frame to cut off for ability to have nicer shadows/borders
|
|
393
|
+
return (
|
|
394
|
+
<PopperArrowOuterFrame ref={refs} {...arrowStyle}>
|
|
395
|
+
<PopperArrowFrame
|
|
396
|
+
width={size}
|
|
397
|
+
height={size}
|
|
398
|
+
{...arrowProps}
|
|
399
|
+
{...innerArrowStyle}
|
|
400
|
+
rotate="45deg"
|
|
401
|
+
{...(primaryPlacement === 'bottom' && {
|
|
402
|
+
borderLeftWidth: borderWidth,
|
|
403
|
+
borderTopWidth: borderWidth,
|
|
404
|
+
})}
|
|
405
|
+
{...(primaryPlacement === 'top' && {
|
|
406
|
+
borderBottomWidth: borderWidth,
|
|
407
|
+
borderRightWidth: borderWidth,
|
|
408
|
+
})}
|
|
409
|
+
{...(primaryPlacement === 'right' && {
|
|
410
|
+
borderLeftWidth: borderWidth,
|
|
411
|
+
borderBottomWidth: borderWidth,
|
|
412
|
+
})}
|
|
413
|
+
{...(primaryPlacement === 'left' && {
|
|
414
|
+
borderTopWidth: borderWidth,
|
|
415
|
+
borderRightWidth: borderWidth,
|
|
416
|
+
})}
|
|
417
|
+
/>
|
|
418
|
+
</PopperArrowOuterFrame>
|
|
419
|
+
)
|
|
420
|
+
})
|
|
413
421
|
|
|
414
422
|
/* -----------------------------------------------------------------------------------------------*/
|