@tamagui/popover 1.2.8 → 1.2.10
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/esm/Popover.mjs +391 -0
- package/dist/esm/Popover.mjs.map +7 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/jsx/Popover.mjs +361 -0
- package/dist/jsx/Popover.mjs.map +7 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/index.mjs.map +7 -0
- package/package.json +17 -17
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "@tamagui/polyfill-dev";
|
|
3
|
+
import {
|
|
4
|
+
useDismiss,
|
|
5
|
+
useFloating,
|
|
6
|
+
useInteractions,
|
|
7
|
+
useRole
|
|
8
|
+
} from "@floating-ui/react-dom-interactions";
|
|
9
|
+
import { Adapt, useAdaptParent } from "@tamagui/adapt";
|
|
10
|
+
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
11
|
+
import { hideOthers } from "@tamagui/aria-hidden";
|
|
12
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
13
|
+
import {
|
|
14
|
+
Stack,
|
|
15
|
+
Theme,
|
|
16
|
+
composeEventHandlers,
|
|
17
|
+
isWeb,
|
|
18
|
+
useEvent,
|
|
19
|
+
useGet,
|
|
20
|
+
useId,
|
|
21
|
+
useMedia,
|
|
22
|
+
useThemeName,
|
|
23
|
+
withStaticProperties
|
|
24
|
+
} from "@tamagui/core";
|
|
25
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
26
|
+
import { FloatingOverrideContext } from "@tamagui/floating";
|
|
27
|
+
import { FocusScope } from "@tamagui/focus-scope";
|
|
28
|
+
import {
|
|
29
|
+
Popper,
|
|
30
|
+
PopperAnchor,
|
|
31
|
+
PopperArrow,
|
|
32
|
+
PopperContent,
|
|
33
|
+
PopperProvider,
|
|
34
|
+
createPopperScope,
|
|
35
|
+
usePopperContext
|
|
36
|
+
} from "@tamagui/popper";
|
|
37
|
+
import { Portal, PortalHost, PortalItem } from "@tamagui/portal";
|
|
38
|
+
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
39
|
+
import { ControlledSheet, SheetController } from "@tamagui/sheet";
|
|
40
|
+
import { YStack } from "@tamagui/stacks";
|
|
41
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
42
|
+
import * as React from "react";
|
|
43
|
+
import {
|
|
44
|
+
Platform,
|
|
45
|
+
ScrollView
|
|
46
|
+
} from "react-native";
|
|
47
|
+
const POPOVER_NAME = "Popover";
|
|
48
|
+
const [createPopoverContext, createPopoverScopeInternal] = createContextScope(
|
|
49
|
+
POPOVER_NAME,
|
|
50
|
+
[createPopperScope]
|
|
51
|
+
);
|
|
52
|
+
const usePopoverScope = createPopperScope();
|
|
53
|
+
const createPopoverScope = createPopoverScopeInternal;
|
|
54
|
+
const [PopoverProviderInternal, usePopoverInternalContext] = createPopoverContext(POPOVER_NAME);
|
|
55
|
+
const __PopoverProviderInternal = PopoverProviderInternal;
|
|
56
|
+
const ANCHOR_NAME = "PopoverAnchor";
|
|
57
|
+
const PopoverAnchor = React.forwardRef(
|
|
58
|
+
(props, forwardedRef) => {
|
|
59
|
+
const { __scopePopover, ...anchorProps } = props;
|
|
60
|
+
const context = usePopoverInternalContext(ANCHOR_NAME, __scopePopover);
|
|
61
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
62
|
+
const { onCustomAnchorAdd, onCustomAnchorRemove } = context;
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
onCustomAnchorAdd();
|
|
65
|
+
return () => onCustomAnchorRemove();
|
|
66
|
+
}, [onCustomAnchorAdd, onCustomAnchorRemove]);
|
|
67
|
+
return /* @__PURE__ */ jsx(PopperAnchor, { ...popperScope, ...anchorProps, ref: forwardedRef });
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
PopoverAnchor.displayName = ANCHOR_NAME;
|
|
71
|
+
const TRIGGER_NAME = "PopoverTrigger";
|
|
72
|
+
const PopoverTrigger = React.forwardRef((props, forwardedRef) => {
|
|
73
|
+
const { __scopePopover, ...triggerProps } = props;
|
|
74
|
+
const context = usePopoverInternalContext(TRIGGER_NAME, __scopePopover);
|
|
75
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
76
|
+
const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
77
|
+
const trigger = /* @__PURE__ */ jsx(
|
|
78
|
+
YStack,
|
|
79
|
+
{
|
|
80
|
+
"aria-haspopup": "dialog",
|
|
81
|
+
"aria-expanded": context.open,
|
|
82
|
+
"data-state": getState(context.open),
|
|
83
|
+
...triggerProps,
|
|
84
|
+
ref: composedTriggerRef,
|
|
85
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
return context.hasCustomAnchor ? trigger : /* @__PURE__ */ jsx(PopperAnchor, { asChild: true, ...popperScope, children: trigger });
|
|
89
|
+
});
|
|
90
|
+
PopoverTrigger.displayName = TRIGGER_NAME;
|
|
91
|
+
const CONTENT_NAME = "PopoverContent";
|
|
92
|
+
const PopoverContent = React.forwardRef((props, forwardedRef) => {
|
|
93
|
+
const {
|
|
94
|
+
allowPinchZoom,
|
|
95
|
+
trapFocus,
|
|
96
|
+
disableRemoveScroll = true,
|
|
97
|
+
zIndex,
|
|
98
|
+
...contentModalProps
|
|
99
|
+
} = props;
|
|
100
|
+
const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover);
|
|
101
|
+
const contentRef = React.useRef(null);
|
|
102
|
+
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
103
|
+
const isRightClickOutsideRef = React.useRef(false);
|
|
104
|
+
React.useEffect(() => {
|
|
105
|
+
if (!context.open)
|
|
106
|
+
return;
|
|
107
|
+
const content = contentRef.current;
|
|
108
|
+
if (content)
|
|
109
|
+
return hideOthers(content);
|
|
110
|
+
}, [context.open]);
|
|
111
|
+
return /* @__PURE__ */ jsx(PopoverContentPortal, { zIndex, children: /* @__PURE__ */ jsx(
|
|
112
|
+
PopoverContentImpl,
|
|
113
|
+
{
|
|
114
|
+
...contentModalProps,
|
|
115
|
+
disableRemoveScroll,
|
|
116
|
+
ref: composedRefs,
|
|
117
|
+
trapFocus: trapFocus ?? context.open,
|
|
118
|
+
disableOutsidePointerEvents: true,
|
|
119
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
|
|
120
|
+
var _a;
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
if (!isRightClickOutsideRef.current)
|
|
123
|
+
(_a = context.triggerRef.current) == null ? void 0 : _a.focus();
|
|
124
|
+
}),
|
|
125
|
+
onPointerDownOutside: composeEventHandlers(
|
|
126
|
+
props.onPointerDownOutside,
|
|
127
|
+
(event) => {
|
|
128
|
+
const originalEvent = event.detail.originalEvent;
|
|
129
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
130
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
131
|
+
isRightClickOutsideRef.current = isRightClick;
|
|
132
|
+
},
|
|
133
|
+
{ checkDefaultPrevented: false }
|
|
134
|
+
),
|
|
135
|
+
onFocusOutside: composeEventHandlers(
|
|
136
|
+
props.onFocusOutside,
|
|
137
|
+
(event) => event.preventDefault(),
|
|
138
|
+
{ checkDefaultPrevented: false }
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
) });
|
|
142
|
+
});
|
|
143
|
+
function PopoverContentPortal(props) {
|
|
144
|
+
const themeName = useThemeName();
|
|
145
|
+
const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover);
|
|
146
|
+
let contents = props.children;
|
|
147
|
+
if (Platform.OS === "android") {
|
|
148
|
+
const popperContext = usePopperContext(CONTENT_NAME, context.popperScope);
|
|
149
|
+
contents = /* @__PURE__ */ jsx(PopperProvider, { ...popperContext, scope: context.popperScope, children: /* @__PURE__ */ jsx(PopoverProviderInternal, { scope: props.__scopePopover, ...context, children: props.children }) });
|
|
150
|
+
}
|
|
151
|
+
const zIndex = props.zIndex ?? 1e3;
|
|
152
|
+
return /* @__PURE__ */ jsx(Portal, { zIndex, children: /* @__PURE__ */ jsxs(Theme, { forceClassName: true, name: themeName, children: [
|
|
153
|
+
!!context.open && !context.breakpointActive && /* @__PURE__ */ jsx(
|
|
154
|
+
YStack,
|
|
155
|
+
{
|
|
156
|
+
fullscreen: true,
|
|
157
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
/* @__PURE__ */ jsx(Stack, { zIndex: zIndex + 1, children: contents })
|
|
161
|
+
] }) });
|
|
162
|
+
}
|
|
163
|
+
const PopoverContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
164
|
+
const {
|
|
165
|
+
__scopePopover,
|
|
166
|
+
trapFocus,
|
|
167
|
+
onOpenAutoFocus,
|
|
168
|
+
onCloseAutoFocus,
|
|
169
|
+
disableOutsidePointerEvents,
|
|
170
|
+
onEscapeKeyDown,
|
|
171
|
+
onPointerDownOutside,
|
|
172
|
+
onFocusOutside,
|
|
173
|
+
onInteractOutside,
|
|
174
|
+
children,
|
|
175
|
+
disableRemoveScroll,
|
|
176
|
+
...contentProps
|
|
177
|
+
} = props;
|
|
178
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
179
|
+
const context = usePopoverInternalContext(CONTENT_NAME, popperScope.__scopePopover);
|
|
180
|
+
if (context.breakpointActive) {
|
|
181
|
+
const childrenWithoutScrollView = React.Children.toArray(children).map((child) => {
|
|
182
|
+
if (React.isValidElement(child)) {
|
|
183
|
+
if (child.type === PopoverScrollView) {
|
|
184
|
+
return child.props.children;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return child;
|
|
188
|
+
});
|
|
189
|
+
return /* @__PURE__ */ jsx(PortalItem, { hostName: `${context.scopeKey}SheetContents`, children: childrenWithoutScrollView });
|
|
190
|
+
}
|
|
191
|
+
return /* @__PURE__ */ jsx(AnimatePresence, { children: !!context.open && /* @__PURE__ */ jsx(
|
|
192
|
+
PopperContent,
|
|
193
|
+
{
|
|
194
|
+
"data-state": getState(context.open),
|
|
195
|
+
id: context.contentId,
|
|
196
|
+
pointerEvents: "auto",
|
|
197
|
+
ref: forwardedRef,
|
|
198
|
+
...popperScope,
|
|
199
|
+
...contentProps,
|
|
200
|
+
children: /* @__PURE__ */ jsx(
|
|
201
|
+
RemoveScroll,
|
|
202
|
+
{
|
|
203
|
+
enabled: disableRemoveScroll ? false : context.open,
|
|
204
|
+
allowPinchZoom: true,
|
|
205
|
+
removeScrollBar: false,
|
|
206
|
+
style: {
|
|
207
|
+
display: "contents"
|
|
208
|
+
},
|
|
209
|
+
children: trapFocus === false ? children : /* @__PURE__ */ jsx(
|
|
210
|
+
FocusScope,
|
|
211
|
+
{
|
|
212
|
+
loop: true,
|
|
213
|
+
trapped: trapFocus ?? context.open,
|
|
214
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
215
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
216
|
+
children: isWeb ? /* @__PURE__ */ jsx("div", { style: { display: "contents" }, children }) : children
|
|
217
|
+
}
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
},
|
|
222
|
+
context.contentId
|
|
223
|
+
) });
|
|
224
|
+
});
|
|
225
|
+
const CLOSE_NAME = "PopoverClose";
|
|
226
|
+
const PopoverClose = React.forwardRef(
|
|
227
|
+
(props, forwardedRef) => {
|
|
228
|
+
const { __scopePopover, ...closeProps } = props;
|
|
229
|
+
const context = usePopoverInternalContext(CLOSE_NAME, __scopePopover);
|
|
230
|
+
return /* @__PURE__ */ jsx(
|
|
231
|
+
YStack,
|
|
232
|
+
{
|
|
233
|
+
...closeProps,
|
|
234
|
+
ref: forwardedRef,
|
|
235
|
+
onPress: composeEventHandlers(
|
|
236
|
+
props.onPress,
|
|
237
|
+
() => context.onOpenChange(false)
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
PopoverClose.displayName = CLOSE_NAME;
|
|
244
|
+
const ARROW_NAME = "PopoverArrow";
|
|
245
|
+
const PopoverArrow = React.forwardRef(
|
|
246
|
+
(props, forwardedRef) => {
|
|
247
|
+
const { __scopePopover, ...arrowProps } = props;
|
|
248
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
249
|
+
return /* @__PURE__ */ jsx(PopperArrow, { ...popperScope, ...arrowProps, ref: forwardedRef });
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
PopoverArrow.displayName = ARROW_NAME;
|
|
253
|
+
const PopoverScrollView = React.forwardRef((props, ref) => {
|
|
254
|
+
return /* @__PURE__ */ jsx(ScrollView, { ref, ...props });
|
|
255
|
+
});
|
|
256
|
+
const Popover = withStaticProperties(
|
|
257
|
+
(props) => {
|
|
258
|
+
const {
|
|
259
|
+
__scopePopover,
|
|
260
|
+
children,
|
|
261
|
+
open: openProp,
|
|
262
|
+
defaultOpen,
|
|
263
|
+
onOpenChange,
|
|
264
|
+
...restProps
|
|
265
|
+
} = props;
|
|
266
|
+
const internalId = useId();
|
|
267
|
+
const id = __scopePopover ? Object.keys(__scopePopover)[0] : internalId;
|
|
268
|
+
const { when, AdaptProvider } = useAdaptParent({
|
|
269
|
+
Contents: React.useCallback(() => {
|
|
270
|
+
return /* @__PURE__ */ jsx(PortalHost, { name: `${id}SheetContents` });
|
|
271
|
+
}, [])
|
|
272
|
+
});
|
|
273
|
+
const sheetBreakpoint = when;
|
|
274
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
275
|
+
const triggerRef = React.useRef(null);
|
|
276
|
+
const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
|
|
277
|
+
const [open, setOpen] = useControllableState({
|
|
278
|
+
prop: openProp,
|
|
279
|
+
defaultProp: defaultOpen || false,
|
|
280
|
+
onChange: onOpenChange,
|
|
281
|
+
transition: true
|
|
282
|
+
});
|
|
283
|
+
const breakpointActive = useSheetBreakpointActive(sheetBreakpoint);
|
|
284
|
+
const useFloatingContext = React.useCallback(
|
|
285
|
+
(props2) => {
|
|
286
|
+
const floating = useFloating({
|
|
287
|
+
...props2,
|
|
288
|
+
open,
|
|
289
|
+
onOpenChange: setOpen
|
|
290
|
+
});
|
|
291
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
292
|
+
// useFocus(floating.context, {
|
|
293
|
+
// enabled: !breakpointActive,
|
|
294
|
+
// keyboardOnly: true,
|
|
295
|
+
// }),
|
|
296
|
+
useRole(floating.context, { role: "dialog" }),
|
|
297
|
+
useDismiss(floating.context, {
|
|
298
|
+
enabled: !breakpointActive
|
|
299
|
+
})
|
|
300
|
+
]);
|
|
301
|
+
return {
|
|
302
|
+
...floating,
|
|
303
|
+
getReferenceProps,
|
|
304
|
+
getFloatingProps
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
[breakpointActive, open, setOpen]
|
|
308
|
+
);
|
|
309
|
+
const popoverContext = {
|
|
310
|
+
scope: __scopePopover,
|
|
311
|
+
scopeKey: id,
|
|
312
|
+
popperScope: popperScope.__scopePopper,
|
|
313
|
+
sheetBreakpoint,
|
|
314
|
+
contentId: useId(),
|
|
315
|
+
triggerRef,
|
|
316
|
+
open,
|
|
317
|
+
breakpointActive,
|
|
318
|
+
onOpenChange: setOpen,
|
|
319
|
+
onOpenToggle: useEvent(() => {
|
|
320
|
+
if (open && breakpointActive) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
setOpen(!open);
|
|
324
|
+
}),
|
|
325
|
+
hasCustomAnchor,
|
|
326
|
+
onCustomAnchorAdd: React.useCallback(() => setHasCustomAnchor(true), []),
|
|
327
|
+
onCustomAnchorRemove: React.useCallback(() => setHasCustomAnchor(false), [])
|
|
328
|
+
};
|
|
329
|
+
const contents = /* @__PURE__ */ jsx(Popper, { ...popperScope, stayInFrame: true, ...restProps, children: /* @__PURE__ */ jsx(PopoverProviderInternal, { ...popoverContext, children: /* @__PURE__ */ jsx(PopoverSheetController, { onOpenChange: setOpen, __scopePopover, children }) }) });
|
|
330
|
+
return /* @__PURE__ */ jsx(AdaptProvider, { children: isWeb ? /* @__PURE__ */ jsx(FloatingOverrideContext.Provider, { value: useFloatingContext, children: contents }) : contents });
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
Anchor: PopoverAnchor,
|
|
334
|
+
Arrow: PopoverArrow,
|
|
335
|
+
Trigger: PopoverTrigger,
|
|
336
|
+
Content: PopoverContent,
|
|
337
|
+
Close: PopoverClose,
|
|
338
|
+
Adapt,
|
|
339
|
+
ScrollView: PopoverScrollView,
|
|
340
|
+
Sheet: ControlledSheet
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
Popover.displayName = POPOVER_NAME;
|
|
344
|
+
function getState(open) {
|
|
345
|
+
return open ? "open" : "closed";
|
|
346
|
+
}
|
|
347
|
+
const PopoverSheetController = (props) => {
|
|
348
|
+
const context = usePopoverInternalContext(
|
|
349
|
+
"PopoverSheetController",
|
|
350
|
+
props.__scopePopover
|
|
351
|
+
);
|
|
352
|
+
const showSheet = useShowPopoverSheet(context);
|
|
353
|
+
const breakpointActive = context.breakpointActive;
|
|
354
|
+
const getShowSheet = useGet(showSheet);
|
|
355
|
+
return /* @__PURE__ */ jsx(
|
|
356
|
+
SheetController,
|
|
357
|
+
{
|
|
358
|
+
onOpenChange: (val) => {
|
|
359
|
+
if (getShowSheet()) {
|
|
360
|
+
props.onOpenChange(val);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
open: context.open,
|
|
364
|
+
hidden: breakpointActive === false,
|
|
365
|
+
children: props.children
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
};
|
|
369
|
+
const useSheetBreakpointActive = (breakpoint) => {
|
|
370
|
+
const media = useMedia();
|
|
371
|
+
if (typeof breakpoint === "boolean" || !breakpoint) {
|
|
372
|
+
return !!breakpoint;
|
|
373
|
+
}
|
|
374
|
+
return media[breakpoint];
|
|
375
|
+
};
|
|
376
|
+
const useShowPopoverSheet = (context) => {
|
|
377
|
+
const breakpointActive = useSheetBreakpointActive(context.sheetBreakpoint);
|
|
378
|
+
return context.open === false ? false : breakpointActive;
|
|
379
|
+
};
|
|
380
|
+
export {
|
|
381
|
+
Popover,
|
|
382
|
+
PopoverAnchor,
|
|
383
|
+
PopoverArrow,
|
|
384
|
+
PopoverClose,
|
|
385
|
+
PopoverContent,
|
|
386
|
+
PopoverTrigger,
|
|
387
|
+
__PopoverProviderInternal,
|
|
388
|
+
createPopoverScope,
|
|
389
|
+
usePopoverScope
|
|
390
|
+
};
|
|
391
|
+
//# sourceMappingURL=Popover.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Popover.tsx"],
|
|
4
|
+
"sourcesContent": ["// adapted from radix-ui popover\n\nimport '@tamagui/polyfill-dev'\n\nimport type { UseFloatingProps } from '@floating-ui/react-dom-interactions'\nimport {\n useDismiss,\n useFloating,\n useInteractions,\n useRole,\n} from '@floating-ui/react-dom-interactions'\nimport { Adapt, useAdaptParent } from '@tamagui/adapt'\nimport { AnimatePresence } from '@tamagui/animate-presence'\nimport { hideOthers } from '@tamagui/aria-hidden'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GestureReponderEvent,\n MediaQueryKey,\n SizeTokens,\n Stack,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n isWeb,\n useEvent,\n useGet,\n useId,\n useMedia,\n useThemeName,\n withStaticProperties,\n} from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport { createContextScope } from '@tamagui/create-context'\nimport { DismissableProps } from '@tamagui/dismissable'\nimport { FloatingOverrideContext } from '@tamagui/floating'\nimport { FocusScope, FocusScopeProps } from '@tamagui/focus-scope'\nimport {\n Popper,\n PopperAnchor,\n PopperArrow,\n PopperArrowProps,\n PopperContent,\n PopperContentProps,\n PopperProps,\n PopperProvider,\n createPopperScope,\n usePopperContext,\n} from '@tamagui/popper'\nimport { Portal, PortalHost, PortalItem } from '@tamagui/portal'\nimport { RemoveScroll, RemoveScrollProps } from '@tamagui/remove-scroll'\nimport { ControlledSheet, SheetController } from '@tamagui/sheet'\nimport { SizableStack, XStack, YStack, YStackProps, ZStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { useEffect } from 'react'\nimport {\n GestureResponderEvent,\n Platform,\n ScrollView,\n ScrollViewProps,\n View,\n} from 'react-native'\n\nconst POPOVER_NAME = 'Popover'\n\ntype ScopedProps<P> = P & { __scopePopover?: Scope }\n\nexport type PopoverProps = PopperProps & {\n open?: boolean\n defaultOpen?: boolean\n onOpenChange?: (open: boolean) => void\n}\n\ntype PopoverContextValue = {\n triggerRef: React.RefObject<any>\n contentId?: string\n open: boolean\n onOpenChange(open: boolean): void\n onOpenToggle(): void\n hasCustomAnchor: boolean\n onCustomAnchorAdd(): void\n onCustomAnchorRemove(): void\n size?: SizeTokens\n sheetBreakpoint: any\n scopeKey: string\n popperScope: any\n breakpointActive?: boolean\n}\n\nconst [createPopoverContext, createPopoverScopeInternal] = createContextScope(\n POPOVER_NAME,\n [createPopperScope]\n)\nexport const usePopoverScope = createPopperScope()\nexport const createPopoverScope = createPopoverScopeInternal\n\nconst [PopoverProviderInternal, usePopoverInternalContext] =\n createPopoverContext<PopoverContextValue>(POPOVER_NAME)\n\nexport const __PopoverProviderInternal = PopoverProviderInternal\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverAnchor\n * -----------------------------------------------------------------------------------------------*/\n\nconst ANCHOR_NAME = 'PopoverAnchor'\n\ntype PopoverAnchorElement = HTMLElement | View\nexport type PopoverAnchorProps = YStackProps\n\nexport const PopoverAnchor = React.forwardRef<PopoverAnchorElement, PopoverAnchorProps>(\n (props: ScopedProps<PopoverAnchorProps>, forwardedRef) => {\n const { __scopePopover, ...anchorProps } = props\n const context = usePopoverInternalContext(ANCHOR_NAME, __scopePopover)\n const popperScope = usePopoverScope(__scopePopover)\n const { onCustomAnchorAdd, onCustomAnchorRemove } = context\n\n React.useEffect(() => {\n onCustomAnchorAdd()\n return () => onCustomAnchorRemove()\n }, [onCustomAnchorAdd, onCustomAnchorRemove])\n\n return <PopperAnchor {...popperScope} {...anchorProps} ref={forwardedRef} />\n }\n)\n\nPopoverAnchor.displayName = ANCHOR_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'PopoverTrigger'\n\ntype PopoverTriggerElement = HTMLElement | View\nexport type PopoverTriggerProps = YStackProps\n\nexport const PopoverTrigger = React.forwardRef<\n PopoverTriggerElement,\n PopoverTriggerProps\n>((props: ScopedProps<PopoverTriggerProps>, forwardedRef) => {\n const { __scopePopover, ...triggerProps } = props\n const context = usePopoverInternalContext(TRIGGER_NAME, __scopePopover)\n const popperScope = usePopoverScope(__scopePopover)\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef)\n\n const trigger = (\n <YStack\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n // TODO not matching\n // aria-controls={context.contentId}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onPress={composeEventHandlers(props.onPress as any, context.onOpenToggle)}\n />\n )\n\n return context.hasCustomAnchor ? (\n trigger\n ) : (\n <PopperAnchor asChild {...popperScope}>\n {trigger}\n </PopperAnchor>\n )\n})\n\nPopoverTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'PopoverContent'\n\nexport type PopoverContentProps = PopoverContentTypeProps\n\ntype PopoverContentTypeElement = PopoverContentImplElement\n\nexport interface PopoverContentTypeProps\n extends Omit<PopoverContentImplProps, 'disableOutsidePointerEvents'> {\n /**\n * @see https://github.com/theKashey/react-remove-scroll#usage\n */\n allowPinchZoom?: RemoveScrollProps['allowPinchZoom']\n}\n\nexport const PopoverContent = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentTypeProps\n>((props: ScopedProps<PopoverContentTypeProps>, forwardedRef) => {\n const {\n allowPinchZoom,\n trapFocus,\n disableRemoveScroll = true,\n zIndex,\n ...contentModalProps\n } = props\n const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover)\n const contentRef = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const isRightClickOutsideRef = React.useRef(false)\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n if (!context.open) return\n const content = contentRef.current\n if (content) return hideOthers(content)\n }, [context.open])\n\n return (\n <PopoverContentPortal zIndex={zIndex}>\n <PopoverContentImpl\n {...contentModalProps}\n disableRemoveScroll={disableRemoveScroll}\n ref={composedRefs}\n // we make sure we're not trapping once it's been closed\n // (closed !== unmounted when animating out)\n trapFocus={trapFocus ?? context.open}\n disableOutsidePointerEvents\n onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {\n event.preventDefault()\n if (!isRightClickOutsideRef.current) context.triggerRef.current?.focus()\n })}\n onPointerDownOutside={composeEventHandlers(\n props.onPointerDownOutside,\n (event) => {\n const originalEvent = event.detail.originalEvent\n const ctrlLeftClick =\n originalEvent.button === 0 && originalEvent.ctrlKey === true\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick\n isRightClickOutsideRef.current = isRightClick\n },\n { checkDefaultPrevented: false }\n )}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(\n props.onFocusOutside,\n (event) => event.preventDefault(),\n { checkDefaultPrevented: false }\n )}\n />\n </PopoverContentPortal>\n )\n})\n\nfunction PopoverContentPortal(props: ScopedProps<PopoverContentTypeProps>) {\n const themeName = useThemeName()\n const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover)\n\n // on android we have to re-pass context\n let contents = props.children\n\n if (Platform.OS === 'android') {\n // ok conditional hooks by platform\n const popperContext = usePopperContext(CONTENT_NAME, context.popperScope)\n\n contents = (\n <PopperProvider {...popperContext} scope={context.popperScope}>\n <PopoverProviderInternal scope={props.__scopePopover} {...context}>\n {/* does this need to be props.__scopePopper? */}\n {props.children}\n </PopoverProviderInternal>\n </PopperProvider>\n )\n }\n\n const zIndex = props.zIndex ?? 1000\n\n // Portal the contents and add a transparent bg overlay to handle dismiss on native\n return (\n <Portal zIndex={zIndex}>\n <Theme forceClassName name={themeName}>\n {!!context.open && !context.breakpointActive && (\n <YStack\n fullscreen\n onPress={composeEventHandlers(props.onPress as any, context.onOpenToggle)}\n />\n )}\n <Stack zIndex={(zIndex as number) + 1}>{contents}</Stack>\n </Theme>\n </Portal>\n )\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PopoverContentImplElement = React.ElementRef<typeof PopperContent>\n\nexport interface PopoverContentImplProps\n extends PopperContentProps,\n Omit<DismissableProps, 'onDismiss' | 'children'> {\n /**\n * Whether focus should be trapped within the `Popover`\n * (default: false)\n */\n trapFocus?: FocusScopeProps['trapped']\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus']\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus']\n\n disableRemoveScroll?: boolean\n}\n\nconst PopoverContentImpl = React.forwardRef<\n PopoverContentImplElement,\n PopoverContentImplProps\n>((props: ScopedProps<PopoverContentImplProps>, forwardedRef) => {\n const {\n __scopePopover,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n disableOutsidePointerEvents,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n children,\n disableRemoveScroll,\n ...contentProps\n } = props\n const popperScope = usePopoverScope(__scopePopover)\n const context = usePopoverInternalContext(CONTENT_NAME, popperScope.__scopePopover)\n\n if (context.breakpointActive) {\n // unwrap the PopoverScrollView if used, as it will use the SheetScrollView if that exists\n const childrenWithoutScrollView = React.Children.toArray(children).map((child) => {\n if (React.isValidElement(child)) {\n if (child.type === PopoverScrollView) {\n return child.props.children\n }\n }\n return child\n })\n\n // doesn't show as popover yet on native, must use as sheet\n return (\n <PortalItem hostName={`${context.scopeKey}SheetContents`}>\n {childrenWithoutScrollView}\n </PortalItem>\n )\n }\n\n // const handleDismiss = React.useCallback((event: GestureResponderEvent) =>{\n // context.onOpenChange(false);\n // }, [])\n // <Dismissable\n // disableOutsidePointerEvents={disableOutsidePointerEvents}\n // // onInteractOutside={onInteractOutside}\n // onEscapeKeyDown={onEscapeKeyDown}\n // // onPointerDownOutside={onPointerDownOutside}\n // // onFocusOutside={onFocusOutside}\n // onDismiss={handleDismiss}\n // >\n\n return (\n <AnimatePresence>\n {!!context.open && (\n <PopperContent\n key={context.contentId}\n data-state={getState(context.open)}\n id={context.contentId}\n pointerEvents=\"auto\"\n ref={forwardedRef}\n {...popperScope}\n {...contentProps}\n >\n <RemoveScroll\n enabled={disableRemoveScroll ? false : context.open}\n allowPinchZoom\n // causes lots of bugs on touch web on site\n removeScrollBar={false}\n style={{\n display: 'contents',\n }}\n >\n {trapFocus === false ? (\n children\n ) : (\n <FocusScope\n loop\n trapped={trapFocus ?? context.open}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n {isWeb ? <div style={{ display: 'contents' }}>{children}</div> : children}\n </FocusScope>\n )}\n </RemoveScroll>\n </PopperContent>\n )}\n </AnimatePresence>\n )\n})\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'PopoverClose'\n\ntype PopoverCloseElement = HTMLElement | View\nexport type PopoverCloseProps = YStackProps\n\nexport const PopoverClose = React.forwardRef<PopoverCloseElement, PopoverCloseProps>(\n (props: ScopedProps<PopoverCloseProps>, forwardedRef) => {\n const { __scopePopover, ...closeProps } = props\n const context = usePopoverInternalContext(CLOSE_NAME, __scopePopover)\n return (\n <YStack\n {...closeProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, () =>\n context.onOpenChange(false)\n )}\n />\n )\n }\n)\n\nPopoverClose.displayName = CLOSE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'PopoverArrow'\n\ntype PopoverArrowElement = HTMLElement | View\nexport type PopoverArrowProps = PopperArrowProps\n\nexport const PopoverArrow = React.forwardRef<PopoverArrowElement, PopoverArrowProps>(\n (props: ScopedProps<PopoverArrowProps>, forwardedRef) => {\n const { __scopePopover, ...arrowProps } = props\n const popperScope = usePopoverScope(__scopePopover)\n return <PopperArrow {...popperScope} {...arrowProps} ref={forwardedRef} />\n }\n)\n\nPopoverArrow.displayName = ARROW_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverScrollView\n * -----------------------------------------------------------------------------------------------*/\n\nconst PopoverScrollView = React.forwardRef<ScrollView, ScrollViewProps>((props, ref) => {\n return <ScrollView ref={ref} {...props} />\n})\n\n/* -------------------------------------------------------------------------------------------------\n * Popover\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Popover = withStaticProperties(\n ((props: ScopedProps<PopoverProps>) => {\n const {\n __scopePopover,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n ...restProps\n } = props\n\n const internalId = useId()\n const id = __scopePopover ? Object.keys(__scopePopover)[0] : internalId\n\n const { when, AdaptProvider } = useAdaptParent({\n Contents: React.useCallback(() => {\n return <PortalHost name={`${id}SheetContents`} />\n }, []),\n })\n\n const sheetBreakpoint = when\n const popperScope = usePopoverScope(__scopePopover)\n const triggerRef = React.useRef<TamaguiElement>(null)\n const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false)\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen || false,\n onChange: onOpenChange,\n transition: true,\n })\n\n const breakpointActive = useSheetBreakpointActive(sheetBreakpoint)\n\n // Custom floating context to override the Popper on web\n const useFloatingContext = React.useCallback(\n (props: UseFloatingProps) => {\n const floating = useFloating({\n ...props,\n open,\n onOpenChange: setOpen,\n })\n const { getReferenceProps, getFloatingProps } = useInteractions([\n // useFocus(floating.context, {\n // enabled: !breakpointActive,\n // keyboardOnly: true,\n // }),\n useRole(floating.context, { role: 'dialog' }),\n useDismiss(floating.context, {\n enabled: !breakpointActive,\n }),\n ])\n return {\n ...floating,\n getReferenceProps,\n getFloatingProps,\n }\n },\n [breakpointActive, open, setOpen]\n )\n\n const popoverContext = {\n scope: __scopePopover,\n scopeKey: id,\n popperScope: popperScope.__scopePopper,\n sheetBreakpoint,\n contentId: useId(),\n triggerRef,\n open,\n breakpointActive,\n onOpenChange: setOpen,\n onOpenToggle: useEvent(() => {\n if (open && breakpointActive) {\n return\n }\n setOpen(!open)\n }),\n hasCustomAnchor,\n onCustomAnchorAdd: React.useCallback(() => setHasCustomAnchor(true), []),\n onCustomAnchorRemove: React.useCallback(() => setHasCustomAnchor(false), []),\n }\n\n // debug if changing too often\n // if (process.env.NODE_ENV === 'development') {\n // Object.keys(popoverContext).forEach((key) => {\n // React.useEffect(() => console.log(`changed`, key), [popoverContext[key]])\n // })\n // }\n\n const contents = (\n <Popper {...popperScope} stayInFrame {...restProps}>\n <PopoverProviderInternal {...popoverContext}>\n <PopoverSheetController onOpenChange={setOpen} __scopePopover={__scopePopover}>\n {children}\n </PopoverSheetController>\n </PopoverProviderInternal>\n </Popper>\n )\n\n return (\n <AdaptProvider>\n {isWeb ? (\n <FloatingOverrideContext.Provider value={useFloatingContext as any}>\n {contents}\n </FloatingOverrideContext.Provider>\n ) : (\n contents\n )}\n </AdaptProvider>\n )\n }) as React.FC<PopoverProps>,\n {\n Anchor: PopoverAnchor,\n Arrow: PopoverArrow,\n Trigger: PopoverTrigger,\n Content: PopoverContent,\n Close: PopoverClose,\n Adapt,\n ScrollView: PopoverScrollView,\n Sheet: ControlledSheet,\n }\n)\n\nPopover.displayName = POPOVER_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getState(open: boolean) {\n return open ? 'open' : 'closed'\n}\n\nconst PopoverSheetController = (\n props: ScopedProps<{\n children: React.ReactNode\n onOpenChange: React.Dispatch<React.SetStateAction<boolean>>\n }>\n) => {\n const context = usePopoverInternalContext(\n 'PopoverSheetController',\n props.__scopePopover\n )\n const showSheet = useShowPopoverSheet(context)\n const breakpointActive = context.breakpointActive\n const getShowSheet = useGet(showSheet)\n return (\n <SheetController\n onOpenChange={(val) => {\n if (getShowSheet()) {\n props.onOpenChange(val)\n }\n }}\n open={context.open}\n hidden={breakpointActive === false}\n >\n {props.children}\n </SheetController>\n )\n}\n\nconst useSheetBreakpointActive = (breakpoint?: MediaQueryKey | null | boolean) => {\n const media = useMedia()\n if (typeof breakpoint === 'boolean' || !breakpoint) {\n return !!breakpoint\n }\n return media[breakpoint]\n}\n\nconst useShowPopoverSheet = (context: PopoverContextValue) => {\n const breakpointActive = useSheetBreakpointActive(context.sheetBreakpoint)\n return context.open === false ? false : breakpointActive\n}\n"],
|
|
5
|
+
"mappings": "AA0HW,cAwJL,YAxJK;AAxHX,OAAO;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,OAAO,sBAAsB;AACtC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC;AAAA,EAIE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AAEnC,SAAS,+BAA+B;AACxC,SAAS,kBAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,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AAA,IACT,SAAS;AAAA,IACT,OAAO;AAAA,IACP;AAAA,IACA,YAAY;AAAA,IACZ,OAAO;AAAA,EACT;AACF;AAEA,QAAQ,cAAc;AAItB,SAAS,SAAS,MAAe;AAC/B,SAAO,OAAO,SAAS;AACzB;AAEA,MAAM,yBAAyB,CAC7B,UAIG;AACH,QAAM,UAAU;AAAA,IACd;AAAA,IACA,MAAM;AAAA,EACR;AACA,QAAM,YAAY,oBAAoB,OAAO;AAC7C,QAAM,mBAAmB,QAAQ;AACjC,QAAM,eAAe,OAAO,SAAS;AACrC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAc,CAAC,QAAQ;AACrB,YAAI,aAAa,GAAG;AAClB,gBAAM,aAAa,GAAG;AAAA,QACxB;AAAA,MACF;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,QAAQ,qBAAqB;AAAA,MAE5B,gBAAM;AAAA;AAAA,EACT;AAEJ;AAEA,MAAM,2BAA2B,CAAC,eAAgD;AAChF,QAAM,QAAQ,SAAS;AACvB,MAAI,OAAO,eAAe,aAAa,CAAC,YAAY;AAClD,WAAO,CAAC,CAAC;AAAA,EACX;AACA,SAAO,MAAM,UAAU;AACzB;AAEA,MAAM,sBAAsB,CAAC,YAAiC;AAC5D,QAAM,mBAAmB,yBAAyB,QAAQ,eAAe;AACzE,SAAO,QAAQ,SAAS,QAAQ,QAAQ;AAC1C;",
|
|
6
|
+
"names": ["props"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import "@tamagui/polyfill-dev";
|
|
2
|
+
import {
|
|
3
|
+
useDismiss,
|
|
4
|
+
useFloating,
|
|
5
|
+
useInteractions,
|
|
6
|
+
useRole
|
|
7
|
+
} from "@floating-ui/react-dom-interactions";
|
|
8
|
+
import { Adapt, useAdaptParent } from "@tamagui/adapt";
|
|
9
|
+
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
10
|
+
import { hideOthers } from "@tamagui/aria-hidden";
|
|
11
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
12
|
+
import {
|
|
13
|
+
Stack,
|
|
14
|
+
Theme,
|
|
15
|
+
composeEventHandlers,
|
|
16
|
+
isWeb,
|
|
17
|
+
useEvent,
|
|
18
|
+
useGet,
|
|
19
|
+
useId,
|
|
20
|
+
useMedia,
|
|
21
|
+
useThemeName,
|
|
22
|
+
withStaticProperties
|
|
23
|
+
} from "@tamagui/core";
|
|
24
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
25
|
+
import { FloatingOverrideContext } from "@tamagui/floating";
|
|
26
|
+
import { FocusScope } from "@tamagui/focus-scope";
|
|
27
|
+
import {
|
|
28
|
+
Popper,
|
|
29
|
+
PopperAnchor,
|
|
30
|
+
PopperArrow,
|
|
31
|
+
PopperContent,
|
|
32
|
+
PopperProvider,
|
|
33
|
+
createPopperScope,
|
|
34
|
+
usePopperContext
|
|
35
|
+
} from "@tamagui/popper";
|
|
36
|
+
import { Portal, PortalHost, PortalItem } from "@tamagui/portal";
|
|
37
|
+
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
38
|
+
import { ControlledSheet, SheetController } from "@tamagui/sheet";
|
|
39
|
+
import { YStack } from "@tamagui/stacks";
|
|
40
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
41
|
+
import * as React from "react";
|
|
42
|
+
import {
|
|
43
|
+
Platform,
|
|
44
|
+
ScrollView
|
|
45
|
+
} from "react-native";
|
|
46
|
+
const POPOVER_NAME = "Popover";
|
|
47
|
+
const [createPopoverContext, createPopoverScopeInternal] = createContextScope(
|
|
48
|
+
POPOVER_NAME,
|
|
49
|
+
[createPopperScope]
|
|
50
|
+
);
|
|
51
|
+
const usePopoverScope = createPopperScope();
|
|
52
|
+
const createPopoverScope = createPopoverScopeInternal;
|
|
53
|
+
const [PopoverProviderInternal, usePopoverInternalContext] = createPopoverContext(POPOVER_NAME);
|
|
54
|
+
const __PopoverProviderInternal = PopoverProviderInternal;
|
|
55
|
+
const ANCHOR_NAME = "PopoverAnchor";
|
|
56
|
+
const PopoverAnchor = React.forwardRef(
|
|
57
|
+
(props, forwardedRef) => {
|
|
58
|
+
const { __scopePopover, ...anchorProps } = props;
|
|
59
|
+
const context = usePopoverInternalContext(ANCHOR_NAME, __scopePopover);
|
|
60
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
61
|
+
const { onCustomAnchorAdd, onCustomAnchorRemove } = context;
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
onCustomAnchorAdd();
|
|
64
|
+
return () => onCustomAnchorRemove();
|
|
65
|
+
}, [onCustomAnchorAdd, onCustomAnchorRemove]);
|
|
66
|
+
return <PopperAnchor {...popperScope} {...anchorProps} ref={forwardedRef} />;
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
PopoverAnchor.displayName = ANCHOR_NAME;
|
|
70
|
+
const TRIGGER_NAME = "PopoverTrigger";
|
|
71
|
+
const PopoverTrigger = React.forwardRef((props, forwardedRef) => {
|
|
72
|
+
const { __scopePopover, ...triggerProps } = props;
|
|
73
|
+
const context = usePopoverInternalContext(TRIGGER_NAME, __scopePopover);
|
|
74
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
75
|
+
const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
76
|
+
const trigger = <YStack
|
|
77
|
+
aria-haspopup="dialog"
|
|
78
|
+
aria-expanded={context.open}
|
|
79
|
+
data-state={getState(context.open)}
|
|
80
|
+
{...triggerProps}
|
|
81
|
+
ref={composedTriggerRef}
|
|
82
|
+
onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}
|
|
83
|
+
/>;
|
|
84
|
+
return context.hasCustomAnchor ? trigger : <PopperAnchor asChild {...popperScope}>{trigger}</PopperAnchor>;
|
|
85
|
+
});
|
|
86
|
+
PopoverTrigger.displayName = TRIGGER_NAME;
|
|
87
|
+
const CONTENT_NAME = "PopoverContent";
|
|
88
|
+
const PopoverContent = React.forwardRef((props, forwardedRef) => {
|
|
89
|
+
const {
|
|
90
|
+
allowPinchZoom,
|
|
91
|
+
trapFocus,
|
|
92
|
+
disableRemoveScroll = true,
|
|
93
|
+
zIndex,
|
|
94
|
+
...contentModalProps
|
|
95
|
+
} = props;
|
|
96
|
+
const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover);
|
|
97
|
+
const contentRef = React.useRef(null);
|
|
98
|
+
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
99
|
+
const isRightClickOutsideRef = React.useRef(false);
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
if (!context.open)
|
|
102
|
+
return;
|
|
103
|
+
const content = contentRef.current;
|
|
104
|
+
if (content)
|
|
105
|
+
return hideOthers(content);
|
|
106
|
+
}, [context.open]);
|
|
107
|
+
return <PopoverContentPortal zIndex={zIndex}><PopoverContentImpl
|
|
108
|
+
{...contentModalProps}
|
|
109
|
+
disableRemoveScroll={disableRemoveScroll}
|
|
110
|
+
ref={composedRefs}
|
|
111
|
+
trapFocus={trapFocus ?? context.open}
|
|
112
|
+
disableOutsidePointerEvents
|
|
113
|
+
onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
if (!isRightClickOutsideRef.current)
|
|
116
|
+
context.triggerRef.current?.focus();
|
|
117
|
+
})}
|
|
118
|
+
onPointerDownOutside={composeEventHandlers(
|
|
119
|
+
props.onPointerDownOutside,
|
|
120
|
+
(event) => {
|
|
121
|
+
const originalEvent = event.detail.originalEvent;
|
|
122
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
123
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
124
|
+
isRightClickOutsideRef.current = isRightClick;
|
|
125
|
+
},
|
|
126
|
+
{ checkDefaultPrevented: false }
|
|
127
|
+
)}
|
|
128
|
+
onFocusOutside={composeEventHandlers(
|
|
129
|
+
props.onFocusOutside,
|
|
130
|
+
(event) => event.preventDefault(),
|
|
131
|
+
{ checkDefaultPrevented: false }
|
|
132
|
+
)}
|
|
133
|
+
/></PopoverContentPortal>;
|
|
134
|
+
});
|
|
135
|
+
function PopoverContentPortal(props) {
|
|
136
|
+
const themeName = useThemeName();
|
|
137
|
+
const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover);
|
|
138
|
+
let contents = props.children;
|
|
139
|
+
if (Platform.OS === "android") {
|
|
140
|
+
const popperContext = usePopperContext(CONTENT_NAME, context.popperScope);
|
|
141
|
+
contents = <PopperProvider {...popperContext} scope={context.popperScope}><PopoverProviderInternal scope={props.__scopePopover} {...context}>{props.children}</PopoverProviderInternal></PopperProvider>;
|
|
142
|
+
}
|
|
143
|
+
const zIndex = props.zIndex ?? 1e3;
|
|
144
|
+
return <Portal zIndex={zIndex}><Theme forceClassName name={themeName}>
|
|
145
|
+
{!!context.open && !context.breakpointActive && <YStack
|
|
146
|
+
fullscreen
|
|
147
|
+
onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}
|
|
148
|
+
/>}
|
|
149
|
+
<Stack zIndex={zIndex + 1}>{contents}</Stack>
|
|
150
|
+
</Theme></Portal>;
|
|
151
|
+
}
|
|
152
|
+
const PopoverContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
153
|
+
const {
|
|
154
|
+
__scopePopover,
|
|
155
|
+
trapFocus,
|
|
156
|
+
onOpenAutoFocus,
|
|
157
|
+
onCloseAutoFocus,
|
|
158
|
+
disableOutsidePointerEvents,
|
|
159
|
+
onEscapeKeyDown,
|
|
160
|
+
onPointerDownOutside,
|
|
161
|
+
onFocusOutside,
|
|
162
|
+
onInteractOutside,
|
|
163
|
+
children,
|
|
164
|
+
disableRemoveScroll,
|
|
165
|
+
...contentProps
|
|
166
|
+
} = props;
|
|
167
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
168
|
+
const context = usePopoverInternalContext(CONTENT_NAME, popperScope.__scopePopover);
|
|
169
|
+
if (context.breakpointActive) {
|
|
170
|
+
const childrenWithoutScrollView = React.Children.toArray(children).map((child) => {
|
|
171
|
+
if (React.isValidElement(child)) {
|
|
172
|
+
if (child.type === PopoverScrollView) {
|
|
173
|
+
return child.props.children;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return child;
|
|
177
|
+
});
|
|
178
|
+
return <PortalItem hostName={`${context.scopeKey}SheetContents`}>{childrenWithoutScrollView}</PortalItem>;
|
|
179
|
+
}
|
|
180
|
+
return <AnimatePresence>{!!context.open && <PopperContent
|
|
181
|
+
key={context.contentId}
|
|
182
|
+
data-state={getState(context.open)}
|
|
183
|
+
id={context.contentId}
|
|
184
|
+
pointerEvents="auto"
|
|
185
|
+
ref={forwardedRef}
|
|
186
|
+
{...popperScope}
|
|
187
|
+
{...contentProps}
|
|
188
|
+
><RemoveScroll
|
|
189
|
+
enabled={disableRemoveScroll ? false : context.open}
|
|
190
|
+
allowPinchZoom
|
|
191
|
+
removeScrollBar={false}
|
|
192
|
+
style={{
|
|
193
|
+
display: "contents"
|
|
194
|
+
}}
|
|
195
|
+
>{trapFocus === false ? children : <FocusScope
|
|
196
|
+
loop
|
|
197
|
+
trapped={trapFocus ?? context.open}
|
|
198
|
+
onMountAutoFocus={onOpenAutoFocus}
|
|
199
|
+
onUnmountAutoFocus={onCloseAutoFocus}
|
|
200
|
+
>{isWeb ? <div style={{ display: "contents" }}>{children}</div> : children}</FocusScope>}</RemoveScroll></PopperContent>}</AnimatePresence>;
|
|
201
|
+
});
|
|
202
|
+
const CLOSE_NAME = "PopoverClose";
|
|
203
|
+
const PopoverClose = React.forwardRef(
|
|
204
|
+
(props, forwardedRef) => {
|
|
205
|
+
const { __scopePopover, ...closeProps } = props;
|
|
206
|
+
const context = usePopoverInternalContext(CLOSE_NAME, __scopePopover);
|
|
207
|
+
return <YStack
|
|
208
|
+
{...closeProps}
|
|
209
|
+
ref={forwardedRef}
|
|
210
|
+
onPress={composeEventHandlers(
|
|
211
|
+
props.onPress,
|
|
212
|
+
() => context.onOpenChange(false)
|
|
213
|
+
)}
|
|
214
|
+
/>;
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
PopoverClose.displayName = CLOSE_NAME;
|
|
218
|
+
const ARROW_NAME = "PopoverArrow";
|
|
219
|
+
const PopoverArrow = React.forwardRef(
|
|
220
|
+
(props, forwardedRef) => {
|
|
221
|
+
const { __scopePopover, ...arrowProps } = props;
|
|
222
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
223
|
+
return <PopperArrow {...popperScope} {...arrowProps} ref={forwardedRef} />;
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
PopoverArrow.displayName = ARROW_NAME;
|
|
227
|
+
const PopoverScrollView = React.forwardRef((props, ref) => {
|
|
228
|
+
return <ScrollView ref={ref} {...props} />;
|
|
229
|
+
});
|
|
230
|
+
const Popover = withStaticProperties(
|
|
231
|
+
(props) => {
|
|
232
|
+
const {
|
|
233
|
+
__scopePopover,
|
|
234
|
+
children,
|
|
235
|
+
open: openProp,
|
|
236
|
+
defaultOpen,
|
|
237
|
+
onOpenChange,
|
|
238
|
+
...restProps
|
|
239
|
+
} = props;
|
|
240
|
+
const internalId = useId();
|
|
241
|
+
const id = __scopePopover ? Object.keys(__scopePopover)[0] : internalId;
|
|
242
|
+
const { when, AdaptProvider } = useAdaptParent({
|
|
243
|
+
Contents: React.useCallback(() => {
|
|
244
|
+
return <PortalHost name={`${id}SheetContents`} />;
|
|
245
|
+
}, [])
|
|
246
|
+
});
|
|
247
|
+
const sheetBreakpoint = when;
|
|
248
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
249
|
+
const triggerRef = React.useRef(null);
|
|
250
|
+
const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
|
|
251
|
+
const [open, setOpen] = useControllableState({
|
|
252
|
+
prop: openProp,
|
|
253
|
+
defaultProp: defaultOpen || false,
|
|
254
|
+
onChange: onOpenChange,
|
|
255
|
+
transition: true
|
|
256
|
+
});
|
|
257
|
+
const breakpointActive = useSheetBreakpointActive(sheetBreakpoint);
|
|
258
|
+
const useFloatingContext = React.useCallback(
|
|
259
|
+
(props2) => {
|
|
260
|
+
const floating = useFloating({
|
|
261
|
+
...props2,
|
|
262
|
+
open,
|
|
263
|
+
onOpenChange: setOpen
|
|
264
|
+
});
|
|
265
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
266
|
+
// useFocus(floating.context, {
|
|
267
|
+
// enabled: !breakpointActive,
|
|
268
|
+
// keyboardOnly: true,
|
|
269
|
+
// }),
|
|
270
|
+
useRole(floating.context, { role: "dialog" }),
|
|
271
|
+
useDismiss(floating.context, {
|
|
272
|
+
enabled: !breakpointActive
|
|
273
|
+
})
|
|
274
|
+
]);
|
|
275
|
+
return {
|
|
276
|
+
...floating,
|
|
277
|
+
getReferenceProps,
|
|
278
|
+
getFloatingProps
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
[breakpointActive, open, setOpen]
|
|
282
|
+
);
|
|
283
|
+
const popoverContext = {
|
|
284
|
+
scope: __scopePopover,
|
|
285
|
+
scopeKey: id,
|
|
286
|
+
popperScope: popperScope.__scopePopper,
|
|
287
|
+
sheetBreakpoint,
|
|
288
|
+
contentId: useId(),
|
|
289
|
+
triggerRef,
|
|
290
|
+
open,
|
|
291
|
+
breakpointActive,
|
|
292
|
+
onOpenChange: setOpen,
|
|
293
|
+
onOpenToggle: useEvent(() => {
|
|
294
|
+
if (open && breakpointActive) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
setOpen(!open);
|
|
298
|
+
}),
|
|
299
|
+
hasCustomAnchor,
|
|
300
|
+
onCustomAnchorAdd: React.useCallback(() => setHasCustomAnchor(true), []),
|
|
301
|
+
onCustomAnchorRemove: React.useCallback(() => setHasCustomAnchor(false), [])
|
|
302
|
+
};
|
|
303
|
+
const contents = <Popper {...popperScope} stayInFrame {...restProps}><PopoverProviderInternal {...popoverContext}><PopoverSheetController onOpenChange={setOpen} __scopePopover={__scopePopover}>{children}</PopoverSheetController></PopoverProviderInternal></Popper>;
|
|
304
|
+
return <AdaptProvider>{isWeb ? <FloatingOverrideContext.Provider value={useFloatingContext}>{contents}</FloatingOverrideContext.Provider> : contents}</AdaptProvider>;
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
Anchor: PopoverAnchor,
|
|
308
|
+
Arrow: PopoverArrow,
|
|
309
|
+
Trigger: PopoverTrigger,
|
|
310
|
+
Content: PopoverContent,
|
|
311
|
+
Close: PopoverClose,
|
|
312
|
+
Adapt,
|
|
313
|
+
ScrollView: PopoverScrollView,
|
|
314
|
+
Sheet: ControlledSheet
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
Popover.displayName = POPOVER_NAME;
|
|
318
|
+
function getState(open) {
|
|
319
|
+
return open ? "open" : "closed";
|
|
320
|
+
}
|
|
321
|
+
const PopoverSheetController = (props) => {
|
|
322
|
+
const context = usePopoverInternalContext(
|
|
323
|
+
"PopoverSheetController",
|
|
324
|
+
props.__scopePopover
|
|
325
|
+
);
|
|
326
|
+
const showSheet = useShowPopoverSheet(context);
|
|
327
|
+
const breakpointActive = context.breakpointActive;
|
|
328
|
+
const getShowSheet = useGet(showSheet);
|
|
329
|
+
return <SheetController
|
|
330
|
+
onOpenChange={(val) => {
|
|
331
|
+
if (getShowSheet()) {
|
|
332
|
+
props.onOpenChange(val);
|
|
333
|
+
}
|
|
334
|
+
}}
|
|
335
|
+
open={context.open}
|
|
336
|
+
hidden={breakpointActive === false}
|
|
337
|
+
>{props.children}</SheetController>;
|
|
338
|
+
};
|
|
339
|
+
const useSheetBreakpointActive = (breakpoint) => {
|
|
340
|
+
const media = useMedia();
|
|
341
|
+
if (typeof breakpoint === "boolean" || !breakpoint) {
|
|
342
|
+
return !!breakpoint;
|
|
343
|
+
}
|
|
344
|
+
return media[breakpoint];
|
|
345
|
+
};
|
|
346
|
+
const useShowPopoverSheet = (context) => {
|
|
347
|
+
const breakpointActive = useSheetBreakpointActive(context.sheetBreakpoint);
|
|
348
|
+
return context.open === false ? false : breakpointActive;
|
|
349
|
+
};
|
|
350
|
+
export {
|
|
351
|
+
Popover,
|
|
352
|
+
PopoverAnchor,
|
|
353
|
+
PopoverArrow,
|
|
354
|
+
PopoverClose,
|
|
355
|
+
PopoverContent,
|
|
356
|
+
PopoverTrigger,
|
|
357
|
+
__PopoverProviderInternal,
|
|
358
|
+
createPopoverScope,
|
|
359
|
+
usePopoverScope
|
|
360
|
+
};
|
|
361
|
+
//# sourceMappingURL=Popover.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Popover.tsx"],
|
|
4
|
+
"sourcesContent": ["// adapted from radix-ui popover\n\nimport '@tamagui/polyfill-dev'\n\nimport type { UseFloatingProps } from '@floating-ui/react-dom-interactions'\nimport {\n useDismiss,\n useFloating,\n useInteractions,\n useRole,\n} from '@floating-ui/react-dom-interactions'\nimport { Adapt, useAdaptParent } from '@tamagui/adapt'\nimport { AnimatePresence } from '@tamagui/animate-presence'\nimport { hideOthers } from '@tamagui/aria-hidden'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GestureReponderEvent,\n MediaQueryKey,\n SizeTokens,\n Stack,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n isWeb,\n useEvent,\n useGet,\n useId,\n useMedia,\n useThemeName,\n withStaticProperties,\n} from '@tamagui/core'\nimport type { Scope } from '@tamagui/create-context'\nimport { createContextScope } from '@tamagui/create-context'\nimport { DismissableProps } from '@tamagui/dismissable'\nimport { FloatingOverrideContext } from '@tamagui/floating'\nimport { FocusScope, FocusScopeProps } from '@tamagui/focus-scope'\nimport {\n Popper,\n PopperAnchor,\n PopperArrow,\n PopperArrowProps,\n PopperContent,\n PopperContentProps,\n PopperProps,\n PopperProvider,\n createPopperScope,\n usePopperContext,\n} from '@tamagui/popper'\nimport { Portal, PortalHost, PortalItem } from '@tamagui/portal'\nimport { RemoveScroll, RemoveScrollProps } from '@tamagui/remove-scroll'\nimport { ControlledSheet, SheetController } from '@tamagui/sheet'\nimport { SizableStack, XStack, YStack, YStackProps, ZStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { useEffect } from 'react'\nimport {\n GestureResponderEvent,\n Platform,\n ScrollView,\n ScrollViewProps,\n View,\n} from 'react-native'\n\nconst POPOVER_NAME = 'Popover'\n\ntype ScopedProps<P> = P & { __scopePopover?: Scope }\n\nexport type PopoverProps = PopperProps & {\n open?: boolean\n defaultOpen?: boolean\n onOpenChange?: (open: boolean) => void\n}\n\ntype PopoverContextValue = {\n triggerRef: React.RefObject<any>\n contentId?: string\n open: boolean\n onOpenChange(open: boolean): void\n onOpenToggle(): void\n hasCustomAnchor: boolean\n onCustomAnchorAdd(): void\n onCustomAnchorRemove(): void\n size?: SizeTokens\n sheetBreakpoint: any\n scopeKey: string\n popperScope: any\n breakpointActive?: boolean\n}\n\nconst [createPopoverContext, createPopoverScopeInternal] = createContextScope(\n POPOVER_NAME,\n [createPopperScope]\n)\nexport const usePopoverScope = createPopperScope()\nexport const createPopoverScope = createPopoverScopeInternal\n\nconst [PopoverProviderInternal, usePopoverInternalContext] =\n createPopoverContext<PopoverContextValue>(POPOVER_NAME)\n\nexport const __PopoverProviderInternal = PopoverProviderInternal\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverAnchor\n * -----------------------------------------------------------------------------------------------*/\n\nconst ANCHOR_NAME = 'PopoverAnchor'\n\ntype PopoverAnchorElement = HTMLElement | View\nexport type PopoverAnchorProps = YStackProps\n\nexport const PopoverAnchor = React.forwardRef<PopoverAnchorElement, PopoverAnchorProps>(\n (props: ScopedProps<PopoverAnchorProps>, forwardedRef) => {\n const { __scopePopover, ...anchorProps } = props\n const context = usePopoverInternalContext(ANCHOR_NAME, __scopePopover)\n const popperScope = usePopoverScope(__scopePopover)\n const { onCustomAnchorAdd, onCustomAnchorRemove } = context\n\n React.useEffect(() => {\n onCustomAnchorAdd()\n return () => onCustomAnchorRemove()\n }, [onCustomAnchorAdd, onCustomAnchorRemove])\n\n return <PopperAnchor {...popperScope} {...anchorProps} ref={forwardedRef} />\n }\n)\n\nPopoverAnchor.displayName = ANCHOR_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'PopoverTrigger'\n\ntype PopoverTriggerElement = HTMLElement | View\nexport type PopoverTriggerProps = YStackProps\n\nexport const PopoverTrigger = React.forwardRef<\n PopoverTriggerElement,\n PopoverTriggerProps\n>((props: ScopedProps<PopoverTriggerProps>, forwardedRef) => {\n const { __scopePopover, ...triggerProps } = props\n const context = usePopoverInternalContext(TRIGGER_NAME, __scopePopover)\n const popperScope = usePopoverScope(__scopePopover)\n const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef)\n\n const trigger = (\n <YStack\n aria-haspopup=\"dialog\"\n aria-expanded={context.open}\n // TODO not matching\n // aria-controls={context.contentId}\n data-state={getState(context.open)}\n {...triggerProps}\n ref={composedTriggerRef}\n onPress={composeEventHandlers(props.onPress as any, context.onOpenToggle)}\n />\n )\n\n return context.hasCustomAnchor ? (\n trigger\n ) : (\n <PopperAnchor asChild {...popperScope}>\n {trigger}\n </PopperAnchor>\n )\n})\n\nPopoverTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'PopoverContent'\n\nexport type PopoverContentProps = PopoverContentTypeProps\n\ntype PopoverContentTypeElement = PopoverContentImplElement\n\nexport interface PopoverContentTypeProps\n extends Omit<PopoverContentImplProps, 'disableOutsidePointerEvents'> {\n /**\n * @see https://github.com/theKashey/react-remove-scroll#usage\n */\n allowPinchZoom?: RemoveScrollProps['allowPinchZoom']\n}\n\nexport const PopoverContent = React.forwardRef<\n PopoverContentTypeElement,\n PopoverContentTypeProps\n>((props: ScopedProps<PopoverContentTypeProps>, forwardedRef) => {\n const {\n allowPinchZoom,\n trapFocus,\n disableRemoveScroll = true,\n zIndex,\n ...contentModalProps\n } = props\n const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover)\n const contentRef = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, contentRef)\n const isRightClickOutsideRef = React.useRef(false)\n\n // aria-hide everything except the content (better supported equivalent to setting aria-modal)\n React.useEffect(() => {\n if (!context.open) return\n const content = contentRef.current\n if (content) return hideOthers(content)\n }, [context.open])\n\n return (\n <PopoverContentPortal zIndex={zIndex}>\n <PopoverContentImpl\n {...contentModalProps}\n disableRemoveScroll={disableRemoveScroll}\n ref={composedRefs}\n // we make sure we're not trapping once it's been closed\n // (closed !== unmounted when animating out)\n trapFocus={trapFocus ?? context.open}\n disableOutsidePointerEvents\n onCloseAutoFocus={composeEventHandlers(props.onCloseAutoFocus, (event) => {\n event.preventDefault()\n if (!isRightClickOutsideRef.current) context.triggerRef.current?.focus()\n })}\n onPointerDownOutside={composeEventHandlers(\n props.onPointerDownOutside,\n (event) => {\n const originalEvent = event.detail.originalEvent\n const ctrlLeftClick =\n originalEvent.button === 0 && originalEvent.ctrlKey === true\n const isRightClick = originalEvent.button === 2 || ctrlLeftClick\n isRightClickOutsideRef.current = isRightClick\n },\n { checkDefaultPrevented: false }\n )}\n // When focus is trapped, a `focusout` event may still happen.\n // We make sure we don't trigger our `onDismiss` in such case.\n onFocusOutside={composeEventHandlers(\n props.onFocusOutside,\n (event) => event.preventDefault(),\n { checkDefaultPrevented: false }\n )}\n />\n </PopoverContentPortal>\n )\n})\n\nfunction PopoverContentPortal(props: ScopedProps<PopoverContentTypeProps>) {\n const themeName = useThemeName()\n const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover)\n\n // on android we have to re-pass context\n let contents = props.children\n\n if (Platform.OS === 'android') {\n // ok conditional hooks by platform\n const popperContext = usePopperContext(CONTENT_NAME, context.popperScope)\n\n contents = (\n <PopperProvider {...popperContext} scope={context.popperScope}>\n <PopoverProviderInternal scope={props.__scopePopover} {...context}>\n {/* does this need to be props.__scopePopper? */}\n {props.children}\n </PopoverProviderInternal>\n </PopperProvider>\n )\n }\n\n const zIndex = props.zIndex ?? 1000\n\n // Portal the contents and add a transparent bg overlay to handle dismiss on native\n return (\n <Portal zIndex={zIndex}>\n <Theme forceClassName name={themeName}>\n {!!context.open && !context.breakpointActive && (\n <YStack\n fullscreen\n onPress={composeEventHandlers(props.onPress as any, context.onOpenToggle)}\n />\n )}\n <Stack zIndex={(zIndex as number) + 1}>{contents}</Stack>\n </Theme>\n </Portal>\n )\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PopoverContentImplElement = React.ElementRef<typeof PopperContent>\n\nexport interface PopoverContentImplProps\n extends PopperContentProps,\n Omit<DismissableProps, 'onDismiss' | 'children'> {\n /**\n * Whether focus should be trapped within the `Popover`\n * (default: false)\n */\n trapFocus?: FocusScopeProps['trapped']\n\n /**\n * Event handler called when auto-focusing on open.\n * Can be prevented.\n */\n onOpenAutoFocus?: FocusScopeProps['onMountAutoFocus']\n\n /**\n * Event handler called when auto-focusing on close.\n * Can be prevented.\n */\n onCloseAutoFocus?: FocusScopeProps['onUnmountAutoFocus']\n\n disableRemoveScroll?: boolean\n}\n\nconst PopoverContentImpl = React.forwardRef<\n PopoverContentImplElement,\n PopoverContentImplProps\n>((props: ScopedProps<PopoverContentImplProps>, forwardedRef) => {\n const {\n __scopePopover,\n trapFocus,\n onOpenAutoFocus,\n onCloseAutoFocus,\n disableOutsidePointerEvents,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n children,\n disableRemoveScroll,\n ...contentProps\n } = props\n const popperScope = usePopoverScope(__scopePopover)\n const context = usePopoverInternalContext(CONTENT_NAME, popperScope.__scopePopover)\n\n if (context.breakpointActive) {\n // unwrap the PopoverScrollView if used, as it will use the SheetScrollView if that exists\n const childrenWithoutScrollView = React.Children.toArray(children).map((child) => {\n if (React.isValidElement(child)) {\n if (child.type === PopoverScrollView) {\n return child.props.children\n }\n }\n return child\n })\n\n // doesn't show as popover yet on native, must use as sheet\n return (\n <PortalItem hostName={`${context.scopeKey}SheetContents`}>\n {childrenWithoutScrollView}\n </PortalItem>\n )\n }\n\n // const handleDismiss = React.useCallback((event: GestureResponderEvent) =>{\n // context.onOpenChange(false);\n // }, [])\n // <Dismissable\n // disableOutsidePointerEvents={disableOutsidePointerEvents}\n // // onInteractOutside={onInteractOutside}\n // onEscapeKeyDown={onEscapeKeyDown}\n // // onPointerDownOutside={onPointerDownOutside}\n // // onFocusOutside={onFocusOutside}\n // onDismiss={handleDismiss}\n // >\n\n return (\n <AnimatePresence>\n {!!context.open && (\n <PopperContent\n key={context.contentId}\n data-state={getState(context.open)}\n id={context.contentId}\n pointerEvents=\"auto\"\n ref={forwardedRef}\n {...popperScope}\n {...contentProps}\n >\n <RemoveScroll\n enabled={disableRemoveScroll ? false : context.open}\n allowPinchZoom\n // causes lots of bugs on touch web on site\n removeScrollBar={false}\n style={{\n display: 'contents',\n }}\n >\n {trapFocus === false ? (\n children\n ) : (\n <FocusScope\n loop\n trapped={trapFocus ?? context.open}\n onMountAutoFocus={onOpenAutoFocus}\n onUnmountAutoFocus={onCloseAutoFocus}\n >\n {isWeb ? <div style={{ display: 'contents' }}>{children}</div> : children}\n </FocusScope>\n )}\n </RemoveScroll>\n </PopperContent>\n )}\n </AnimatePresence>\n )\n})\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'PopoverClose'\n\ntype PopoverCloseElement = HTMLElement | View\nexport type PopoverCloseProps = YStackProps\n\nexport const PopoverClose = React.forwardRef<PopoverCloseElement, PopoverCloseProps>(\n (props: ScopedProps<PopoverCloseProps>, forwardedRef) => {\n const { __scopePopover, ...closeProps } = props\n const context = usePopoverInternalContext(CLOSE_NAME, __scopePopover)\n return (\n <YStack\n {...closeProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, () =>\n context.onOpenChange(false)\n )}\n />\n )\n }\n)\n\nPopoverClose.displayName = CLOSE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'PopoverArrow'\n\ntype PopoverArrowElement = HTMLElement | View\nexport type PopoverArrowProps = PopperArrowProps\n\nexport const PopoverArrow = React.forwardRef<PopoverArrowElement, PopoverArrowProps>(\n (props: ScopedProps<PopoverArrowProps>, forwardedRef) => {\n const { __scopePopover, ...arrowProps } = props\n const popperScope = usePopoverScope(__scopePopover)\n return <PopperArrow {...popperScope} {...arrowProps} ref={forwardedRef} />\n }\n)\n\nPopoverArrow.displayName = ARROW_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * PopoverScrollView\n * -----------------------------------------------------------------------------------------------*/\n\nconst PopoverScrollView = React.forwardRef<ScrollView, ScrollViewProps>((props, ref) => {\n return <ScrollView ref={ref} {...props} />\n})\n\n/* -------------------------------------------------------------------------------------------------\n * Popover\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Popover = withStaticProperties(\n ((props: ScopedProps<PopoverProps>) => {\n const {\n __scopePopover,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n ...restProps\n } = props\n\n const internalId = useId()\n const id = __scopePopover ? Object.keys(__scopePopover)[0] : internalId\n\n const { when, AdaptProvider } = useAdaptParent({\n Contents: React.useCallback(() => {\n return <PortalHost name={`${id}SheetContents`} />\n }, []),\n })\n\n const sheetBreakpoint = when\n const popperScope = usePopoverScope(__scopePopover)\n const triggerRef = React.useRef<TamaguiElement>(null)\n const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false)\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen || false,\n onChange: onOpenChange,\n transition: true,\n })\n\n const breakpointActive = useSheetBreakpointActive(sheetBreakpoint)\n\n // Custom floating context to override the Popper on web\n const useFloatingContext = React.useCallback(\n (props: UseFloatingProps) => {\n const floating = useFloating({\n ...props,\n open,\n onOpenChange: setOpen,\n })\n const { getReferenceProps, getFloatingProps } = useInteractions([\n // useFocus(floating.context, {\n // enabled: !breakpointActive,\n // keyboardOnly: true,\n // }),\n useRole(floating.context, { role: 'dialog' }),\n useDismiss(floating.context, {\n enabled: !breakpointActive,\n }),\n ])\n return {\n ...floating,\n getReferenceProps,\n getFloatingProps,\n }\n },\n [breakpointActive, open, setOpen]\n )\n\n const popoverContext = {\n scope: __scopePopover,\n scopeKey: id,\n popperScope: popperScope.__scopePopper,\n sheetBreakpoint,\n contentId: useId(),\n triggerRef,\n open,\n breakpointActive,\n onOpenChange: setOpen,\n onOpenToggle: useEvent(() => {\n if (open && breakpointActive) {\n return\n }\n setOpen(!open)\n }),\n hasCustomAnchor,\n onCustomAnchorAdd: React.useCallback(() => setHasCustomAnchor(true), []),\n onCustomAnchorRemove: React.useCallback(() => setHasCustomAnchor(false), []),\n }\n\n // debug if changing too often\n // if (process.env.NODE_ENV === 'development') {\n // Object.keys(popoverContext).forEach((key) => {\n // React.useEffect(() => console.log(`changed`, key), [popoverContext[key]])\n // })\n // }\n\n const contents = (\n <Popper {...popperScope} stayInFrame {...restProps}>\n <PopoverProviderInternal {...popoverContext}>\n <PopoverSheetController onOpenChange={setOpen} __scopePopover={__scopePopover}>\n {children}\n </PopoverSheetController>\n </PopoverProviderInternal>\n </Popper>\n )\n\n return (\n <AdaptProvider>\n {isWeb ? (\n <FloatingOverrideContext.Provider value={useFloatingContext as any}>\n {contents}\n </FloatingOverrideContext.Provider>\n ) : (\n contents\n )}\n </AdaptProvider>\n )\n }) as React.FC<PopoverProps>,\n {\n Anchor: PopoverAnchor,\n Arrow: PopoverArrow,\n Trigger: PopoverTrigger,\n Content: PopoverContent,\n Close: PopoverClose,\n Adapt,\n ScrollView: PopoverScrollView,\n Sheet: ControlledSheet,\n }\n)\n\nPopover.displayName = POPOVER_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getState(open: boolean) {\n return open ? 'open' : 'closed'\n}\n\nconst PopoverSheetController = (\n props: ScopedProps<{\n children: React.ReactNode\n onOpenChange: React.Dispatch<React.SetStateAction<boolean>>\n }>\n) => {\n const context = usePopoverInternalContext(\n 'PopoverSheetController',\n props.__scopePopover\n )\n const showSheet = useShowPopoverSheet(context)\n const breakpointActive = context.breakpointActive\n const getShowSheet = useGet(showSheet)\n return (\n <SheetController\n onOpenChange={(val) => {\n if (getShowSheet()) {\n props.onOpenChange(val)\n }\n }}\n open={context.open}\n hidden={breakpointActive === false}\n >\n {props.children}\n </SheetController>\n )\n}\n\nconst useSheetBreakpointActive = (breakpoint?: MediaQueryKey | null | boolean) => {\n const media = useMedia()\n if (typeof breakpoint === 'boolean' || !breakpoint) {\n return !!breakpoint\n }\n return media[breakpoint]\n}\n\nconst useShowPopoverSheet = (context: PopoverContextValue) => {\n const breakpointActive = useSheetBreakpointActive(context.sheetBreakpoint)\n return context.open === false ? false : breakpointActive\n}\n"],
|
|
5
|
+
"mappings": "AAEA,OAAO;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,OAAO,sBAAsB;AACtC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC;AAAA,EAIE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AAEnC,SAAS,+BAA+B;AACxC,SAAS,kBAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,QAAQ,YAAY,kBAAkB;AAC/C,SAAS,oBAAuC;AAChD,SAAS,iBAAiB,uBAAuB;AACjD,SAA+B,cAAmC;AAClE,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAEvB;AAAA,EAEE;AAAA,EACA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;AAClB,cAAM,aAAa,GAAG;AAAA,MACxB;AAAA,IACF;AAAA,IACA,MAAM,QAAQ;AAAA,IACd,QAAQ,qBAAqB;AAAA,IAE5B,MAAM,SACT,EAVC;AAYL;AAEA,MAAM,2BAA2B,CAAC,eAAgD;AAChF,QAAM,QAAQ,SAAS;AACvB,MAAI,OAAO,eAAe,aAAa,CAAC,YAAY;AAClD,WAAO,CAAC,CAAC;AAAA,EACX;AACA,SAAO,MAAM,UAAU;AACzB;AAEA,MAAM,sBAAsB,CAAC,YAAiC;AAC5D,QAAM,mBAAmB,yBAAyB,QAAQ,eAAe;AACzE,SAAO,QAAQ,SAAS,QAAQ,QAAQ;AAC1C;",
|
|
6
|
+
"names": ["props"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/popover",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@floating-ui/react-dom-interactions": "0.8.1",
|
|
27
|
-
"@tamagui/adapt": "^1.2.
|
|
28
|
-
"@tamagui/animate-presence": "^1.2.
|
|
29
|
-
"@tamagui/aria-hidden": "^1.2.
|
|
30
|
-
"@tamagui/compose-refs": "^1.2.
|
|
31
|
-
"@tamagui/core": "^1.2.
|
|
32
|
-
"@tamagui/create-context": "^1.2.
|
|
33
|
-
"@tamagui/dismissable": "^1.2.
|
|
34
|
-
"@tamagui/focus-scope": "^1.2.
|
|
35
|
-
"@tamagui/polyfill-dev": "^1.2.
|
|
36
|
-
"@tamagui/popper": "^1.2.
|
|
37
|
-
"@tamagui/portal": "^1.2.
|
|
38
|
-
"@tamagui/scroll-view": "^1.2.
|
|
39
|
-
"@tamagui/sheet": "^1.2.
|
|
40
|
-
"@tamagui/stacks": "^1.2.
|
|
41
|
-
"@tamagui/use-controllable-state": "^1.2.
|
|
27
|
+
"@tamagui/adapt": "^1.2.10",
|
|
28
|
+
"@tamagui/animate-presence": "^1.2.10",
|
|
29
|
+
"@tamagui/aria-hidden": "^1.2.10",
|
|
30
|
+
"@tamagui/compose-refs": "^1.2.10",
|
|
31
|
+
"@tamagui/core": "^1.2.10",
|
|
32
|
+
"@tamagui/create-context": "^1.2.10",
|
|
33
|
+
"@tamagui/dismissable": "^1.2.10",
|
|
34
|
+
"@tamagui/focus-scope": "^1.2.10",
|
|
35
|
+
"@tamagui/polyfill-dev": "^1.2.10",
|
|
36
|
+
"@tamagui/popper": "^1.2.10",
|
|
37
|
+
"@tamagui/portal": "^1.2.10",
|
|
38
|
+
"@tamagui/scroll-view": "^1.2.10",
|
|
39
|
+
"@tamagui/sheet": "^1.2.10",
|
|
40
|
+
"@tamagui/stacks": "^1.2.10",
|
|
41
|
+
"@tamagui/use-controllable-state": "^1.2.10"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": "*",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-native": "*"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "^1.2.
|
|
49
|
+
"@tamagui/build": "^1.2.10",
|
|
50
50
|
"@types/react-dom": "^18.0.3",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-dom": "^18.2.0",
|