@tamagui/dialog 1.0.1-beta.99 → 1.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/Dialog.js +413 -297
- package/dist/cjs/Dialog.js.map +3 -3
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Dialog.js +408 -299
- package/dist/esm/Dialog.js.map +3 -3
- package/dist/esm/index.js +0 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Dialog.js +256 -168
- package/dist/jsx/Dialog.js.map +3 -3
- package/dist/jsx/index.js +0 -0
- package/dist/jsx/index.js.map +1 -1
- package/package.json +32 -21
- package/src/Dialog.tsx +292 -159
- package/types/Dialog.d.ts +1009 -584
- package/types/index.d.ts +0 -0
- package/types/Dialog.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
package/dist/cjs/Dialog.js
CHANGED
|
@@ -1,38 +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 __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
8
|
var __export = (target, all) => {
|
|
37
9
|
for (var name in all)
|
|
38
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -45,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
45
17
|
}
|
|
46
18
|
return to;
|
|
47
19
|
};
|
|
48
|
-
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
|
+
));
|
|
49
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
25
|
var Dialog_exports = {};
|
|
51
26
|
__export(Dialog_exports, {
|
|
@@ -55,25 +30,30 @@ __export(Dialog_exports, {
|
|
|
55
30
|
DialogDescription: () => DialogDescription,
|
|
56
31
|
DialogOverlay: () => DialogOverlay,
|
|
57
32
|
DialogPortal: () => DialogPortal,
|
|
33
|
+
DialogPortalFrame: () => DialogPortalFrame,
|
|
34
|
+
DialogSheetContents: () => DialogSheetContents,
|
|
58
35
|
DialogTitle: () => DialogTitle,
|
|
59
36
|
DialogTrigger: () => DialogTrigger,
|
|
60
|
-
|
|
37
|
+
DialogWarningProvider: () => DialogWarningProvider,
|
|
61
38
|
createDialogScope: () => createDialogScope
|
|
62
39
|
});
|
|
63
40
|
module.exports = __toCommonJS(Dialog_exports);
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var import_adapt = require("@tamagui/adapt");
|
|
64
43
|
var import_animate_presence = require("@tamagui/animate-presence");
|
|
44
|
+
var import_aria_hidden = require("@tamagui/aria-hidden");
|
|
65
45
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
66
46
|
var import_core = require("@tamagui/core");
|
|
67
47
|
var import_create_context = require("@tamagui/create-context");
|
|
68
48
|
var import_dismissable = require("@tamagui/dismissable");
|
|
69
49
|
var import_focus_scope = require("@tamagui/focus-scope");
|
|
70
50
|
var import_portal = require("@tamagui/portal");
|
|
51
|
+
var import_remove_scroll = require("@tamagui/remove-scroll");
|
|
52
|
+
var import_sheet = require("@tamagui/sheet");
|
|
71
53
|
var import_stacks = require("@tamagui/stacks");
|
|
72
54
|
var import_text = require("@tamagui/text");
|
|
73
55
|
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
74
|
-
var import_aria_hidden = require("aria-hidden");
|
|
75
56
|
var React = __toESM(require("react"));
|
|
76
|
-
var import_react_remove_scroll = require("react-remove-scroll");
|
|
77
57
|
const DIALOG_NAME = "Dialog";
|
|
78
58
|
const [createDialogContext, createDialogScope] = (0, import_create_context.createContextScope)(DIALOG_NAME);
|
|
79
59
|
const [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
|
|
@@ -81,96 +61,112 @@ const TRIGGER_NAME = "DialogTrigger";
|
|
|
81
61
|
const DialogTriggerFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
82
62
|
name: TRIGGER_NAME
|
|
83
63
|
});
|
|
84
|
-
const DialogTrigger = React.forwardRef(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
64
|
+
const DialogTrigger = React.forwardRef(
|
|
65
|
+
(props, forwardedRef) => {
|
|
66
|
+
const { __scopeDialog, ...triggerProps } = props;
|
|
67
|
+
const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
|
|
68
|
+
const composedTriggerRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTriggerFrame, {
|
|
70
|
+
tag: "button",
|
|
71
|
+
"aria-haspopup": "dialog",
|
|
72
|
+
"aria-expanded": context.open,
|
|
73
|
+
"aria-controls": context.contentId,
|
|
74
|
+
"data-state": getState(context.open),
|
|
75
|
+
...triggerProps,
|
|
76
|
+
ref: composedTriggerRef,
|
|
77
|
+
onPress: (0, import_core.composeEventHandlers)(props.onPress, context.onOpenToggle)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
);
|
|
99
81
|
DialogTrigger.displayName = TRIGGER_NAME;
|
|
100
82
|
const PORTAL_NAME = "DialogPortal";
|
|
101
83
|
const [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
|
|
102
84
|
forceMount: void 0
|
|
103
85
|
});
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return contents;
|
|
86
|
+
const DialogPortalFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
87
|
+
alignItems: "center",
|
|
88
|
+
justifyContent: "center",
|
|
89
|
+
fullscreen: true,
|
|
90
|
+
zIndex: 100,
|
|
91
|
+
...import_core.isWeb && {
|
|
92
|
+
maxHeight: "100vh"
|
|
112
93
|
}
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
});
|
|
95
|
+
const DialogPortal = DialogPortalFrame.extractable(
|
|
96
|
+
(props) => {
|
|
97
|
+
const { __scopeDialog, forceMount, children, ...frameProps } = props;
|
|
98
|
+
const themeName = (0, import_core.useThemeName)();
|
|
99
|
+
const context = useDialogContext(PORTAL_NAME, __scopeDialog);
|
|
100
|
+
const isShowing = forceMount || context.open;
|
|
101
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
|
|
102
|
+
children: isShowing ? children : null
|
|
103
|
+
});
|
|
104
|
+
const isSheet = useShowDialogSheet(context);
|
|
105
|
+
if (!context.modal || isSheet) {
|
|
106
|
+
return contents;
|
|
107
|
+
}
|
|
108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
|
|
109
|
+
name: `${context.scopeKey}SheetContents`,
|
|
110
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
|
|
111
|
+
scope: __scopeDialog,
|
|
112
|
+
...context,
|
|
113
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
114
|
+
name: themeName,
|
|
115
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalProvider, {
|
|
116
|
+
scope: __scopeDialog,
|
|
117
|
+
forceMount,
|
|
118
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalFrame, {
|
|
119
|
+
pointerEvents: isShowing ? "auto" : "none",
|
|
120
|
+
...frameProps,
|
|
121
|
+
children: contents
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
});
|
|
115
127
|
}
|
|
116
|
-
|
|
117
|
-
scope: __scopeDialog,
|
|
118
|
-
forceMount
|
|
119
|
-
}, /* @__PURE__ */ React.createElement(import_portal.Portal, __spreadValues(__spreadValues({
|
|
120
|
-
alignItems: "center",
|
|
121
|
-
justifyContent: "center",
|
|
122
|
-
zIndex: 100,
|
|
123
|
-
pointerEvents: isShowing ? "auto" : "none"
|
|
124
|
-
}, import_core.isWeb && {
|
|
125
|
-
maxHeight: "100vh"
|
|
126
|
-
}), rest), /* @__PURE__ */ React.createElement(import_core.Theme, {
|
|
127
|
-
name: themeName
|
|
128
|
-
}, contents)));
|
|
129
|
-
};
|
|
128
|
+
);
|
|
130
129
|
DialogPortal.displayName = PORTAL_NAME;
|
|
131
130
|
const OVERLAY_NAME = "DialogOverlay";
|
|
132
131
|
const DialogOverlayFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
133
132
|
name: OVERLAY_NAME,
|
|
134
|
-
pointerEvents: "auto",
|
|
135
133
|
backgrounded: true,
|
|
136
134
|
fullscreen: true
|
|
137
135
|
});
|
|
138
|
-
const DialogOverlay = React.forwardRef(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
const DialogOverlay = React.forwardRef(
|
|
137
|
+
({ __scopeDialog, ...props }, forwardedRef) => {
|
|
138
|
+
const portalContext = usePortalContext(OVERLAY_NAME, __scopeDialog);
|
|
139
|
+
const { forceMount = portalContext.forceMount, ...overlayProps } = props;
|
|
140
|
+
const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
|
|
141
|
+
const showSheet = useShowDialogSheet(context);
|
|
142
|
+
if (!forceMount) {
|
|
143
|
+
if (!context.modal || showSheet) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogOverlayImpl, {
|
|
148
|
+
context,
|
|
149
|
+
...overlayProps,
|
|
150
|
+
ref: forwardedRef
|
|
151
|
+
});
|
|
145
152
|
}
|
|
146
|
-
|
|
147
|
-
ref: forwardedRef
|
|
148
|
-
}));
|
|
149
|
-
});
|
|
153
|
+
);
|
|
150
154
|
DialogOverlay.displayName = OVERLAY_NAME;
|
|
151
|
-
const DialogOverlayImpl = React.forwardRef(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (!import_core.isWeb) {
|
|
161
|
-
return content;
|
|
155
|
+
const DialogOverlayImpl = React.forwardRef(
|
|
156
|
+
(props, forwardedRef) => {
|
|
157
|
+
const { context, ...overlayProps } = props;
|
|
158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogOverlayFrame, {
|
|
159
|
+
"data-state": getState(context.open),
|
|
160
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
161
|
+
...overlayProps,
|
|
162
|
+
ref: forwardedRef
|
|
163
|
+
});
|
|
162
164
|
}
|
|
163
|
-
|
|
164
|
-
as: import_core.Slot,
|
|
165
|
-
allowPinchZoom: context.allowPinchZoom,
|
|
166
|
-
shards: [context.contentRef]
|
|
167
|
-
}, content);
|
|
168
|
-
});
|
|
165
|
+
);
|
|
169
166
|
const CONTENT_NAME = "DialogContent";
|
|
170
167
|
const DialogContentFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
171
168
|
name: CONTENT_NAME,
|
|
172
169
|
tag: "dialog",
|
|
173
|
-
pointerEvents: "auto",
|
|
174
170
|
position: "relative",
|
|
175
171
|
backgrounded: true,
|
|
176
172
|
padded: true,
|
|
@@ -187,216 +183,289 @@ const DialogContentFrame = (0, import_core.styled)(import_stacks.ThemeableStack,
|
|
|
187
183
|
size: "$4"
|
|
188
184
|
}
|
|
189
185
|
});
|
|
190
|
-
const DialogContent =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
React.useEffect(() => {
|
|
208
|
-
if (!context.open)
|
|
209
|
-
return;
|
|
210
|
-
const content = contentRef.current;
|
|
211
|
-
if (content)
|
|
212
|
-
return (0, import_aria_hidden.hideOthers)(content);
|
|
213
|
-
}, [context.open]);
|
|
214
|
-
return /* @__PURE__ */ React.createElement(DialogContentImpl, __spreadProps(__spreadValues({}, props), {
|
|
215
|
-
ref: composedRefs,
|
|
216
|
-
trapFocus: context.open,
|
|
217
|
-
disableOutsidePointerEvents: true,
|
|
218
|
-
onCloseAutoFocus: (0, import_core.composeEventHandlers)(props.onCloseAutoFocus, (event) => {
|
|
219
|
-
var _a;
|
|
220
|
-
event.preventDefault();
|
|
221
|
-
(_a = context.triggerRef.current) == null ? void 0 : _a.focus();
|
|
222
|
-
}),
|
|
223
|
-
onPointerDownOutside: (0, import_core.composeEventHandlers)(props.onPointerDownOutside, (event) => {
|
|
224
|
-
const originalEvent = event["detail"].originalEvent;
|
|
225
|
-
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
226
|
-
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
227
|
-
if (isRightClick)
|
|
228
|
-
event.preventDefault();
|
|
229
|
-
}),
|
|
230
|
-
onFocusOutside: (0, import_core.composeEventHandlers)(props.onFocusOutside, (event) => event.preventDefault())
|
|
231
|
-
}));
|
|
232
|
-
});
|
|
233
|
-
const DialogContentNonModal = React.forwardRef((props, forwardedRef) => {
|
|
234
|
-
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
235
|
-
const hasInteractedOutsideRef = React.useRef(false);
|
|
236
|
-
return /* @__PURE__ */ React.createElement(DialogContentImpl, __spreadProps(__spreadValues({}, props), {
|
|
237
|
-
ref: forwardedRef,
|
|
238
|
-
trapFocus: false,
|
|
239
|
-
disableOutsidePointerEvents: false,
|
|
240
|
-
onCloseAutoFocus: (event) => {
|
|
241
|
-
var _a, _b;
|
|
242
|
-
(_a = props.onCloseAutoFocus) == null ? void 0 : _a.call(props, event);
|
|
243
|
-
if (!event.defaultPrevented) {
|
|
244
|
-
if (!hasInteractedOutsideRef.current)
|
|
245
|
-
(_b = context.triggerRef.current) == null ? void 0 : _b.focus();
|
|
246
|
-
event.preventDefault();
|
|
186
|
+
const DialogContent = DialogContentFrame.extractable(
|
|
187
|
+
React.forwardRef(
|
|
188
|
+
({ __scopeDialog, ...props }, forwardedRef) => {
|
|
189
|
+
const portalContext = usePortalContext(CONTENT_NAME, __scopeDialog);
|
|
190
|
+
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
191
|
+
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
192
|
+
const contents = context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentModal, {
|
|
193
|
+
context,
|
|
194
|
+
...contentProps,
|
|
195
|
+
ref: forwardedRef
|
|
196
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentNonModal, {
|
|
197
|
+
context,
|
|
198
|
+
...contentProps,
|
|
199
|
+
ref: forwardedRef
|
|
200
|
+
});
|
|
201
|
+
if (!import_core.isWeb) {
|
|
202
|
+
return contents;
|
|
247
203
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
|
|
205
|
+
forwardProps: true,
|
|
206
|
+
enabled: context.open,
|
|
207
|
+
allowPinchZoom: context.allowPinchZoom,
|
|
208
|
+
shards: [context.contentRef],
|
|
209
|
+
removeScrollBar: false,
|
|
210
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
211
|
+
className: "_dsp_contents",
|
|
212
|
+
children: contents
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
);
|
|
218
|
+
DialogContent.displayName = CONTENT_NAME;
|
|
219
|
+
const DialogContentModal = React.forwardRef(
|
|
220
|
+
({ children, context, ...props }, forwardedRef) => {
|
|
221
|
+
const contentRef = React.useRef(null);
|
|
222
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.contentRef, contentRef);
|
|
223
|
+
React.useEffect(() => {
|
|
224
|
+
if (!context.open)
|
|
258
225
|
return;
|
|
259
|
-
const
|
|
260
|
-
if (
|
|
226
|
+
const content = contentRef.current;
|
|
227
|
+
if (content)
|
|
228
|
+
return (0, import_aria_hidden.hideOthers)(content);
|
|
229
|
+
}, [context.open]);
|
|
230
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentImpl, {
|
|
231
|
+
...props,
|
|
232
|
+
context,
|
|
233
|
+
ref: composedRefs,
|
|
234
|
+
trapFocus: context.open,
|
|
235
|
+
disableOutsidePointerEvents: true,
|
|
236
|
+
onCloseAutoFocus: (0, import_core.composeEventHandlers)(props.onCloseAutoFocus, (event) => {
|
|
237
|
+
var _a;
|
|
261
238
|
event.preventDefault();
|
|
239
|
+
(_a = context.triggerRef.current) == null ? void 0 : _a.focus();
|
|
240
|
+
}),
|
|
241
|
+
onPointerDownOutside: (0, import_core.composeEventHandlers)(props.onPointerDownOutside, (event) => {
|
|
242
|
+
const originalEvent = event["detail"].originalEvent;
|
|
243
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
244
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
245
|
+
if (isRightClick)
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
}),
|
|
248
|
+
onFocusOutside: (0, import_core.composeEventHandlers)(
|
|
249
|
+
props.onFocusOutside,
|
|
250
|
+
(event) => event.preventDefault()
|
|
251
|
+
),
|
|
252
|
+
children
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
const DialogContentNonModal = React.forwardRef(
|
|
257
|
+
(props, forwardedRef) => {
|
|
258
|
+
const hasInteractedOutsideRef = React.useRef(false);
|
|
259
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentImpl, {
|
|
260
|
+
...props,
|
|
261
|
+
ref: forwardedRef,
|
|
262
|
+
trapFocus: false,
|
|
263
|
+
disableOutsidePointerEvents: false,
|
|
264
|
+
onCloseAutoFocus: (event) => {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
(_a = props.onCloseAutoFocus) == null ? void 0 : _a.call(props, event);
|
|
267
|
+
if (!event.defaultPrevented) {
|
|
268
|
+
if (!hasInteractedOutsideRef.current) {
|
|
269
|
+
(_b = props.context.triggerRef.current) == null ? void 0 : _b.focus();
|
|
270
|
+
}
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
}
|
|
273
|
+
hasInteractedOutsideRef.current = false;
|
|
274
|
+
},
|
|
275
|
+
onInteractOutside: (event) => {
|
|
276
|
+
var _a;
|
|
277
|
+
(_a = props.onInteractOutside) == null ? void 0 : _a.call(props, event);
|
|
278
|
+
if (!event.defaultPrevented)
|
|
279
|
+
hasInteractedOutsideRef.current = true;
|
|
280
|
+
const target = event.target;
|
|
281
|
+
const trigger = props.context.triggerRef.current;
|
|
282
|
+
if (!(trigger instanceof HTMLElement))
|
|
283
|
+
return;
|
|
284
|
+
const targetIsTrigger = trigger.contains(target);
|
|
285
|
+
if (targetIsTrigger)
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
const DialogContentImpl = React.forwardRef(
|
|
292
|
+
(props, forwardedRef) => {
|
|
293
|
+
const {
|
|
294
|
+
__scopeDialog,
|
|
295
|
+
trapFocus,
|
|
296
|
+
onOpenAutoFocus,
|
|
297
|
+
onCloseAutoFocus,
|
|
298
|
+
disableOutsidePointerEvents,
|
|
299
|
+
onEscapeKeyDown,
|
|
300
|
+
onPointerDownOutside,
|
|
301
|
+
onFocusOutside,
|
|
302
|
+
onInteractOutside,
|
|
303
|
+
context,
|
|
304
|
+
...contentProps
|
|
305
|
+
} = props;
|
|
306
|
+
const contentRef = React.useRef(null);
|
|
307
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef);
|
|
308
|
+
const showSheet = useShowDialogSheet(context);
|
|
309
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentFrame, {
|
|
310
|
+
id: context.contentId,
|
|
311
|
+
"aria-describedby": context.descriptionId,
|
|
312
|
+
"aria-labelledby": context.titleId,
|
|
313
|
+
"data-state": getState(context.open),
|
|
314
|
+
...contentProps
|
|
315
|
+
});
|
|
316
|
+
if (showSheet) {
|
|
317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
|
|
318
|
+
hostName: `${context.scopeKey}SheetContents`,
|
|
319
|
+
children: contentProps.children
|
|
320
|
+
});
|
|
262
321
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
titleId: context.titleId
|
|
310
|
-
}), /* @__PURE__ */ React.createElement(DescriptionWarning, {
|
|
311
|
-
contentRef,
|
|
312
|
-
descriptionId: context.descriptionId
|
|
313
|
-
})));
|
|
314
|
-
});
|
|
322
|
+
if (!import_core.isWeb) {
|
|
323
|
+
return contents;
|
|
324
|
+
}
|
|
325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
326
|
+
children: [
|
|
327
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
|
|
328
|
+
loop: true,
|
|
329
|
+
trapped: trapFocus,
|
|
330
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
331
|
+
forceUnmount: !context.open,
|
|
332
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
333
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
|
|
334
|
+
disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
|
|
335
|
+
forceUnmount: !context.open,
|
|
336
|
+
onEscapeKeyDown,
|
|
337
|
+
onPointerDownOutside,
|
|
338
|
+
onFocusOutside,
|
|
339
|
+
onInteractOutside,
|
|
340
|
+
ref: composedRefs,
|
|
341
|
+
onDismiss: () => context.onOpenChange(false),
|
|
342
|
+
children: contents
|
|
343
|
+
})
|
|
344
|
+
}),
|
|
345
|
+
process.env.NODE_ENV === "development" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
346
|
+
children: [
|
|
347
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleWarning, {
|
|
348
|
+
titleId: context.titleId
|
|
349
|
+
}),
|
|
350
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionWarning, {
|
|
351
|
+
contentRef,
|
|
352
|
+
descriptionId: context.descriptionId
|
|
353
|
+
})
|
|
354
|
+
]
|
|
355
|
+
})
|
|
356
|
+
]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
const SHEET_CONTENTS_NAME = "DialogSheetContents";
|
|
361
|
+
const DialogSheetContents = ({ __scopeDialog }) => {
|
|
362
|
+
const context = useDialogContext(SHEET_CONTENTS_NAME, __scopeDialog);
|
|
363
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
|
|
364
|
+
name: `${context.scopeKey}SheetContents`
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
DialogSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
315
368
|
const TITLE_NAME = "DialogTitle";
|
|
316
369
|
const DialogTitleFrame = (0, import_core.styled)(import_text.H2, {
|
|
317
370
|
name: TITLE_NAME
|
|
318
371
|
});
|
|
319
|
-
const DialogTitle = React.forwardRef(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
});
|
|
372
|
+
const DialogTitle = React.forwardRef(
|
|
373
|
+
(props, forwardedRef) => {
|
|
374
|
+
const { __scopeDialog, ...titleProps } = props;
|
|
375
|
+
const context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
376
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitleFrame, {
|
|
377
|
+
id: context.titleId,
|
|
378
|
+
...titleProps,
|
|
379
|
+
ref: forwardedRef
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
);
|
|
328
383
|
DialogTitle.displayName = TITLE_NAME;
|
|
329
384
|
const DialogDescriptionFrame = (0, import_core.styled)(import_text.Paragraph, {
|
|
330
385
|
name: "DialogDescription"
|
|
331
386
|
});
|
|
332
387
|
const DESCRIPTION_NAME = "DialogDescription";
|
|
333
|
-
const DialogDescription = React.forwardRef(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
});
|
|
388
|
+
const DialogDescription = React.forwardRef(
|
|
389
|
+
(props, forwardedRef) => {
|
|
390
|
+
const { __scopeDialog, ...descriptionProps } = props;
|
|
391
|
+
const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
392
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogDescriptionFrame, {
|
|
393
|
+
id: context.descriptionId,
|
|
394
|
+
...descriptionProps,
|
|
395
|
+
ref: forwardedRef
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
);
|
|
342
399
|
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
343
400
|
const CLOSE_NAME = "DialogClose";
|
|
344
|
-
const DialogClose = React.forwardRef(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
401
|
+
const DialogClose = React.forwardRef(
|
|
402
|
+
(props, forwardedRef) => {
|
|
403
|
+
const { __scopeDialog, ...closeProps } = props;
|
|
404
|
+
const context = useDialogContext(CLOSE_NAME, __scopeDialog);
|
|
405
|
+
const isSheet = useShowDialogSheet(context);
|
|
406
|
+
if (isSheet) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
410
|
+
tag: "button",
|
|
411
|
+
...closeProps,
|
|
412
|
+
ref: forwardedRef,
|
|
413
|
+
onPress: (0, import_core.composeEventHandlers)(props.onPress, () => context.onOpenChange(false))
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
);
|
|
354
417
|
DialogClose.displayName = CLOSE_NAME;
|
|
355
418
|
function getState(open) {
|
|
356
419
|
return open ? "open" : "closed";
|
|
357
420
|
}
|
|
358
421
|
const TITLE_WARNING_NAME = "DialogTitleWarning";
|
|
359
|
-
const [
|
|
422
|
+
const [DialogWarningProvider, useWarningContext] = (0, import_create_context.createContext)(TITLE_WARNING_NAME, {
|
|
360
423
|
contentName: CONTENT_NAME,
|
|
361
424
|
titleName: TITLE_NAME,
|
|
362
425
|
docsSlug: "dialog"
|
|
363
426
|
});
|
|
364
427
|
const TitleWarning = ({ titleId }) => {
|
|
365
|
-
|
|
366
|
-
|
|
428
|
+
if (process.env.NODE_ENV === "development") {
|
|
429
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
|
|
430
|
+
const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
367
431
|
|
|
368
432
|
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
369
433
|
|
|
370
434
|
For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
435
|
+
React.useEffect(() => {
|
|
436
|
+
if (!import_core.isWeb)
|
|
437
|
+
return;
|
|
438
|
+
if (titleId) {
|
|
439
|
+
const hasTitle = document.getElementById(titleId);
|
|
440
|
+
if (!hasTitle) {
|
|
441
|
+
console.warn(MESSAGE);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}, [MESSAGE, titleId]);
|
|
445
|
+
}
|
|
380
446
|
return null;
|
|
381
447
|
};
|
|
382
448
|
const DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
|
|
383
449
|
const DescriptionWarning = ({ contentRef, descriptionId }) => {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
450
|
+
if (process.env.NODE_ENV === "development") {
|
|
451
|
+
const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
|
|
452
|
+
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
|
|
453
|
+
React.useEffect(() => {
|
|
454
|
+
if (!import_core.isWeb)
|
|
455
|
+
return;
|
|
456
|
+
const contentNode = contentRef.current;
|
|
457
|
+
if (!(contentNode instanceof HTMLElement)) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const describedById = contentNode.getAttribute("aria-describedby");
|
|
461
|
+
if (descriptionId && describedById) {
|
|
462
|
+
const hasDescription = document.getElementById(descriptionId);
|
|
463
|
+
if (!hasDescription) {
|
|
464
|
+
console.warn(MESSAGE);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
468
|
+
}
|
|
400
469
|
return null;
|
|
401
470
|
};
|
|
402
471
|
const DialogInner = React.forwardRef(function Dialog(props, ref) {
|
|
@@ -409,6 +478,10 @@ const DialogInner = React.forwardRef(function Dialog(props, ref) {
|
|
|
409
478
|
modal = true,
|
|
410
479
|
allowPinchZoom = false
|
|
411
480
|
} = props;
|
|
481
|
+
const { when, AdaptProvider } = (0, import_adapt.useAdaptParent)({
|
|
482
|
+
Contents: DialogSheetContents
|
|
483
|
+
});
|
|
484
|
+
const sheetBreakpoint = when || false;
|
|
412
485
|
const triggerRef = React.useRef(null);
|
|
413
486
|
const contentRef = React.useRef(null);
|
|
414
487
|
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
@@ -416,22 +489,37 @@ const DialogInner = React.forwardRef(function Dialog(props, ref) {
|
|
|
416
489
|
defaultProp: defaultOpen,
|
|
417
490
|
onChange: onOpenChange
|
|
418
491
|
});
|
|
419
|
-
React.useImperativeHandle(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
492
|
+
React.useImperativeHandle(
|
|
493
|
+
ref,
|
|
494
|
+
() => ({
|
|
495
|
+
open: setOpen
|
|
496
|
+
}),
|
|
497
|
+
[setOpen]
|
|
498
|
+
);
|
|
499
|
+
const scopeId = (0, import_core.useId)();
|
|
500
|
+
const scopeKey = __scopeDialog ? Object.keys(__scopeDialog)[0] : scopeId;
|
|
501
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptProvider, {
|
|
502
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
|
|
503
|
+
scope: __scopeDialog,
|
|
504
|
+
scopeKey,
|
|
505
|
+
triggerRef,
|
|
506
|
+
contentRef,
|
|
507
|
+
contentId: (0, import_core.useId)() || "",
|
|
508
|
+
titleId: (0, import_core.useId)() || "",
|
|
509
|
+
descriptionId: (0, import_core.useId)() || "",
|
|
510
|
+
open,
|
|
511
|
+
onOpenChange: setOpen,
|
|
512
|
+
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
513
|
+
modal,
|
|
514
|
+
allowPinchZoom,
|
|
515
|
+
sheetBreakpoint,
|
|
516
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogSheetController, {
|
|
517
|
+
onOpenChange: setOpen,
|
|
518
|
+
__scopeDialog,
|
|
519
|
+
children
|
|
520
|
+
})
|
|
521
|
+
})
|
|
522
|
+
});
|
|
435
523
|
});
|
|
436
524
|
const Dialog2 = (0, import_core.withStaticProperties)(DialogInner, {
|
|
437
525
|
Trigger: DialogTrigger,
|
|
@@ -440,8 +528,34 @@ const Dialog2 = (0, import_core.withStaticProperties)(DialogInner, {
|
|
|
440
528
|
Content: DialogContent,
|
|
441
529
|
Title: DialogTitle,
|
|
442
530
|
Description: DialogDescription,
|
|
443
|
-
Close: DialogClose
|
|
531
|
+
Close: DialogClose,
|
|
532
|
+
Sheet: import_sheet.ControlledSheet,
|
|
533
|
+
Adapt: import_adapt.Adapt
|
|
444
534
|
});
|
|
535
|
+
const DialogSheetController = (props) => {
|
|
536
|
+
const context = useDialogContext("DialogSheetController", props.__scopeDialog);
|
|
537
|
+
const showSheet = useShowDialogSheet(context);
|
|
538
|
+
const breakpointActive = useSheetBreakpointActive(context);
|
|
539
|
+
const getShowSheet = (0, import_core.useGet)(showSheet);
|
|
540
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sheet.SheetController, {
|
|
541
|
+
onOpenChange: (val) => {
|
|
542
|
+
if (getShowSheet()) {
|
|
543
|
+
props.onOpenChange(val);
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
open: context.open,
|
|
547
|
+
hidden: breakpointActive === false,
|
|
548
|
+
children: props.children
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
const useSheetBreakpointActive = (context) => {
|
|
552
|
+
const media = (0, import_core.useMedia)();
|
|
553
|
+
return context.sheetBreakpoint ? media[context.sheetBreakpoint] : false;
|
|
554
|
+
};
|
|
555
|
+
const useShowDialogSheet = (context) => {
|
|
556
|
+
const breakpointActive = useSheetBreakpointActive(context);
|
|
557
|
+
return context.open === false ? false : breakpointActive;
|
|
558
|
+
};
|
|
445
559
|
// Annotate the CommonJS export names for ESM import in node:
|
|
446
560
|
0 && (module.exports = {
|
|
447
561
|
Dialog,
|
|
@@ -450,9 +564,11 @@ const Dialog2 = (0, import_core.withStaticProperties)(DialogInner, {
|
|
|
450
564
|
DialogDescription,
|
|
451
565
|
DialogOverlay,
|
|
452
566
|
DialogPortal,
|
|
567
|
+
DialogPortalFrame,
|
|
568
|
+
DialogSheetContents,
|
|
453
569
|
DialogTitle,
|
|
454
570
|
DialogTrigger,
|
|
455
|
-
|
|
571
|
+
DialogWarningProvider,
|
|
456
572
|
createDialogScope
|
|
457
573
|
});
|
|
458
574
|
//# sourceMappingURL=Dialog.js.map
|