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