@radix-ui/react-dialog 1.0.6-rc.5 → 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.js CHANGED
@@ -1,389 +1,350 @@
1
- var $aJCrN$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
2
- var $aJCrN$react = require("react");
3
- var $aJCrN$radixuiprimitive = require("@radix-ui/primitive");
4
- var $aJCrN$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
5
- var $aJCrN$radixuireactcontext = require("@radix-ui/react-context");
6
- var $aJCrN$radixuireactid = require("@radix-ui/react-id");
7
- var $aJCrN$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
8
- var $aJCrN$radixuireactdismissablelayer = require("@radix-ui/react-dismissable-layer");
9
- var $aJCrN$radixuireactfocusscope = require("@radix-ui/react-focus-scope");
10
- var $aJCrN$radixuireactportal = require("@radix-ui/react-portal");
11
- var $aJCrN$radixuireactpresence = require("@radix-ui/react-presence");
12
- var $aJCrN$radixuireactprimitive = require("@radix-ui/react-primitive");
13
- var $aJCrN$radixuireactfocusguards = require("@radix-ui/react-focus-guards");
14
- var $aJCrN$reactremovescroll = require("react-remove-scroll");
15
- var $aJCrN$ariahidden = require("aria-hidden");
16
- var $aJCrN$radixuireactslot = require("@radix-ui/react-slot");
1
+ "use strict";
2
+ (() => {
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
17
31
 
18
- function $parcel$export(e, n, v, s) {
19
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
20
- }
21
- function $parcel$interopDefault(a) {
22
- return a && a.__esModule ? a.default : a;
23
- }
24
-
25
- $parcel$export(module.exports, "createDialogScope", () => $f4833395aa1bca1a$export$cc702773b8ea3e41);
26
- $parcel$export(module.exports, "Dialog", () => $f4833395aa1bca1a$export$3ddf2d174ce01153);
27
- $parcel$export(module.exports, "DialogTrigger", () => $f4833395aa1bca1a$export$2e1e1122cf0cba88);
28
- $parcel$export(module.exports, "DialogPortal", () => $f4833395aa1bca1a$export$dad7c95542bacce0);
29
- $parcel$export(module.exports, "DialogOverlay", () => $f4833395aa1bca1a$export$bd1d06c79be19e17);
30
- $parcel$export(module.exports, "DialogContent", () => $f4833395aa1bca1a$export$b6d9565de1e068cf);
31
- $parcel$export(module.exports, "DialogTitle", () => $f4833395aa1bca1a$export$16f7638e4a34b909);
32
- $parcel$export(module.exports, "DialogDescription", () => $f4833395aa1bca1a$export$94e94c2ec2c954d5);
33
- $parcel$export(module.exports, "DialogClose", () => $f4833395aa1bca1a$export$fba2fb7cd781b7ac);
34
- $parcel$export(module.exports, "Root", () => $f4833395aa1bca1a$export$be92b6f5f03c0fe9);
35
- $parcel$export(module.exports, "Trigger", () => $f4833395aa1bca1a$export$41fb9f06171c75f4);
36
- $parcel$export(module.exports, "Portal", () => $f4833395aa1bca1a$export$602eac185826482c);
37
- $parcel$export(module.exports, "Overlay", () => $f4833395aa1bca1a$export$c6fdb837b070b4ff);
38
- $parcel$export(module.exports, "Content", () => $f4833395aa1bca1a$export$7c6e2c02157bb7d2);
39
- $parcel$export(module.exports, "Title", () => $f4833395aa1bca1a$export$f99233281efd08a0);
40
- $parcel$export(module.exports, "Description", () => $f4833395aa1bca1a$export$393edc798c47379d);
41
- $parcel$export(module.exports, "Close", () => $f4833395aa1bca1a$export$f39c2d165cd861fe);
42
- $parcel$export(module.exports, "WarningProvider", () => $f4833395aa1bca1a$export$69b62a49393917d6);
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
- /* -------------------------------------------------------------------------------------------------
60
- * Dialog
61
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$DIALOG_NAME = 'Dialog';
62
- const [$f4833395aa1bca1a$var$createDialogContext, $f4833395aa1bca1a$export$cc702773b8ea3e41] = $aJCrN$radixuireactcontext.createContextScope($f4833395aa1bca1a$var$DIALOG_NAME);
63
- const [$f4833395aa1bca1a$var$DialogProvider, $f4833395aa1bca1a$var$useDialogContext] = $f4833395aa1bca1a$var$createDialogContext($f4833395aa1bca1a$var$DIALOG_NAME);
64
- const $f4833395aa1bca1a$export$3ddf2d174ce01153 = (props)=>{
65
- const { __scopeDialog: __scopeDialog , children: children , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , modal: modal = true } = props;
66
- const triggerRef = $aJCrN$react.useRef(null);
67
- const contentRef = $aJCrN$react.useRef(null);
68
- const [open = false, setOpen] = $aJCrN$radixuireactusecontrollablestate.useControllableState({
69
- prop: openProp,
70
- defaultProp: defaultOpen,
71
- onChange: onOpenChange
32
+ // packages/react/dialog/src/Dialog.tsx
33
+ var React = __toESM(__require("react"));
34
+ var import_primitive = __require("@radix-ui/primitive");
35
+ var import_react_compose_refs = __require("@radix-ui/react-compose-refs");
36
+ var import_react_context = __require("@radix-ui/react-context");
37
+ var import_react_id = __require("@radix-ui/react-id");
38
+ var import_react_use_controllable_state = __require("@radix-ui/react-use-controllable-state");
39
+ var import_react_dismissable_layer = __require("@radix-ui/react-dismissable-layer");
40
+ var import_react_focus_scope = __require("@radix-ui/react-focus-scope");
41
+ var import_react_portal = __require("@radix-ui/react-portal");
42
+ var import_react_presence = __require("@radix-ui/react-presence");
43
+ var import_react_primitive = __require("@radix-ui/react-primitive");
44
+ var import_react_focus_guards = __require("@radix-ui/react-focus-guards");
45
+ var import_react_remove_scroll = __require("react-remove-scroll");
46
+ var import_aria_hidden = __require("aria-hidden");
47
+ var import_react_slot = __require("@radix-ui/react-slot");
48
+ var import_jsx_runtime = __require("react/jsx-runtime");
49
+ var DIALOG_NAME = "Dialog";
50
+ var [createDialogContext, createDialogScope] = (0, import_react_context.createContextScope)(DIALOG_NAME);
51
+ var [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
52
+ var Dialog = (props) => {
53
+ const {
54
+ __scopeDialog,
55
+ children,
56
+ open: openProp,
57
+ defaultOpen,
58
+ onOpenChange,
59
+ modal = true
60
+ } = props;
61
+ const triggerRef = React.useRef(null);
62
+ const contentRef = React.useRef(null);
63
+ const [open = false, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
64
+ prop: openProp,
65
+ defaultProp: defaultOpen,
66
+ onChange: onOpenChange
72
67
  });
73
- return /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogProvider, {
68
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
69
+ DialogProvider,
70
+ {
74
71
  scope: __scopeDialog,
75
- triggerRef: triggerRef,
76
- contentRef: contentRef,
77
- contentId: $aJCrN$radixuireactid.useId(),
78
- titleId: $aJCrN$radixuireactid.useId(),
79
- descriptionId: $aJCrN$radixuireactid.useId(),
80
- open: open,
72
+ triggerRef,
73
+ contentRef,
74
+ contentId: (0, import_react_id.useId)(),
75
+ titleId: (0, import_react_id.useId)(),
76
+ descriptionId: (0, import_react_id.useId)(),
77
+ open,
81
78
  onOpenChange: setOpen,
82
- onOpenToggle: $aJCrN$react.useCallback(()=>setOpen((prevOpen)=>!prevOpen
83
- )
84
- , [
85
- setOpen
86
- ]),
87
- modal: modal
88
- }, children);
89
- };
90
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$3ddf2d174ce01153, {
91
- displayName: $f4833395aa1bca1a$var$DIALOG_NAME
92
- });
93
- /* -------------------------------------------------------------------------------------------------
94
- * DialogTrigger
95
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$TRIGGER_NAME = 'DialogTrigger';
96
- const $f4833395aa1bca1a$export$2e1e1122cf0cba88 = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
97
- const { __scopeDialog: __scopeDialog , ...triggerProps } = props;
98
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$TRIGGER_NAME, __scopeDialog);
99
- const composedTriggerRef = $aJCrN$radixuireactcomposerefs.useComposedRefs(forwardedRef, context.triggerRef);
100
- return /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
101
- type: "button",
102
- "aria-haspopup": "dialog",
103
- "aria-expanded": context.open,
104
- "aria-controls": context.contentId,
105
- "data-state": $f4833395aa1bca1a$var$getState(context.open)
106
- }, triggerProps, {
107
- ref: composedTriggerRef,
108
- onClick: $aJCrN$radixuiprimitive.composeEventHandlers(props.onClick, context.onOpenToggle)
109
- }));
110
- });
111
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$2e1e1122cf0cba88, {
112
- displayName: $f4833395aa1bca1a$var$TRIGGER_NAME
113
- });
114
- /* -------------------------------------------------------------------------------------------------
115
- * DialogPortal
116
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$PORTAL_NAME = 'DialogPortal';
117
- const [$f4833395aa1bca1a$var$PortalProvider, $f4833395aa1bca1a$var$usePortalContext] = $f4833395aa1bca1a$var$createDialogContext($f4833395aa1bca1a$var$PORTAL_NAME, {
118
- forceMount: undefined
119
- });
120
- const $f4833395aa1bca1a$export$dad7c95542bacce0 = (props)=>{
121
- const { __scopeDialog: __scopeDialog , forceMount: forceMount , children: children , container: container } = props;
122
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$PORTAL_NAME, __scopeDialog);
123
- return /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$PortalProvider, {
124
- scope: __scopeDialog,
125
- forceMount: forceMount
126
- }, $aJCrN$react.Children.map(children, (child)=>/*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactpresence.Presence, {
127
- present: forceMount || context.open
128
- }, /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactportal.Portal, {
129
- asChild: true,
130
- container: container
131
- }, child))
132
- ));
133
- };
134
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$dad7c95542bacce0, {
135
- displayName: $f4833395aa1bca1a$var$PORTAL_NAME
136
- });
137
- /* -------------------------------------------------------------------------------------------------
138
- * DialogOverlay
139
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$OVERLAY_NAME = 'DialogOverlay';
140
- const $f4833395aa1bca1a$export$bd1d06c79be19e17 = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
141
- const portalContext = $f4833395aa1bca1a$var$usePortalContext($f4833395aa1bca1a$var$OVERLAY_NAME, props.__scopeDialog);
142
- const { forceMount: forceMount = portalContext.forceMount , ...overlayProps } = props;
143
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$OVERLAY_NAME, props.__scopeDialog);
144
- return context.modal ? /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactpresence.Presence, {
145
- present: forceMount || context.open
146
- }, /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogOverlayImpl, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({}, overlayProps, {
147
- ref: forwardedRef
148
- }))) : null;
149
- });
150
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$bd1d06c79be19e17, {
151
- displayName: $f4833395aa1bca1a$var$OVERLAY_NAME
152
- });
153
- const $f4833395aa1bca1a$var$DialogOverlayImpl = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
154
- const { __scopeDialog: __scopeDialog , ...overlayProps } = props;
155
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$OVERLAY_NAME, __scopeDialog);
156
- return(/*#__PURE__*/ // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
157
- // ie. when `Overlay` and `Content` are siblings
158
- $aJCrN$react.createElement($aJCrN$reactremovescroll.RemoveScroll, {
159
- as: $aJCrN$radixuireactslot.Slot,
160
- allowPinchZoom: true,
161
- shards: [
162
- context.contentRef
163
- ]
164
- }, /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
165
- "data-state": $f4833395aa1bca1a$var$getState(context.open)
166
- }, overlayProps, {
167
- ref: forwardedRef // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.
168
- ,
169
- style: {
170
- pointerEvents: 'auto',
171
- ...overlayProps.style
79
+ onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
80
+ modal,
81
+ children
82
+ }
83
+ );
84
+ };
85
+ Dialog.displayName = DIALOG_NAME;
86
+ var TRIGGER_NAME = "DialogTrigger";
87
+ var DialogTrigger = React.forwardRef(
88
+ (props, forwardedRef) => {
89
+ const { __scopeDialog, ...triggerProps } = props;
90
+ const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
91
+ const composedTriggerRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
92
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
93
+ import_react_primitive.Primitive.button,
94
+ {
95
+ type: "button",
96
+ "aria-haspopup": "dialog",
97
+ "aria-expanded": context.open,
98
+ "aria-controls": context.contentId,
99
+ "data-state": getState(context.open),
100
+ ...triggerProps,
101
+ ref: composedTriggerRef,
102
+ onClick: (0, import_primitive.composeEventHandlers)(props.onClick, context.onOpenToggle)
172
103
  }
173
- }))));
174
- });
175
- /* -------------------------------------------------------------------------------------------------
176
- * DialogContent
177
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$CONTENT_NAME = 'DialogContent';
178
- const $f4833395aa1bca1a$export$b6d9565de1e068cf = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
179
- const portalContext = $f4833395aa1bca1a$var$usePortalContext($f4833395aa1bca1a$var$CONTENT_NAME, props.__scopeDialog);
180
- const { forceMount: forceMount = portalContext.forceMount , ...contentProps } = props;
181
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$CONTENT_NAME, props.__scopeDialog);
182
- return /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactpresence.Presence, {
183
- present: forceMount || context.open
184
- }, context.modal ? /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogContentModal, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({}, contentProps, {
185
- ref: forwardedRef
186
- })) : /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogContentNonModal, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({}, contentProps, {
187
- ref: forwardedRef
188
- })));
189
- });
190
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$b6d9565de1e068cf, {
191
- displayName: $f4833395aa1bca1a$var$CONTENT_NAME
192
- });
193
- /* -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$DialogContentModal = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
194
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$CONTENT_NAME, props.__scopeDialog);
195
- const contentRef = $aJCrN$react.useRef(null);
196
- const composedRefs = $aJCrN$radixuireactcomposerefs.useComposedRefs(forwardedRef, context.contentRef, contentRef); // aria-hide everything except the content (better supported equivalent to setting aria-modal)
197
- $aJCrN$react.useEffect(()=>{
104
+ );
105
+ }
106
+ );
107
+ DialogTrigger.displayName = TRIGGER_NAME;
108
+ var PORTAL_NAME = "DialogPortal";
109
+ var [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
110
+ forceMount: void 0
111
+ });
112
+ var DialogPortal = (props) => {
113
+ const { __scopeDialog, forceMount, children, container } = props;
114
+ const context = useDialogContext(PORTAL_NAME, __scopeDialog);
115
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalProvider, { scope: __scopeDialog, forceMount, children: React.Children.map(children, (child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_portal.Portal, { asChild: true, container, children: child }) })) });
116
+ };
117
+ DialogPortal.displayName = PORTAL_NAME;
118
+ var OVERLAY_NAME = "DialogOverlay";
119
+ var DialogOverlay = React.forwardRef(
120
+ (props, forwardedRef) => {
121
+ const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);
122
+ const { forceMount = portalContext.forceMount, ...overlayProps } = props;
123
+ const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);
124
+ return context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogOverlayImpl, { ...overlayProps, ref: forwardedRef }) }) : null;
125
+ }
126
+ );
127
+ DialogOverlay.displayName = OVERLAY_NAME;
128
+ var DialogOverlayImpl = React.forwardRef(
129
+ (props, forwardedRef) => {
130
+ const { __scopeDialog, ...overlayProps } = props;
131
+ const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
132
+ return (
133
+ // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
134
+ // ie. when `Overlay` and `Content` are siblings
135
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_remove_scroll.RemoveScroll, { as: import_react_slot.Slot, allowPinchZoom: true, shards: [context.contentRef], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
136
+ import_react_primitive.Primitive.div,
137
+ {
138
+ "data-state": getState(context.open),
139
+ ...overlayProps,
140
+ ref: forwardedRef,
141
+ style: { pointerEvents: "auto", ...overlayProps.style }
142
+ }
143
+ ) })
144
+ );
145
+ }
146
+ );
147
+ var CONTENT_NAME = "DialogContent";
148
+ var DialogContent = React.forwardRef(
149
+ (props, forwardedRef) => {
150
+ const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);
151
+ const { forceMount = portalContext.forceMount, ...contentProps } = props;
152
+ const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
153
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentNonModal, { ...contentProps, ref: forwardedRef }) });
154
+ }
155
+ );
156
+ DialogContent.displayName = CONTENT_NAME;
157
+ var DialogContentModal = React.forwardRef(
158
+ (props, forwardedRef) => {
159
+ const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
160
+ const contentRef = React.useRef(null);
161
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.contentRef, contentRef);
162
+ React.useEffect(() => {
198
163
  const content = contentRef.current;
199
- if (content) return $aJCrN$ariahidden.hideOthers(content);
200
- }, []);
201
- return /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogContentImpl, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({}, props, {
202
- ref: composedRefs // we make sure focus isn't trapped once `DialogContent` has been closed
203
- ,
204
- trapFocus: context.open,
205
- disableOutsidePointerEvents: true,
206
- onCloseAutoFocus: $aJCrN$radixuiprimitive.composeEventHandlers(props.onCloseAutoFocus, (event)=>{
207
- var _context$triggerRef$c;
164
+ if (content) return (0, import_aria_hidden.hideOthers)(content);
165
+ }, []);
166
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
167
+ DialogContentImpl,
168
+ {
169
+ ...props,
170
+ ref: composedRefs,
171
+ trapFocus: context.open,
172
+ disableOutsidePointerEvents: true,
173
+ onCloseAutoFocus: (0, import_primitive.composeEventHandlers)(props.onCloseAutoFocus, (event) => {
208
174
  event.preventDefault();
209
- (_context$triggerRef$c = context.triggerRef.current) === null || _context$triggerRef$c === void 0 || _context$triggerRef$c.focus();
210
- }),
211
- onPointerDownOutside: $aJCrN$radixuiprimitive.composeEventHandlers(props.onPointerDownOutside, (event)=>{
175
+ context.triggerRef.current?.focus();
176
+ }),
177
+ onPointerDownOutside: (0, import_primitive.composeEventHandlers)(props.onPointerDownOutside, (event) => {
212
178
  const originalEvent = event.detail.originalEvent;
213
179
  const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
214
- const isRightClick = originalEvent.button === 2 || ctrlLeftClick; // If the event is a right-click, we shouldn't close because
215
- // it is effectively as if we right-clicked the `Overlay`.
180
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
216
181
  if (isRightClick) event.preventDefault();
217
- }) // When focus is trapped, a `focusout` event may still happen.
218
- ,
219
- onFocusOutside: $aJCrN$radixuiprimitive.composeEventHandlers(props.onFocusOutside, (event)=>event.preventDefault()
220
- )
221
- }));
222
- });
223
- /* -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$DialogContentNonModal = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
224
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$CONTENT_NAME, props.__scopeDialog);
225
- const hasInteractedOutsideRef = $aJCrN$react.useRef(false);
226
- const hasPointerDownOutsideRef = $aJCrN$react.useRef(false);
227
- return /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogContentImpl, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({}, props, {
228
- ref: forwardedRef,
229
- trapFocus: false,
230
- disableOutsidePointerEvents: false,
231
- onCloseAutoFocus: (event)=>{
232
- var _props$onCloseAutoFoc;
233
- (_props$onCloseAutoFoc = props.onCloseAutoFocus) === null || _props$onCloseAutoFoc === void 0 || _props$onCloseAutoFoc.call(props, event);
182
+ }),
183
+ onFocusOutside: (0, import_primitive.composeEventHandlers)(
184
+ props.onFocusOutside,
185
+ (event) => event.preventDefault()
186
+ )
187
+ }
188
+ );
189
+ }
190
+ );
191
+ var DialogContentNonModal = React.forwardRef(
192
+ (props, forwardedRef) => {
193
+ const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
194
+ const hasInteractedOutsideRef = React.useRef(false);
195
+ const hasPointerDownOutsideRef = React.useRef(false);
196
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
197
+ DialogContentImpl,
198
+ {
199
+ ...props,
200
+ ref: forwardedRef,
201
+ trapFocus: false,
202
+ disableOutsidePointerEvents: false,
203
+ onCloseAutoFocus: (event) => {
204
+ props.onCloseAutoFocus?.(event);
234
205
  if (!event.defaultPrevented) {
235
- var _context$triggerRef$c2;
236
- if (!hasInteractedOutsideRef.current) (_context$triggerRef$c2 = context.triggerRef.current) === null || _context$triggerRef$c2 === void 0 || _context$triggerRef$c2.focus(); // Always prevent auto focus because we either focus manually or want user agent focus
237
- event.preventDefault();
206
+ if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
207
+ event.preventDefault();
238
208
  }
239
209
  hasInteractedOutsideRef.current = false;
240
210
  hasPointerDownOutsideRef.current = false;
241
- },
242
- onInteractOutside: (event)=>{
243
- var _props$onInteractOuts, _context$triggerRef$c3;
244
- (_props$onInteractOuts = props.onInteractOutside) === null || _props$onInteractOuts === void 0 || _props$onInteractOuts.call(props, event);
211
+ },
212
+ onInteractOutside: (event) => {
213
+ props.onInteractOutside?.(event);
245
214
  if (!event.defaultPrevented) {
246
- hasInteractedOutsideRef.current = true;
247
- if (event.detail.originalEvent.type === 'pointerdown') hasPointerDownOutsideRef.current = true;
248
- } // Prevent dismissing when clicking the trigger.
249
- // As the trigger is already setup to close, without doing so would
250
- // cause it to close and immediately open.
215
+ hasInteractedOutsideRef.current = true;
216
+ if (event.detail.originalEvent.type === "pointerdown") {
217
+ hasPointerDownOutsideRef.current = true;
218
+ }
219
+ }
251
220
  const target = event.target;
252
- const targetIsTrigger = (_context$triggerRef$c3 = context.triggerRef.current) === null || _context$triggerRef$c3 === void 0 ? void 0 : _context$triggerRef$c3.contains(target);
253
- if (targetIsTrigger) event.preventDefault(); // On Safari if the trigger is inside a container with tabIndex={0}, when clicked
254
- // we will get the pointer down outside event on the trigger, but then a subsequent
255
- // focus outside event on the container, we ignore any focus outside event when we've
256
- // already had a pointer down outside event.
257
- if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) event.preventDefault();
221
+ const targetIsTrigger = context.triggerRef.current?.contains(target);
222
+ if (targetIsTrigger) event.preventDefault();
223
+ if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
224
+ event.preventDefault();
225
+ }
226
+ }
258
227
  }
259
- }));
260
- });
261
- /* -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$DialogContentImpl = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
262
- const { __scopeDialog: __scopeDialog , trapFocus: trapFocus , onOpenAutoFocus: onOpenAutoFocus , onCloseAutoFocus: onCloseAutoFocus , ...contentProps } = props;
263
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$CONTENT_NAME, __scopeDialog);
264
- const contentRef = $aJCrN$react.useRef(null);
265
- const composedRefs = $aJCrN$radixuireactcomposerefs.useComposedRefs(forwardedRef, contentRef); // Make sure the whole tree has focus guards as our `Dialog` will be
266
- // the last element in the DOM (beacuse of the `Portal`)
267
- $aJCrN$radixuireactfocusguards.useFocusGuards();
268
- return /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$react.Fragment, null, /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactfocusscope.FocusScope, {
269
- asChild: true,
270
- loop: true,
271
- trapped: trapFocus,
272
- onMountAutoFocus: onOpenAutoFocus,
273
- onUnmountAutoFocus: onCloseAutoFocus
274
- }, /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactdismissablelayer.DismissableLayer, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
275
- role: "dialog",
276
- id: context.contentId,
277
- "aria-describedby": context.descriptionId,
278
- "aria-labelledby": context.titleId,
279
- "data-state": $f4833395aa1bca1a$var$getState(context.open)
280
- }, contentProps, {
281
- ref: composedRefs,
282
- onDismiss: ()=>context.onOpenChange(false)
283
- }))), false);
284
- });
285
- /* -------------------------------------------------------------------------------------------------
286
- * DialogTitle
287
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$TITLE_NAME = 'DialogTitle';
288
- const $f4833395aa1bca1a$export$16f7638e4a34b909 = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
289
- const { __scopeDialog: __scopeDialog , ...titleProps } = props;
290
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$TITLE_NAME, __scopeDialog);
291
- return /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactprimitive.Primitive.h2, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
292
- id: context.titleId
293
- }, titleProps, {
294
- ref: forwardedRef
295
- }));
296
- });
297
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$16f7638e4a34b909, {
298
- displayName: $f4833395aa1bca1a$var$TITLE_NAME
299
- });
300
- /* -------------------------------------------------------------------------------------------------
301
- * DialogDescription
302
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$DESCRIPTION_NAME = 'DialogDescription';
303
- const $f4833395aa1bca1a$export$94e94c2ec2c954d5 = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
304
- const { __scopeDialog: __scopeDialog , ...descriptionProps } = props;
305
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$DESCRIPTION_NAME, __scopeDialog);
306
- return /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactprimitive.Primitive.p, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
307
- id: context.descriptionId
308
- }, descriptionProps, {
309
- ref: forwardedRef
310
- }));
311
- });
312
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$94e94c2ec2c954d5, {
313
- displayName: $f4833395aa1bca1a$var$DESCRIPTION_NAME
314
- });
315
- /* -------------------------------------------------------------------------------------------------
316
- * DialogClose
317
- * -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$CLOSE_NAME = 'DialogClose';
318
- const $f4833395aa1bca1a$export$fba2fb7cd781b7ac = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
319
- const { __scopeDialog: __scopeDialog , ...closeProps } = props;
320
- const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$CLOSE_NAME, __scopeDialog);
321
- return /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
322
- type: "button"
323
- }, closeProps, {
324
- ref: forwardedRef,
325
- onClick: $aJCrN$radixuiprimitive.composeEventHandlers(props.onClick, ()=>context.onOpenChange(false)
326
- )
327
- }));
328
- });
329
- /*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$fba2fb7cd781b7ac, {
330
- displayName: $f4833395aa1bca1a$var$CLOSE_NAME
331
- });
332
- /* -----------------------------------------------------------------------------------------------*/ function $f4833395aa1bca1a$var$getState(open) {
333
- return open ? 'open' : 'closed';
334
- }
335
- const $f4833395aa1bca1a$var$TITLE_WARNING_NAME = 'DialogTitleWarning';
336
- const [$f4833395aa1bca1a$export$69b62a49393917d6, $f4833395aa1bca1a$var$useWarningContext] = $aJCrN$radixuireactcontext.createContext($f4833395aa1bca1a$var$TITLE_WARNING_NAME, {
337
- contentName: $f4833395aa1bca1a$var$CONTENT_NAME,
338
- titleName: $f4833395aa1bca1a$var$TITLE_NAME,
339
- docsSlug: 'dialog'
340
- });
341
- const $f4833395aa1bca1a$var$TitleWarning = ({ titleId: titleId })=>{
342
- const titleWarningContext = $f4833395aa1bca1a$var$useWarningContext($f4833395aa1bca1a$var$TITLE_WARNING_NAME);
228
+ );
229
+ }
230
+ );
231
+ var DialogContentImpl = React.forwardRef(
232
+ (props, forwardedRef) => {
233
+ const { __scopeDialog, trapFocus, onOpenAutoFocus, onCloseAutoFocus, ...contentProps } = props;
234
+ const context = useDialogContext(CONTENT_NAME, __scopeDialog);
235
+ const contentRef = React.useRef(null);
236
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, contentRef);
237
+ (0, import_react_focus_guards.useFocusGuards)();
238
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
239
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
240
+ import_react_focus_scope.FocusScope,
241
+ {
242
+ asChild: true,
243
+ loop: true,
244
+ trapped: trapFocus,
245
+ onMountAutoFocus: onOpenAutoFocus,
246
+ onUnmountAutoFocus: onCloseAutoFocus,
247
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
248
+ import_react_dismissable_layer.DismissableLayer,
249
+ {
250
+ role: "dialog",
251
+ id: context.contentId,
252
+ "aria-describedby": context.descriptionId,
253
+ "aria-labelledby": context.titleId,
254
+ "data-state": getState(context.open),
255
+ ...contentProps,
256
+ ref: composedRefs,
257
+ onDismiss: () => context.onOpenChange(false)
258
+ }
259
+ )
260
+ }
261
+ ),
262
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleWarning, { titleId: context.titleId }),
264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionWarning, { contentRef, descriptionId: context.descriptionId })
265
+ ] })
266
+ ] });
267
+ }
268
+ );
269
+ var TITLE_NAME = "DialogTitle";
270
+ var DialogTitle = React.forwardRef(
271
+ (props, forwardedRef) => {
272
+ const { __scopeDialog, ...titleProps } = props;
273
+ const context = useDialogContext(TITLE_NAME, __scopeDialog);
274
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.h2, { id: context.titleId, ...titleProps, ref: forwardedRef });
275
+ }
276
+ );
277
+ DialogTitle.displayName = TITLE_NAME;
278
+ var DESCRIPTION_NAME = "DialogDescription";
279
+ var DialogDescription = React.forwardRef(
280
+ (props, forwardedRef) => {
281
+ const { __scopeDialog, ...descriptionProps } = props;
282
+ const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
283
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.p, { id: context.descriptionId, ...descriptionProps, ref: forwardedRef });
284
+ }
285
+ );
286
+ DialogDescription.displayName = DESCRIPTION_NAME;
287
+ var CLOSE_NAME = "DialogClose";
288
+ var DialogClose = React.forwardRef(
289
+ (props, forwardedRef) => {
290
+ const { __scopeDialog, ...closeProps } = props;
291
+ const context = useDialogContext(CLOSE_NAME, __scopeDialog);
292
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
293
+ import_react_primitive.Primitive.button,
294
+ {
295
+ type: "button",
296
+ ...closeProps,
297
+ ref: forwardedRef,
298
+ onClick: (0, import_primitive.composeEventHandlers)(props.onClick, () => context.onOpenChange(false))
299
+ }
300
+ );
301
+ }
302
+ );
303
+ DialogClose.displayName = CLOSE_NAME;
304
+ function getState(open) {
305
+ return open ? "open" : "closed";
306
+ }
307
+ var TITLE_WARNING_NAME = "DialogTitleWarning";
308
+ var [WarningProvider, useWarningContext] = (0, import_react_context.createContext)(TITLE_WARNING_NAME, {
309
+ contentName: CONTENT_NAME,
310
+ titleName: TITLE_NAME,
311
+ docsSlug: "dialog"
312
+ });
313
+ var TitleWarning = ({ titleId }) => {
314
+ const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
343
315
  const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
344
316
 
345
317
  If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
346
318
 
347
319
  For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
348
- $aJCrN$react.useEffect(()=>{
349
- if (titleId) {
350
- const hasTitle = document.getElementById(titleId);
351
- if (!hasTitle) throw new Error(MESSAGE);
352
- }
353
- }, [
354
- MESSAGE,
355
- titleId
356
- ]);
320
+ React.useEffect(() => {
321
+ if (titleId) {
322
+ const hasTitle = document.getElementById(titleId);
323
+ if (!hasTitle) throw new Error(MESSAGE);
324
+ }
325
+ }, [MESSAGE, titleId]);
357
326
  return null;
358
- };
359
- const $f4833395aa1bca1a$var$DESCRIPTION_WARNING_NAME = 'DialogDescriptionWarning';
360
- const $f4833395aa1bca1a$var$DescriptionWarning = ({ contentRef: contentRef , descriptionId: descriptionId })=>{
361
- const descriptionWarningContext = $f4833395aa1bca1a$var$useWarningContext($f4833395aa1bca1a$var$DESCRIPTION_WARNING_NAME);
327
+ };
328
+ var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
329
+ var DescriptionWarning = ({ contentRef, descriptionId }) => {
330
+ const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
362
331
  const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
363
- $aJCrN$react.useEffect(()=>{
364
- var _contentRef$current;
365
- const describedById = (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.getAttribute('aria-describedby'); // if we have an id and the user hasn't set aria-describedby={undefined}
366
- if (descriptionId && describedById) {
367
- const hasDescription = document.getElementById(descriptionId);
368
- if (!hasDescription) console.warn(MESSAGE);
369
- }
370
- }, [
371
- MESSAGE,
372
- contentRef,
373
- descriptionId
374
- ]);
332
+ React.useEffect(() => {
333
+ const describedById = contentRef.current?.getAttribute("aria-describedby");
334
+ if (descriptionId && describedById) {
335
+ const hasDescription = document.getElementById(descriptionId);
336
+ if (!hasDescription) console.warn(MESSAGE);
337
+ }
338
+ }, [MESSAGE, contentRef, descriptionId]);
375
339
  return null;
376
- };
377
- const $f4833395aa1bca1a$export$be92b6f5f03c0fe9 = $f4833395aa1bca1a$export$3ddf2d174ce01153;
378
- const $f4833395aa1bca1a$export$41fb9f06171c75f4 = $f4833395aa1bca1a$export$2e1e1122cf0cba88;
379
- const $f4833395aa1bca1a$export$602eac185826482c = $f4833395aa1bca1a$export$dad7c95542bacce0;
380
- const $f4833395aa1bca1a$export$c6fdb837b070b4ff = $f4833395aa1bca1a$export$bd1d06c79be19e17;
381
- const $f4833395aa1bca1a$export$7c6e2c02157bb7d2 = $f4833395aa1bca1a$export$b6d9565de1e068cf;
382
- const $f4833395aa1bca1a$export$f99233281efd08a0 = $f4833395aa1bca1a$export$16f7638e4a34b909;
383
- const $f4833395aa1bca1a$export$393edc798c47379d = $f4833395aa1bca1a$export$94e94c2ec2c954d5;
384
- const $f4833395aa1bca1a$export$f39c2d165cd861fe = $f4833395aa1bca1a$export$fba2fb7cd781b7ac;
385
-
386
-
387
-
388
-
340
+ };
341
+ var Root = Dialog;
342
+ var Trigger = DialogTrigger;
343
+ var Portal = DialogPortal;
344
+ var Overlay = DialogOverlay;
345
+ var Content = DialogContent;
346
+ var Title = DialogTitle;
347
+ var Description = DialogDescription;
348
+ var Close = DialogClose;
349
+ })();
389
350
  //# sourceMappingURL=index.js.map