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