@tamagui/dialog 1.130.7 → 1.131.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.
@@ -34,15 +34,17 @@ __export(Dialog_exports, {
34
34
  Dialog: () => Dialog,
35
35
  DialogClose: () => DialogClose,
36
36
  DialogContent: () => DialogContent,
37
+ DialogContext: () => DialogContext,
37
38
  DialogDescription: () => DialogDescription,
38
39
  DialogOverlay: () => DialogOverlay,
39
40
  DialogOverlayFrame: () => DialogOverlayFrame,
40
41
  DialogPortal: () => DialogPortal,
41
42
  DialogPortalFrame: () => DialogPortalFrame,
43
+ DialogProvider: () => DialogProvider,
42
44
  DialogTitle: () => DialogTitle,
43
45
  DialogTrigger: () => DialogTrigger,
44
46
  DialogWarningProvider: () => DialogWarningProvider,
45
- createDialogScope: () => createDialogScope
47
+ useDialogContext: () => useDialogContext
46
48
  });
47
49
  module.exports = __toCommonJS(Dialog_exports);
48
50
  var import_adapt = require("@tamagui/adapt"),
@@ -64,20 +66,23 @@ var import_adapt = require("@tamagui/adapt"),
64
66
  import_z_index_stack = require("@tamagui/z-index-stack"),
65
67
  React = __toESM(require("react")),
66
68
  import_jsx_runtime = require("react/jsx-runtime");
67
- const DIALOG_NAME = "Dialog",
68
- [createDialogContext, createDialogScope] = (0, import_create_context.createContextScope)(DIALOG_NAME),
69
- [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME),
70
- TRIGGER_NAME = "DialogTrigger",
69
+ const DialogContext = (0, import_core.createStyledContext)(
70
+ // since we always provide this we can avoid setting here
71
+ {}, "Dialog__"),
72
+ {
73
+ useStyledContext: useDialogContext,
74
+ Provider: DialogProvider
75
+ } = DialogContext,
71
76
  DialogTriggerFrame = (0, import_core.styled)(import_core.View, {
72
- name: TRIGGER_NAME
77
+ name: "DialogTrigger"
73
78
  }),
74
79
  DialogTrigger = DialogTriggerFrame.styleable(function (props, forwardedRef) {
75
80
  const {
76
- __scopeDialog,
81
+ scope,
77
82
  ...triggerProps
78
83
  } = props,
79
84
  isInsideButton = React.useContext(import_stacks.ButtonNestingContext),
80
- context = useDialogContext(TRIGGER_NAME, __scopeDialog),
85
+ context = useDialogContext(scope),
81
86
  composedTriggerRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
82
87
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
83
88
  value: !0,
@@ -92,12 +97,8 @@ const DIALOG_NAME = "Dialog",
92
97
  onPress: (0, import_helpers.composeEventHandlers)(props.onPress, context.onOpenToggle)
93
98
  })
94
99
  });
95
- }),
96
- PORTAL_NAME = "DialogPortal",
97
- [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
98
- forceMount: void 0
99
- }),
100
- DialogPortalFrame = (0, import_core.styled)(import_stacks.YStack, {
100
+ });
101
+ const DialogPortalFrame = (0, import_core.styled)(import_stacks.YStack, {
101
102
  pointerEvents: "none",
102
103
  variants: {
103
104
  unstyled: {
@@ -116,50 +117,43 @@ const DIALOG_NAME = "Dialog",
116
117
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
117
118
  }
118
119
  }),
119
- DialogPortalItem = props => {
120
- const {
121
- __scopeDialog,
122
- children,
123
- space,
124
- spaceDirection,
125
- separator
126
- } = props,
127
- themeName = (0, import_core.useThemeName)(),
128
- context = useDialogContext(PORTAL_NAME, props.__scopeDialog),
129
- isAdapted = (0, import_adapt.useAdaptIsActive)();
130
- let childrenSpaced = children;
131
- (space || separator) && (childrenSpaced = (0, import_core.spacedChildren)({
132
- children,
133
- separator,
134
- space,
135
- direction: spaceDirection
136
- }));
137
- const content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogProvider, {
138
- scope: __scopeDialog,
139
- ...context,
140
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
141
- name: themeName,
142
- children: childrenSpaced
143
- })
120
+ needsRepropagation = import_constants.isAndroid || import_constants.isIos && !import_portal.USE_NATIVE_PORTAL,
121
+ DialogPortalItem = ({
122
+ context,
123
+ children
124
+ }) => {
125
+ const themeName = (0, import_core.useThemeName)(),
126
+ isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope),
127
+ adaptContext = (0, import_adapt.useAdaptContext)(context.adaptScope);
128
+ let content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
129
+ name: themeName,
130
+ children
144
131
  });
145
- return isAdapted ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptPortalContents, {
132
+ return needsRepropagation && (content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.ProvideAdaptContext, {
133
+ ...adaptContext,
134
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogProvider, {
135
+ ...context,
136
+ children: content
137
+ })
138
+ })), isAdapted ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptPortalContents, {
139
+ scope: context.adaptScope,
146
140
  children: content
147
141
  }) : context.modal ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
148
- hostName: context.modal ? "root" : context.adaptName,
142
+ hostName: context.modal ? "root" : context.adaptScope,
149
143
  children: content
150
144
  }) : content;
151
145
  },
152
146
  DialogPortal = props => {
153
147
  const {
154
- __scopeDialog,
148
+ scope,
155
149
  forceMount,
156
150
  children,
157
151
  ...frameProps
158
152
  } = props,
159
- context = useDialogContext(PORTAL_NAME, __scopeDialog),
153
+ context = useDialogContext(scope),
160
154
  isShowing = forceMount || context.open,
161
155
  [isFullyHidden, setIsFullyHidden] = React.useState(!isShowing),
162
- isAdapted = (0, import_adapt.useAdaptIsActive)();
156
+ isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
163
157
  isShowing && isFullyHidden && setIsFullyHidden(!1);
164
158
  const handleExitComplete = React.useCallback(() => {
165
159
  setIsFullyHidden(!0);
@@ -168,36 +162,37 @@ const DIALOG_NAME = "Dialog",
168
162
  contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_z_index_stack.StackZIndexContext, {
169
163
  zIndex: (0, import_portal.resolveViewZIndex)(zIndex),
170
164
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
165
+ passThrough: isAdapted,
171
166
  onExitComplete: handleExitComplete,
172
167
  children: isShowing || isAdapted ? children : null
173
168
  })
174
169
  });
175
170
  if (isFullyHidden && !isAdapted) return null;
176
- const framedContents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(PortalProvider, {
177
- scope: __scopeDialog,
178
- forceMount,
179
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalFrame, {
180
- pointerEvents: isShowing ? "auto" : "none",
181
- ...frameProps,
182
- children: contents
183
- })
171
+ const framedContents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalFrame, {
172
+ pointerEvents: isShowing ? "auto" : "none",
173
+ ...frameProps,
174
+ children: contents
184
175
  });
185
176
  return import_constants.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
186
177
  zIndex,
187
178
  stackZIndex: 1e3,
179
+ passThrough: isAdapted,
188
180
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PassthroughTheme, {
181
+ passThrough: isAdapted,
189
182
  children: framedContents
190
183
  })
191
184
  }) : isAdapted ? framedContents : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalItem, {
192
- __scopeDialog,
185
+ context,
193
186
  children: framedContents
194
187
  });
195
188
  },
196
189
  PassthroughTheme = ({
197
- children
190
+ children,
191
+ passThrough
198
192
  }) => {
199
193
  const themeName = (0, import_core.useThemeName)();
200
194
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
195
+ passThrough,
201
196
  name: themeName,
202
197
  forceClassName: !0,
203
198
  children
@@ -207,24 +202,23 @@ const DIALOG_NAME = "Dialog",
207
202
  DialogOverlayFrame = (0, import_core.styled)(import_sheet.Overlay, {
208
203
  name: OVERLAY_NAME
209
204
  }),
210
- DialogOverlay = DialogOverlayFrame.extractable(React.forwardRef(function ({
211
- __scopeDialog,
205
+ DialogOverlay = DialogOverlayFrame.styleable(function ({
206
+ scope,
212
207
  ...props
213
208
  }, forwardedRef) {
214
- const portalContext = usePortalContext(OVERLAY_NAME, __scopeDialog),
209
+ const context = useDialogContext(scope),
215
210
  {
216
- forceMount = portalContext.forceMount,
211
+ forceMount = context.forceMount,
217
212
  ...overlayProps
218
213
  } = props,
219
- context = useDialogContext(OVERLAY_NAME, __scopeDialog),
220
- isAdapted = (0, import_adapt.useAdaptIsActive)();
214
+ isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
221
215
  return !forceMount && (!context.modal || isAdapted) ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogOverlayFrame, {
222
216
  "data-state": getState(context.open),
223
217
  pointerEvents: context.open ? "auto" : "none",
224
218
  ...overlayProps,
225
219
  ref: forwardedRef
226
220
  });
227
- })),
221
+ }),
228
222
  CONTENT_NAME = "DialogContent",
229
223
  DialogContentFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
230
224
  name: CONTENT_NAME,
@@ -249,16 +243,15 @@ const DIALOG_NAME = "Dialog",
249
243
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
250
244
  }
251
245
  }),
252
- DialogContent = DialogContentFrame.extractable(React.forwardRef(function ({
253
- __scopeDialog,
246
+ DialogContent = DialogContentFrame.styleable(function ({
247
+ scope,
254
248
  ...props
255
249
  }, forwardedRef) {
256
- const portalContext = usePortalContext(CONTENT_NAME, __scopeDialog),
250
+ const context = useDialogContext(scope),
257
251
  {
258
- forceMount = portalContext.forceMount,
252
+ forceMount = context.forceMount,
259
253
  ...contentProps
260
254
  } = props,
261
- context = useDialogContext(CONTENT_NAME, __scopeDialog),
262
255
  contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
263
256
  children: context.modal ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentModal, {
264
257
  context,
@@ -278,7 +271,7 @@ const DIALOG_NAME = "Dialog",
278
271
  children: contents
279
272
  })
280
273
  });
281
- })),
274
+ }),
282
275
  DialogContentModal = React.forwardRef(({
283
276
  children,
284
277
  context,
@@ -332,7 +325,6 @@ const DIALOG_NAME = "Dialog",
332
325
  }),
333
326
  DialogContentImpl = React.forwardRef((props, forwardedRef) => {
334
327
  const {
335
- __scopeDialog,
336
328
  trapFocus,
337
329
  onOpenAutoFocus,
338
330
  onCloseAutoFocus,
@@ -348,7 +340,8 @@ const DIALOG_NAME = "Dialog",
348
340
  // TODO react 19 type workaround
349
341
  void 0),
350
342
  composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef);
351
- if ((0, import_adapt.useAdaptIsActive)()) return !import_constants.isWeb && !context.open ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalItem, {
343
+ if ((0, import_adapt.useAdaptIsActive)(context.adaptScope)) return !import_constants.isWeb && !context.open ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogPortalItem, {
344
+ context,
352
345
  children: contentProps.children
353
346
  });
354
347
  const contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogContentFrame, {
@@ -392,10 +385,10 @@ const DIALOG_NAME = "Dialog",
392
385
  }),
393
386
  DialogTitle = DialogTitleFrame.styleable(function (props, forwardedRef) {
394
387
  const {
395
- __scopeDialog,
388
+ scope,
396
389
  ...titleProps
397
390
  } = props,
398
- context = useDialogContext("DialogTitle", __scopeDialog);
391
+ context = useDialogContext(scope);
399
392
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogTitleFrame, {
400
393
  id: context.titleId,
401
394
  ...titleProps,
@@ -405,13 +398,12 @@ const DIALOG_NAME = "Dialog",
405
398
  DialogDescriptionFrame = (0, import_core.styled)(import_text.Paragraph, {
406
399
  name: "DialogDescription"
407
400
  }),
408
- DESCRIPTION_NAME = "DialogDescription",
409
401
  DialogDescription = DialogDescriptionFrame.styleable(function (props, forwardedRef) {
410
402
  const {
411
- __scopeDialog,
403
+ scope,
412
404
  ...descriptionProps
413
405
  } = props,
414
- context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
406
+ context = useDialogContext(scope);
415
407
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogDescriptionFrame, {
416
408
  id: context.descriptionId,
417
409
  ...descriptionProps,
@@ -425,15 +417,12 @@ const DIALOG_NAME = "Dialog",
425
417
  }),
426
418
  DialogClose = DialogCloseFrame.styleable((props, forwardedRef) => {
427
419
  const {
428
- __scopeDialog,
420
+ scope,
429
421
  displayWhenAdapted,
430
422
  ...closeProps
431
423
  } = props,
432
- context = useDialogContext(CLOSE_NAME, __scopeDialog, {
433
- warn: !1,
434
- fallback: {}
435
- }),
436
- isAdapted = (0, import_adapt.useAdaptIsActive)(),
424
+ context = useDialogContext(scope),
425
+ isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope),
437
426
  isInsideButton = React.useContext(import_stacks.ButtonNestingContext);
438
427
  return isAdapted && !displayWhenAdapted ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogCloseFrame, {
439
428
  accessibilityLabel: "Dialog Close",
@@ -485,7 +474,7 @@ const TITLE_WARNING_NAME = "DialogTitleWarning",
485
474
  },
486
475
  Dialog = (0, import_helpers.withStaticProperties)(React.forwardRef(function (props, ref) {
487
476
  const {
488
- __scopeDialog,
477
+ scope = "",
489
478
  children,
490
479
  open: openProp,
491
480
  defaultOpen = !1,
@@ -494,15 +483,10 @@ const TITLE_WARNING_NAME = "DialogTitleWarning",
494
483
  disableRemoveScroll = !1
495
484
  } = props,
496
485
  baseId = React.useId(),
497
- scopeId = `scope-${baseId}`,
498
- contentId = `content-${baseId}`,
499
- titleId = `title-${baseId}`,
500
- descriptionId = `description-${baseId}`,
501
- scopeKey = __scopeDialog ? Object.keys(__scopeDialog)[0] : scopeId,
502
- adaptName = getAdaptName({
503
- scopeKey,
504
- contentId
505
- }),
486
+ dialogId = `Dialog-${scope}-${baseId}`,
487
+ contentId = `${dialogId}-content`,
488
+ titleId = `${dialogId}-title`,
489
+ descriptionId = `${dialogId}-description`,
506
490
  triggerRef = React.useRef(null),
507
491
  contentRef = React.useRef(null),
508
492
  [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
@@ -513,9 +497,10 @@ const TITLE_WARNING_NAME = "DialogTitleWarning",
513
497
  onOpenToggle = React.useCallback(() => {
514
498
  setOpen(prevOpen => !prevOpen);
515
499
  }, [setOpen]),
500
+ adaptScope = `DialogAdapt${scope}`,
516
501
  context = {
517
- scope: __scopeDialog,
518
- scopeKey,
502
+ dialogScope: scope,
503
+ adaptScope,
519
504
  triggerRef,
520
505
  contentRef,
521
506
  contentId,
@@ -525,21 +510,21 @@ const TITLE_WARNING_NAME = "DialogTitleWarning",
525
510
  onOpenChange: setOpen,
526
511
  onOpenToggle,
527
512
  modal,
528
- disableRemoveScroll,
529
- adaptName
513
+ disableRemoveScroll
530
514
  };
531
515
  return React.useImperativeHandle(ref, () => ({
532
516
  open: setOpen
533
517
  }), [setOpen]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, {
534
- scope: adaptName,
518
+ scope: adaptScope,
535
519
  portal: {
536
520
  forwardProps: props
537
521
  },
538
522
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogProvider, {
523
+ scope,
539
524
  ...context,
540
525
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DialogSheetController, {
541
526
  onOpenChange: setOpen,
542
- __scopeDialog,
527
+ scope,
543
528
  children
544
529
  })
545
530
  })
@@ -555,20 +540,16 @@ const TITLE_WARNING_NAME = "DialogTitleWarning",
555
540
  Sheet: import_sheet.Sheet.Controlled,
556
541
  FocusScope: import_focus_scope.FocusScopeController,
557
542
  Adapt: import_adapt.Adapt
558
- }),
559
- getAdaptName = ({
560
- scopeKey,
561
- contentId
562
- }) => `${scopeKey || contentId}DialogAdapt`,
563
- DialogSheetController = props => {
564
- const context = useDialogContext("DialogSheetController", props.__scopeDialog),
565
- isAdapted = (0, import_adapt.useAdaptIsActive)();
566
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_sheet.SheetController, {
567
- onOpenChange: val => {
568
- isAdapted && props.onOpenChange?.(val);
569
- },
570
- open: context.open,
571
- hidden: !isAdapted,
572
- children: props.children
573
- });
574
- };
543
+ });
544
+ const DialogSheetController = props => {
545
+ const context = useDialogContext(props.scope),
546
+ isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
547
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_sheet.SheetController, {
548
+ onOpenChange: val => {
549
+ isAdapted && props.onOpenChange?.(val);
550
+ },
551
+ open: context.open,
552
+ hidden: !isAdapted,
553
+ children: props.children
554
+ });
555
+ };