@tamagui/dialog 1.1.8 → 1.1.9

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.
@@ -37,16 +37,19 @@ const DialogTrigger = React.forwardRef(
37
37
  const { __scopeDialog, ...triggerProps } = props;
38
38
  const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
39
39
  const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
40
- return /* @__PURE__ */ jsx(DialogTriggerFrame, {
41
- tag: "button",
42
- "aria-haspopup": "dialog",
43
- "aria-expanded": context.open,
44
- "aria-controls": context.contentId,
45
- "data-state": getState(context.open),
46
- ...triggerProps,
47
- ref: composedTriggerRef,
48
- onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
49
- });
40
+ return /* @__PURE__ */ jsx(
41
+ DialogTriggerFrame,
42
+ {
43
+ tag: "button",
44
+ "aria-haspopup": "dialog",
45
+ "aria-expanded": context.open,
46
+ "aria-controls": context.contentId,
47
+ "data-state": getState(context.open),
48
+ ...triggerProps,
49
+ ref: composedTriggerRef,
50
+ onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
51
+ }
52
+ );
50
53
  }
51
54
  );
52
55
  DialogTrigger.displayName = TRIGGER_NAME;
@@ -70,14 +73,7 @@ const DialogPortalFrame = styled(YStack, {
70
73
  const DialogPortalItem = (props) => {
71
74
  const themeName = useThemeName();
72
75
  const context = useDialogContext(PORTAL_NAME, props.__scopeDialog);
73
- return /* @__PURE__ */ jsx(PortalItem, {
74
- hostName: props.hostName,
75
- children: /* @__PURE__ */ jsx(DialogPortalItemContent, {
76
- ...props,
77
- themeName,
78
- context
79
- })
80
- });
76
+ return /* @__PURE__ */ jsx(PortalItem, { hostName: props.hostName, children: /* @__PURE__ */ jsx(DialogPortalItemContent, { ...props, themeName, context }) });
81
77
  };
82
78
  function DialogPortalItemContent(props) {
83
79
  const {
@@ -98,14 +94,7 @@ function DialogPortalItemContent(props) {
98
94
  direction: spaceDirection
99
95
  });
100
96
  }
101
- return /* @__PURE__ */ jsx(DialogProvider, {
102
- scope: __scopeDialog,
103
- ...context,
104
- children: /* @__PURE__ */ jsx(Theme, {
105
- name: themeName,
106
- children: childrenSpaced
107
- })
108
- });
97
+ return /* @__PURE__ */ jsx(DialogProvider, { scope: __scopeDialog, ...context, children: /* @__PURE__ */ jsx(Theme, { name: themeName, children: childrenSpaced }) });
109
98
  }
110
99
  const DialogPortal = (props) => {
111
100
  const { __scopeDialog, forceMount, children, ...frameProps } = props;
@@ -115,12 +104,15 @@ const DialogPortal = (props) => {
115
104
  if (isShowing && isFullyHidden) {
116
105
  setIsFullyHidden(false);
117
106
  }
118
- const contents = /* @__PURE__ */ jsx(AnimatePresence, {
119
- onExitComplete: () => {
120
- setIsFullyHidden(true);
121
- },
122
- children: isShowing ? children : null
123
- });
107
+ const contents = /* @__PURE__ */ jsx(
108
+ AnimatePresence,
109
+ {
110
+ onExitComplete: () => {
111
+ setIsFullyHidden(true);
112
+ },
113
+ children: isShowing ? children : null
114
+ }
115
+ );
124
116
  const isSheet = useShowDialogSheet(context);
125
117
  if (isSheet) {
126
118
  return children;
@@ -129,18 +121,7 @@ const DialogPortal = (props) => {
129
121
  if (isFullyHidden) {
130
122
  return null;
131
123
  }
132
- return /* @__PURE__ */ jsx(DialogPortalItem, {
133
- __scopeDialog,
134
- children: /* @__PURE__ */ jsx(PortalProvider, {
135
- scope: __scopeDialog,
136
- forceMount,
137
- children: /* @__PURE__ */ jsx(DialogPortalFrame, {
138
- pointerEvents: isShowing ? "auto" : "none",
139
- ...frameProps,
140
- children: contents
141
- })
142
- })
143
- });
124
+ return /* @__PURE__ */ jsx(DialogPortalItem, { __scopeDialog, children: /* @__PURE__ */ jsx(PortalProvider, { scope: __scopeDialog, forceMount, children: /* @__PURE__ */ jsx(DialogPortalFrame, { pointerEvents: isShowing ? "auto" : "none", ...frameProps, children: contents }) }) });
144
125
  }
145
126
  return contents;
146
127
  };
@@ -162,23 +143,26 @@ const DialogOverlay = React.forwardRef(
162
143
  return null;
163
144
  }
164
145
  }
165
- return /* @__PURE__ */ jsx(DialogOverlayImpl, {
166
- context,
167
- ...overlayProps,
168
- ref: forwardedRef
169
- });
146
+ return /* @__PURE__ */ jsx(DialogOverlayImpl, { context, ...overlayProps, ref: forwardedRef });
170
147
  }
171
148
  );
172
149
  DialogOverlay.displayName = OVERLAY_NAME;
173
150
  const DialogOverlayImpl = React.forwardRef(
174
151
  (props, forwardedRef) => {
175
152
  const { context, ...overlayProps } = props;
176
- return /* @__PURE__ */ jsx(DialogOverlayFrame, {
177
- "data-state": getState(context.open),
178
- pointerEvents: context.open ? "auto" : "none",
179
- ...overlayProps,
180
- ref: forwardedRef
181
- });
153
+ return (
154
+ // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
155
+ // ie. when `Overlay` and `Content` are siblings
156
+ /* @__PURE__ */ jsx(
157
+ DialogOverlayFrame,
158
+ {
159
+ "data-state": getState(context.open),
160
+ pointerEvents: context.open ? "auto" : "none",
161
+ ...overlayProps,
162
+ ref: forwardedRef
163
+ }
164
+ )
165
+ );
182
166
  }
183
167
  );
184
168
  const CONTENT_NAME = "DialogContent";
@@ -207,29 +191,21 @@ const DialogContent = DialogContentFrame.extractable(
207
191
  const portalContext = usePortalContext(CONTENT_NAME, __scopeDialog);
208
192
  const { forceMount = portalContext.forceMount, ...contentProps } = props;
209
193
  const context = useDialogContext(CONTENT_NAME, __scopeDialog);
210
- const contents = context.modal ? /* @__PURE__ */ jsx(DialogContentModal, {
211
- context,
212
- ...contentProps,
213
- ref: forwardedRef
214
- }) : /* @__PURE__ */ jsx(DialogContentNonModal, {
215
- context,
216
- ...contentProps,
217
- ref: forwardedRef
218
- });
194
+ const contents = context.modal ? /* @__PURE__ */ jsx(DialogContentModal, { context, ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(DialogContentNonModal, { context, ...contentProps, ref: forwardedRef });
219
195
  if (!isWeb) {
220
196
  return contents;
221
197
  }
222
- return /* @__PURE__ */ jsx(RemoveScroll, {
223
- forwardProps: true,
224
- enabled: context.open,
225
- allowPinchZoom: context.allowPinchZoom,
226
- shards: [context.contentRef],
227
- removeScrollBar: false,
228
- children: /* @__PURE__ */ jsx("div", {
229
- className: "_dsp_contents",
230
- children: contents
231
- })
232
- });
198
+ return /* @__PURE__ */ jsx(
199
+ RemoveScroll,
200
+ {
201
+ forwardProps: true,
202
+ enabled: context.open,
203
+ allowPinchZoom: context.allowPinchZoom,
204
+ shards: [context.contentRef],
205
+ removeScrollBar: false,
206
+ children: /* @__PURE__ */ jsx("div", { className: "_dsp_contents", children: contents })
207
+ }
208
+ );
233
209
  }
234
210
  )
235
211
  );
@@ -247,67 +223,73 @@ const DialogContentModal = React.forwardRef(
247
223
  return hideOthers(content);
248
224
  }, [context.open]);
249
225
  }
250
- return /* @__PURE__ */ jsx(DialogContentImpl, {
251
- ...props,
252
- context,
253
- ref: composedRefs,
254
- disableOutsidePointerEvents: true,
255
- onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
256
- var _a;
257
- event.preventDefault();
258
- (_a = context.triggerRef.current) == null ? void 0 : _a.focus();
259
- }),
260
- onPointerDownOutside: composeEventHandlers(
261
- props.onPointerDownOutside,
262
- (event) => {
263
- const originalEvent = event["detail"].originalEvent;
264
- const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
265
- const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
266
- if (isRightClick)
267
- event.preventDefault();
268
- }
269
- ),
270
- onFocusOutside: composeEventHandlers(
271
- props.onFocusOutside,
272
- (event) => event.preventDefault()
273
- ),
274
- children
275
- });
226
+ return /* @__PURE__ */ jsx(
227
+ DialogContentImpl,
228
+ {
229
+ ...props,
230
+ context,
231
+ ref: composedRefs,
232
+ disableOutsidePointerEvents: true,
233
+ onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
234
+ var _a;
235
+ event.preventDefault();
236
+ (_a = context.triggerRef.current) == null ? void 0 : _a.focus();
237
+ }),
238
+ onPointerDownOutside: composeEventHandlers(
239
+ props.onPointerDownOutside,
240
+ (event) => {
241
+ const originalEvent = event["detail"].originalEvent;
242
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
243
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
244
+ if (isRightClick)
245
+ event.preventDefault();
246
+ }
247
+ ),
248
+ onFocusOutside: composeEventHandlers(
249
+ props.onFocusOutside,
250
+ (event) => event.preventDefault()
251
+ ),
252
+ children
253
+ }
254
+ );
276
255
  }
277
256
  );
278
257
  const DialogContentNonModal = React.forwardRef(
279
258
  (props, forwardedRef) => {
280
259
  const hasInteractedOutsideRef = React.useRef(false);
281
- return /* @__PURE__ */ jsx(DialogContentImpl, {
282
- ...props,
283
- ref: forwardedRef,
284
- trapFocus: false,
285
- disableOutsidePointerEvents: false,
286
- onCloseAutoFocus: (event) => {
287
- var _a, _b;
288
- (_a = props.onCloseAutoFocus) == null ? void 0 : _a.call(props, event);
289
- if (!event.defaultPrevented) {
290
- if (!hasInteractedOutsideRef.current) {
291
- (_b = props.context.triggerRef.current) == null ? void 0 : _b.focus();
260
+ return /* @__PURE__ */ jsx(
261
+ DialogContentImpl,
262
+ {
263
+ ...props,
264
+ ref: forwardedRef,
265
+ trapFocus: false,
266
+ disableOutsidePointerEvents: false,
267
+ onCloseAutoFocus: (event) => {
268
+ var _a, _b;
269
+ (_a = props.onCloseAutoFocus) == null ? void 0 : _a.call(props, event);
270
+ if (!event.defaultPrevented) {
271
+ if (!hasInteractedOutsideRef.current) {
272
+ (_b = props.context.triggerRef.current) == null ? void 0 : _b.focus();
273
+ }
274
+ event.preventDefault();
292
275
  }
293
- event.preventDefault();
276
+ hasInteractedOutsideRef.current = false;
277
+ },
278
+ onInteractOutside: (event) => {
279
+ var _a;
280
+ (_a = props.onInteractOutside) == null ? void 0 : _a.call(props, event);
281
+ if (!event.defaultPrevented)
282
+ hasInteractedOutsideRef.current = true;
283
+ const target = event.target;
284
+ const trigger = props.context.triggerRef.current;
285
+ if (!(trigger instanceof HTMLElement))
286
+ return;
287
+ const targetIsTrigger = trigger.contains(target);
288
+ if (targetIsTrigger)
289
+ event.preventDefault();
294
290
  }
295
- hasInteractedOutsideRef.current = false;
296
- },
297
- onInteractOutside: (event) => {
298
- var _a;
299
- (_a = props.onInteractOutside) == null ? void 0 : _a.call(props, event);
300
- if (!event.defaultPrevented)
301
- hasInteractedOutsideRef.current = true;
302
- const target = event.target;
303
- const trigger = props.context.triggerRef.current;
304
- if (!(trigger instanceof HTMLElement))
305
- return;
306
- const targetIsTrigger = trigger.contains(target);
307
- if (targetIsTrigger)
308
- event.preventDefault();
309
291
  }
310
- });
292
+ );
311
293
  }
312
294
  );
313
295
  const DialogContentImpl = React.forwardRef(
@@ -328,55 +310,58 @@ const DialogContentImpl = React.forwardRef(
328
310
  const contentRef = React.useRef(null);
329
311
  const composedRefs = useComposedRefs(forwardedRef, contentRef);
330
312
  const showSheet = useShowDialogSheet(context);
331
- const contents = /* @__PURE__ */ jsx(DialogContentFrame, {
332
- id: context.contentId,
333
- "aria-describedby": context.descriptionId,
334
- "aria-labelledby": context.titleId,
335
- "data-state": getState(context.open),
336
- ...contentProps
337
- });
313
+ const contents = /* @__PURE__ */ jsx(
314
+ DialogContentFrame,
315
+ {
316
+ id: context.contentId,
317
+ "aria-describedby": context.descriptionId,
318
+ "aria-labelledby": context.titleId,
319
+ "data-state": getState(context.open),
320
+ ...contentProps
321
+ }
322
+ );
338
323
  if (showSheet) {
339
- return /* @__PURE__ */ jsx(DialogPortalItem, {
340
- hostName: getSheetContentsName(context),
341
- children: contentProps.children
342
- });
324
+ return /* @__PURE__ */ jsx(DialogPortalItem, { hostName: getSheetContentsName(context), children: contentProps.children });
343
325
  }
344
326
  if (!isWeb) {
345
327
  return contents;
346
328
  }
347
- return /* @__PURE__ */ jsxs(Fragment, {
348
- children: [
349
- /* @__PURE__ */ jsx(FocusScope, {
329
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
330
+ /* @__PURE__ */ jsx(
331
+ FocusScope,
332
+ {
350
333
  loop: true,
351
334
  trapped: trapFocus,
352
335
  onMountAutoFocus: onOpenAutoFocus,
353
336
  forceUnmount: !context.open,
354
337
  onUnmountAutoFocus: onCloseAutoFocus,
355
- children: /* @__PURE__ */ jsx(Dismissable, {
356
- disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
357
- forceUnmount: !context.open,
358
- onEscapeKeyDown,
359
- onPointerDownOutside,
360
- onFocusOutside,
361
- onInteractOutside,
362
- ref: composedRefs,
363
- onDismiss: () => context.onOpenChange(false),
364
- children: contents
365
- })
366
- }),
367
- process.env.NODE_ENV === "development" && /* @__PURE__ */ jsxs(Fragment, {
368
- children: [
369
- /* @__PURE__ */ jsx(TitleWarning, {
370
- titleId: context.titleId
371
- }),
372
- /* @__PURE__ */ jsx(DescriptionWarning, {
373
- contentRef,
374
- descriptionId: context.descriptionId
375
- })
376
- ]
377
- })
378
- ]
379
- });
338
+ children: /* @__PURE__ */ jsx(
339
+ Dismissable,
340
+ {
341
+ disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
342
+ forceUnmount: !context.open,
343
+ onEscapeKeyDown,
344
+ onPointerDownOutside,
345
+ onFocusOutside,
346
+ onInteractOutside,
347
+ ref: composedRefs,
348
+ onDismiss: () => context.onOpenChange(false),
349
+ children: contents
350
+ }
351
+ )
352
+ }
353
+ ),
354
+ process.env.NODE_ENV === "development" && /* @__PURE__ */ jsxs(Fragment, { children: [
355
+ /* @__PURE__ */ jsx(TitleWarning, { titleId: context.titleId }),
356
+ /* @__PURE__ */ jsx(
357
+ DescriptionWarning,
358
+ {
359
+ contentRef,
360
+ descriptionId: context.descriptionId
361
+ }
362
+ )
363
+ ] })
364
+ ] });
380
365
  }
381
366
  );
382
367
  const TITLE_NAME = "DialogTitle";
@@ -387,11 +372,7 @@ const DialogTitle = React.forwardRef(
387
372
  (props, forwardedRef) => {
388
373
  const { __scopeDialog, ...titleProps } = props;
389
374
  const context = useDialogContext(TITLE_NAME, __scopeDialog);
390
- return /* @__PURE__ */ jsx(DialogTitleFrame, {
391
- id: context.titleId,
392
- ...titleProps,
393
- ref: forwardedRef
394
- });
375
+ return /* @__PURE__ */ jsx(DialogTitleFrame, { id: context.titleId, ...titleProps, ref: forwardedRef });
395
376
  }
396
377
  );
397
378
  DialogTitle.displayName = TITLE_NAME;
@@ -403,11 +384,14 @@ const DialogDescription = React.forwardRef(
403
384
  (props, forwardedRef) => {
404
385
  const { __scopeDialog, ...descriptionProps } = props;
405
386
  const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
406
- return /* @__PURE__ */ jsx(DialogDescriptionFrame, {
407
- id: context.descriptionId,
408
- ...descriptionProps,
409
- ref: forwardedRef
410
- });
387
+ return /* @__PURE__ */ jsx(
388
+ DialogDescriptionFrame,
389
+ {
390
+ id: context.descriptionId,
391
+ ...descriptionProps,
392
+ ref: forwardedRef
393
+ }
394
+ );
411
395
  }
412
396
  );
413
397
  DialogDescription.displayName = DESCRIPTION_NAME;
@@ -420,15 +404,18 @@ const DialogClose = React.forwardRef(
420
404
  if (isSheet && !displayWhenAdapted) {
421
405
  return null;
422
406
  }
423
- return /* @__PURE__ */ jsx(YStack, {
424
- tag: "button",
425
- ...closeProps,
426
- ref: forwardedRef,
427
- onPress: composeEventHandlers(
428
- props.onPress,
429
- () => context.onOpenChange(false)
430
- )
431
- });
407
+ return /* @__PURE__ */ jsx(
408
+ YStack,
409
+ {
410
+ tag: "button",
411
+ ...closeProps,
412
+ ref: forwardedRef,
413
+ onPress: composeEventHandlers(
414
+ props.onPress,
415
+ () => context.onOpenChange(false)
416
+ )
417
+ }
418
+ );
432
419
  }
433
420
  );
434
421
  DialogClose.displayName = CLOSE_NAME;
@@ -533,10 +520,7 @@ const Dialog = withStaticProperties(
533
520
  const { when, AdaptProvider } = useAdaptParent({
534
521
  Contents: React.useCallback(
535
522
  (props2) => {
536
- return /* @__PURE__ */ jsx(PortalHost, {
537
- forwardProps: props2,
538
- name: sheetContentsName
539
- });
523
+ return /* @__PURE__ */ jsx(PortalHost, { forwardProps: props2, name: sheetContentsName });
540
524
  },
541
525
  [sheetContentsName]
542
526
  )
@@ -548,17 +532,7 @@ const Dialog = withStaticProperties(
548
532
  }),
549
533
  [setOpen]
550
534
  );
551
- return /* @__PURE__ */ jsx(AdaptProvider, {
552
- children: /* @__PURE__ */ jsx(DialogProvider, {
553
- ...context,
554
- sheetBreakpoint: when,
555
- children: /* @__PURE__ */ jsx(DialogSheetController, {
556
- onOpenChange: setOpen,
557
- __scopeDialog,
558
- children
559
- })
560
- })
561
- });
535
+ return /* @__PURE__ */ jsx(AdaptProvider, { children: /* @__PURE__ */ jsx(DialogProvider, { ...context, sheetBreakpoint: when, children: /* @__PURE__ */ jsx(DialogSheetController, { onOpenChange: setOpen, __scopeDialog, children }) }) });
562
536
  }),
563
537
  {
564
538
  Trigger: DialogTrigger,
@@ -577,10 +551,7 @@ const DialogSheetContents = ({
577
551
  name,
578
552
  ...props
579
553
  }) => {
580
- return /* @__PURE__ */ jsx(PortalHost, {
581
- forwardProps: props,
582
- name
583
- });
554
+ return /* @__PURE__ */ jsx(PortalHost, { forwardProps: props, name });
584
555
  };
585
556
  DialogSheetContents.displayName = SHEET_CONTENTS_NAME;
586
557
  const getSheetContentsName = ({
@@ -592,16 +563,19 @@ const DialogSheetController = (props) => {
592
563
  const showSheet = useShowDialogSheet(context);
593
564
  const breakpointActive = useSheetBreakpointActive(context);
594
565
  const getShowSheet = useGet(showSheet);
595
- return /* @__PURE__ */ jsx(SheetController, {
596
- onOpenChange: (val) => {
597
- if (getShowSheet()) {
598
- props.onOpenChange(val);
599
- }
600
- },
601
- open: context.open,
602
- hidden: breakpointActive === false,
603
- children: props.children
604
- });
566
+ return /* @__PURE__ */ jsx(
567
+ SheetController,
568
+ {
569
+ onOpenChange: (val) => {
570
+ if (getShowSheet()) {
571
+ props.onOpenChange(val);
572
+ }
573
+ },
574
+ open: context.open,
575
+ hidden: breakpointActive === false,
576
+ children: props.children
577
+ }
578
+ );
605
579
  };
606
580
  const useSheetBreakpointActive = (context) => {
607
581
  const media = useMedia();