@tamagui/dialog 2.7.7 → 3.0.0-beta.643.1

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.
@@ -0,0 +1,684 @@
1
+ "use strict";
2
+
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var Dialog_exports = {};
31
+ __export(Dialog_exports, {
32
+ Dialog: () => Dialog,
33
+ DialogClose: () => DialogClose,
34
+ DialogContent: () => DialogContent,
35
+ DialogContext: () => DialogContext,
36
+ DialogDescription: () => DialogDescription,
37
+ DialogOverlay: () => DialogOverlay,
38
+ DialogOverlayFrame: () => DialogOverlayFrame,
39
+ DialogPortal: () => DialogPortal,
40
+ DialogPortalFrame: () => DialogPortalFrame,
41
+ DialogProvider: () => DialogProvider,
42
+ DialogTitle: () => DialogTitle,
43
+ DialogTrigger: () => DialogTrigger,
44
+ DialogWarningProvider: () => DialogWarningProvider,
45
+ useDialogContext: () => useDialogContext
46
+ });
47
+ module.exports = __toCommonJS(Dialog_exports);
48
+ var import_jsx_runtime = require("react/jsx-runtime");
49
+ var import_adapt = require("@tamagui/adapt");
50
+ var import_animate = require("@tamagui/animate");
51
+ var import_compose_refs = require("@tamagui/compose-refs");
52
+ var import_constants = require("@tamagui/constants");
53
+ var import_core = require("@tamagui/core");
54
+ var import_create_context = require("@tamagui/create-context");
55
+ var import_dismissable = require("@tamagui/dismissable");
56
+ var import_focus_scope = require("@tamagui/focus-scope");
57
+ var import_helpers = require("@tamagui/helpers");
58
+ var import_portal = require("@tamagui/portal");
59
+ var import_remove_scroll = require("@tamagui/remove-scroll");
60
+ var import_stacks = require("@tamagui/stacks");
61
+ var import_text = require("@tamagui/text");
62
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
63
+ var import_z_index_stack = require("@tamagui/z-index-stack");
64
+ var React = __toESM(require("react"), 1);
65
+ function _instanceof(left, right) {
66
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
67
+ return !!right[Symbol.hasInstance](left);
68
+ } else {
69
+ return left instanceof right;
70
+ }
71
+ }
72
+ var DialogContext = (0, import_core.createStyledContext)({}, "Dialog__");
73
+ var { useStyledContext: useDialogContext, Provider: DialogProvider } = DialogContext;
74
+ var DialogTriggerFrame = (0, import_core.styled)(import_core.View, { displayName: "DialogTrigger" });
75
+ var DialogTrigger = (0, import_core.createStyledHOC)(DialogTriggerFrame, function DialogTrigger2(props, forwardedRef) {
76
+ var { scope, ...triggerProps } = props;
77
+ var isInsideButton = React.useContext(import_stacks.ButtonNestingContext);
78
+ var context = useDialogContext(scope);
79
+ var composedTriggerRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
80
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
81
+ value: props.asChild ? isInsideButton : true,
82
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTriggerFrame, {
83
+ render: isInsideButton ? "span" : "button",
84
+ "aria-haspopup": "dialog",
85
+ "aria-expanded": context.open,
86
+ "aria-controls": context.contentId,
87
+ "data-state": getState(context.open),
88
+ ...triggerProps,
89
+ ref: composedTriggerRef,
90
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress, context.onOpenToggle)
91
+ })
92
+ });
93
+ });
94
+ var DialogPortalFrame = (0, import_core.styled)(import_stacks.YStack, {
95
+ pointerEvents: "none",
96
+ alignItems: "center",
97
+ justifyContent: "center",
98
+ position: "absolute web:fixed",
99
+ inset: 0,
100
+ borderWidth: "web:0px",
101
+ backgroundColor: "web:transparent",
102
+ color: "web:inherit",
103
+ maxInlineSize: "web:none",
104
+ margin: "web:0px",
105
+ width: "web:auto",
106
+ height: "web:auto",
107
+ maxHeight: "web:100vh",
108
+ zIndex: "web:1",
109
+ render: "dialog"
110
+ });
111
+ var needsRepropagation = (0, import_portal.needsPortalRepropagation)();
112
+ var DialogPortalItem = function(param) {
113
+ var { context, children } = param;
114
+ var themeName = (0, import_core.useThemeName)();
115
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
116
+ var adaptContext = (0, import_adapt.useAdaptContext)(context.adaptScope);
117
+ var content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
118
+ name: themeName,
119
+ children
120
+ });
121
+ if (needsRepropagation) {
122
+ content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.ProvideAdaptContext, {
123
+ ...adaptContext,
124
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
125
+ ...context,
126
+ children: content
127
+ })
128
+ });
129
+ }
130
+ return isAdapted ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptPortalContents, {
131
+ scope: context.adaptScope,
132
+ children: content
133
+ }) : context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
134
+ hostName: "root",
135
+ children: content
136
+ }) : content;
137
+ };
138
+ var DialogPortal = (0, import_core.createRefComponent)(function(props, forwardedRef) {
139
+ var { scope, forceMount, children, ...frameProps } = props;
140
+ var dialogRef = React.useRef(null);
141
+ var ref = (0, import_compose_refs.composeRefs)(dialogRef, forwardedRef);
142
+ var context = useDialogContext(scope);
143
+ var portalContext = forceMount ? {
144
+ ...context,
145
+ forceMount: true
146
+ } : context;
147
+ var keepMounted = forceMount || context.keepChildrenMounted;
148
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
149
+ var isVisible = context.open || context.hasPresentParts;
150
+ if (import_constants.isWeb) {
151
+ (0, import_constants.useIsomorphicLayoutEffect)(function() {
152
+ var node = dialogRef.current;
153
+ if (!_instanceof(node, HTMLDialogElement)) return;
154
+ if (isVisible) {
155
+ var _node_show;
156
+ (_node_show = node.show) === null || _node_show === void 0 ? void 0 : _node_show.call(node);
157
+ } else {
158
+ var _node_close;
159
+ (_node_close = node.close) === null || _node_close === void 0 ? void 0 : _node_close.call(node);
160
+ }
161
+ }, [isVisible]);
162
+ }
163
+ var zIndex = (0, import_core.getExpandedShorthand)("zIndex", props);
164
+ var contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
165
+ zIndex: (0, import_portal.resolveViewZIndex)(zIndex),
166
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
167
+ scope: context.dialogScope,
168
+ ...portalContext,
169
+ children
170
+ })
171
+ });
172
+ var framedContents = !isVisible && !keepMounted && !isAdapted ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
173
+ disable: !context.open,
174
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalFrame, {
175
+ ref,
176
+ ...import_constants.isWeb && context.open && context.modal && { "aria-modal": true },
177
+ pointerEvents: context.open && context.modal ? "auto" : "none",
178
+ ...frameProps,
179
+ className: `_no_backdrop ` + (frameProps.className || ""),
180
+ children: contents
181
+ })
182
+ });
183
+ if (import_constants.isWeb) {
184
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.Portal, {
185
+ zIndex,
186
+ stackZIndex: 1e5,
187
+ passThrough: isAdapted,
188
+ hidden: !isVisible,
189
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PassthroughTheme, {
190
+ passThrough: isAdapted,
191
+ children: framedContents
192
+ })
193
+ });
194
+ }
195
+ return isAdapted ? framedContents : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalItem, {
196
+ context: portalContext,
197
+ children: framedContents
198
+ });
199
+ });
200
+ var PassthroughTheme = function(param) {
201
+ var { children, passThrough } = param;
202
+ var themeName = (0, import_core.useThemeName)();
203
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
204
+ passThrough,
205
+ name: themeName,
206
+ forceClassName: true,
207
+ children
208
+ });
209
+ };
210
+ function useDialogAnimationReporter(context) {
211
+ var onAnimationCompleteRef = React.useRef(context.onAnimationComplete);
212
+ onAnimationCompleteRef.current = context.onAnimationComplete;
213
+ var openRef = React.useRef(context.open);
214
+ var pendingTransitionRef = React.useRef(context.open ? true : null);
215
+ if (openRef.current !== context.open) {
216
+ openRef.current = context.open;
217
+ pendingTransitionRef.current = context.open;
218
+ }
219
+ var reportComplete = React.useCallback(function(open) {
220
+ var _onAnimationCompleteRef_current;
221
+ if (pendingTransitionRef.current !== open) return;
222
+ if (openRef.current !== open) return;
223
+ pendingTransitionRef.current = null;
224
+ (_onAnimationCompleteRef_current = onAnimationCompleteRef.current) === null || _onAnimationCompleteRef_current === void 0 ? void 0 : _onAnimationCompleteRef_current.call(onAnimationCompleteRef, { open });
225
+ }, []);
226
+ return React.useMemo(function() {
227
+ return {
228
+ onEnterComplete: function() {
229
+ return reportComplete(true);
230
+ },
231
+ onExitComplete: function() {
232
+ return reportComplete(false);
233
+ }
234
+ };
235
+ }, [reportComplete]);
236
+ }
237
+ function useDialogPartPresence(context, options) {
238
+ var [isFullyHidden, setIsFullyHidden] = React.useState(!context.open);
239
+ var reactId = React.useId();
240
+ var partPresenceId = `${context.contentId}-${options.id}-${reactId}`;
241
+ var keepMounted = options.forceMount || context.keepChildrenMounted;
242
+ var isPresent = context.open || !isFullyHidden;
243
+ (0, import_constants.useIsomorphicLayoutEffect)(function() {
244
+ if (context.open && isFullyHidden) {
245
+ setIsFullyHidden(false);
246
+ }
247
+ }, [context.open, isFullyHidden]);
248
+ (0, import_constants.useIsomorphicLayoutEffect)(function() {
249
+ if (options.disabled) return;
250
+ context.setPartPresence(partPresenceId, isPresent);
251
+ return function() {
252
+ context.setPartPresence(partPresenceId, false);
253
+ };
254
+ }, [
255
+ context.setPartPresence,
256
+ isPresent,
257
+ options.disabled,
258
+ partPresenceId
259
+ ]);
260
+ var onExitComplete = React.useCallback(function() {
261
+ var _options_onExitComplete;
262
+ setIsFullyHidden(true);
263
+ (_options_onExitComplete = options.onExitComplete) === null || _options_onExitComplete === void 0 ? void 0 : _options_onExitComplete.call(options);
264
+ }, [options.onExitComplete]);
265
+ return {
266
+ keepMounted,
267
+ onExitComplete,
268
+ shouldRender: Boolean(keepMounted || context.open || !isFullyHidden)
269
+ };
270
+ }
271
+ var OVERLAY_NAME = "DialogOverlay";
272
+ var DialogOverlayFrame = (0, import_core.styled)(import_stacks.YStack, {
273
+ displayName: OVERLAY_NAME,
274
+ zIndex: 1,
275
+ inset: 0,
276
+ position: "absolute",
277
+ pointerEvents: "auto",
278
+ variants: { open: {
279
+ true: { pointerEvents: "auto" },
280
+ false: { pointerEvents: "none" }
281
+ } }
282
+ });
283
+ var DialogOverlay = (0, import_core.createStyledHOC)(DialogOverlayFrame, function DialogOverlay2(param, forwardedRef) {
284
+ var { scope, ...props } = param;
285
+ var context = useDialogContext(scope);
286
+ var { forceMount = context.forceMount, ...overlayProps } = props;
287
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
288
+ var presence = useDialogPartPresence(context, {
289
+ disabled: isAdapted,
290
+ forceMount,
291
+ id: "overlay"
292
+ });
293
+ if (!forceMount && isAdapted) {
294
+ return null;
295
+ }
296
+ if (!presence.shouldRender) {
297
+ return null;
298
+ }
299
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate.Animate, {
300
+ type: "presence",
301
+ present: Boolean(context.open),
302
+ keepChildrenMounted: Boolean(presence.keepMounted),
303
+ onExitComplete: presence.onExitComplete,
304
+ passThrough: isAdapted,
305
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogOverlayFrame, {
306
+ "data-state": getState(context.open),
307
+ pointerEvents: context.open && context.modal ? "auto exit:none" : "none",
308
+ ...overlayProps,
309
+ ref: forwardedRef
310
+ }, `${context.contentId}-overlay`)
311
+ });
312
+ });
313
+ var CONTENT_NAME = "DialogContent";
314
+ var DialogContentFrame = (0, import_core.styled)(import_stacks.YStack, {
315
+ displayName: CONTENT_NAME,
316
+ zIndex: 2,
317
+ position: "relative",
318
+ pointerEvents: "auto",
319
+ variants: {
320
+ elevate: { true: {
321
+ shadowColor: "shadow-color",
322
+ shadowRadius: 24,
323
+ shadowOffset: {
324
+ width: 0,
325
+ height: 12
326
+ }
327
+ } },
328
+ bordered: { true: {
329
+ borderWidth: 1,
330
+ borderColor: "border-color"
331
+ } }
332
+ }
333
+ });
334
+ var DialogContent = (0, import_core.createStyledHOC)(DialogContentFrame, function DialogContent2(param, forwardedRef) {
335
+ var { scope, ...props } = param;
336
+ var context = useDialogContext(scope);
337
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
338
+ var reporter = useDialogAnimationReporter(context);
339
+ var onTransitionProp = props.onTransition;
340
+ var onTransition = React.useCallback(function(event) {
341
+ if (event.phase === "end" && event.cause === "enter") {
342
+ reporter.onEnterComplete();
343
+ }
344
+ onTransitionProp === null || onTransitionProp === void 0 ? void 0 : onTransitionProp(event);
345
+ }, [reporter.onEnterComplete, onTransitionProp]);
346
+ var presence = useDialogPartPresence(context, {
347
+ disabled: isAdapted,
348
+ forceMount: context.forceMount,
349
+ id: "content",
350
+ onExitComplete: reporter.onExitComplete
351
+ });
352
+ var contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentModal, {
353
+ context,
354
+ ...props,
355
+ onTransition,
356
+ ref: forwardedRef
357
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentNonModal, {
358
+ context,
359
+ ...props,
360
+ onTransition,
361
+ ref: forwardedRef
362
+ }) });
363
+ if (isAdapted) {
364
+ if (!import_constants.isWeb || context.disableRemoveScroll) {
365
+ return contents;
366
+ }
367
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
368
+ enabled: context.open && context.modal,
369
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
370
+ "data-remove-scroll-container": true,
371
+ className: "_dsp_contents",
372
+ children: contents
373
+ })
374
+ });
375
+ }
376
+ if (!presence.shouldRender) {
377
+ return null;
378
+ }
379
+ var animated = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_animate.Animate, {
380
+ type: "presence",
381
+ present: Boolean(context.open),
382
+ keepChildrenMounted: Boolean(presence.keepMounted),
383
+ onExitComplete: presence.onExitComplete,
384
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(React.Fragment, { children: contents }, context.contentId)
385
+ });
386
+ if (!import_constants.isWeb || context.disableRemoveScroll) {
387
+ return animated;
388
+ }
389
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
390
+ enabled: context.open && context.modal,
391
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
392
+ "data-remove-scroll-container": true,
393
+ className: "_dsp_contents",
394
+ children: animated
395
+ })
396
+ });
397
+ });
398
+ var DialogContentModal = (0, import_core.createRefComponent)(function(param, forwardedRef) {
399
+ var { children, context: contextProp, ...props } = param;
400
+ var context = useDialogContext(contextProp.dialogScope);
401
+ var contentRef = React.useRef(null);
402
+ var composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.contentRef, contentRef);
403
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentImpl, {
404
+ ...props,
405
+ context,
406
+ ref: composedRefs,
407
+ trapFocus: context.open,
408
+ disableOutsidePointerEvents: true,
409
+ onCloseAutoFocus: (0, import_helpers.composeEventHandlers)(props.onCloseAutoFocus, function(event) {
410
+ var _context_triggerRef_current;
411
+ event.cancel();
412
+ (_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 ? void 0 : _context_triggerRef_current.focus();
413
+ }),
414
+ onPointerDownOutside: (0, import_helpers.composeEventHandlers)(props.onPointerDownOutside, function(event) {
415
+ var originalEvent = event.event;
416
+ if (!originalEvent) return;
417
+ var ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
418
+ var isRightClick = originalEvent.button === 2 || ctrlLeftClick;
419
+ if (isRightClick) event.cancel();
420
+ }),
421
+ onFocusOutside: (0, import_helpers.composeEventHandlers)(props.onFocusOutside, function(event) {
422
+ return event.cancel();
423
+ }),
424
+ outlineStyle: "none",
425
+ children
426
+ });
427
+ });
428
+ var DialogContentNonModal = (0, import_core.createRefComponent)(function(props, forwardedRef) {
429
+ var context = useDialogContext(props.context.dialogScope);
430
+ var hasInteractedOutsideRef = React.useRef(false);
431
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentImpl, {
432
+ ...props,
433
+ context,
434
+ ref: forwardedRef,
435
+ trapFocus: false,
436
+ disableOutsidePointerEvents: false,
437
+ onCloseAutoFocus: function(event) {
438
+ var _props_onCloseAutoFocus;
439
+ (_props_onCloseAutoFocus = props.onCloseAutoFocus) === null || _props_onCloseAutoFocus === void 0 ? void 0 : _props_onCloseAutoFocus.call(props, event);
440
+ if (!event.isCanceled) {
441
+ if (!hasInteractedOutsideRef.current) {
442
+ var _props_context_triggerRef_current;
443
+ (_props_context_triggerRef_current = props.context.triggerRef.current) === null || _props_context_triggerRef_current === void 0 ? void 0 : _props_context_triggerRef_current.focus();
444
+ }
445
+ event.cancel();
446
+ }
447
+ hasInteractedOutsideRef.current = false;
448
+ },
449
+ onInteractOutside: function(event) {
450
+ var _props_onInteractOutside, _event_event;
451
+ (_props_onInteractOutside = props.onInteractOutside) === null || _props_onInteractOutside === void 0 ? void 0 : _props_onInteractOutside.call(props, event);
452
+ if (!event.isCanceled) hasInteractedOutsideRef.current = true;
453
+ var target = (_event_event = event.event) === null || _event_event === void 0 ? void 0 : _event_event.target;
454
+ var trigger = props.context.triggerRef.current;
455
+ if (!target || !_instanceof(trigger, HTMLElement)) return;
456
+ var targetIsTrigger = trigger.contains(target);
457
+ if (targetIsTrigger) event.cancel();
458
+ }
459
+ });
460
+ });
461
+ var DialogContentImpl = (0, import_core.createRefComponent)(function(props, forwardedRef) {
462
+ var { trapFocus, onOpenAutoFocus, onCloseAutoFocus, disableOutsidePointerEvents, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, context, onTransition, ...contentProps } = props;
463
+ var contentRef = React.useRef(null);
464
+ var composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef);
465
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
466
+ var adaptContext = (0, import_adapt.useAdaptContext)(context.adaptScope);
467
+ if (isAdapted) {
468
+ if (!context.open && !context.keepChildrenMounted && adaptContext.targetFullyHidden) {
469
+ return null;
470
+ }
471
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogPortalItem, {
472
+ context,
473
+ children: contentProps.children
474
+ });
475
+ }
476
+ var contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentFrame, {
477
+ ref: composedRefs,
478
+ id: context.contentId,
479
+ role: "dialog",
480
+ "aria-modal": context.modal,
481
+ "aria-describedby": context.descriptionId,
482
+ "aria-labelledby": context.titleId,
483
+ "data-state": getState(context.open),
484
+ pointerEvents: context.open ? "auto" : "none",
485
+ onTransition,
486
+ ...contentProps
487
+ });
488
+ if (!import_constants.isWeb) {
489
+ return contents;
490
+ }
491
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
492
+ disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
493
+ forceUnmount: !context.open,
494
+ onEscapeKeyDown,
495
+ onPointerDownOutside,
496
+ onFocusOutside,
497
+ onInteractOutside,
498
+ onDismiss: function() {
499
+ var _context_onOpenChange;
500
+ return context === null || context === void 0 ? void 0 : (_context_onOpenChange = context.onOpenChange) === null || _context_onOpenChange === void 0 ? void 0 : _context_onOpenChange.call(context, false);
501
+ },
502
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
503
+ loop: true,
504
+ enabled: context.open,
505
+ trapped: trapFocus,
506
+ onMountAutoFocus: onOpenAutoFocus,
507
+ forceUnmount: !context.open,
508
+ onUnmountAutoFocus: onCloseAutoFocus,
509
+ children: contents
510
+ })
511
+ }), process.env.NODE_ENV === "development" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleWarning, { titleId: context.titleId }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionWarning, {
512
+ contentRef,
513
+ descriptionId: context.descriptionId
514
+ })] })] });
515
+ });
516
+ var DialogTitleFrame = (0, import_core.styled)(import_text.H2, { displayName: "DialogTitle" });
517
+ var DialogTitle = (0, import_core.createStyledHOC)(DialogTitleFrame, function DialogTitle2(props, forwardedRef) {
518
+ var { scope, ...titleProps } = props;
519
+ var context = useDialogContext(scope);
520
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitleFrame, {
521
+ id: context.titleId,
522
+ ...titleProps,
523
+ ref: forwardedRef
524
+ });
525
+ });
526
+ var DialogDescriptionFrame = (0, import_core.styled)(import_text.Paragraph, { displayName: "DialogDescription" });
527
+ var DialogDescription = (0, import_core.createStyledHOC)(DialogDescriptionFrame, function DialogDescription2(props, forwardedRef) {
528
+ var { scope, ...descriptionProps } = props;
529
+ var context = useDialogContext(scope);
530
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogDescriptionFrame, {
531
+ id: context.descriptionId,
532
+ ...descriptionProps,
533
+ ref: forwardedRef
534
+ });
535
+ });
536
+ var CLOSE_NAME = "DialogClose";
537
+ var DialogCloseFrame = (0, import_core.styled)(import_core.View, {
538
+ displayName: CLOSE_NAME,
539
+ render: "button"
540
+ });
541
+ var DialogClose = (0, import_core.createStyledHOC)(DialogCloseFrame, function(props, forwardedRef) {
542
+ var { scope, displayWhenAdapted, ...closeProps } = props;
543
+ var context = useDialogContext(scope);
544
+ var isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
545
+ var isInsideButton = React.useContext(import_stacks.ButtonNestingContext);
546
+ if (isAdapted && !displayWhenAdapted) {
547
+ return null;
548
+ }
549
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogCloseFrame, {
550
+ "aria-label": "Dialog Close",
551
+ render: isInsideButton ? "span" : "button",
552
+ ...closeProps,
553
+ ref: forwardedRef,
554
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress, function() {
555
+ context.onOpenChange(false);
556
+ })
557
+ });
558
+ });
559
+ function getState(open) {
560
+ return open ? "open" : "closed";
561
+ }
562
+ var TITLE_WARNING_NAME = "DialogTitleWarning";
563
+ var [DialogWarningProvider, useWarningContext] = (0, import_create_context.createContext)(TITLE_WARNING_NAME, {
564
+ contentName: CONTENT_NAME,
565
+ titleName: "DialogTitle",
566
+ docsSlug: "dialog"
567
+ });
568
+ var TitleWarning = function(param) {
569
+ var { titleId } = param;
570
+ if (process.env.NODE_ENV === "development") {
571
+ var titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
572
+ var MESSAGE = `\`${titleWarningContext.contentName}\` wants a \`${titleWarningContext.titleName}\` to be accessible. If you want to hide the \`${titleWarningContext.titleName}\`, wrap it with <VisuallyHidden />.`;
573
+ React.useEffect(function() {
574
+ if (!import_constants.isWeb) return;
575
+ if (titleId) {
576
+ var hasTitle = document.getElementById(titleId);
577
+ if (!hasTitle) {
578
+ console.warn(MESSAGE);
579
+ }
580
+ }
581
+ }, [MESSAGE, titleId]);
582
+ }
583
+ return null;
584
+ };
585
+ var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
586
+ var DescriptionWarning = function(param) {
587
+ var { contentRef, descriptionId } = param;
588
+ if (process.env.NODE_ENV === "development") {
589
+ var descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
590
+ var MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
591
+ React.useEffect(function() {
592
+ if (!import_constants.isWeb) return;
593
+ var contentNode = contentRef.current;
594
+ if (!_instanceof(contentNode, HTMLElement)) {
595
+ return;
596
+ }
597
+ var describedById = contentNode.getAttribute("aria-describedby");
598
+ if (descriptionId && describedById) {
599
+ var hasDescription = document.getElementById(descriptionId);
600
+ if (!hasDescription) {
601
+ console.warn(MESSAGE);
602
+ }
603
+ }
604
+ }, [
605
+ MESSAGE,
606
+ contentRef,
607
+ descriptionId
608
+ ]);
609
+ }
610
+ return null;
611
+ };
612
+ var Dialog = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)(function Dialog2(props) {
613
+ var { scope = "", children, open: openProp, defaultOpen = false, onOpenChange, modal = true, keepChildrenMounted, disableRemoveScroll = false, onAnimationComplete } = props;
614
+ var baseId = React.useId();
615
+ var dialogId = `Dialog-${scope}-${baseId}`;
616
+ var contentId = `${dialogId}-content`;
617
+ var titleId = `${dialogId}-title`;
618
+ var descriptionId = `${dialogId}-description`;
619
+ var triggerRef = React.useRef(null);
620
+ var contentRef = React.useRef(null);
621
+ var presentPartIdsRef = React.useRef(/* @__PURE__ */ new Set());
622
+ var [presentPartCount, setPresentPartCount] = React.useState(0);
623
+ var [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
624
+ prop: openProp,
625
+ defaultProp: defaultOpen,
626
+ onChange: onOpenChange
627
+ });
628
+ var onOpenToggle = React.useCallback(function() {
629
+ setOpen(function(prevOpen) {
630
+ return !prevOpen;
631
+ });
632
+ }, [setOpen]);
633
+ var adaptScope = `DialogAdapt${scope}`;
634
+ var setPartPresence = React.useCallback(function(id, present) {
635
+ var presentPartIds = presentPartIdsRef.current;
636
+ var hasPart = presentPartIds.has(id);
637
+ if (present && !hasPart) {
638
+ presentPartIds.add(id);
639
+ setPresentPartCount(presentPartIds.size);
640
+ } else if (!present && hasPart) {
641
+ presentPartIds.delete(id);
642
+ setPresentPartCount(presentPartIds.size);
643
+ }
644
+ }, []);
645
+ var context = {
646
+ dialogScope: scope,
647
+ adaptScope,
648
+ triggerRef,
649
+ contentRef,
650
+ contentId,
651
+ titleId,
652
+ descriptionId,
653
+ open,
654
+ onOpenChange: setOpen,
655
+ onOpenToggle,
656
+ modal,
657
+ keepChildrenMounted,
658
+ disableRemoveScroll,
659
+ hasPresentParts: presentPartCount > 0,
660
+ setPartPresence,
661
+ onAnimationComplete
662
+ };
663
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, {
664
+ scope: adaptScope,
665
+ open,
666
+ onOpenChange: setOpen,
667
+ state: context,
668
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogProvider, {
669
+ scope,
670
+ ...context,
671
+ children
672
+ })
673
+ });
674
+ }), {
675
+ Trigger: DialogTrigger,
676
+ Portal: DialogPortal,
677
+ Overlay: DialogOverlay,
678
+ Content: DialogContent,
679
+ Title: DialogTitle,
680
+ Description: DialogDescription,
681
+ Close: DialogClose,
682
+ FocusScope: import_focus_scope.FocusScopeController,
683
+ Adapt: import_adapt.Adapt
684
+ });