@tamagui/popover 1.0.1-beta.21 → 1.0.1-beta.211
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/Popover.js +312 -236
- package/dist/cjs/Popover.js.map +3 -3
- package/dist/cjs/floating.js +37 -0
- package/dist/cjs/floating.js.map +7 -0
- package/dist/cjs/floating.native.js +59 -0
- package/dist/cjs/floating.native.js.map +7 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Popover.js +318 -216
- package/dist/esm/Popover.js.map +3 -3
- package/dist/esm/floating.js +15 -0
- package/dist/esm/floating.js.map +7 -0
- package/dist/esm/floating.native.js +31 -0
- package/dist/esm/floating.native.js.map +7 -0
- package/dist/esm/index.js +0 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Popover.js +216 -149
- package/dist/jsx/Popover.js.map +7 -0
- package/dist/jsx/floating.js +15 -0
- package/dist/jsx/floating.js.map +7 -0
- package/dist/jsx/floating.native.js +31 -0
- package/dist/jsx/floating.native.js.map +7 -0
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +7 -0
- package/package.json +25 -15
- package/src/Popover.tsx +544 -0
- package/src/floating.native.ts +18 -0
- package/src/floating.ts +8 -0
- package/src/index.tsx +1 -0
- package/types/Popover.d.ts +177 -103
- package/types/floating.d.ts +2 -0
- package/types/floating.native.d.ts +15 -0
- package/types/Popover.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
package/dist/esm/Popover.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
2
|
import "@tamagui/polyfill-dev";
|
|
4
|
-
import {
|
|
5
|
-
useDismiss,
|
|
6
|
-
useFloating,
|
|
7
|
-
useFocus,
|
|
8
|
-
useInteractions,
|
|
9
|
-
useRole
|
|
10
|
-
} from "@floating-ui/react-dom-interactions";
|
|
11
3
|
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
4
|
+
import { hideOthers } from "@tamagui/aria-hidden";
|
|
12
5
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
13
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
Theme,
|
|
8
|
+
composeEventHandlers,
|
|
9
|
+
isWeb,
|
|
10
|
+
useEvent,
|
|
11
|
+
useGet,
|
|
12
|
+
useId,
|
|
13
|
+
useMedia,
|
|
14
|
+
useThemeName,
|
|
15
|
+
withStaticProperties
|
|
16
|
+
} from "@tamagui/core";
|
|
14
17
|
import { createContextScope } from "@tamagui/create-context";
|
|
18
|
+
import { FocusScope } from "@tamagui/focus-scope";
|
|
15
19
|
import {
|
|
16
20
|
FloatingOverrideContext,
|
|
17
21
|
Popper,
|
|
@@ -20,10 +24,14 @@ import {
|
|
|
20
24
|
PopperContent,
|
|
21
25
|
createPopperScope
|
|
22
26
|
} from "@tamagui/popper";
|
|
23
|
-
import { Portal } from "@tamagui/portal";
|
|
27
|
+
import { Portal, PortalHost, PortalItem } from "@tamagui/portal";
|
|
28
|
+
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
29
|
+
import { ControlledSheet, SheetController } from "@tamagui/sheet";
|
|
24
30
|
import { YStack } from "@tamagui/stacks";
|
|
25
31
|
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
26
32
|
import * as React from "react";
|
|
33
|
+
import { ScrollView } from "react-native";
|
|
34
|
+
import { useDismiss, useFloating, useFocus, useInteractions, useRole } from "./floating";
|
|
27
35
|
const POPOVER_NAME = "Popover";
|
|
28
36
|
const [createPopoverContext, createPopoverScopeInternal] = createContextScope(POPOVER_NAME, [
|
|
29
37
|
createPopperScope
|
|
@@ -33,232 +41,326 @@ const createPopoverScope = createPopoverScopeInternal;
|
|
|
33
41
|
const [PopoverProviderInternal, usePopoverInternalContext] = createPopoverContext(POPOVER_NAME);
|
|
34
42
|
const __PopoverProviderInternal = PopoverProviderInternal;
|
|
35
43
|
const ANCHOR_NAME = "PopoverAnchor";
|
|
36
|
-
const PopoverAnchor = React.forwardRef(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
44
|
+
const PopoverAnchor = React.forwardRef(
|
|
45
|
+
(props, forwardedRef) => {
|
|
46
|
+
const { __scopePopover, ...anchorProps } = props;
|
|
47
|
+
const context = usePopoverInternalContext(ANCHOR_NAME, __scopePopover);
|
|
48
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
49
|
+
const { onCustomAnchorAdd, onCustomAnchorRemove } = context;
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
onCustomAnchorAdd();
|
|
52
|
+
return () => onCustomAnchorRemove();
|
|
53
|
+
}, [onCustomAnchorAdd, onCustomAnchorRemove]);
|
|
54
|
+
return /* @__PURE__ */ jsx(PopperAnchor, {
|
|
55
|
+
...popperScope,
|
|
56
|
+
...anchorProps,
|
|
57
|
+
ref: forwardedRef
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
);
|
|
51
61
|
PopoverAnchor.displayName = ANCHOR_NAME;
|
|
52
62
|
const TRIGGER_NAME = "PopoverTrigger";
|
|
53
|
-
const PopoverTrigger = React.forwardRef(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
63
|
+
const PopoverTrigger = React.forwardRef(
|
|
64
|
+
(props, forwardedRef) => {
|
|
65
|
+
const { __scopePopover, ...triggerProps } = props;
|
|
66
|
+
const context = usePopoverInternalContext(TRIGGER_NAME, __scopePopover);
|
|
67
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
68
|
+
const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
69
|
+
const trigger = /* @__PURE__ */ jsx(YStack, {
|
|
70
|
+
"aria-haspopup": "dialog",
|
|
71
|
+
"aria-expanded": context.open,
|
|
72
|
+
"data-state": getState(context.open),
|
|
73
|
+
...triggerProps,
|
|
74
|
+
ref: composedTriggerRef,
|
|
75
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
76
|
+
});
|
|
77
|
+
return context.hasCustomAnchor ? trigger : /* @__PURE__ */ jsx(PopperAnchor, {
|
|
78
|
+
asChild: true,
|
|
79
|
+
...popperScope,
|
|
80
|
+
children: trigger
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
);
|
|
72
84
|
PopoverTrigger.displayName = TRIGGER_NAME;
|
|
73
85
|
const CONTENT_NAME = "PopoverContent";
|
|
74
|
-
const PopoverContent = React.forwardRef(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
86
|
+
const PopoverContent = React.forwardRef(
|
|
87
|
+
(props, forwardedRef) => {
|
|
88
|
+
const { allowPinchZoom, trapFocus, disableRemoveScroll = true, ...contentModalProps } = props;
|
|
89
|
+
const context = usePopoverInternalContext(CONTENT_NAME, props.__scopePopover);
|
|
90
|
+
const contentRef = React.useRef(null);
|
|
91
|
+
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
92
|
+
const isRightClickOutsideRef = React.useRef(false);
|
|
93
|
+
const themeName = useThemeName();
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
if (!context.open)
|
|
96
|
+
return;
|
|
97
|
+
const content = contentRef.current;
|
|
98
|
+
if (content)
|
|
99
|
+
return hideOthers(content);
|
|
100
|
+
}, [context.open]);
|
|
101
|
+
return /* @__PURE__ */ jsx(Portal, {
|
|
102
|
+
zIndex: props.zIndex ?? 1e3,
|
|
103
|
+
children: /* @__PURE__ */ jsx(Theme, {
|
|
104
|
+
name: themeName,
|
|
105
|
+
children: /* @__PURE__ */ jsx(PopoverContentImpl, {
|
|
106
|
+
...contentModalProps,
|
|
107
|
+
disableRemoveScroll,
|
|
108
|
+
ref: composedRefs,
|
|
109
|
+
trapFocus: trapFocus ?? context.open,
|
|
110
|
+
disableOutsidePointerEvents: true,
|
|
111
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
|
|
112
|
+
var _a;
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
if (!isRightClickOutsideRef.current)
|
|
115
|
+
(_a = context.triggerRef.current) == null ? void 0 : _a.focus();
|
|
116
|
+
}),
|
|
117
|
+
onPointerDownOutside: composeEventHandlers(
|
|
118
|
+
props.onPointerDownOutside,
|
|
119
|
+
(event) => {
|
|
120
|
+
const originalEvent = event.detail.originalEvent;
|
|
121
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
122
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
123
|
+
isRightClickOutsideRef.current = isRightClick;
|
|
124
|
+
},
|
|
125
|
+
{ checkDefaultPrevented: false }
|
|
126
|
+
),
|
|
127
|
+
onFocusOutside: composeEventHandlers(
|
|
128
|
+
props.onFocusOutside,
|
|
129
|
+
(event) => event.preventDefault(),
|
|
130
|
+
{ checkDefaultPrevented: false }
|
|
131
|
+
)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
const PopoverContentImpl = React.forwardRef(
|
|
138
|
+
(props, forwardedRef) => {
|
|
139
|
+
const {
|
|
140
|
+
__scopePopover,
|
|
141
|
+
trapFocus,
|
|
142
|
+
onOpenAutoFocus,
|
|
143
|
+
onCloseAutoFocus,
|
|
144
|
+
disableOutsidePointerEvents,
|
|
145
|
+
onEscapeKeyDown,
|
|
146
|
+
onPointerDownOutside,
|
|
147
|
+
onFocusOutside,
|
|
148
|
+
onInteractOutside,
|
|
149
|
+
children,
|
|
150
|
+
disableRemoveScroll,
|
|
151
|
+
...contentProps
|
|
152
|
+
} = props;
|
|
153
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
154
|
+
const context = usePopoverInternalContext(CONTENT_NAME, popperScope.__scopePopover);
|
|
155
|
+
const showSheet = useShowPopoverSheet(context);
|
|
156
|
+
if (showSheet) {
|
|
157
|
+
const childrenWithoutScrollView = React.Children.toArray(children).map((child) => {
|
|
158
|
+
if (React.isValidElement(child)) {
|
|
159
|
+
if (child.type === PopoverScrollView) {
|
|
160
|
+
return child.props.children;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return child;
|
|
164
|
+
});
|
|
165
|
+
return /* @__PURE__ */ jsx(PortalItem, {
|
|
166
|
+
hostName: `${context.scopeKey}SheetContents`,
|
|
167
|
+
children: childrenWithoutScrollView
|
|
168
|
+
});
|
|
142
169
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
})
|
|
170
|
+
return /* @__PURE__ */ jsx(AnimatePresence, {
|
|
171
|
+
children: !!context.open && /* @__PURE__ */ jsx(PopperContent, {
|
|
172
|
+
"data-state": getState(context.open),
|
|
173
|
+
id: context.contentId,
|
|
174
|
+
pointerEvents: "auto",
|
|
175
|
+
...popperScope,
|
|
176
|
+
...contentProps,
|
|
177
|
+
ref: forwardedRef,
|
|
178
|
+
children: /* @__PURE__ */ jsx(RemoveScroll, {
|
|
179
|
+
enabled: disableRemoveScroll ? false : context.open,
|
|
180
|
+
allowPinchZoom: true,
|
|
181
|
+
removeScrollBar: false,
|
|
182
|
+
style: {
|
|
183
|
+
display: "contents"
|
|
184
|
+
},
|
|
185
|
+
children: trapFocus === false ? children : /* @__PURE__ */ jsx(FocusScope, {
|
|
186
|
+
loop: true,
|
|
187
|
+
trapped: trapFocus ?? context.open,
|
|
188
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
189
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
190
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
191
|
+
style: { display: "contents" },
|
|
192
|
+
children
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
}, "popper-content")
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
);
|
|
169
200
|
const CLOSE_NAME = "PopoverClose";
|
|
170
|
-
const PopoverClose = React.forwardRef(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
201
|
+
const PopoverClose = React.forwardRef(
|
|
202
|
+
(props, forwardedRef) => {
|
|
203
|
+
const { __scopePopover, ...closeProps } = props;
|
|
204
|
+
const context = usePopoverInternalContext(CLOSE_NAME, __scopePopover);
|
|
205
|
+
return /* @__PURE__ */ jsx(YStack, {
|
|
206
|
+
...closeProps,
|
|
207
|
+
ref: forwardedRef,
|
|
208
|
+
onPress: composeEventHandlers(props.onPress, () => context.onOpenChange(false))
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
);
|
|
179
212
|
PopoverClose.displayName = CLOSE_NAME;
|
|
180
213
|
const ARROW_NAME = "PopoverArrow";
|
|
181
|
-
const PopoverArrow = React.forwardRef(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
214
|
+
const PopoverArrow = React.forwardRef(
|
|
215
|
+
(props, forwardedRef) => {
|
|
216
|
+
const { __scopePopover, ...arrowProps } = props;
|
|
217
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
218
|
+
return /* @__PURE__ */ jsx(PopperArrow, {
|
|
219
|
+
...popperScope,
|
|
220
|
+
...arrowProps,
|
|
221
|
+
ref: forwardedRef
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
);
|
|
190
225
|
PopoverArrow.displayName = ARROW_NAME;
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
|
|
204
|
-
const [open, setOpen] = useControllableState({
|
|
205
|
-
prop: openProp,
|
|
206
|
-
defaultProp: defaultOpen || false,
|
|
207
|
-
onChange: onOpenChange
|
|
226
|
+
const SHEET_CONTENTS_NAME = "PopoverSheetContents";
|
|
227
|
+
const PopoverSheetContents = ({ __scopePopover }) => {
|
|
228
|
+
const context = usePopoverInternalContext(SHEET_CONTENTS_NAME, __scopePopover);
|
|
229
|
+
return /* @__PURE__ */ jsx(PortalHost, {
|
|
230
|
+
name: `${context.scopeKey}SheetContents`
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
PopoverSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
234
|
+
const PopoverScrollView = React.forwardRef((props, ref) => {
|
|
235
|
+
return /* @__PURE__ */ jsx(ScrollView, {
|
|
236
|
+
ref,
|
|
237
|
+
...props
|
|
208
238
|
});
|
|
209
|
-
const useFloatingFn = /* @__PURE__ */ __name((props2) => {
|
|
210
|
-
const floating = useFloating({
|
|
211
|
-
...props2,
|
|
212
|
-
open,
|
|
213
|
-
onOpenChange: setOpen
|
|
214
|
-
});
|
|
215
|
-
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
216
|
-
useFocus(floating.context),
|
|
217
|
-
useRole(floating.context, { role: "dialog" }),
|
|
218
|
-
useDismiss(floating.context)
|
|
219
|
-
]);
|
|
220
|
-
return {
|
|
221
|
-
...floating,
|
|
222
|
-
getReferenceProps,
|
|
223
|
-
getFloatingProps
|
|
224
|
-
};
|
|
225
|
-
}, "useFloatingFn");
|
|
226
|
-
const useFloatingContext = React.useCallback(useFloatingFn, [open]);
|
|
227
|
-
return /* @__PURE__ */ React.createElement(FloatingOverrideContext.Provider, {
|
|
228
|
-
value: useFloatingContext
|
|
229
|
-
}, /* @__PURE__ */ React.createElement(Popper, {
|
|
230
|
-
...popperScope,
|
|
231
|
-
...restProps
|
|
232
|
-
}, /* @__PURE__ */ React.createElement(PopoverProviderInternal, {
|
|
233
|
-
scope: __scopePopover,
|
|
234
|
-
contentId: useId(),
|
|
235
|
-
triggerRef,
|
|
236
|
-
open,
|
|
237
|
-
onOpenChange: setOpen,
|
|
238
|
-
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
239
|
-
hasCustomAnchor,
|
|
240
|
-
onCustomAnchorAdd: React.useCallback(() => setHasCustomAnchor(true), []),
|
|
241
|
-
onCustomAnchorRemove: React.useCallback(() => setHasCustomAnchor(false), []),
|
|
242
|
-
modal
|
|
243
|
-
}, children)));
|
|
244
|
-
}, {
|
|
245
|
-
Anchor: PopoverAnchor,
|
|
246
|
-
Arrow: PopoverArrow,
|
|
247
|
-
Trigger: PopoverTrigger,
|
|
248
|
-
Content: PopoverContent,
|
|
249
|
-
Close: PopoverClose
|
|
250
239
|
});
|
|
240
|
+
const Popover = withStaticProperties(
|
|
241
|
+
(props) => {
|
|
242
|
+
const {
|
|
243
|
+
__scopePopover,
|
|
244
|
+
children,
|
|
245
|
+
open: openProp,
|
|
246
|
+
defaultOpen,
|
|
247
|
+
onOpenChange,
|
|
248
|
+
sheetBreakpoint = false,
|
|
249
|
+
...restProps
|
|
250
|
+
} = props;
|
|
251
|
+
const popperScope = usePopoverScope(__scopePopover);
|
|
252
|
+
const triggerRef = React.useRef(null);
|
|
253
|
+
const [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
|
|
254
|
+
const [open, setOpen] = useControllableState({
|
|
255
|
+
prop: openProp,
|
|
256
|
+
defaultProp: defaultOpen || false,
|
|
257
|
+
onChange: onOpenChange
|
|
258
|
+
});
|
|
259
|
+
const breakpointActive = useSheetBreakpointActive(sheetBreakpoint);
|
|
260
|
+
const useFloatingContext = React.useCallback(
|
|
261
|
+
(props2) => {
|
|
262
|
+
const floating = useFloating({
|
|
263
|
+
...props2,
|
|
264
|
+
open,
|
|
265
|
+
onOpenChange: setOpen
|
|
266
|
+
});
|
|
267
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
268
|
+
useFocus(floating.context, {
|
|
269
|
+
enabled: !breakpointActive
|
|
270
|
+
}),
|
|
271
|
+
useRole(floating.context, { role: "dialog" }),
|
|
272
|
+
useDismiss(floating.context, {
|
|
273
|
+
enabled: !breakpointActive
|
|
274
|
+
})
|
|
275
|
+
]);
|
|
276
|
+
return {
|
|
277
|
+
...floating,
|
|
278
|
+
getReferenceProps,
|
|
279
|
+
getFloatingProps
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
[breakpointActive, open, setOpen]
|
|
283
|
+
);
|
|
284
|
+
return /* @__PURE__ */ jsx(FloatingOverrideContext.Provider, {
|
|
285
|
+
value: useFloatingContext,
|
|
286
|
+
children: /* @__PURE__ */ jsx(Popper, {
|
|
287
|
+
...popperScope,
|
|
288
|
+
stayInFrame: true,
|
|
289
|
+
...restProps,
|
|
290
|
+
children: /* @__PURE__ */ jsx(PopoverProviderInternal, {
|
|
291
|
+
scope: __scopePopover,
|
|
292
|
+
scopeKey: __scopePopover ? Object.keys(__scopePopover)[0] : "",
|
|
293
|
+
sheetBreakpoint,
|
|
294
|
+
contentId: useId(),
|
|
295
|
+
triggerRef,
|
|
296
|
+
open,
|
|
297
|
+
onOpenChange: setOpen,
|
|
298
|
+
onOpenToggle: useEvent(() => {
|
|
299
|
+
if (open && breakpointActive) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
setOpen(!open);
|
|
303
|
+
}),
|
|
304
|
+
hasCustomAnchor,
|
|
305
|
+
onCustomAnchorAdd: React.useCallback(() => setHasCustomAnchor(true), []),
|
|
306
|
+
onCustomAnchorRemove: React.useCallback(() => setHasCustomAnchor(false), []),
|
|
307
|
+
children: /* @__PURE__ */ jsx(PopoverSheetController, {
|
|
308
|
+
onOpenChange: setOpen,
|
|
309
|
+
__scopePopover,
|
|
310
|
+
children
|
|
311
|
+
})
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
Anchor: PopoverAnchor,
|
|
318
|
+
Arrow: PopoverArrow,
|
|
319
|
+
Trigger: PopoverTrigger,
|
|
320
|
+
Content: PopoverContent,
|
|
321
|
+
Close: PopoverClose,
|
|
322
|
+
SheetContents: PopoverSheetContents,
|
|
323
|
+
ScrollView: PopoverScrollView,
|
|
324
|
+
Sheet: ControlledSheet
|
|
325
|
+
}
|
|
326
|
+
);
|
|
251
327
|
Popover.displayName = POPOVER_NAME;
|
|
252
328
|
function getState(open) {
|
|
253
329
|
return open ? "open" : "closed";
|
|
254
330
|
}
|
|
255
|
-
|
|
331
|
+
const PopoverSheetController = (props) => {
|
|
332
|
+
const context = usePopoverInternalContext("PopoverSheetController", props.__scopePopover);
|
|
333
|
+
const showSheet = useShowPopoverSheet(context);
|
|
334
|
+
const breakpointActive = useSheetBreakpointActive(context.sheetBreakpoint);
|
|
335
|
+
const getShowSheet = useGet(showSheet);
|
|
336
|
+
return /* @__PURE__ */ jsx(SheetController, {
|
|
337
|
+
onOpenChange: (val) => {
|
|
338
|
+
if (getShowSheet()) {
|
|
339
|
+
props.onOpenChange(val);
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
open: context.open,
|
|
343
|
+
hidden: breakpointActive === false,
|
|
344
|
+
children: props.children
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
const useSheetBreakpointActive = (breakpoint) => {
|
|
348
|
+
const media = useMedia();
|
|
349
|
+
return breakpoint ? media[breakpoint] : false;
|
|
350
|
+
};
|
|
351
|
+
const useShowPopoverSheet = (context) => {
|
|
352
|
+
if (!isWeb)
|
|
353
|
+
return true;
|
|
354
|
+
const breakpointActive = useSheetBreakpointActive(context.sheetBreakpoint);
|
|
355
|
+
return context.open === false ? false : breakpointActive;
|
|
356
|
+
};
|
|
256
357
|
export {
|
|
257
358
|
Popover,
|
|
258
359
|
PopoverAnchor,
|
|
259
360
|
PopoverArrow,
|
|
260
361
|
PopoverClose,
|
|
261
362
|
PopoverContent,
|
|
363
|
+
PopoverSheetContents,
|
|
262
364
|
PopoverTrigger,
|
|
263
365
|
__PopoverProviderInternal,
|
|
264
366
|
createPopoverScope,
|