@tamagui/popper 1.13.3 → 1.13.4
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 +1 -326
- package/dist/cjs/Popper.js.map +2 -2
- package/dist/cjs/index.js +1 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Popper.js +1 -297
- package/dist/esm/Popper.js.map +2 -2
- package/dist/esm/Popper.mjs +1 -297
- package/dist/esm/Popper.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Popper.js +1 -280
- package/dist/jsx/Popper.js.map +2 -2
- package/dist/jsx/Popper.mjs +1 -280
- package/dist/jsx/Popper.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/jsx/Popper.js
CHANGED
|
@@ -1,281 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
getVariableValue,
|
|
4
|
-
isWeb,
|
|
5
|
-
styled,
|
|
6
|
-
useIsomorphicLayoutEffect
|
|
7
|
-
} from "@tamagui/core";
|
|
8
|
-
import { createContextScope } from "@tamagui/create-context";
|
|
9
|
-
import {
|
|
10
|
-
arrow,
|
|
11
|
-
autoUpdate,
|
|
12
|
-
flip,
|
|
13
|
-
offset,
|
|
14
|
-
shift,
|
|
15
|
-
useFloating
|
|
16
|
-
} from "@tamagui/floating";
|
|
17
|
-
import { stepTokenUpOrDown } from "@tamagui/get-size";
|
|
18
|
-
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
19
|
-
import * as React from "react";
|
|
20
|
-
import { Keyboard, useWindowDimensions } from "react-native";
|
|
21
|
-
const POPPER_NAME = "Popper";
|
|
22
|
-
const [createPopperContext, createScope] = createContextScope(POPPER_NAME);
|
|
23
|
-
const createPopperScope = createScope;
|
|
24
|
-
const [PopperProvider, usePopperContext] = createPopperContext(POPPER_NAME);
|
|
25
|
-
function Popper(props) {
|
|
26
|
-
const {
|
|
27
|
-
__scopePopper,
|
|
28
|
-
children,
|
|
29
|
-
size,
|
|
30
|
-
strategy = "absolute",
|
|
31
|
-
placement = "bottom",
|
|
32
|
-
stayInFrame,
|
|
33
|
-
allowFlip
|
|
34
|
-
} = props;
|
|
35
|
-
const [isMounted, setIsMounted] = React.useState(false);
|
|
36
|
-
useIsomorphicLayoutEffect(() => {
|
|
37
|
-
setIsMounted(true);
|
|
38
|
-
}, []);
|
|
39
|
-
const anchorRef = React.useRef();
|
|
40
|
-
const [arrowEl, setArrow] = React.useState(null);
|
|
41
|
-
const [arrowSize, setArrowSize] = React.useState(0);
|
|
42
|
-
const arrowRef = React.useRef();
|
|
43
|
-
const floating = useFloating({
|
|
44
|
-
strategy,
|
|
45
|
-
placement,
|
|
46
|
-
sameScrollView: false,
|
|
47
|
-
// this only takes effect on native
|
|
48
|
-
middleware: [
|
|
49
|
-
stayInFrame ? shift(typeof stayInFrame === "boolean" ? {} : stayInFrame) : null,
|
|
50
|
-
allowFlip ? flip(typeof allowFlip === "boolean" ? {} : allowFlip) : null,
|
|
51
|
-
arrowEl ? arrow({ element: arrowEl }) : null,
|
|
52
|
-
arrowSize ? offset(arrowSize) : null
|
|
53
|
-
].filter(Boolean)
|
|
54
|
-
});
|
|
55
|
-
const { refs, middlewareData } = floating;
|
|
56
|
-
const composedArrowRefs = useComposedRefs(arrowRef, setArrow);
|
|
57
|
-
useIsomorphicLayoutEffect(() => {
|
|
58
|
-
floating.reference(anchorRef.current);
|
|
59
|
-
}, [anchorRef]);
|
|
60
|
-
if (isWeb) {
|
|
61
|
-
React.useEffect(() => {
|
|
62
|
-
if (!(refs.reference.current && refs.floating.current)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
return autoUpdate(refs.reference.current, refs.floating.current, floating.update);
|
|
66
|
-
}, [floating.update, refs.floating, refs.reference]);
|
|
67
|
-
} else {
|
|
68
|
-
const dimensions = useWindowDimensions();
|
|
69
|
-
const [keyboardOpen, setKeyboardOpen] = React.useState(false);
|
|
70
|
-
React.useEffect(() => {
|
|
71
|
-
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
|
|
72
|
-
setKeyboardOpen(true);
|
|
73
|
-
});
|
|
74
|
-
const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
|
|
75
|
-
setKeyboardOpen(false);
|
|
76
|
-
});
|
|
77
|
-
return () => {
|
|
78
|
-
showSubscription.remove();
|
|
79
|
-
hideSubscription.remove();
|
|
80
|
-
};
|
|
81
|
-
}, []);
|
|
82
|
-
useIsomorphicLayoutEffect(() => {
|
|
83
|
-
floating.update();
|
|
84
|
-
}, [dimensions, keyboardOpen]);
|
|
85
|
-
}
|
|
86
|
-
return <PopperProvider
|
|
87
|
-
scope={__scopePopper}
|
|
88
|
-
anchorRef={anchorRef}
|
|
89
|
-
size={size}
|
|
90
|
-
arrowRef={composedArrowRefs}
|
|
91
|
-
arrowStyle={middlewareData.arrow}
|
|
92
|
-
onArrowSize={setArrowSize}
|
|
93
|
-
isMounted={isMounted}
|
|
94
|
-
{...floating}
|
|
95
|
-
>{children}</PopperProvider>;
|
|
96
|
-
}
|
|
97
|
-
const ANCHOR_NAME = "PopperAnchor";
|
|
98
|
-
const PopperAnchor = YStack.extractable(
|
|
99
|
-
React.forwardRef(function PopperAnchor2(props, forwardedRef) {
|
|
100
|
-
const { __scopePopper, virtualRef, ...anchorProps } = props;
|
|
101
|
-
const { anchorRef, getReferenceProps } = usePopperContext(ANCHOR_NAME, __scopePopper);
|
|
102
|
-
const ref = React.useRef(null);
|
|
103
|
-
const composedRefs = useComposedRefs(forwardedRef, ref, anchorRef);
|
|
104
|
-
if (virtualRef) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
const stackProps = {
|
|
108
|
-
ref: composedRefs,
|
|
109
|
-
...anchorProps
|
|
110
|
-
};
|
|
111
|
-
return <YStack {...getReferenceProps ? getReferenceProps(stackProps) : stackProps} />;
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
const CONTENT_NAME = "PopperContent";
|
|
115
|
-
const PopperContentFrame = styled(ThemeableStack, {
|
|
116
|
-
name: "PopperContent",
|
|
117
|
-
variants: {
|
|
118
|
-
unstyled: {
|
|
119
|
-
false: {
|
|
120
|
-
size: "$true",
|
|
121
|
-
backgroundColor: "$background",
|
|
122
|
-
alignItems: "center",
|
|
123
|
-
radiused: true
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
size: {
|
|
127
|
-
"...size": (val, { tokens }) => {
|
|
128
|
-
return {
|
|
129
|
-
padding: tokens.space[val],
|
|
130
|
-
borderRadius: tokens.radius[val]
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
defaultVariants: {
|
|
136
|
-
unstyled: false
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
const PopperContent = React.forwardRef(
|
|
140
|
-
function PopperContent2(props, forwardedRef) {
|
|
141
|
-
const { __scopePopper, ...contentProps } = props;
|
|
142
|
-
const { strategy, placement, floating, x, y, getFloatingProps, size, isMounted } = usePopperContext(CONTENT_NAME, __scopePopper);
|
|
143
|
-
const contentRefs = useComposedRefs(floating, forwardedRef);
|
|
144
|
-
const contents = React.useMemo(() => {
|
|
145
|
-
return <PopperContentFrame
|
|
146
|
-
key="popper-content-frame"
|
|
147
|
-
data-placement={placement}
|
|
148
|
-
data-strategy={strategy}
|
|
149
|
-
size={contentProps.size || size}
|
|
150
|
-
{...contentProps}
|
|
151
|
-
/>;
|
|
152
|
-
}, [placement, strategy, props]);
|
|
153
|
-
if (!isMounted) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
const frameProps = {
|
|
157
|
-
ref: contentRefs,
|
|
158
|
-
x: x || 0,
|
|
159
|
-
y: y || 0,
|
|
160
|
-
position: strategy
|
|
161
|
-
};
|
|
162
|
-
return <YStack
|
|
163
|
-
animateOnly={["transform"]}
|
|
164
|
-
{...getFloatingProps ? getFloatingProps(frameProps) : frameProps}
|
|
165
|
-
>{contents}</YStack>;
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
const ARROW_NAME = "PopperArrow";
|
|
169
|
-
const PopperArrowFrame = styled(YStack, {
|
|
170
|
-
name: "PopperArrow",
|
|
171
|
-
variants: {
|
|
172
|
-
unstyled: {
|
|
173
|
-
false: {
|
|
174
|
-
borderColor: "$borderColor",
|
|
175
|
-
backgroundColor: "$background",
|
|
176
|
-
position: "relative"
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
defaultVariants: {
|
|
181
|
-
unstyled: false
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
const PopperArrowOuterFrame = styled(YStack, {
|
|
185
|
-
name: "PopperArrowOuter",
|
|
186
|
-
variants: {
|
|
187
|
-
unstyled: {
|
|
188
|
-
false: {
|
|
189
|
-
position: "absolute",
|
|
190
|
-
zIndex: -1,
|
|
191
|
-
pointerEvents: "none",
|
|
192
|
-
overflow: "hidden",
|
|
193
|
-
alignItems: "center",
|
|
194
|
-
justifyContent: "center"
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
defaultVariants: {
|
|
199
|
-
unstyled: false
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
const opposites = {
|
|
203
|
-
top: "bottom",
|
|
204
|
-
right: "left",
|
|
205
|
-
bottom: "top",
|
|
206
|
-
left: "right"
|
|
207
|
-
};
|
|
208
|
-
const PopperArrow = PopperArrowFrame.extractable(
|
|
209
|
-
React.forwardRef(function PopperArrow2(props, forwardedRef) {
|
|
210
|
-
const {
|
|
211
|
-
__scopePopper,
|
|
212
|
-
offset: offset2,
|
|
213
|
-
size: sizeProp,
|
|
214
|
-
borderWidth = 0,
|
|
215
|
-
...arrowProps
|
|
216
|
-
} = props;
|
|
217
|
-
const context = usePopperContext(ARROW_NAME, __scopePopper);
|
|
218
|
-
const sizeVal = sizeProp ?? context.size;
|
|
219
|
-
const sizeValResolved = getVariableValue(stepTokenUpOrDown("space", sizeVal, -2, [2]));
|
|
220
|
-
const size = +sizeValResolved;
|
|
221
|
-
const { placement } = context;
|
|
222
|
-
const refs = useComposedRefs(context.arrowRef, forwardedRef);
|
|
223
|
-
const x = context.arrowStyle?.x || 0;
|
|
224
|
-
const y = context.arrowStyle?.y || 0;
|
|
225
|
-
const primaryPlacement = placement ? placement.split("-")[0] : "top";
|
|
226
|
-
const arrowStyle = { x, y, width: size, height: size };
|
|
227
|
-
const innerArrowStyle = {};
|
|
228
|
-
const isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
229
|
-
if (primaryPlacement) {
|
|
230
|
-
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
231
|
-
const oppSide = opposites[primaryPlacement];
|
|
232
|
-
if (oppSide) {
|
|
233
|
-
arrowStyle[oppSide] = -size;
|
|
234
|
-
innerArrowStyle[oppSide] = size / 2;
|
|
235
|
-
}
|
|
236
|
-
if (oppSide === "top" || oppSide === "bottom") {
|
|
237
|
-
arrowStyle.left = 0;
|
|
238
|
-
}
|
|
239
|
-
if (oppSide === "left" || oppSide === "right") {
|
|
240
|
-
arrowStyle.top = 0;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
useIsomorphicLayoutEffect(() => {
|
|
244
|
-
context.onArrowSize?.(size);
|
|
245
|
-
}, [size, context.onArrowSize]);
|
|
246
|
-
return <PopperArrowOuterFrame ref={refs} {...arrowStyle}><PopperArrowFrame
|
|
247
|
-
width={size}
|
|
248
|
-
height={size}
|
|
249
|
-
{...arrowProps}
|
|
250
|
-
{...innerArrowStyle}
|
|
251
|
-
rotate="45deg"
|
|
252
|
-
{...primaryPlacement === "bottom" && {
|
|
253
|
-
borderBottomWidth: borderWidth,
|
|
254
|
-
borderRightWidth: borderWidth
|
|
255
|
-
}}
|
|
256
|
-
{...primaryPlacement === "top" && {
|
|
257
|
-
borderTopWidth: borderWidth,
|
|
258
|
-
borderLeftWidth: borderWidth
|
|
259
|
-
}}
|
|
260
|
-
{...primaryPlacement === "right" && {
|
|
261
|
-
borderTopWidth: borderWidth,
|
|
262
|
-
borderRightWidth: borderWidth
|
|
263
|
-
}}
|
|
264
|
-
{...primaryPlacement === "left" && {
|
|
265
|
-
borderBottomWidth: borderWidth,
|
|
266
|
-
borderLeftWidth: borderWidth
|
|
267
|
-
}}
|
|
268
|
-
/></PopperArrowOuterFrame>;
|
|
269
|
-
})
|
|
270
|
-
);
|
|
271
|
-
export {
|
|
272
|
-
Popper,
|
|
273
|
-
PopperAnchor,
|
|
274
|
-
PopperArrow,
|
|
275
|
-
PopperContent,
|
|
276
|
-
PopperContentFrame,
|
|
277
|
-
PopperProvider,
|
|
278
|
-
createPopperScope,
|
|
279
|
-
usePopperContext
|
|
280
|
-
};
|
|
1
|
+
import{useComposedRefs as g}from"@tamagui/compose-refs";import{getVariableValue as T,isWeb as W,styled as k,useIsomorphicLayoutEffect as z}from"@tamagui/core";import{createContextScope as L}from"@tamagui/create-context";import{arrow as N,autoUpdate as I,flip as D,offset as H,shift as Y,useFloating as U}from"@tamagui/floating";import{stepTokenUpOrDown as $}from"@tamagui/get-size";import{ThemeableStack as B,YStack as R}from"@tamagui/stacks";import*as n from"react";import{Keyboard as E,useWindowDimensions as j}from"react-native";const O="Popper",[K,q]=L(O),Fe=q,[G,C]=K(O);function _e(f){const{__scopePopper:p,children:d,size:P,strategy:u="absolute",placement:c="bottom",stayInFrame:e,allowFlip:a}=f,[r,m]=n.useState(!1);z(()=>{m(!0)},[]);const i=n.useRef(),[t,y]=n.useState(null),[w,h]=n.useState(0),S=n.useRef(),o=U({strategy:u,placement:c,sameScrollView:!1,middleware:[e?Y(typeof e=="boolean"?{}:e):null,a?D(typeof a=="boolean"?{}:a):null,t?N({element:t}):null,w?H(w):null].filter(Boolean)}),{refs:s,middlewareData:A}=o,x=g(S,y);if(z(()=>{o.reference(i.current)},[i]),W)n.useEffect(()=>{if(s.reference.current&&s.floating.current)return I(s.reference.current,s.floating.current,o.update)},[o.update,s.floating,s.reference]);else{const l=j(),[F,v]=n.useState(!1);n.useEffect(()=>{const _=E.addListener("keyboardDidShow",()=>{v(!0)}),M=E.addListener("keyboardDidHide",()=>{v(!1)});return()=>{_.remove(),M.remove()}},[]),z(()=>{o.update()},[l,F])}return<G scope={p}anchorRef={i}size={P}arrowRef={x}arrowStyle={A.arrow}onArrowSize={h}isMounted={r}{...o}>{d}</G>}const J="PopperAnchor",Me=R.extractable(n.forwardRef(function(p,d){const{__scopePopper:P,virtualRef:u,...c}=p,{anchorRef:e,getReferenceProps:a}=C(J,P),r=n.useRef(null),m=g(d,r,e);if(u)return null;const i={ref:m,...c};return<R{...a?a(i):i}/>})),Q="PopperContent",X=k(B,{name:"PopperContent",variants:{unstyled:{false:{size:"$true",backgroundColor:"$background",alignItems:"center",radiused:!0}},size:{"...size":(f,{tokens:p})=>({padding:p.space[f],borderRadius:p.radius[f]})}},defaultVariants:{unstyled:!1}}),Te=n.forwardRef(function(p,d){const{__scopePopper:P,...u}=p,{strategy:c,placement:e,floating:a,x:r,y:m,getFloatingProps:i,size:t,isMounted:y}=C(Q,P),w=g(a,d),h=n.useMemo(()=><X key="popper-content-frame"data-placement={e}data-strategy={c}size={u.size||t}{...u}/>,[e,c,p]);if(!y)return null;const S={ref:w,x:r||0,y:m||0,position:c};return<R animateOnly={["transform"]}{...i?i(S):S}>{h}</R>}),Z="PopperArrow",V=k(R,{name:"PopperArrow",variants:{unstyled:{false:{borderColor:"$borderColor",backgroundColor:"$background",position:"relative"}}},defaultVariants:{unstyled:!1}}),Pe=k(R,{name:"PopperArrowOuter",variants:{unstyled:{false:{position:"absolute",zIndex:-1,pointerEvents:"none",overflow:"hidden",alignItems:"center",justifyContent:"center"}}},defaultVariants:{unstyled:!1}}),ue={top:"bottom",right:"left",bottom:"top",left:"right"},We=V.extractable(n.forwardRef(function(p,d){const{__scopePopper:P,offset:u,size:c,borderWidth:e=0,...a}=p,r=C(Z,P),m=c??r.size,t=+T($("space",m,-2,[2])),{placement:y}=r,w=g(r.arrowRef,d),h=r.arrowStyle?.x||0,S=r.arrowStyle?.y||0,o=y?y.split("-")[0]:"top",s={x:h,y:S,width:t,height:t},A={},x=o==="bottom"||o==="top";if(o){s[x?"width":"height"]=t*2;const l=ue[o];l&&(s[l]=-t,A[l]=t/2),(l==="top"||l==="bottom")&&(s.left=0),(l==="left"||l==="right")&&(s.top=0)}return z(()=>{r.onArrowSize?.(t)},[t,r.onArrowSize]),<Pe ref={w}{...s}><V width={t}height={t}{...a}{...A}rotate="45deg"{...o==="bottom"&&{borderBottomWidth:e,borderRightWidth:e}}{...o==="top"&&{borderTopWidth:e,borderLeftWidth:e}}{...o==="right"&&{borderTopWidth:e,borderRightWidth:e}}{...o==="left"&&{borderBottomWidth:e,borderLeftWidth:e}}/></Pe>}));export{_e as Popper,Me as PopperAnchor,We as PopperArrow,Te as PopperContent,X as PopperContentFrame,G as PopperProvider,Fe as createPopperScope,C as usePopperContext};
|
|
281
2
|
//# sourceMappingURL=Popper.js.map
|
package/dist/jsx/Popper.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Popper.tsx"],
|
|
4
4
|
"sourcesContent": ["// adapted from radix-ui popper\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n SizeTokens,\n StackProps,\n getVariableValue,\n isWeb,\n styled,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport {\n Coords,\n Placement,\n Strategy,\n UseFloatingReturn,\n arrow,\n autoUpdate,\n flip,\n offset,\n shift,\n useFloating,\n} from '@tamagui/floating'\nimport { stepTokenUpOrDown } from '@tamagui/get-size'\nimport { SizableStackProps, ThemeableStack, YStack, YStackProps } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Keyboard, View, useWindowDimensions } from 'react-native'\n\ntype ShiftProps = typeof shift extends (options: infer Opts) => void ? Opts : never\ntype FlipProps = typeof flip extends (options: infer Opts) => void ? Opts : never\n\n/* -------------------------------------------------------------------------------------------------\n * Popper\n * -----------------------------------------------------------------------------------------------*/\n\nconst POPPER_NAME = 'Popper'\n\ntype ScopedProps<P> = P & { __scopePopper?: Scope }\nconst [createPopperContext, createScope] = createContextScope(POPPER_NAME)\n\nexport const createPopperScope = createScope\n\ntype PopperContextValue = UseFloatingReturn & {\n isMounted: boolean\n anchorRef: any\n size?: SizeTokens\n placement?: Placement\n arrowRef: any\n onArrowSize?: (val: number) => void\n arrowStyle?: Partial<Coords> & {\n centerOffset: number\n }\n}\nexport const [PopperProvider, usePopperContext] =\n createPopperContext<PopperContextValue>(POPPER_NAME)\n\nexport type PopperProps = {\n size?: SizeTokens\n children?: React.ReactNode\n placement?: Placement\n stayInFrame?: ShiftProps | boolean\n allowFlip?: FlipProps | boolean\n strategy?: Strategy\n}\n\nexport function Popper(props: ScopedProps<PopperProps>) {\n const {\n __scopePopper,\n children,\n size,\n strategy = 'absolute',\n placement = 'bottom',\n stayInFrame,\n allowFlip,\n } = props\n\n const [isMounted, setIsMounted] = React.useState(false)\n useIsomorphicLayoutEffect(() => {\n setIsMounted(true)\n }, [])\n\n const anchorRef = React.useRef<any>()\n const [arrowEl, setArrow] = React.useState<any>(null)\n const [arrowSize, setArrowSize] = React.useState(0)\n const arrowRef = React.useRef()\n\n const floating = useFloating({\n strategy,\n placement,\n sameScrollView: false, // this only takes effect on native\n middleware: [\n stayInFrame\n ? shift(typeof stayInFrame === 'boolean' ? {} : stayInFrame)\n : (null as any),\n allowFlip ? flip(typeof allowFlip === 'boolean' ? {} : allowFlip) : (null as any),\n arrowEl ? arrow({ element: arrowEl }) : (null as any),\n arrowSize ? offset(arrowSize) : (null as any),\n ].filter(Boolean),\n })\n\n const { refs, middlewareData } = floating\n\n const composedArrowRefs = useComposedRefs<any>(arrowRef, setArrow)\n\n useIsomorphicLayoutEffect(() => {\n floating.reference(anchorRef.current)\n }, [anchorRef])\n\n if (isWeb) {\n React.useEffect(() => {\n if (!(refs.reference.current && refs.floating.current)) {\n return\n }\n // Only call this when the floating element is rendered\n return autoUpdate(refs.reference.current, refs.floating.current, floating.update)\n }, [floating.update, refs.floating, refs.reference])\n } else {\n // On Native there's no autoupdate so we call update() when necessary\n\n // Subscribe to window dimensions (orientation, scale, etc...)\n const dimensions = useWindowDimensions()\n\n // Subscribe to keyboard state\n const [keyboardOpen, setKeyboardOpen] = React.useState(false)\n React.useEffect(() => {\n const showSubscription = Keyboard.addListener('keyboardDidShow', () => {\n setKeyboardOpen(true)\n })\n const hideSubscription = Keyboard.addListener('keyboardDidHide', () => {\n setKeyboardOpen(false)\n })\n\n return () => {\n showSubscription.remove()\n hideSubscription.remove()\n }\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n floating.update()\n }, [dimensions, keyboardOpen])\n }\n\n return (\n <PopperProvider\n scope={__scopePopper}\n anchorRef={anchorRef}\n size={size}\n arrowRef={composedArrowRefs}\n arrowStyle={middlewareData.arrow}\n onArrowSize={setArrowSize}\n isMounted={isMounted}\n {...floating}\n >\n {children}\n </PopperProvider>\n )\n}\n\n/* -------------------------------------------------------------------------------------------------\n * PopperAnchor\n * -----------------------------------------------------------------------------------------------*/\n\nconst ANCHOR_NAME = 'PopperAnchor'\n\ntype PopperAnchorRef = HTMLElement | View\n\nexport type PopperAnchorProps = YStackProps & {\n virtualRef?: React.RefObject<any>\n}\n\nexport const PopperAnchor = YStack.extractable(\n React.forwardRef<PopperAnchorRef, PopperAnchorProps>(function PopperAnchor(\n props: ScopedProps<PopperAnchorProps>,\n forwardedRef\n ) {\n const { __scopePopper, virtualRef, ...anchorProps } = props\n const { anchorRef, getReferenceProps } = usePopperContext(ANCHOR_NAME, __scopePopper)\n const ref = React.useRef<PopperAnchorRef>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref, anchorRef)\n if (virtualRef) {\n return null\n }\n const stackProps = {\n ref: composedRefs,\n ...anchorProps,\n }\n return (\n <YStack {...(getReferenceProps ? getReferenceProps(stackProps) : stackProps)} />\n )\n })\n)\n\n/* -------------------------------------------------------------------------------------------------\n * PopperContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'PopperContent'\n\ntype PopperContentElement = HTMLElement | View\n\nexport type PopperContentProps = SizableStackProps\n\nexport const PopperContentFrame = styled(ThemeableStack, {\n name: 'PopperContent',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n backgroundColor: '$background',\n alignItems: 'center',\n radiused: true,\n },\n },\n\n size: {\n '...size': (val, { tokens }) => {\n return {\n padding: tokens.space[val],\n borderRadius: tokens.radius[val],\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nexport const PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>(\n function PopperContent(props: ScopedProps<PopperContentProps>, forwardedRef) {\n const { __scopePopper, ...contentProps } = props\n const { strategy, placement, floating, x, y, getFloatingProps, size, isMounted } =\n usePopperContext(CONTENT_NAME, __scopePopper)\n const contentRefs = useComposedRefs<any>(floating, forwardedRef)\n\n const contents = React.useMemo(() => {\n return (\n <PopperContentFrame\n key=\"popper-content-frame\"\n data-placement={placement}\n data-strategy={strategy}\n size={contentProps.size || size}\n {...contentProps}\n />\n )\n }, [placement, strategy, props])\n\n // all poppers hidden on ssr by default\n if (!isMounted) {\n return null\n }\n\n const frameProps = {\n ref: contentRefs,\n x: x || 0,\n y: y || 0,\n position: strategy,\n }\n\n // outer frame because we explicitly dont want animation to apply to this\n return (\n <YStack\n animateOnly={['transform']}\n {...(getFloatingProps ? getFloatingProps(frameProps) : frameProps)}\n >\n {contents}\n </YStack>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * PopperArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'PopperArrow'\n\ntype PopperArrowElement = HTMLElement | View\n\nexport type PopperArrowProps = YStackProps & {\n offset?: number\n size?: SizeTokens\n}\n\nconst PopperArrowFrame = styled(YStack, {\n name: 'PopperArrow',\n\n variants: {\n unstyled: {\n false: {\n borderColor: '$borderColor',\n backgroundColor: '$background',\n position: 'relative',\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nconst PopperArrowOuterFrame = styled(YStack, {\n name: 'PopperArrowOuter',\n\n variants: {\n unstyled: {\n false: {\n position: 'absolute',\n zIndex: -1,\n pointerEvents: 'none',\n overflow: 'hidden',\n alignItems: 'center',\n justifyContent: 'center',\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nconst opposites = {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right',\n} as const\n\ntype Sides = keyof typeof opposites\n\nexport const PopperArrow = PopperArrowFrame.extractable(\n React.forwardRef<PopperArrowElement, PopperArrowProps>(function PopperArrow(\n props: ScopedProps<PopperArrowProps>,\n forwardedRef\n ) {\n const {\n __scopePopper,\n offset,\n size: sizeProp,\n borderWidth = 0,\n ...arrowProps\n } = props\n const context = usePopperContext(ARROW_NAME, __scopePopper)\n const sizeVal = sizeProp ?? context.size\n const sizeValResolved = getVariableValue(stepTokenUpOrDown('space', sizeVal, -2, [2]))\n const size = +sizeValResolved\n const { placement } = context\n const refs = useComposedRefs(context.arrowRef, forwardedRef)\n\n // Sometimes floating-ui can return NaN during orientation or screen size changes on native\n // so we explictly force the x,y position types as a number\n const x = (context.arrowStyle?.x as number) || 0\n const y = (context.arrowStyle?.y as number) || 0\n\n const primaryPlacement = (placement ? placement.split('-')[0] : 'top') as Sides\n\n const arrowStyle: StackProps = { x, y, width: size, height: size }\n const innerArrowStyle: StackProps = {}\n const isVertical = primaryPlacement === 'bottom' || primaryPlacement === 'top'\n\n if (primaryPlacement) {\n // allows for extra diagonal size\n arrowStyle[isVertical ? 'width' : 'height'] = size * 2\n const oppSide = opposites[primaryPlacement]\n if (oppSide) {\n arrowStyle[oppSide] = -size\n innerArrowStyle[oppSide] = size / 2\n }\n if (oppSide === 'top' || oppSide === 'bottom') {\n arrowStyle.left = 0\n }\n if (oppSide === 'left' || oppSide === 'right') {\n arrowStyle.top = 0\n }\n }\n\n // send the Arrow's offset up to Popper\n useIsomorphicLayoutEffect(() => {\n context.onArrowSize?.(size)\n }, [size, context.onArrowSize])\n\n // outer frame to cut off for ability to have nicer shadows/borders\n return (\n <PopperArrowOuterFrame ref={refs} {...arrowStyle}>\n <PopperArrowFrame\n width={size}\n height={size}\n {...arrowProps}\n {...innerArrowStyle}\n rotate=\"45deg\"\n {...(primaryPlacement === 'bottom' && {\n borderBottomWidth: borderWidth,\n borderRightWidth: borderWidth,\n })}\n {...(primaryPlacement === 'top' && {\n borderTopWidth: borderWidth,\n borderLeftWidth: borderWidth,\n })}\n {...(primaryPlacement === 'right' && {\n borderTopWidth: borderWidth,\n borderRightWidth: borderWidth,\n })}\n {...(primaryPlacement === 'left' && {\n borderBottomWidth: borderWidth,\n borderLeftWidth: borderWidth,\n })}\n />\n </PopperArrowOuterFrame>\n )\n })\n)\n\n/* -----------------------------------------------------------------------------------------------*/\n"],
|
|
5
|
-
"mappings": "AAEA,
|
|
6
|
-
"names": ["PopperAnchor", "PopperContent", "PopperArrow", "
|
|
5
|
+
"mappings": "AAEA,OAAS,mBAAAA,MAAuB,wBAChC,OAGE,oBAAAC,EACA,SAAAC,EACA,UAAAC,EACA,6BAAAC,MACK,gBACP,OAAgB,sBAAAC,MAA0B,0BAC1C,OAKE,SAAAC,EACA,cAAAC,EACA,QAAAC,EACA,UAAAC,EACA,SAAAC,EACA,eAAAC,MACK,oBACP,OAAS,qBAAAC,MAAyB,oBAClC,OAA4B,kBAAAC,EAAgB,UAAAC,MAA2B,kBACvE,UAAYC,MAAW,QACvB,OAAS,YAAAC,EAAgB,uBAAAC,MAA2B,eASpD,MAAMC,EAAc,SAG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ACpC,CAACV,EACC,OAAO5C,EACP,QAAQA,MACJkD,MACAK,EACJ,OAAO,WACFF,IAAqB,UAAY,CACpC,kBAAmBJ,EACnB,iBAAkBA,CACpB,MACKI,IAAqB,OAAS,CACjC,eAAgBJ,EAChB,gBAAiBA,CACnB,MACKI,IAAqB,SAAW,CACnC,eAAgBJ,EAChB,iBAAkBA,CACpB,MACKI,IAAqB,QAAU,CAClC,kBAAmBJ,EACnB,gBAAiBA,CACnB,EACF,EACF,EAxBCJ,GA0BL,CAAC,CACH",
|
|
6
|
+
"names": ["useComposedRefs", "getVariableValue", "isWeb", "styled", "useIsomorphicLayoutEffect", "createContextScope", "arrow", "autoUpdate", "flip", "offset", "shift", "useFloating", "stepTokenUpOrDown", "ThemeableStack", "YStack", "React", "Keyboard", "useWindowDimensions", "POPPER_NAME", "createPopperContext", "createScope", "createPopperScope", "PopperProvider", "usePopperContext", "Popper", "props", "__scopePopper", "children", "size", "strategy", "placement", "stayInFrame", "allowFlip", "isMounted", "setIsMounted", "anchorRef", "arrowEl", "setArrow", "arrowSize", "setArrowSize", "arrowRef", "floating", "refs", "middlewareData", "composedArrowRefs", "dimensions", "keyboardOpen", "setKeyboardOpen", "showSubscription", "hideSubscription", "ANCHOR_NAME", "PopperAnchor", "forwardedRef", "virtualRef", "anchorProps", "getReferenceProps", "ref", "composedRefs", "stackProps", "CONTENT_NAME", "PopperContentFrame", "val", "tokens", "PopperContent", "contentProps", "x", "y", "getFloatingProps", "contentRefs", "contents", "frameProps", "ARROW_NAME", "PopperArrowFrame", "PopperArrowOuterFrame", "opposites", "PopperArrow", "sizeProp", "borderWidth", "arrowProps", "context", "sizeVal", "primaryPlacement", "arrowStyle", "innerArrowStyle", "isVertical", "oppSide"]
|
|
7
7
|
}
|
package/dist/jsx/Popper.mjs
CHANGED
|
@@ -1,281 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
getVariableValue,
|
|
4
|
-
isWeb,
|
|
5
|
-
styled,
|
|
6
|
-
useIsomorphicLayoutEffect
|
|
7
|
-
} from "@tamagui/core";
|
|
8
|
-
import { createContextScope } from "@tamagui/create-context";
|
|
9
|
-
import {
|
|
10
|
-
arrow,
|
|
11
|
-
autoUpdate,
|
|
12
|
-
flip,
|
|
13
|
-
offset,
|
|
14
|
-
shift,
|
|
15
|
-
useFloating
|
|
16
|
-
} from "@tamagui/floating";
|
|
17
|
-
import { stepTokenUpOrDown } from "@tamagui/get-size";
|
|
18
|
-
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
19
|
-
import * as React from "react";
|
|
20
|
-
import { Keyboard, useWindowDimensions } from "react-native";
|
|
21
|
-
const POPPER_NAME = "Popper";
|
|
22
|
-
const [createPopperContext, createScope] = createContextScope(POPPER_NAME);
|
|
23
|
-
const createPopperScope = createScope;
|
|
24
|
-
const [PopperProvider, usePopperContext] = createPopperContext(POPPER_NAME);
|
|
25
|
-
function Popper(props) {
|
|
26
|
-
const {
|
|
27
|
-
__scopePopper,
|
|
28
|
-
children,
|
|
29
|
-
size,
|
|
30
|
-
strategy = "absolute",
|
|
31
|
-
placement = "bottom",
|
|
32
|
-
stayInFrame,
|
|
33
|
-
allowFlip
|
|
34
|
-
} = props;
|
|
35
|
-
const [isMounted, setIsMounted] = React.useState(false);
|
|
36
|
-
useIsomorphicLayoutEffect(() => {
|
|
37
|
-
setIsMounted(true);
|
|
38
|
-
}, []);
|
|
39
|
-
const anchorRef = React.useRef();
|
|
40
|
-
const [arrowEl, setArrow] = React.useState(null);
|
|
41
|
-
const [arrowSize, setArrowSize] = React.useState(0);
|
|
42
|
-
const arrowRef = React.useRef();
|
|
43
|
-
const floating = useFloating({
|
|
44
|
-
strategy,
|
|
45
|
-
placement,
|
|
46
|
-
sameScrollView: false,
|
|
47
|
-
// this only takes effect on native
|
|
48
|
-
middleware: [
|
|
49
|
-
stayInFrame ? shift(typeof stayInFrame === "boolean" ? {} : stayInFrame) : null,
|
|
50
|
-
allowFlip ? flip(typeof allowFlip === "boolean" ? {} : allowFlip) : null,
|
|
51
|
-
arrowEl ? arrow({ element: arrowEl }) : null,
|
|
52
|
-
arrowSize ? offset(arrowSize) : null
|
|
53
|
-
].filter(Boolean)
|
|
54
|
-
});
|
|
55
|
-
const { refs, middlewareData } = floating;
|
|
56
|
-
const composedArrowRefs = useComposedRefs(arrowRef, setArrow);
|
|
57
|
-
useIsomorphicLayoutEffect(() => {
|
|
58
|
-
floating.reference(anchorRef.current);
|
|
59
|
-
}, [anchorRef]);
|
|
60
|
-
if (isWeb) {
|
|
61
|
-
React.useEffect(() => {
|
|
62
|
-
if (!(refs.reference.current && refs.floating.current)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
return autoUpdate(refs.reference.current, refs.floating.current, floating.update);
|
|
66
|
-
}, [floating.update, refs.floating, refs.reference]);
|
|
67
|
-
} else {
|
|
68
|
-
const dimensions = useWindowDimensions();
|
|
69
|
-
const [keyboardOpen, setKeyboardOpen] = React.useState(false);
|
|
70
|
-
React.useEffect(() => {
|
|
71
|
-
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
|
|
72
|
-
setKeyboardOpen(true);
|
|
73
|
-
});
|
|
74
|
-
const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
|
|
75
|
-
setKeyboardOpen(false);
|
|
76
|
-
});
|
|
77
|
-
return () => {
|
|
78
|
-
showSubscription.remove();
|
|
79
|
-
hideSubscription.remove();
|
|
80
|
-
};
|
|
81
|
-
}, []);
|
|
82
|
-
useIsomorphicLayoutEffect(() => {
|
|
83
|
-
floating.update();
|
|
84
|
-
}, [dimensions, keyboardOpen]);
|
|
85
|
-
}
|
|
86
|
-
return <PopperProvider
|
|
87
|
-
scope={__scopePopper}
|
|
88
|
-
anchorRef={anchorRef}
|
|
89
|
-
size={size}
|
|
90
|
-
arrowRef={composedArrowRefs}
|
|
91
|
-
arrowStyle={middlewareData.arrow}
|
|
92
|
-
onArrowSize={setArrowSize}
|
|
93
|
-
isMounted={isMounted}
|
|
94
|
-
{...floating}
|
|
95
|
-
>{children}</PopperProvider>;
|
|
96
|
-
}
|
|
97
|
-
const ANCHOR_NAME = "PopperAnchor";
|
|
98
|
-
const PopperAnchor = YStack.extractable(
|
|
99
|
-
React.forwardRef(function PopperAnchor2(props, forwardedRef) {
|
|
100
|
-
const { __scopePopper, virtualRef, ...anchorProps } = props;
|
|
101
|
-
const { anchorRef, getReferenceProps } = usePopperContext(ANCHOR_NAME, __scopePopper);
|
|
102
|
-
const ref = React.useRef(null);
|
|
103
|
-
const composedRefs = useComposedRefs(forwardedRef, ref, anchorRef);
|
|
104
|
-
if (virtualRef) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
const stackProps = {
|
|
108
|
-
ref: composedRefs,
|
|
109
|
-
...anchorProps
|
|
110
|
-
};
|
|
111
|
-
return <YStack {...getReferenceProps ? getReferenceProps(stackProps) : stackProps} />;
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
const CONTENT_NAME = "PopperContent";
|
|
115
|
-
const PopperContentFrame = styled(ThemeableStack, {
|
|
116
|
-
name: "PopperContent",
|
|
117
|
-
variants: {
|
|
118
|
-
unstyled: {
|
|
119
|
-
false: {
|
|
120
|
-
size: "$true",
|
|
121
|
-
backgroundColor: "$background",
|
|
122
|
-
alignItems: "center",
|
|
123
|
-
radiused: true
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
size: {
|
|
127
|
-
"...size": (val, { tokens }) => {
|
|
128
|
-
return {
|
|
129
|
-
padding: tokens.space[val],
|
|
130
|
-
borderRadius: tokens.radius[val]
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
defaultVariants: {
|
|
136
|
-
unstyled: false
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
const PopperContent = React.forwardRef(
|
|
140
|
-
function PopperContent2(props, forwardedRef) {
|
|
141
|
-
const { __scopePopper, ...contentProps } = props;
|
|
142
|
-
const { strategy, placement, floating, x, y, getFloatingProps, size, isMounted } = usePopperContext(CONTENT_NAME, __scopePopper);
|
|
143
|
-
const contentRefs = useComposedRefs(floating, forwardedRef);
|
|
144
|
-
const contents = React.useMemo(() => {
|
|
145
|
-
return <PopperContentFrame
|
|
146
|
-
key="popper-content-frame"
|
|
147
|
-
data-placement={placement}
|
|
148
|
-
data-strategy={strategy}
|
|
149
|
-
size={contentProps.size || size}
|
|
150
|
-
{...contentProps}
|
|
151
|
-
/>;
|
|
152
|
-
}, [placement, strategy, props]);
|
|
153
|
-
if (!isMounted) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
const frameProps = {
|
|
157
|
-
ref: contentRefs,
|
|
158
|
-
x: x || 0,
|
|
159
|
-
y: y || 0,
|
|
160
|
-
position: strategy
|
|
161
|
-
};
|
|
162
|
-
return <YStack
|
|
163
|
-
animateOnly={["transform"]}
|
|
164
|
-
{...getFloatingProps ? getFloatingProps(frameProps) : frameProps}
|
|
165
|
-
>{contents}</YStack>;
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
const ARROW_NAME = "PopperArrow";
|
|
169
|
-
const PopperArrowFrame = styled(YStack, {
|
|
170
|
-
name: "PopperArrow",
|
|
171
|
-
variants: {
|
|
172
|
-
unstyled: {
|
|
173
|
-
false: {
|
|
174
|
-
borderColor: "$borderColor",
|
|
175
|
-
backgroundColor: "$background",
|
|
176
|
-
position: "relative"
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
defaultVariants: {
|
|
181
|
-
unstyled: false
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
const PopperArrowOuterFrame = styled(YStack, {
|
|
185
|
-
name: "PopperArrowOuter",
|
|
186
|
-
variants: {
|
|
187
|
-
unstyled: {
|
|
188
|
-
false: {
|
|
189
|
-
position: "absolute",
|
|
190
|
-
zIndex: -1,
|
|
191
|
-
pointerEvents: "none",
|
|
192
|
-
overflow: "hidden",
|
|
193
|
-
alignItems: "center",
|
|
194
|
-
justifyContent: "center"
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
defaultVariants: {
|
|
199
|
-
unstyled: false
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
const opposites = {
|
|
203
|
-
top: "bottom",
|
|
204
|
-
right: "left",
|
|
205
|
-
bottom: "top",
|
|
206
|
-
left: "right"
|
|
207
|
-
};
|
|
208
|
-
const PopperArrow = PopperArrowFrame.extractable(
|
|
209
|
-
React.forwardRef(function PopperArrow2(props, forwardedRef) {
|
|
210
|
-
const {
|
|
211
|
-
__scopePopper,
|
|
212
|
-
offset: offset2,
|
|
213
|
-
size: sizeProp,
|
|
214
|
-
borderWidth = 0,
|
|
215
|
-
...arrowProps
|
|
216
|
-
} = props;
|
|
217
|
-
const context = usePopperContext(ARROW_NAME, __scopePopper);
|
|
218
|
-
const sizeVal = sizeProp ?? context.size;
|
|
219
|
-
const sizeValResolved = getVariableValue(stepTokenUpOrDown("space", sizeVal, -2, [2]));
|
|
220
|
-
const size = +sizeValResolved;
|
|
221
|
-
const { placement } = context;
|
|
222
|
-
const refs = useComposedRefs(context.arrowRef, forwardedRef);
|
|
223
|
-
const x = context.arrowStyle?.x || 0;
|
|
224
|
-
const y = context.arrowStyle?.y || 0;
|
|
225
|
-
const primaryPlacement = placement ? placement.split("-")[0] : "top";
|
|
226
|
-
const arrowStyle = { x, y, width: size, height: size };
|
|
227
|
-
const innerArrowStyle = {};
|
|
228
|
-
const isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
229
|
-
if (primaryPlacement) {
|
|
230
|
-
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
231
|
-
const oppSide = opposites[primaryPlacement];
|
|
232
|
-
if (oppSide) {
|
|
233
|
-
arrowStyle[oppSide] = -size;
|
|
234
|
-
innerArrowStyle[oppSide] = size / 2;
|
|
235
|
-
}
|
|
236
|
-
if (oppSide === "top" || oppSide === "bottom") {
|
|
237
|
-
arrowStyle.left = 0;
|
|
238
|
-
}
|
|
239
|
-
if (oppSide === "left" || oppSide === "right") {
|
|
240
|
-
arrowStyle.top = 0;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
useIsomorphicLayoutEffect(() => {
|
|
244
|
-
context.onArrowSize?.(size);
|
|
245
|
-
}, [size, context.onArrowSize]);
|
|
246
|
-
return <PopperArrowOuterFrame ref={refs} {...arrowStyle}><PopperArrowFrame
|
|
247
|
-
width={size}
|
|
248
|
-
height={size}
|
|
249
|
-
{...arrowProps}
|
|
250
|
-
{...innerArrowStyle}
|
|
251
|
-
rotate="45deg"
|
|
252
|
-
{...primaryPlacement === "bottom" && {
|
|
253
|
-
borderBottomWidth: borderWidth,
|
|
254
|
-
borderRightWidth: borderWidth
|
|
255
|
-
}}
|
|
256
|
-
{...primaryPlacement === "top" && {
|
|
257
|
-
borderTopWidth: borderWidth,
|
|
258
|
-
borderLeftWidth: borderWidth
|
|
259
|
-
}}
|
|
260
|
-
{...primaryPlacement === "right" && {
|
|
261
|
-
borderTopWidth: borderWidth,
|
|
262
|
-
borderRightWidth: borderWidth
|
|
263
|
-
}}
|
|
264
|
-
{...primaryPlacement === "left" && {
|
|
265
|
-
borderBottomWidth: borderWidth,
|
|
266
|
-
borderLeftWidth: borderWidth
|
|
267
|
-
}}
|
|
268
|
-
/></PopperArrowOuterFrame>;
|
|
269
|
-
})
|
|
270
|
-
);
|
|
271
|
-
export {
|
|
272
|
-
Popper,
|
|
273
|
-
PopperAnchor,
|
|
274
|
-
PopperArrow,
|
|
275
|
-
PopperContent,
|
|
276
|
-
PopperContentFrame,
|
|
277
|
-
PopperProvider,
|
|
278
|
-
createPopperScope,
|
|
279
|
-
usePopperContext
|
|
280
|
-
};
|
|
1
|
+
import{useComposedRefs as g}from"@tamagui/compose-refs";import{getVariableValue as T,isWeb as W,styled as k,useIsomorphicLayoutEffect as z}from"@tamagui/core";import{createContextScope as L}from"@tamagui/create-context";import{arrow as N,autoUpdate as I,flip as D,offset as H,shift as Y,useFloating as U}from"@tamagui/floating";import{stepTokenUpOrDown as $}from"@tamagui/get-size";import{ThemeableStack as B,YStack as R}from"@tamagui/stacks";import*as n from"react";import{Keyboard as E,useWindowDimensions as j}from"react-native";const O="Popper",[K,q]=L(O),Fe=q,[G,C]=K(O);function _e(f){const{__scopePopper:p,children:d,size:P,strategy:u="absolute",placement:c="bottom",stayInFrame:e,allowFlip:a}=f,[r,m]=n.useState(!1);z(()=>{m(!0)},[]);const i=n.useRef(),[t,y]=n.useState(null),[w,h]=n.useState(0),S=n.useRef(),o=U({strategy:u,placement:c,sameScrollView:!1,middleware:[e?Y(typeof e=="boolean"?{}:e):null,a?D(typeof a=="boolean"?{}:a):null,t?N({element:t}):null,w?H(w):null].filter(Boolean)}),{refs:s,middlewareData:A}=o,x=g(S,y);if(z(()=>{o.reference(i.current)},[i]),W)n.useEffect(()=>{if(s.reference.current&&s.floating.current)return I(s.reference.current,s.floating.current,o.update)},[o.update,s.floating,s.reference]);else{const l=j(),[F,v]=n.useState(!1);n.useEffect(()=>{const _=E.addListener("keyboardDidShow",()=>{v(!0)}),M=E.addListener("keyboardDidHide",()=>{v(!1)});return()=>{_.remove(),M.remove()}},[]),z(()=>{o.update()},[l,F])}return<G scope={p}anchorRef={i}size={P}arrowRef={x}arrowStyle={A.arrow}onArrowSize={h}isMounted={r}{...o}>{d}</G>}const J="PopperAnchor",Me=R.extractable(n.forwardRef(function(p,d){const{__scopePopper:P,virtualRef:u,...c}=p,{anchorRef:e,getReferenceProps:a}=C(J,P),r=n.useRef(null),m=g(d,r,e);if(u)return null;const i={ref:m,...c};return<R{...a?a(i):i}/>})),Q="PopperContent",X=k(B,{name:"PopperContent",variants:{unstyled:{false:{size:"$true",backgroundColor:"$background",alignItems:"center",radiused:!0}},size:{"...size":(f,{tokens:p})=>({padding:p.space[f],borderRadius:p.radius[f]})}},defaultVariants:{unstyled:!1}}),Te=n.forwardRef(function(p,d){const{__scopePopper:P,...u}=p,{strategy:c,placement:e,floating:a,x:r,y:m,getFloatingProps:i,size:t,isMounted:y}=C(Q,P),w=g(a,d),h=n.useMemo(()=><X key="popper-content-frame"data-placement={e}data-strategy={c}size={u.size||t}{...u}/>,[e,c,p]);if(!y)return null;const S={ref:w,x:r||0,y:m||0,position:c};return<R animateOnly={["transform"]}{...i?i(S):S}>{h}</R>}),Z="PopperArrow",V=k(R,{name:"PopperArrow",variants:{unstyled:{false:{borderColor:"$borderColor",backgroundColor:"$background",position:"relative"}}},defaultVariants:{unstyled:!1}}),Pe=k(R,{name:"PopperArrowOuter",variants:{unstyled:{false:{position:"absolute",zIndex:-1,pointerEvents:"none",overflow:"hidden",alignItems:"center",justifyContent:"center"}}},defaultVariants:{unstyled:!1}}),ue={top:"bottom",right:"left",bottom:"top",left:"right"},We=V.extractable(n.forwardRef(function(p,d){const{__scopePopper:P,offset:u,size:c,borderWidth:e=0,...a}=p,r=C(Z,P),m=c??r.size,t=+T($("space",m,-2,[2])),{placement:y}=r,w=g(r.arrowRef,d),h=r.arrowStyle?.x||0,S=r.arrowStyle?.y||0,o=y?y.split("-")[0]:"top",s={x:h,y:S,width:t,height:t},A={},x=o==="bottom"||o==="top";if(o){s[x?"width":"height"]=t*2;const l=ue[o];l&&(s[l]=-t,A[l]=t/2),(l==="top"||l==="bottom")&&(s.left=0),(l==="left"||l==="right")&&(s.top=0)}return z(()=>{r.onArrowSize?.(t)},[t,r.onArrowSize]),<Pe ref={w}{...s}><V width={t}height={t}{...a}{...A}rotate="45deg"{...o==="bottom"&&{borderBottomWidth:e,borderRightWidth:e}}{...o==="top"&&{borderTopWidth:e,borderLeftWidth:e}}{...o==="right"&&{borderTopWidth:e,borderRightWidth:e}}{...o==="left"&&{borderBottomWidth:e,borderLeftWidth:e}}/></Pe>}));export{_e as Popper,Me as PopperAnchor,We as PopperArrow,Te as PopperContent,X as PopperContentFrame,G as PopperProvider,Fe as createPopperScope,C as usePopperContext};
|
|
281
2
|
//# sourceMappingURL=Popper.mjs.map
|