@tamagui/toast 2.0.0-rc.32 → 2.0.0-rc.33
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/ToastComposable.cjs +764 -0
- package/dist/cjs/ToastComposable.native.js +874 -0
- package/dist/cjs/ToastComposable.native.js.map +1 -0
- package/dist/cjs/ToastImpl.cjs +35 -32
- package/dist/cjs/ToastImpl.native.js +8 -4
- package/dist/cjs/ToastImpl.native.js.map +1 -1
- package/dist/cjs/ToastItemFrame.cjs +141 -0
- package/dist/cjs/ToastItemFrame.native.js +146 -0
- package/dist/cjs/ToastItemFrame.native.js.map +1 -0
- package/dist/cjs/ToastPortal.cjs +3 -3
- package/dist/cjs/ToastPortal.native.js +2 -2
- package/dist/cjs/ToastPortal.native.js.map +1 -1
- package/dist/cjs/ToastProvider.native.js.map +1 -1
- package/dist/cjs/ToastState.cjs +248 -0
- package/dist/cjs/ToastState.native.js +257 -0
- package/dist/cjs/ToastState.native.js.map +1 -0
- package/dist/cjs/ToastViewport.cjs +3 -3
- package/dist/cjs/ToastViewport.native.js +4 -3
- package/dist/cjs/ToastViewport.native.js.map +1 -1
- package/dist/cjs/Toaster.cjs +85 -0
- package/dist/cjs/Toaster.native.js +89 -0
- package/dist/cjs/Toaster.native.js.map +1 -0
- package/dist/cjs/createNativeToast.cjs +10 -19
- package/dist/cjs/createNativeToast.native.js +5 -1
- package/dist/cjs/createNativeToast.native.js.map +1 -1
- package/dist/cjs/dispatchNativeToast.cjs +44 -0
- package/dist/cjs/dispatchNativeToast.native.js +50 -0
- package/dist/cjs/dispatchNativeToast.native.js.map +1 -0
- package/dist/cjs/index.cjs +20 -4
- package/dist/cjs/index.native.js +20 -4
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useAnimatedDragGesture.cjs +150 -0
- package/dist/cjs/useAnimatedDragGesture.native.js +168 -0
- package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/cjs/useReducedMotion.cjs +60 -0
- package/dist/cjs/useReducedMotion.native.js +74 -0
- package/dist/cjs/useReducedMotion.native.js.map +1 -0
- package/dist/cjs/useToastAnimations.cjs +240 -0
- package/dist/cjs/useToastAnimations.native.js +252 -0
- package/dist/cjs/useToastAnimations.native.js.map +1 -0
- package/dist/cjs/v1.cjs +31 -0
- package/dist/cjs/v1.native.js +34 -0
- package/dist/cjs/v1.native.js.map +1 -0
- package/dist/esm/ToastComposable.mjs +728 -0
- package/dist/esm/ToastComposable.mjs.map +1 -0
- package/dist/esm/ToastComposable.native.js +835 -0
- package/dist/esm/ToastComposable.native.js.map +1 -0
- package/dist/esm/ToastImpl.mjs +35 -32
- package/dist/esm/ToastImpl.mjs.map +1 -1
- package/dist/esm/ToastImpl.native.js +9 -5
- package/dist/esm/ToastImpl.native.js.map +1 -1
- package/dist/esm/ToastItemFrame.mjs +114 -0
- package/dist/esm/ToastItemFrame.mjs.map +1 -0
- package/dist/esm/ToastItemFrame.native.js +116 -0
- package/dist/esm/ToastItemFrame.native.js.map +1 -0
- package/dist/esm/ToastPortal.mjs +2 -2
- package/dist/esm/ToastPortal.mjs.map +1 -1
- package/dist/esm/ToastPortal.native.js +2 -2
- package/dist/esm/ToastPortal.native.js.map +1 -1
- package/dist/esm/ToastProvider.mjs.map +1 -1
- package/dist/esm/ToastProvider.native.js.map +1 -1
- package/dist/esm/ToastState.mjs +224 -0
- package/dist/esm/ToastState.mjs.map +1 -0
- package/dist/esm/ToastState.native.js +230 -0
- package/dist/esm/ToastState.native.js.map +1 -0
- package/dist/esm/ToastViewport.mjs +3 -3
- package/dist/esm/ToastViewport.mjs.map +1 -1
- package/dist/esm/ToastViewport.native.js +4 -3
- package/dist/esm/ToastViewport.native.js.map +1 -1
- package/dist/esm/Toaster.mjs +51 -0
- package/dist/esm/Toaster.mjs.map +1 -0
- package/dist/esm/Toaster.native.js +52 -0
- package/dist/esm/Toaster.native.js.map +1 -0
- package/dist/esm/createNativeToast.mjs +8 -18
- package/dist/esm/createNativeToast.mjs.map +1 -1
- package/dist/esm/createNativeToast.native.js +4 -1
- package/dist/esm/createNativeToast.native.js.map +1 -1
- package/dist/esm/dispatchNativeToast.mjs +21 -0
- package/dist/esm/dispatchNativeToast.mjs.map +1 -0
- package/dist/esm/dispatchNativeToast.native.js +24 -0
- package/dist/esm/dispatchNativeToast.native.js.map +1 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +5 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +5 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/useAnimatedDragGesture.mjs +116 -0
- package/dist/esm/useAnimatedDragGesture.mjs.map +1 -0
- package/dist/esm/useAnimatedDragGesture.native.js +131 -0
- package/dist/esm/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/esm/useReducedMotion.mjs +26 -0
- package/dist/esm/useReducedMotion.mjs.map +1 -0
- package/dist/esm/useReducedMotion.native.js +37 -0
- package/dist/esm/useReducedMotion.native.js.map +1 -0
- package/dist/esm/useToastAnimations.mjs +206 -0
- package/dist/esm/useToastAnimations.mjs.map +1 -0
- package/dist/esm/useToastAnimations.native.js +215 -0
- package/dist/esm/useToastAnimations.native.js.map +1 -0
- package/dist/esm/v1.mjs +3 -0
- package/dist/esm/v1.mjs.map +1 -0
- package/dist/esm/v1.native.js +3 -0
- package/dist/esm/v1.native.js.map +1 -0
- package/dist/jsx/ToastComposable.mjs +728 -0
- package/dist/jsx/ToastComposable.mjs.map +1 -0
- package/dist/jsx/ToastComposable.native.js +874 -0
- package/dist/jsx/ToastComposable.native.js.map +1 -0
- package/dist/jsx/ToastImpl.mjs +35 -32
- package/dist/jsx/ToastImpl.mjs.map +1 -1
- package/dist/jsx/ToastImpl.native.js +8 -4
- package/dist/jsx/ToastImpl.native.js.map +1 -1
- package/dist/jsx/ToastItemFrame.mjs +114 -0
- package/dist/jsx/ToastItemFrame.mjs.map +1 -0
- package/dist/jsx/ToastItemFrame.native.js +146 -0
- package/dist/jsx/ToastItemFrame.native.js.map +1 -0
- package/dist/jsx/ToastPortal.mjs +2 -2
- package/dist/jsx/ToastPortal.mjs.map +1 -1
- package/dist/jsx/ToastPortal.native.js +2 -2
- package/dist/jsx/ToastPortal.native.js.map +1 -1
- package/dist/jsx/ToastProvider.mjs.map +1 -1
- package/dist/jsx/ToastProvider.native.js.map +1 -1
- package/dist/jsx/ToastState.mjs +224 -0
- package/dist/jsx/ToastState.mjs.map +1 -0
- package/dist/jsx/ToastState.native.js +257 -0
- package/dist/jsx/ToastState.native.js.map +1 -0
- package/dist/jsx/ToastViewport.mjs +3 -3
- package/dist/jsx/ToastViewport.mjs.map +1 -1
- package/dist/jsx/ToastViewport.native.js +4 -3
- package/dist/jsx/ToastViewport.native.js.map +1 -1
- package/dist/jsx/Toaster.mjs +51 -0
- package/dist/jsx/Toaster.mjs.map +1 -0
- package/dist/jsx/Toaster.native.js +89 -0
- package/dist/jsx/Toaster.native.js.map +1 -0
- package/dist/jsx/createNativeToast.mjs +8 -18
- package/dist/jsx/createNativeToast.mjs.map +1 -1
- package/dist/jsx/createNativeToast.native.js +5 -1
- package/dist/jsx/createNativeToast.native.js.map +1 -1
- package/dist/jsx/dispatchNativeToast.mjs +21 -0
- package/dist/jsx/dispatchNativeToast.mjs.map +1 -0
- package/dist/jsx/dispatchNativeToast.native.js +50 -0
- package/dist/jsx/dispatchNativeToast.native.js.map +1 -0
- package/dist/jsx/index.js +5 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +5 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/index.native.js +20 -4
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useAnimatedDragGesture.mjs +116 -0
- package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -0
- package/dist/jsx/useAnimatedDragGesture.native.js +168 -0
- package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/jsx/useReducedMotion.mjs +26 -0
- package/dist/jsx/useReducedMotion.mjs.map +1 -0
- package/dist/jsx/useReducedMotion.native.js +74 -0
- package/dist/jsx/useReducedMotion.native.js.map +1 -0
- package/dist/jsx/useToastAnimations.mjs +206 -0
- package/dist/jsx/useToastAnimations.mjs.map +1 -0
- package/dist/jsx/useToastAnimations.native.js +252 -0
- package/dist/jsx/useToastAnimations.native.js.map +1 -0
- package/dist/jsx/v1.mjs +3 -0
- package/dist/jsx/v1.mjs.map +1 -0
- package/dist/jsx/v1.native.js +34 -0
- package/dist/jsx/v1.native.js.map +1 -0
- package/package.json +18 -18
- package/types/ToastComposable.d.ts.map +1 -0
- package/types/ToastImpl.d.ts.map +1 -1
- package/types/ToastItemFrame.d.ts.map +1 -0
- package/types/ToastPortal.d.ts.map +1 -1
- package/types/ToastProvider.d.ts.map +1 -1
- package/types/ToastState.d.ts.map +1 -0
- package/types/ToastViewport.d.ts.map +1 -1
- package/types/Toaster.d.ts.map +1 -0
- package/types/createNativeToast.d.ts.map +1 -1
- package/types/createNativeToast.native.d.ts.map +1 -1
- package/types/dispatchNativeToast.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.d.ts.map +1 -0
- package/types/useAnimatedDragGesture.native.d.ts.map +1 -0
- package/types/useReducedMotion.d.ts.map +1 -0
- package/types/useToastAnimations.d.ts.map +1 -0
- package/types/v1.d.ts.map +1 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var ToastComposable_exports = {};
|
|
33
|
+
__export(ToastComposable_exports, {
|
|
34
|
+
Toast: () => Toast,
|
|
35
|
+
useToastItem: () => useToastItem,
|
|
36
|
+
useToasts: () => useToasts
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(ToastComposable_exports);
|
|
39
|
+
var import_animate_presence = require("@tamagui/animate-presence"),
|
|
40
|
+
import_constants = require("@tamagui/constants"),
|
|
41
|
+
import_native = require("@tamagui/native"),
|
|
42
|
+
import_core = require("@tamagui/core"),
|
|
43
|
+
import_helpers = require("@tamagui/helpers"),
|
|
44
|
+
import_portal = require("@tamagui/portal"),
|
|
45
|
+
import_stacks = require("@tamagui/stacks"),
|
|
46
|
+
import_text = require("@tamagui/text"),
|
|
47
|
+
React = __toESM(require("react"), 1),
|
|
48
|
+
import_ToastState = require("./ToastState.cjs"),
|
|
49
|
+
import_dispatchNativeToast = require("./dispatchNativeToast.cjs"),
|
|
50
|
+
import_useAnimatedDragGesture = require("./useAnimatedDragGesture.cjs"),
|
|
51
|
+
import_useToastAnimations = require("./useToastAnimations.cjs"),
|
|
52
|
+
import_useReducedMotion = require("./useReducedMotion.cjs"),
|
|
53
|
+
import_ToastItemFrame = require("./ToastItemFrame.cjs"),
|
|
54
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
55
|
+
const VISIBLE_TOASTS_AMOUNT = 4,
|
|
56
|
+
VIEWPORT_OFFSET = 24,
|
|
57
|
+
TOAST_GAP = 14,
|
|
58
|
+
TOAST_LIFETIME = 4e3,
|
|
59
|
+
TIME_BEFORE_UNMOUNT = 200,
|
|
60
|
+
DEFAULT_HOTKEY = ["altKey", "KeyT"],
|
|
61
|
+
ToastContext = (0, import_core.createStyledContext)({}, "Toast__"),
|
|
62
|
+
useToastContext = ToastContext.useStyledContext,
|
|
63
|
+
ToastItemContext = React.createContext(null);
|
|
64
|
+
function useToastItemContext() {
|
|
65
|
+
const ctx = React.useContext(ToastItemContext);
|
|
66
|
+
if (!ctx) throw new Error("useToastItemContext must be used within Toast.Item or Toast.List");
|
|
67
|
+
return ctx;
|
|
68
|
+
}
|
|
69
|
+
function resolveSwipeDirection(direction, position) {
|
|
70
|
+
if (direction !== "auto") return direction;
|
|
71
|
+
const [yPosition, xPosition] = position.split("-");
|
|
72
|
+
return import_constants.isWeb ? xPosition === "left" ? "left" : xPosition === "right" ? "right" : "horizontal" : yPosition === "top" ? "up" : "down";
|
|
73
|
+
}
|
|
74
|
+
const ToastRoot = React.forwardRef(function (props, _ref) {
|
|
75
|
+
const {
|
|
76
|
+
children,
|
|
77
|
+
position = "bottom-right",
|
|
78
|
+
duration = TOAST_LIFETIME,
|
|
79
|
+
gap = TOAST_GAP,
|
|
80
|
+
visibleToasts = VISIBLE_TOASTS_AMOUNT,
|
|
81
|
+
swipeDirection: swipeDirectionProp = "auto",
|
|
82
|
+
swipeThreshold = 50,
|
|
83
|
+
closeButton = !1,
|
|
84
|
+
expand = !1,
|
|
85
|
+
theme: themeProp,
|
|
86
|
+
reducedMotion: reducedMotionProp,
|
|
87
|
+
native = !1,
|
|
88
|
+
burntOptions,
|
|
89
|
+
notificationOptions,
|
|
90
|
+
icons
|
|
91
|
+
} = props,
|
|
92
|
+
reducedMotion = (0, import_useReducedMotion.useReducedMotion)(reducedMotionProp),
|
|
93
|
+
[toasts, setToasts] = React.useState([]),
|
|
94
|
+
[heights, setHeights] = React.useState({}),
|
|
95
|
+
[localExpanded, setExpanded] = React.useState(!1),
|
|
96
|
+
expanded = expand || localExpanded,
|
|
97
|
+
[interacting, setInteracting] = React.useState(!1),
|
|
98
|
+
heightsLockedRef = React.useRef(!1),
|
|
99
|
+
prevExpandedRef = React.useRef(expanded);
|
|
100
|
+
React.useLayoutEffect(() => {
|
|
101
|
+
prevExpandedRef.current !== expanded && (heightsLockedRef.current = !0, prevExpandedRef.current = expanded);
|
|
102
|
+
const timer = setTimeout(() => {
|
|
103
|
+
heightsLockedRef.current = !1;
|
|
104
|
+
}, 350);
|
|
105
|
+
return () => clearTimeout(timer);
|
|
106
|
+
}, [expanded]);
|
|
107
|
+
const setToastHeight = React.useCallback((toastId, height) => {
|
|
108
|
+
if (heightsLockedRef.current) return;
|
|
109
|
+
const rounded = Math.round(height);
|
|
110
|
+
setHeights(prev => {
|
|
111
|
+
const existing = prev[toastId];
|
|
112
|
+
return existing != null && Math.abs(existing - rounded) <= 2 ? prev : {
|
|
113
|
+
...prev,
|
|
114
|
+
[toastId]: rounded
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}, []),
|
|
118
|
+
removeToastHeight = React.useCallback(toastId => {
|
|
119
|
+
setHeights(prev => {
|
|
120
|
+
if (!(toastId in prev)) return prev;
|
|
121
|
+
const next = {
|
|
122
|
+
...prev
|
|
123
|
+
};
|
|
124
|
+
return delete next[toastId], next;
|
|
125
|
+
});
|
|
126
|
+
}, []),
|
|
127
|
+
dismissCooldownRef = React.useRef(!1),
|
|
128
|
+
dismissCooldownTimerRef = React.useRef(null),
|
|
129
|
+
triggerDismissCooldown = React.useCallback(() => {
|
|
130
|
+
dismissCooldownRef.current = !0, dismissCooldownTimerRef.current && clearTimeout(dismissCooldownTimerRef.current), dismissCooldownTimerRef.current = setTimeout(() => {
|
|
131
|
+
dismissCooldownRef.current = !1;
|
|
132
|
+
}, 800);
|
|
133
|
+
}, []),
|
|
134
|
+
isInDismissCooldown = React.useCallback(() => dismissCooldownRef.current, []),
|
|
135
|
+
burntOptionsRef = React.useRef(burntOptions),
|
|
136
|
+
notificationOptionsRef = React.useRef(notificationOptions);
|
|
137
|
+
React.useEffect(() => {
|
|
138
|
+
burntOptionsRef.current = burntOptions;
|
|
139
|
+
}, [burntOptions]), React.useEffect(() => {
|
|
140
|
+
notificationOptionsRef.current = notificationOptions;
|
|
141
|
+
}, [notificationOptions]), React.useEffect(() => import_ToastState.ToastState.subscribe(toast => {
|
|
142
|
+
if (toast.dismiss) {
|
|
143
|
+
setToasts(toasts2 => toasts2.map(t => t.id === toast.id ? {
|
|
144
|
+
...t,
|
|
145
|
+
delete: !0
|
|
146
|
+
} : t));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
native && (0, import_dispatchNativeToast.dispatchNativeToast)(toast, {
|
|
150
|
+
duration,
|
|
151
|
+
burntOptions: burntOptionsRef.current,
|
|
152
|
+
notificationOptions: notificationOptionsRef.current
|
|
153
|
+
}) || setToasts(toasts2 => {
|
|
154
|
+
const idx = toasts2.findIndex(t => t.id === toast.id);
|
|
155
|
+
return idx !== -1 ? [...toasts2.slice(0, idx), {
|
|
156
|
+
...toasts2[idx],
|
|
157
|
+
...toast
|
|
158
|
+
}, ...toasts2.slice(idx + 1)] : [toast, ...toasts2];
|
|
159
|
+
});
|
|
160
|
+
}), [native, duration]);
|
|
161
|
+
const prevToastCountRef = React.useRef(toasts.length);
|
|
162
|
+
React.useEffect(() => {
|
|
163
|
+
const prevCount = prevToastCountRef.current;
|
|
164
|
+
prevToastCountRef.current = toasts.length, (toasts.length <= 1 && !dismissCooldownRef.current || toasts.length > prevCount && expanded) && setExpanded(!1);
|
|
165
|
+
}, [toasts.length, expanded]);
|
|
166
|
+
const removeToast = React.useCallback(toastToRemove => {
|
|
167
|
+
setToasts(toasts2 => (toasts2.find(t => t.id === toastToRemove.id)?.delete || import_ToastState.ToastState.dismiss(toastToRemove.id), toasts2.filter(({
|
|
168
|
+
id
|
|
169
|
+
}) => id !== toastToRemove.id)));
|
|
170
|
+
}, []),
|
|
171
|
+
swipeDirection = resolveSwipeDirection(swipeDirectionProp, position),
|
|
172
|
+
currentTheme = (0, import_core.useThemeName)(),
|
|
173
|
+
resolvedTheme = themeProp === "system" || !themeProp ? currentTheme?.includes("dark") ? "dark" : "light" : themeProp,
|
|
174
|
+
contextValue = {
|
|
175
|
+
toasts,
|
|
176
|
+
heights,
|
|
177
|
+
setToastHeight,
|
|
178
|
+
removeToastHeight,
|
|
179
|
+
expanded,
|
|
180
|
+
setExpanded,
|
|
181
|
+
interacting,
|
|
182
|
+
setInteracting,
|
|
183
|
+
triggerDismissCooldown,
|
|
184
|
+
isInDismissCooldown,
|
|
185
|
+
removeToast,
|
|
186
|
+
position,
|
|
187
|
+
duration,
|
|
188
|
+
gap,
|
|
189
|
+
visibleToasts,
|
|
190
|
+
swipeDirection,
|
|
191
|
+
swipeThreshold,
|
|
192
|
+
closeButton,
|
|
193
|
+
reducedMotion,
|
|
194
|
+
native,
|
|
195
|
+
burntOptions,
|
|
196
|
+
notificationOptions,
|
|
197
|
+
icons
|
|
198
|
+
};
|
|
199
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
|
|
200
|
+
...contextValue,
|
|
201
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
202
|
+
name: resolvedTheme,
|
|
203
|
+
children
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
}),
|
|
207
|
+
ToastViewportFrame = (0, import_core.styled)(import_core.View, {
|
|
208
|
+
name: "ToastViewport",
|
|
209
|
+
variants: {
|
|
210
|
+
unstyled: {
|
|
211
|
+
false: {
|
|
212
|
+
position: import_constants.isWeb ? "fixed" : "absolute",
|
|
213
|
+
zIndex: 1e5,
|
|
214
|
+
pointerEvents: "box-none",
|
|
215
|
+
maxWidth: "100%",
|
|
216
|
+
width: 356,
|
|
217
|
+
minHeight: 1
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
defaultVariants: {
|
|
222
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
223
|
+
}
|
|
224
|
+
}),
|
|
225
|
+
ToastViewport = ToastViewportFrame.styleable(function (props, ref) {
|
|
226
|
+
const {
|
|
227
|
+
offset = VIEWPORT_OFFSET,
|
|
228
|
+
hotkey = DEFAULT_HOTKEY,
|
|
229
|
+
label = "Notifications",
|
|
230
|
+
portalToRoot = !0,
|
|
231
|
+
portalZIndex = Number.MAX_SAFE_INTEGER,
|
|
232
|
+
children,
|
|
233
|
+
...rest
|
|
234
|
+
} = props,
|
|
235
|
+
ctx = useToastContext(),
|
|
236
|
+
listRef = React.useRef(null),
|
|
237
|
+
hoverTimeoutRef = React.useRef(null),
|
|
238
|
+
hoverCooldownRef = React.useRef(!1),
|
|
239
|
+
deferredCollapseRef = React.useRef(null),
|
|
240
|
+
mouseInsideRef = React.useRef(!1),
|
|
241
|
+
[yPosition, xPosition] = ctx.position.split("-"),
|
|
242
|
+
{
|
|
243
|
+
insets: safeInsets
|
|
244
|
+
} = (0, import_core.useConfiguration)(),
|
|
245
|
+
offsetStyles = React.useMemo(() => {
|
|
246
|
+
const styles = {},
|
|
247
|
+
defaultOffset = typeof offset == "number" ? offset : VIEWPORT_OFFSET,
|
|
248
|
+
offsetObj = typeof offset == "object" ? offset : {
|
|
249
|
+
top: defaultOffset,
|
|
250
|
+
right: defaultOffset,
|
|
251
|
+
bottom: defaultOffset,
|
|
252
|
+
left: defaultOffset
|
|
253
|
+
},
|
|
254
|
+
safeTop = safeInsets?.top ?? 0,
|
|
255
|
+
safeBottom = safeInsets?.bottom ?? 0;
|
|
256
|
+
return yPosition === "top" ? styles.top = (offsetObj.top ?? defaultOffset) + safeTop : styles.bottom = (offsetObj.bottom ?? defaultOffset) + safeBottom, xPosition === "left" ? styles.left = offsetObj.left ?? defaultOffset : xPosition === "right" ? styles.right = offsetObj.right ?? defaultOffset : import_constants.isWeb ? (styles.left = "50%", styles.transform = "translateX(-50%)") : (styles.left = offsetObj.left ?? defaultOffset, styles.right = offsetObj.right ?? defaultOffset, styles.alignItems = "center"), styles;
|
|
257
|
+
}, [offset, yPosition, xPosition]);
|
|
258
|
+
if (React.useEffect(() => {
|
|
259
|
+
if (!import_constants.isWeb) return;
|
|
260
|
+
const handleKeyDown = event => {
|
|
261
|
+
hotkey.length > 0 && hotkey.every(key => event[key] || event.code === key) && (ctx.setExpanded(!0), listRef.current?.focus());
|
|
262
|
+
};
|
|
263
|
+
return document.addEventListener("keydown", handleKeyDown), () => document.removeEventListener("keydown", handleKeyDown);
|
|
264
|
+
}, [hotkey]), ctx.toasts.length === 0) return null;
|
|
265
|
+
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, ""),
|
|
266
|
+
content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastViewportFrame, {
|
|
267
|
+
ref: listRef,
|
|
268
|
+
"aria-label": `${label} ${hotkeyLabel}`,
|
|
269
|
+
tabIndex: -1,
|
|
270
|
+
"aria-live": "polite",
|
|
271
|
+
style: offsetStyles,
|
|
272
|
+
"data-y-position": yPosition,
|
|
273
|
+
"data-x-position": xPosition,
|
|
274
|
+
...(import_constants.isWeb ? {
|
|
275
|
+
onMouseEnter: () => {
|
|
276
|
+
mouseInsideRef.current = !0, deferredCollapseRef.current && (clearTimeout(deferredCollapseRef.current), deferredCollapseRef.current = null), ctx.toasts.length > 1 && !ctx.interacting && !hoverCooldownRef.current && (hoverTimeoutRef.current = setTimeout(() => ctx.setExpanded(!0), 50));
|
|
277
|
+
},
|
|
278
|
+
onMouseLeave: () => {
|
|
279
|
+
mouseInsideRef.current = !1, hoverTimeoutRef.current && (clearTimeout(hoverTimeoutRef.current), hoverTimeoutRef.current = null), !ctx.interacting && !ctx.isInDismissCooldown() ? ctx.setExpanded(!1) : ctx.isInDismissCooldown() && (deferredCollapseRef.current && clearTimeout(deferredCollapseRef.current), deferredCollapseRef.current = setTimeout(() => {
|
|
280
|
+
deferredCollapseRef.current = null, mouseInsideRef.current || ctx.setExpanded(!1);
|
|
281
|
+
}, 1200));
|
|
282
|
+
},
|
|
283
|
+
onPointerDown: () => {
|
|
284
|
+
hoverTimeoutRef.current && (clearTimeout(hoverTimeoutRef.current), hoverTimeoutRef.current = null), ctx.setInteracting(!0);
|
|
285
|
+
},
|
|
286
|
+
onPointerUp: () => ctx.setInteracting(!1),
|
|
287
|
+
onPointerCancel: () => ctx.setInteracting(!1)
|
|
288
|
+
} : {
|
|
289
|
+
onPress: () => {
|
|
290
|
+
ctx.toasts.length > 1 && ctx.setExpanded(prev => !prev);
|
|
291
|
+
}
|
|
292
|
+
}),
|
|
293
|
+
...(import_constants.isWeb && {
|
|
294
|
+
onFocus: event => {
|
|
295
|
+
event.currentTarget.contains(event.relatedTarget) || (ctx.toasts.length > 1 && ctx.setExpanded(!0), ctx.setInteracting(!0));
|
|
296
|
+
},
|
|
297
|
+
onBlur: event => {
|
|
298
|
+
event.currentTarget.contains(event.relatedTarget) || (ctx.setInteracting(!1), ctx.isInDismissCooldown() || ctx.setExpanded(!1));
|
|
299
|
+
}
|
|
300
|
+
}),
|
|
301
|
+
...rest,
|
|
302
|
+
children
|
|
303
|
+
});
|
|
304
|
+
return portalToRoot ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
|
|
305
|
+
zIndex: portalZIndex,
|
|
306
|
+
children: content
|
|
307
|
+
}) : content;
|
|
308
|
+
});
|
|
309
|
+
function ToastList({
|
|
310
|
+
renderItem
|
|
311
|
+
}) {
|
|
312
|
+
const ctx = useToastContext(),
|
|
313
|
+
maxRender = ctx.expanded ? ctx.toasts.length : Math.min(ctx.toasts.length, ctx.visibleToasts + 1);
|
|
314
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
|
|
315
|
+
children: ctx.toasts.slice(0, maxRender).map((toast, index) => {
|
|
316
|
+
const handleClose = () => {
|
|
317
|
+
toast.dismissible !== !1 && (toast.onDismiss?.(toast), ctx.removeToast(toast));
|
|
318
|
+
},
|
|
319
|
+
itemContextValue = {
|
|
320
|
+
toast,
|
|
321
|
+
handleClose
|
|
322
|
+
};
|
|
323
|
+
return renderItem ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
|
|
324
|
+
value: itemContextValue,
|
|
325
|
+
children: renderItem({
|
|
326
|
+
toast,
|
|
327
|
+
index,
|
|
328
|
+
handleClose
|
|
329
|
+
})
|
|
330
|
+
}, toast.id) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
|
|
331
|
+
value: itemContextValue,
|
|
332
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemInner, {
|
|
333
|
+
toast,
|
|
334
|
+
index,
|
|
335
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultToastContent, {
|
|
336
|
+
toast
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
}, toast.id);
|
|
340
|
+
})
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function DefaultToastContent({
|
|
344
|
+
toast
|
|
345
|
+
}) {
|
|
346
|
+
const ctx = useToastContext(),
|
|
347
|
+
{
|
|
348
|
+
handleClose
|
|
349
|
+
} = useToastItemContext(),
|
|
350
|
+
toastType = toast.type ?? "default",
|
|
351
|
+
dismissible = toast.dismissible !== !1,
|
|
352
|
+
title = typeof toast.title == "function" ? toast.title() : toast.title,
|
|
353
|
+
description = typeof toast.description == "function" ? toast.description() : toast.description;
|
|
354
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.XStack, {
|
|
355
|
+
alignItems: "flex-start",
|
|
356
|
+
gap: "$3",
|
|
357
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastIcon, {}), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.YStack, {
|
|
358
|
+
flex: 1,
|
|
359
|
+
gap: "$1",
|
|
360
|
+
children: [title && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastTitle, {
|
|
361
|
+
children: title
|
|
362
|
+
}), description && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastDescription, {
|
|
363
|
+
children: description
|
|
364
|
+
}), (toast.action || toast.cancel) && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.XStack, {
|
|
365
|
+
gap: "$2",
|
|
366
|
+
marginTop: "$2",
|
|
367
|
+
children: [toast.cancel && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastActionFrame, {
|
|
368
|
+
backgroundColor: "transparent",
|
|
369
|
+
onPress: e => {
|
|
370
|
+
toast.cancel?.onClick?.(e), handleClose();
|
|
371
|
+
},
|
|
372
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
|
|
373
|
+
size: "$2",
|
|
374
|
+
color: "$color11",
|
|
375
|
+
children: toast.cancel.label
|
|
376
|
+
})
|
|
377
|
+
}), toast.action && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastActionFrame, {
|
|
378
|
+
backgroundColor: "$color12",
|
|
379
|
+
hoverStyle: {
|
|
380
|
+
backgroundColor: "$color11"
|
|
381
|
+
},
|
|
382
|
+
pressStyle: {
|
|
383
|
+
backgroundColor: "$color10"
|
|
384
|
+
},
|
|
385
|
+
onPress: e => {
|
|
386
|
+
toast.action?.onClick?.(e), e.defaultPrevented || handleClose();
|
|
387
|
+
},
|
|
388
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
|
|
389
|
+
size: "$2",
|
|
390
|
+
fontWeight: "600",
|
|
391
|
+
color: "$background",
|
|
392
|
+
children: toast.action.label
|
|
393
|
+
})
|
|
394
|
+
})]
|
|
395
|
+
})]
|
|
396
|
+
}), ctx.closeButton && dismissible && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastClose, {})]
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
function DragWrapper({
|
|
400
|
+
animatedStyle,
|
|
401
|
+
gestureHandlers,
|
|
402
|
+
gesture,
|
|
403
|
+
AnimatedView,
|
|
404
|
+
dragRef,
|
|
405
|
+
children
|
|
406
|
+
}) {
|
|
407
|
+
if (import_constants.isWeb) return /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
|
|
408
|
+
ref: dragRef,
|
|
409
|
+
style: {
|
|
410
|
+
flex: 1,
|
|
411
|
+
display: "flex",
|
|
412
|
+
flexDirection: "column",
|
|
413
|
+
userSelect: "none",
|
|
414
|
+
WebkitUserSelect: "none",
|
|
415
|
+
touchAction: "none",
|
|
416
|
+
cursor: "default"
|
|
417
|
+
},
|
|
418
|
+
...gestureHandlers,
|
|
419
|
+
children
|
|
420
|
+
});
|
|
421
|
+
if (gesture) {
|
|
422
|
+
const GestureDetector = (0, import_native.getGestureHandler)().state.GestureDetector;
|
|
423
|
+
if (GestureDetector) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(GestureDetector, {
|
|
424
|
+
gesture,
|
|
425
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
426
|
+
style: {
|
|
427
|
+
flex: 1
|
|
428
|
+
},
|
|
429
|
+
collapsable: !1,
|
|
430
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
|
|
431
|
+
style: [{
|
|
432
|
+
flex: 1
|
|
433
|
+
}, animatedStyle],
|
|
434
|
+
children
|
|
435
|
+
})
|
|
436
|
+
})
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
|
|
440
|
+
style: [{
|
|
441
|
+
flex: 1
|
|
442
|
+
}, animatedStyle],
|
|
443
|
+
...gestureHandlers,
|
|
444
|
+
children
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
const ToastItemInner = import_ToastItemFrame.ToastItemFrame.styleable(function (props, ref) {
|
|
448
|
+
const {
|
|
449
|
+
toast,
|
|
450
|
+
index,
|
|
451
|
+
children,
|
|
452
|
+
...rest
|
|
453
|
+
} = props,
|
|
454
|
+
ctx = useToastContext(),
|
|
455
|
+
[mounted, setMounted] = React.useState(!1),
|
|
456
|
+
[removed, setRemoved] = React.useState(!1),
|
|
457
|
+
[swipeOut, setSwipeOut] = React.useState(!1),
|
|
458
|
+
[offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0),
|
|
459
|
+
closeTimerRef = React.useRef(null),
|
|
460
|
+
closeTimerStartRef = React.useRef(0),
|
|
461
|
+
lastPauseTimeRef = React.useRef(0),
|
|
462
|
+
remainingTimeRef = React.useRef(toast.duration ?? ctx.duration),
|
|
463
|
+
isFront = index === 0,
|
|
464
|
+
isVisible = index < ctx.visibleToasts,
|
|
465
|
+
toastType = toast.type ?? "default",
|
|
466
|
+
dismissible = toast.dismissible !== !1,
|
|
467
|
+
duration = toast.duration ?? ctx.duration,
|
|
468
|
+
[yPosition] = ctx.position.split("-"),
|
|
469
|
+
isTop = yPosition === "top",
|
|
470
|
+
expandedOffset = React.useMemo(() => {
|
|
471
|
+
let totalHeight = 0,
|
|
472
|
+
activeCount = 0;
|
|
473
|
+
for (let i = 0; i < index; i++) {
|
|
474
|
+
const toastId = ctx.toasts[i]?.id;
|
|
475
|
+
if (toastId == null) continue;
|
|
476
|
+
const h = ctx.heights[toastId];
|
|
477
|
+
h !== 0 && (totalHeight += h ?? 55, activeCount++);
|
|
478
|
+
}
|
|
479
|
+
return totalHeight + activeCount * ctx.gap;
|
|
480
|
+
}, [ctx.toasts, ctx.heights, index, ctx.gap]),
|
|
481
|
+
expandedOffsetRef = React.useRef(expandedOffset);
|
|
482
|
+
expandedOffsetRef.current = expandedOffset;
|
|
483
|
+
const isExpandedRef = React.useRef(ctx.expanded);
|
|
484
|
+
isExpandedRef.current = ctx.expanded;
|
|
485
|
+
const startTimer = React.useCallback(() => {
|
|
486
|
+
duration === Number.POSITIVE_INFINITY || toastType === "loading" || (closeTimerStartRef.current = Date.now(), closeTimerRef.current = setTimeout(() => {
|
|
487
|
+
toast.onAutoClose?.(toast), setRemoved(!0), setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
|
|
488
|
+
}, remainingTimeRef.current));
|
|
489
|
+
}, [duration, toastType, toast, ctx.removeToast]),
|
|
490
|
+
pauseTimer = (0, import_core.useEvent)(() => {
|
|
491
|
+
if (closeTimerRef.current && clearTimeout(closeTimerRef.current), lastPauseTimeRef.current < closeTimerStartRef.current) {
|
|
492
|
+
const elapsed = Date.now() - closeTimerStartRef.current;
|
|
493
|
+
remainingTimeRef.current = Math.max(0, remainingTimeRef.current - elapsed);
|
|
494
|
+
}
|
|
495
|
+
lastPauseTimeRef.current = Date.now();
|
|
496
|
+
}),
|
|
497
|
+
resumeTimer = (0, import_core.useEvent)(() => {
|
|
498
|
+
ctx.expanded || ctx.interacting || startTimer();
|
|
499
|
+
});
|
|
500
|
+
React.useEffect(() => {
|
|
501
|
+
setMounted(!0);
|
|
502
|
+
}, []), React.useEffect(() => {
|
|
503
|
+
toast.delete && (setRemoved(!0), isExpandedRef.current && (setOffsetBeforeRemove(expandedOffsetRef.current), ctx.setToastHeight(toast.id, 0)), setTimeout(() => {
|
|
504
|
+
ctx.removeToast(toast);
|
|
505
|
+
}, TIME_BEFORE_UNMOUNT));
|
|
506
|
+
}, [toast.delete, toast, ctx.removeToast, ctx.setToastHeight]), React.useEffect(() => (ctx.expanded || ctx.interacting ? pauseTimer() : startTimer(), () => {
|
|
507
|
+
closeTimerRef.current && clearTimeout(closeTimerRef.current);
|
|
508
|
+
}), [ctx.expanded, ctx.interacting, startTimer]), React.useEffect(() => {
|
|
509
|
+
remainingTimeRef.current = duration;
|
|
510
|
+
}, [duration]);
|
|
511
|
+
const {
|
|
512
|
+
setDragOffset,
|
|
513
|
+
springBack,
|
|
514
|
+
animateOut,
|
|
515
|
+
animatedStyle,
|
|
516
|
+
AnimatedView,
|
|
517
|
+
dragRef
|
|
518
|
+
} = (0, import_useToastAnimations.useToastAnimations)({
|
|
519
|
+
reducedMotion: ctx.reducedMotion,
|
|
520
|
+
swipeAxis: ctx.swipeDirection === "up" || ctx.swipeDirection === "down" || ctx.swipeDirection === "vertical" ? "vertical" : "horizontal"
|
|
521
|
+
}),
|
|
522
|
+
{
|
|
523
|
+
isDragging,
|
|
524
|
+
gestureHandlers,
|
|
525
|
+
gesture
|
|
526
|
+
} = (0, import_useAnimatedDragGesture.useAnimatedDragGesture)({
|
|
527
|
+
direction: ctx.swipeDirection,
|
|
528
|
+
threshold: ctx.swipeThreshold,
|
|
529
|
+
disabled: !dismissible || toastType === "loading",
|
|
530
|
+
expanded: ctx.expanded,
|
|
531
|
+
onDragStart: pauseTimer,
|
|
532
|
+
onDragMove: setDragOffset,
|
|
533
|
+
onDismiss: (exitDirection, velocity) => {
|
|
534
|
+
ctx.triggerDismissCooldown(), setSwipeOut(!0), toast.onDismiss?.(toast), setRemoved(!0), ctx.removeToastHeight(toast.id), ctx.removeToast(toast), animateOut(exitDirection, velocity);
|
|
535
|
+
},
|
|
536
|
+
onCancel: () => {
|
|
537
|
+
springBack(() => {
|
|
538
|
+
resumeTimer();
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}),
|
|
542
|
+
handleLayout = React.useCallback(event => {
|
|
543
|
+
if (removed || !ctx.expanded && index !== 0) return;
|
|
544
|
+
const {
|
|
545
|
+
height
|
|
546
|
+
} = event.nativeEvent.layout;
|
|
547
|
+
ctx.setToastHeight(toast.id, height);
|
|
548
|
+
}, [toast.id, ctx.setToastHeight, index, ctx.expanded, removed]);
|
|
549
|
+
React.useEffect(() => () => {
|
|
550
|
+
ctx.removeToastHeight(toast.id);
|
|
551
|
+
}, [toast.id, ctx.removeToastHeight]);
|
|
552
|
+
const handleClose = React.useCallback(() => {
|
|
553
|
+
dismissible && (ctx.triggerDismissCooldown(), toast.onDismiss?.(toast), setRemoved(!0), isExpandedRef.current && (setOffsetBeforeRemove(expandedOffsetRef.current), ctx.setToastHeight(toast.id, 0)), setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT));
|
|
554
|
+
}, [dismissible, toast, ctx.removeToast, ctx.setToastHeight, ctx.triggerDismissCooldown]),
|
|
555
|
+
itemContextValue = React.useMemo(() => ({
|
|
556
|
+
toast,
|
|
557
|
+
handleClose
|
|
558
|
+
}), [toast, handleClose]);
|
|
559
|
+
let frontToastHeight = -1;
|
|
560
|
+
for (const t of ctx.toasts) {
|
|
561
|
+
const h = ctx.heights[t.id];
|
|
562
|
+
if (h != null && h > 0) {
|
|
563
|
+
frontToastHeight = h;
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
const stackScale = !ctx.expanded && !isFront ? 1 - index * 0.05 : 1,
|
|
568
|
+
activeExpandedOffset = removed ? offsetBeforeRemove : expandedOffset,
|
|
569
|
+
stackY = ctx.expanded ? isTop ? activeExpandedOffset : -activeExpandedOffset : isFront ? 0 : isTop ? ctx.gap * index : -ctx.gap * index,
|
|
570
|
+
computedOpacity = removed && !swipeOut || index >= ctx.visibleToasts ? 0 : !ctx.expanded && index === ctx.visibleToasts - 1 ? 0.5 : 1,
|
|
571
|
+
computedZIndex = removed ? 0 : ctx.visibleToasts - index + 1,
|
|
572
|
+
myHeight = ctx.heights[toast.id],
|
|
573
|
+
computedHeight = ctx.expanded ? myHeight && myHeight > 0 ? myHeight : void 0 : !isFront && frontToastHeight > 0 ? frontToastHeight : void 0,
|
|
574
|
+
computedPointerEvents = index >= ctx.visibleToasts ? "none" : "auto",
|
|
575
|
+
gapFillerHeight = ctx.expanded ? ctx.gap + 1 : 0,
|
|
576
|
+
dataAttributes = {
|
|
577
|
+
"data-mounted": mounted ? "true" : "false",
|
|
578
|
+
"data-removed": removed ? "true" : "false",
|
|
579
|
+
"data-swipe-out": swipeOut ? "true" : "false",
|
|
580
|
+
"data-visible": isVisible ? "true" : "false",
|
|
581
|
+
"data-front": isFront ? "true" : "false",
|
|
582
|
+
"data-index": String(index),
|
|
583
|
+
"data-type": toastType,
|
|
584
|
+
"data-expanded": ctx.expanded ? "true" : "false"
|
|
585
|
+
};
|
|
586
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastPositionWrapper, {
|
|
587
|
+
ref,
|
|
588
|
+
testID: rest.testID,
|
|
589
|
+
accessibilityLabel: rest.accessibilityLabel,
|
|
590
|
+
...dataAttributes,
|
|
591
|
+
transition: isDragging || ctx.reducedMotion ? void 0 : removed ? "200ms" : "400ms",
|
|
592
|
+
animateOnly: ["transform", "opacity", "height"],
|
|
593
|
+
y: stackY,
|
|
594
|
+
scale: stackScale,
|
|
595
|
+
opacity: computedOpacity,
|
|
596
|
+
zIndex: computedZIndex,
|
|
597
|
+
height: computedHeight,
|
|
598
|
+
overflow: "visible",
|
|
599
|
+
pointerEvents: computedPointerEvents,
|
|
600
|
+
top: isTop ? 0 : void 0,
|
|
601
|
+
bottom: isTop ? void 0 : 0,
|
|
602
|
+
...(import_constants.isWeb && !isFront && {
|
|
603
|
+
style: {
|
|
604
|
+
transformOrigin: isTop ? "top center" : "bottom center"
|
|
605
|
+
}
|
|
606
|
+
}),
|
|
607
|
+
enterStyle: ctx.reducedMotion ? {
|
|
608
|
+
opacity: 0
|
|
609
|
+
} : {
|
|
610
|
+
opacity: 0,
|
|
611
|
+
y: isTop ? -80 : 80
|
|
612
|
+
},
|
|
613
|
+
exitStyle: ctx.reducedMotion ? {
|
|
614
|
+
opacity: 0
|
|
615
|
+
} : swipeOut ? {
|
|
616
|
+
opacity: 0,
|
|
617
|
+
x: 0,
|
|
618
|
+
y: 0,
|
|
619
|
+
scale: 1
|
|
620
|
+
} : {
|
|
621
|
+
opacity: 0,
|
|
622
|
+
y: stackY,
|
|
623
|
+
scale: stackScale
|
|
624
|
+
},
|
|
625
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DragWrapper, {
|
|
626
|
+
animatedStyle,
|
|
627
|
+
gestureHandlers,
|
|
628
|
+
gesture,
|
|
629
|
+
AnimatedView,
|
|
630
|
+
dragRef,
|
|
631
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_ToastItemFrame.ToastItemFrame, {
|
|
632
|
+
role: "status",
|
|
633
|
+
"aria-live": "polite",
|
|
634
|
+
"aria-atomic": !0,
|
|
635
|
+
tabIndex: 0,
|
|
636
|
+
onLayout: handleLayout,
|
|
637
|
+
...(import_constants.isWeb && {
|
|
638
|
+
onKeyDown: event => {
|
|
639
|
+
if (event.key === "Escape" && dismissible) {
|
|
640
|
+
const current = event.currentTarget,
|
|
641
|
+
container = current.closest("[aria-label]");
|
|
642
|
+
if (container) {
|
|
643
|
+
const focusables = container.querySelectorAll('[tabindex="0"]'),
|
|
644
|
+
arr = Array.from(focusables),
|
|
645
|
+
idx = arr.indexOf(current);
|
|
646
|
+
(arr[idx + 1] || arr[idx - 1])?.focus();
|
|
647
|
+
}
|
|
648
|
+
handleClose();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}),
|
|
652
|
+
...rest,
|
|
653
|
+
children: [ctx.expanded && gapFillerHeight > 0 && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
654
|
+
position: "absolute",
|
|
655
|
+
left: 0,
|
|
656
|
+
right: 0,
|
|
657
|
+
height: gapFillerHeight,
|
|
658
|
+
pointerEvents: "auto",
|
|
659
|
+
...(isTop ? {
|
|
660
|
+
top: "100%"
|
|
661
|
+
} : {
|
|
662
|
+
bottom: "100%"
|
|
663
|
+
})
|
|
664
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
|
|
665
|
+
value: itemContextValue,
|
|
666
|
+
children
|
|
667
|
+
})]
|
|
668
|
+
})
|
|
669
|
+
})
|
|
670
|
+
});
|
|
671
|
+
}),
|
|
672
|
+
ToastTitle = (0, import_core.styled)(import_text.SizableText, {
|
|
673
|
+
name: "ToastTitle",
|
|
674
|
+
variants: {
|
|
675
|
+
unstyled: {
|
|
676
|
+
false: {
|
|
677
|
+
color: "$color",
|
|
678
|
+
fontWeight: "600",
|
|
679
|
+
size: "$4"
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
defaultVariants: {
|
|
684
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
685
|
+
}
|
|
686
|
+
}),
|
|
687
|
+
ToastDescription = (0, import_core.styled)(import_text.SizableText, {
|
|
688
|
+
name: "ToastDescription",
|
|
689
|
+
variants: {
|
|
690
|
+
unstyled: {
|
|
691
|
+
false: {
|
|
692
|
+
color: "$color11",
|
|
693
|
+
size: "$2"
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
defaultVariants: {
|
|
698
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
699
|
+
}
|
|
700
|
+
}),
|
|
701
|
+
ToastClose = import_ToastItemFrame.ToastCloseFrame.styleable(function (props, ref) {
|
|
702
|
+
let handleClose;
|
|
703
|
+
try {
|
|
704
|
+
handleClose = useToastItemContext().handleClose;
|
|
705
|
+
} catch {}
|
|
706
|
+
const ctx = useToastContext();
|
|
707
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastCloseFrame, {
|
|
708
|
+
ref,
|
|
709
|
+
"aria-label": "Close toast",
|
|
710
|
+
onPress: handleClose,
|
|
711
|
+
...props,
|
|
712
|
+
children: props.children ?? ctx.icons?.close ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.DefaultCloseIcon, {})
|
|
713
|
+
});
|
|
714
|
+
}),
|
|
715
|
+
ToastAction = import_ToastItemFrame.ToastActionFrame.styleable(function (props, ref) {
|
|
716
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastActionFrame, {
|
|
717
|
+
ref,
|
|
718
|
+
...props
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
function ToastIcon(props) {
|
|
722
|
+
const ctx = useToastContext();
|
|
723
|
+
let toast;
|
|
724
|
+
try {
|
|
725
|
+
toast = useToastItemContext().toast;
|
|
726
|
+
} catch {
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
729
|
+
if (!toast) return null;
|
|
730
|
+
if (toast.icon !== void 0) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
731
|
+
flexShrink: 0,
|
|
732
|
+
marginTop: "$0.5",
|
|
733
|
+
children: toast.icon
|
|
734
|
+
});
|
|
735
|
+
const toastType = toast.type ?? "default",
|
|
736
|
+
icon = ctx.icons?.[toastType] ?? null;
|
|
737
|
+
return icon ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
738
|
+
flexShrink: 0,
|
|
739
|
+
marginTop: "$0.5",
|
|
740
|
+
children: icon
|
|
741
|
+
}) : null;
|
|
742
|
+
}
|
|
743
|
+
function useToasts() {
|
|
744
|
+
const ctx = useToastContext();
|
|
745
|
+
return {
|
|
746
|
+
toasts: ctx.toasts,
|
|
747
|
+
expanded: ctx.expanded,
|
|
748
|
+
position: ctx.position
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
function useToastItem() {
|
|
752
|
+
return useToastItemContext();
|
|
753
|
+
}
|
|
754
|
+
ToastRoot.displayName = "Toast";
|
|
755
|
+
const Toast = (0, import_helpers.withStaticProperties)(ToastRoot, {
|
|
756
|
+
Viewport: ToastViewport,
|
|
757
|
+
List: ToastList,
|
|
758
|
+
Item: ToastItemInner,
|
|
759
|
+
Title: ToastTitle,
|
|
760
|
+
Description: ToastDescription,
|
|
761
|
+
Close: ToastClose,
|
|
762
|
+
Action: ToastAction,
|
|
763
|
+
Icon: ToastIcon
|
|
764
|
+
});
|