@tamagui/dialog 1.13.3 → 1.14.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.
- package/dist/cjs/Dialog.js +3 -642
- package/dist/cjs/Dialog.js.map +2 -2
- package/dist/cjs/index.js +1 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Dialog.js +3 -607
- package/dist/esm/Dialog.js.map +2 -2
- package/dist/esm/Dialog.mjs +3 -607
- package/dist/esm/Dialog.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Dialog.js +3 -558
- package/dist/jsx/Dialog.js.map +2 -2
- package/dist/jsx/Dialog.mjs +3 -558
- package/dist/jsx/Dialog.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +18 -18
package/dist/esm/Dialog.mjs
CHANGED
|
@@ -1,610 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Adapt, useAdaptParent } from "@tamagui/adapt";
|
|
3
|
-
import { AnimatePresence } from "@tamagui/animate-presence";
|
|
4
|
-
import { hideOthers } from "@tamagui/aria-hidden";
|
|
5
|
-
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
6
|
-
import {
|
|
7
|
-
Theme,
|
|
8
|
-
composeEventHandlers,
|
|
9
|
-
isWeb,
|
|
10
|
-
spacedChildren,
|
|
11
|
-
styled,
|
|
12
|
-
useGet,
|
|
13
|
-
useId,
|
|
14
|
-
useMedia,
|
|
15
|
-
useThemeName,
|
|
16
|
-
withStaticProperties
|
|
17
|
-
} from "@tamagui/core";
|
|
18
|
-
import { createContext, createContextScope } from "@tamagui/create-context";
|
|
19
|
-
import { Dismissable } from "@tamagui/dismissable";
|
|
20
|
-
import { FocusScope } from "@tamagui/focus-scope";
|
|
21
|
-
import { PortalHost, PortalItem } from "@tamagui/portal";
|
|
22
|
-
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
23
|
-
import { ControlledSheet, SheetController, SheetOverlayFrame } from "@tamagui/sheet";
|
|
24
|
-
import { ThemeableStack, YStack } from "@tamagui/stacks";
|
|
25
|
-
import { H2, Paragraph } from "@tamagui/text";
|
|
26
|
-
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
27
|
-
import * as React from "react";
|
|
28
|
-
const DIALOG_NAME = "Dialog";
|
|
29
|
-
const [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);
|
|
30
|
-
const [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
|
|
31
|
-
const TRIGGER_NAME = "DialogTrigger";
|
|
32
|
-
const DialogTriggerFrame = styled(YStack, {
|
|
33
|
-
name: TRIGGER_NAME
|
|
34
|
-
});
|
|
35
|
-
const DialogTrigger = React.forwardRef(
|
|
36
|
-
(props, forwardedRef) => {
|
|
37
|
-
const { __scopeDialog, ...triggerProps } = props;
|
|
38
|
-
const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
|
|
39
|
-
const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
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
|
-
);
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
DialogTrigger.displayName = TRIGGER_NAME;
|
|
56
|
-
const PORTAL_NAME = "DialogPortal";
|
|
57
|
-
const [PortalProvider, usePortalContext] = createDialogContext(
|
|
58
|
-
PORTAL_NAME,
|
|
59
|
-
{
|
|
60
|
-
forceMount: void 0
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
const DialogPortalFrame = styled(YStack, {
|
|
64
|
-
alignItems: "center",
|
|
65
|
-
justifyContent: "center",
|
|
66
|
-
fullscreen: true,
|
|
67
|
-
zIndex: 100,
|
|
68
|
-
...isWeb && {
|
|
69
|
-
maxHeight: "100vh",
|
|
70
|
-
position: "fixed"
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
const DialogPortalItem = (props) => {
|
|
74
|
-
const themeName = useThemeName();
|
|
75
|
-
const context = useDialogContext(PORTAL_NAME, props.__scopeDialog);
|
|
76
|
-
return /* @__PURE__ */ jsx(PortalItem, { hostName: props.hostName, children: /* @__PURE__ */ jsx(DialogPortalItemContent, { ...props, themeName, context }) });
|
|
77
|
-
};
|
|
78
|
-
function DialogPortalItemContent(props) {
|
|
79
|
-
const {
|
|
80
|
-
__scopeDialog,
|
|
81
|
-
children,
|
|
82
|
-
context,
|
|
83
|
-
themeName,
|
|
84
|
-
space,
|
|
85
|
-
spaceDirection,
|
|
86
|
-
separator
|
|
87
|
-
} = props;
|
|
88
|
-
let childrenSpaced = children;
|
|
89
|
-
if (space || separator) {
|
|
90
|
-
childrenSpaced = spacedChildren({
|
|
91
|
-
children,
|
|
92
|
-
separator,
|
|
93
|
-
space,
|
|
94
|
-
direction: spaceDirection
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return /* @__PURE__ */ jsx(DialogProvider, { scope: __scopeDialog, ...context, children: /* @__PURE__ */ jsx(Theme, { name: themeName, children: childrenSpaced }) });
|
|
98
|
-
}
|
|
99
|
-
const DialogPortal = (props) => {
|
|
100
|
-
const { __scopeDialog, forceMount, children, ...frameProps } = props;
|
|
101
|
-
const context = useDialogContext(PORTAL_NAME, __scopeDialog);
|
|
102
|
-
const isShowing = forceMount || context.open;
|
|
103
|
-
const [isFullyHidden, setIsFullyHidden] = React.useState(!isShowing);
|
|
104
|
-
if (isShowing && isFullyHidden) {
|
|
105
|
-
setIsFullyHidden(false);
|
|
106
|
-
}
|
|
107
|
-
const contents = /* @__PURE__ */ jsx(
|
|
108
|
-
AnimatePresence,
|
|
109
|
-
{
|
|
110
|
-
onExitComplete: () => {
|
|
111
|
-
setIsFullyHidden(true);
|
|
112
|
-
},
|
|
113
|
-
children: isShowing ? children : null
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
const isSheet = useShowDialogSheet(context);
|
|
117
|
-
if (isSheet) {
|
|
118
|
-
return children;
|
|
119
|
-
}
|
|
120
|
-
if (context.modal) {
|
|
121
|
-
if (isFullyHidden) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
return /* @__PURE__ */ jsx(DialogPortalItem, { __scopeDialog, children: /* @__PURE__ */ jsx(PortalProvider, { scope: __scopeDialog, forceMount, children: /* @__PURE__ */ jsx(DialogPortalFrame, { pointerEvents: isShowing ? "auto" : "none", ...frameProps, children: contents }) }) });
|
|
125
|
-
}
|
|
126
|
-
return contents;
|
|
127
|
-
};
|
|
128
|
-
DialogPortal.displayName = PORTAL_NAME;
|
|
129
|
-
const OVERLAY_NAME = "DialogOverlay";
|
|
130
|
-
const DialogOverlayFrame = styled(SheetOverlayFrame, {
|
|
131
|
-
name: OVERLAY_NAME
|
|
132
|
-
});
|
|
133
|
-
const DialogOverlay = DialogOverlayFrame.extractable(
|
|
134
|
-
React.forwardRef(
|
|
135
|
-
({ __scopeDialog, ...props }, forwardedRef) => {
|
|
136
|
-
const portalContext = usePortalContext(OVERLAY_NAME, __scopeDialog);
|
|
137
|
-
const { forceMount = portalContext.forceMount, ...overlayProps } = props;
|
|
138
|
-
const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
|
|
139
|
-
const showSheet = useShowDialogSheet(context);
|
|
140
|
-
if (!forceMount) {
|
|
141
|
-
if (!context.modal || showSheet) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return /* @__PURE__ */ jsx(DialogOverlayImpl, { context, ...overlayProps, ref: forwardedRef });
|
|
146
|
-
}
|
|
147
|
-
)
|
|
148
|
-
);
|
|
149
|
-
DialogOverlay.displayName = OVERLAY_NAME;
|
|
150
|
-
const DialogOverlayImpl = React.forwardRef(
|
|
151
|
-
(props, forwardedRef) => {
|
|
152
|
-
const { context, ...overlayProps } = props;
|
|
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
|
-
);
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
const CONTENT_NAME = "DialogContent";
|
|
169
|
-
const DialogContentFrame = styled(ThemeableStack, {
|
|
170
|
-
name: CONTENT_NAME,
|
|
171
|
-
tag: "dialog",
|
|
172
|
-
position: "relative",
|
|
173
|
-
backgrounded: true,
|
|
174
|
-
padded: true,
|
|
175
|
-
radiused: true,
|
|
176
|
-
elevate: true,
|
|
177
|
-
variants: {
|
|
178
|
-
size: {
|
|
179
|
-
"...size": (val, extras) => {
|
|
180
|
-
return {};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
defaultVariants: {
|
|
185
|
-
size: "$true"
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
const DialogContent = DialogContentFrame.extractable(
|
|
189
|
-
React.forwardRef(
|
|
190
|
-
({ __scopeDialog, ...props }, forwardedRef) => {
|
|
191
|
-
const portalContext = usePortalContext(CONTENT_NAME, __scopeDialog);
|
|
192
|
-
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
193
|
-
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
194
|
-
const contents = context.modal ? /* @__PURE__ */ jsx(DialogContentModal, { context, ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(DialogContentNonModal, { context, ...contentProps, ref: forwardedRef });
|
|
195
|
-
if (!isWeb) {
|
|
196
|
-
return contents;
|
|
197
|
-
}
|
|
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
|
-
);
|
|
209
|
-
}
|
|
210
|
-
)
|
|
211
|
-
);
|
|
212
|
-
DialogContent.displayName = CONTENT_NAME;
|
|
213
|
-
const DialogContentModal = React.forwardRef(
|
|
214
|
-
({ children, context, ...props }, forwardedRef) => {
|
|
215
|
-
const contentRef = React.useRef(null);
|
|
216
|
-
const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
217
|
-
if (isWeb) {
|
|
218
|
-
React.useEffect(() => {
|
|
219
|
-
if (!context.open)
|
|
220
|
-
return;
|
|
221
|
-
const content = contentRef.current;
|
|
222
|
-
if (content)
|
|
223
|
-
return hideOthers(content);
|
|
224
|
-
}, [context.open]);
|
|
225
|
-
}
|
|
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
|
-
);
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
const DialogContentNonModal = React.forwardRef(
|
|
258
|
-
(props, forwardedRef) => {
|
|
259
|
-
const hasInteractedOutsideRef = React.useRef(false);
|
|
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();
|
|
275
|
-
}
|
|
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();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
const DialogContentImpl = React.forwardRef(
|
|
296
|
-
(props, forwardedRef) => {
|
|
297
|
-
const {
|
|
298
|
-
__scopeDialog,
|
|
299
|
-
trapFocus,
|
|
300
|
-
onOpenAutoFocus,
|
|
301
|
-
onCloseAutoFocus,
|
|
302
|
-
disableOutsidePointerEvents,
|
|
303
|
-
onEscapeKeyDown,
|
|
304
|
-
onPointerDownOutside,
|
|
305
|
-
onFocusOutside,
|
|
306
|
-
onInteractOutside,
|
|
307
|
-
context,
|
|
308
|
-
...contentProps
|
|
309
|
-
} = props;
|
|
310
|
-
const contentRef = React.useRef(null);
|
|
311
|
-
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
312
|
-
const showSheet = useShowDialogSheet(context);
|
|
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
|
-
);
|
|
323
|
-
if (showSheet) {
|
|
324
|
-
return /* @__PURE__ */ jsx(DialogPortalItem, { hostName: getSheetContentsName(context), children: contentProps.children });
|
|
325
|
-
}
|
|
326
|
-
if (!isWeb) {
|
|
327
|
-
return contents;
|
|
328
|
-
}
|
|
329
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
330
|
-
/* @__PURE__ */ jsx(
|
|
331
|
-
FocusScope,
|
|
332
|
-
{
|
|
333
|
-
loop: true,
|
|
334
|
-
trapped: trapFocus,
|
|
335
|
-
onMountAutoFocus: onOpenAutoFocus,
|
|
336
|
-
forceUnmount: !context.open,
|
|
337
|
-
onUnmountAutoFocus: onCloseAutoFocus,
|
|
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
|
-
] });
|
|
365
|
-
}
|
|
366
|
-
);
|
|
367
|
-
const TITLE_NAME = "DialogTitle";
|
|
368
|
-
const DialogTitleFrame = styled(H2, {
|
|
369
|
-
name: TITLE_NAME
|
|
370
|
-
});
|
|
371
|
-
const DialogTitle = React.forwardRef(
|
|
372
|
-
(props, forwardedRef) => {
|
|
373
|
-
const { __scopeDialog, ...titleProps } = props;
|
|
374
|
-
const context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
375
|
-
return /* @__PURE__ */ jsx(DialogTitleFrame, { id: context.titleId, ...titleProps, ref: forwardedRef });
|
|
376
|
-
}
|
|
377
|
-
);
|
|
378
|
-
DialogTitle.displayName = TITLE_NAME;
|
|
379
|
-
const DialogDescriptionFrame = styled(Paragraph, {
|
|
380
|
-
name: "DialogDescription"
|
|
381
|
-
});
|
|
382
|
-
const DESCRIPTION_NAME = "DialogDescription";
|
|
383
|
-
const DialogDescription = React.forwardRef(
|
|
384
|
-
(props, forwardedRef) => {
|
|
385
|
-
const { __scopeDialog, ...descriptionProps } = props;
|
|
386
|
-
const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
387
|
-
return /* @__PURE__ */ jsx(
|
|
388
|
-
DialogDescriptionFrame,
|
|
389
|
-
{
|
|
390
|
-
id: context.descriptionId,
|
|
391
|
-
...descriptionProps,
|
|
392
|
-
ref: forwardedRef
|
|
393
|
-
}
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
);
|
|
397
|
-
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
398
|
-
const CLOSE_NAME = "DialogClose";
|
|
399
|
-
const DialogClose = React.forwardRef(
|
|
400
|
-
(props, forwardedRef) => {
|
|
401
|
-
const { __scopeDialog, displayWhenAdapted, ...closeProps } = props;
|
|
402
|
-
const context = useDialogContext(CLOSE_NAME, __scopeDialog, {
|
|
403
|
-
warn: false,
|
|
404
|
-
fallback: {}
|
|
405
|
-
});
|
|
406
|
-
const isSheet = useShowDialogSheet(context);
|
|
407
|
-
if (isSheet && !displayWhenAdapted) {
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
return /* @__PURE__ */ jsx(
|
|
411
|
-
YStack,
|
|
412
|
-
{
|
|
413
|
-
tag: "button",
|
|
414
|
-
accessibilityLabel: "Dialog Close",
|
|
415
|
-
...closeProps,
|
|
416
|
-
ref: forwardedRef,
|
|
417
|
-
onPress: composeEventHandlers(
|
|
418
|
-
props.onPress,
|
|
419
|
-
() => context.onOpenChange(false)
|
|
420
|
-
)
|
|
421
|
-
}
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
);
|
|
425
|
-
DialogClose.displayName = CLOSE_NAME;
|
|
426
|
-
function getState(open) {
|
|
427
|
-
return open ? "open" : "closed";
|
|
428
|
-
}
|
|
429
|
-
const TITLE_WARNING_NAME = "DialogTitleWarning";
|
|
430
|
-
const [DialogWarningProvider, useWarningContext] = createContext(TITLE_WARNING_NAME, {
|
|
431
|
-
contentName: CONTENT_NAME,
|
|
432
|
-
titleName: TITLE_NAME,
|
|
433
|
-
docsSlug: "dialog"
|
|
434
|
-
});
|
|
435
|
-
const TitleWarning = ({ titleId }) => {
|
|
436
|
-
if (process.env.NODE_ENV === "development") {
|
|
437
|
-
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
|
|
438
|
-
const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
1
|
+
import{Fragment as ne,jsx as i,jsxs as re}from"react/jsx-runtime";import{Adapt as ue,useAdaptParent as ge}from"@tamagui/adapt";import{AnimatePresence as de}from"@tamagui/animate-presence";import{hideOthers as me}from"@tamagui/aria-hidden";import{useComposedRefs as F}from"@tamagui/compose-refs";import{Theme as fe,composeEventHandlers as P,isWeb as f,spacedChildren as De,styled as D,useGet as Pe,useId as N,useMedia as Ce,useThemeName as he,withStaticProperties as Se}from"@tamagui/core";import{createContext as ye,createContextScope as Te}from"@tamagui/create-context";import{Dismissable as Ee}from"@tamagui/dismissable";import{FocusScope as Oe}from"@tamagui/focus-scope";import{PortalHost as B,PortalItem as ve}from"@tamagui/portal";import{RemoveScroll as Ne}from"@tamagui/remove-scroll";import{ControlledSheet as Re,SheetController as xe,SheetOverlayFrame as Ie}from"@tamagui/sheet";import{ThemeableStack as be,YStack as A}from"@tamagui/stacks";import{H2 as Fe,Paragraph as Ae}from"@tamagui/text";import{useControllableState as we}from"@tamagui/use-controllable-state";import*as c from"react";const Y="Dialog",[Z,_e]=Te(Y),[$,g]=Z(Y),w="DialogTrigger",Me=D(A,{name:w}),_=c.forwardRef((e,o)=>{const{__scopeDialog:n,...t}=e,r=g(w,n),s=F(o,r.triggerRef);return i(Me,{tag:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":G(r.open),...t,ref:s,onPress:P(e.onPress,r.onOpenToggle)})});_.displayName=w;const R="DialogPortal",[ke,K]=Z(R,{forceMount:void 0}),We=D(A,{alignItems:"center",justifyContent:"center",fullscreen:!0,zIndex:100,...f&&{maxHeight:"100vh",position:"fixed"}}),j=e=>{const o=he(),n=g(R,e.__scopeDialog);return i(ve,{hostName:e.hostName,children:i(Ve,{...e,themeName:o,context:n})})};function Ve(e){const{__scopeDialog:o,children:n,context:t,themeName:r,space:s,spaceDirection:a,separator:l}=e;let u=n;return(s||l)&&(u=De({children:n,separator:l,space:s,direction:a})),i($,{scope:o,...t,children:i(fe,{name:r,children:u})})}const M=e=>{const{__scopeDialog:o,forceMount:n,children:t,...r}=e,s=g(R,o),a=n||s.open,[l,u]=c.useState(!a);a&&l&&u(!1);const d=i(de,{onExitComplete:()=>{u(!0)},children:a?t:null});return h(s)?t:s.modal?l?null:i(j,{__scopeDialog:o,children:i(ke,{scope:o,forceMount:n,children:i(We,{pointerEvents:a?"auto":"none",...r,children:d})})}):d};M.displayName=R;const x="DialogOverlay",z=D(Ie,{name:x}),k=z.extractable(c.forwardRef(({__scopeDialog:e,...o},n)=>{const t=K(x,e),{forceMount:r=t.forceMount,...s}=o,a=g(x,e),l=h(a);return!r&&(!a.modal||l)?null:i(He,{context:a,...s,ref:n})}));k.displayName=x;const He=c.forwardRef((e,o)=>{const{context:n,...t}=e;return i(z,{"data-state":G(n.open),pointerEvents:n.open?"auto":"none",...t,ref:o})}),C="DialogContent",U=D(be,{name:C,tag:"dialog",position:"relative",backgrounded:!0,padded:!0,radiused:!0,elevate:!0,variants:{size:{"...size":(e,o)=>({})}},defaultVariants:{size:"$true"}}),W=U.extractable(c.forwardRef(({__scopeDialog:e,...o},n)=>{const t=K(C,e),{forceMount:r=t.forceMount,...s}=o,a=g(C,e),l=a.modal?i(Le,{context:a,...s,ref:n}):i(Ge,{context:a,...s,ref:n});return f?i(Ne,{forwardProps:!0,enabled:a.open,allowPinchZoom:a.allowPinchZoom,shards:[a.contentRef],removeScrollBar:!1,children:i("div",{className:"_dsp_contents",children:l})}):l}));W.displayName=C;const Le=c.forwardRef(({children:e,context:o,...n},t)=>{const r=c.useRef(null),s=F(t,o.contentRef,r);return f&&c.useEffect(()=>{if(!o.open)return;const a=r.current;if(a)return me(a)},[o.open]),i(q,{...n,context:o,ref:s,disableOutsidePointerEvents:!0,onCloseAutoFocus:P(n.onCloseAutoFocus,a=>{var l;a.preventDefault(),(l=o.triggerRef.current)==null||l.focus()}),onPointerDownOutside:P(n.onPointerDownOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0;(l.button===2||u)&&a.preventDefault()}),onFocusOutside:P(n.onFocusOutside,a=>a.preventDefault()),children:e})}),Ge=c.forwardRef((e,o)=>{const n=c.useRef(!1);return i(q,{...e,ref:o,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{var r,s;(r=e.onCloseAutoFocus)==null||r.call(e,t),t.defaultPrevented||(n.current||(s=e.context.triggerRef.current)==null||s.focus(),t.preventDefault()),n.current=!1},onInteractOutside:t=>{var l;(l=e.onInteractOutside)==null||l.call(e,t),t.defaultPrevented||(n.current=!0);const r=t.target,s=e.context.triggerRef.current;if(!(s instanceof HTMLElement))return;s.contains(r)&&t.preventDefault()}})}),q=c.forwardRef((e,o)=>{const{__scopeDialog:n,trapFocus:t,onOpenAutoFocus:r,onCloseAutoFocus:s,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:S,context:p,...y}=e,T=c.useRef(null),E=F(o,T),O=h(p),v=i(U,{id:p.contentId,"aria-describedby":p.descriptionId,"aria-labelledby":p.titleId,"data-state":G(p.open),...y});return O?i(j,{hostName:oe(p),children:y.children}):f?re(ne,{children:[i(Oe,{loop:!0,trapped:t,onMountAutoFocus:r,forceUnmount:!p.open,onUnmountAutoFocus:s,children:i(Ee,{disableOutsidePointerEvents:p.open&&a,forceUnmount:!p.open,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:S,ref:E,onDismiss:()=>p.onOpenChange(!1),children:v})}),process.env.NODE_ENV==="development"&&re(ne,{children:[i($e,{titleId:p.titleId}),i(je,{contentRef:T,descriptionId:p.descriptionId})]})]}):v}),I="DialogTitle",Be=D(Fe,{name:I}),V=c.forwardRef((e,o)=>{const{__scopeDialog:n,...t}=e,r=g(I,n);return i(Be,{id:r.titleId,...t,ref:o})});V.displayName=I;const Ye=D(Ae,{name:"DialogDescription"}),J="DialogDescription",H=c.forwardRef((e,o)=>{const{__scopeDialog:n,...t}=e,r=g(J,n);return i(Ye,{id:r.descriptionId,...t,ref:o})});H.displayName=J;const Q="DialogClose",L=c.forwardRef((e,o)=>{const{__scopeDialog:n,displayWhenAdapted:t,...r}=e,s=g(Q,n,{warn:!1,fallback:{}});return h(s)&&!t?null:i(A,{tag:"button",accessibilityLabel:"Dialog Close",...r,ref:o,onPress:P(e.onPress,()=>s.onOpenChange(!1))})});L.displayName=Q;function G(e){return e?"open":"closed"}const X="DialogTitleWarning",[Ze,ee]=ye(X,{contentName:C,titleName:I,docsSlug:"dialog"}),$e=({titleId:e})=>{if(process.env.NODE_ENV==="development"){const o=ee(X),n=`\`${o.contentName}\` requires a \`${o.titleName}\` for the component to be accessible for screen reader users.
|
|
439
2
|
|
|
440
|
-
If you want to hide the \`${
|
|
3
|
+
If you want to hide the \`${o.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
441
4
|
|
|
442
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${
|
|
443
|
-
React.useEffect(() => {
|
|
444
|
-
if (!isWeb)
|
|
445
|
-
return;
|
|
446
|
-
if (titleId) {
|
|
447
|
-
const hasTitle = document.getElementById(titleId);
|
|
448
|
-
if (!hasTitle) {
|
|
449
|
-
console.warn(MESSAGE);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}, [MESSAGE, titleId]);
|
|
453
|
-
}
|
|
454
|
-
return null;
|
|
455
|
-
};
|
|
456
|
-
const DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
|
|
457
|
-
const DescriptionWarning = ({
|
|
458
|
-
contentRef,
|
|
459
|
-
descriptionId
|
|
460
|
-
}) => {
|
|
461
|
-
if (process.env.NODE_ENV === "development") {
|
|
462
|
-
const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
|
|
463
|
-
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
|
|
464
|
-
React.useEffect(() => {
|
|
465
|
-
if (!isWeb)
|
|
466
|
-
return;
|
|
467
|
-
const contentNode = contentRef.current;
|
|
468
|
-
if (!(contentNode instanceof HTMLElement)) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
const describedById = contentNode.getAttribute("aria-describedby");
|
|
472
|
-
if (descriptionId && describedById) {
|
|
473
|
-
const hasDescription = document.getElementById(descriptionId);
|
|
474
|
-
if (!hasDescription) {
|
|
475
|
-
console.warn(MESSAGE);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}, [MESSAGE, contentRef, descriptionId]);
|
|
479
|
-
}
|
|
480
|
-
return null;
|
|
481
|
-
};
|
|
482
|
-
const Dialog = withStaticProperties(
|
|
483
|
-
React.forwardRef(function Dialog2(props, ref) {
|
|
484
|
-
const {
|
|
485
|
-
__scopeDialog,
|
|
486
|
-
children,
|
|
487
|
-
open: openProp,
|
|
488
|
-
defaultOpen = false,
|
|
489
|
-
onOpenChange,
|
|
490
|
-
modal = true,
|
|
491
|
-
allowPinchZoom = false
|
|
492
|
-
} = props;
|
|
493
|
-
const scopeId = useId();
|
|
494
|
-
const contentId = useId();
|
|
495
|
-
const titleId = useId();
|
|
496
|
-
const descriptionId = useId();
|
|
497
|
-
const scopeKey = __scopeDialog ? Object.keys(__scopeDialog)[0] : scopeId;
|
|
498
|
-
const sheetContentsName = getSheetContentsName({ scopeKey, contentId });
|
|
499
|
-
const triggerRef = React.useRef(null);
|
|
500
|
-
const contentRef = React.useRef(null);
|
|
501
|
-
const [open, setOpen] = useControllableState({
|
|
502
|
-
prop: openProp,
|
|
503
|
-
defaultProp: defaultOpen,
|
|
504
|
-
onChange: onOpenChange
|
|
505
|
-
});
|
|
506
|
-
const onOpenToggle = React.useCallback(() => {
|
|
507
|
-
setOpen((prevOpen) => !prevOpen);
|
|
508
|
-
}, [setOpen]);
|
|
509
|
-
const context = {
|
|
510
|
-
scope: __scopeDialog,
|
|
511
|
-
scopeKey,
|
|
512
|
-
triggerRef,
|
|
513
|
-
contentRef,
|
|
514
|
-
contentId,
|
|
515
|
-
titleId,
|
|
516
|
-
descriptionId,
|
|
517
|
-
open,
|
|
518
|
-
onOpenChange: setOpen,
|
|
519
|
-
onOpenToggle,
|
|
520
|
-
modal,
|
|
521
|
-
allowPinchZoom
|
|
522
|
-
};
|
|
523
|
-
const { when, AdaptProvider } = useAdaptParent({
|
|
524
|
-
Contents: React.useCallback(
|
|
525
|
-
(props2) => {
|
|
526
|
-
return /* @__PURE__ */ jsx(PortalHost, { forwardProps: props2, name: sheetContentsName });
|
|
527
|
-
},
|
|
528
|
-
[sheetContentsName]
|
|
529
|
-
)
|
|
530
|
-
});
|
|
531
|
-
React.useImperativeHandle(
|
|
532
|
-
ref,
|
|
533
|
-
() => ({
|
|
534
|
-
open: setOpen
|
|
535
|
-
}),
|
|
536
|
-
[setOpen]
|
|
537
|
-
);
|
|
538
|
-
return /* @__PURE__ */ jsx(AdaptProvider, { children: /* @__PURE__ */ jsx(DialogProvider, { ...context, sheetBreakpoint: when, children: /* @__PURE__ */ jsx(DialogSheetController, { onOpenChange: setOpen, __scopeDialog, children }) }) });
|
|
539
|
-
}),
|
|
540
|
-
{
|
|
541
|
-
Trigger: DialogTrigger,
|
|
542
|
-
Portal: DialogPortal,
|
|
543
|
-
Overlay: DialogOverlay,
|
|
544
|
-
Content: DialogContent,
|
|
545
|
-
Title: DialogTitle,
|
|
546
|
-
Description: DialogDescription,
|
|
547
|
-
Close: DialogClose,
|
|
548
|
-
Sheet: ControlledSheet,
|
|
549
|
-
Adapt
|
|
550
|
-
}
|
|
551
|
-
);
|
|
552
|
-
const SHEET_CONTENTS_NAME = "DialogSheetContents";
|
|
553
|
-
const DialogSheetContents = ({
|
|
554
|
-
name,
|
|
555
|
-
...props
|
|
556
|
-
}) => {
|
|
557
|
-
return /* @__PURE__ */ jsx(PortalHost, { forwardProps: props, name });
|
|
558
|
-
};
|
|
559
|
-
DialogSheetContents.displayName = SHEET_CONTENTS_NAME;
|
|
560
|
-
const getSheetContentsName = ({
|
|
561
|
-
scopeKey,
|
|
562
|
-
contentId
|
|
563
|
-
}) => `${scopeKey || contentId}SheetContents`;
|
|
564
|
-
const DialogSheetController = (props) => {
|
|
565
|
-
const context = useDialogContext("DialogSheetController", props.__scopeDialog);
|
|
566
|
-
const showSheet = useShowDialogSheet(context);
|
|
567
|
-
const breakpointActive = useSheetBreakpointActive(context);
|
|
568
|
-
const getShowSheet = useGet(showSheet);
|
|
569
|
-
return /* @__PURE__ */ jsx(
|
|
570
|
-
SheetController,
|
|
571
|
-
{
|
|
572
|
-
onOpenChange: (val) => {
|
|
573
|
-
if (getShowSheet()) {
|
|
574
|
-
props.onOpenChange(val);
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
open: context.open,
|
|
578
|
-
hidden: breakpointActive === false,
|
|
579
|
-
children: props.children
|
|
580
|
-
}
|
|
581
|
-
);
|
|
582
|
-
};
|
|
583
|
-
const useSheetBreakpointActive = (context) => {
|
|
584
|
-
const media = useMedia();
|
|
585
|
-
if (!context.sheetBreakpoint)
|
|
586
|
-
return false;
|
|
587
|
-
if (context.sheetBreakpoint === true)
|
|
588
|
-
return true;
|
|
589
|
-
return media[context.sheetBreakpoint];
|
|
590
|
-
};
|
|
591
|
-
const useShowDialogSheet = (context) => {
|
|
592
|
-
const breakpointActive = useSheetBreakpointActive(context);
|
|
593
|
-
return context.open === false ? false : breakpointActive;
|
|
594
|
-
};
|
|
595
|
-
export {
|
|
596
|
-
Dialog,
|
|
597
|
-
DialogClose,
|
|
598
|
-
DialogContent,
|
|
599
|
-
DialogDescription,
|
|
600
|
-
DialogOverlay,
|
|
601
|
-
DialogOverlayFrame,
|
|
602
|
-
DialogPortal,
|
|
603
|
-
DialogPortalFrame,
|
|
604
|
-
DialogSheetContents,
|
|
605
|
-
DialogTitle,
|
|
606
|
-
DialogTrigger,
|
|
607
|
-
DialogWarningProvider,
|
|
608
|
-
createDialogScope
|
|
609
|
-
};
|
|
5
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${o.docsSlug}`;c.useEffect(()=>{f&&e&&(document.getElementById(e)||console.warn(n))},[n,e])}return null},Ke="DialogDescriptionWarning",je=({contentRef:e,descriptionId:o})=>{if(process.env.NODE_ENV==="development"){const t=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${ee(Ke).contentName}}.`;c.useEffect(()=>{if(!f)return;const r=e.current;if(!(r instanceof HTMLElement))return;const s=r.getAttribute("aria-describedby");o&&s&&(document.getElementById(o)||console.warn(t))},[t,e,o])}return null},ze=Se(c.forwardRef(function(o,n){const{__scopeDialog:t,children:r,open:s,defaultOpen:a=!1,onOpenChange:l,modal:u=!0,allowPinchZoom:d=!1}=o,S=N(),p=N(),y=N(),T=N(),E=t?Object.keys(t)[0]:S,O=oe({scopeKey:E,contentId:p}),v=c.useRef(null),ae=c.useRef(null),[se,m]=we({prop:s,defaultProp:a,onChange:l}),ie=c.useCallback(()=>{m(b=>!b)},[m]),le={scope:t,scopeKey:E,triggerRef:v,contentRef:ae,contentId:p,titleId:y,descriptionId:T,open:se,onOpenChange:m,onOpenToggle:ie,modal:u,allowPinchZoom:d},{when:ce,AdaptProvider:pe}=ge({Contents:c.useCallback(b=>i(B,{forwardProps:b,name:O}),[O])});return c.useImperativeHandle(n,()=>({open:m}),[m]),i(pe,{children:i($,{...le,sheetBreakpoint:ce,children:i(Je,{onOpenChange:m,__scopeDialog:t,children:r})})})}),{Trigger:_,Portal:M,Overlay:k,Content:W,Title:V,Description:H,Close:L,Sheet:Re,Adapt:ue}),Ue="DialogSheetContents",qe=({name:e,...o})=>i(B,{forwardProps:o,name:e});qe.displayName=Ue;const oe=({scopeKey:e,contentId:o})=>`${e||o}SheetContents`,Je=e=>{const o=g("DialogSheetController",e.__scopeDialog),n=h(o),t=te(o),r=Pe(n);return i(xe,{onOpenChange:s=>{r()&&e.onOpenChange(s)},open:o.open,hidden:t===!1,children:e.children})},te=e=>{const o=Ce();return e.sheetBreakpoint?e.sheetBreakpoint===!0?!0:o[e.sheetBreakpoint]:!1},h=e=>{const o=te(e);return e.open===!1?!1:o};export{ze as Dialog,L as DialogClose,W as DialogContent,H as DialogDescription,k as DialogOverlay,z as DialogOverlayFrame,M as DialogPortal,We as DialogPortalFrame,qe as DialogSheetContents,V as DialogTitle,_ as DialogTrigger,Ze as DialogWarningProvider,_e as createDialogScope};
|
|
610
6
|
//# sourceMappingURL=Dialog.mjs.map
|