@radix-ui/react-dialog 1.0.6-rc.6 → 1.1.0-rc.1
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/index.d.mts +52 -40
- package/dist/index.d.ts +52 -40
- package/dist/index.js +324 -363
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +309 -336
- package/dist/index.mjs.map +7 -1
- package/package.json +13 -14
- package/dist/index.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,365 +1,338 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {composeEventHandlers
|
|
4
|
-
import {useComposedRefs
|
|
5
|
-
import {
|
|
6
|
-
import {useId
|
|
7
|
-
import {useControllableState
|
|
8
|
-
import {DismissableLayer
|
|
9
|
-
import {FocusScope
|
|
10
|
-
import {Portal as
|
|
11
|
-
import {Presence
|
|
12
|
-
import {Primitive
|
|
13
|
-
import {useFocusGuards
|
|
14
|
-
import {RemoveScroll
|
|
15
|
-
import {hideOthers
|
|
16
|
-
import {Slot
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
titleId: $67UHm$useId(),
|
|
54
|
-
descriptionId: $67UHm$useId(),
|
|
55
|
-
open: open,
|
|
56
|
-
onOpenChange: setOpen,
|
|
57
|
-
onOpenToggle: $67UHm$useCallback(()=>setOpen((prevOpen)=>!prevOpen
|
|
58
|
-
)
|
|
59
|
-
, [
|
|
60
|
-
setOpen
|
|
61
|
-
]),
|
|
62
|
-
modal: modal
|
|
63
|
-
}, children);
|
|
1
|
+
// packages/react/dialog/src/Dialog.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
4
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
5
|
+
import { createContext, createContextScope } from "@radix-ui/react-context";
|
|
6
|
+
import { useId } from "@radix-ui/react-id";
|
|
7
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
8
|
+
import { DismissableLayer } from "@radix-ui/react-dismissable-layer";
|
|
9
|
+
import { FocusScope } from "@radix-ui/react-focus-scope";
|
|
10
|
+
import { Portal as PortalPrimitive } from "@radix-ui/react-portal";
|
|
11
|
+
import { Presence } from "@radix-ui/react-presence";
|
|
12
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
13
|
+
import { useFocusGuards } from "@radix-ui/react-focus-guards";
|
|
14
|
+
import { RemoveScroll } from "react-remove-scroll";
|
|
15
|
+
import { hideOthers } from "aria-hidden";
|
|
16
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
17
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
var DIALOG_NAME = "Dialog";
|
|
19
|
+
var [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);
|
|
20
|
+
var [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
|
|
21
|
+
var Dialog = (props) => {
|
|
22
|
+
const {
|
|
23
|
+
__scopeDialog,
|
|
24
|
+
children,
|
|
25
|
+
open: openProp,
|
|
26
|
+
defaultOpen,
|
|
27
|
+
onOpenChange,
|
|
28
|
+
modal = true
|
|
29
|
+
} = props;
|
|
30
|
+
const triggerRef = React.useRef(null);
|
|
31
|
+
const contentRef = React.useRef(null);
|
|
32
|
+
const [open = false, setOpen] = useControllableState({
|
|
33
|
+
prop: openProp,
|
|
34
|
+
defaultProp: defaultOpen,
|
|
35
|
+
onChange: onOpenChange
|
|
36
|
+
});
|
|
37
|
+
return /* @__PURE__ */ jsx(
|
|
38
|
+
DialogProvider,
|
|
39
|
+
{
|
|
40
|
+
scope: __scopeDialog,
|
|
41
|
+
triggerRef,
|
|
42
|
+
contentRef,
|
|
43
|
+
contentId: useId(),
|
|
44
|
+
titleId: useId(),
|
|
45
|
+
descriptionId: useId(),
|
|
46
|
+
open,
|
|
47
|
+
onOpenChange: setOpen,
|
|
48
|
+
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
49
|
+
modal,
|
|
50
|
+
children
|
|
51
|
+
}
|
|
52
|
+
);
|
|
64
53
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.button, $67UHm$babelruntimehelpersesmextends({
|
|
54
|
+
Dialog.displayName = DIALOG_NAME;
|
|
55
|
+
var TRIGGER_NAME = "DialogTrigger";
|
|
56
|
+
var DialogTrigger = React.forwardRef(
|
|
57
|
+
(props, forwardedRef) => {
|
|
58
|
+
const { __scopeDialog, ...triggerProps } = props;
|
|
59
|
+
const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
|
|
60
|
+
const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
61
|
+
return /* @__PURE__ */ jsx(
|
|
62
|
+
Primitive.button,
|
|
63
|
+
{
|
|
76
64
|
type: "button",
|
|
77
65
|
"aria-haspopup": "dialog",
|
|
78
66
|
"aria-expanded": context.open,
|
|
79
67
|
"aria-controls": context.contentId,
|
|
80
|
-
"data-state":
|
|
81
|
-
|
|
68
|
+
"data-state": getState(context.open),
|
|
69
|
+
...triggerProps,
|
|
82
70
|
ref: composedTriggerRef,
|
|
83
|
-
onClick:
|
|
84
|
-
|
|
71
|
+
onClick: composeEventHandlers(props.onClick, context.onOpenToggle)
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
DialogTrigger.displayName = TRIGGER_NAME;
|
|
77
|
+
var PORTAL_NAME = "DialogPortal";
|
|
78
|
+
var [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
|
|
79
|
+
forceMount: void 0
|
|
85
80
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/*
|
|
90
|
-
* DialogPortal
|
|
91
|
-
* -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$PORTAL_NAME = 'DialogPortal';
|
|
92
|
-
const [$5d3850c4d0b4e6c7$var$PortalProvider, $5d3850c4d0b4e6c7$var$usePortalContext] = $5d3850c4d0b4e6c7$var$createDialogContext($5d3850c4d0b4e6c7$var$PORTAL_NAME, {
|
|
93
|
-
forceMount: undefined
|
|
94
|
-
});
|
|
95
|
-
const $5d3850c4d0b4e6c7$export$dad7c95542bacce0 = (props)=>{
|
|
96
|
-
const { __scopeDialog: __scopeDialog , forceMount: forceMount , children: children , container: container } = props;
|
|
97
|
-
const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$PORTAL_NAME, __scopeDialog);
|
|
98
|
-
return /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$PortalProvider, {
|
|
99
|
-
scope: __scopeDialog,
|
|
100
|
-
forceMount: forceMount
|
|
101
|
-
}, $67UHm$Children.map(children, (child)=>/*#__PURE__*/ $67UHm$createElement($67UHm$Presence, {
|
|
102
|
-
present: forceMount || context.open
|
|
103
|
-
}, /*#__PURE__*/ $67UHm$createElement($67UHm$Portal, {
|
|
104
|
-
asChild: true,
|
|
105
|
-
container: container
|
|
106
|
-
}, child))
|
|
107
|
-
));
|
|
81
|
+
var DialogPortal = (props) => {
|
|
82
|
+
const { __scopeDialog, forceMount, children, container } = props;
|
|
83
|
+
const context = useDialogContext(PORTAL_NAME, __scopeDialog);
|
|
84
|
+
return /* @__PURE__ */ jsx(PortalProvider, { scope: __scopeDialog, forceMount, children: React.Children.map(children, (child) => /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(PortalPrimitive, { asChild: true, container, children: child }) })) });
|
|
108
85
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
as: $67UHm$Slot,
|
|
135
|
-
allowPinchZoom: true,
|
|
136
|
-
shards: [
|
|
137
|
-
context.contentRef
|
|
138
|
-
]
|
|
139
|
-
}, /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.div, $67UHm$babelruntimehelpersesmextends({
|
|
140
|
-
"data-state": $5d3850c4d0b4e6c7$var$getState(context.open)
|
|
141
|
-
}, overlayProps, {
|
|
142
|
-
ref: forwardedRef // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.
|
|
143
|
-
,
|
|
144
|
-
style: {
|
|
145
|
-
pointerEvents: 'auto',
|
|
146
|
-
...overlayProps.style
|
|
86
|
+
DialogPortal.displayName = PORTAL_NAME;
|
|
87
|
+
var OVERLAY_NAME = "DialogOverlay";
|
|
88
|
+
var DialogOverlay = React.forwardRef(
|
|
89
|
+
(props, forwardedRef) => {
|
|
90
|
+
const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);
|
|
91
|
+
const { forceMount = portalContext.forceMount, ...overlayProps } = props;
|
|
92
|
+
const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);
|
|
93
|
+
return context.modal ? /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(DialogOverlayImpl, { ...overlayProps, ref: forwardedRef }) }) : null;
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
DialogOverlay.displayName = OVERLAY_NAME;
|
|
97
|
+
var DialogOverlayImpl = React.forwardRef(
|
|
98
|
+
(props, forwardedRef) => {
|
|
99
|
+
const { __scopeDialog, ...overlayProps } = props;
|
|
100
|
+
const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
|
|
101
|
+
return (
|
|
102
|
+
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
|
|
103
|
+
// ie. when `Overlay` and `Content` are siblings
|
|
104
|
+
/* @__PURE__ */ jsx(RemoveScroll, { as: Slot, allowPinchZoom: true, shards: [context.contentRef], children: /* @__PURE__ */ jsx(
|
|
105
|
+
Primitive.div,
|
|
106
|
+
{
|
|
107
|
+
"data-state": getState(context.open),
|
|
108
|
+
...overlayProps,
|
|
109
|
+
ref: forwardedRef,
|
|
110
|
+
style: { pointerEvents: "auto", ...overlayProps.style }
|
|
147
111
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const contentRef = $67UHm$useRef(null);
|
|
171
|
-
const composedRefs = $67UHm$useComposedRefs(forwardedRef, context.contentRef, contentRef); // aria-hide everything except the content (better supported equivalent to setting aria-modal)
|
|
172
|
-
$67UHm$useEffect(()=>{
|
|
173
|
-
const content = contentRef.current;
|
|
174
|
-
if (content) return $67UHm$hideOthers(content);
|
|
112
|
+
) })
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
var CONTENT_NAME = "DialogContent";
|
|
117
|
+
var DialogContent = React.forwardRef(
|
|
118
|
+
(props, forwardedRef) => {
|
|
119
|
+
const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);
|
|
120
|
+
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
121
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
122
|
+
return /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ jsx(DialogContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(DialogContentNonModal, { ...contentProps, ref: forwardedRef }) });
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
DialogContent.displayName = CONTENT_NAME;
|
|
126
|
+
var DialogContentModal = React.forwardRef(
|
|
127
|
+
(props, forwardedRef) => {
|
|
128
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
129
|
+
const contentRef = React.useRef(null);
|
|
130
|
+
const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
131
|
+
React.useEffect(() => {
|
|
132
|
+
const content = contentRef.current;
|
|
133
|
+
if (content) return hideOthers(content);
|
|
175
134
|
}, []);
|
|
176
|
-
return
|
|
177
|
-
|
|
178
|
-
|
|
135
|
+
return /* @__PURE__ */ jsx(
|
|
136
|
+
DialogContentImpl,
|
|
137
|
+
{
|
|
138
|
+
...props,
|
|
139
|
+
ref: composedRefs,
|
|
179
140
|
trapFocus: context.open,
|
|
180
141
|
disableOutsidePointerEvents: true,
|
|
181
|
-
onCloseAutoFocus:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
142
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
context.triggerRef.current?.focus();
|
|
145
|
+
}),
|
|
146
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, (event) => {
|
|
147
|
+
const originalEvent = event.detail.originalEvent;
|
|
148
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
149
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
150
|
+
if (isRightClick) event.preventDefault();
|
|
185
151
|
}),
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const isRightClick = originalEvent.button === 2 || ctrlLeftClick; // If the event is a right-click, we shouldn't close because
|
|
190
|
-
// it is effectively as if we right-clicked the `Overlay`.
|
|
191
|
-
if (isRightClick) event.preventDefault();
|
|
192
|
-
}) // When focus is trapped, a `focusout` event may still happen.
|
|
193
|
-
,
|
|
194
|
-
onFocusOutside: $67UHm$composeEventHandlers(props.onFocusOutside, (event)=>event.preventDefault()
|
|
152
|
+
onFocusOutside: composeEventHandlers(
|
|
153
|
+
props.onFocusOutside,
|
|
154
|
+
(event) => event.preventDefault()
|
|
195
155
|
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
var DialogContentNonModal = React.forwardRef(
|
|
161
|
+
(props, forwardedRef) => {
|
|
162
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
163
|
+
const hasInteractedOutsideRef = React.useRef(false);
|
|
164
|
+
const hasPointerDownOutsideRef = React.useRef(false);
|
|
165
|
+
return /* @__PURE__ */ jsx(
|
|
166
|
+
DialogContentImpl,
|
|
167
|
+
{
|
|
168
|
+
...props,
|
|
203
169
|
ref: forwardedRef,
|
|
204
170
|
trapFocus: false,
|
|
205
171
|
disableOutsidePointerEvents: false,
|
|
206
|
-
onCloseAutoFocus: (event)=>{
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (!
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
hasInteractedOutsideRef.current = false;
|
|
215
|
-
hasPointerDownOutsideRef.current = false;
|
|
172
|
+
onCloseAutoFocus: (event) => {
|
|
173
|
+
props.onCloseAutoFocus?.(event);
|
|
174
|
+
if (!event.defaultPrevented) {
|
|
175
|
+
if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
}
|
|
178
|
+
hasInteractedOutsideRef.current = false;
|
|
179
|
+
hasPointerDownOutsideRef.current = false;
|
|
216
180
|
},
|
|
217
|
-
onInteractOutside: (event)=>{
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// already had a pointer down outside event.
|
|
232
|
-
if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) event.preventDefault();
|
|
181
|
+
onInteractOutside: (event) => {
|
|
182
|
+
props.onInteractOutside?.(event);
|
|
183
|
+
if (!event.defaultPrevented) {
|
|
184
|
+
hasInteractedOutsideRef.current = true;
|
|
185
|
+
if (event.detail.originalEvent.type === "pointerdown") {
|
|
186
|
+
hasPointerDownOutsideRef.current = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const target = event.target;
|
|
190
|
+
const targetIsTrigger = context.triggerRef.current?.contains(target);
|
|
191
|
+
if (targetIsTrigger) event.preventDefault();
|
|
192
|
+
if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
}
|
|
233
195
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const { __scopeDialog
|
|
280
|
-
const context =
|
|
281
|
-
return
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
/*
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
var DialogContentImpl = React.forwardRef(
|
|
201
|
+
(props, forwardedRef) => {
|
|
202
|
+
const { __scopeDialog, trapFocus, onOpenAutoFocus, onCloseAutoFocus, ...contentProps } = props;
|
|
203
|
+
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
204
|
+
const contentRef = React.useRef(null);
|
|
205
|
+
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
206
|
+
useFocusGuards();
|
|
207
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
208
|
+
/* @__PURE__ */ jsx(
|
|
209
|
+
FocusScope,
|
|
210
|
+
{
|
|
211
|
+
asChild: true,
|
|
212
|
+
loop: true,
|
|
213
|
+
trapped: trapFocus,
|
|
214
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
215
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
216
|
+
children: /* @__PURE__ */ jsx(
|
|
217
|
+
DismissableLayer,
|
|
218
|
+
{
|
|
219
|
+
role: "dialog",
|
|
220
|
+
id: context.contentId,
|
|
221
|
+
"aria-describedby": context.descriptionId,
|
|
222
|
+
"aria-labelledby": context.titleId,
|
|
223
|
+
"data-state": getState(context.open),
|
|
224
|
+
...contentProps,
|
|
225
|
+
ref: composedRefs,
|
|
226
|
+
onDismiss: () => context.onOpenChange(false)
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
232
|
+
/* @__PURE__ */ jsx(TitleWarning, { titleId: context.titleId }),
|
|
233
|
+
/* @__PURE__ */ jsx(DescriptionWarning, { contentRef, descriptionId: context.descriptionId })
|
|
234
|
+
] })
|
|
235
|
+
] });
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
var TITLE_NAME = "DialogTitle";
|
|
239
|
+
var DialogTitle = React.forwardRef(
|
|
240
|
+
(props, forwardedRef) => {
|
|
241
|
+
const { __scopeDialog, ...titleProps } = props;
|
|
242
|
+
const context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
243
|
+
return /* @__PURE__ */ jsx(Primitive.h2, { id: context.titleId, ...titleProps, ref: forwardedRef });
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
DialogTitle.displayName = TITLE_NAME;
|
|
247
|
+
var DESCRIPTION_NAME = "DialogDescription";
|
|
248
|
+
var DialogDescription = React.forwardRef(
|
|
249
|
+
(props, forwardedRef) => {
|
|
250
|
+
const { __scopeDialog, ...descriptionProps } = props;
|
|
251
|
+
const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
252
|
+
return /* @__PURE__ */ jsx(Primitive.p, { id: context.descriptionId, ...descriptionProps, ref: forwardedRef });
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
256
|
+
var CLOSE_NAME = "DialogClose";
|
|
257
|
+
var DialogClose = React.forwardRef(
|
|
258
|
+
(props, forwardedRef) => {
|
|
259
|
+
const { __scopeDialog, ...closeProps } = props;
|
|
260
|
+
const context = useDialogContext(CLOSE_NAME, __scopeDialog);
|
|
261
|
+
return /* @__PURE__ */ jsx(
|
|
262
|
+
Primitive.button,
|
|
263
|
+
{
|
|
264
|
+
type: "button",
|
|
265
|
+
...closeProps,
|
|
299
266
|
ref: forwardedRef,
|
|
300
|
-
onClick:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return open ? 'open' : 'closed';
|
|
267
|
+
onClick: composeEventHandlers(props.onClick, () => context.onOpenChange(false))
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
DialogClose.displayName = CLOSE_NAME;
|
|
273
|
+
function getState(open) {
|
|
274
|
+
return open ? "open" : "closed";
|
|
309
275
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
276
|
+
var TITLE_WARNING_NAME = "DialogTitleWarning";
|
|
277
|
+
var [WarningProvider, useWarningContext] = createContext(TITLE_WARNING_NAME, {
|
|
278
|
+
contentName: CONTENT_NAME,
|
|
279
|
+
titleName: TITLE_NAME,
|
|
280
|
+
docsSlug: "dialog"
|
|
315
281
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
282
|
+
var TitleWarning = ({ titleId }) => {
|
|
283
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
|
|
284
|
+
const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
319
285
|
|
|
320
286
|
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
321
287
|
|
|
322
288
|
For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
titleId
|
|
331
|
-
]);
|
|
332
|
-
return null;
|
|
289
|
+
React.useEffect(() => {
|
|
290
|
+
if (titleId) {
|
|
291
|
+
const hasTitle = document.getElementById(titleId);
|
|
292
|
+
if (!hasTitle) throw new Error(MESSAGE);
|
|
293
|
+
}
|
|
294
|
+
}, [MESSAGE, titleId]);
|
|
295
|
+
return null;
|
|
333
296
|
};
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
297
|
+
var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
|
|
298
|
+
var DescriptionWarning = ({ contentRef, descriptionId }) => {
|
|
299
|
+
const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
|
|
300
|
+
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
|
|
301
|
+
React.useEffect(() => {
|
|
302
|
+
const describedById = contentRef.current?.getAttribute("aria-describedby");
|
|
303
|
+
if (descriptionId && describedById) {
|
|
304
|
+
const hasDescription = document.getElementById(descriptionId);
|
|
305
|
+
if (!hasDescription) console.warn(MESSAGE);
|
|
306
|
+
}
|
|
307
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
308
|
+
return null;
|
|
309
|
+
};
|
|
310
|
+
var Root = Dialog;
|
|
311
|
+
var Trigger = DialogTrigger;
|
|
312
|
+
var Portal = DialogPortal;
|
|
313
|
+
var Overlay = DialogOverlay;
|
|
314
|
+
var Content = DialogContent;
|
|
315
|
+
var Title = DialogTitle;
|
|
316
|
+
var Description = DialogDescription;
|
|
317
|
+
var Close = DialogClose;
|
|
318
|
+
export {
|
|
319
|
+
Close,
|
|
320
|
+
Content,
|
|
321
|
+
Description,
|
|
322
|
+
Dialog,
|
|
323
|
+
DialogClose,
|
|
324
|
+
DialogContent,
|
|
325
|
+
DialogDescription,
|
|
326
|
+
DialogOverlay,
|
|
327
|
+
DialogPortal,
|
|
328
|
+
DialogTitle,
|
|
329
|
+
DialogTrigger,
|
|
330
|
+
Overlay,
|
|
331
|
+
Portal,
|
|
332
|
+
Root,
|
|
333
|
+
Title,
|
|
334
|
+
Trigger,
|
|
335
|
+
WarningProvider,
|
|
336
|
+
createDialogScope
|
|
351
337
|
};
|
|
352
|
-
const $5d3850c4d0b4e6c7$export$be92b6f5f03c0fe9 = $5d3850c4d0b4e6c7$export$3ddf2d174ce01153;
|
|
353
|
-
const $5d3850c4d0b4e6c7$export$41fb9f06171c75f4 = $5d3850c4d0b4e6c7$export$2e1e1122cf0cba88;
|
|
354
|
-
const $5d3850c4d0b4e6c7$export$602eac185826482c = $5d3850c4d0b4e6c7$export$dad7c95542bacce0;
|
|
355
|
-
const $5d3850c4d0b4e6c7$export$c6fdb837b070b4ff = $5d3850c4d0b4e6c7$export$bd1d06c79be19e17;
|
|
356
|
-
const $5d3850c4d0b4e6c7$export$7c6e2c02157bb7d2 = $5d3850c4d0b4e6c7$export$b6d9565de1e068cf;
|
|
357
|
-
const $5d3850c4d0b4e6c7$export$f99233281efd08a0 = $5d3850c4d0b4e6c7$export$16f7638e4a34b909;
|
|
358
|
-
const $5d3850c4d0b4e6c7$export$393edc798c47379d = $5d3850c4d0b4e6c7$export$94e94c2ec2c954d5;
|
|
359
|
-
const $5d3850c4d0b4e6c7$export$f39c2d165cd861fe = $5d3850c4d0b4e6c7$export$fba2fb7cd781b7ac;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
export {$5d3850c4d0b4e6c7$export$cc702773b8ea3e41 as createDialogScope, $5d3850c4d0b4e6c7$export$3ddf2d174ce01153 as Dialog, $5d3850c4d0b4e6c7$export$2e1e1122cf0cba88 as DialogTrigger, $5d3850c4d0b4e6c7$export$dad7c95542bacce0 as DialogPortal, $5d3850c4d0b4e6c7$export$bd1d06c79be19e17 as DialogOverlay, $5d3850c4d0b4e6c7$export$b6d9565de1e068cf as DialogContent, $5d3850c4d0b4e6c7$export$16f7638e4a34b909 as DialogTitle, $5d3850c4d0b4e6c7$export$94e94c2ec2c954d5 as DialogDescription, $5d3850c4d0b4e6c7$export$fba2fb7cd781b7ac as DialogClose, $5d3850c4d0b4e6c7$export$be92b6f5f03c0fe9 as Root, $5d3850c4d0b4e6c7$export$41fb9f06171c75f4 as Trigger, $5d3850c4d0b4e6c7$export$602eac185826482c as Portal, $5d3850c4d0b4e6c7$export$c6fdb837b070b4ff as Overlay, $5d3850c4d0b4e6c7$export$7c6e2c02157bb7d2 as Content, $5d3850c4d0b4e6c7$export$f99233281efd08a0 as Title, $5d3850c4d0b4e6c7$export$393edc798c47379d as Description, $5d3850c4d0b4e6c7$export$f39c2d165cd861fe as Close, $5d3850c4d0b4e6c7$export$69b62a49393917d6 as WarningProvider};
|
|
365
338
|
//# sourceMappingURL=index.mjs.map
|