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