@tamagui/dialog 1.14.1 → 1.14.2
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 +642 -3
- package/dist/cjs/Dialog.js.map +2 -2
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Dialog.js +607 -3
- package/dist/esm/Dialog.js.map +2 -2
- package/dist/esm/Dialog.mjs +607 -3
- 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 +558 -3
- package/dist/jsx/Dialog.js.map +2 -2
- package/dist/jsx/Dialog.mjs +558 -3
- 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.mjs
CHANGED
|
@@ -1,6 +1,561 @@
|
|
|
1
|
-
import
|
|
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 {
|
|
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.
|
|
2
394
|
|
|
3
|
-
If you want to hide the \`${
|
|
395
|
+
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
4
396
|
|
|
5
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${
|
|
397
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
|
|
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
|
+
};
|
|
6
561
|
//# sourceMappingURL=Dialog.mjs.map
|