@radix-ui/react-toast 0.1.2-rc.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +718 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +697 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +16 -16
package/dist/index.js
CHANGED
|
@@ -1,2 +1,719 @@
|
|
|
1
|
-
var
|
|
1
|
+
var $iTyic$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
|
|
2
|
+
var $iTyic$react = require("react");
|
|
3
|
+
var $iTyic$reactdom = require("react-dom");
|
|
4
|
+
var $iTyic$radixuiprimitive = require("@radix-ui/primitive");
|
|
5
|
+
var $iTyic$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
|
|
6
|
+
var $iTyic$radixuireactcollection = require("@radix-ui/react-collection");
|
|
7
|
+
var $iTyic$radixuireactcontext = require("@radix-ui/react-context");
|
|
8
|
+
var $iTyic$radixuireactdismissablelayer = require("@radix-ui/react-dismissable-layer");
|
|
9
|
+
var $iTyic$radixuireactportal = require("@radix-ui/react-portal");
|
|
10
|
+
var $iTyic$radixuireactpresence = require("@radix-ui/react-presence");
|
|
11
|
+
var $iTyic$radixuireactprimitive = require("@radix-ui/react-primitive");
|
|
12
|
+
var $iTyic$radixuireactusecallbackref = require("@radix-ui/react-use-callback-ref");
|
|
13
|
+
var $iTyic$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
|
|
14
|
+
var $iTyic$radixuireactuselayouteffect = require("@radix-ui/react-use-layout-effect");
|
|
15
|
+
var $iTyic$radixuireactvisuallyhidden = require("@radix-ui/react-visually-hidden");
|
|
16
|
+
|
|
17
|
+
function $parcel$export(e, n, v, s) {
|
|
18
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
19
|
+
}
|
|
20
|
+
function $parcel$interopDefault(a) {
|
|
21
|
+
return a && a.__esModule ? a.default : a;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
$parcel$export(module.exports, "createToastScope", () => $9208a85b3e79d33f$export$8a359da18fbc9073);
|
|
25
|
+
$parcel$export(module.exports, "ToastProvider", () => $9208a85b3e79d33f$export$f5d03d415824e0e);
|
|
26
|
+
$parcel$export(module.exports, "ToastViewport", () => $9208a85b3e79d33f$export$6192c2425ecfd989);
|
|
27
|
+
$parcel$export(module.exports, "Toast", () => $9208a85b3e79d33f$export$8d8dc7d5f743331b);
|
|
28
|
+
$parcel$export(module.exports, "ToastTitle", () => $9208a85b3e79d33f$export$16d42d7c29b95a4);
|
|
29
|
+
$parcel$export(module.exports, "ToastDescription", () => $9208a85b3e79d33f$export$ecddd96c53621d9a);
|
|
30
|
+
$parcel$export(module.exports, "ToastAction", () => $9208a85b3e79d33f$export$3019feecfda683d2);
|
|
31
|
+
$parcel$export(module.exports, "ToastClose", () => $9208a85b3e79d33f$export$811e70f61c205839);
|
|
32
|
+
$parcel$export(module.exports, "Provider", () => $9208a85b3e79d33f$export$2881499e37b75b9a);
|
|
33
|
+
$parcel$export(module.exports, "Viewport", () => $9208a85b3e79d33f$export$d5c6c08dc2d3ca7);
|
|
34
|
+
$parcel$export(module.exports, "Root", () => $9208a85b3e79d33f$export$be92b6f5f03c0fe9);
|
|
35
|
+
$parcel$export(module.exports, "Title", () => $9208a85b3e79d33f$export$f99233281efd08a0);
|
|
36
|
+
$parcel$export(module.exports, "Description", () => $9208a85b3e79d33f$export$393edc798c47379d);
|
|
37
|
+
$parcel$export(module.exports, "Action", () => $9208a85b3e79d33f$export$e19cd5f9376f8cee);
|
|
38
|
+
$parcel$export(module.exports, "Close", () => $9208a85b3e79d33f$export$f39c2d165cd861fe);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/* -------------------------------------------------------------------------------------------------
|
|
55
|
+
* ToastProvider
|
|
56
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$PROVIDER_NAME = 'ToastProvider';
|
|
57
|
+
const [$9208a85b3e79d33f$var$Collection, $9208a85b3e79d33f$var$useCollection, $9208a85b3e79d33f$var$createCollectionScope] = $iTyic$radixuireactcollection.createCollection('Toast');
|
|
58
|
+
const [$9208a85b3e79d33f$var$createToastContext, $9208a85b3e79d33f$export$8a359da18fbc9073] = $iTyic$radixuireactcontext.createContextScope('Toast', [
|
|
59
|
+
$9208a85b3e79d33f$var$createCollectionScope
|
|
60
|
+
]);
|
|
61
|
+
const [$9208a85b3e79d33f$var$ToastProviderProvider, $9208a85b3e79d33f$var$useToastProviderContext] = $9208a85b3e79d33f$var$createToastContext($9208a85b3e79d33f$var$PROVIDER_NAME);
|
|
62
|
+
const $9208a85b3e79d33f$export$f5d03d415824e0e = (props)=>{
|
|
63
|
+
const { __scopeToast: __scopeToast , label: label = 'Notification' , duration: duration = 5000 , swipeDirection: swipeDirection = 'right' , swipeThreshold: swipeThreshold = 50 , children: children } = props;
|
|
64
|
+
const [viewport, setViewport] = $iTyic$react.useState(null);
|
|
65
|
+
const [toastCount, setToastCount] = $iTyic$react.useState(0);
|
|
66
|
+
const isFocusedToastEscapeKeyDownRef = $iTyic$react.useRef(false);
|
|
67
|
+
const isClosePausedRef = $iTyic$react.useRef(false);
|
|
68
|
+
return /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$Collection.Provider, {
|
|
69
|
+
scope: __scopeToast
|
|
70
|
+
}, /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$ToastProviderProvider, {
|
|
71
|
+
scope: __scopeToast,
|
|
72
|
+
label: label,
|
|
73
|
+
duration: duration,
|
|
74
|
+
swipeDirection: swipeDirection,
|
|
75
|
+
swipeThreshold: swipeThreshold,
|
|
76
|
+
toastCount: toastCount,
|
|
77
|
+
viewport: viewport,
|
|
78
|
+
onViewportChange: setViewport,
|
|
79
|
+
onToastAdd: $iTyic$react.useCallback(()=>setToastCount((prevCount)=>prevCount + 1
|
|
80
|
+
)
|
|
81
|
+
, []),
|
|
82
|
+
onToastRemove: $iTyic$react.useCallback(()=>setToastCount((prevCount)=>prevCount - 1
|
|
83
|
+
)
|
|
84
|
+
, []),
|
|
85
|
+
isFocusedToastEscapeKeyDownRef: isFocusedToastEscapeKeyDownRef,
|
|
86
|
+
isClosePausedRef: isClosePausedRef
|
|
87
|
+
}, children));
|
|
88
|
+
};
|
|
89
|
+
$9208a85b3e79d33f$export$f5d03d415824e0e.propTypes = {
|
|
90
|
+
label (props) {
|
|
91
|
+
if (props.label && typeof props.label === 'string' && !props.label.trim()) {
|
|
92
|
+
const error = `Invalid prop \`label\` supplied to \`${$9208a85b3e79d33f$var$PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
|
|
93
|
+
return new Error(error);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$f5d03d415824e0e, {
|
|
99
|
+
displayName: $9208a85b3e79d33f$var$PROVIDER_NAME
|
|
100
|
+
});
|
|
101
|
+
/* -------------------------------------------------------------------------------------------------
|
|
102
|
+
* ToastViewport
|
|
103
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$VIEWPORT_NAME = 'ToastViewport';
|
|
104
|
+
const $9208a85b3e79d33f$var$VIEWPORT_DEFAULT_HOTKEY = [
|
|
105
|
+
'F8'
|
|
106
|
+
];
|
|
107
|
+
const $9208a85b3e79d33f$var$VIEWPORT_PAUSE = 'toast.viewportPause';
|
|
108
|
+
const $9208a85b3e79d33f$var$VIEWPORT_RESUME = 'toast.viewportResume';
|
|
109
|
+
const $9208a85b3e79d33f$export$6192c2425ecfd989 = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
110
|
+
const { __scopeToast: __scopeToast , hotkey: hotkey = $9208a85b3e79d33f$var$VIEWPORT_DEFAULT_HOTKEY , label: label = 'Notifications ({hotkey})' , ...viewportProps } = props;
|
|
111
|
+
const context = $9208a85b3e79d33f$var$useToastProviderContext($9208a85b3e79d33f$var$VIEWPORT_NAME, __scopeToast);
|
|
112
|
+
const getItems = $9208a85b3e79d33f$var$useCollection(__scopeToast);
|
|
113
|
+
const wrapperRef = $iTyic$react.useRef(null);
|
|
114
|
+
const headFocusProxyRef = $iTyic$react.useRef(null);
|
|
115
|
+
const tailFocusProxyRef = $iTyic$react.useRef(null);
|
|
116
|
+
const ref = $iTyic$react.useRef(null);
|
|
117
|
+
const composedRefs = $iTyic$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref, context.onViewportChange);
|
|
118
|
+
const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
|
|
119
|
+
const hasToasts = context.toastCount > 0;
|
|
120
|
+
$iTyic$react.useEffect(()=>{
|
|
121
|
+
const handleKeyDown = (event)=>{
|
|
122
|
+
var _ref$current;
|
|
123
|
+
// we use `event.code` as it is consistent regardless of meta keys that were pressed.
|
|
124
|
+
// for example, `event.key` for `Control+Alt+t` is `†` and `t !== †`
|
|
125
|
+
const isHotkeyPressed = hotkey.every((key)=>event[key] || event.code === key
|
|
126
|
+
);
|
|
127
|
+
if (isHotkeyPressed) (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.focus();
|
|
128
|
+
};
|
|
129
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
130
|
+
return ()=>document.removeEventListener('keydown', handleKeyDown)
|
|
131
|
+
;
|
|
132
|
+
}, [
|
|
133
|
+
hotkey
|
|
134
|
+
]);
|
|
135
|
+
$iTyic$react.useEffect(()=>{
|
|
136
|
+
const wrapper = wrapperRef.current;
|
|
137
|
+
const viewport = ref.current;
|
|
138
|
+
if (wrapper && viewport) {
|
|
139
|
+
const handlePause = ()=>{
|
|
140
|
+
const pauseEvent = new CustomEvent($9208a85b3e79d33f$var$VIEWPORT_PAUSE);
|
|
141
|
+
viewport.dispatchEvent(pauseEvent);
|
|
142
|
+
context.isClosePausedRef.current = true;
|
|
143
|
+
};
|
|
144
|
+
const handleResume = ()=>{
|
|
145
|
+
const resumeEvent = new CustomEvent($9208a85b3e79d33f$var$VIEWPORT_RESUME);
|
|
146
|
+
viewport.dispatchEvent(resumeEvent);
|
|
147
|
+
context.isClosePausedRef.current = false;
|
|
148
|
+
}; // Toasts are not in the viewport React tree so we need to bind DOM events
|
|
149
|
+
wrapper.addEventListener('focusin', handlePause);
|
|
150
|
+
wrapper.addEventListener('focusout', handleResume);
|
|
151
|
+
wrapper.addEventListener('pointerenter', handlePause);
|
|
152
|
+
wrapper.addEventListener('pointerleave', handleResume);
|
|
153
|
+
window.addEventListener('blur', handlePause);
|
|
154
|
+
window.addEventListener('focus', handleResume);
|
|
155
|
+
return ()=>{
|
|
156
|
+
wrapper.removeEventListener('focusin', handlePause);
|
|
157
|
+
wrapper.removeEventListener('focusout', handleResume);
|
|
158
|
+
wrapper.removeEventListener('pointerenter', handlePause);
|
|
159
|
+
wrapper.removeEventListener('pointerleave', handleResume);
|
|
160
|
+
window.removeEventListener('blur', handlePause);
|
|
161
|
+
window.removeEventListener('focus', handleResume);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}, [
|
|
165
|
+
context.isClosePausedRef
|
|
166
|
+
]);
|
|
167
|
+
const getSortedTabbableCandidates = $iTyic$react.useCallback(({ tabbingDirection: tabbingDirection })=>{
|
|
168
|
+
const toastItems = getItems();
|
|
169
|
+
const tabbableCandidates = toastItems.map((toastItem)=>{
|
|
170
|
+
const toastNode = toastItem.ref.current;
|
|
171
|
+
const toastTabbableCandidates = [
|
|
172
|
+
toastNode,
|
|
173
|
+
...$9208a85b3e79d33f$var$getTabbableCandidates(toastNode)
|
|
174
|
+
];
|
|
175
|
+
return tabbingDirection === 'forwards' ? toastTabbableCandidates : toastTabbableCandidates.reverse();
|
|
176
|
+
});
|
|
177
|
+
return (tabbingDirection === 'forwards' ? tabbableCandidates.reverse() : tabbableCandidates).flat();
|
|
178
|
+
}, [
|
|
179
|
+
getItems
|
|
180
|
+
]);
|
|
181
|
+
$iTyic$react.useEffect(()=>{
|
|
182
|
+
const viewport = ref.current; // We programmatically manage tabbing as we are unable to influence
|
|
183
|
+
// the source order with portals, this allows us to reverse the
|
|
184
|
+
// tab order so that it runs from most recent toast to least
|
|
185
|
+
if (viewport) {
|
|
186
|
+
const handleKeyDown = (event)=>{
|
|
187
|
+
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
188
|
+
const isTabKey = event.key === 'Tab' && !isMetaKey;
|
|
189
|
+
if (isTabKey) {
|
|
190
|
+
const focusedElement = document.activeElement;
|
|
191
|
+
const isTabbingBackwards = event.shiftKey;
|
|
192
|
+
const targetIsViewport = event.target === viewport; // If we're back tabbing after jumping to the viewport then we simply
|
|
193
|
+
// proxy focus out to the preceding document
|
|
194
|
+
if (targetIsViewport && isTabbingBackwards) {
|
|
195
|
+
var _headFocusProxyRef$cu;
|
|
196
|
+
(_headFocusProxyRef$cu = headFocusProxyRef.current) === null || _headFocusProxyRef$cu === void 0 || _headFocusProxyRef$cu.focus();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards';
|
|
200
|
+
const sortedCandidates = getSortedTabbableCandidates({
|
|
201
|
+
tabbingDirection: tabbingDirection
|
|
202
|
+
});
|
|
203
|
+
const index = sortedCandidates.findIndex((candidate)=>candidate === focusedElement
|
|
204
|
+
);
|
|
205
|
+
if ($9208a85b3e79d33f$var$focusFirst(sortedCandidates.slice(index + 1))) event.preventDefault();
|
|
206
|
+
else {
|
|
207
|
+
var _headFocusProxyRef$cu2, _tailFocusProxyRef$cu;
|
|
208
|
+
// If we can't focus that means we're at the edges so we
|
|
209
|
+
// proxy to the corresponding exit point and let the browser handle
|
|
210
|
+
// tab/shift+tab keypress and implicitly pass focus to the next valid element in the document
|
|
211
|
+
isTabbingBackwards ? (_headFocusProxyRef$cu2 = headFocusProxyRef.current) === null || _headFocusProxyRef$cu2 === void 0 || _headFocusProxyRef$cu2.focus() : (_tailFocusProxyRef$cu = tailFocusProxyRef.current) === null || _tailFocusProxyRef$cu === void 0 || _tailFocusProxyRef$cu.focus();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}; // Toasts are not in the viewport React tree so we need to bind DOM events
|
|
215
|
+
viewport.addEventListener('keydown', handleKeyDown);
|
|
216
|
+
return ()=>viewport.removeEventListener('keydown', handleKeyDown)
|
|
217
|
+
;
|
|
218
|
+
}
|
|
219
|
+
}, [
|
|
220
|
+
getItems,
|
|
221
|
+
getSortedTabbableCandidates
|
|
222
|
+
]);
|
|
223
|
+
return /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactdismissablelayer.Branch, {
|
|
224
|
+
ref: wrapperRef,
|
|
225
|
+
role: "region",
|
|
226
|
+
"aria-label": label.replace('{hotkey}', hotkeyLabel) // Ensure virtual cursor from landmarks menus triggers focus/blur for pause/resume
|
|
227
|
+
,
|
|
228
|
+
tabIndex: -1 // incase list has size when empty (e.g. padding), we remove pointer events so
|
|
229
|
+
,
|
|
230
|
+
style: {
|
|
231
|
+
pointerEvents: hasToasts ? undefined : 'none'
|
|
232
|
+
}
|
|
233
|
+
}, hasToasts && /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$FocusProxy, {
|
|
234
|
+
ref: headFocusProxyRef,
|
|
235
|
+
onFocusFromOutsideViewport: ()=>{
|
|
236
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
237
|
+
tabbingDirection: 'forwards'
|
|
238
|
+
});
|
|
239
|
+
$9208a85b3e79d33f$var$focusFirst(tabbableCandidates);
|
|
240
|
+
}
|
|
241
|
+
}), /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$Collection.Slot, {
|
|
242
|
+
scope: __scopeToast
|
|
243
|
+
}, /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactprimitive.Primitive.ol, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({
|
|
244
|
+
tabIndex: -1
|
|
245
|
+
}, viewportProps, {
|
|
246
|
+
ref: composedRefs
|
|
247
|
+
}))), hasToasts && /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$FocusProxy, {
|
|
248
|
+
ref: tailFocusProxyRef,
|
|
249
|
+
onFocusFromOutsideViewport: ()=>{
|
|
250
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
251
|
+
tabbingDirection: 'backwards'
|
|
252
|
+
});
|
|
253
|
+
$9208a85b3e79d33f$var$focusFirst(tabbableCandidates);
|
|
254
|
+
}
|
|
255
|
+
}));
|
|
256
|
+
});
|
|
257
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$6192c2425ecfd989, {
|
|
258
|
+
displayName: $9208a85b3e79d33f$var$VIEWPORT_NAME
|
|
259
|
+
});
|
|
260
|
+
/* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$FOCUS_PROXY_NAME = 'ToastFocusProxy';
|
|
261
|
+
const $9208a85b3e79d33f$var$FocusProxy = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
262
|
+
const { __scopeToast: __scopeToast , onFocusFromOutsideViewport: onFocusFromOutsideViewport , ...proxyProps } = props;
|
|
263
|
+
const context = $9208a85b3e79d33f$var$useToastProviderContext($9208a85b3e79d33f$var$FOCUS_PROXY_NAME, __scopeToast);
|
|
264
|
+
return /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactvisuallyhidden.VisuallyHidden, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({
|
|
265
|
+
"aria-hidden": true,
|
|
266
|
+
tabIndex: 0
|
|
267
|
+
}, proxyProps, {
|
|
268
|
+
ref: forwardedRef // Avoid page scrolling when focus is on the focus proxy
|
|
269
|
+
,
|
|
270
|
+
style: {
|
|
271
|
+
position: 'fixed'
|
|
272
|
+
},
|
|
273
|
+
onFocus: (event)=>{
|
|
274
|
+
var _context$viewport;
|
|
275
|
+
const prevFocusedElement = event.relatedTarget;
|
|
276
|
+
const isFocusFromOutsideViewport = !((_context$viewport = context.viewport) !== null && _context$viewport !== void 0 && _context$viewport.contains(prevFocusedElement));
|
|
277
|
+
if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
|
|
278
|
+
}
|
|
279
|
+
}));
|
|
280
|
+
});
|
|
281
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$var$FocusProxy, {
|
|
282
|
+
displayName: $9208a85b3e79d33f$var$FOCUS_PROXY_NAME
|
|
283
|
+
});
|
|
284
|
+
/* -------------------------------------------------------------------------------------------------
|
|
285
|
+
* Toast
|
|
286
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$TOAST_NAME = 'Toast';
|
|
287
|
+
const $9208a85b3e79d33f$var$TOAST_SWIPE_START = 'toast.swipeStart';
|
|
288
|
+
const $9208a85b3e79d33f$var$TOAST_SWIPE_MOVE = 'toast.swipeMove';
|
|
289
|
+
const $9208a85b3e79d33f$var$TOAST_SWIPE_CANCEL = 'toast.swipeCancel';
|
|
290
|
+
const $9208a85b3e79d33f$var$TOAST_SWIPE_END = 'toast.swipeEnd';
|
|
291
|
+
const $9208a85b3e79d33f$export$8d8dc7d5f743331b = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
292
|
+
const { forceMount: forceMount , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , ...toastProps } = props;
|
|
293
|
+
const [open = true, setOpen] = $iTyic$radixuireactusecontrollablestate.useControllableState({
|
|
294
|
+
prop: openProp,
|
|
295
|
+
defaultProp: defaultOpen,
|
|
296
|
+
onChange: onOpenChange
|
|
297
|
+
});
|
|
298
|
+
return /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactpresence.Presence, {
|
|
299
|
+
present: forceMount || open
|
|
300
|
+
}, /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$ToastImpl, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({
|
|
301
|
+
open: open
|
|
302
|
+
}, toastProps, {
|
|
303
|
+
ref: forwardedRef,
|
|
304
|
+
onClose: ()=>setOpen(false)
|
|
305
|
+
,
|
|
306
|
+
onSwipeStart: $iTyic$radixuiprimitive.composeEventHandlers(props.onSwipeStart, (event)=>{
|
|
307
|
+
event.currentTarget.setAttribute('data-swipe', 'start');
|
|
308
|
+
}),
|
|
309
|
+
onSwipeMove: $iTyic$radixuiprimitive.composeEventHandlers(props.onSwipeMove, (event)=>{
|
|
310
|
+
const { x: x , y: y } = event.detail.delta;
|
|
311
|
+
event.currentTarget.setAttribute('data-swipe', 'move');
|
|
312
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-move-x', `${x}px`);
|
|
313
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-move-y', `${y}px`);
|
|
314
|
+
}),
|
|
315
|
+
onSwipeCancel: $iTyic$radixuiprimitive.composeEventHandlers(props.onSwipeCancel, (event)=>{
|
|
316
|
+
event.currentTarget.setAttribute('data-swipe', 'cancel');
|
|
317
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-x');
|
|
318
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-y');
|
|
319
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-end-x');
|
|
320
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-end-y');
|
|
321
|
+
}),
|
|
322
|
+
onSwipeEnd: $iTyic$radixuiprimitive.composeEventHandlers(props.onSwipeEnd, (event)=>{
|
|
323
|
+
const { x: x , y: y } = event.detail.delta;
|
|
324
|
+
event.currentTarget.setAttribute('data-swipe', 'end');
|
|
325
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-x');
|
|
326
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-y');
|
|
327
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-end-x', `${x}px`);
|
|
328
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-end-y', `${y}px`);
|
|
329
|
+
setOpen(false);
|
|
330
|
+
})
|
|
331
|
+
})));
|
|
332
|
+
});
|
|
333
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$8d8dc7d5f743331b, {
|
|
334
|
+
displayName: $9208a85b3e79d33f$var$TOAST_NAME
|
|
335
|
+
});
|
|
336
|
+
/* -----------------------------------------------------------------------------------------------*/ const [$9208a85b3e79d33f$var$ToastInteractiveProvider, $9208a85b3e79d33f$var$useToastInteractiveContext] = $9208a85b3e79d33f$var$createToastContext($9208a85b3e79d33f$var$TOAST_NAME, {
|
|
337
|
+
isInteractive: false,
|
|
338
|
+
onClose () {}
|
|
339
|
+
});
|
|
340
|
+
const $9208a85b3e79d33f$var$ToastImpl = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
341
|
+
const { __scopeToast: __scopeToast , type: type = 'foreground' , duration: durationProp , open: open , onClose: onClose , onEscapeKeyDown: onEscapeKeyDown , onSwipeStart: onSwipeStart , onSwipeMove: onSwipeMove , onSwipeCancel: onSwipeCancel , onSwipeEnd: onSwipeEnd , ...toastProps } = props;
|
|
342
|
+
const context = $9208a85b3e79d33f$var$useToastProviderContext($9208a85b3e79d33f$var$TOAST_NAME, __scopeToast);
|
|
343
|
+
const ref = $iTyic$react.useRef(null);
|
|
344
|
+
const composedRefs = $iTyic$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
|
|
345
|
+
const pointerStartRef = $iTyic$react.useRef(null);
|
|
346
|
+
const swipeDeltaRef = $iTyic$react.useRef(null);
|
|
347
|
+
const duration1 = durationProp || context.duration;
|
|
348
|
+
const closeTimerStartTimeRef = $iTyic$react.useRef(0);
|
|
349
|
+
const closeTimerRemainingTimeRef = $iTyic$react.useRef(duration1);
|
|
350
|
+
const closeTimerRef = $iTyic$react.useRef(0);
|
|
351
|
+
const { onToastAdd: onToastAdd , onToastRemove: onToastRemove } = context;
|
|
352
|
+
const handleClose = $iTyic$radixuireactusecallbackref.useCallbackRef(()=>{
|
|
353
|
+
var _ref$current2, _context$viewport2;
|
|
354
|
+
// focus viewport if focus is within toast to read the remaining toast
|
|
355
|
+
// count to SR users and ensure focus isn't lost
|
|
356
|
+
const isFocusInToast = (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.contains(document.activeElement);
|
|
357
|
+
if (isFocusInToast) (_context$viewport2 = context.viewport) === null || _context$viewport2 === void 0 || _context$viewport2.focus();
|
|
358
|
+
onClose();
|
|
359
|
+
});
|
|
360
|
+
const startTimer = $iTyic$react.useCallback((duration)=>{
|
|
361
|
+
if (!duration || duration === Infinity) return;
|
|
362
|
+
window.clearTimeout(closeTimerRef.current);
|
|
363
|
+
closeTimerStartTimeRef.current = new Date().getTime();
|
|
364
|
+
closeTimerRef.current = window.setTimeout(handleClose, duration);
|
|
365
|
+
}, [
|
|
366
|
+
handleClose
|
|
367
|
+
]);
|
|
368
|
+
$iTyic$react.useEffect(()=>{
|
|
369
|
+
const viewport = context.viewport;
|
|
370
|
+
if (viewport) {
|
|
371
|
+
const handleResume = ()=>{
|
|
372
|
+
startTimer(closeTimerRemainingTimeRef.current);
|
|
373
|
+
};
|
|
374
|
+
const handlePause = ()=>{
|
|
375
|
+
const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;
|
|
376
|
+
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
377
|
+
window.clearTimeout(closeTimerRef.current);
|
|
378
|
+
};
|
|
379
|
+
viewport.addEventListener($9208a85b3e79d33f$var$VIEWPORT_PAUSE, handlePause);
|
|
380
|
+
viewport.addEventListener($9208a85b3e79d33f$var$VIEWPORT_RESUME, handleResume);
|
|
381
|
+
return ()=>{
|
|
382
|
+
viewport.removeEventListener($9208a85b3e79d33f$var$VIEWPORT_PAUSE, handlePause);
|
|
383
|
+
viewport.removeEventListener($9208a85b3e79d33f$var$VIEWPORT_RESUME, handleResume);
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}, [
|
|
387
|
+
context.viewport,
|
|
388
|
+
duration1,
|
|
389
|
+
startTimer
|
|
390
|
+
]); // start timer when toast opens or duration changes.
|
|
391
|
+
// we include `open` in deps because closed !== unmounted when animating
|
|
392
|
+
// so it could reopen before being completely unmounted
|
|
393
|
+
$iTyic$react.useEffect(()=>{
|
|
394
|
+
if (open && !context.isClosePausedRef.current) startTimer(duration1);
|
|
395
|
+
}, [
|
|
396
|
+
open,
|
|
397
|
+
duration1,
|
|
398
|
+
context.isClosePausedRef,
|
|
399
|
+
startTimer
|
|
400
|
+
]);
|
|
401
|
+
$iTyic$react.useEffect(()=>{
|
|
402
|
+
onToastAdd();
|
|
403
|
+
return ()=>onToastRemove()
|
|
404
|
+
;
|
|
405
|
+
}, [
|
|
406
|
+
onToastAdd,
|
|
407
|
+
onToastRemove
|
|
408
|
+
]);
|
|
409
|
+
if (!context.viewport) return null;
|
|
410
|
+
return /*#__PURE__*/ $iTyic$react.createElement($iTyic$react.Fragment, null, /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$ToastAnnounce, {
|
|
411
|
+
__scopeToast: __scopeToast // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.
|
|
412
|
+
,
|
|
413
|
+
role: "status",
|
|
414
|
+
"aria-live": type === 'foreground' ? 'assertive' : 'polite',
|
|
415
|
+
"aria-atomic": true
|
|
416
|
+
}, props.children), /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$ToastInteractiveProvider, {
|
|
417
|
+
scope: __scopeToast,
|
|
418
|
+
isInteractive: true,
|
|
419
|
+
onClose: handleClose
|
|
420
|
+
}, /*#__PURE__*/ $iTyic$reactdom.createPortal(/*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$var$Collection.ItemSlot, {
|
|
421
|
+
scope: __scopeToast
|
|
422
|
+
}, /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactdismissablelayer.Root, {
|
|
423
|
+
asChild: true,
|
|
424
|
+
onEscapeKeyDown: $iTyic$radixuiprimitive.composeEventHandlers(onEscapeKeyDown, ()=>{
|
|
425
|
+
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
|
|
426
|
+
context.isFocusedToastEscapeKeyDownRef.current = false;
|
|
427
|
+
})
|
|
428
|
+
}, /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactprimitive.Primitive.li, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({
|
|
429
|
+
tabIndex: 0,
|
|
430
|
+
"data-state": open ? 'open' : 'closed',
|
|
431
|
+
"data-swipe-direction": context.swipeDirection
|
|
432
|
+
}, toastProps, {
|
|
433
|
+
ref: composedRefs,
|
|
434
|
+
style: {
|
|
435
|
+
userSelect: 'none',
|
|
436
|
+
touchAction: 'none',
|
|
437
|
+
...props.style
|
|
438
|
+
},
|
|
439
|
+
onKeyDown: $iTyic$radixuiprimitive.composeEventHandlers(props.onKeyDown, (event)=>{
|
|
440
|
+
if (event.key !== 'Escape') return;
|
|
441
|
+
onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event.nativeEvent);
|
|
442
|
+
if (!event.nativeEvent.defaultPrevented) {
|
|
443
|
+
context.isFocusedToastEscapeKeyDownRef.current = true;
|
|
444
|
+
handleClose();
|
|
445
|
+
}
|
|
446
|
+
}),
|
|
447
|
+
onPointerDown: $iTyic$radixuiprimitive.composeEventHandlers(props.onPointerDown, (event)=>{
|
|
448
|
+
if (event.button !== 0) return;
|
|
449
|
+
pointerStartRef.current = {
|
|
450
|
+
x: event.clientX,
|
|
451
|
+
y: event.clientY
|
|
452
|
+
};
|
|
453
|
+
}),
|
|
454
|
+
onPointerMove: $iTyic$radixuiprimitive.composeEventHandlers(props.onPointerMove, (event)=>{
|
|
455
|
+
if (!pointerStartRef.current) return;
|
|
456
|
+
const x = event.clientX - pointerStartRef.current.x;
|
|
457
|
+
const y = event.clientY - pointerStartRef.current.y;
|
|
458
|
+
const hasSwipeMoveStarted = Boolean(swipeDeltaRef.current);
|
|
459
|
+
const isHorizontalSwipe = [
|
|
460
|
+
'left',
|
|
461
|
+
'right'
|
|
462
|
+
].includes(context.swipeDirection);
|
|
463
|
+
const clamp = [
|
|
464
|
+
'left',
|
|
465
|
+
'up'
|
|
466
|
+
].includes(context.swipeDirection) ? Math.min : Math.max;
|
|
467
|
+
const clampedX = isHorizontalSwipe ? clamp(0, x) : 0;
|
|
468
|
+
const clampedY = !isHorizontalSwipe ? clamp(0, y) : 0;
|
|
469
|
+
const moveStartBuffer = event.pointerType === 'touch' ? 10 : 2;
|
|
470
|
+
const delta = {
|
|
471
|
+
x: clampedX,
|
|
472
|
+
y: clampedY
|
|
473
|
+
};
|
|
474
|
+
const eventDetail = {
|
|
475
|
+
originalEvent: event,
|
|
476
|
+
delta: delta
|
|
477
|
+
};
|
|
478
|
+
if (hasSwipeMoveStarted) {
|
|
479
|
+
swipeDeltaRef.current = delta;
|
|
480
|
+
$9208a85b3e79d33f$var$handleAndDispatchCustomEvent($9208a85b3e79d33f$var$TOAST_SWIPE_MOVE, onSwipeMove, eventDetail, {
|
|
481
|
+
discrete: false
|
|
482
|
+
});
|
|
483
|
+
} else if ($9208a85b3e79d33f$var$isDeltaInDirection(delta, context.swipeDirection, moveStartBuffer)) {
|
|
484
|
+
swipeDeltaRef.current = delta;
|
|
485
|
+
$9208a85b3e79d33f$var$handleAndDispatchCustomEvent($9208a85b3e79d33f$var$TOAST_SWIPE_START, onSwipeStart, eventDetail, {
|
|
486
|
+
discrete: false
|
|
487
|
+
});
|
|
488
|
+
event.target.setPointerCapture(event.pointerId);
|
|
489
|
+
} else if (Math.abs(x) > moveStartBuffer || Math.abs(y) > moveStartBuffer) // User is swiping in wrong direction so we disable swipe gesture
|
|
490
|
+
// for the current pointer down interaction
|
|
491
|
+
pointerStartRef.current = null;
|
|
492
|
+
}),
|
|
493
|
+
onPointerUp: $iTyic$radixuiprimitive.composeEventHandlers(props.onPointerUp, (event1)=>{
|
|
494
|
+
const delta = swipeDeltaRef.current;
|
|
495
|
+
event1.target.releasePointerCapture(event1.pointerId);
|
|
496
|
+
swipeDeltaRef.current = null;
|
|
497
|
+
pointerStartRef.current = null;
|
|
498
|
+
if (delta) {
|
|
499
|
+
const toast = event1.currentTarget;
|
|
500
|
+
const eventDetail = {
|
|
501
|
+
originalEvent: event1,
|
|
502
|
+
delta: delta
|
|
503
|
+
};
|
|
504
|
+
if ($9208a85b3e79d33f$var$isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) $9208a85b3e79d33f$var$handleAndDispatchCustomEvent($9208a85b3e79d33f$var$TOAST_SWIPE_END, onSwipeEnd, eventDetail, {
|
|
505
|
+
discrete: true
|
|
506
|
+
});
|
|
507
|
+
else $9208a85b3e79d33f$var$handleAndDispatchCustomEvent($9208a85b3e79d33f$var$TOAST_SWIPE_CANCEL, onSwipeCancel, eventDetail, {
|
|
508
|
+
discrete: true
|
|
509
|
+
});
|
|
510
|
+
// Prevent click event from triggering on items within the toast when
|
|
511
|
+
// pointer up is part of a swipe gesture
|
|
512
|
+
toast.addEventListener('click', (event)=>event.preventDefault()
|
|
513
|
+
, {
|
|
514
|
+
once: true
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
})
|
|
518
|
+
})))), context.viewport)));
|
|
519
|
+
});
|
|
520
|
+
$9208a85b3e79d33f$var$ToastImpl.propTypes = {
|
|
521
|
+
type (props) {
|
|
522
|
+
if (props.type && ![
|
|
523
|
+
'foreground',
|
|
524
|
+
'background'
|
|
525
|
+
].includes(props.type)) {
|
|
526
|
+
const error = `Invalid prop \`type\` supplied to \`${$9208a85b3e79d33f$var$TOAST_NAME}\`. Expected \`foreground | background\`.`;
|
|
527
|
+
return new Error(error);
|
|
528
|
+
}
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
/* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$ToastAnnounce = (props)=>{
|
|
533
|
+
const { __scopeToast: __scopeToast , children: children , ...announceProps } = props;
|
|
534
|
+
const context = $9208a85b3e79d33f$var$useToastProviderContext($9208a85b3e79d33f$var$TOAST_NAME, __scopeToast);
|
|
535
|
+
const [renderAnnounceText, setRenderAnnounceText] = $iTyic$react.useState(false);
|
|
536
|
+
const [isAnnounced, setIsAnnounced] = $iTyic$react.useState(false);
|
|
537
|
+
const [fragment, setFragment] = $iTyic$react.useState();
|
|
538
|
+
const [rootFragmentNode, setRootFragmentNode] = $iTyic$react.useState(null); // We portal children into a document fragment so that we can extract the bare text nodes
|
|
539
|
+
// before rendering to the DOM. This avoids issues with duplicate `children`
|
|
540
|
+
// and animation libraries when composing via `asChild`.
|
|
541
|
+
const announceTextContent = $iTyic$react.useMemo(()=>{
|
|
542
|
+
return rootFragmentNode ? $9208a85b3e79d33f$var$getAnnounceTextContent(rootFragmentNode) : null;
|
|
543
|
+
}, [
|
|
544
|
+
rootFragmentNode
|
|
545
|
+
]); // setting the fragment in `useLayoutEffect` as `DocumentFragment` doesn't exist on the server
|
|
546
|
+
$iTyic$radixuireactuselayouteffect.useLayoutEffect(()=>{
|
|
547
|
+
setFragment(new DocumentFragment());
|
|
548
|
+
}, []); // render text content in the next frame to ensure toast is announced in NVDA
|
|
549
|
+
$9208a85b3e79d33f$var$useNextFrame(()=>setRenderAnnounceText(true)
|
|
550
|
+
);
|
|
551
|
+
$iTyic$react.useEffect(()=>{
|
|
552
|
+
const timer = window.setTimeout(()=>setIsAnnounced(true)
|
|
553
|
+
, 1000);
|
|
554
|
+
return ()=>window.clearTimeout(timer)
|
|
555
|
+
;
|
|
556
|
+
}, []);
|
|
557
|
+
return isAnnounced ? null : /*#__PURE__*/ $iTyic$react.createElement($iTyic$react.Fragment, null, fragment && /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactportal.Portal, {
|
|
558
|
+
container: fragment,
|
|
559
|
+
ref: setRootFragmentNode
|
|
560
|
+
}, context.label, " ", children), /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactportal.Portal, {
|
|
561
|
+
asChild: true
|
|
562
|
+
}, /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactvisuallyhidden.VisuallyHidden, announceProps, renderAnnounceText && announceTextContent)));
|
|
563
|
+
};
|
|
564
|
+
/* -------------------------------------------------------------------------------------------------
|
|
565
|
+
* ToastTitle
|
|
566
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$TITLE_NAME = 'ToastTitle';
|
|
567
|
+
const $9208a85b3e79d33f$export$16d42d7c29b95a4 = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
568
|
+
const { __scopeToast: __scopeToast , ...titleProps } = props;
|
|
569
|
+
return /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({}, titleProps, {
|
|
570
|
+
ref: forwardedRef
|
|
571
|
+
}));
|
|
572
|
+
});
|
|
573
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$16d42d7c29b95a4, {
|
|
574
|
+
displayName: $9208a85b3e79d33f$var$TITLE_NAME
|
|
575
|
+
});
|
|
576
|
+
/* -------------------------------------------------------------------------------------------------
|
|
577
|
+
* ToastDescription
|
|
578
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$DESCRIPTION_NAME = 'ToastDescription';
|
|
579
|
+
const $9208a85b3e79d33f$export$ecddd96c53621d9a = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
580
|
+
const { __scopeToast: __scopeToast , ...descriptionProps } = props;
|
|
581
|
+
return /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({}, descriptionProps, {
|
|
582
|
+
ref: forwardedRef
|
|
583
|
+
}));
|
|
584
|
+
});
|
|
585
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$ecddd96c53621d9a, {
|
|
586
|
+
displayName: $9208a85b3e79d33f$var$DESCRIPTION_NAME
|
|
587
|
+
});
|
|
588
|
+
/* -------------------------------------------------------------------------------------------------
|
|
589
|
+
* ToastAction
|
|
590
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$ACTION_NAME = 'ToastAction';
|
|
591
|
+
const $9208a85b3e79d33f$export$3019feecfda683d2 = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
592
|
+
const { altText: altText , ...actionProps } = props;
|
|
593
|
+
const context = $9208a85b3e79d33f$var$useToastInteractiveContext($9208a85b3e79d33f$var$ACTION_NAME, props.__scopeToast);
|
|
594
|
+
if (!altText) return null;
|
|
595
|
+
return context.isInteractive ? /*#__PURE__*/ $iTyic$react.createElement($9208a85b3e79d33f$export$811e70f61c205839, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({}, actionProps, {
|
|
596
|
+
ref: forwardedRef
|
|
597
|
+
})) : /*#__PURE__*/ $iTyic$react.createElement("span", null, altText);
|
|
598
|
+
});
|
|
599
|
+
$9208a85b3e79d33f$export$3019feecfda683d2.propTypes = {
|
|
600
|
+
altText (props) {
|
|
601
|
+
if (!props.altText) return new Error(`Missing prop \`altText\` expected on \`${$9208a85b3e79d33f$var$ACTION_NAME}\``);
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$3019feecfda683d2, {
|
|
606
|
+
displayName: $9208a85b3e79d33f$var$ACTION_NAME
|
|
607
|
+
});
|
|
608
|
+
/* -------------------------------------------------------------------------------------------------
|
|
609
|
+
* ToastClose
|
|
610
|
+
* -----------------------------------------------------------------------------------------------*/ const $9208a85b3e79d33f$var$CLOSE_NAME = 'ToastClose';
|
|
611
|
+
const $9208a85b3e79d33f$export$811e70f61c205839 = /*#__PURE__*/ $iTyic$react.forwardRef((props, forwardedRef)=>{
|
|
612
|
+
const { __scopeToast: __scopeToast , ...closeProps } = props;
|
|
613
|
+
const interactiveContext = $9208a85b3e79d33f$var$useToastInteractiveContext($9208a85b3e79d33f$var$CLOSE_NAME, __scopeToast);
|
|
614
|
+
return interactiveContext.isInteractive ? /*#__PURE__*/ $iTyic$react.createElement($iTyic$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($iTyic$babelruntimehelpersextends))({
|
|
615
|
+
type: "button"
|
|
616
|
+
}, closeProps, {
|
|
617
|
+
ref: forwardedRef,
|
|
618
|
+
onClick: $iTyic$radixuiprimitive.composeEventHandlers(props.onClick, interactiveContext.onClose)
|
|
619
|
+
})) : null;
|
|
620
|
+
});
|
|
621
|
+
/*#__PURE__*/ Object.assign($9208a85b3e79d33f$export$811e70f61c205839, {
|
|
622
|
+
displayName: $9208a85b3e79d33f$var$CLOSE_NAME
|
|
623
|
+
});
|
|
624
|
+
/* ---------------------------------------------------------------------------------------------- */ function $9208a85b3e79d33f$var$handleAndDispatchCustomEvent(name, handler, detail, { discrete: discrete }) {
|
|
625
|
+
const currentTarget = detail.originalEvent.currentTarget;
|
|
626
|
+
const event = new CustomEvent(name, {
|
|
627
|
+
bubbles: true,
|
|
628
|
+
cancelable: true,
|
|
629
|
+
detail: detail
|
|
630
|
+
});
|
|
631
|
+
if (handler) currentTarget.addEventListener(name, handler, {
|
|
632
|
+
once: true
|
|
633
|
+
});
|
|
634
|
+
if (discrete) $iTyic$radixuireactprimitive.dispatchDiscreteCustomEvent(currentTarget, event);
|
|
635
|
+
else currentTarget.dispatchEvent(event);
|
|
636
|
+
}
|
|
637
|
+
const $9208a85b3e79d33f$var$isDeltaInDirection = (delta, direction, threshold = 0)=>{
|
|
638
|
+
const deltaX = Math.abs(delta.x);
|
|
639
|
+
const deltaY = Math.abs(delta.y);
|
|
640
|
+
const isDeltaX = deltaX > deltaY;
|
|
641
|
+
if (direction === 'left' || direction === 'right') return isDeltaX && deltaX > threshold;
|
|
642
|
+
else return !isDeltaX && deltaY > threshold;
|
|
643
|
+
};
|
|
644
|
+
function $9208a85b3e79d33f$var$useNextFrame(callback = ()=>{}) {
|
|
645
|
+
const fn = $iTyic$radixuireactusecallbackref.useCallbackRef(callback);
|
|
646
|
+
$iTyic$radixuireactuselayouteffect.useLayoutEffect(()=>{
|
|
647
|
+
let raf1 = 0;
|
|
648
|
+
let raf2 = 0;
|
|
649
|
+
raf1 = window.requestAnimationFrame(()=>raf2 = window.requestAnimationFrame(fn)
|
|
650
|
+
);
|
|
651
|
+
return ()=>{
|
|
652
|
+
window.cancelAnimationFrame(raf1);
|
|
653
|
+
window.cancelAnimationFrame(raf2);
|
|
654
|
+
};
|
|
655
|
+
}, [
|
|
656
|
+
fn
|
|
657
|
+
]);
|
|
658
|
+
}
|
|
659
|
+
function $9208a85b3e79d33f$var$getAnnounceTextContent(container) {
|
|
660
|
+
const textContent = [];
|
|
661
|
+
const childNodes = Array.from(container.childNodes);
|
|
662
|
+
childNodes.forEach((node)=>{
|
|
663
|
+
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
|
|
664
|
+
if ($9208a85b3e79d33f$var$isHTMLElement(node)) {
|
|
665
|
+
const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none';
|
|
666
|
+
if (!isHidden) textContent.push(...$9208a85b3e79d33f$var$getAnnounceTextContent(node));
|
|
667
|
+
}
|
|
668
|
+
}); // We return a collection of text rather than a single concatenated string.
|
|
669
|
+
// This allows SR VO to naturally pause break between nodes while announcing.
|
|
670
|
+
return textContent;
|
|
671
|
+
}
|
|
672
|
+
function $9208a85b3e79d33f$var$isHTMLElement(node) {
|
|
673
|
+
return node.nodeType === node.ELEMENT_NODE;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Returns a list of potential tabbable candidates.
|
|
677
|
+
*
|
|
678
|
+
* NOTE: This is only a close approximation. For example it doesn't take into account cases like when
|
|
679
|
+
* elements are not visible. This cannot be worked out easily by just reading a property, but rather
|
|
680
|
+
* necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
|
|
681
|
+
*
|
|
682
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
|
|
683
|
+
* Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
|
|
684
|
+
*/ function $9208a85b3e79d33f$var$getTabbableCandidates(container) {
|
|
685
|
+
const nodes = [];
|
|
686
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
687
|
+
acceptNode: (node)=>{
|
|
688
|
+
const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
|
|
689
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP; // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
|
|
690
|
+
// runtime's understanding of tabbability, so this automatically accounts
|
|
691
|
+
// for any kind of element that could be tabbed to.
|
|
692
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
while(walker.nextNode())nodes.push(walker.currentNode); // we do not take into account the order of nodes with positive `tabIndex` as it
|
|
696
|
+
// hinders accessibility to have tab order different from visual order.
|
|
697
|
+
return nodes;
|
|
698
|
+
}
|
|
699
|
+
function $9208a85b3e79d33f$var$focusFirst(candidates) {
|
|
700
|
+
const previouslyFocusedElement = document.activeElement;
|
|
701
|
+
return candidates.some((candidate)=>{
|
|
702
|
+
// if focus is already where we want to go, we don't want to keep going through the candidates
|
|
703
|
+
if (candidate === previouslyFocusedElement) return true;
|
|
704
|
+
candidate.focus();
|
|
705
|
+
return document.activeElement !== previouslyFocusedElement;
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
const $9208a85b3e79d33f$export$2881499e37b75b9a = $9208a85b3e79d33f$export$f5d03d415824e0e;
|
|
709
|
+
const $9208a85b3e79d33f$export$d5c6c08dc2d3ca7 = $9208a85b3e79d33f$export$6192c2425ecfd989;
|
|
710
|
+
const $9208a85b3e79d33f$export$be92b6f5f03c0fe9 = $9208a85b3e79d33f$export$8d8dc7d5f743331b;
|
|
711
|
+
const $9208a85b3e79d33f$export$f99233281efd08a0 = $9208a85b3e79d33f$export$16d42d7c29b95a4;
|
|
712
|
+
const $9208a85b3e79d33f$export$393edc798c47379d = $9208a85b3e79d33f$export$ecddd96c53621d9a;
|
|
713
|
+
const $9208a85b3e79d33f$export$e19cd5f9376f8cee = $9208a85b3e79d33f$export$3019feecfda683d2;
|
|
714
|
+
const $9208a85b3e79d33f$export$f39c2d165cd861fe = $9208a85b3e79d33f$export$811e70f61c205839;
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
2
719
|
//# sourceMappingURL=index.js.map
|