@tamagui/toast 1.0.1-beta.151 → 1.0.1-beta.154
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 +276 -225
- package/dist/cjs/Toast.js.map +2 -2
- package/dist/esm/Toast.js +272 -224
- package/dist/esm/Toast.js.map +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Toast.js +204 -179
- package/dist/jsx/Toast.js.map +2 -2
- package/dist/jsx/index.js.map +1 -1
- package/package.json +13 -13
package/dist/esm/Toast.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
3
|
import {
|
|
3
4
|
composeEventHandlers,
|
|
@@ -26,7 +27,7 @@ const ToastProvider = (props) => {
|
|
|
26
27
|
const [toastCount, setToastCount] = React.useState(0);
|
|
27
28
|
const isFocusedToastEscapeKeyDownRef = React.useRef(false);
|
|
28
29
|
const isClosePausedRef = React.useRef(false);
|
|
29
|
-
return /* @__PURE__ */
|
|
30
|
+
return /* @__PURE__ */ jsx(ToastProviderProvider, {
|
|
30
31
|
scope: __scopeToast,
|
|
31
32
|
label,
|
|
32
33
|
duration,
|
|
@@ -38,8 +39,9 @@ const ToastProvider = (props) => {
|
|
|
38
39
|
onToastAdd: React.useCallback(() => setToastCount((prevCount) => prevCount + 1), []),
|
|
39
40
|
onToastRemove: React.useCallback(() => setToastCount((prevCount) => prevCount - 1), []),
|
|
40
41
|
isFocusedToastEscapeKeyDownRef,
|
|
41
|
-
isClosePausedRef
|
|
42
|
-
|
|
42
|
+
isClosePausedRef,
|
|
43
|
+
children
|
|
44
|
+
});
|
|
43
45
|
};
|
|
44
46
|
ToastProvider.propTypes = {
|
|
45
47
|
label(props) {
|
|
@@ -55,199 +57,223 @@ const VIEWPORT_NAME = "ToastViewport";
|
|
|
55
57
|
const VIEWPORT_DEFAULT_HOTKEY = ["F8"];
|
|
56
58
|
const VIEWPORT_PAUSE = "toast.viewportPause";
|
|
57
59
|
const VIEWPORT_RESUME = "toast.viewportResume";
|
|
58
|
-
const ToastViewport = React.forwardRef(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var _a;
|
|
76
|
-
const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
|
|
77
|
-
if (isHotkeyPressed)
|
|
78
|
-
(_a = ref.current) == null ? void 0 : _a.focus();
|
|
79
|
-
};
|
|
80
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
81
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
82
|
-
}, [hotkey]);
|
|
83
|
-
React.useEffect(() => {
|
|
84
|
-
const wrapper = wrapperRef.current;
|
|
85
|
-
const viewport = ref.current;
|
|
86
|
-
if (wrapper && viewport) {
|
|
87
|
-
const handlePause = () => {
|
|
88
|
-
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
|
|
89
|
-
context.isClosePausedRef.current = true;
|
|
90
|
-
};
|
|
91
|
-
const handleResume = () => {
|
|
92
|
-
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
|
|
93
|
-
context.isClosePausedRef.current = false;
|
|
94
|
-
};
|
|
95
|
-
wrapper.addEventListener("focusin", handlePause);
|
|
96
|
-
wrapper.addEventListener("focusout", handleResume);
|
|
97
|
-
wrapper.addEventListener("pointerenter", handlePause);
|
|
98
|
-
wrapper.addEventListener("pointerleave", handleResume);
|
|
99
|
-
window.addEventListener("blur", handlePause);
|
|
100
|
-
window.addEventListener("focus", handleResume);
|
|
101
|
-
return () => {
|
|
102
|
-
wrapper.removeEventListener("focusin", handlePause);
|
|
103
|
-
wrapper.removeEventListener("focusout", handleResume);
|
|
104
|
-
wrapper.removeEventListener("pointerenter", handlePause);
|
|
105
|
-
wrapper.removeEventListener("pointerleave", handleResume);
|
|
106
|
-
window.removeEventListener("blur", handlePause);
|
|
107
|
-
window.removeEventListener("focus", handleResume);
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}, [context.isClosePausedRef]);
|
|
111
|
-
React.useEffect(() => {
|
|
112
|
-
const viewport = ref.current;
|
|
113
|
-
if (viewport) {
|
|
60
|
+
const ToastViewport = React.forwardRef(
|
|
61
|
+
(props, forwardedRef) => {
|
|
62
|
+
const {
|
|
63
|
+
__scopeToast,
|
|
64
|
+
hotkey = VIEWPORT_DEFAULT_HOTKEY,
|
|
65
|
+
label = "Notifications ({hotkey})",
|
|
66
|
+
...viewportProps
|
|
67
|
+
} = props;
|
|
68
|
+
const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast);
|
|
69
|
+
const wrapperRef = React.useRef(null);
|
|
70
|
+
const headFocusProxyRef = React.useRef(null);
|
|
71
|
+
const tailFocusProxyRef = React.useRef(null);
|
|
72
|
+
const ref = React.useRef(null);
|
|
73
|
+
const composedRefs = useComposedRefs(forwardedRef, ref, context.onViewportChange);
|
|
74
|
+
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
|
|
75
|
+
const hasToasts = context.toastCount > 0;
|
|
76
|
+
React.useEffect(() => {
|
|
114
77
|
const handleKeyDown = (event) => {
|
|
115
78
|
var _a;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const focusedElement = document.activeElement;
|
|
120
|
-
const isTabbingBackwards = event.shiftKey;
|
|
121
|
-
const targetIsViewport = event.target === viewport;
|
|
122
|
-
if (targetIsViewport && isTabbingBackwards) {
|
|
123
|
-
(_a = headFocusProxyRef.current) == null ? void 0 : _a.focus();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
return () => {
|
|
79
|
+
const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
|
|
80
|
+
if (isHotkeyPressed)
|
|
81
|
+
(_a = ref.current) == null ? void 0 : _a.focus();
|
|
130
82
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
83
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
84
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
85
|
+
}, [hotkey]);
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
const wrapper = wrapperRef.current;
|
|
88
|
+
const viewport = ref.current;
|
|
89
|
+
if (wrapper && viewport) {
|
|
90
|
+
const handlePause = () => {
|
|
91
|
+
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
|
|
92
|
+
context.isClosePausedRef.current = true;
|
|
93
|
+
};
|
|
94
|
+
const handleResume = () => {
|
|
95
|
+
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
|
|
96
|
+
context.isClosePausedRef.current = false;
|
|
97
|
+
};
|
|
98
|
+
wrapper.addEventListener("focusin", handlePause);
|
|
99
|
+
wrapper.addEventListener("focusout", handleResume);
|
|
100
|
+
wrapper.addEventListener("pointerenter", handlePause);
|
|
101
|
+
wrapper.addEventListener("pointerleave", handleResume);
|
|
102
|
+
window.addEventListener("blur", handlePause);
|
|
103
|
+
window.addEventListener("focus", handleResume);
|
|
104
|
+
return () => {
|
|
105
|
+
wrapper.removeEventListener("focusin", handlePause);
|
|
106
|
+
wrapper.removeEventListener("focusout", handleResume);
|
|
107
|
+
wrapper.removeEventListener("pointerenter", handlePause);
|
|
108
|
+
wrapper.removeEventListener("pointerleave", handleResume);
|
|
109
|
+
window.removeEventListener("blur", handlePause);
|
|
110
|
+
window.removeEventListener("focus", handleResume);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}, [context.isClosePausedRef]);
|
|
114
|
+
React.useEffect(
|
|
115
|
+
() => {
|
|
116
|
+
const viewport = ref.current;
|
|
117
|
+
if (viewport) {
|
|
118
|
+
const handleKeyDown = (event) => {
|
|
119
|
+
var _a;
|
|
120
|
+
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
121
|
+
const isTabKey = event.key === "Tab" && !isMetaKey;
|
|
122
|
+
if (isTabKey) {
|
|
123
|
+
const focusedElement = document.activeElement;
|
|
124
|
+
const isTabbingBackwards = event.shiftKey;
|
|
125
|
+
const targetIsViewport = event.target === viewport;
|
|
126
|
+
if (targetIsViewport && isTabbingBackwards) {
|
|
127
|
+
(_a = headFocusProxyRef.current) == null ? void 0 : _a.focus();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return () => {
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
[]
|
|
138
|
+
);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
);
|
|
135
142
|
ToastViewport.displayName = VIEWPORT_NAME;
|
|
136
143
|
const FOCUS_PROXY_NAME = "ToastFocusProxy";
|
|
137
|
-
const FocusProxy = React.forwardRef(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
144
|
+
const FocusProxy = React.forwardRef(
|
|
145
|
+
(props, forwardedRef) => {
|
|
146
|
+
const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props;
|
|
147
|
+
const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast);
|
|
148
|
+
return /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
149
|
+
"aria-hidden": true,
|
|
150
|
+
tabIndex: 0,
|
|
151
|
+
...proxyProps,
|
|
152
|
+
ref: forwardedRef,
|
|
153
|
+
position: isWeb ? "fixed" : "absolute",
|
|
154
|
+
onFocus: (event) => {
|
|
155
|
+
var _a;
|
|
156
|
+
const prevFocusedElement = event.relatedTarget;
|
|
157
|
+
const isFocusFromOutsideViewport = !((_a = context.viewport) == null ? void 0 : _a.contains(prevFocusedElement));
|
|
158
|
+
if (isFocusFromOutsideViewport)
|
|
159
|
+
onFocusFromOutsideViewport();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
);
|
|
155
164
|
FocusProxy.displayName = FOCUS_PROXY_NAME;
|
|
156
165
|
const TOAST_NAME = "Toast";
|
|
157
166
|
const TOAST_SWIPE_START = "toast.swipeStart";
|
|
158
167
|
const TOAST_SWIPE_MOVE = "toast.swipeMove";
|
|
159
168
|
const TOAST_SWIPE_CANCEL = "toast.swipeCancel";
|
|
160
169
|
const TOAST_SWIPE_END = "toast.swipeEnd";
|
|
161
|
-
const Toast = React.forwardRef(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
170
|
+
const Toast = React.forwardRef(
|
|
171
|
+
(props, forwardedRef) => {
|
|
172
|
+
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
|
|
173
|
+
const [open, setOpen] = useControllableState({
|
|
174
|
+
prop: openProp,
|
|
175
|
+
defaultProp: defaultOpen || true,
|
|
176
|
+
onChange: onOpenChange
|
|
177
|
+
});
|
|
178
|
+
return /* @__PURE__ */ jsx(ToastImpl, {
|
|
179
|
+
open,
|
|
180
|
+
...toastProps,
|
|
181
|
+
ref: forwardedRef,
|
|
182
|
+
onClose: () => setOpen(false)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
);
|
|
175
186
|
Toast.displayName = TOAST_NAME;
|
|
176
187
|
const [ToastInteractiveProvider, useToastInteractiveContext] = {};
|
|
177
|
-
const ToastImpl = React.forwardRef(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
closeTimerRef.current = window.setTimeout(handleClose, duration2);
|
|
210
|
-
}, [handleClose]);
|
|
211
|
-
React.useEffect(() => {
|
|
212
|
-
const viewport = context.viewport;
|
|
213
|
-
if (viewport) {
|
|
214
|
-
const handleResume = () => {
|
|
215
|
-
startTimer(closeTimerRemainingTimeRef.current);
|
|
216
|
-
};
|
|
217
|
-
const handlePause = () => {
|
|
218
|
-
const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;
|
|
219
|
-
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
188
|
+
const ToastImpl = React.forwardRef(
|
|
189
|
+
(props, forwardedRef) => {
|
|
190
|
+
const {
|
|
191
|
+
__scopeToast,
|
|
192
|
+
type = "foreground",
|
|
193
|
+
duration: durationProp,
|
|
194
|
+
open,
|
|
195
|
+
onClose,
|
|
196
|
+
onEscapeKeyDown,
|
|
197
|
+
onSwipeStart,
|
|
198
|
+
onSwipeMove,
|
|
199
|
+
onSwipeCancel,
|
|
200
|
+
onSwipeEnd,
|
|
201
|
+
...toastProps
|
|
202
|
+
} = props;
|
|
203
|
+
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
204
|
+
const ref = React.useRef(null);
|
|
205
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
206
|
+
const pointerStartRef = React.useRef(null);
|
|
207
|
+
const swipeDeltaRef = React.useRef(null);
|
|
208
|
+
const duration = durationProp || context.duration;
|
|
209
|
+
const closeTimerStartTimeRef = React.useRef(0);
|
|
210
|
+
const closeTimerRemainingTimeRef = React.useRef(duration);
|
|
211
|
+
const closeTimerRef = React.useRef(0);
|
|
212
|
+
const { onToastAdd, onToastRemove } = context;
|
|
213
|
+
const handleClose = useEvent(() => {
|
|
214
|
+
onClose();
|
|
215
|
+
});
|
|
216
|
+
const startTimer = React.useCallback(
|
|
217
|
+
(duration2) => {
|
|
218
|
+
if (!duration2 || duration2 === Infinity)
|
|
219
|
+
return;
|
|
220
220
|
window.clearTimeout(closeTimerRef.current);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
221
|
+
closeTimerStartTimeRef.current = new Date().getTime();
|
|
222
|
+
closeTimerRef.current = window.setTimeout(handleClose, duration2);
|
|
223
|
+
},
|
|
224
|
+
[handleClose]
|
|
225
|
+
);
|
|
226
|
+
React.useEffect(() => {
|
|
227
|
+
const viewport = context.viewport;
|
|
228
|
+
if (viewport) {
|
|
229
|
+
const handleResume = () => {
|
|
230
|
+
startTimer(closeTimerRemainingTimeRef.current);
|
|
231
|
+
};
|
|
232
|
+
const handlePause = () => {
|
|
233
|
+
const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;
|
|
234
|
+
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
235
|
+
window.clearTimeout(closeTimerRef.current);
|
|
236
|
+
};
|
|
237
|
+
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
|
|
238
|
+
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
|
|
239
|
+
return () => {
|
|
240
|
+
viewport.removeEventListener(VIEWPORT_PAUSE, handlePause);
|
|
241
|
+
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}, [context.viewport, duration, startTimer]);
|
|
245
|
+
React.useEffect(() => {
|
|
246
|
+
if (open && !context.isClosePausedRef.current)
|
|
247
|
+
startTimer(duration);
|
|
248
|
+
}, [open, duration, context.isClosePausedRef, startTimer]);
|
|
249
|
+
React.useEffect(() => {
|
|
250
|
+
onToastAdd();
|
|
251
|
+
return () => onToastRemove();
|
|
252
|
+
}, [onToastAdd, onToastRemove]);
|
|
253
|
+
if (!context.viewport)
|
|
254
|
+
return null;
|
|
255
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
256
|
+
children: [
|
|
257
|
+
/* @__PURE__ */ jsx(ToastAnnounce, {
|
|
258
|
+
__scopeToast,
|
|
259
|
+
role: "status",
|
|
260
|
+
"aria-live": type === "foreground" ? "assertive" : "polite",
|
|
261
|
+
"aria-atomic": true,
|
|
262
|
+
children: props.children
|
|
263
|
+
}),
|
|
264
|
+
/* @__PURE__ */ jsx(ToastInteractiveProvider, {
|
|
265
|
+
scope: __scopeToast,
|
|
266
|
+
isInteractive: true,
|
|
267
|
+
onClose: handleClose,
|
|
268
|
+
children: ReactDOM.createPortal(
|
|
269
|
+
/* @__PURE__ */ jsx("div", {}),
|
|
270
|
+
context.viewport
|
|
271
|
+
)
|
|
272
|
+
})
|
|
273
|
+
]
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
);
|
|
251
277
|
ToastImpl.propTypes = {
|
|
252
278
|
type(props) {
|
|
253
279
|
if (props.type && !["foreground", "background"].includes(props.type)) {
|
|
@@ -275,44 +301,64 @@ const ToastAnnounce = (props) => {
|
|
|
275
301
|
const timer = window.setTimeout(() => setIsAnnounced(true), 1e3);
|
|
276
302
|
return () => window.clearTimeout(timer);
|
|
277
303
|
}, []);
|
|
278
|
-
return isAnnounced ? null : /* @__PURE__ */
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
304
|
+
return isAnnounced ? null : /* @__PURE__ */ jsxs(Fragment, {
|
|
305
|
+
children: [
|
|
306
|
+
fragment && /* @__PURE__ */ jsxs(Portal, {
|
|
307
|
+
container: fragment,
|
|
308
|
+
ref: setRootFragmentNode,
|
|
309
|
+
children: [
|
|
310
|
+
context.label,
|
|
311
|
+
" ",
|
|
312
|
+
children
|
|
313
|
+
]
|
|
314
|
+
}),
|
|
315
|
+
/* @__PURE__ */ jsx(Portal, {
|
|
316
|
+
asChild: true,
|
|
317
|
+
children: /* @__PURE__ */ jsx(VisuallyHidden, {
|
|
318
|
+
...announceProps,
|
|
319
|
+
children: renderAnnounceText && announceTextContent
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
]
|
|
323
|
+
});
|
|
286
324
|
};
|
|
287
325
|
const TITLE_NAME = "ToastTitle";
|
|
288
|
-
const ToastTitle = React.forwardRef(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
});
|
|
326
|
+
const ToastTitle = React.forwardRef(
|
|
327
|
+
(props, forwardedRef) => {
|
|
328
|
+
const { __scopeToast, ...titleProps } = props;
|
|
329
|
+
return /* @__PURE__ */ jsx(YStack, {
|
|
330
|
+
...titleProps,
|
|
331
|
+
ref: forwardedRef
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
);
|
|
295
335
|
ToastTitle.displayName = TITLE_NAME;
|
|
296
336
|
const DESCRIPTION_NAME = "ToastDescription";
|
|
297
|
-
const ToastDescription = React.forwardRef(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
});
|
|
337
|
+
const ToastDescription = React.forwardRef(
|
|
338
|
+
(props, forwardedRef) => {
|
|
339
|
+
const { __scopeToast, ...descriptionProps } = props;
|
|
340
|
+
return /* @__PURE__ */ jsx(YStack, {
|
|
341
|
+
...descriptionProps,
|
|
342
|
+
ref: forwardedRef
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
);
|
|
304
346
|
ToastDescription.displayName = DESCRIPTION_NAME;
|
|
305
347
|
const ACTION_NAME = "ToastAction";
|
|
306
|
-
const ToastAction = React.forwardRef(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
})
|
|
348
|
+
const ToastAction = React.forwardRef(
|
|
349
|
+
(props, forwardedRef) => {
|
|
350
|
+
const { altText, ...actionProps } = props;
|
|
351
|
+
const context = useToastInteractiveContext(ACTION_NAME, props.__scopeToast);
|
|
352
|
+
if (!altText)
|
|
353
|
+
return null;
|
|
354
|
+
return context.isInteractive ? /* @__PURE__ */ jsx(ToastClose, {
|
|
355
|
+
...actionProps,
|
|
356
|
+
ref: forwardedRef
|
|
357
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
358
|
+
children: altText
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
);
|
|
316
362
|
ToastAction.propTypes = {
|
|
317
363
|
altText(props) {
|
|
318
364
|
if (!props.altText) {
|
|
@@ -323,16 +369,18 @@ ToastAction.propTypes = {
|
|
|
323
369
|
};
|
|
324
370
|
ToastAction.displayName = ACTION_NAME;
|
|
325
371
|
const CLOSE_NAME = "ToastClose";
|
|
326
|
-
const ToastClose = React.forwardRef(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
372
|
+
const ToastClose = React.forwardRef(
|
|
373
|
+
(props, forwardedRef) => {
|
|
374
|
+
const { __scopeToast, ...closeProps } = props;
|
|
375
|
+
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
|
|
376
|
+
return interactiveContext.isInteractive ? /* @__PURE__ */ jsx(YStack, {
|
|
377
|
+
tag: "button",
|
|
378
|
+
...closeProps,
|
|
379
|
+
ref: forwardedRef,
|
|
380
|
+
onPress: composeEventHandlers(props.onPress, interactiveContext.onClose)
|
|
381
|
+
}) : null;
|
|
382
|
+
}
|
|
383
|
+
);
|
|
336
384
|
ToastClose.displayName = CLOSE_NAME;
|
|
337
385
|
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
338
386
|
const currentTarget = detail.originalEvent.currentTarget;
|