@tamagui/dialog 1.88.12 → 1.89.0-1706308641099
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.
- package/dist/esm/Dialog.mjs +556 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/jsx/Dialog.mjs +556 -0
- package/dist/jsx/index.mjs +1 -0
- package/package.json +20 -20
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import { Adapt, useAdaptParent } from "@tamagui/adapt";
|
|
2
|
+
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
3
|
+
import { hideOthers } from "@tamagui/aria-hidden";
|
|
4
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
5
|
+
import { isWeb } from "@tamagui/constants";
|
|
6
|
+
import { Theme, View, spacedChildren, styled, useGet, useMedia, useThemeName } from "@tamagui/core";
|
|
7
|
+
import { createContext, createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { Dismissable } from "@tamagui/dismissable";
|
|
9
|
+
import { FocusScope } from "@tamagui/focus-scope";
|
|
10
|
+
import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
|
|
11
|
+
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
12
|
+
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
13
|
+
import { Overlay, Sheet, SheetController } from "@tamagui/sheet";
|
|
14
|
+
import { ButtonNestingContext, ThemeableStack, YStack } from "@tamagui/stacks";
|
|
15
|
+
import { H2, Paragraph } from "@tamagui/text";
|
|
16
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
17
|
+
import * as React from "react";
|
|
18
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
const DIALOG_NAME = "Dialog",
|
|
20
|
+
[createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME),
|
|
21
|
+
[DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME),
|
|
22
|
+
TRIGGER_NAME = "DialogTrigger",
|
|
23
|
+
DialogTriggerFrame = styled(View, {
|
|
24
|
+
name: TRIGGER_NAME
|
|
25
|
+
}),
|
|
26
|
+
DialogTrigger = DialogTriggerFrame.styleable((props, forwardedRef) => {
|
|
27
|
+
const {
|
|
28
|
+
__scopeDialog,
|
|
29
|
+
...triggerProps
|
|
30
|
+
} = props,
|
|
31
|
+
isInsideButton = React.useContext(ButtonNestingContext),
|
|
32
|
+
context = useDialogContext(TRIGGER_NAME, __scopeDialog),
|
|
33
|
+
composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
34
|
+
return /* @__PURE__ */jsx(ButtonNestingContext.Provider, {
|
|
35
|
+
value: !0,
|
|
36
|
+
children: /* @__PURE__ */jsx(DialogTriggerFrame, {
|
|
37
|
+
tag: isInsideButton ? "span" : "button",
|
|
38
|
+
"aria-haspopup": "dialog",
|
|
39
|
+
"aria-expanded": context.open,
|
|
40
|
+
"aria-controls": context.contentId,
|
|
41
|
+
"data-state": getState(context.open),
|
|
42
|
+
...triggerProps,
|
|
43
|
+
ref: composedTriggerRef,
|
|
44
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
DialogTrigger.displayName = TRIGGER_NAME;
|
|
49
|
+
const PORTAL_NAME = "DialogPortal",
|
|
50
|
+
[PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
|
|
51
|
+
forceMount: void 0
|
|
52
|
+
}),
|
|
53
|
+
DialogPortalFrame = styled(YStack, {
|
|
54
|
+
variants: {
|
|
55
|
+
unstyled: {
|
|
56
|
+
false: {
|
|
57
|
+
alignItems: "center",
|
|
58
|
+
justifyContent: "center",
|
|
59
|
+
fullscreen: !0,
|
|
60
|
+
zIndex: 1e5,
|
|
61
|
+
...(isWeb && {
|
|
62
|
+
maxHeight: "100vh",
|
|
63
|
+
position: "fixed"
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
defaultVariants: {
|
|
69
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
DialogPortalItem = props => {
|
|
73
|
+
const themeName = useThemeName(),
|
|
74
|
+
context = useDialogContext(PORTAL_NAME, props.__scopeDialog);
|
|
75
|
+
return /* @__PURE__ */jsx(PortalItem, {
|
|
76
|
+
hostName: props.hostName,
|
|
77
|
+
children: /* @__PURE__ */jsx(DialogPortalItemContent, {
|
|
78
|
+
...props,
|
|
79
|
+
themeName,
|
|
80
|
+
context
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
function DialogPortalItemContent(props) {
|
|
85
|
+
const {
|
|
86
|
+
__scopeDialog,
|
|
87
|
+
children,
|
|
88
|
+
context,
|
|
89
|
+
themeName,
|
|
90
|
+
space,
|
|
91
|
+
spaceDirection,
|
|
92
|
+
separator
|
|
93
|
+
} = props;
|
|
94
|
+
let childrenSpaced = children;
|
|
95
|
+
return (space || separator) && (childrenSpaced = spacedChildren({
|
|
96
|
+
children,
|
|
97
|
+
separator,
|
|
98
|
+
space,
|
|
99
|
+
direction: spaceDirection
|
|
100
|
+
})), /* @__PURE__ */jsx(DialogProvider, {
|
|
101
|
+
scope: __scopeDialog,
|
|
102
|
+
...context,
|
|
103
|
+
children: /* @__PURE__ */jsx(Theme, {
|
|
104
|
+
name: themeName,
|
|
105
|
+
children: childrenSpaced
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const DialogPortal = props => {
|
|
110
|
+
const {
|
|
111
|
+
__scopeDialog,
|
|
112
|
+
forceMount,
|
|
113
|
+
children,
|
|
114
|
+
...frameProps
|
|
115
|
+
} = props,
|
|
116
|
+
context = useDialogContext(PORTAL_NAME, __scopeDialog),
|
|
117
|
+
isShowing = forceMount || context.open,
|
|
118
|
+
[isFullyHidden, setIsFullyHidden] = React.useState(!isShowing);
|
|
119
|
+
isShowing && isFullyHidden && setIsFullyHidden(!1);
|
|
120
|
+
const contents = /* @__PURE__ */jsx(AnimatePresence, {
|
|
121
|
+
onExitComplete: () => {
|
|
122
|
+
setIsFullyHidden(!0);
|
|
123
|
+
},
|
|
124
|
+
children: isShowing ? children : null
|
|
125
|
+
});
|
|
126
|
+
return useShowDialogSheet(context) ? children : context.modal ? isFullyHidden ? null : /* @__PURE__ */jsx(DialogPortalItem, {
|
|
127
|
+
__scopeDialog,
|
|
128
|
+
children: /* @__PURE__ */jsx(PortalProvider, {
|
|
129
|
+
scope: __scopeDialog,
|
|
130
|
+
forceMount,
|
|
131
|
+
children: /* @__PURE__ */jsx(DialogPortalFrame, {
|
|
132
|
+
pointerEvents: isShowing ? "auto" : "none",
|
|
133
|
+
...frameProps,
|
|
134
|
+
children: contents
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
}) : contents;
|
|
138
|
+
};
|
|
139
|
+
DialogPortal.displayName = PORTAL_NAME;
|
|
140
|
+
const OVERLAY_NAME = "DialogOverlay",
|
|
141
|
+
DialogOverlayFrame = styled(Overlay, {
|
|
142
|
+
name: OVERLAY_NAME
|
|
143
|
+
}),
|
|
144
|
+
DialogOverlay = DialogOverlayFrame.extractable(React.forwardRef(({
|
|
145
|
+
__scopeDialog,
|
|
146
|
+
...props
|
|
147
|
+
}, forwardedRef) => {
|
|
148
|
+
const portalContext = usePortalContext(OVERLAY_NAME, __scopeDialog),
|
|
149
|
+
{
|
|
150
|
+
forceMount = portalContext.forceMount,
|
|
151
|
+
...overlayProps
|
|
152
|
+
} = props,
|
|
153
|
+
context = useDialogContext(OVERLAY_NAME, __scopeDialog),
|
|
154
|
+
showSheet = useShowDialogSheet(context);
|
|
155
|
+
return !forceMount && (!context.modal || showSheet) ? null : /* @__PURE__ */jsx(DialogOverlayImpl, {
|
|
156
|
+
context,
|
|
157
|
+
...overlayProps,
|
|
158
|
+
ref: forwardedRef
|
|
159
|
+
});
|
|
160
|
+
}));
|
|
161
|
+
DialogOverlay.displayName = OVERLAY_NAME;
|
|
162
|
+
const DialogOverlayImpl = React.forwardRef((props, forwardedRef) => {
|
|
163
|
+
const {
|
|
164
|
+
context,
|
|
165
|
+
...overlayProps
|
|
166
|
+
} = props;
|
|
167
|
+
return (
|
|
168
|
+
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
|
|
169
|
+
// ie. when `Overlay` and `Content` are siblings
|
|
170
|
+
/* @__PURE__ */
|
|
171
|
+
jsx(DialogOverlayFrame, {
|
|
172
|
+
"data-state": getState(context.open),
|
|
173
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
174
|
+
...overlayProps,
|
|
175
|
+
ref: forwardedRef
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}),
|
|
179
|
+
CONTENT_NAME = "DialogContent",
|
|
180
|
+
DialogContentFrame = styled(ThemeableStack, {
|
|
181
|
+
name: CONTENT_NAME,
|
|
182
|
+
tag: "dialog",
|
|
183
|
+
variants: {
|
|
184
|
+
size: {
|
|
185
|
+
"...size": (val, extras) => ({})
|
|
186
|
+
},
|
|
187
|
+
unstyled: {
|
|
188
|
+
false: {
|
|
189
|
+
position: "relative",
|
|
190
|
+
backgrounded: !0,
|
|
191
|
+
padded: !0,
|
|
192
|
+
radiused: !0,
|
|
193
|
+
elevate: !0,
|
|
194
|
+
zIndex: 1e5
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
defaultVariants: {
|
|
199
|
+
size: "$true",
|
|
200
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
201
|
+
}
|
|
202
|
+
}),
|
|
203
|
+
DialogContent = DialogContentFrame.extractable(React.forwardRef(({
|
|
204
|
+
__scopeDialog,
|
|
205
|
+
...props
|
|
206
|
+
}, forwardedRef) => {
|
|
207
|
+
const portalContext = usePortalContext(CONTENT_NAME, __scopeDialog),
|
|
208
|
+
{
|
|
209
|
+
forceMount = portalContext.forceMount,
|
|
210
|
+
...contentProps
|
|
211
|
+
} = props,
|
|
212
|
+
context = useDialogContext(CONTENT_NAME, __scopeDialog),
|
|
213
|
+
contents = context.modal ? /* @__PURE__ */jsx(DialogContentModal, {
|
|
214
|
+
context,
|
|
215
|
+
...contentProps,
|
|
216
|
+
ref: forwardedRef
|
|
217
|
+
}) : /* @__PURE__ */jsx(DialogContentNonModal, {
|
|
218
|
+
context,
|
|
219
|
+
...contentProps,
|
|
220
|
+
ref: forwardedRef
|
|
221
|
+
});
|
|
222
|
+
return !isWeb || context.disableRemoveScroll ? contents : /* @__PURE__ */jsx(RemoveScroll, {
|
|
223
|
+
forwardProps: !0,
|
|
224
|
+
enabled: context.open,
|
|
225
|
+
allowPinchZoom: context.allowPinchZoom,
|
|
226
|
+
shards: [context.contentRef],
|
|
227
|
+
removeScrollBar: !1,
|
|
228
|
+
children: /* @__PURE__ */jsx("div", {
|
|
229
|
+
"data-remove-scroll-container": !0,
|
|
230
|
+
className: "_dsp_contents",
|
|
231
|
+
children: contents
|
|
232
|
+
})
|
|
233
|
+
});
|
|
234
|
+
}));
|
|
235
|
+
DialogContent.displayName = CONTENT_NAME;
|
|
236
|
+
const DialogContentModal = React.forwardRef(({
|
|
237
|
+
children,
|
|
238
|
+
context,
|
|
239
|
+
...props
|
|
240
|
+
}, forwardedRef) => {
|
|
241
|
+
const contentRef = React.useRef(null),
|
|
242
|
+
composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
243
|
+
return isWeb && React.useEffect(() => {
|
|
244
|
+
if (!context.open) return;
|
|
245
|
+
const content = contentRef.current;
|
|
246
|
+
if (content) return hideOthers(content);
|
|
247
|
+
}, [context.open]), /* @__PURE__ */jsx(DialogContentImpl, {
|
|
248
|
+
...props,
|
|
249
|
+
context,
|
|
250
|
+
ref: composedRefs,
|
|
251
|
+
trapFocus: context.open,
|
|
252
|
+
disableOutsidePointerEvents: !0,
|
|
253
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
|
|
254
|
+
event.preventDefault(), context.triggerRef.current?.focus();
|
|
255
|
+
}),
|
|
256
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, event => {
|
|
257
|
+
const originalEvent = event.detail.originalEvent,
|
|
258
|
+
ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === !0;
|
|
259
|
+
(originalEvent.button === 2 || ctrlLeftClick) && event.preventDefault();
|
|
260
|
+
}),
|
|
261
|
+
onFocusOutside: composeEventHandlers(props.onFocusOutside, event => event.preventDefault()),
|
|
262
|
+
...(!props.unstyled && {
|
|
263
|
+
outlineStyle: "none"
|
|
264
|
+
}),
|
|
265
|
+
children
|
|
266
|
+
});
|
|
267
|
+
}),
|
|
268
|
+
DialogContentNonModal = React.forwardRef((props, forwardedRef) => {
|
|
269
|
+
const hasInteractedOutsideRef = React.useRef(!1);
|
|
270
|
+
return /* @__PURE__ */jsx(DialogContentImpl, {
|
|
271
|
+
...props,
|
|
272
|
+
ref: forwardedRef,
|
|
273
|
+
trapFocus: !1,
|
|
274
|
+
disableOutsidePointerEvents: !1,
|
|
275
|
+
onCloseAutoFocus: event => {
|
|
276
|
+
props.onCloseAutoFocus?.(event), event.defaultPrevented || (hasInteractedOutsideRef.current || props.context.triggerRef.current?.focus(), event.preventDefault()), hasInteractedOutsideRef.current = !1;
|
|
277
|
+
},
|
|
278
|
+
onInteractOutside: event => {
|
|
279
|
+
props.onInteractOutside?.(event), event.defaultPrevented || (hasInteractedOutsideRef.current = !0);
|
|
280
|
+
const target = event.target,
|
|
281
|
+
trigger = props.context.triggerRef.current;
|
|
282
|
+
if (!(trigger instanceof HTMLElement)) return;
|
|
283
|
+
trigger.contains(target) && event.preventDefault();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}),
|
|
287
|
+
DialogContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
288
|
+
const {
|
|
289
|
+
__scopeDialog,
|
|
290
|
+
trapFocus,
|
|
291
|
+
onOpenAutoFocus,
|
|
292
|
+
onCloseAutoFocus,
|
|
293
|
+
disableOutsidePointerEvents,
|
|
294
|
+
onEscapeKeyDown,
|
|
295
|
+
onPointerDownOutside,
|
|
296
|
+
onFocusOutside,
|
|
297
|
+
onInteractOutside,
|
|
298
|
+
context,
|
|
299
|
+
...contentProps
|
|
300
|
+
} = props,
|
|
301
|
+
contentRef = React.useRef(null),
|
|
302
|
+
composedRefs = useComposedRefs(forwardedRef, contentRef),
|
|
303
|
+
showSheet = useShowDialogSheet(context),
|
|
304
|
+
contents = /* @__PURE__ */jsx(DialogContentFrame, {
|
|
305
|
+
id: context.contentId,
|
|
306
|
+
"aria-describedby": context.descriptionId,
|
|
307
|
+
"aria-labelledby": context.titleId,
|
|
308
|
+
"data-state": getState(context.open),
|
|
309
|
+
...contentProps
|
|
310
|
+
});
|
|
311
|
+
return showSheet ? /* @__PURE__ */jsx(DialogPortalItem, {
|
|
312
|
+
hostName: getSheetContentsName(context),
|
|
313
|
+
children: contentProps.children
|
|
314
|
+
}) : isWeb ? /* @__PURE__ */jsxs(Fragment, {
|
|
315
|
+
children: [/* @__PURE__ */jsx(Dismissable, {
|
|
316
|
+
disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
|
|
317
|
+
forceUnmount: !context.open,
|
|
318
|
+
onEscapeKeyDown,
|
|
319
|
+
onPointerDownOutside,
|
|
320
|
+
onFocusOutside,
|
|
321
|
+
onInteractOutside,
|
|
322
|
+
ref: composedRefs,
|
|
323
|
+
onDismiss: () => context.onOpenChange(!1),
|
|
324
|
+
children: /* @__PURE__ */jsx(FocusScope, {
|
|
325
|
+
loop: !0,
|
|
326
|
+
enabled: context.open,
|
|
327
|
+
trapped: trapFocus,
|
|
328
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
329
|
+
forceUnmount: !context.open,
|
|
330
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
331
|
+
children: contents
|
|
332
|
+
})
|
|
333
|
+
}), process.env.NODE_ENV === "development" && /* @__PURE__ */jsxs(Fragment, {
|
|
334
|
+
children: [/* @__PURE__ */jsx(TitleWarning, {
|
|
335
|
+
titleId: context.titleId
|
|
336
|
+
}), /* @__PURE__ */jsx(DescriptionWarning, {
|
|
337
|
+
contentRef,
|
|
338
|
+
descriptionId: context.descriptionId
|
|
339
|
+
})]
|
|
340
|
+
})]
|
|
341
|
+
}) : contents;
|
|
342
|
+
}),
|
|
343
|
+
TITLE_NAME = "DialogTitle",
|
|
344
|
+
DialogTitleFrame = styled(H2, {
|
|
345
|
+
name: TITLE_NAME
|
|
346
|
+
}),
|
|
347
|
+
DialogTitle = DialogTitleFrame.styleable((props, forwardedRef) => {
|
|
348
|
+
const {
|
|
349
|
+
__scopeDialog,
|
|
350
|
+
...titleProps
|
|
351
|
+
} = props,
|
|
352
|
+
context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
353
|
+
return /* @__PURE__ */jsx(DialogTitleFrame, {
|
|
354
|
+
id: context.titleId,
|
|
355
|
+
...titleProps,
|
|
356
|
+
ref: forwardedRef
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
DialogTitle.displayName = TITLE_NAME;
|
|
360
|
+
const DialogDescriptionFrame = styled(Paragraph, {
|
|
361
|
+
name: "DialogDescription"
|
|
362
|
+
}),
|
|
363
|
+
DESCRIPTION_NAME = "DialogDescription",
|
|
364
|
+
DialogDescription = DialogDescriptionFrame.styleable((props, forwardedRef) => {
|
|
365
|
+
const {
|
|
366
|
+
__scopeDialog,
|
|
367
|
+
...descriptionProps
|
|
368
|
+
} = props,
|
|
369
|
+
context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
370
|
+
return /* @__PURE__ */jsx(DialogDescriptionFrame, {
|
|
371
|
+
id: context.descriptionId,
|
|
372
|
+
...descriptionProps,
|
|
373
|
+
ref: forwardedRef
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
377
|
+
const CLOSE_NAME = "DialogClose",
|
|
378
|
+
DialogCloseFrame = styled(View, {
|
|
379
|
+
name: CLOSE_NAME,
|
|
380
|
+
tag: "button"
|
|
381
|
+
}),
|
|
382
|
+
DialogClose = DialogCloseFrame.styleable((props, forwardedRef) => {
|
|
383
|
+
const {
|
|
384
|
+
__scopeDialog,
|
|
385
|
+
displayWhenAdapted,
|
|
386
|
+
...closeProps
|
|
387
|
+
} = props,
|
|
388
|
+
context = useDialogContext(CLOSE_NAME, __scopeDialog, {
|
|
389
|
+
warn: !1,
|
|
390
|
+
fallback: {}
|
|
391
|
+
}),
|
|
392
|
+
isSheet = useShowDialogSheet(context),
|
|
393
|
+
isInsideButton = React.useContext(ButtonNestingContext);
|
|
394
|
+
return isSheet && !displayWhenAdapted ? null : /* @__PURE__ */jsx(DialogCloseFrame, {
|
|
395
|
+
accessibilityLabel: "Dialog Close",
|
|
396
|
+
tag: isInsideButton ? "span" : "button",
|
|
397
|
+
...closeProps,
|
|
398
|
+
ref: forwardedRef,
|
|
399
|
+
onPress: composeEventHandlers(props.onPress, () => context.onOpenChange(!1))
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
function getState(open) {
|
|
403
|
+
return open ? "open" : "closed";
|
|
404
|
+
}
|
|
405
|
+
const TITLE_WARNING_NAME = "DialogTitleWarning",
|
|
406
|
+
[DialogWarningProvider, useWarningContext] = createContext(TITLE_WARNING_NAME, {
|
|
407
|
+
contentName: CONTENT_NAME,
|
|
408
|
+
titleName: TITLE_NAME,
|
|
409
|
+
docsSlug: "dialog"
|
|
410
|
+
}),
|
|
411
|
+
TitleWarning = ({
|
|
412
|
+
titleId
|
|
413
|
+
}) => {
|
|
414
|
+
if (process.env.NODE_ENV === "development") {
|
|
415
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME),
|
|
416
|
+
MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
417
|
+
|
|
418
|
+
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.`;
|
|
419
|
+
React.useEffect(() => {
|
|
420
|
+
isWeb && titleId && (document.getElementById(titleId) || console.warn(MESSAGE));
|
|
421
|
+
}, [MESSAGE, titleId]);
|
|
422
|
+
}
|
|
423
|
+
return null;
|
|
424
|
+
},
|
|
425
|
+
DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning",
|
|
426
|
+
DescriptionWarning = ({
|
|
427
|
+
contentRef,
|
|
428
|
+
descriptionId
|
|
429
|
+
}) => {
|
|
430
|
+
if (process.env.NODE_ENV === "development") {
|
|
431
|
+
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${useWarningContext(DESCRIPTION_WARNING_NAME).contentName}}.`;
|
|
432
|
+
React.useEffect(() => {
|
|
433
|
+
if (!isWeb) return;
|
|
434
|
+
const contentNode = contentRef.current;
|
|
435
|
+
if (!(contentNode instanceof HTMLElement)) return;
|
|
436
|
+
const describedById = contentNode.getAttribute("aria-describedby");
|
|
437
|
+
descriptionId && describedById && (document.getElementById(descriptionId) || console.warn(MESSAGE));
|
|
438
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
},
|
|
442
|
+
Dialog = withStaticProperties(React.forwardRef(function (props, ref) {
|
|
443
|
+
const {
|
|
444
|
+
__scopeDialog,
|
|
445
|
+
children,
|
|
446
|
+
open: openProp,
|
|
447
|
+
defaultOpen = !1,
|
|
448
|
+
onOpenChange,
|
|
449
|
+
modal = !0,
|
|
450
|
+
allowPinchZoom = !1,
|
|
451
|
+
disableRemoveScroll = !1
|
|
452
|
+
} = props,
|
|
453
|
+
baseId = React.useId(),
|
|
454
|
+
scopeId = `scope-${baseId}`,
|
|
455
|
+
contentId = `content-${baseId}`,
|
|
456
|
+
titleId = `title-${baseId}`,
|
|
457
|
+
descriptionId = `description-${baseId}`,
|
|
458
|
+
scopeKey = __scopeDialog ? Object.keys(__scopeDialog)[0] : scopeId,
|
|
459
|
+
sheetContentsName = getSheetContentsName({
|
|
460
|
+
scopeKey,
|
|
461
|
+
contentId
|
|
462
|
+
}),
|
|
463
|
+
triggerRef = React.useRef(null),
|
|
464
|
+
contentRef = React.useRef(null),
|
|
465
|
+
[open, setOpen] = useControllableState({
|
|
466
|
+
prop: openProp,
|
|
467
|
+
defaultProp: defaultOpen,
|
|
468
|
+
onChange: onOpenChange
|
|
469
|
+
}),
|
|
470
|
+
onOpenToggle = React.useCallback(() => {
|
|
471
|
+
setOpen(prevOpen => !prevOpen);
|
|
472
|
+
}, [setOpen]),
|
|
473
|
+
context = {
|
|
474
|
+
scope: __scopeDialog,
|
|
475
|
+
scopeKey,
|
|
476
|
+
triggerRef,
|
|
477
|
+
contentRef,
|
|
478
|
+
contentId,
|
|
479
|
+
titleId,
|
|
480
|
+
descriptionId,
|
|
481
|
+
open,
|
|
482
|
+
onOpenChange: setOpen,
|
|
483
|
+
onOpenToggle,
|
|
484
|
+
modal,
|
|
485
|
+
allowPinchZoom
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
when,
|
|
489
|
+
AdaptProvider
|
|
490
|
+
} = useAdaptParent({
|
|
491
|
+
Contents: React.useCallback(props2 => /* @__PURE__ */jsx(PortalHost, {
|
|
492
|
+
forwardProps: props2,
|
|
493
|
+
name: sheetContentsName
|
|
494
|
+
}), [sheetContentsName])
|
|
495
|
+
});
|
|
496
|
+
return React.useImperativeHandle(ref, () => ({
|
|
497
|
+
open: setOpen
|
|
498
|
+
}), [setOpen]), /* @__PURE__ */jsx(AdaptProvider, {
|
|
499
|
+
children: /* @__PURE__ */jsx(DialogProvider, {
|
|
500
|
+
...context,
|
|
501
|
+
sheetBreakpoint: when,
|
|
502
|
+
disableRemoveScroll,
|
|
503
|
+
children: /* @__PURE__ */jsx(DialogSheetController, {
|
|
504
|
+
onOpenChange: setOpen,
|
|
505
|
+
__scopeDialog,
|
|
506
|
+
children
|
|
507
|
+
})
|
|
508
|
+
})
|
|
509
|
+
});
|
|
510
|
+
}), {
|
|
511
|
+
Trigger: DialogTrigger,
|
|
512
|
+
Portal: DialogPortal,
|
|
513
|
+
Overlay: DialogOverlay,
|
|
514
|
+
Content: DialogContent,
|
|
515
|
+
Title: DialogTitle,
|
|
516
|
+
Description: DialogDescription,
|
|
517
|
+
Close: DialogClose,
|
|
518
|
+
Sheet: Sheet.Controlled,
|
|
519
|
+
Adapt
|
|
520
|
+
}),
|
|
521
|
+
SHEET_CONTENTS_NAME = "DialogSheetContents",
|
|
522
|
+
DialogSheetContents = ({
|
|
523
|
+
name,
|
|
524
|
+
...props
|
|
525
|
+
}) => /* @__PURE__ */jsx(PortalHost, {
|
|
526
|
+
forwardProps: props,
|
|
527
|
+
name
|
|
528
|
+
});
|
|
529
|
+
DialogSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
530
|
+
const getSheetContentsName = ({
|
|
531
|
+
scopeKey,
|
|
532
|
+
contentId
|
|
533
|
+
}) => `${scopeKey || contentId}SheetContents`,
|
|
534
|
+
DialogSheetController = props => {
|
|
535
|
+
const context = useDialogContext("DialogSheetController", props.__scopeDialog),
|
|
536
|
+
showSheet = useShowDialogSheet(context),
|
|
537
|
+
breakpointActive = useSheetBreakpointActive(context),
|
|
538
|
+
getShowSheet = useGet(showSheet);
|
|
539
|
+
return /* @__PURE__ */jsx(SheetController, {
|
|
540
|
+
onOpenChange: val => {
|
|
541
|
+
getShowSheet() && props.onOpenChange(val);
|
|
542
|
+
},
|
|
543
|
+
open: context.open,
|
|
544
|
+
hidden: breakpointActive === !1,
|
|
545
|
+
children: props.children
|
|
546
|
+
});
|
|
547
|
+
},
|
|
548
|
+
useSheetBreakpointActive = context => {
|
|
549
|
+
const media = useMedia();
|
|
550
|
+
return context.sheetBreakpoint ? context.sheetBreakpoint === !0 ? !0 : media[context.sheetBreakpoint] : !1;
|
|
551
|
+
},
|
|
552
|
+
useShowDialogSheet = context => {
|
|
553
|
+
const breakpointActive = useSheetBreakpointActive(context);
|
|
554
|
+
return context.open === !1 ? !1 : breakpointActive;
|
|
555
|
+
};
|
|
556
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogOverlay, DialogOverlayFrame, DialogPortal, DialogPortalFrame, DialogSheetContents, DialogTitle, DialogTrigger, DialogWarningProvider, createDialogScope };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Dialog.mjs";
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import { Adapt, useAdaptParent } from "@tamagui/adapt";
|
|
2
|
+
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
3
|
+
import { hideOthers } from "@tamagui/aria-hidden";
|
|
4
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
5
|
+
import { isWeb } from "@tamagui/constants";
|
|
6
|
+
import { Theme, View, spacedChildren, styled, useGet, useMedia, useThemeName } from "@tamagui/core";
|
|
7
|
+
import { createContext, createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { Dismissable } from "@tamagui/dismissable";
|
|
9
|
+
import { FocusScope } from "@tamagui/focus-scope";
|
|
10
|
+
import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
|
|
11
|
+
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
12
|
+
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
13
|
+
import { Overlay, Sheet, SheetController } from "@tamagui/sheet";
|
|
14
|
+
import { ButtonNestingContext, ThemeableStack, YStack } from "@tamagui/stacks";
|
|
15
|
+
import { H2, Paragraph } from "@tamagui/text";
|
|
16
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
17
|
+
import * as React from "react";
|
|
18
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
const DIALOG_NAME = "Dialog",
|
|
20
|
+
[createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME),
|
|
21
|
+
[DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME),
|
|
22
|
+
TRIGGER_NAME = "DialogTrigger",
|
|
23
|
+
DialogTriggerFrame = styled(View, {
|
|
24
|
+
name: TRIGGER_NAME
|
|
25
|
+
}),
|
|
26
|
+
DialogTrigger = DialogTriggerFrame.styleable((props, forwardedRef) => {
|
|
27
|
+
const {
|
|
28
|
+
__scopeDialog,
|
|
29
|
+
...triggerProps
|
|
30
|
+
} = props,
|
|
31
|
+
isInsideButton = React.useContext(ButtonNestingContext),
|
|
32
|
+
context = useDialogContext(TRIGGER_NAME, __scopeDialog),
|
|
33
|
+
composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
34
|
+
return /* @__PURE__ */jsx(ButtonNestingContext.Provider, {
|
|
35
|
+
value: !0,
|
|
36
|
+
children: /* @__PURE__ */jsx(DialogTriggerFrame, {
|
|
37
|
+
tag: isInsideButton ? "span" : "button",
|
|
38
|
+
"aria-haspopup": "dialog",
|
|
39
|
+
"aria-expanded": context.open,
|
|
40
|
+
"aria-controls": context.contentId,
|
|
41
|
+
"data-state": getState(context.open),
|
|
42
|
+
...triggerProps,
|
|
43
|
+
ref: composedTriggerRef,
|
|
44
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
DialogTrigger.displayName = TRIGGER_NAME;
|
|
49
|
+
const PORTAL_NAME = "DialogPortal",
|
|
50
|
+
[PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
|
|
51
|
+
forceMount: void 0
|
|
52
|
+
}),
|
|
53
|
+
DialogPortalFrame = styled(YStack, {
|
|
54
|
+
variants: {
|
|
55
|
+
unstyled: {
|
|
56
|
+
false: {
|
|
57
|
+
alignItems: "center",
|
|
58
|
+
justifyContent: "center",
|
|
59
|
+
fullscreen: !0,
|
|
60
|
+
zIndex: 1e5,
|
|
61
|
+
...(isWeb && {
|
|
62
|
+
maxHeight: "100vh",
|
|
63
|
+
position: "fixed"
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
defaultVariants: {
|
|
69
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
DialogPortalItem = props => {
|
|
73
|
+
const themeName = useThemeName(),
|
|
74
|
+
context = useDialogContext(PORTAL_NAME, props.__scopeDialog);
|
|
75
|
+
return /* @__PURE__ */jsx(PortalItem, {
|
|
76
|
+
hostName: props.hostName,
|
|
77
|
+
children: /* @__PURE__ */jsx(DialogPortalItemContent, {
|
|
78
|
+
...props,
|
|
79
|
+
themeName,
|
|
80
|
+
context
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
function DialogPortalItemContent(props) {
|
|
85
|
+
const {
|
|
86
|
+
__scopeDialog,
|
|
87
|
+
children,
|
|
88
|
+
context,
|
|
89
|
+
themeName,
|
|
90
|
+
space,
|
|
91
|
+
spaceDirection,
|
|
92
|
+
separator
|
|
93
|
+
} = props;
|
|
94
|
+
let childrenSpaced = children;
|
|
95
|
+
return (space || separator) && (childrenSpaced = spacedChildren({
|
|
96
|
+
children,
|
|
97
|
+
separator,
|
|
98
|
+
space,
|
|
99
|
+
direction: spaceDirection
|
|
100
|
+
})), /* @__PURE__ */jsx(DialogProvider, {
|
|
101
|
+
scope: __scopeDialog,
|
|
102
|
+
...context,
|
|
103
|
+
children: /* @__PURE__ */jsx(Theme, {
|
|
104
|
+
name: themeName,
|
|
105
|
+
children: childrenSpaced
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const DialogPortal = props => {
|
|
110
|
+
const {
|
|
111
|
+
__scopeDialog,
|
|
112
|
+
forceMount,
|
|
113
|
+
children,
|
|
114
|
+
...frameProps
|
|
115
|
+
} = props,
|
|
116
|
+
context = useDialogContext(PORTAL_NAME, __scopeDialog),
|
|
117
|
+
isShowing = forceMount || context.open,
|
|
118
|
+
[isFullyHidden, setIsFullyHidden] = React.useState(!isShowing);
|
|
119
|
+
isShowing && isFullyHidden && setIsFullyHidden(!1);
|
|
120
|
+
const contents = /* @__PURE__ */jsx(AnimatePresence, {
|
|
121
|
+
onExitComplete: () => {
|
|
122
|
+
setIsFullyHidden(!0);
|
|
123
|
+
},
|
|
124
|
+
children: isShowing ? children : null
|
|
125
|
+
});
|
|
126
|
+
return useShowDialogSheet(context) ? children : context.modal ? isFullyHidden ? null : /* @__PURE__ */jsx(DialogPortalItem, {
|
|
127
|
+
__scopeDialog,
|
|
128
|
+
children: /* @__PURE__ */jsx(PortalProvider, {
|
|
129
|
+
scope: __scopeDialog,
|
|
130
|
+
forceMount,
|
|
131
|
+
children: /* @__PURE__ */jsx(DialogPortalFrame, {
|
|
132
|
+
pointerEvents: isShowing ? "auto" : "none",
|
|
133
|
+
...frameProps,
|
|
134
|
+
children: contents
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
}) : contents;
|
|
138
|
+
};
|
|
139
|
+
DialogPortal.displayName = PORTAL_NAME;
|
|
140
|
+
const OVERLAY_NAME = "DialogOverlay",
|
|
141
|
+
DialogOverlayFrame = styled(Overlay, {
|
|
142
|
+
name: OVERLAY_NAME
|
|
143
|
+
}),
|
|
144
|
+
DialogOverlay = DialogOverlayFrame.extractable(React.forwardRef(({
|
|
145
|
+
__scopeDialog,
|
|
146
|
+
...props
|
|
147
|
+
}, forwardedRef) => {
|
|
148
|
+
const portalContext = usePortalContext(OVERLAY_NAME, __scopeDialog),
|
|
149
|
+
{
|
|
150
|
+
forceMount = portalContext.forceMount,
|
|
151
|
+
...overlayProps
|
|
152
|
+
} = props,
|
|
153
|
+
context = useDialogContext(OVERLAY_NAME, __scopeDialog),
|
|
154
|
+
showSheet = useShowDialogSheet(context);
|
|
155
|
+
return !forceMount && (!context.modal || showSheet) ? null : /* @__PURE__ */jsx(DialogOverlayImpl, {
|
|
156
|
+
context,
|
|
157
|
+
...overlayProps,
|
|
158
|
+
ref: forwardedRef
|
|
159
|
+
});
|
|
160
|
+
}));
|
|
161
|
+
DialogOverlay.displayName = OVERLAY_NAME;
|
|
162
|
+
const DialogOverlayImpl = React.forwardRef((props, forwardedRef) => {
|
|
163
|
+
const {
|
|
164
|
+
context,
|
|
165
|
+
...overlayProps
|
|
166
|
+
} = props;
|
|
167
|
+
return (
|
|
168
|
+
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
|
|
169
|
+
// ie. when `Overlay` and `Content` are siblings
|
|
170
|
+
/* @__PURE__ */
|
|
171
|
+
jsx(DialogOverlayFrame, {
|
|
172
|
+
"data-state": getState(context.open),
|
|
173
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
174
|
+
...overlayProps,
|
|
175
|
+
ref: forwardedRef
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}),
|
|
179
|
+
CONTENT_NAME = "DialogContent",
|
|
180
|
+
DialogContentFrame = styled(ThemeableStack, {
|
|
181
|
+
name: CONTENT_NAME,
|
|
182
|
+
tag: "dialog",
|
|
183
|
+
variants: {
|
|
184
|
+
size: {
|
|
185
|
+
"...size": (val, extras) => ({})
|
|
186
|
+
},
|
|
187
|
+
unstyled: {
|
|
188
|
+
false: {
|
|
189
|
+
position: "relative",
|
|
190
|
+
backgrounded: !0,
|
|
191
|
+
padded: !0,
|
|
192
|
+
radiused: !0,
|
|
193
|
+
elevate: !0,
|
|
194
|
+
zIndex: 1e5
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
defaultVariants: {
|
|
199
|
+
size: "$true",
|
|
200
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
201
|
+
}
|
|
202
|
+
}),
|
|
203
|
+
DialogContent = DialogContentFrame.extractable(React.forwardRef(({
|
|
204
|
+
__scopeDialog,
|
|
205
|
+
...props
|
|
206
|
+
}, forwardedRef) => {
|
|
207
|
+
const portalContext = usePortalContext(CONTENT_NAME, __scopeDialog),
|
|
208
|
+
{
|
|
209
|
+
forceMount = portalContext.forceMount,
|
|
210
|
+
...contentProps
|
|
211
|
+
} = props,
|
|
212
|
+
context = useDialogContext(CONTENT_NAME, __scopeDialog),
|
|
213
|
+
contents = context.modal ? /* @__PURE__ */jsx(DialogContentModal, {
|
|
214
|
+
context,
|
|
215
|
+
...contentProps,
|
|
216
|
+
ref: forwardedRef
|
|
217
|
+
}) : /* @__PURE__ */jsx(DialogContentNonModal, {
|
|
218
|
+
context,
|
|
219
|
+
...contentProps,
|
|
220
|
+
ref: forwardedRef
|
|
221
|
+
});
|
|
222
|
+
return !isWeb || context.disableRemoveScroll ? contents : /* @__PURE__ */jsx(RemoveScroll, {
|
|
223
|
+
forwardProps: !0,
|
|
224
|
+
enabled: context.open,
|
|
225
|
+
allowPinchZoom: context.allowPinchZoom,
|
|
226
|
+
shards: [context.contentRef],
|
|
227
|
+
removeScrollBar: !1,
|
|
228
|
+
children: /* @__PURE__ */jsx("div", {
|
|
229
|
+
"data-remove-scroll-container": !0,
|
|
230
|
+
className: "_dsp_contents",
|
|
231
|
+
children: contents
|
|
232
|
+
})
|
|
233
|
+
});
|
|
234
|
+
}));
|
|
235
|
+
DialogContent.displayName = CONTENT_NAME;
|
|
236
|
+
const DialogContentModal = React.forwardRef(({
|
|
237
|
+
children,
|
|
238
|
+
context,
|
|
239
|
+
...props
|
|
240
|
+
}, forwardedRef) => {
|
|
241
|
+
const contentRef = React.useRef(null),
|
|
242
|
+
composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
243
|
+
return isWeb && React.useEffect(() => {
|
|
244
|
+
if (!context.open) return;
|
|
245
|
+
const content = contentRef.current;
|
|
246
|
+
if (content) return hideOthers(content);
|
|
247
|
+
}, [context.open]), /* @__PURE__ */jsx(DialogContentImpl, {
|
|
248
|
+
...props,
|
|
249
|
+
context,
|
|
250
|
+
ref: composedRefs,
|
|
251
|
+
trapFocus: context.open,
|
|
252
|
+
disableOutsidePointerEvents: !0,
|
|
253
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
|
|
254
|
+
event.preventDefault(), context.triggerRef.current?.focus();
|
|
255
|
+
}),
|
|
256
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, event => {
|
|
257
|
+
const originalEvent = event.detail.originalEvent,
|
|
258
|
+
ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === !0;
|
|
259
|
+
(originalEvent.button === 2 || ctrlLeftClick) && event.preventDefault();
|
|
260
|
+
}),
|
|
261
|
+
onFocusOutside: composeEventHandlers(props.onFocusOutside, event => event.preventDefault()),
|
|
262
|
+
...(!props.unstyled && {
|
|
263
|
+
outlineStyle: "none"
|
|
264
|
+
}),
|
|
265
|
+
children
|
|
266
|
+
});
|
|
267
|
+
}),
|
|
268
|
+
DialogContentNonModal = React.forwardRef((props, forwardedRef) => {
|
|
269
|
+
const hasInteractedOutsideRef = React.useRef(!1);
|
|
270
|
+
return /* @__PURE__ */jsx(DialogContentImpl, {
|
|
271
|
+
...props,
|
|
272
|
+
ref: forwardedRef,
|
|
273
|
+
trapFocus: !1,
|
|
274
|
+
disableOutsidePointerEvents: !1,
|
|
275
|
+
onCloseAutoFocus: event => {
|
|
276
|
+
props.onCloseAutoFocus?.(event), event.defaultPrevented || (hasInteractedOutsideRef.current || props.context.triggerRef.current?.focus(), event.preventDefault()), hasInteractedOutsideRef.current = !1;
|
|
277
|
+
},
|
|
278
|
+
onInteractOutside: event => {
|
|
279
|
+
props.onInteractOutside?.(event), event.defaultPrevented || (hasInteractedOutsideRef.current = !0);
|
|
280
|
+
const target = event.target,
|
|
281
|
+
trigger = props.context.triggerRef.current;
|
|
282
|
+
if (!(trigger instanceof HTMLElement)) return;
|
|
283
|
+
trigger.contains(target) && event.preventDefault();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}),
|
|
287
|
+
DialogContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
288
|
+
const {
|
|
289
|
+
__scopeDialog,
|
|
290
|
+
trapFocus,
|
|
291
|
+
onOpenAutoFocus,
|
|
292
|
+
onCloseAutoFocus,
|
|
293
|
+
disableOutsidePointerEvents,
|
|
294
|
+
onEscapeKeyDown,
|
|
295
|
+
onPointerDownOutside,
|
|
296
|
+
onFocusOutside,
|
|
297
|
+
onInteractOutside,
|
|
298
|
+
context,
|
|
299
|
+
...contentProps
|
|
300
|
+
} = props,
|
|
301
|
+
contentRef = React.useRef(null),
|
|
302
|
+
composedRefs = useComposedRefs(forwardedRef, contentRef),
|
|
303
|
+
showSheet = useShowDialogSheet(context),
|
|
304
|
+
contents = /* @__PURE__ */jsx(DialogContentFrame, {
|
|
305
|
+
id: context.contentId,
|
|
306
|
+
"aria-describedby": context.descriptionId,
|
|
307
|
+
"aria-labelledby": context.titleId,
|
|
308
|
+
"data-state": getState(context.open),
|
|
309
|
+
...contentProps
|
|
310
|
+
});
|
|
311
|
+
return showSheet ? /* @__PURE__ */jsx(DialogPortalItem, {
|
|
312
|
+
hostName: getSheetContentsName(context),
|
|
313
|
+
children: contentProps.children
|
|
314
|
+
}) : isWeb ? /* @__PURE__ */jsxs(Fragment, {
|
|
315
|
+
children: [/* @__PURE__ */jsx(Dismissable, {
|
|
316
|
+
disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
|
|
317
|
+
forceUnmount: !context.open,
|
|
318
|
+
onEscapeKeyDown,
|
|
319
|
+
onPointerDownOutside,
|
|
320
|
+
onFocusOutside,
|
|
321
|
+
onInteractOutside,
|
|
322
|
+
ref: composedRefs,
|
|
323
|
+
onDismiss: () => context.onOpenChange(!1),
|
|
324
|
+
children: /* @__PURE__ */jsx(FocusScope, {
|
|
325
|
+
loop: !0,
|
|
326
|
+
enabled: context.open,
|
|
327
|
+
trapped: trapFocus,
|
|
328
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
329
|
+
forceUnmount: !context.open,
|
|
330
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
331
|
+
children: contents
|
|
332
|
+
})
|
|
333
|
+
}), process.env.NODE_ENV === "development" && /* @__PURE__ */jsxs(Fragment, {
|
|
334
|
+
children: [/* @__PURE__ */jsx(TitleWarning, {
|
|
335
|
+
titleId: context.titleId
|
|
336
|
+
}), /* @__PURE__ */jsx(DescriptionWarning, {
|
|
337
|
+
contentRef,
|
|
338
|
+
descriptionId: context.descriptionId
|
|
339
|
+
})]
|
|
340
|
+
})]
|
|
341
|
+
}) : contents;
|
|
342
|
+
}),
|
|
343
|
+
TITLE_NAME = "DialogTitle",
|
|
344
|
+
DialogTitleFrame = styled(H2, {
|
|
345
|
+
name: TITLE_NAME
|
|
346
|
+
}),
|
|
347
|
+
DialogTitle = DialogTitleFrame.styleable((props, forwardedRef) => {
|
|
348
|
+
const {
|
|
349
|
+
__scopeDialog,
|
|
350
|
+
...titleProps
|
|
351
|
+
} = props,
|
|
352
|
+
context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
353
|
+
return /* @__PURE__ */jsx(DialogTitleFrame, {
|
|
354
|
+
id: context.titleId,
|
|
355
|
+
...titleProps,
|
|
356
|
+
ref: forwardedRef
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
DialogTitle.displayName = TITLE_NAME;
|
|
360
|
+
const DialogDescriptionFrame = styled(Paragraph, {
|
|
361
|
+
name: "DialogDescription"
|
|
362
|
+
}),
|
|
363
|
+
DESCRIPTION_NAME = "DialogDescription",
|
|
364
|
+
DialogDescription = DialogDescriptionFrame.styleable((props, forwardedRef) => {
|
|
365
|
+
const {
|
|
366
|
+
__scopeDialog,
|
|
367
|
+
...descriptionProps
|
|
368
|
+
} = props,
|
|
369
|
+
context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
370
|
+
return /* @__PURE__ */jsx(DialogDescriptionFrame, {
|
|
371
|
+
id: context.descriptionId,
|
|
372
|
+
...descriptionProps,
|
|
373
|
+
ref: forwardedRef
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
377
|
+
const CLOSE_NAME = "DialogClose",
|
|
378
|
+
DialogCloseFrame = styled(View, {
|
|
379
|
+
name: CLOSE_NAME,
|
|
380
|
+
tag: "button"
|
|
381
|
+
}),
|
|
382
|
+
DialogClose = DialogCloseFrame.styleable((props, forwardedRef) => {
|
|
383
|
+
const {
|
|
384
|
+
__scopeDialog,
|
|
385
|
+
displayWhenAdapted,
|
|
386
|
+
...closeProps
|
|
387
|
+
} = props,
|
|
388
|
+
context = useDialogContext(CLOSE_NAME, __scopeDialog, {
|
|
389
|
+
warn: !1,
|
|
390
|
+
fallback: {}
|
|
391
|
+
}),
|
|
392
|
+
isSheet = useShowDialogSheet(context),
|
|
393
|
+
isInsideButton = React.useContext(ButtonNestingContext);
|
|
394
|
+
return isSheet && !displayWhenAdapted ? null : /* @__PURE__ */jsx(DialogCloseFrame, {
|
|
395
|
+
accessibilityLabel: "Dialog Close",
|
|
396
|
+
tag: isInsideButton ? "span" : "button",
|
|
397
|
+
...closeProps,
|
|
398
|
+
ref: forwardedRef,
|
|
399
|
+
onPress: composeEventHandlers(props.onPress, () => context.onOpenChange(!1))
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
function getState(open) {
|
|
403
|
+
return open ? "open" : "closed";
|
|
404
|
+
}
|
|
405
|
+
const TITLE_WARNING_NAME = "DialogTitleWarning",
|
|
406
|
+
[DialogWarningProvider, useWarningContext] = createContext(TITLE_WARNING_NAME, {
|
|
407
|
+
contentName: CONTENT_NAME,
|
|
408
|
+
titleName: TITLE_NAME,
|
|
409
|
+
docsSlug: "dialog"
|
|
410
|
+
}),
|
|
411
|
+
TitleWarning = ({
|
|
412
|
+
titleId
|
|
413
|
+
}) => {
|
|
414
|
+
if (process.env.NODE_ENV === "development") {
|
|
415
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME),
|
|
416
|
+
MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
417
|
+
|
|
418
|
+
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.`;
|
|
419
|
+
React.useEffect(() => {
|
|
420
|
+
isWeb && titleId && (document.getElementById(titleId) || console.warn(MESSAGE));
|
|
421
|
+
}, [MESSAGE, titleId]);
|
|
422
|
+
}
|
|
423
|
+
return null;
|
|
424
|
+
},
|
|
425
|
+
DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning",
|
|
426
|
+
DescriptionWarning = ({
|
|
427
|
+
contentRef,
|
|
428
|
+
descriptionId
|
|
429
|
+
}) => {
|
|
430
|
+
if (process.env.NODE_ENV === "development") {
|
|
431
|
+
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${useWarningContext(DESCRIPTION_WARNING_NAME).contentName}}.`;
|
|
432
|
+
React.useEffect(() => {
|
|
433
|
+
if (!isWeb) return;
|
|
434
|
+
const contentNode = contentRef.current;
|
|
435
|
+
if (!(contentNode instanceof HTMLElement)) return;
|
|
436
|
+
const describedById = contentNode.getAttribute("aria-describedby");
|
|
437
|
+
descriptionId && describedById && (document.getElementById(descriptionId) || console.warn(MESSAGE));
|
|
438
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
},
|
|
442
|
+
Dialog = withStaticProperties(React.forwardRef(function (props, ref) {
|
|
443
|
+
const {
|
|
444
|
+
__scopeDialog,
|
|
445
|
+
children,
|
|
446
|
+
open: openProp,
|
|
447
|
+
defaultOpen = !1,
|
|
448
|
+
onOpenChange,
|
|
449
|
+
modal = !0,
|
|
450
|
+
allowPinchZoom = !1,
|
|
451
|
+
disableRemoveScroll = !1
|
|
452
|
+
} = props,
|
|
453
|
+
baseId = React.useId(),
|
|
454
|
+
scopeId = `scope-${baseId}`,
|
|
455
|
+
contentId = `content-${baseId}`,
|
|
456
|
+
titleId = `title-${baseId}`,
|
|
457
|
+
descriptionId = `description-${baseId}`,
|
|
458
|
+
scopeKey = __scopeDialog ? Object.keys(__scopeDialog)[0] : scopeId,
|
|
459
|
+
sheetContentsName = getSheetContentsName({
|
|
460
|
+
scopeKey,
|
|
461
|
+
contentId
|
|
462
|
+
}),
|
|
463
|
+
triggerRef = React.useRef(null),
|
|
464
|
+
contentRef = React.useRef(null),
|
|
465
|
+
[open, setOpen] = useControllableState({
|
|
466
|
+
prop: openProp,
|
|
467
|
+
defaultProp: defaultOpen,
|
|
468
|
+
onChange: onOpenChange
|
|
469
|
+
}),
|
|
470
|
+
onOpenToggle = React.useCallback(() => {
|
|
471
|
+
setOpen(prevOpen => !prevOpen);
|
|
472
|
+
}, [setOpen]),
|
|
473
|
+
context = {
|
|
474
|
+
scope: __scopeDialog,
|
|
475
|
+
scopeKey,
|
|
476
|
+
triggerRef,
|
|
477
|
+
contentRef,
|
|
478
|
+
contentId,
|
|
479
|
+
titleId,
|
|
480
|
+
descriptionId,
|
|
481
|
+
open,
|
|
482
|
+
onOpenChange: setOpen,
|
|
483
|
+
onOpenToggle,
|
|
484
|
+
modal,
|
|
485
|
+
allowPinchZoom
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
when,
|
|
489
|
+
AdaptProvider
|
|
490
|
+
} = useAdaptParent({
|
|
491
|
+
Contents: React.useCallback(props2 => /* @__PURE__ */jsx(PortalHost, {
|
|
492
|
+
forwardProps: props2,
|
|
493
|
+
name: sheetContentsName
|
|
494
|
+
}), [sheetContentsName])
|
|
495
|
+
});
|
|
496
|
+
return React.useImperativeHandle(ref, () => ({
|
|
497
|
+
open: setOpen
|
|
498
|
+
}), [setOpen]), /* @__PURE__ */jsx(AdaptProvider, {
|
|
499
|
+
children: /* @__PURE__ */jsx(DialogProvider, {
|
|
500
|
+
...context,
|
|
501
|
+
sheetBreakpoint: when,
|
|
502
|
+
disableRemoveScroll,
|
|
503
|
+
children: /* @__PURE__ */jsx(DialogSheetController, {
|
|
504
|
+
onOpenChange: setOpen,
|
|
505
|
+
__scopeDialog,
|
|
506
|
+
children
|
|
507
|
+
})
|
|
508
|
+
})
|
|
509
|
+
});
|
|
510
|
+
}), {
|
|
511
|
+
Trigger: DialogTrigger,
|
|
512
|
+
Portal: DialogPortal,
|
|
513
|
+
Overlay: DialogOverlay,
|
|
514
|
+
Content: DialogContent,
|
|
515
|
+
Title: DialogTitle,
|
|
516
|
+
Description: DialogDescription,
|
|
517
|
+
Close: DialogClose,
|
|
518
|
+
Sheet: Sheet.Controlled,
|
|
519
|
+
Adapt
|
|
520
|
+
}),
|
|
521
|
+
SHEET_CONTENTS_NAME = "DialogSheetContents",
|
|
522
|
+
DialogSheetContents = ({
|
|
523
|
+
name,
|
|
524
|
+
...props
|
|
525
|
+
}) => /* @__PURE__ */jsx(PortalHost, {
|
|
526
|
+
forwardProps: props,
|
|
527
|
+
name
|
|
528
|
+
});
|
|
529
|
+
DialogSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
530
|
+
const getSheetContentsName = ({
|
|
531
|
+
scopeKey,
|
|
532
|
+
contentId
|
|
533
|
+
}) => `${scopeKey || contentId}SheetContents`,
|
|
534
|
+
DialogSheetController = props => {
|
|
535
|
+
const context = useDialogContext("DialogSheetController", props.__scopeDialog),
|
|
536
|
+
showSheet = useShowDialogSheet(context),
|
|
537
|
+
breakpointActive = useSheetBreakpointActive(context),
|
|
538
|
+
getShowSheet = useGet(showSheet);
|
|
539
|
+
return /* @__PURE__ */jsx(SheetController, {
|
|
540
|
+
onOpenChange: val => {
|
|
541
|
+
getShowSheet() && props.onOpenChange(val);
|
|
542
|
+
},
|
|
543
|
+
open: context.open,
|
|
544
|
+
hidden: breakpointActive === !1,
|
|
545
|
+
children: props.children
|
|
546
|
+
});
|
|
547
|
+
},
|
|
548
|
+
useSheetBreakpointActive = context => {
|
|
549
|
+
const media = useMedia();
|
|
550
|
+
return context.sheetBreakpoint ? context.sheetBreakpoint === !0 ? !0 : media[context.sheetBreakpoint] : !1;
|
|
551
|
+
},
|
|
552
|
+
useShowDialogSheet = context => {
|
|
553
|
+
const breakpointActive = useSheetBreakpointActive(context);
|
|
554
|
+
return context.open === !1 ? !1 : breakpointActive;
|
|
555
|
+
};
|
|
556
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogOverlay, DialogOverlayFrame, DialogPortal, DialogPortalFrame, DialogSheetContents, DialogTitle, DialogTrigger, DialogWarningProvider, createDialogScope };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Dialog.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/dialog",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.0-1706308641099",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -32,31 +32,31 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@tamagui/adapt": "1.
|
|
36
|
-
"@tamagui/animate-presence": "1.
|
|
37
|
-
"@tamagui/aria-hidden": "1.
|
|
38
|
-
"@tamagui/compose-refs": "1.
|
|
39
|
-
"@tamagui/constants": "1.
|
|
40
|
-
"@tamagui/core": "1.
|
|
41
|
-
"@tamagui/create-context": "1.
|
|
42
|
-
"@tamagui/dismissable": "1.
|
|
43
|
-
"@tamagui/focus-scope": "1.
|
|
44
|
-
"@tamagui/helpers": "1.
|
|
45
|
-
"@tamagui/polyfill-dev": "1.
|
|
46
|
-
"@tamagui/popper": "1.
|
|
47
|
-
"@tamagui/portal": "1.
|
|
48
|
-
"@tamagui/remove-scroll": "1.
|
|
49
|
-
"@tamagui/sheet": "1.
|
|
50
|
-
"@tamagui/stacks": "1.
|
|
51
|
-
"@tamagui/text": "1.
|
|
52
|
-
"@tamagui/use-controllable-state": "1.
|
|
35
|
+
"@tamagui/adapt": "1.89.0-1706308641099",
|
|
36
|
+
"@tamagui/animate-presence": "1.89.0-1706308641099",
|
|
37
|
+
"@tamagui/aria-hidden": "1.89.0-1706308641099",
|
|
38
|
+
"@tamagui/compose-refs": "1.89.0-1706308641099",
|
|
39
|
+
"@tamagui/constants": "1.89.0-1706308641099",
|
|
40
|
+
"@tamagui/core": "1.89.0-1706308641099",
|
|
41
|
+
"@tamagui/create-context": "1.89.0-1706308641099",
|
|
42
|
+
"@tamagui/dismissable": "1.89.0-1706308641099",
|
|
43
|
+
"@tamagui/focus-scope": "1.89.0-1706308641099",
|
|
44
|
+
"@tamagui/helpers": "1.89.0-1706308641099",
|
|
45
|
+
"@tamagui/polyfill-dev": "1.89.0-1706308641099",
|
|
46
|
+
"@tamagui/popper": "1.89.0-1706308641099",
|
|
47
|
+
"@tamagui/portal": "1.89.0-1706308641099",
|
|
48
|
+
"@tamagui/remove-scroll": "1.89.0-1706308641099",
|
|
49
|
+
"@tamagui/sheet": "1.89.0-1706308641099",
|
|
50
|
+
"@tamagui/stacks": "1.89.0-1706308641099",
|
|
51
|
+
"@tamagui/text": "1.89.0-1706308641099",
|
|
52
|
+
"@tamagui/use-controllable-state": "1.89.0-1706308641099"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"react": "*",
|
|
56
56
|
"react-native": "*"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@tamagui/build": "1.
|
|
59
|
+
"@tamagui/build": "1.89.0-1706308641099",
|
|
60
60
|
"react": "^18.2.0",
|
|
61
61
|
"react-native": "^0.72.6"
|
|
62
62
|
},
|