@hanzogui/dialog 3.0.2 → 7.3.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/LICENSE +42 -21
- package/dist/cjs/Dialog.cjs +623 -538
- package/dist/cjs/Dialog.native.js +659 -596
- package/dist/cjs/Dialog.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Dialog.mjs +580 -497
- package/dist/esm/Dialog.mjs.map +1 -1
- package/dist/esm/Dialog.native.js +616 -555
- package/dist/esm/Dialog.native.js.map +1 -1
- package/dist/jsx/Dialog.mjs +580 -497
- package/dist/jsx/Dialog.mjs.map +1 -1
- package/dist/jsx/Dialog.native.js +659 -596
- package/dist/jsx/Dialog.native.js.map +1 -1
- package/dist/jsx/index.native.js +7 -5
- package/package.json +27 -25
- package/src/Dialog.tsx +48 -5
- package/types/Dialog.d.ts +102 -102
- package/types/Dialog.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
|
@@ -17,170 +17,185 @@ import { useControllableState } from "@hanzogui/use-controllable-state";
|
|
|
17
17
|
import { StackZIndexContext } from "@hanzogui/z-index-stack";
|
|
18
18
|
import * as React from "react";
|
|
19
19
|
function _instanceof(left, right) {
|
|
20
|
-
|
|
20
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
21
|
+
return !!right[Symbol.hasInstance](left);
|
|
22
|
+
} else {
|
|
23
|
+
return left instanceof right;
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
var DialogContext = createStyledContext(
|
|
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
|
-
})
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
27
|
+
// since we always provide this we can avoid setting here
|
|
28
|
+
{}, "Dialog__");
|
|
29
|
+
var {
|
|
30
|
+
useStyledContext: useDialogContext,
|
|
31
|
+
Provider: DialogProvider
|
|
32
|
+
} = DialogContext;
|
|
33
|
+
var DialogAdaptHiddenContext = /* @__PURE__ */React.createContext(true);
|
|
34
|
+
var DialogTriggerFrame = styled(View, {
|
|
35
|
+
name: "DialogTrigger"
|
|
36
|
+
});
|
|
37
|
+
var DialogTrigger = DialogTriggerFrame.styleable(function DialogTrigger2(props, forwardedRef) {
|
|
38
|
+
var {
|
|
39
|
+
scope,
|
|
40
|
+
...triggerProps
|
|
41
|
+
} = props;
|
|
42
|
+
var isInsideButton = React.useContext(ButtonNestingContext);
|
|
43
|
+
var context = useDialogContext(scope);
|
|
44
|
+
var composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
45
|
+
return /* @__PURE__ */_jsx(ButtonNestingContext.Provider, {
|
|
46
|
+
value: true,
|
|
47
|
+
children: /* @__PURE__ */_jsx(DialogTriggerFrame, {
|
|
48
|
+
render: isInsideButton ? "span" : "button",
|
|
49
|
+
"aria-haspopup": "dialog",
|
|
50
|
+
"aria-expanded": context.open,
|
|
51
|
+
"aria-controls": context.contentId,
|
|
52
|
+
"data-state": getState(context.open),
|
|
53
|
+
...triggerProps,
|
|
54
|
+
ref: composedTriggerRef,
|
|
55
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
var DialogPortalFrame = styled(YStack, {
|
|
60
|
+
pointerEvents: "none",
|
|
61
|
+
render: "dialog",
|
|
62
|
+
variants: {
|
|
63
|
+
unstyled: {
|
|
64
|
+
false: {
|
|
65
|
+
alignItems: "center",
|
|
66
|
+
justifyContent: "center",
|
|
67
|
+
fullscreen: true,
|
|
68
|
+
"$platform-web": {
|
|
69
|
+
// undo dialog styles
|
|
70
|
+
borderWidth: 0,
|
|
71
|
+
backgroundColor: "transparent",
|
|
72
|
+
color: "inherit",
|
|
73
|
+
maxInlineSize: "none",
|
|
74
|
+
margin: 0,
|
|
75
|
+
width: "auto",
|
|
76
|
+
height: "auto",
|
|
77
|
+
// ensure always in frame and right height
|
|
78
|
+
maxHeight: "100vh",
|
|
79
|
+
position: "fixed",
|
|
80
|
+
// ensure dialog inherits stacking context from portal wrapper
|
|
81
|
+
zIndex: 1
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
},
|
|
81
|
-
defaultVariants: {
|
|
82
|
-
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
83
84
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
},
|
|
86
|
+
defaultVariants: {
|
|
87
|
+
unstyled: process.env.GUI_HEADLESS === "1"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
var needsRepropagation = needsPortalRepropagation();
|
|
91
|
+
var DialogPortalItem = function (param) {
|
|
92
|
+
var {
|
|
93
|
+
context,
|
|
94
|
+
children
|
|
95
|
+
} = param;
|
|
96
|
+
var themeName = useThemeName();
|
|
97
|
+
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
98
|
+
var adaptContext = useAdaptContext(context.adaptScope);
|
|
99
|
+
var content = /* @__PURE__ */_jsx(Theme, {
|
|
100
|
+
name: themeName,
|
|
101
|
+
children
|
|
102
|
+
});
|
|
103
|
+
if (needsRepropagation) {
|
|
104
|
+
content = /* @__PURE__ */_jsx(ProvideAdaptContext, {
|
|
99
105
|
...adaptContext,
|
|
100
106
|
children: /* @__PURE__ */_jsx(DialogProvider, {
|
|
101
107
|
...context,
|
|
102
108
|
children: content
|
|
103
109
|
})
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return isAdapted ? /* @__PURE__ */_jsx(AdaptPortalContents, {
|
|
113
|
+
scope: context.adaptScope,
|
|
114
|
+
children: content
|
|
115
|
+
}) : context.modal ? /* @__PURE__ */_jsx(PortalItem, {
|
|
116
|
+
hostName: context.modal ? "root" : context.adaptScope,
|
|
117
|
+
children: content
|
|
118
|
+
}) : content;
|
|
119
|
+
};
|
|
120
|
+
var DialogPortal = /* @__PURE__ */React.forwardRef(function (props, forwardRef) {
|
|
121
|
+
var {
|
|
122
|
+
scope,
|
|
123
|
+
forceMount,
|
|
124
|
+
children,
|
|
125
|
+
...frameProps
|
|
126
|
+
} = props;
|
|
127
|
+
var dialogRef = React.useRef(null);
|
|
128
|
+
var ref = composeRefs(dialogRef, forwardRef);
|
|
129
|
+
var context = useDialogContext(scope);
|
|
130
|
+
var keepMounted = forceMount || context.keepChildrenMounted;
|
|
131
|
+
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
132
|
+
var [isFullyHidden, setIsFullyHidden] = React.useState(!context.open);
|
|
133
|
+
if (context.open && isFullyHidden) {
|
|
134
|
+
setIsFullyHidden(false);
|
|
135
|
+
}
|
|
136
|
+
var isVisible = context.open ? true : !isFullyHidden;
|
|
137
|
+
if (isWeb) {
|
|
138
|
+
useIsomorphicLayoutEffect(function () {
|
|
128
139
|
var node = dialogRef.current;
|
|
129
|
-
if (_instanceof(node, HTMLDialogElement))
|
|
140
|
+
if (!_instanceof(node, HTMLDialogElement)) return;
|
|
141
|
+
if (isVisible) {
|
|
130
142
|
var _node_show;
|
|
131
|
-
(_node_show = node.show) === null || _node_show === void 0
|
|
143
|
+
(_node_show = node.show) === null || _node_show === void 0 ? void 0 : _node_show.call(node);
|
|
132
144
|
} else {
|
|
133
145
|
var _node_close;
|
|
134
|
-
(_node_close = node.close) === null || _node_close === void 0
|
|
146
|
+
(_node_close = node.close) === null || _node_close === void 0 ? void 0 : _node_close.call(node);
|
|
135
147
|
}
|
|
136
148
|
}, [isVisible]);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
149
|
+
}
|
|
150
|
+
var onAnimationCompleteRef = React.useRef(context.onAnimationComplete);
|
|
151
|
+
onAnimationCompleteRef.current = context.onAnimationComplete;
|
|
152
|
+
var handleExitComplete = React.useCallback(function () {
|
|
153
|
+
var _onAnimationCompleteRef_current;
|
|
154
|
+
setIsFullyHidden(true);
|
|
155
|
+
(_onAnimationCompleteRef_current = onAnimationCompleteRef.current) === null || _onAnimationCompleteRef_current === void 0 ? void 0 : _onAnimationCompleteRef_current.call(onAnimationCompleteRef, {
|
|
156
|
+
open: false
|
|
157
|
+
});
|
|
158
|
+
}, []);
|
|
159
|
+
React.useEffect(function () {
|
|
160
|
+
if (context.open && !isAdapted && onAnimationCompleteRef.current) {
|
|
161
|
+
var tm = setTimeout(function () {
|
|
162
|
+
var _onAnimationCompleteRef_current;
|
|
163
|
+
(_onAnimationCompleteRef_current = onAnimationCompleteRef.current) === null || _onAnimationCompleteRef_current === void 0 ? void 0 : _onAnimationCompleteRef_current.call(onAnimationCompleteRef, {
|
|
164
|
+
open: true
|
|
165
|
+
});
|
|
166
|
+
}, 350);
|
|
167
|
+
return function () {
|
|
168
|
+
return clearTimeout(tm);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}, [context.open, isAdapted]);
|
|
172
|
+
var zIndex = getExpandedShorthand("zIndex", props);
|
|
173
|
+
var contents = /* @__PURE__ */_jsx(StackZIndexContext, {
|
|
174
|
+
zIndex: resolveViewZIndex(zIndex),
|
|
175
|
+
children: /* @__PURE__ */_jsx(Animate, {
|
|
176
|
+
type: "presence",
|
|
177
|
+
present: Boolean(context.open),
|
|
178
|
+
keepChildrenMounted: Boolean(keepMounted),
|
|
179
|
+
onExitComplete: handleExitComplete,
|
|
180
|
+
passThrough: isAdapted,
|
|
181
|
+
children
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
var framedContents = isFullyHidden && !keepMounted && !isAdapted ? null : /* @__PURE__ */_jsx(LayoutMeasurementController, {
|
|
185
|
+
disable: !context.open,
|
|
186
|
+
children: /* @__PURE__ */_jsx(DialogPortalFrame, {
|
|
187
|
+
ref,
|
|
188
|
+
...(isWeb && context.open && {
|
|
189
|
+
"aria-modal": true
|
|
169
190
|
}),
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
...frameProps,
|
|
179
|
-
className: "_no_backdrop " + (frameProps.className || ""),
|
|
180
|
-
children: contents
|
|
181
|
-
})
|
|
182
|
-
});
|
|
183
|
-
return isWeb ? /* @__PURE__ */_jsx(Portal, {
|
|
191
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
192
|
+
...frameProps,
|
|
193
|
+
className: `_no_backdrop ` + (frameProps.className || ""),
|
|
194
|
+
children: contents
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
if (isWeb) {
|
|
198
|
+
return /* @__PURE__ */_jsx(Portal, {
|
|
184
199
|
zIndex,
|
|
185
200
|
// set to 100000 which ensures dialogs are above most fixed UI (headers, navs)
|
|
186
201
|
// this makes sure its above typical stacking contexts
|
|
@@ -190,451 +205,497 @@ var DialogContext = createStyledContext(
|
|
|
190
205
|
passThrough: isAdapted,
|
|
191
206
|
children: framedContents
|
|
192
207
|
})
|
|
193
|
-
}) : isAdapted ? framedContents : /* @__PURE__ */_jsx(DialogPortalItem, {
|
|
194
|
-
context,
|
|
195
|
-
children: framedContents
|
|
196
|
-
});
|
|
197
|
-
}),
|
|
198
|
-
PassthroughTheme = function (param) {
|
|
199
|
-
var {
|
|
200
|
-
children,
|
|
201
|
-
passThrough
|
|
202
|
-
} = param,
|
|
203
|
-
themeName = useThemeName();
|
|
204
|
-
return /* @__PURE__ */_jsx(Theme, {
|
|
205
|
-
passThrough,
|
|
206
|
-
name: themeName,
|
|
207
|
-
forceClassName: !0,
|
|
208
|
-
children
|
|
209
208
|
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
}
|
|
210
|
+
return isAdapted ? framedContents : /* @__PURE__ */_jsx(DialogPortalItem, {
|
|
211
|
+
context,
|
|
212
|
+
children: framedContents
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
var PassthroughTheme = function (param) {
|
|
216
|
+
var {
|
|
217
|
+
children,
|
|
218
|
+
passThrough
|
|
219
|
+
} = param;
|
|
220
|
+
var themeName = useThemeName();
|
|
221
|
+
return /* @__PURE__ */_jsx(Theme, {
|
|
222
|
+
passThrough,
|
|
223
|
+
name: themeName,
|
|
224
|
+
forceClassName: true,
|
|
225
|
+
children
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
var OVERLAY_NAME = "DialogOverlay";
|
|
229
|
+
var DialogOverlayFrame = styled(YStack, {
|
|
230
|
+
name: OVERLAY_NAME,
|
|
231
|
+
zIndex: 1,
|
|
232
|
+
variants: {
|
|
233
|
+
open: {
|
|
234
|
+
true: {
|
|
235
|
+
pointerEvents: "auto"
|
|
223
236
|
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
fullscreen: !0,
|
|
227
|
-
position: "absolute",
|
|
228
|
-
backgroundColor: "$background",
|
|
229
|
-
pointerEvents: "auto"
|
|
230
|
-
}
|
|
237
|
+
false: {
|
|
238
|
+
pointerEvents: "none"
|
|
231
239
|
}
|
|
232
240
|
},
|
|
233
|
-
|
|
234
|
-
|
|
241
|
+
unstyled: {
|
|
242
|
+
false: {
|
|
243
|
+
fullscreen: true,
|
|
244
|
+
position: "absolute",
|
|
245
|
+
backgroundColor: "$background",
|
|
246
|
+
pointerEvents: "auto"
|
|
247
|
+
}
|
|
235
248
|
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
borderRadius: "$true",
|
|
279
|
-
elevate: !0,
|
|
280
|
-
// Ensure content receives pointer events (fixes React 19 + display:contents inheritance)
|
|
281
|
-
pointerEvents: "auto"
|
|
282
|
-
}
|
|
249
|
+
},
|
|
250
|
+
defaultVariants: {
|
|
251
|
+
unstyled: process.env.GUI_HEADLESS === "1"
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
var DialogOverlay = DialogOverlayFrame.styleable(function DialogOverlay2(param, forwardedRef) {
|
|
255
|
+
var {
|
|
256
|
+
scope,
|
|
257
|
+
...props
|
|
258
|
+
} = param;
|
|
259
|
+
var context = useDialogContext(scope);
|
|
260
|
+
var {
|
|
261
|
+
forceMount = context.forceMount,
|
|
262
|
+
...overlayProps
|
|
263
|
+
} = props;
|
|
264
|
+
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
265
|
+
if (!forceMount) {
|
|
266
|
+
if (!context.modal || isAdapted) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return /* @__PURE__ */_jsx(DialogOverlayFrame, {
|
|
271
|
+
"data-state": getState(context.open),
|
|
272
|
+
// TODO: this will be apply for v2
|
|
273
|
+
// onPress={() => {
|
|
274
|
+
// // if the overlay is pressed, close the dialog
|
|
275
|
+
// context.onOpenChange(false)
|
|
276
|
+
// }}
|
|
277
|
+
// We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.
|
|
278
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
279
|
+
...overlayProps,
|
|
280
|
+
ref: forwardedRef
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
var CONTENT_NAME = "DialogContent";
|
|
284
|
+
var DialogContentFrame = styled(ThemeableStack, {
|
|
285
|
+
name: CONTENT_NAME,
|
|
286
|
+
zIndex: 2,
|
|
287
|
+
variants: {
|
|
288
|
+
size: {
|
|
289
|
+
"...size": function (val, extras) {
|
|
290
|
+
return {};
|
|
283
291
|
}
|
|
284
292
|
},
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
293
|
+
unstyled: {
|
|
294
|
+
false: {
|
|
295
|
+
position: "relative",
|
|
296
|
+
backgroundColor: "$background",
|
|
297
|
+
borderWidth: 1,
|
|
298
|
+
borderColor: "$borderColor",
|
|
299
|
+
padding: "$true",
|
|
300
|
+
borderRadius: "$true",
|
|
301
|
+
elevate: true,
|
|
302
|
+
// Ensure content receives pointer events (fixes React 19 + display:contents inheritance)
|
|
303
|
+
pointerEvents: "auto"
|
|
304
|
+
}
|
|
288
305
|
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
ref: forwardedRef
|
|
305
|
-
})
|
|
306
|
-
});
|
|
307
|
-
return !isWeb || context.disableRemoveScroll ? contents : /* @__PURE__ */_jsx(RemoveScroll, {
|
|
308
|
-
enabled: context.open,
|
|
309
|
-
children: /* @__PURE__ */_jsx("div", {
|
|
310
|
-
"data-remove-scroll-container": !0,
|
|
311
|
-
className: "_dsp_contents",
|
|
312
|
-
children: contents
|
|
313
|
-
})
|
|
314
|
-
});
|
|
315
|
-
}),
|
|
316
|
-
DialogContentModal = /* @__PURE__ */React.forwardRef(function (param, forwardedRef) {
|
|
317
|
-
var {
|
|
318
|
-
children,
|
|
319
|
-
context,
|
|
320
|
-
...props
|
|
321
|
-
} = param,
|
|
322
|
-
contentRef = React.useRef(null),
|
|
323
|
-
composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
324
|
-
return /* @__PURE__ */_jsx(DialogContentImpl, {
|
|
306
|
+
},
|
|
307
|
+
defaultVariants: {
|
|
308
|
+
size: "$true",
|
|
309
|
+
unstyled: process.env.GUI_HEADLESS === "1"
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
var DialogContent = DialogContentFrame.styleable(function DialogContent2(param, forwardedRef) {
|
|
313
|
+
var {
|
|
314
|
+
scope,
|
|
315
|
+
...props
|
|
316
|
+
} = param;
|
|
317
|
+
var context = useDialogContext(scope);
|
|
318
|
+
var contents = /* @__PURE__ */_jsx(_Fragment, {
|
|
319
|
+
children: context.modal ? /* @__PURE__ */_jsx(DialogContentModal, {
|
|
320
|
+
context,
|
|
325
321
|
...props,
|
|
322
|
+
ref: forwardedRef
|
|
323
|
+
}) : /* @__PURE__ */_jsx(DialogContentNonModal, {
|
|
326
324
|
context,
|
|
327
|
-
ref: composedRefs,
|
|
328
|
-
// we make sure focus isn't trapped once `DialogContent` has been closed
|
|
329
|
-
// (closed !== unmounted when animating out)
|
|
330
|
-
trapFocus: context.open,
|
|
331
|
-
disableOutsidePointerEvents: !0,
|
|
332
|
-
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, function (event) {
|
|
333
|
-
var _context_triggerRef_current;
|
|
334
|
-
event.preventDefault(), (_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 || _context_triggerRef_current.focus();
|
|
335
|
-
}),
|
|
336
|
-
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, function (event) {
|
|
337
|
-
var originalEvent = event.detail.originalEvent,
|
|
338
|
-
ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === !0,
|
|
339
|
-
isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
340
|
-
isRightClick && event.preventDefault();
|
|
341
|
-
}),
|
|
342
|
-
// When focus is trapped, a `focusout` event may still happen.
|
|
343
|
-
// We make sure we don't trigger our `onDismiss` in such case.
|
|
344
|
-
onFocusOutside: composeEventHandlers(props.onFocusOutside, function (event) {
|
|
345
|
-
return event.preventDefault();
|
|
346
|
-
}),
|
|
347
|
-
...(!props.unstyled && {
|
|
348
|
-
outlineStyle: "none"
|
|
349
|
-
}),
|
|
350
|
-
children
|
|
351
|
-
});
|
|
352
|
-
}),
|
|
353
|
-
DialogContentNonModal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
|
|
354
|
-
var hasInteractedOutsideRef = React.useRef(!1);
|
|
355
|
-
return /* @__PURE__ */_jsx(DialogContentImpl, {
|
|
356
325
|
...props,
|
|
357
|
-
ref: forwardedRef
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
326
|
+
ref: forwardedRef
|
|
327
|
+
})
|
|
328
|
+
});
|
|
329
|
+
if (!isWeb || context.disableRemoveScroll) {
|
|
330
|
+
return contents;
|
|
331
|
+
}
|
|
332
|
+
return /* @__PURE__ */_jsx(RemoveScroll, {
|
|
333
|
+
enabled: context.open,
|
|
334
|
+
children: /* @__PURE__ */_jsx("div", {
|
|
335
|
+
"data-remove-scroll-container": true,
|
|
336
|
+
className: "_dsp_contents",
|
|
337
|
+
children: contents
|
|
338
|
+
})
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
var DialogContentModal = /* @__PURE__ */React.forwardRef(function (param, forwardedRef) {
|
|
342
|
+
var {
|
|
343
|
+
children,
|
|
344
|
+
context,
|
|
345
|
+
...props
|
|
346
|
+
} = param;
|
|
347
|
+
var contentRef = React.useRef(null);
|
|
348
|
+
var composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
349
|
+
return /* @__PURE__ */_jsx(DialogContentImpl, {
|
|
350
|
+
...props,
|
|
351
|
+
context,
|
|
352
|
+
ref: composedRefs,
|
|
353
|
+
// we make sure focus isn't trapped once `DialogContent` has been closed
|
|
354
|
+
// (closed !== unmounted when animating out)
|
|
355
|
+
trapFocus: context.open,
|
|
356
|
+
disableOutsidePointerEvents: true,
|
|
357
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, function (event) {
|
|
358
|
+
var _context_triggerRef_current;
|
|
359
|
+
event.preventDefault();
|
|
360
|
+
(_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 ? void 0 : _context_triggerRef_current.focus();
|
|
361
|
+
}),
|
|
362
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, function (event) {
|
|
363
|
+
var originalEvent = event["detail"].originalEvent;
|
|
364
|
+
var ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
365
|
+
var isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
366
|
+
if (isRightClick) event.preventDefault();
|
|
367
|
+
}),
|
|
368
|
+
// When focus is trapped, a `focusout` event may still happen.
|
|
369
|
+
// We make sure we don't trigger our `onDismiss` in such case.
|
|
370
|
+
onFocusOutside: composeEventHandlers(props.onFocusOutside, function (event) {
|
|
371
|
+
return event.preventDefault();
|
|
372
|
+
}),
|
|
373
|
+
...(!props.unstyled && {
|
|
374
|
+
outlineStyle: "none"
|
|
375
|
+
}),
|
|
376
|
+
children
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
var DialogContentNonModal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
|
|
380
|
+
var hasInteractedOutsideRef = React.useRef(false);
|
|
381
|
+
return /* @__PURE__ */_jsx(DialogContentImpl, {
|
|
382
|
+
...props,
|
|
383
|
+
ref: forwardedRef,
|
|
384
|
+
trapFocus: false,
|
|
385
|
+
disableOutsidePointerEvents: false,
|
|
386
|
+
onCloseAutoFocus: function (event) {
|
|
387
|
+
var _props_onCloseAutoFocus;
|
|
388
|
+
(_props_onCloseAutoFocus = props.onCloseAutoFocus) === null || _props_onCloseAutoFocus === void 0 ? void 0 : _props_onCloseAutoFocus.call(props, event);
|
|
389
|
+
if (!event.defaultPrevented) {
|
|
390
|
+
if (!hasInteractedOutsideRef.current) {
|
|
391
|
+
var _props_context_triggerRef_current;
|
|
392
|
+
(_props_context_triggerRef_current = props.context.triggerRef.current) === null || _props_context_triggerRef_current === void 0 ? void 0 : _props_context_triggerRef_current.focus();
|
|
379
393
|
}
|
|
394
|
+
event.preventDefault();
|
|
380
395
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
396
|
+
hasInteractedOutsideRef.current = false;
|
|
397
|
+
},
|
|
398
|
+
onInteractOutside: function (event) {
|
|
399
|
+
var _props_onInteractOutside;
|
|
400
|
+
(_props_onInteractOutside = props.onInteractOutside) === null || _props_onInteractOutside === void 0 ? void 0 : _props_onInteractOutside.call(props, event);
|
|
401
|
+
if (!event.defaultPrevented) hasInteractedOutsideRef.current = true;
|
|
402
|
+
var target = event.target;
|
|
403
|
+
var trigger = props.context.triggerRef.current;
|
|
404
|
+
if (!_instanceof(trigger, HTMLElement)) return;
|
|
405
|
+
var targetIsTrigger = trigger.contains(target);
|
|
406
|
+
if (targetIsTrigger) event.preventDefault();
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
var DialogContentImpl = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
|
|
411
|
+
var {
|
|
412
|
+
trapFocus,
|
|
413
|
+
onOpenAutoFocus,
|
|
414
|
+
onCloseAutoFocus,
|
|
415
|
+
disableOutsidePointerEvents,
|
|
416
|
+
onEscapeKeyDown,
|
|
417
|
+
onPointerDownOutside,
|
|
418
|
+
onFocusOutside,
|
|
419
|
+
onInteractOutside,
|
|
420
|
+
context,
|
|
421
|
+
...contentProps
|
|
422
|
+
} = props;
|
|
423
|
+
var contentRef = React.useRef(null);
|
|
424
|
+
var composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
425
|
+
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
426
|
+
var isAdaptFullyHidden = React.useContext(DialogAdaptHiddenContext);
|
|
427
|
+
if (isAdapted) {
|
|
428
|
+
if (!context.open && !context.keepChildrenMounted && isAdaptFullyHidden) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
return /* @__PURE__ */_jsx(DialogPortalItem, {
|
|
400
432
|
context,
|
|
401
433
|
children: contentProps.children
|
|
402
434
|
});
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
435
|
+
}
|
|
436
|
+
var contents = /* @__PURE__ */_jsx(DialogContentFrame, {
|
|
437
|
+
ref: composedRefs,
|
|
438
|
+
id: context.contentId,
|
|
439
|
+
role: "dialog",
|
|
440
|
+
"aria-modal": context.modal,
|
|
441
|
+
"aria-describedby": context.descriptionId,
|
|
442
|
+
"aria-labelledby": context.titleId,
|
|
443
|
+
"data-state": getState(context.open),
|
|
444
|
+
// allow clicking through content during exit animation
|
|
445
|
+
pointerEvents: context.open ? "auto" : "none",
|
|
446
|
+
...contentProps
|
|
447
|
+
});
|
|
448
|
+
if (!isWeb) {
|
|
449
|
+
return contents;
|
|
450
|
+
}
|
|
451
|
+
return /* @__PURE__ */_jsxs(_Fragment, {
|
|
452
|
+
children: [/* @__PURE__ */_jsx(Dismissable, {
|
|
453
|
+
disableOutsidePointerEvents: context.open && disableOutsidePointerEvents,
|
|
454
|
+
forceUnmount: !context.open,
|
|
455
|
+
onEscapeKeyDown,
|
|
456
|
+
onPointerDownOutside,
|
|
457
|
+
onFocusOutside,
|
|
458
|
+
onInteractOutside,
|
|
459
|
+
onDismiss: function () {
|
|
460
|
+
var _context_onOpenChange;
|
|
461
|
+
return context === null || context === void 0 ? void 0 : (_context_onOpenChange = context.onOpenChange) === null || _context_onOpenChange === void 0 ? void 0 : _context_onOpenChange.call(context, false);
|
|
462
|
+
},
|
|
463
|
+
children: /* @__PURE__ */_jsx(FocusScope, {
|
|
464
|
+
loop: true,
|
|
465
|
+
enabled: context.open,
|
|
466
|
+
trapped: trapFocus,
|
|
467
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
418
468
|
forceUnmount: !context.open,
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
onFocusOutside,
|
|
422
|
-
onInteractOutside,
|
|
423
|
-
onDismiss: function () {
|
|
424
|
-
var _context_onOpenChange;
|
|
425
|
-
return context == null || (_context_onOpenChange = context.onOpenChange) === null || _context_onOpenChange === void 0 ? void 0 : _context_onOpenChange.call(context, !1);
|
|
426
|
-
},
|
|
427
|
-
children: /* @__PURE__ */_jsx(FocusScope, {
|
|
428
|
-
loop: !0,
|
|
429
|
-
enabled: context.open,
|
|
430
|
-
trapped: trapFocus,
|
|
431
|
-
onMountAutoFocus: onOpenAutoFocus,
|
|
432
|
-
forceUnmount: !context.open,
|
|
433
|
-
onUnmountAutoFocus: onCloseAutoFocus,
|
|
434
|
-
children: contents
|
|
435
|
-
})
|
|
436
|
-
}), process.env.NODE_ENV === "development" && /* @__PURE__ */_jsxs(_Fragment, {
|
|
437
|
-
children: [/* @__PURE__ */_jsx(TitleWarning, {
|
|
438
|
-
titleId: context.titleId
|
|
439
|
-
}), /* @__PURE__ */_jsx(DescriptionWarning, {
|
|
440
|
-
contentRef,
|
|
441
|
-
descriptionId: context.descriptionId
|
|
442
|
-
})]
|
|
443
|
-
})]
|
|
444
|
-
}) : contents;
|
|
445
|
-
}),
|
|
446
|
-
DialogTitleFrame = styled(H2, {
|
|
447
|
-
name: "DialogTitle"
|
|
448
|
-
}),
|
|
449
|
-
DialogTitle = DialogTitleFrame.styleable(function (props, forwardedRef) {
|
|
450
|
-
var {
|
|
451
|
-
scope,
|
|
452
|
-
...titleProps
|
|
453
|
-
} = props,
|
|
454
|
-
context = useDialogContext(scope);
|
|
455
|
-
return /* @__PURE__ */_jsx(DialogTitleFrame, {
|
|
456
|
-
id: context.titleId,
|
|
457
|
-
...titleProps,
|
|
458
|
-
ref: forwardedRef
|
|
459
|
-
});
|
|
460
|
-
}),
|
|
461
|
-
DialogDescriptionFrame = styled(Paragraph, {
|
|
462
|
-
name: "DialogDescription"
|
|
463
|
-
}),
|
|
464
|
-
DialogDescription = DialogDescriptionFrame.styleable(function (props, forwardedRef) {
|
|
465
|
-
var {
|
|
466
|
-
scope,
|
|
467
|
-
...descriptionProps
|
|
468
|
-
} = props,
|
|
469
|
-
context = useDialogContext(scope);
|
|
470
|
-
return /* @__PURE__ */_jsx(DialogDescriptionFrame, {
|
|
471
|
-
id: context.descriptionId,
|
|
472
|
-
...descriptionProps,
|
|
473
|
-
ref: forwardedRef
|
|
474
|
-
});
|
|
475
|
-
}),
|
|
476
|
-
CLOSE_NAME = "DialogClose",
|
|
477
|
-
DialogCloseFrame = styled(View, {
|
|
478
|
-
name: CLOSE_NAME,
|
|
479
|
-
render: "button"
|
|
480
|
-
}),
|
|
481
|
-
DialogClose = DialogCloseFrame.styleable(function (props, forwardedRef) {
|
|
482
|
-
var {
|
|
483
|
-
scope,
|
|
484
|
-
displayWhenAdapted,
|
|
485
|
-
...closeProps
|
|
486
|
-
} = props,
|
|
487
|
-
context = useDialogContext(scope),
|
|
488
|
-
isAdapted = useAdaptIsActive(context.adaptScope),
|
|
489
|
-
isInsideButton = React.useContext(ButtonNestingContext);
|
|
490
|
-
return isAdapted && !displayWhenAdapted ? null : /* @__PURE__ */_jsx(DialogCloseFrame, {
|
|
491
|
-
"aria-label": "Dialog Close",
|
|
492
|
-
render: isInsideButton ? "span" : "button",
|
|
493
|
-
...closeProps,
|
|
494
|
-
ref: forwardedRef,
|
|
495
|
-
onPress: composeEventHandlers(props.onPress, function () {
|
|
496
|
-
context.onOpenChange(!1);
|
|
469
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
470
|
+
children: contents
|
|
497
471
|
})
|
|
498
|
-
})
|
|
472
|
+
}), process.env.NODE_ENV === "development" && /* @__PURE__ */_jsxs(_Fragment, {
|
|
473
|
+
children: [/* @__PURE__ */_jsx(TitleWarning, {
|
|
474
|
+
titleId: context.titleId
|
|
475
|
+
}), /* @__PURE__ */_jsx(DescriptionWarning, {
|
|
476
|
+
contentRef,
|
|
477
|
+
descriptionId: context.descriptionId
|
|
478
|
+
})]
|
|
479
|
+
})]
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
var DialogTitleFrame = styled(H2, {
|
|
483
|
+
name: "DialogTitle"
|
|
484
|
+
});
|
|
485
|
+
var DialogTitle = DialogTitleFrame.styleable(function DialogTitle2(props, forwardedRef) {
|
|
486
|
+
var {
|
|
487
|
+
scope,
|
|
488
|
+
...titleProps
|
|
489
|
+
} = props;
|
|
490
|
+
var context = useDialogContext(scope);
|
|
491
|
+
return /* @__PURE__ */_jsx(DialogTitleFrame, {
|
|
492
|
+
id: context.titleId,
|
|
493
|
+
...titleProps,
|
|
494
|
+
ref: forwardedRef
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
var DialogDescriptionFrame = styled(Paragraph, {
|
|
498
|
+
name: "DialogDescription"
|
|
499
|
+
});
|
|
500
|
+
var DialogDescription = DialogDescriptionFrame.styleable(function DialogDescription2(props, forwardedRef) {
|
|
501
|
+
var {
|
|
502
|
+
scope,
|
|
503
|
+
...descriptionProps
|
|
504
|
+
} = props;
|
|
505
|
+
var context = useDialogContext(scope);
|
|
506
|
+
return /* @__PURE__ */_jsx(DialogDescriptionFrame, {
|
|
507
|
+
id: context.descriptionId,
|
|
508
|
+
...descriptionProps,
|
|
509
|
+
ref: forwardedRef
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
var CLOSE_NAME = "DialogClose";
|
|
513
|
+
var DialogCloseFrame = styled(View, {
|
|
514
|
+
name: CLOSE_NAME,
|
|
515
|
+
render: "button"
|
|
516
|
+
});
|
|
517
|
+
var DialogClose = DialogCloseFrame.styleable(function (props, forwardedRef) {
|
|
518
|
+
var {
|
|
519
|
+
scope,
|
|
520
|
+
displayWhenAdapted,
|
|
521
|
+
...closeProps
|
|
522
|
+
} = props;
|
|
523
|
+
var context = useDialogContext(scope);
|
|
524
|
+
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
525
|
+
var isInsideButton = React.useContext(ButtonNestingContext);
|
|
526
|
+
if (isAdapted && !displayWhenAdapted) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
return /* @__PURE__ */_jsx(DialogCloseFrame, {
|
|
530
|
+
"aria-label": "Dialog Close",
|
|
531
|
+
render: isInsideButton ? "span" : "button",
|
|
532
|
+
...closeProps,
|
|
533
|
+
ref: forwardedRef,
|
|
534
|
+
onPress: composeEventHandlers(props.onPress, function () {
|
|
535
|
+
context.onOpenChange(false);
|
|
536
|
+
})
|
|
499
537
|
});
|
|
538
|
+
});
|
|
500
539
|
function getState(open) {
|
|
501
540
|
return open ? "open" : "closed";
|
|
502
541
|
}
|
|
503
|
-
var TITLE_WARNING_NAME = "DialogTitleWarning"
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
542
|
+
var TITLE_WARNING_NAME = "DialogTitleWarning";
|
|
543
|
+
var [DialogWarningProvider, useWarningContext] = createContext(TITLE_WARNING_NAME, {
|
|
544
|
+
contentName: CONTENT_NAME,
|
|
545
|
+
titleName: "DialogTitle",
|
|
546
|
+
docsSlug: "dialog"
|
|
547
|
+
});
|
|
548
|
+
var TitleWarning = function (param) {
|
|
549
|
+
var {
|
|
550
|
+
titleId
|
|
551
|
+
} = param;
|
|
552
|
+
if (process.env.NODE_ENV === "development") {
|
|
553
|
+
var titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
|
|
554
|
+
var MESSAGE = `\`${titleWarningContext.contentName}\` wants a \`${titleWarningContext.titleName}\` to be accessible. If you want to hide the \`${titleWarningContext.titleName}\`, wrap it with <VisuallyHidden />.`;
|
|
555
|
+
React.useEffect(function () {
|
|
556
|
+
if (!isWeb) return;
|
|
557
|
+
if (titleId) {
|
|
558
|
+
var hasTitle = document.getElementById(titleId);
|
|
559
|
+
if (!hasTitle) {
|
|
560
|
+
console.warn(MESSAGE);
|
|
520
561
|
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
562
|
+
}
|
|
563
|
+
}, [MESSAGE, titleId]);
|
|
564
|
+
}
|
|
565
|
+
return null;
|
|
566
|
+
};
|
|
567
|
+
var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
|
|
568
|
+
var DescriptionWarning = function (param) {
|
|
569
|
+
var {
|
|
570
|
+
contentRef,
|
|
571
|
+
descriptionId
|
|
572
|
+
} = param;
|
|
573
|
+
if (process.env.NODE_ENV === "development") {
|
|
574
|
+
var descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
|
|
575
|
+
var MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
|
|
576
|
+
React.useEffect(function () {
|
|
577
|
+
if (!isWeb) return;
|
|
578
|
+
var contentNode = contentRef.current;
|
|
579
|
+
if (!_instanceof(contentNode, HTMLElement)) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
var describedById = contentNode.getAttribute("aria-describedby");
|
|
583
|
+
if (descriptionId && describedById) {
|
|
584
|
+
var hasDescription = document.getElementById(descriptionId);
|
|
585
|
+
if (!hasDescription) {
|
|
586
|
+
console.warn(MESSAGE);
|
|
544
587
|
}
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
+
}
|
|
589
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
590
|
+
}
|
|
591
|
+
return null;
|
|
592
|
+
};
|
|
593
|
+
var Dialog = withStaticProperties(/* @__PURE__ */React.forwardRef(function Dialog2(props, ref) {
|
|
594
|
+
var {
|
|
595
|
+
scope = "",
|
|
596
|
+
children,
|
|
597
|
+
open: openProp,
|
|
598
|
+
defaultOpen = false,
|
|
599
|
+
onOpenChange,
|
|
600
|
+
modal = true,
|
|
601
|
+
keepChildrenMounted,
|
|
602
|
+
disableRemoveScroll = false,
|
|
603
|
+
onAnimationComplete
|
|
604
|
+
} = props;
|
|
605
|
+
var baseId = React.useId();
|
|
606
|
+
var dialogId = `Dialog-${scope}-${baseId}`;
|
|
607
|
+
var contentId = `${dialogId}-content`;
|
|
608
|
+
var titleId = `${dialogId}-title`;
|
|
609
|
+
var descriptionId = `${dialogId}-description`;
|
|
610
|
+
var triggerRef = React.useRef(null);
|
|
611
|
+
var contentRef = React.useRef(null);
|
|
612
|
+
var [open, setOpen] = useControllableState({
|
|
613
|
+
prop: openProp,
|
|
614
|
+
defaultProp: defaultOpen,
|
|
615
|
+
onChange: onOpenChange
|
|
616
|
+
});
|
|
617
|
+
var onOpenToggle = React.useCallback(function () {
|
|
618
|
+
setOpen(function (prevOpen) {
|
|
619
|
+
return !prevOpen;
|
|
620
|
+
});
|
|
621
|
+
}, [setOpen]);
|
|
622
|
+
var adaptScope = `DialogAdapt${scope}`;
|
|
623
|
+
var context = {
|
|
624
|
+
dialogScope: scope,
|
|
625
|
+
adaptScope,
|
|
626
|
+
triggerRef,
|
|
627
|
+
contentRef,
|
|
628
|
+
contentId,
|
|
629
|
+
titleId,
|
|
630
|
+
descriptionId,
|
|
631
|
+
open,
|
|
632
|
+
onOpenChange: setOpen,
|
|
633
|
+
onOpenToggle,
|
|
634
|
+
modal,
|
|
635
|
+
keepChildrenMounted,
|
|
636
|
+
disableRemoveScroll,
|
|
637
|
+
onAnimationComplete
|
|
638
|
+
};
|
|
639
|
+
React.useImperativeHandle(ref, function () {
|
|
640
|
+
return {
|
|
641
|
+
open: setOpen
|
|
642
|
+
};
|
|
643
|
+
}, [setOpen]);
|
|
644
|
+
return /* @__PURE__ */_jsx(AdaptParent, {
|
|
645
|
+
scope: adaptScope,
|
|
646
|
+
portal: {
|
|
647
|
+
forwardProps: props
|
|
648
|
+
},
|
|
649
|
+
children: /* @__PURE__ */_jsx(DialogProvider, {
|
|
650
|
+
scope,
|
|
651
|
+
...context,
|
|
652
|
+
children: /* @__PURE__ */_jsx(DialogSheetController, {
|
|
588
653
|
onOpenChange: setOpen,
|
|
589
|
-
onOpenToggle,
|
|
590
|
-
modal,
|
|
591
|
-
keepChildrenMounted,
|
|
592
|
-
disableRemoveScroll,
|
|
593
|
-
onAnimationComplete
|
|
594
|
-
};
|
|
595
|
-
return React.useImperativeHandle(ref, function () {
|
|
596
|
-
return {
|
|
597
|
-
open: setOpen
|
|
598
|
-
};
|
|
599
|
-
}, [setOpen]), /* @__PURE__ */_jsx(AdaptParent, {
|
|
600
|
-
scope: adaptScope,
|
|
601
|
-
portal: {
|
|
602
|
-
forwardProps: props
|
|
603
|
-
},
|
|
604
|
-
children: /* @__PURE__ */_jsx(DialogProvider, {
|
|
605
654
|
scope,
|
|
606
|
-
|
|
607
|
-
children: /* @__PURE__ */_jsx(DialogSheetController, {
|
|
608
|
-
onOpenChange: setOpen,
|
|
609
|
-
scope,
|
|
610
|
-
children
|
|
611
|
-
})
|
|
655
|
+
children
|
|
612
656
|
})
|
|
613
|
-
})
|
|
614
|
-
}), {
|
|
615
|
-
Trigger: DialogTrigger,
|
|
616
|
-
Portal: DialogPortal,
|
|
617
|
-
Overlay: DialogOverlay,
|
|
618
|
-
Content: DialogContent,
|
|
619
|
-
Title: DialogTitle,
|
|
620
|
-
Description: DialogDescription,
|
|
621
|
-
Close: DialogClose,
|
|
622
|
-
FocusScope: FocusScopeController,
|
|
623
|
-
Adapt
|
|
657
|
+
})
|
|
624
658
|
});
|
|
659
|
+
}), {
|
|
660
|
+
Trigger: DialogTrigger,
|
|
661
|
+
Portal: DialogPortal,
|
|
662
|
+
Overlay: DialogOverlay,
|
|
663
|
+
Content: DialogContent,
|
|
664
|
+
Title: DialogTitle,
|
|
665
|
+
Description: DialogDescription,
|
|
666
|
+
Close: DialogClose,
|
|
667
|
+
FocusScope: FocusScopeController,
|
|
668
|
+
Adapt
|
|
669
|
+
});
|
|
625
670
|
var DialogSheetController = function (props) {
|
|
626
|
-
var context = useDialogContext(props.scope)
|
|
627
|
-
|
|
671
|
+
var context = useDialogContext(props.scope);
|
|
672
|
+
var isAdapted = useAdaptIsActive(context.adaptScope);
|
|
673
|
+
var [isAdaptFullyHidden, setIsAdaptFullyHidden] = React.useState(!context.open);
|
|
674
|
+
if (context.open && isAdaptFullyHidden) {
|
|
675
|
+
setIsAdaptFullyHidden(false);
|
|
676
|
+
}
|
|
677
|
+
var handleSheetAnimationComplete = React.useCallback(function (param) {
|
|
678
|
+
var {
|
|
679
|
+
open
|
|
680
|
+
} = param;
|
|
681
|
+
if (!open) {
|
|
682
|
+
setIsAdaptFullyHidden(true);
|
|
683
|
+
}
|
|
684
|
+
}, []);
|
|
628
685
|
return /* @__PURE__ */_jsx(SheetController, {
|
|
629
686
|
onOpenChange: function (val) {
|
|
630
687
|
if (isAdapted) {
|
|
631
688
|
var _props_onOpenChange;
|
|
632
|
-
(_props_onOpenChange = props.onOpenChange) === null || _props_onOpenChange === void 0
|
|
689
|
+
(_props_onOpenChange = props.onOpenChange) === null || _props_onOpenChange === void 0 ? void 0 : _props_onOpenChange.call(props, val);
|
|
633
690
|
}
|
|
634
691
|
},
|
|
692
|
+
onAnimationComplete: handleSheetAnimationComplete,
|
|
635
693
|
open: context.open,
|
|
636
694
|
hidden: !isAdapted,
|
|
637
|
-
children:
|
|
695
|
+
children: /* @__PURE__ */_jsx(DialogAdaptHiddenContext.Provider, {
|
|
696
|
+
value: isAdaptFullyHidden,
|
|
697
|
+
children: props.children
|
|
698
|
+
})
|
|
638
699
|
});
|
|
639
700
|
};
|
|
640
701
|
export { Dialog, DialogClose, DialogContent, DialogContext, DialogDescription, DialogOverlay, DialogOverlayFrame, DialogPortal, DialogPortalFrame, DialogProvider, DialogTitle, DialogTrigger, DialogWarningProvider, useDialogContext };
|