@hanzogui/dialog 2.0.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.cjs +618 -0
- package/dist/cjs/Dialog.native.js +691 -0
- package/dist/cjs/Dialog.native.js.map +1 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.native.js +21 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/Dialog.mjs +571 -0
- package/dist/esm/Dialog.mjs.map +1 -0
- package/dist/esm/Dialog.native.js +641 -0
- package/dist/esm/Dialog.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/jsx/Dialog.mjs +571 -0
- package/dist/jsx/Dialog.mjs.map +1 -0
- package/dist/jsx/Dialog.native.js +691 -0
- package/dist/jsx/Dialog.native.js.map +1 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +21 -0
- package/dist/jsx/index.native.js.map +1 -0
- package/package.json +68 -0
- package/src/Dialog.tsx +1009 -0
- package/src/index.ts +1 -0
- package/types/Dialog.d.ts +409 -0
- package/types/index.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 WorkOS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Dialog_exports = {};
|
|
33
|
+
__export(Dialog_exports, {
|
|
34
|
+
Dialog: () => Dialog,
|
|
35
|
+
DialogClose: () => DialogClose,
|
|
36
|
+
DialogContent: () => DialogContent,
|
|
37
|
+
DialogContext: () => DialogContext,
|
|
38
|
+
DialogDescription: () => DialogDescription,
|
|
39
|
+
DialogOverlay: () => DialogOverlay,
|
|
40
|
+
DialogOverlayFrame: () => DialogOverlayFrame,
|
|
41
|
+
DialogPortal: () => DialogPortal,
|
|
42
|
+
DialogPortalFrame: () => DialogPortalFrame,
|
|
43
|
+
DialogProvider: () => DialogProvider,
|
|
44
|
+
DialogTitle: () => DialogTitle,
|
|
45
|
+
DialogTrigger: () => DialogTrigger,
|
|
46
|
+
DialogWarningProvider: () => DialogWarningProvider,
|
|
47
|
+
useDialogContext: () => useDialogContext
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(Dialog_exports);
|
|
50
|
+
var import_gui_adapt = require("@hanzo/gui-adapt"),
|
|
51
|
+
import_gui_animate = require("@hanzo/gui-animate"),
|
|
52
|
+
import_gui_compose_refs = require("@hanzo/gui-compose-refs"),
|
|
53
|
+
import_gui_constants = require("@hanzo/gui-constants"),
|
|
54
|
+
import_gui_core = require("@hanzo/gui-core"),
|
|
55
|
+
import_gui_create_context = require("@hanzo/gui-create-context"),
|
|
56
|
+
import_gui_dismissable = require("@hanzo/gui-dismissable"),
|
|
57
|
+
import_gui_focus_scope = require("@hanzo/gui-focus-scope"),
|
|
58
|
+
import_gui_helpers = require("@hanzo/gui-helpers"),
|
|
59
|
+
import_gui_portal = require("@hanzo/gui-portal"),
|
|
60
|
+
import_gui_remove_scroll = require("@hanzo/gui-remove-scroll"),
|
|
61
|
+
import_controller = require("@hanzo/gui-sheet/controller"),
|
|
62
|
+
import_gui_stacks = require("@hanzo/gui-stacks"),
|
|
63
|
+
import_gui_text = require("@hanzo/gui-text"),
|
|
64
|
+
import_gui_use_controllable_state = require("@hanzo/gui-use-controllable-state"),
|
|
65
|
+
import_gui_z_index_stack = require("@hanzo/gui-z-index-stack"),
|
|
66
|
+
React = __toESM(require("react"), 1),
|
|
67
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
68
|
+
const DialogContext = (0, import_gui_core.createStyledContext)(
|
|
69
|
+
// since we always provide this we can avoid setting here
|
|
70
|
+
{}, "Dialog__"),
|
|
71
|
+
{
|
|
72
|
+
useStyledContext: useDialogContext,
|
|
73
|
+
Provider: DialogProvider
|
|
74
|
+
} = DialogContext,
|
|
75
|
+
DialogTriggerFrame = (0, import_gui_core.styled)(import_gui_core.View, {
|
|
76
|
+
name: "DialogTrigger"
|
|
77
|
+
}),
|
|
78
|
+
DialogTrigger = DialogTriggerFrame.styleable(function (props, forwardedRef) {
|
|
79
|
+
const {
|
|
80
|
+
scope,
|
|
81
|
+
...triggerProps
|
|
82
|
+
} = props,
|
|
83
|
+
isInsideButton = React.useContext(import_gui_stacks.ButtonNestingContext),
|
|
84
|
+
context = useDialogContext(scope),
|
|
85
|
+
composedTriggerRef = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
|
|
86
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_stacks.ButtonNestingContext.Provider, {
|
|
87
|
+
value: !0,
|
|
88
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogTriggerFrame, {
|
|
89
|
+
render: isInsideButton ? "span" : "button",
|
|
90
|
+
"aria-haspopup": "dialog",
|
|
91
|
+
"aria-expanded": context.open,
|
|
92
|
+
"aria-controls": context.contentId,
|
|
93
|
+
"data-state": getState(context.open),
|
|
94
|
+
...triggerProps,
|
|
95
|
+
ref: composedTriggerRef,
|
|
96
|
+
onPress: (0, import_gui_helpers.composeEventHandlers)(props.onPress, context.onOpenToggle)
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
}),
|
|
100
|
+
DialogPortalFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
101
|
+
pointerEvents: "none",
|
|
102
|
+
render: "dialog",
|
|
103
|
+
variants: {
|
|
104
|
+
unstyled: {
|
|
105
|
+
false: {
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
justifyContent: "center",
|
|
108
|
+
fullscreen: !0,
|
|
109
|
+
"$platform-web": {
|
|
110
|
+
// undo dialog styles
|
|
111
|
+
borderWidth: 0,
|
|
112
|
+
backgroundColor: "transparent",
|
|
113
|
+
color: "inherit",
|
|
114
|
+
maxInlineSize: "none",
|
|
115
|
+
margin: 0,
|
|
116
|
+
width: "auto",
|
|
117
|
+
height: "auto",
|
|
118
|
+
// ensure always in frame and right height
|
|
119
|
+
maxHeight: "100vh",
|
|
120
|
+
position: "fixed",
|
|
121
|
+
// ensure dialog inherits stacking context from portal wrapper
|
|
122
|
+
zIndex: 1
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
defaultVariants: {
|
|
128
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
needsRepropagation = (0, import_gui_portal.needsPortalRepropagation)(),
|
|
132
|
+
DialogPortalItem = ({
|
|
133
|
+
context,
|
|
134
|
+
children
|
|
135
|
+
}) => {
|
|
136
|
+
const themeName = (0, import_gui_core.useThemeName)(),
|
|
137
|
+
isAdapted = (0, import_gui_adapt.useAdaptIsActive)(context.adaptScope),
|
|
138
|
+
adaptContext = (0, import_gui_adapt.useAdaptContext)(context.adaptScope);
|
|
139
|
+
let content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.Theme, {
|
|
140
|
+
name: themeName,
|
|
141
|
+
children
|
|
142
|
+
});
|
|
143
|
+
return needsRepropagation && (content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_adapt.ProvideAdaptContext, {
|
|
144
|
+
...adaptContext,
|
|
145
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogProvider, {
|
|
146
|
+
...context,
|
|
147
|
+
children: content
|
|
148
|
+
})
|
|
149
|
+
})), isAdapted ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_adapt.AdaptPortalContents, {
|
|
150
|
+
scope: context.adaptScope,
|
|
151
|
+
children: content
|
|
152
|
+
}) : context.modal ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_portal.PortalItem, {
|
|
153
|
+
hostName: context.modal ? "root" : context.adaptScope,
|
|
154
|
+
children: content
|
|
155
|
+
}) : content;
|
|
156
|
+
},
|
|
157
|
+
DialogPortal = React.forwardRef((props, forwardRef) => {
|
|
158
|
+
const {
|
|
159
|
+
scope,
|
|
160
|
+
forceMount,
|
|
161
|
+
children,
|
|
162
|
+
...frameProps
|
|
163
|
+
} = props,
|
|
164
|
+
dialogRef = React.useRef(null),
|
|
165
|
+
ref = (0, import_gui_compose_refs.composeRefs)(dialogRef, forwardRef),
|
|
166
|
+
context = useDialogContext(scope),
|
|
167
|
+
keepMounted = forceMount || context.keepChildrenMounted,
|
|
168
|
+
isAdapted = (0, import_gui_adapt.useAdaptIsActive)(context.adaptScope),
|
|
169
|
+
[isFullyHidden, setIsFullyHidden] = React.useState(!context.open);
|
|
170
|
+
context.open && isFullyHidden && setIsFullyHidden(!1);
|
|
171
|
+
const isVisible = context.open ? !0 : !isFullyHidden;
|
|
172
|
+
import_gui_constants.isWeb && (0, import_gui_constants.useIsomorphicLayoutEffect)(() => {
|
|
173
|
+
const node = dialogRef.current;
|
|
174
|
+
node instanceof HTMLDialogElement && (isVisible ? node.show?.() : node.close?.());
|
|
175
|
+
}, [isVisible]);
|
|
176
|
+
const onAnimationCompleteRef = React.useRef(context.onAnimationComplete);
|
|
177
|
+
onAnimationCompleteRef.current = context.onAnimationComplete;
|
|
178
|
+
const handleExitComplete = React.useCallback(() => {
|
|
179
|
+
setIsFullyHidden(!0), onAnimationCompleteRef.current?.({
|
|
180
|
+
open: !1
|
|
181
|
+
});
|
|
182
|
+
}, []);
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (context.open && !isAdapted && onAnimationCompleteRef.current) {
|
|
185
|
+
const tm = setTimeout(() => {
|
|
186
|
+
onAnimationCompleteRef.current?.({
|
|
187
|
+
open: !0
|
|
188
|
+
});
|
|
189
|
+
}, 350);
|
|
190
|
+
return () => clearTimeout(tm);
|
|
191
|
+
}
|
|
192
|
+
}, [context.open, isAdapted]);
|
|
193
|
+
const zIndex = (0, import_gui_core.getExpandedShorthand)("zIndex", props),
|
|
194
|
+
contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_z_index_stack.StackZIndexContext, {
|
|
195
|
+
zIndex: (0, import_gui_portal.resolveViewZIndex)(zIndex),
|
|
196
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_animate.Animate, {
|
|
197
|
+
type: "presence",
|
|
198
|
+
present: !!context.open,
|
|
199
|
+
keepChildrenMounted: !!keepMounted,
|
|
200
|
+
onExitComplete: handleExitComplete,
|
|
201
|
+
passThrough: isAdapted,
|
|
202
|
+
children
|
|
203
|
+
})
|
|
204
|
+
}),
|
|
205
|
+
framedContents = isFullyHidden && !keepMounted && !isAdapted ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.LayoutMeasurementController, {
|
|
206
|
+
disable: !context.open,
|
|
207
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalFrame, {
|
|
208
|
+
ref,
|
|
209
|
+
...(import_gui_constants.isWeb && context.open && {
|
|
210
|
+
"aria-modal": !0
|
|
211
|
+
}),
|
|
212
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
213
|
+
...frameProps,
|
|
214
|
+
className: "_no_backdrop " + (frameProps.className || ""),
|
|
215
|
+
children: contents
|
|
216
|
+
})
|
|
217
|
+
});
|
|
218
|
+
return import_gui_constants.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_portal.Portal, {
|
|
219
|
+
zIndex,
|
|
220
|
+
stackZIndex: 1e5,
|
|
221
|
+
passThrough: isAdapted,
|
|
222
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PassthroughTheme, {
|
|
223
|
+
passThrough: isAdapted,
|
|
224
|
+
children: framedContents
|
|
225
|
+
})
|
|
226
|
+
}) : isAdapted ? framedContents : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalItem, {
|
|
227
|
+
context,
|
|
228
|
+
children: framedContents
|
|
229
|
+
});
|
|
230
|
+
}),
|
|
231
|
+
PassthroughTheme = ({
|
|
232
|
+
children,
|
|
233
|
+
passThrough
|
|
234
|
+
}) => {
|
|
235
|
+
const themeName = (0, import_gui_core.useThemeName)();
|
|
236
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.Theme, {
|
|
237
|
+
passThrough,
|
|
238
|
+
name: themeName,
|
|
239
|
+
forceClassName: !0,
|
|
240
|
+
children
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
OVERLAY_NAME = "DialogOverlay",
|
|
244
|
+
DialogOverlayFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
245
|
+
name: OVERLAY_NAME,
|
|
246
|
+
zIndex: 1,
|
|
247
|
+
variants: {
|
|
248
|
+
open: {
|
|
249
|
+
true: {
|
|
250
|
+
pointerEvents: "auto"
|
|
251
|
+
},
|
|
252
|
+
false: {
|
|
253
|
+
pointerEvents: "none"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
unstyled: {
|
|
257
|
+
false: {
|
|
258
|
+
fullscreen: !0,
|
|
259
|
+
position: "absolute",
|
|
260
|
+
backgroundColor: "$background",
|
|
261
|
+
pointerEvents: "auto"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
defaultVariants: {
|
|
266
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
269
|
+
DialogOverlay = DialogOverlayFrame.styleable(function ({
|
|
270
|
+
scope,
|
|
271
|
+
...props
|
|
272
|
+
}, forwardedRef) {
|
|
273
|
+
const context = useDialogContext(scope),
|
|
274
|
+
{
|
|
275
|
+
forceMount = context.forceMount,
|
|
276
|
+
...overlayProps
|
|
277
|
+
} = props,
|
|
278
|
+
isAdapted = (0, import_gui_adapt.useAdaptIsActive)(context.adaptScope);
|
|
279
|
+
return !forceMount && (!context.modal || isAdapted) ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogOverlayFrame, {
|
|
280
|
+
"data-state": getState(context.open),
|
|
281
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
282
|
+
...overlayProps,
|
|
283
|
+
ref: forwardedRef
|
|
284
|
+
});
|
|
285
|
+
}),
|
|
286
|
+
CONTENT_NAME = "DialogContent",
|
|
287
|
+
DialogContentFrame = (0, import_gui_core.styled)(import_gui_stacks.ThemeableStack, {
|
|
288
|
+
name: CONTENT_NAME,
|
|
289
|
+
zIndex: 2,
|
|
290
|
+
variants: {
|
|
291
|
+
size: {
|
|
292
|
+
"...size": (val, extras) => ({})
|
|
293
|
+
},
|
|
294
|
+
unstyled: {
|
|
295
|
+
false: {
|
|
296
|
+
position: "relative",
|
|
297
|
+
backgroundColor: "$background",
|
|
298
|
+
borderWidth: 1,
|
|
299
|
+
borderColor: "$borderColor",
|
|
300
|
+
padding: "$true",
|
|
301
|
+
borderRadius: "$true",
|
|
302
|
+
elevate: !0,
|
|
303
|
+
// Ensure content receives pointer events (fixes React 19 + display:contents inheritance)
|
|
304
|
+
pointerEvents: "auto"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
defaultVariants: {
|
|
309
|
+
size: "$true",
|
|
310
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
311
|
+
}
|
|
312
|
+
}),
|
|
313
|
+
DialogContent = DialogContentFrame.styleable(function ({
|
|
314
|
+
scope,
|
|
315
|
+
...props
|
|
316
|
+
}, forwardedRef) {
|
|
317
|
+
const context = useDialogContext(scope),
|
|
318
|
+
contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
319
|
+
children: context.modal ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentModal, {
|
|
320
|
+
context,
|
|
321
|
+
...props,
|
|
322
|
+
ref: forwardedRef
|
|
323
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentNonModal, {
|
|
324
|
+
context,
|
|
325
|
+
...props,
|
|
326
|
+
ref: forwardedRef
|
|
327
|
+
})
|
|
328
|
+
});
|
|
329
|
+
return !import_gui_constants.isWeb || context.disableRemoveScroll ? contents : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_remove_scroll.RemoveScroll, {
|
|
330
|
+
enabled: context.open,
|
|
331
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
|
|
332
|
+
"data-remove-scroll-container": !0,
|
|
333
|
+
className: "_dsp_contents",
|
|
334
|
+
children: contents
|
|
335
|
+
})
|
|
336
|
+
});
|
|
337
|
+
}),
|
|
338
|
+
DialogContentModal = React.forwardRef(({
|
|
339
|
+
children,
|
|
340
|
+
context,
|
|
341
|
+
...props
|
|
342
|
+
}, forwardedRef) => {
|
|
343
|
+
const contentRef = React.useRef(null),
|
|
344
|
+
composedRefs = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, context.contentRef, contentRef);
|
|
345
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentImpl, {
|
|
346
|
+
...props,
|
|
347
|
+
context,
|
|
348
|
+
ref: composedRefs,
|
|
349
|
+
trapFocus: context.open,
|
|
350
|
+
disableOutsidePointerEvents: !0,
|
|
351
|
+
onCloseAutoFocus: (0, import_gui_helpers.composeEventHandlers)(props.onCloseAutoFocus, event => {
|
|
352
|
+
event.preventDefault(), context.triggerRef.current?.focus();
|
|
353
|
+
}),
|
|
354
|
+
onPointerDownOutside: (0, import_gui_helpers.composeEventHandlers)(props.onPointerDownOutside, event => {
|
|
355
|
+
const originalEvent = event.detail.originalEvent,
|
|
356
|
+
ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === !0;
|
|
357
|
+
(originalEvent.button === 2 || ctrlLeftClick) && event.preventDefault();
|
|
358
|
+
}),
|
|
359
|
+
onFocusOutside: (0, import_gui_helpers.composeEventHandlers)(props.onFocusOutside, event => event.preventDefault()),
|
|
360
|
+
...(!props.unstyled && {
|
|
361
|
+
outlineStyle: "none"
|
|
362
|
+
}),
|
|
363
|
+
children
|
|
364
|
+
});
|
|
365
|
+
}),
|
|
366
|
+
DialogContentNonModal = React.forwardRef((props, forwardedRef) => {
|
|
367
|
+
const hasInteractedOutsideRef = React.useRef(!1);
|
|
368
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentImpl, {
|
|
369
|
+
...props,
|
|
370
|
+
ref: forwardedRef,
|
|
371
|
+
trapFocus: !1,
|
|
372
|
+
disableOutsidePointerEvents: !1,
|
|
373
|
+
onCloseAutoFocus: event => {
|
|
374
|
+
props.onCloseAutoFocus?.(event), event.defaultPrevented || (hasInteractedOutsideRef.current || props.context.triggerRef.current?.focus(), event.preventDefault()), hasInteractedOutsideRef.current = !1;
|
|
375
|
+
},
|
|
376
|
+
onInteractOutside: event => {
|
|
377
|
+
props.onInteractOutside?.(event), event.defaultPrevented || (hasInteractedOutsideRef.current = !0);
|
|
378
|
+
const target = event.target,
|
|
379
|
+
trigger = props.context.triggerRef.current;
|
|
380
|
+
if (!(trigger instanceof HTMLElement)) return;
|
|
381
|
+
trigger.contains(target) && event.preventDefault();
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}),
|
|
385
|
+
DialogContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
386
|
+
const {
|
|
387
|
+
trapFocus,
|
|
388
|
+
onOpenAutoFocus,
|
|
389
|
+
onCloseAutoFocus,
|
|
390
|
+
disableOutsidePointerEvents,
|
|
391
|
+
onEscapeKeyDown,
|
|
392
|
+
onPointerDownOutside,
|
|
393
|
+
onFocusOutside,
|
|
394
|
+
onInteractOutside,
|
|
395
|
+
context,
|
|
396
|
+
...contentProps
|
|
397
|
+
} = props,
|
|
398
|
+
contentRef = React.useRef(null),
|
|
399
|
+
composedRefs = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, contentRef);
|
|
400
|
+
if ((0, import_gui_adapt.useAdaptIsActive)(context.adaptScope)) return !import_gui_constants.isWeb && !context.open ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalItem, {
|
|
401
|
+
context,
|
|
402
|
+
children: contentProps.children
|
|
403
|
+
});
|
|
404
|
+
const contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentFrame, {
|
|
405
|
+
ref: composedRefs,
|
|
406
|
+
id: context.contentId,
|
|
407
|
+
role: "dialog",
|
|
408
|
+
"aria-modal": context.modal,
|
|
409
|
+
"aria-describedby": context.descriptionId,
|
|
410
|
+
"aria-labelledby": context.titleId,
|
|
411
|
+
"data-state": getState(context.open),
|
|
412
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
413
|
+
...contentProps
|
|
414
|
+
});
|
|
415
|
+
return import_gui_constants.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
416
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_dismissable.Dismissable, {
|
|
417
|
+
disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
|
|
418
|
+
forceUnmount: !context.open,
|
|
419
|
+
onEscapeKeyDown,
|
|
420
|
+
onPointerDownOutside,
|
|
421
|
+
onFocusOutside,
|
|
422
|
+
onInteractOutside,
|
|
423
|
+
onDismiss: () => context?.onOpenChange?.(!1),
|
|
424
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_focus_scope.FocusScope, {
|
|
425
|
+
loop: !0,
|
|
426
|
+
enabled: context.open,
|
|
427
|
+
trapped: trapFocus,
|
|
428
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
429
|
+
forceUnmount: !context.open,
|
|
430
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
431
|
+
children: contents
|
|
432
|
+
})
|
|
433
|
+
}), process.env.NODE_ENV === "development" && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
434
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(TitleWarning, {
|
|
435
|
+
titleId: context.titleId
|
|
436
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionWarning, {
|
|
437
|
+
contentRef,
|
|
438
|
+
descriptionId: context.descriptionId
|
|
439
|
+
})]
|
|
440
|
+
})]
|
|
441
|
+
}) : contents;
|
|
442
|
+
}),
|
|
443
|
+
DialogTitleFrame = (0, import_gui_core.styled)(import_gui_text.H2, {
|
|
444
|
+
name: "DialogTitle"
|
|
445
|
+
}),
|
|
446
|
+
DialogTitle = DialogTitleFrame.styleable(function (props, forwardedRef) {
|
|
447
|
+
const {
|
|
448
|
+
scope,
|
|
449
|
+
...titleProps
|
|
450
|
+
} = props,
|
|
451
|
+
context = useDialogContext(scope);
|
|
452
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogTitleFrame, {
|
|
453
|
+
id: context.titleId,
|
|
454
|
+
...titleProps,
|
|
455
|
+
ref: forwardedRef
|
|
456
|
+
});
|
|
457
|
+
}),
|
|
458
|
+
DialogDescriptionFrame = (0, import_gui_core.styled)(import_gui_text.Paragraph, {
|
|
459
|
+
name: "DialogDescription"
|
|
460
|
+
}),
|
|
461
|
+
DialogDescription = DialogDescriptionFrame.styleable(function (props, forwardedRef) {
|
|
462
|
+
const {
|
|
463
|
+
scope,
|
|
464
|
+
...descriptionProps
|
|
465
|
+
} = props,
|
|
466
|
+
context = useDialogContext(scope);
|
|
467
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogDescriptionFrame, {
|
|
468
|
+
id: context.descriptionId,
|
|
469
|
+
...descriptionProps,
|
|
470
|
+
ref: forwardedRef
|
|
471
|
+
});
|
|
472
|
+
}),
|
|
473
|
+
CLOSE_NAME = "DialogClose",
|
|
474
|
+
DialogCloseFrame = (0, import_gui_core.styled)(import_gui_core.View, {
|
|
475
|
+
name: CLOSE_NAME,
|
|
476
|
+
render: "button"
|
|
477
|
+
}),
|
|
478
|
+
DialogClose = DialogCloseFrame.styleable((props, forwardedRef) => {
|
|
479
|
+
const {
|
|
480
|
+
scope,
|
|
481
|
+
displayWhenAdapted,
|
|
482
|
+
...closeProps
|
|
483
|
+
} = props,
|
|
484
|
+
context = useDialogContext(scope),
|
|
485
|
+
isAdapted = (0, import_gui_adapt.useAdaptIsActive)(context.adaptScope),
|
|
486
|
+
isInsideButton = React.useContext(import_gui_stacks.ButtonNestingContext);
|
|
487
|
+
return isAdapted && !displayWhenAdapted ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogCloseFrame, {
|
|
488
|
+
"aria-label": "Dialog Close",
|
|
489
|
+
render: isInsideButton ? "span" : "button",
|
|
490
|
+
...closeProps,
|
|
491
|
+
ref: forwardedRef,
|
|
492
|
+
onPress: (0, import_gui_helpers.composeEventHandlers)(props.onPress, () => {
|
|
493
|
+
context.onOpenChange(!1);
|
|
494
|
+
})
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
function getState(open) {
|
|
498
|
+
return open ? "open" : "closed";
|
|
499
|
+
}
|
|
500
|
+
const TITLE_WARNING_NAME = "DialogTitleWarning",
|
|
501
|
+
[DialogWarningProvider, useWarningContext] = (0, import_gui_create_context.createContext)(TITLE_WARNING_NAME, {
|
|
502
|
+
contentName: CONTENT_NAME,
|
|
503
|
+
titleName: "DialogTitle",
|
|
504
|
+
docsSlug: "dialog"
|
|
505
|
+
}),
|
|
506
|
+
TitleWarning = ({
|
|
507
|
+
titleId
|
|
508
|
+
}) => {
|
|
509
|
+
if (process.env.NODE_ENV === "development") {
|
|
510
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME),
|
|
511
|
+
MESSAGE = `\`${titleWarningContext.contentName}\` wants a \`${titleWarningContext.titleName}\` to be accessible. If you want to hide the \`${titleWarningContext.titleName}\`, wrap it with <VisuallyHidden />.`;
|
|
512
|
+
React.useEffect(() => {
|
|
513
|
+
import_gui_constants.isWeb && titleId && (document.getElementById(titleId) || console.warn(MESSAGE));
|
|
514
|
+
}, [MESSAGE, titleId]);
|
|
515
|
+
}
|
|
516
|
+
return null;
|
|
517
|
+
},
|
|
518
|
+
DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning",
|
|
519
|
+
DescriptionWarning = ({
|
|
520
|
+
contentRef,
|
|
521
|
+
descriptionId
|
|
522
|
+
}) => {
|
|
523
|
+
if (process.env.NODE_ENV === "development") {
|
|
524
|
+
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${useWarningContext(DESCRIPTION_WARNING_NAME).contentName}}.`;
|
|
525
|
+
React.useEffect(() => {
|
|
526
|
+
if (!import_gui_constants.isWeb) return;
|
|
527
|
+
const contentNode = contentRef.current;
|
|
528
|
+
if (!(contentNode instanceof HTMLElement)) return;
|
|
529
|
+
const describedById = contentNode.getAttribute("aria-describedby");
|
|
530
|
+
descriptionId && describedById && (document.getElementById(descriptionId) || console.warn(MESSAGE));
|
|
531
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
532
|
+
}
|
|
533
|
+
return null;
|
|
534
|
+
},
|
|
535
|
+
Dialog = (0, import_gui_helpers.withStaticProperties)(React.forwardRef(function (props, ref) {
|
|
536
|
+
const {
|
|
537
|
+
scope = "",
|
|
538
|
+
children,
|
|
539
|
+
open: openProp,
|
|
540
|
+
defaultOpen = !1,
|
|
541
|
+
onOpenChange,
|
|
542
|
+
modal = !0,
|
|
543
|
+
keepChildrenMounted,
|
|
544
|
+
disableRemoveScroll = !1,
|
|
545
|
+
onAnimationComplete
|
|
546
|
+
} = props,
|
|
547
|
+
baseId = React.useId(),
|
|
548
|
+
dialogId = `Dialog-${scope}-${baseId}`,
|
|
549
|
+
contentId = `${dialogId}-content`,
|
|
550
|
+
titleId = `${dialogId}-title`,
|
|
551
|
+
descriptionId = `${dialogId}-description`,
|
|
552
|
+
triggerRef = React.useRef(null),
|
|
553
|
+
contentRef = React.useRef(null),
|
|
554
|
+
[open, setOpen] = (0, import_gui_use_controllable_state.useControllableState)({
|
|
555
|
+
prop: openProp,
|
|
556
|
+
defaultProp: defaultOpen,
|
|
557
|
+
onChange: onOpenChange
|
|
558
|
+
}),
|
|
559
|
+
onOpenToggle = React.useCallback(() => {
|
|
560
|
+
setOpen(prevOpen => !prevOpen);
|
|
561
|
+
}, [setOpen]),
|
|
562
|
+
adaptScope = `DialogAdapt${scope}`,
|
|
563
|
+
context = {
|
|
564
|
+
dialogScope: scope,
|
|
565
|
+
adaptScope,
|
|
566
|
+
triggerRef,
|
|
567
|
+
contentRef,
|
|
568
|
+
contentId,
|
|
569
|
+
titleId,
|
|
570
|
+
descriptionId,
|
|
571
|
+
open,
|
|
572
|
+
onOpenChange: setOpen,
|
|
573
|
+
onOpenToggle,
|
|
574
|
+
modal,
|
|
575
|
+
keepChildrenMounted,
|
|
576
|
+
disableRemoveScroll,
|
|
577
|
+
onAnimationComplete
|
|
578
|
+
};
|
|
579
|
+
return React.useImperativeHandle(ref, () => ({
|
|
580
|
+
open: setOpen
|
|
581
|
+
}), [setOpen]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_adapt.AdaptParent, {
|
|
582
|
+
scope: adaptScope,
|
|
583
|
+
portal: {
|
|
584
|
+
forwardProps: props
|
|
585
|
+
},
|
|
586
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogProvider, {
|
|
587
|
+
scope,
|
|
588
|
+
...context,
|
|
589
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogSheetController, {
|
|
590
|
+
onOpenChange: setOpen,
|
|
591
|
+
scope,
|
|
592
|
+
children
|
|
593
|
+
})
|
|
594
|
+
})
|
|
595
|
+
});
|
|
596
|
+
}), {
|
|
597
|
+
Trigger: DialogTrigger,
|
|
598
|
+
Portal: DialogPortal,
|
|
599
|
+
Overlay: DialogOverlay,
|
|
600
|
+
Content: DialogContent,
|
|
601
|
+
Title: DialogTitle,
|
|
602
|
+
Description: DialogDescription,
|
|
603
|
+
Close: DialogClose,
|
|
604
|
+
FocusScope: import_gui_focus_scope.FocusScopeController,
|
|
605
|
+
Adapt: import_gui_adapt.Adapt
|
|
606
|
+
});
|
|
607
|
+
const DialogSheetController = props => {
|
|
608
|
+
const context = useDialogContext(props.scope),
|
|
609
|
+
isAdapted = (0, import_gui_adapt.useAdaptIsActive)(context.adaptScope);
|
|
610
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_controller.SheetController, {
|
|
611
|
+
onOpenChange: val => {
|
|
612
|
+
isAdapted && props.onOpenChange?.(val);
|
|
613
|
+
},
|
|
614
|
+
open: context.open,
|
|
615
|
+
hidden: !isAdapted,
|
|
616
|
+
children: props.children
|
|
617
|
+
});
|
|
618
|
+
};
|