@tamagui/toast 1.7.11 → 1.8.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/cjs/Toast.js +95 -543
- package/dist/cjs/Toast.js.map +3 -3
- package/dist/cjs/ToastAnnounce.js +93 -0
- package/dist/cjs/ToastAnnounce.js.map +7 -0
- package/dist/cjs/ToastImpl.js +354 -0
- package/dist/cjs/ToastImpl.js.map +7 -0
- package/dist/cjs/ToastProvider.js +109 -0
- package/dist/cjs/ToastProvider.js.map +7 -0
- package/dist/cjs/ToastViewport.js +307 -0
- package/dist/cjs/ToastViewport.js.map +7 -0
- package/dist/cjs/constants.js +29 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/createNativeToast.js +49 -0
- package/dist/cjs/createNativeToast.js.map +7 -0
- package/dist/cjs/createNativeToast.native.js +37 -0
- package/dist/cjs/createNativeToast.native.js.map +7 -0
- package/dist/cjs/createToast.js +88 -0
- package/dist/cjs/createToast.js.map +7 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/Toast.js +101 -531
- package/dist/esm/Toast.js.map +3 -3
- package/dist/esm/Toast.mjs +101 -531
- package/dist/esm/Toast.mjs.map +3 -3
- package/dist/esm/ToastAnnounce.js +64 -0
- package/dist/esm/ToastAnnounce.js.map +7 -0
- package/dist/esm/ToastAnnounce.mjs +64 -0
- package/dist/esm/ToastAnnounce.mjs.map +7 -0
- package/dist/esm/ToastImpl.js +330 -0
- package/dist/esm/ToastImpl.js.map +7 -0
- package/dist/esm/ToastImpl.mjs +330 -0
- package/dist/esm/ToastImpl.mjs.map +7 -0
- package/dist/esm/ToastProvider.js +70 -0
- package/dist/esm/ToastProvider.js.map +7 -0
- package/dist/esm/ToastProvider.mjs +70 -0
- package/dist/esm/ToastProvider.mjs.map +7 -0
- package/dist/esm/ToastViewport.js +274 -0
- package/dist/esm/ToastViewport.js.map +7 -0
- package/dist/esm/ToastViewport.mjs +274 -0
- package/dist/esm/ToastViewport.mjs.map +7 -0
- package/dist/esm/constants.js +5 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/constants.mjs +5 -0
- package/dist/esm/constants.mjs.map +7 -0
- package/dist/esm/createNativeToast.js +25 -0
- package/dist/esm/createNativeToast.js.map +7 -0
- package/dist/esm/createNativeToast.mjs +25 -0
- package/dist/esm/createNativeToast.mjs.map +7 -0
- package/dist/esm/createNativeToast.native.js +13 -0
- package/dist/esm/createNativeToast.native.js.map +7 -0
- package/dist/esm/createNativeToast.native.mjs +13 -0
- package/dist/esm/createNativeToast.native.mjs.map +7 -0
- package/dist/esm/createToast.js +54 -0
- package/dist/esm/createToast.js.map +7 -0
- package/dist/esm/createToast.mjs +54 -0
- package/dist/esm/createToast.mjs.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/types.mjs +1 -0
- package/dist/esm/types.mjs.map +7 -0
- package/dist/jsx/Toast.js +97 -509
- package/dist/jsx/Toast.js.map +3 -3
- package/dist/jsx/Toast.mjs +97 -509
- package/dist/jsx/Toast.mjs.map +3 -3
- package/dist/jsx/ToastAnnounce.js +60 -0
- package/dist/jsx/ToastAnnounce.js.map +7 -0
- package/dist/jsx/ToastAnnounce.mjs +60 -0
- package/dist/jsx/ToastAnnounce.mjs.map +7 -0
- package/dist/jsx/ToastImpl.js +309 -0
- package/dist/jsx/ToastImpl.js.map +7 -0
- package/dist/jsx/ToastImpl.mjs +309 -0
- package/dist/jsx/ToastImpl.mjs.map +7 -0
- package/dist/jsx/ToastProvider.js +65 -0
- package/dist/jsx/ToastProvider.js.map +7 -0
- package/dist/jsx/ToastProvider.mjs +65 -0
- package/dist/jsx/ToastProvider.mjs.map +7 -0
- package/dist/jsx/ToastViewport.js +254 -0
- package/dist/jsx/ToastViewport.js.map +7 -0
- package/dist/jsx/ToastViewport.mjs +254 -0
- package/dist/jsx/ToastViewport.mjs.map +7 -0
- package/dist/jsx/constants.js +5 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/constants.mjs +5 -0
- package/dist/jsx/constants.mjs.map +7 -0
- package/dist/jsx/createNativeToast.js +25 -0
- package/dist/jsx/createNativeToast.js.map +7 -0
- package/dist/jsx/createNativeToast.mjs +25 -0
- package/dist/jsx/createNativeToast.mjs.map +7 -0
- package/dist/jsx/createNativeToast.native.js +13 -0
- package/dist/jsx/createNativeToast.native.js.map +7 -0
- package/dist/jsx/createNativeToast.native.mjs +13 -0
- package/dist/jsx/createNativeToast.native.mjs.map +7 -0
- package/dist/jsx/createToast.js +49 -0
- package/dist/jsx/createToast.js.map +7 -0
- package/dist/jsx/createToast.mjs +49 -0
- package/dist/jsx/createToast.mjs.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/dist/jsx/types.mjs +1 -0
- package/dist/jsx/types.mjs.map +7 -0
- package/package.json +14 -13
- package/src/Toast.tsx +139 -908
- package/src/ToastAnnounce.tsx +97 -0
- package/src/ToastImpl.tsx +439 -0
- package/src/ToastProvider.tsx +134 -0
- package/src/ToastViewport.tsx +354 -0
- package/src/constants.ts +1 -0
- package/src/createNativeToast.native.tsx +16 -0
- package/src/createNativeToast.tsx +25 -0
- package/src/createToast.tsx +93 -0
- package/src/types.ts +21 -0
- package/types/Toast.d.ts +429 -106
- package/types/Toast.d.ts.map +1 -1
- package/types/ToastAnnounce.d.ts +35 -0
- package/types/ToastAnnounce.d.ts.map +1 -0
- package/types/ToastImpl.d.ts +267 -0
- package/types/ToastImpl.d.ts.map +1 -0
- package/types/ToastProvider.d.ts +80 -0
- package/types/ToastProvider.d.ts.map +1 -0
- package/types/ToastViewport.d.ts +115 -0
- package/types/ToastViewport.d.ts.map +1 -0
- package/types/constants.d.ts +2 -0
- package/types/constants.d.ts.map +1 -0
- package/types/createNativeToast.d.ts +3 -0
- package/types/createNativeToast.d.ts.map +1 -0
- package/types/createNativeToast.native.d.ts +3 -0
- package/types/createNativeToast.native.d.ts.map +1 -0
- package/types/createToast.d.ts +42 -0
- package/types/createToast.d.ts.map +1 -0
- package/types/types.d.ts +17 -0
- package/types/types.d.ts.map +1 -0
package/dist/cjs/Toast.js
CHANGED
|
@@ -28,477 +28,76 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var Toast_exports = {};
|
|
30
30
|
__export(Toast_exports, {
|
|
31
|
-
Action: () => Action,
|
|
32
|
-
Close: () => Close,
|
|
33
|
-
Description: () => Description,
|
|
34
|
-
Provider: () => Provider,
|
|
35
|
-
Root: () => Root,
|
|
36
|
-
Title: () => Title,
|
|
37
31
|
Toast: () => Toast,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ToastTitle: () => ToastTitle,
|
|
43
|
-
ToastViewport: () => ToastViewport,
|
|
44
|
-
Viewport: () => Viewport
|
|
32
|
+
ToastProvider: () => import_ToastProvider.ToastProvider,
|
|
33
|
+
ToastViewport: () => import_ToastViewport.ToastViewport,
|
|
34
|
+
createToast: () => import_createToast.createToast,
|
|
35
|
+
createToastScope: () => import_ToastProvider.createToastScope
|
|
45
36
|
});
|
|
46
37
|
module.exports = __toCommonJS(Toast_exports);
|
|
47
|
-
var import_jsx_runtime = (
|
|
48
|
-
// <Collection.Provider scope={__scopeToast}>
|
|
49
|
-
require("react/jsx-runtime")
|
|
50
|
-
);
|
|
51
|
-
var import_compose_refs = require("@tamagui/compose-refs");
|
|
38
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
39
|
var import_core = require("@tamagui/core");
|
|
53
|
-
var import_portal = require("@tamagui/portal");
|
|
54
40
|
var import_stacks = require("@tamagui/stacks");
|
|
41
|
+
var import_text = require("@tamagui/text");
|
|
55
42
|
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
56
|
-
var import_visually_hidden = require("@tamagui/visually-hidden");
|
|
57
43
|
var React = __toESM(require("react"));
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const isFocusedToastEscapeKeyDownRef = React.useRef(false);
|
|
73
|
-
const isClosePausedRef = React.useRef(false);
|
|
74
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
75
|
-
ToastProviderProvider,
|
|
76
|
-
{
|
|
77
|
-
scope: __scopeToast,
|
|
78
|
-
label,
|
|
79
|
-
duration,
|
|
80
|
-
swipeDirection,
|
|
81
|
-
swipeThreshold,
|
|
82
|
-
toastCount,
|
|
83
|
-
viewport,
|
|
84
|
-
onViewportChange: setViewport,
|
|
85
|
-
onToastAdd: React.useCallback(
|
|
86
|
-
() => setToastCount((prevCount) => prevCount + 1),
|
|
87
|
-
[]
|
|
88
|
-
),
|
|
89
|
-
onToastRemove: React.useCallback(
|
|
90
|
-
() => setToastCount((prevCount) => prevCount - 1),
|
|
91
|
-
[]
|
|
92
|
-
),
|
|
93
|
-
isFocusedToastEscapeKeyDownRef,
|
|
94
|
-
isClosePausedRef,
|
|
95
|
-
children
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
ToastProvider.propTypes = {
|
|
100
|
-
label(props) {
|
|
101
|
-
if (props.label && typeof props.label === "string" && !props.label.trim()) {
|
|
102
|
-
const error = `Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
|
|
103
|
-
return new Error(error);
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
ToastProvider.displayName = PROVIDER_NAME;
|
|
109
|
-
const VIEWPORT_NAME = "ToastViewport";
|
|
110
|
-
const VIEWPORT_DEFAULT_HOTKEY = ["F8"];
|
|
111
|
-
const VIEWPORT_PAUSE = "toast.viewportPause";
|
|
112
|
-
const VIEWPORT_RESUME = "toast.viewportResume";
|
|
113
|
-
const ToastViewport = React.forwardRef(
|
|
114
|
-
(props, forwardedRef) => {
|
|
115
|
-
const {
|
|
116
|
-
__scopeToast,
|
|
117
|
-
hotkey = VIEWPORT_DEFAULT_HOTKEY,
|
|
118
|
-
label = "Notifications ({hotkey})",
|
|
119
|
-
...viewportProps
|
|
120
|
-
} = props;
|
|
121
|
-
const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast);
|
|
122
|
-
const wrapperRef = React.useRef(null);
|
|
123
|
-
const headFocusProxyRef = React.useRef(null);
|
|
124
|
-
const tailFocusProxyRef = React.useRef(null);
|
|
125
|
-
const ref = React.useRef(null);
|
|
126
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, context.onViewportChange);
|
|
127
|
-
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
|
|
128
|
-
const hasToasts = context.toastCount > 0;
|
|
129
|
-
React.useEffect(() => {
|
|
130
|
-
const handleKeyDown = (event) => {
|
|
131
|
-
var _a;
|
|
132
|
-
const isHotkeyPressed = hotkey.every(
|
|
133
|
-
(key) => event[key] || event.code === key
|
|
134
|
-
);
|
|
135
|
-
if (isHotkeyPressed)
|
|
136
|
-
(_a = ref.current) == null ? void 0 : _a.focus();
|
|
137
|
-
};
|
|
138
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
139
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
140
|
-
}, [hotkey]);
|
|
141
|
-
React.useEffect(() => {
|
|
142
|
-
const wrapper = wrapperRef.current;
|
|
143
|
-
const viewport = ref.current;
|
|
144
|
-
if (wrapper && viewport) {
|
|
145
|
-
const handlePause = () => {
|
|
146
|
-
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
|
|
147
|
-
context.isClosePausedRef.current = true;
|
|
148
|
-
};
|
|
149
|
-
const handleResume = () => {
|
|
150
|
-
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
|
|
151
|
-
context.isClosePausedRef.current = false;
|
|
152
|
-
};
|
|
153
|
-
wrapper.addEventListener("focusin", handlePause);
|
|
154
|
-
wrapper.addEventListener("focusout", handleResume);
|
|
155
|
-
wrapper.addEventListener("pointerenter", handlePause);
|
|
156
|
-
wrapper.addEventListener("pointerleave", handleResume);
|
|
157
|
-
window.addEventListener("blur", handlePause);
|
|
158
|
-
window.addEventListener("focus", handleResume);
|
|
159
|
-
return () => {
|
|
160
|
-
wrapper.removeEventListener("focusin", handlePause);
|
|
161
|
-
wrapper.removeEventListener("focusout", handleResume);
|
|
162
|
-
wrapper.removeEventListener("pointerenter", handlePause);
|
|
163
|
-
wrapper.removeEventListener("pointerleave", handleResume);
|
|
164
|
-
window.removeEventListener("blur", handlePause);
|
|
165
|
-
window.removeEventListener("focus", handleResume);
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}, [context.isClosePausedRef]);
|
|
169
|
-
React.useEffect(
|
|
170
|
-
() => {
|
|
171
|
-
const viewport = ref.current;
|
|
172
|
-
if (viewport) {
|
|
173
|
-
const handleKeyDown = (event) => {
|
|
174
|
-
var _a;
|
|
175
|
-
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
176
|
-
const isTabKey = event.key === "Tab" && !isMetaKey;
|
|
177
|
-
if (isTabKey) {
|
|
178
|
-
const focusedElement = document.activeElement;
|
|
179
|
-
const isTabbingBackwards = event.shiftKey;
|
|
180
|
-
const targetIsViewport = event.target === viewport;
|
|
181
|
-
if (targetIsViewport && isTabbingBackwards) {
|
|
182
|
-
(_a = headFocusProxyRef.current) == null ? void 0 : _a.focus();
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
return () => {
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
[
|
|
193
|
-
// getItems, getSortedTabbableCandidates
|
|
194
|
-
]
|
|
195
|
-
);
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
);
|
|
199
|
-
ToastViewport.displayName = VIEWPORT_NAME;
|
|
200
|
-
const FOCUS_PROXY_NAME = "ToastFocusProxy";
|
|
201
|
-
const FocusProxy = React.forwardRef(
|
|
202
|
-
(props, forwardedRef) => {
|
|
203
|
-
const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props;
|
|
204
|
-
const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast);
|
|
205
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
206
|
-
import_visually_hidden.VisuallyHidden,
|
|
207
|
-
{
|
|
208
|
-
"aria-hidden": true,
|
|
209
|
-
tabIndex: 0,
|
|
210
|
-
...proxyProps,
|
|
211
|
-
ref: forwardedRef,
|
|
212
|
-
position: import_core.isWeb ? "fixed" : "absolute",
|
|
213
|
-
onFocus: (event) => {
|
|
214
|
-
var _a;
|
|
215
|
-
const prevFocusedElement = event.relatedTarget;
|
|
216
|
-
const isFocusFromOutsideViewport = !((_a = context.viewport) == null ? void 0 : _a.contains(prevFocusedElement));
|
|
217
|
-
if (isFocusFromOutsideViewport)
|
|
218
|
-
onFocusFromOutsideViewport();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
);
|
|
224
|
-
FocusProxy.displayName = FOCUS_PROXY_NAME;
|
|
225
|
-
const TOAST_NAME = "Toast";
|
|
226
|
-
const TOAST_SWIPE_START = "toast.swipeStart";
|
|
227
|
-
const TOAST_SWIPE_MOVE = "toast.swipeMove";
|
|
228
|
-
const TOAST_SWIPE_CANCEL = "toast.swipeCancel";
|
|
229
|
-
const TOAST_SWIPE_END = "toast.swipeEnd";
|
|
230
|
-
const Toast = React.forwardRef(
|
|
231
|
-
(props, forwardedRef) => {
|
|
232
|
-
const {
|
|
233
|
-
forceMount,
|
|
234
|
-
open: openProp,
|
|
235
|
-
defaultOpen,
|
|
236
|
-
onOpenChange,
|
|
237
|
-
...toastProps
|
|
238
|
-
} = props;
|
|
239
|
-
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
240
|
-
prop: openProp,
|
|
241
|
-
defaultProp: true,
|
|
242
|
-
onChange: onOpenChange,
|
|
243
|
-
transition: true
|
|
244
|
-
});
|
|
245
|
-
return (
|
|
246
|
-
// <Presence present={forceMount || open}>
|
|
247
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
248
|
-
ToastImpl,
|
|
249
|
-
{
|
|
250
|
-
open,
|
|
251
|
-
...toastProps,
|
|
252
|
-
ref: forwardedRef,
|
|
253
|
-
onClose: () => setOpen(false)
|
|
254
|
-
}
|
|
255
|
-
)
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
);
|
|
259
|
-
Toast.displayName = TOAST_NAME;
|
|
260
|
-
const [ToastInteractiveProvider, useToastInteractiveContext] = {};
|
|
261
|
-
const ToastImpl = React.forwardRef(
|
|
262
|
-
(props, forwardedRef) => {
|
|
263
|
-
const {
|
|
264
|
-
__scopeToast,
|
|
265
|
-
type = "foreground",
|
|
266
|
-
duration: durationProp,
|
|
267
|
-
open,
|
|
268
|
-
onClose,
|
|
269
|
-
onEscapeKeyDown,
|
|
270
|
-
onSwipeStart,
|
|
271
|
-
onSwipeMove,
|
|
272
|
-
onSwipeCancel,
|
|
273
|
-
onSwipeEnd,
|
|
274
|
-
...toastProps
|
|
275
|
-
} = props;
|
|
276
|
-
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
277
|
-
const ref = React.useRef(null);
|
|
278
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
279
|
-
const pointerStartRef = React.useRef(null);
|
|
280
|
-
const swipeDeltaRef = React.useRef(null);
|
|
281
|
-
const duration = durationProp || context.duration;
|
|
282
|
-
const closeTimerStartTimeRef = React.useRef(0);
|
|
283
|
-
const closeTimerRemainingTimeRef = React.useRef(duration);
|
|
284
|
-
const closeTimerRef = React.useRef(0);
|
|
285
|
-
const { onToastAdd, onToastRemove } = context;
|
|
286
|
-
const handleClose = (0, import_core.useEvent)(() => {
|
|
287
|
-
onClose();
|
|
288
|
-
});
|
|
289
|
-
const startTimer = React.useCallback(
|
|
290
|
-
(duration2) => {
|
|
291
|
-
if (!duration2 || duration2 === Infinity)
|
|
292
|
-
return;
|
|
293
|
-
window.clearTimeout(closeTimerRef.current);
|
|
294
|
-
closeTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
|
|
295
|
-
closeTimerRef.current = window.setTimeout(handleClose, duration2);
|
|
296
|
-
},
|
|
297
|
-
[handleClose]
|
|
298
|
-
);
|
|
299
|
-
React.useEffect(() => {
|
|
300
|
-
const viewport = context.viewport;
|
|
301
|
-
if (viewport) {
|
|
302
|
-
const handleResume = () => {
|
|
303
|
-
startTimer(closeTimerRemainingTimeRef.current);
|
|
304
|
-
};
|
|
305
|
-
const handlePause = () => {
|
|
306
|
-
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef.current;
|
|
307
|
-
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
308
|
-
window.clearTimeout(closeTimerRef.current);
|
|
309
|
-
};
|
|
310
|
-
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
|
|
311
|
-
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
|
|
312
|
-
return () => {
|
|
313
|
-
viewport.removeEventListener(VIEWPORT_PAUSE, handlePause);
|
|
314
|
-
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
|
|
315
|
-
};
|
|
44
|
+
var import_constants = require("./constants");
|
|
45
|
+
var import_createToast = require("./createToast");
|
|
46
|
+
var import_ToastAnnounce = require("./ToastAnnounce");
|
|
47
|
+
var import_ToastImpl = require("./ToastImpl");
|
|
48
|
+
var import_ToastProvider = require("./ToastProvider");
|
|
49
|
+
var import_ToastViewport = require("./ToastViewport");
|
|
50
|
+
const TITLE_NAME = "ToastTitle";
|
|
51
|
+
const ToastTitleFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
52
|
+
name: TITLE_NAME,
|
|
53
|
+
color: "$color",
|
|
54
|
+
variants: {
|
|
55
|
+
unstyled: {
|
|
56
|
+
false: {
|
|
57
|
+
size: "$4"
|
|
316
58
|
}
|
|
317
|
-
}, [context.viewport, duration, startTimer]);
|
|
318
|
-
React.useEffect(() => {
|
|
319
|
-
if (open && !context.isClosePausedRef.current)
|
|
320
|
-
startTimer(duration);
|
|
321
|
-
}, [open, duration, context.isClosePausedRef, startTimer]);
|
|
322
|
-
React.useEffect(() => {
|
|
323
|
-
onToastAdd();
|
|
324
|
-
return () => onToastRemove();
|
|
325
|
-
}, [onToastAdd, onToastRemove]);
|
|
326
|
-
if (!context.viewport)
|
|
327
|
-
return null;
|
|
328
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
329
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
330
|
-
ToastAnnounce,
|
|
331
|
-
{
|
|
332
|
-
__scopeToast,
|
|
333
|
-
role: "status",
|
|
334
|
-
"aria-live": type === "foreground" ? "assertive" : "polite",
|
|
335
|
-
"aria-atomic": true,
|
|
336
|
-
children: props.children
|
|
337
|
-
}
|
|
338
|
-
),
|
|
339
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
340
|
-
ToastInteractiveProvider,
|
|
341
|
-
{
|
|
342
|
-
scope: __scopeToast,
|
|
343
|
-
isInteractive: true,
|
|
344
|
-
onClose: handleClose,
|
|
345
|
-
children: ReactDOM.createPortal(
|
|
346
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {}),
|
|
347
|
-
// <Collection.ItemSlot scope={__scopeToast}>
|
|
348
|
-
// <DismissableLayer.Root
|
|
349
|
-
// asChild
|
|
350
|
-
// onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {
|
|
351
|
-
// if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose()
|
|
352
|
-
// context.isFocusedToastEscapeKeyDownRef.current = false
|
|
353
|
-
// })}
|
|
354
|
-
// >
|
|
355
|
-
// <Primitive.li
|
|
356
|
-
// // Ensure toasts are announced as status list or status when focused
|
|
357
|
-
// role="status"
|
|
358
|
-
// aria-live="off"
|
|
359
|
-
// aria-atomic
|
|
360
|
-
// tabIndex={0}
|
|
361
|
-
// data-state={open ? 'open' : 'closed'}
|
|
362
|
-
// data-swipe-direction={context.swipeDirection}
|
|
363
|
-
// {...toastProps}
|
|
364
|
-
// ref={composedRefs}
|
|
365
|
-
// style={{ userSelect: 'none', touchAction: 'none', ...props.style }}
|
|
366
|
-
// onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {
|
|
367
|
-
// if (event.key !== 'Escape') return
|
|
368
|
-
// onEscapeKeyDown?.(event.nativeEvent)
|
|
369
|
-
// if (!event.nativeEvent.defaultPrevented) {
|
|
370
|
-
// context.isFocusedToastEscapeKeyDownRef.current = true
|
|
371
|
-
// handleClose()
|
|
372
|
-
// }
|
|
373
|
-
// })}
|
|
374
|
-
// onPointerDown={composeEventHandlers(props.onPointerDown, (event) => {
|
|
375
|
-
// if (event.button !== 0) return
|
|
376
|
-
// pointerStartRef.current = { x: event.clientX, y: event.clientY }
|
|
377
|
-
// })}
|
|
378
|
-
// onPointerMove={composeEventHandlers(props.onPointerMove, (event) => {
|
|
379
|
-
// if (!pointerStartRef.current) return
|
|
380
|
-
// const x = event.clientX - pointerStartRef.current.x
|
|
381
|
-
// const y = event.clientY - pointerStartRef.current.y
|
|
382
|
-
// const hasSwipeMoveStarted = Boolean(swipeDeltaRef.current)
|
|
383
|
-
// const isHorizontalSwipe = ['left', 'right'].includes(context.swipeDirection)
|
|
384
|
-
// const clamp = ['left', 'up'].includes(context.swipeDirection)
|
|
385
|
-
// ? Math.min
|
|
386
|
-
// : Math.max
|
|
387
|
-
// const clampedX = isHorizontalSwipe ? clamp(0, x) : 0
|
|
388
|
-
// const clampedY = !isHorizontalSwipe ? clamp(0, y) : 0
|
|
389
|
-
// const moveStartBuffer = event.pointerType === 'touch' ? 10 : 2
|
|
390
|
-
// const delta = { x: clampedX, y: clampedY }
|
|
391
|
-
// const eventDetail = { originalEvent: event, delta }
|
|
392
|
-
// if (hasSwipeMoveStarted) {
|
|
393
|
-
// swipeDeltaRef.current = delta
|
|
394
|
-
// handleAndDispatchCustomEvent(TOAST_SWIPE_MOVE, onSwipeMove, eventDetail, {
|
|
395
|
-
// discrete: false,
|
|
396
|
-
// })
|
|
397
|
-
// } else if (isDeltaInDirection(delta, context.swipeDirection, moveStartBuffer)) {
|
|
398
|
-
// swipeDeltaRef.current = delta
|
|
399
|
-
// handleAndDispatchCustomEvent(TOAST_SWIPE_START, onSwipeStart, eventDetail, {
|
|
400
|
-
// discrete: false,
|
|
401
|
-
// })
|
|
402
|
-
// ;(event.target as HTMLElement).setPointerCapture(event.pointerId)
|
|
403
|
-
// } else if (Math.abs(x) > moveStartBuffer || Math.abs(y) > moveStartBuffer) {
|
|
404
|
-
// // User is swiping in wrong direction so we disable swipe gesture
|
|
405
|
-
// // for the current pointer down interaction
|
|
406
|
-
// pointerStartRef.current = null
|
|
407
|
-
// }
|
|
408
|
-
// })}
|
|
409
|
-
// onPointerUp={composeEventHandlers(props.onPointerUp, (event) => {
|
|
410
|
-
// const delta = swipeDeltaRef.current
|
|
411
|
-
// ;(event.target as HTMLElement).releasePointerCapture(event.pointerId)
|
|
412
|
-
// swipeDeltaRef.current = null
|
|
413
|
-
// pointerStartRef.current = null
|
|
414
|
-
// if (delta) {
|
|
415
|
-
// const toast = event.currentTarget
|
|
416
|
-
// const eventDetail = { originalEvent: event, delta }
|
|
417
|
-
// if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {
|
|
418
|
-
// handleAndDispatchCustomEvent(TOAST_SWIPE_END, onSwipeEnd, eventDetail, {
|
|
419
|
-
// discrete: true,
|
|
420
|
-
// })
|
|
421
|
-
// } else {
|
|
422
|
-
// handleAndDispatchCustomEvent(TOAST_SWIPE_CANCEL, onSwipeCancel, eventDetail, {
|
|
423
|
-
// discrete: true,
|
|
424
|
-
// })
|
|
425
|
-
// }
|
|
426
|
-
// // Prevent click event from triggering on items within the toast when
|
|
427
|
-
// // pointer up is part of a swipe gesture
|
|
428
|
-
// toast.addEventListener('click', (event) => event.preventDefault(), {
|
|
429
|
-
// once: true,
|
|
430
|
-
// })
|
|
431
|
-
// }
|
|
432
|
-
// })}
|
|
433
|
-
// />
|
|
434
|
-
// </DismissableLayer.Root>,
|
|
435
|
-
// </Collection.ItemSlot>,
|
|
436
|
-
context.viewport
|
|
437
|
-
)
|
|
438
|
-
}
|
|
439
|
-
)
|
|
440
|
-
] });
|
|
441
|
-
}
|
|
442
|
-
);
|
|
443
|
-
ToastImpl.propTypes = {
|
|
444
|
-
type(props) {
|
|
445
|
-
if (props.type && !["foreground", "background"].includes(props.type)) {
|
|
446
|
-
const error = `Invalid prop \`type\` supplied to \`${TOAST_NAME}\`. Expected \`foreground | background\`.`;
|
|
447
|
-
return new Error(error);
|
|
448
59
|
}
|
|
449
|
-
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: {
|
|
62
|
+
unstyled: false
|
|
450
63
|
}
|
|
451
|
-
};
|
|
452
|
-
const ToastAnnounce = (props) => {
|
|
453
|
-
const { __scopeToast, children, ...announceProps } = props;
|
|
454
|
-
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
455
|
-
const [renderAnnounceText, setRenderAnnounceText] = React.useState(false);
|
|
456
|
-
const [isAnnounced, setIsAnnounced] = React.useState(false);
|
|
457
|
-
const [fragment, setFragment] = React.useState();
|
|
458
|
-
const [rootFragmentNode, setRootFragmentNode] = React.useState(null);
|
|
459
|
-
const announceTextContent = React.useMemo(() => {
|
|
460
|
-
return rootFragmentNode ? getAnnounceTextContent(rootFragmentNode) : null;
|
|
461
|
-
}, [rootFragmentNode]);
|
|
462
|
-
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
463
|
-
setFragment(new DocumentFragment());
|
|
464
|
-
}, []);
|
|
465
|
-
useNextFrame(() => setRenderAnnounceText(true));
|
|
466
|
-
React.useEffect(() => {
|
|
467
|
-
const timer = window.setTimeout(() => setIsAnnounced(true), 1e3);
|
|
468
|
-
return () => window.clearTimeout(timer);
|
|
469
|
-
}, []);
|
|
470
|
-
return isAnnounced ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
471
|
-
fragment && // @ts-ignore
|
|
472
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_portal.Portal, { container: fragment, ref: setRootFragmentNode, children: [
|
|
473
|
-
context.label,
|
|
474
|
-
" ",
|
|
475
|
-
children
|
|
476
|
-
] }),
|
|
477
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.Portal, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_visually_hidden.VisuallyHidden, { ...announceProps, children: renderAnnounceText && announceTextContent }) })
|
|
478
|
-
] });
|
|
479
|
-
};
|
|
480
|
-
const TITLE_NAME = "ToastTitle";
|
|
64
|
+
});
|
|
481
65
|
const ToastTitle = React.forwardRef(
|
|
482
66
|
(props, forwardedRef) => {
|
|
483
67
|
const { __scopeToast, ...titleProps } = props;
|
|
484
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastTitleFrame, { ...titleProps, ref: forwardedRef });
|
|
485
69
|
}
|
|
486
70
|
);
|
|
487
71
|
ToastTitle.displayName = TITLE_NAME;
|
|
488
72
|
const DESCRIPTION_NAME = "ToastDescription";
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
73
|
+
const ToastDescriptionFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
74
|
+
name: DESCRIPTION_NAME,
|
|
75
|
+
color: "$color11",
|
|
76
|
+
variants: {
|
|
77
|
+
unstyled: {
|
|
78
|
+
false: {
|
|
79
|
+
size: "$1"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
defaultVariants: {
|
|
84
|
+
unstyled: false
|
|
85
|
+
}
|
|
492
86
|
});
|
|
87
|
+
const ToastDescription = React.forwardRef(
|
|
88
|
+
(props, forwardedRef) => {
|
|
89
|
+
const { __scopeToast, ...descriptionProps } = props;
|
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastDescriptionFrame, { ...descriptionProps, ref: forwardedRef });
|
|
91
|
+
}
|
|
92
|
+
);
|
|
493
93
|
ToastDescription.displayName = DESCRIPTION_NAME;
|
|
494
94
|
const ACTION_NAME = "ToastAction";
|
|
495
95
|
const ToastAction = React.forwardRef(
|
|
496
96
|
(props, forwardedRef) => {
|
|
497
97
|
const { altText, ...actionProps } = props;
|
|
498
|
-
const context = useToastInteractiveContext(ACTION_NAME, props.__scopeToast);
|
|
499
98
|
if (!altText)
|
|
500
99
|
return null;
|
|
501
|
-
return
|
|
100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounceExclude, { altText, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastClose, { ...actionProps, ref: forwardedRef }) });
|
|
502
101
|
}
|
|
503
102
|
);
|
|
504
103
|
ToastAction.propTypes = {
|
|
@@ -511,119 +110,72 @@ ToastAction.propTypes = {
|
|
|
511
110
|
};
|
|
512
111
|
ToastAction.displayName = ACTION_NAME;
|
|
513
112
|
const CLOSE_NAME = "ToastClose";
|
|
113
|
+
const ToastCloseFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
114
|
+
name: CLOSE_NAME,
|
|
115
|
+
tag: "button"
|
|
116
|
+
});
|
|
514
117
|
const ToastClose = React.forwardRef(
|
|
515
118
|
(props, forwardedRef) => {
|
|
516
119
|
const { __scopeToast, ...closeProps } = props;
|
|
517
|
-
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
|
|
518
|
-
return
|
|
519
|
-
|
|
120
|
+
const interactiveContext = (0, import_ToastImpl.useToastInteractiveContext)(CLOSE_NAME, __scopeToast);
|
|
121
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounceExclude, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
122
|
+
ToastCloseFrame,
|
|
520
123
|
{
|
|
521
|
-
|
|
124
|
+
accessibilityLabel: "Dialog Close",
|
|
522
125
|
...closeProps,
|
|
523
126
|
ref: forwardedRef,
|
|
524
127
|
onPress: (0, import_core.composeEventHandlers)(props.onPress, interactiveContext.onClose)
|
|
525
128
|
}
|
|
526
|
-
)
|
|
129
|
+
) });
|
|
527
130
|
}
|
|
528
131
|
);
|
|
529
132
|
ToastClose.displayName = CLOSE_NAME;
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
() => raf2 = window.requestAnimationFrame(fn)
|
|
133
|
+
const ToastComponent = React.forwardRef(
|
|
134
|
+
import_ToastImpl.ToastImplFrame.extractable((props, forwardedRef) => {
|
|
135
|
+
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
|
|
136
|
+
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
137
|
+
prop: openProp,
|
|
138
|
+
defaultProp: defaultOpen ?? true,
|
|
139
|
+
onChange: onOpenChange
|
|
140
|
+
});
|
|
141
|
+
const id = (0, import_core.useId)();
|
|
142
|
+
const onPause = (0, import_core.useEvent)(props.onPause);
|
|
143
|
+
const onResume = (0, import_core.useEvent)(props.onResume);
|
|
144
|
+
if (!forceMount && !open)
|
|
145
|
+
return null;
|
|
146
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
147
|
+
import_ToastImpl.ToastImpl,
|
|
148
|
+
{
|
|
149
|
+
id,
|
|
150
|
+
open,
|
|
151
|
+
...toastProps,
|
|
152
|
+
ref: forwardedRef,
|
|
153
|
+
onClose: () => setOpen(false),
|
|
154
|
+
onPause,
|
|
155
|
+
onResume,
|
|
156
|
+
onSwipeEnd: (0, import_core.composeEventHandlers)(props.onSwipeEnd, (event) => {
|
|
157
|
+
setOpen(false);
|
|
158
|
+
})
|
|
159
|
+
}
|
|
558
160
|
);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (isHTMLElement(node)) {
|
|
572
|
-
const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
|
|
573
|
-
if (!isHidden)
|
|
574
|
-
textContent.push(...getAnnounceTextContent(node));
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
return textContent;
|
|
578
|
-
}
|
|
579
|
-
function isHTMLElement(node) {
|
|
580
|
-
return node.nodeType === node.ELEMENT_NODE;
|
|
581
|
-
}
|
|
582
|
-
function getTabbableCandidates(container) {
|
|
583
|
-
const nodes = [];
|
|
584
|
-
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
585
|
-
acceptNode: (node) => {
|
|
586
|
-
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
587
|
-
if (node.disabled || node.hidden || isHiddenInput)
|
|
588
|
-
return NodeFilter.FILTER_SKIP;
|
|
589
|
-
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
while (walker.nextNode())
|
|
593
|
-
nodes.push(walker.currentNode);
|
|
594
|
-
return nodes;
|
|
595
|
-
}
|
|
596
|
-
function focusFirst(candidates) {
|
|
597
|
-
const previouslyFocusedElement = document.activeElement;
|
|
598
|
-
return candidates.some((candidate) => {
|
|
599
|
-
if (candidate === previouslyFocusedElement)
|
|
600
|
-
return true;
|
|
601
|
-
candidate.focus();
|
|
602
|
-
return document.activeElement !== previouslyFocusedElement;
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
const Provider = ToastProvider;
|
|
606
|
-
const Viewport = ToastViewport;
|
|
607
|
-
const Root = Toast;
|
|
608
|
-
const Title = ToastTitle;
|
|
609
|
-
const Description = ToastDescription;
|
|
610
|
-
const Action = ToastAction;
|
|
611
|
-
const Close = ToastClose;
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
ToastComponent.displayName = import_constants.TOAST_NAME;
|
|
164
|
+
const Toast = (0, import_core.withStaticProperties)(
|
|
165
|
+
(0, import_core.themeable)(ToastComponent, import_ToastImpl.ToastImplFrame.staticConfig),
|
|
166
|
+
{
|
|
167
|
+
Title: ToastTitle,
|
|
168
|
+
Description: ToastDescription,
|
|
169
|
+
Action: ToastAction,
|
|
170
|
+
Close: ToastClose
|
|
171
|
+
}
|
|
172
|
+
);
|
|
612
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
613
174
|
0 && (module.exports = {
|
|
614
|
-
Action,
|
|
615
|
-
Close,
|
|
616
|
-
Description,
|
|
617
|
-
Provider,
|
|
618
|
-
Root,
|
|
619
|
-
Title,
|
|
620
175
|
Toast,
|
|
621
|
-
ToastAction,
|
|
622
|
-
ToastClose,
|
|
623
|
-
ToastDescription,
|
|
624
176
|
ToastProvider,
|
|
625
|
-
ToastTitle,
|
|
626
177
|
ToastViewport,
|
|
627
|
-
|
|
178
|
+
createToast,
|
|
179
|
+
createToastScope
|
|
628
180
|
});
|
|
629
181
|
//# sourceMappingURL=Toast.js.map
|