@tamagui/popper 1.88.13 → 1.89.0-1706308641099
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 +21 -0
- package/dist/esm/Popper.mjs +284 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/jsx/Popper.mjs +284 -0
- package/dist/jsx/index.mjs +1 -0
- package/package.json +9 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
|
+
import { Stack, View as TamaguiView, createStyledContext, getVariableValue, styled, useDidFinishSSR, useProps } from "@tamagui/core";
|
|
4
|
+
import { arrow, autoUpdate, flip, offset as offsetFn, shift, useFloating } from "@tamagui/floating";
|
|
5
|
+
import { getSpace } from "@tamagui/get-token";
|
|
6
|
+
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { Keyboard, useWindowDimensions } from "react-native-web";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
const PopperContext = createStyledContext({}),
|
|
11
|
+
{
|
|
12
|
+
useStyledContext: usePopperContext,
|
|
13
|
+
Provider: PopperProvider
|
|
14
|
+
} = PopperContext;
|
|
15
|
+
function Popper(props) {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
size,
|
|
19
|
+
strategy = "absolute",
|
|
20
|
+
placement = "bottom",
|
|
21
|
+
stayInFrame,
|
|
22
|
+
allowFlip,
|
|
23
|
+
offset,
|
|
24
|
+
__scopePopper
|
|
25
|
+
} = props,
|
|
26
|
+
isMounted = useDidFinishSSR(),
|
|
27
|
+
[arrowEl, setArrow] = React.useState(null),
|
|
28
|
+
[arrowSize, setArrowSize] = React.useState(0),
|
|
29
|
+
offsetOptions = offset ?? arrowSize,
|
|
30
|
+
floating = useFloating({
|
|
31
|
+
strategy,
|
|
32
|
+
placement,
|
|
33
|
+
sameScrollView: !1,
|
|
34
|
+
// this only takes effect on native
|
|
35
|
+
middleware: [stayInFrame ? shift(typeof stayInFrame == "boolean" ? {} : stayInFrame) : null, allowFlip ? flip(typeof allowFlip == "boolean" ? {} : allowFlip) : null, arrowEl ? arrow({
|
|
36
|
+
element: arrowEl
|
|
37
|
+
}) : null, typeof offsetOptions < "u" ? offsetFn(offsetOptions) : null].filter(Boolean)
|
|
38
|
+
}),
|
|
39
|
+
{
|
|
40
|
+
refs,
|
|
41
|
+
middlewareData,
|
|
42
|
+
// @ts-expect-error this comes from Tooltip for example
|
|
43
|
+
open
|
|
44
|
+
} = floating;
|
|
45
|
+
if (isWeb) useIsomorphicLayoutEffect(() => {
|
|
46
|
+
if (open && refs.reference.current && refs.floating.current) return autoUpdate(refs.reference.current, refs.floating.current, floating.update);
|
|
47
|
+
}, [open, floating.update, refs.floating, refs.reference]);else {
|
|
48
|
+
const dimensions = useWindowDimensions(),
|
|
49
|
+
[keyboardOpen, setKeyboardOpen] = React.useState(!1);
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
|
|
52
|
+
setKeyboardOpen(!0);
|
|
53
|
+
}),
|
|
54
|
+
hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
|
|
55
|
+
setKeyboardOpen(!1);
|
|
56
|
+
});
|
|
57
|
+
return () => {
|
|
58
|
+
showSubscription.remove(), hideSubscription.remove();
|
|
59
|
+
};
|
|
60
|
+
}, []), useIsomorphicLayoutEffect(() => {
|
|
61
|
+
floating.update();
|
|
62
|
+
}, [dimensions, keyboardOpen]);
|
|
63
|
+
}
|
|
64
|
+
const popperContext = {
|
|
65
|
+
size,
|
|
66
|
+
arrowRef: setArrow,
|
|
67
|
+
arrowStyle: middlewareData.arrow,
|
|
68
|
+
onArrowSize: setArrowSize,
|
|
69
|
+
isMounted,
|
|
70
|
+
scope: __scopePopper,
|
|
71
|
+
...floating
|
|
72
|
+
};
|
|
73
|
+
return /* @__PURE__ */jsx(PopperProvider, {
|
|
74
|
+
...popperContext,
|
|
75
|
+
children
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const PopperAnchor = YStack.extractable(React.forwardRef(function (props, forwardedRef) {
|
|
79
|
+
const {
|
|
80
|
+
virtualRef,
|
|
81
|
+
__scopePopper,
|
|
82
|
+
...anchorProps
|
|
83
|
+
} = props,
|
|
84
|
+
{
|
|
85
|
+
getReferenceProps,
|
|
86
|
+
refs
|
|
87
|
+
} = usePopperContext(__scopePopper),
|
|
88
|
+
ref = React.useRef(null),
|
|
89
|
+
composedRefs = useComposedRefs(forwardedRef, ref, virtualRef ?? refs.setReference);
|
|
90
|
+
if (virtualRef) return null;
|
|
91
|
+
const stackProps = {
|
|
92
|
+
ref: composedRefs,
|
|
93
|
+
...anchorProps
|
|
94
|
+
};
|
|
95
|
+
return /* @__PURE__ */jsx(TamaguiView, {
|
|
96
|
+
...(getReferenceProps ? getReferenceProps(stackProps) : stackProps)
|
|
97
|
+
});
|
|
98
|
+
})),
|
|
99
|
+
PopperContentFrame = styled(ThemeableStack, {
|
|
100
|
+
name: "PopperContent",
|
|
101
|
+
variants: {
|
|
102
|
+
unstyled: {
|
|
103
|
+
false: {
|
|
104
|
+
size: "$true",
|
|
105
|
+
backgroundColor: "$background",
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
radiused: !0
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
size: {
|
|
111
|
+
"...size": (val, {
|
|
112
|
+
tokens
|
|
113
|
+
}) => ({
|
|
114
|
+
padding: tokens.space[val],
|
|
115
|
+
borderRadius: tokens.radius[val]
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
defaultVariants: {
|
|
120
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
PopperContent = React.forwardRef(function (props, forwardedRef) {
|
|
124
|
+
const {
|
|
125
|
+
__scopePopper,
|
|
126
|
+
enableAnimationForPositionChange,
|
|
127
|
+
...rest
|
|
128
|
+
} = props,
|
|
129
|
+
{
|
|
130
|
+
strategy,
|
|
131
|
+
placement,
|
|
132
|
+
refs,
|
|
133
|
+
x,
|
|
134
|
+
y,
|
|
135
|
+
getFloatingProps,
|
|
136
|
+
size,
|
|
137
|
+
isMounted,
|
|
138
|
+
update
|
|
139
|
+
} = usePopperContext(__scopePopper),
|
|
140
|
+
contentRefs = useComposedRefs(refs.setFloating, forwardedRef),
|
|
141
|
+
contents = React.useMemo(() => /* @__PURE__ */jsx(PopperContentFrame, {
|
|
142
|
+
"data-placement": placement,
|
|
143
|
+
"data-strategy": strategy,
|
|
144
|
+
contain: "layout",
|
|
145
|
+
size,
|
|
146
|
+
...rest
|
|
147
|
+
}, "popper-content-frame"), [placement, strategy, props]),
|
|
148
|
+
[hasInitialPosition, setHasInitialPosition] = React.useState(!0);
|
|
149
|
+
if (React.useEffect(() => {
|
|
150
|
+
(x || y) && setHasInitialPosition(!1);
|
|
151
|
+
}, [x, y]), useIsomorphicLayoutEffect(() => {
|
|
152
|
+
isMounted && update();
|
|
153
|
+
}, [isMounted]), !isMounted) return null;
|
|
154
|
+
const frameProps = {
|
|
155
|
+
ref: contentRefs,
|
|
156
|
+
x: x || 0,
|
|
157
|
+
y: y || 0,
|
|
158
|
+
top: 0,
|
|
159
|
+
left: 0,
|
|
160
|
+
position: strategy,
|
|
161
|
+
...(enableAnimationForPositionChange && {
|
|
162
|
+
// apply animation but disable it on initial render to avoid animating from 0 to the first position
|
|
163
|
+
animation: rest.animation,
|
|
164
|
+
animateOnly: ["none"]
|
|
165
|
+
}),
|
|
166
|
+
...(enableAnimationForPositionChange && !hasInitialPosition && {
|
|
167
|
+
animation: rest.animation,
|
|
168
|
+
animateOnly: rest.animateOnly
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
return /* @__PURE__ */jsx(Stack, {
|
|
172
|
+
...(getFloatingProps ? getFloatingProps(frameProps) : frameProps),
|
|
173
|
+
children: contents
|
|
174
|
+
});
|
|
175
|
+
}),
|
|
176
|
+
PopperArrowFrame = styled(YStack, {
|
|
177
|
+
name: "PopperArrow",
|
|
178
|
+
variants: {
|
|
179
|
+
unstyled: {
|
|
180
|
+
false: {
|
|
181
|
+
borderColor: "$borderColor",
|
|
182
|
+
backgroundColor: "$background",
|
|
183
|
+
position: "relative"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
defaultVariants: {
|
|
188
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
PopperArrowOuterFrame = styled(YStack, {
|
|
192
|
+
name: "PopperArrowOuter",
|
|
193
|
+
variants: {
|
|
194
|
+
unstyled: {
|
|
195
|
+
false: {
|
|
196
|
+
position: "absolute",
|
|
197
|
+
zIndex: 1e6,
|
|
198
|
+
pointerEvents: "none",
|
|
199
|
+
overflow: "hidden",
|
|
200
|
+
alignItems: "center",
|
|
201
|
+
justifyContent: "center"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
defaultVariants: {
|
|
206
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
209
|
+
opposites = {
|
|
210
|
+
top: "bottom",
|
|
211
|
+
right: "left",
|
|
212
|
+
bottom: "top",
|
|
213
|
+
left: "right"
|
|
214
|
+
},
|
|
215
|
+
PopperArrow = PopperArrowFrame.styleable(function (propsIn, forwardedRef) {
|
|
216
|
+
const {
|
|
217
|
+
__scopePopper,
|
|
218
|
+
...rest
|
|
219
|
+
} = propsIn,
|
|
220
|
+
props = useProps(rest),
|
|
221
|
+
{
|
|
222
|
+
offset,
|
|
223
|
+
size: sizeProp,
|
|
224
|
+
borderWidth = 0,
|
|
225
|
+
...arrowProps
|
|
226
|
+
} = props,
|
|
227
|
+
context = usePopperContext(__scopePopper),
|
|
228
|
+
sizeVal = sizeProp ?? context.size,
|
|
229
|
+
sizeValResolved = getVariableValue(getSpace(sizeVal, {
|
|
230
|
+
shift: -2,
|
|
231
|
+
bounds: [2]
|
|
232
|
+
})),
|
|
233
|
+
size = Math.max(0, +sizeValResolved),
|
|
234
|
+
{
|
|
235
|
+
placement
|
|
236
|
+
} = context,
|
|
237
|
+
refs = useComposedRefs(context.arrowRef, forwardedRef),
|
|
238
|
+
x = context.arrowStyle?.x || 0,
|
|
239
|
+
y = context.arrowStyle?.y || 0,
|
|
240
|
+
primaryPlacement = placement ? placement.split("-")[0] : "top",
|
|
241
|
+
arrowStyle = {
|
|
242
|
+
x,
|
|
243
|
+
y,
|
|
244
|
+
width: size,
|
|
245
|
+
height: size
|
|
246
|
+
},
|
|
247
|
+
innerArrowStyle = {},
|
|
248
|
+
isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
249
|
+
if (primaryPlacement) {
|
|
250
|
+
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
251
|
+
const oppSide = opposites[primaryPlacement];
|
|
252
|
+
oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), oppSide === "bottom" && (arrowStyle[oppSide] += 1), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0), useIsomorphicLayoutEffect(() => {
|
|
253
|
+
context.onArrowSize?.(size);
|
|
254
|
+
}, [size, context.onArrowSize]);
|
|
255
|
+
}
|
|
256
|
+
return /* @__PURE__ */jsx(PopperArrowOuterFrame, {
|
|
257
|
+
ref: refs,
|
|
258
|
+
...arrowStyle,
|
|
259
|
+
children: /* @__PURE__ */jsx(PopperArrowFrame, {
|
|
260
|
+
width: size,
|
|
261
|
+
height: size,
|
|
262
|
+
...arrowProps,
|
|
263
|
+
...innerArrowStyle,
|
|
264
|
+
rotate: "45deg",
|
|
265
|
+
...(primaryPlacement === "bottom" && {
|
|
266
|
+
borderLeftWidth: borderWidth,
|
|
267
|
+
borderTopWidth: borderWidth
|
|
268
|
+
}),
|
|
269
|
+
...(primaryPlacement === "top" && {
|
|
270
|
+
borderBottomWidth: borderWidth,
|
|
271
|
+
borderRightWidth: borderWidth
|
|
272
|
+
}),
|
|
273
|
+
...(primaryPlacement === "right" && {
|
|
274
|
+
borderLeftWidth: borderWidth,
|
|
275
|
+
borderBottomWidth: borderWidth
|
|
276
|
+
}),
|
|
277
|
+
...(primaryPlacement === "left" && {
|
|
278
|
+
borderTopWidth: borderWidth,
|
|
279
|
+
borderRightWidth: borderWidth
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
export { Popper, PopperAnchor, PopperArrow, PopperContent, PopperContentFrame, PopperContext, PopperProvider, usePopperContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Popper.mjs";
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
3
|
+
import { Stack, View as TamaguiView, createStyledContext, getVariableValue, styled, useDidFinishSSR, useProps } from "@tamagui/core";
|
|
4
|
+
import { arrow, autoUpdate, flip, offset as offsetFn, shift, useFloating } from "@tamagui/floating";
|
|
5
|
+
import { getSpace } from "@tamagui/get-token";
|
|
6
|
+
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { Keyboard, useWindowDimensions } from "react-native-web";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
const PopperContext = createStyledContext({}),
|
|
11
|
+
{
|
|
12
|
+
useStyledContext: usePopperContext,
|
|
13
|
+
Provider: PopperProvider
|
|
14
|
+
} = PopperContext;
|
|
15
|
+
function Popper(props) {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
size,
|
|
19
|
+
strategy = "absolute",
|
|
20
|
+
placement = "bottom",
|
|
21
|
+
stayInFrame,
|
|
22
|
+
allowFlip,
|
|
23
|
+
offset,
|
|
24
|
+
__scopePopper
|
|
25
|
+
} = props,
|
|
26
|
+
isMounted = useDidFinishSSR(),
|
|
27
|
+
[arrowEl, setArrow] = React.useState(null),
|
|
28
|
+
[arrowSize, setArrowSize] = React.useState(0),
|
|
29
|
+
offsetOptions = offset ?? arrowSize,
|
|
30
|
+
floating = useFloating({
|
|
31
|
+
strategy,
|
|
32
|
+
placement,
|
|
33
|
+
sameScrollView: !1,
|
|
34
|
+
// this only takes effect on native
|
|
35
|
+
middleware: [stayInFrame ? shift(typeof stayInFrame == "boolean" ? {} : stayInFrame) : null, allowFlip ? flip(typeof allowFlip == "boolean" ? {} : allowFlip) : null, arrowEl ? arrow({
|
|
36
|
+
element: arrowEl
|
|
37
|
+
}) : null, typeof offsetOptions < "u" ? offsetFn(offsetOptions) : null].filter(Boolean)
|
|
38
|
+
}),
|
|
39
|
+
{
|
|
40
|
+
refs,
|
|
41
|
+
middlewareData,
|
|
42
|
+
// @ts-expect-error this comes from Tooltip for example
|
|
43
|
+
open
|
|
44
|
+
} = floating;
|
|
45
|
+
if (isWeb) useIsomorphicLayoutEffect(() => {
|
|
46
|
+
if (open && refs.reference.current && refs.floating.current) return autoUpdate(refs.reference.current, refs.floating.current, floating.update);
|
|
47
|
+
}, [open, floating.update, refs.floating, refs.reference]);else {
|
|
48
|
+
const dimensions = useWindowDimensions(),
|
|
49
|
+
[keyboardOpen, setKeyboardOpen] = React.useState(!1);
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
|
|
52
|
+
setKeyboardOpen(!0);
|
|
53
|
+
}),
|
|
54
|
+
hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
|
|
55
|
+
setKeyboardOpen(!1);
|
|
56
|
+
});
|
|
57
|
+
return () => {
|
|
58
|
+
showSubscription.remove(), hideSubscription.remove();
|
|
59
|
+
};
|
|
60
|
+
}, []), useIsomorphicLayoutEffect(() => {
|
|
61
|
+
floating.update();
|
|
62
|
+
}, [dimensions, keyboardOpen]);
|
|
63
|
+
}
|
|
64
|
+
const popperContext = {
|
|
65
|
+
size,
|
|
66
|
+
arrowRef: setArrow,
|
|
67
|
+
arrowStyle: middlewareData.arrow,
|
|
68
|
+
onArrowSize: setArrowSize,
|
|
69
|
+
isMounted,
|
|
70
|
+
scope: __scopePopper,
|
|
71
|
+
...floating
|
|
72
|
+
};
|
|
73
|
+
return /* @__PURE__ */jsx(PopperProvider, {
|
|
74
|
+
...popperContext,
|
|
75
|
+
children
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const PopperAnchor = YStack.extractable(React.forwardRef(function (props, forwardedRef) {
|
|
79
|
+
const {
|
|
80
|
+
virtualRef,
|
|
81
|
+
__scopePopper,
|
|
82
|
+
...anchorProps
|
|
83
|
+
} = props,
|
|
84
|
+
{
|
|
85
|
+
getReferenceProps,
|
|
86
|
+
refs
|
|
87
|
+
} = usePopperContext(__scopePopper),
|
|
88
|
+
ref = React.useRef(null),
|
|
89
|
+
composedRefs = useComposedRefs(forwardedRef, ref, virtualRef ?? refs.setReference);
|
|
90
|
+
if (virtualRef) return null;
|
|
91
|
+
const stackProps = {
|
|
92
|
+
ref: composedRefs,
|
|
93
|
+
...anchorProps
|
|
94
|
+
};
|
|
95
|
+
return /* @__PURE__ */jsx(TamaguiView, {
|
|
96
|
+
...(getReferenceProps ? getReferenceProps(stackProps) : stackProps)
|
|
97
|
+
});
|
|
98
|
+
})),
|
|
99
|
+
PopperContentFrame = styled(ThemeableStack, {
|
|
100
|
+
name: "PopperContent",
|
|
101
|
+
variants: {
|
|
102
|
+
unstyled: {
|
|
103
|
+
false: {
|
|
104
|
+
size: "$true",
|
|
105
|
+
backgroundColor: "$background",
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
radiused: !0
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
size: {
|
|
111
|
+
"...size": (val, {
|
|
112
|
+
tokens
|
|
113
|
+
}) => ({
|
|
114
|
+
padding: tokens.space[val],
|
|
115
|
+
borderRadius: tokens.radius[val]
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
defaultVariants: {
|
|
120
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
PopperContent = React.forwardRef(function (props, forwardedRef) {
|
|
124
|
+
const {
|
|
125
|
+
__scopePopper,
|
|
126
|
+
enableAnimationForPositionChange,
|
|
127
|
+
...rest
|
|
128
|
+
} = props,
|
|
129
|
+
{
|
|
130
|
+
strategy,
|
|
131
|
+
placement,
|
|
132
|
+
refs,
|
|
133
|
+
x,
|
|
134
|
+
y,
|
|
135
|
+
getFloatingProps,
|
|
136
|
+
size,
|
|
137
|
+
isMounted,
|
|
138
|
+
update
|
|
139
|
+
} = usePopperContext(__scopePopper),
|
|
140
|
+
contentRefs = useComposedRefs(refs.setFloating, forwardedRef),
|
|
141
|
+
contents = React.useMemo(() => /* @__PURE__ */jsx(PopperContentFrame, {
|
|
142
|
+
"data-placement": placement,
|
|
143
|
+
"data-strategy": strategy,
|
|
144
|
+
contain: "layout",
|
|
145
|
+
size,
|
|
146
|
+
...rest
|
|
147
|
+
}, "popper-content-frame"), [placement, strategy, props]),
|
|
148
|
+
[hasInitialPosition, setHasInitialPosition] = React.useState(!0);
|
|
149
|
+
if (React.useEffect(() => {
|
|
150
|
+
(x || y) && setHasInitialPosition(!1);
|
|
151
|
+
}, [x, y]), useIsomorphicLayoutEffect(() => {
|
|
152
|
+
isMounted && update();
|
|
153
|
+
}, [isMounted]), !isMounted) return null;
|
|
154
|
+
const frameProps = {
|
|
155
|
+
ref: contentRefs,
|
|
156
|
+
x: x || 0,
|
|
157
|
+
y: y || 0,
|
|
158
|
+
top: 0,
|
|
159
|
+
left: 0,
|
|
160
|
+
position: strategy,
|
|
161
|
+
...(enableAnimationForPositionChange && {
|
|
162
|
+
// apply animation but disable it on initial render to avoid animating from 0 to the first position
|
|
163
|
+
animation: rest.animation,
|
|
164
|
+
animateOnly: ["none"]
|
|
165
|
+
}),
|
|
166
|
+
...(enableAnimationForPositionChange && !hasInitialPosition && {
|
|
167
|
+
animation: rest.animation,
|
|
168
|
+
animateOnly: rest.animateOnly
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
return /* @__PURE__ */jsx(Stack, {
|
|
172
|
+
...(getFloatingProps ? getFloatingProps(frameProps) : frameProps),
|
|
173
|
+
children: contents
|
|
174
|
+
});
|
|
175
|
+
}),
|
|
176
|
+
PopperArrowFrame = styled(YStack, {
|
|
177
|
+
name: "PopperArrow",
|
|
178
|
+
variants: {
|
|
179
|
+
unstyled: {
|
|
180
|
+
false: {
|
|
181
|
+
borderColor: "$borderColor",
|
|
182
|
+
backgroundColor: "$background",
|
|
183
|
+
position: "relative"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
defaultVariants: {
|
|
188
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
PopperArrowOuterFrame = styled(YStack, {
|
|
192
|
+
name: "PopperArrowOuter",
|
|
193
|
+
variants: {
|
|
194
|
+
unstyled: {
|
|
195
|
+
false: {
|
|
196
|
+
position: "absolute",
|
|
197
|
+
zIndex: 1e6,
|
|
198
|
+
pointerEvents: "none",
|
|
199
|
+
overflow: "hidden",
|
|
200
|
+
alignItems: "center",
|
|
201
|
+
justifyContent: "center"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
defaultVariants: {
|
|
206
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
209
|
+
opposites = {
|
|
210
|
+
top: "bottom",
|
|
211
|
+
right: "left",
|
|
212
|
+
bottom: "top",
|
|
213
|
+
left: "right"
|
|
214
|
+
},
|
|
215
|
+
PopperArrow = PopperArrowFrame.styleable(function (propsIn, forwardedRef) {
|
|
216
|
+
const {
|
|
217
|
+
__scopePopper,
|
|
218
|
+
...rest
|
|
219
|
+
} = propsIn,
|
|
220
|
+
props = useProps(rest),
|
|
221
|
+
{
|
|
222
|
+
offset,
|
|
223
|
+
size: sizeProp,
|
|
224
|
+
borderWidth = 0,
|
|
225
|
+
...arrowProps
|
|
226
|
+
} = props,
|
|
227
|
+
context = usePopperContext(__scopePopper),
|
|
228
|
+
sizeVal = sizeProp ?? context.size,
|
|
229
|
+
sizeValResolved = getVariableValue(getSpace(sizeVal, {
|
|
230
|
+
shift: -2,
|
|
231
|
+
bounds: [2]
|
|
232
|
+
})),
|
|
233
|
+
size = Math.max(0, +sizeValResolved),
|
|
234
|
+
{
|
|
235
|
+
placement
|
|
236
|
+
} = context,
|
|
237
|
+
refs = useComposedRefs(context.arrowRef, forwardedRef),
|
|
238
|
+
x = context.arrowStyle?.x || 0,
|
|
239
|
+
y = context.arrowStyle?.y || 0,
|
|
240
|
+
primaryPlacement = placement ? placement.split("-")[0] : "top",
|
|
241
|
+
arrowStyle = {
|
|
242
|
+
x,
|
|
243
|
+
y,
|
|
244
|
+
width: size,
|
|
245
|
+
height: size
|
|
246
|
+
},
|
|
247
|
+
innerArrowStyle = {},
|
|
248
|
+
isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
249
|
+
if (primaryPlacement) {
|
|
250
|
+
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
251
|
+
const oppSide = opposites[primaryPlacement];
|
|
252
|
+
oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), oppSide === "bottom" && (arrowStyle[oppSide] += 1), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0), useIsomorphicLayoutEffect(() => {
|
|
253
|
+
context.onArrowSize?.(size);
|
|
254
|
+
}, [size, context.onArrowSize]);
|
|
255
|
+
}
|
|
256
|
+
return /* @__PURE__ */jsx(PopperArrowOuterFrame, {
|
|
257
|
+
ref: refs,
|
|
258
|
+
...arrowStyle,
|
|
259
|
+
children: /* @__PURE__ */jsx(PopperArrowFrame, {
|
|
260
|
+
width: size,
|
|
261
|
+
height: size,
|
|
262
|
+
...arrowProps,
|
|
263
|
+
...innerArrowStyle,
|
|
264
|
+
rotate: "45deg",
|
|
265
|
+
...(primaryPlacement === "bottom" && {
|
|
266
|
+
borderLeftWidth: borderWidth,
|
|
267
|
+
borderTopWidth: borderWidth
|
|
268
|
+
}),
|
|
269
|
+
...(primaryPlacement === "top" && {
|
|
270
|
+
borderBottomWidth: borderWidth,
|
|
271
|
+
borderRightWidth: borderWidth
|
|
272
|
+
}),
|
|
273
|
+
...(primaryPlacement === "right" && {
|
|
274
|
+
borderLeftWidth: borderWidth,
|
|
275
|
+
borderBottomWidth: borderWidth
|
|
276
|
+
}),
|
|
277
|
+
...(primaryPlacement === "left" && {
|
|
278
|
+
borderTopWidth: borderWidth,
|
|
279
|
+
borderRightWidth: borderWidth
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
export { Popper, PopperAnchor, PopperArrow, PopperContent, PopperContentFrame, PopperContext, PopperProvider, usePopperContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Popper.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/popper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@tamagui/compose-refs": "1.
|
|
36
|
-
"@tamagui/constants": "1.
|
|
37
|
-
"@tamagui/core": "1.
|
|
38
|
-
"@tamagui/floating": "1.
|
|
39
|
-
"@tamagui/get-token": "1.
|
|
40
|
-
"@tamagui/stacks": "1.
|
|
41
|
-
"@tamagui/use-controllable-state": "1.
|
|
35
|
+
"@tamagui/compose-refs": "1.89.0-1706308641099",
|
|
36
|
+
"@tamagui/constants": "1.89.0-1706308641099",
|
|
37
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
38
|
+
"@tamagui/floating": "1.89.0-1706308641099",
|
|
39
|
+
"@tamagui/get-token": "1.89.0-1706308641099",
|
|
40
|
+
"@tamagui/stacks": "1.89.0-1706308641099",
|
|
41
|
+
"@tamagui/use-controllable-state": "1.89.0-1706308641099"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": "*",
|
|
45
45
|
"react-native": "*"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@tamagui/build": "1.
|
|
48
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
49
49
|
"react": "^18.2.0",
|
|
50
50
|
"react-native": "^0.72.6"
|
|
51
51
|
},
|