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