@tamagui/toast 1.144.2 → 1.144.4
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 +891 -0
- package/dist/cjs/ToastComposable.js +693 -0
- package/dist/cjs/ToastComposable.js.map +6 -0
- package/dist/cjs/ToastComposable.native.js +994 -0
- package/dist/cjs/ToastComposable.native.js.map +1 -0
- package/dist/cjs/ToastItem.cjs +644 -0
- package/dist/cjs/ToastItem.js +536 -0
- package/dist/cjs/ToastItem.js.map +6 -0
- package/dist/cjs/ToastItem.native.js +732 -0
- package/dist/cjs/ToastItem.native.js.map +1 -0
- package/dist/cjs/ToastState.cjs +248 -0
- package/dist/cjs/ToastState.js +160 -0
- package/dist/cjs/ToastState.js.map +6 -0
- package/dist/cjs/ToastState.native.js +257 -0
- package/dist/cjs/ToastState.native.js.map +1 -0
- package/dist/cjs/Toaster.cjs +249 -0
- package/dist/cjs/Toaster.js +204 -0
- package/dist/cjs/Toaster.js.map +6 -0
- package/dist/cjs/Toaster.native.js +308 -0
- package/dist/cjs/Toaster.native.js.map +1 -0
- package/dist/cjs/useAnimatedDragGesture.cjs +132 -0
- package/dist/cjs/useAnimatedDragGesture.js +129 -0
- package/dist/cjs/useAnimatedDragGesture.js.map +6 -0
- package/dist/cjs/useAnimatedDragGesture.native.js +110 -0
- package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/cjs/useDragGesture.cjs +129 -0
- package/dist/cjs/useDragGesture.js +100 -0
- package/dist/cjs/useDragGesture.js.map +6 -0
- package/dist/cjs/useDragGesture.native.js +146 -0
- package/dist/cjs/useDragGesture.native.js.map +1 -0
- package/dist/cjs/useReducedMotion.cjs +60 -0
- package/dist/cjs/useReducedMotion.js +53 -0
- package/dist/cjs/useReducedMotion.js.map +6 -0
- package/dist/cjs/useReducedMotion.native.js +74 -0
- package/dist/cjs/useReducedMotion.native.js.map +1 -0
- package/dist/cjs/useToastAnimations.cjs +214 -0
- package/dist/cjs/useToastAnimations.js +144 -0
- package/dist/cjs/useToastAnimations.js.map +6 -0
- package/dist/cjs/useToastAnimations.native.js +226 -0
- package/dist/cjs/useToastAnimations.native.js.map +1 -0
- package/dist/cjs/v1.cjs +31 -0
- package/dist/cjs/v1.js +26 -0
- package/dist/cjs/v1.js.map +6 -0
- package/dist/cjs/v1.native.js +34 -0
- package/dist/cjs/v1.native.js.map +1 -0
- package/dist/esm/ToastComposable.js +688 -0
- package/dist/esm/ToastComposable.js.map +6 -0
- package/dist/esm/ToastComposable.mjs +855 -0
- package/dist/esm/ToastComposable.mjs.map +1 -0
- package/dist/esm/ToastComposable.native.js +955 -0
- package/dist/esm/ToastComposable.native.js.map +1 -0
- package/dist/esm/ToastItem.js +520 -0
- package/dist/esm/ToastItem.js.map +6 -0
- package/dist/esm/ToastItem.mjs +610 -0
- package/dist/esm/ToastItem.mjs.map +1 -0
- package/dist/esm/ToastItem.native.js +695 -0
- package/dist/esm/ToastItem.native.js.map +1 -0
- package/dist/esm/ToastState.js +144 -0
- package/dist/esm/ToastState.js.map +6 -0
- 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/Toaster.js +188 -0
- package/dist/esm/Toaster.js.map +6 -0
- package/dist/esm/Toaster.mjs +215 -0
- package/dist/esm/Toaster.mjs.map +1 -0
- package/dist/esm/Toaster.native.js +271 -0
- package/dist/esm/Toaster.native.js.map +1 -0
- package/dist/esm/useAnimatedDragGesture.js +105 -0
- package/dist/esm/useAnimatedDragGesture.js.map +6 -0
- package/dist/esm/useAnimatedDragGesture.mjs +98 -0
- package/dist/esm/useAnimatedDragGesture.mjs.map +1 -0
- package/dist/esm/useAnimatedDragGesture.native.js +73 -0
- package/dist/esm/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/esm/useDragGesture.js +76 -0
- package/dist/esm/useDragGesture.js.map +6 -0
- package/dist/esm/useDragGesture.mjs +95 -0
- package/dist/esm/useDragGesture.mjs.map +1 -0
- package/dist/esm/useDragGesture.native.js +109 -0
- package/dist/esm/useDragGesture.native.js.map +1 -0
- package/dist/esm/useReducedMotion.js +30 -0
- package/dist/esm/useReducedMotion.js.map +6 -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.js +122 -0
- package/dist/esm/useToastAnimations.js.map +6 -0
- package/dist/esm/useToastAnimations.mjs +180 -0
- package/dist/esm/useToastAnimations.mjs.map +1 -0
- package/dist/esm/useToastAnimations.native.js +189 -0
- package/dist/esm/useToastAnimations.native.js.map +1 -0
- package/dist/esm/v1.js +17 -0
- package/dist/esm/v1.js.map +6 -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.js +688 -0
- package/dist/jsx/ToastComposable.js.map +6 -0
- package/dist/jsx/ToastComposable.mjs +855 -0
- package/dist/jsx/ToastComposable.mjs.map +1 -0
- package/dist/jsx/ToastComposable.native.js +994 -0
- package/dist/jsx/ToastComposable.native.js.map +1 -0
- package/dist/jsx/ToastItem.js +520 -0
- package/dist/jsx/ToastItem.js.map +6 -0
- package/dist/jsx/ToastItem.mjs +610 -0
- package/dist/jsx/ToastItem.mjs.map +1 -0
- package/dist/jsx/ToastItem.native.js +732 -0
- package/dist/jsx/ToastItem.native.js.map +1 -0
- package/dist/jsx/ToastState.js +144 -0
- package/dist/jsx/ToastState.js.map +6 -0
- 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/Toaster.js +188 -0
- package/dist/jsx/Toaster.js.map +6 -0
- package/dist/jsx/Toaster.mjs +215 -0
- package/dist/jsx/Toaster.mjs.map +1 -0
- package/dist/jsx/Toaster.native.js +308 -0
- package/dist/jsx/Toaster.native.js.map +1 -0
- package/dist/jsx/useAnimatedDragGesture.js +105 -0
- package/dist/jsx/useAnimatedDragGesture.js.map +6 -0
- package/dist/jsx/useAnimatedDragGesture.mjs +98 -0
- package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -0
- package/dist/jsx/useAnimatedDragGesture.native.js +110 -0
- package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/jsx/useDragGesture.js +76 -0
- package/dist/jsx/useDragGesture.js.map +6 -0
- package/dist/jsx/useDragGesture.mjs +95 -0
- package/dist/jsx/useDragGesture.mjs.map +1 -0
- package/dist/jsx/useDragGesture.native.js +146 -0
- package/dist/jsx/useDragGesture.native.js.map +1 -0
- package/dist/jsx/useReducedMotion.js +30 -0
- package/dist/jsx/useReducedMotion.js.map +6 -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.js +122 -0
- package/dist/jsx/useToastAnimations.js.map +6 -0
- package/dist/jsx/useToastAnimations.mjs +180 -0
- package/dist/jsx/useToastAnimations.mjs.map +1 -0
- package/dist/jsx/useToastAnimations.native.js +226 -0
- package/dist/jsx/useToastAnimations.native.js.map +1 -0
- package/dist/jsx/v1.js +17 -0
- package/dist/jsx/v1.js.map +6 -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 +17 -17
|
@@ -0,0 +1,891 @@
|
|
|
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_core = require("@tamagui/core"),
|
|
42
|
+
import_helpers = require("@tamagui/helpers"),
|
|
43
|
+
import_portal = require("@tamagui/portal"),
|
|
44
|
+
import_stacks = require("@tamagui/stacks"),
|
|
45
|
+
import_text = require("@tamagui/text"),
|
|
46
|
+
React = __toESM(require("react"), 1),
|
|
47
|
+
import_ToastState = require("./ToastState.cjs"),
|
|
48
|
+
import_useAnimatedDragGesture = require("./useAnimatedDragGesture.cjs"),
|
|
49
|
+
import_useToastAnimations = require("./useToastAnimations.cjs"),
|
|
50
|
+
import_useReducedMotion = require("./useReducedMotion.cjs"),
|
|
51
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
52
|
+
const VISIBLE_TOASTS_AMOUNT = 4,
|
|
53
|
+
VIEWPORT_OFFSET = 24,
|
|
54
|
+
TOAST_GAP = 14,
|
|
55
|
+
TOAST_LIFETIME = 4e3,
|
|
56
|
+
TIME_BEFORE_UNMOUNT = 200,
|
|
57
|
+
ToastContext = (0, import_core.createStyledContext)({}, "Toast__"),
|
|
58
|
+
useToastContext = ToastContext.useStyledContext,
|
|
59
|
+
ToastItemContext = React.createContext(null);
|
|
60
|
+
function useToastItemContext() {
|
|
61
|
+
const ctx = React.useContext(ToastItemContext);
|
|
62
|
+
if (!ctx) throw new Error("useToastItemContext must be used within Toast.Item or Toast.List");
|
|
63
|
+
return ctx;
|
|
64
|
+
}
|
|
65
|
+
const ICON_SIZE = 20,
|
|
66
|
+
DefaultSuccessIcon = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
67
|
+
width: ICON_SIZE,
|
|
68
|
+
height: ICON_SIZE,
|
|
69
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)("svg", {
|
|
70
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
71
|
+
viewBox: "0 0 24 24",
|
|
72
|
+
width: ICON_SIZE,
|
|
73
|
+
height: ICON_SIZE,
|
|
74
|
+
fill: "none",
|
|
75
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("circle", {
|
|
76
|
+
cx: "12",
|
|
77
|
+
cy: "12",
|
|
78
|
+
r: "10",
|
|
79
|
+
fill: "var(--green5)"
|
|
80
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
81
|
+
d: "M8 12.5l2.5 2.5 5.5-5.5",
|
|
82
|
+
stroke: "var(--green10)",
|
|
83
|
+
strokeWidth: "2",
|
|
84
|
+
strokeLinecap: "round",
|
|
85
|
+
strokeLinejoin: "round"
|
|
86
|
+
})]
|
|
87
|
+
})
|
|
88
|
+
}),
|
|
89
|
+
DefaultErrorIcon = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
90
|
+
width: ICON_SIZE,
|
|
91
|
+
height: ICON_SIZE,
|
|
92
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)("svg", {
|
|
93
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
94
|
+
viewBox: "0 0 24 24",
|
|
95
|
+
width: ICON_SIZE,
|
|
96
|
+
height: ICON_SIZE,
|
|
97
|
+
fill: "none",
|
|
98
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("circle", {
|
|
99
|
+
cx: "12",
|
|
100
|
+
cy: "12",
|
|
101
|
+
r: "10",
|
|
102
|
+
fill: "var(--red5)"
|
|
103
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
104
|
+
d: "M15 9l-6 6M9 9l6 6",
|
|
105
|
+
stroke: "var(--red10)",
|
|
106
|
+
strokeWidth: "2",
|
|
107
|
+
strokeLinecap: "round",
|
|
108
|
+
strokeLinejoin: "round"
|
|
109
|
+
})]
|
|
110
|
+
})
|
|
111
|
+
}),
|
|
112
|
+
DefaultWarningIcon = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
113
|
+
width: ICON_SIZE,
|
|
114
|
+
height: ICON_SIZE,
|
|
115
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)("svg", {
|
|
116
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
117
|
+
viewBox: "0 0 24 24",
|
|
118
|
+
width: ICON_SIZE,
|
|
119
|
+
height: ICON_SIZE,
|
|
120
|
+
fill: "none",
|
|
121
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
122
|
+
d: "M12 3L2 21h20L12 3z",
|
|
123
|
+
fill: "var(--yellow5)",
|
|
124
|
+
stroke: "var(--yellow8)",
|
|
125
|
+
strokeWidth: "1.5",
|
|
126
|
+
strokeLinejoin: "round"
|
|
127
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
128
|
+
d: "M12 10v4",
|
|
129
|
+
stroke: "var(--yellow11)",
|
|
130
|
+
strokeWidth: "2",
|
|
131
|
+
strokeLinecap: "round"
|
|
132
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("circle", {
|
|
133
|
+
cx: "12",
|
|
134
|
+
cy: "17",
|
|
135
|
+
r: "1",
|
|
136
|
+
fill: "var(--yellow11)"
|
|
137
|
+
})]
|
|
138
|
+
})
|
|
139
|
+
}),
|
|
140
|
+
DefaultInfoIcon = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
141
|
+
width: ICON_SIZE,
|
|
142
|
+
height: ICON_SIZE,
|
|
143
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)("svg", {
|
|
144
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
145
|
+
viewBox: "0 0 24 24",
|
|
146
|
+
width: ICON_SIZE,
|
|
147
|
+
height: ICON_SIZE,
|
|
148
|
+
fill: "none",
|
|
149
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("circle", {
|
|
150
|
+
cx: "12",
|
|
151
|
+
cy: "12",
|
|
152
|
+
r: "10",
|
|
153
|
+
fill: "var(--blue5)"
|
|
154
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
155
|
+
d: "M12 11v5",
|
|
156
|
+
stroke: "var(--blue10)",
|
|
157
|
+
strokeWidth: "2",
|
|
158
|
+
strokeLinecap: "round"
|
|
159
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("circle", {
|
|
160
|
+
cx: "12",
|
|
161
|
+
cy: "8",
|
|
162
|
+
r: "1",
|
|
163
|
+
fill: "var(--blue10)"
|
|
164
|
+
})]
|
|
165
|
+
})
|
|
166
|
+
}),
|
|
167
|
+
spinKeyframes = import_constants.isWeb ? `
|
|
168
|
+
@keyframes toast-spin {
|
|
169
|
+
from { transform: rotate(0deg); }
|
|
170
|
+
to { transform: rotate(360deg); }
|
|
171
|
+
}
|
|
172
|
+
` : "";
|
|
173
|
+
if (import_constants.isWeb && typeof document < "u") {
|
|
174
|
+
const styleId = "tamagui-toast-spin";
|
|
175
|
+
if (!document.getElementById(styleId)) {
|
|
176
|
+
const style = document.createElement("style");
|
|
177
|
+
style.id = styleId, style.textContent = spinKeyframes, document.head.appendChild(style);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const DefaultLoadingIcon = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
181
|
+
width: ICON_SIZE,
|
|
182
|
+
height: ICON_SIZE,
|
|
183
|
+
...(import_constants.isWeb && {
|
|
184
|
+
style: {
|
|
185
|
+
animation: "toast-spin 1s linear infinite"
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)("svg", {
|
|
189
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
190
|
+
viewBox: "0 0 24 24",
|
|
191
|
+
width: ICON_SIZE,
|
|
192
|
+
height: ICON_SIZE,
|
|
193
|
+
fill: "none",
|
|
194
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)("circle", {
|
|
195
|
+
cx: "12",
|
|
196
|
+
cy: "12",
|
|
197
|
+
r: "10",
|
|
198
|
+
stroke: "var(--color5)",
|
|
199
|
+
strokeWidth: "2.5"
|
|
200
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("path", {
|
|
201
|
+
d: "M12 2a10 10 0 0 1 10 10",
|
|
202
|
+
stroke: "var(--color11)",
|
|
203
|
+
strokeWidth: "2.5",
|
|
204
|
+
strokeLinecap: "round"
|
|
205
|
+
})]
|
|
206
|
+
})
|
|
207
|
+
}),
|
|
208
|
+
DefaultCloseIcon = () => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
|
|
209
|
+
size: "$1",
|
|
210
|
+
color: "$color11",
|
|
211
|
+
children: "\u2715"
|
|
212
|
+
});
|
|
213
|
+
function resolveSwipeDirection(direction, position) {
|
|
214
|
+
if (direction !== "auto") return direction;
|
|
215
|
+
const [yPosition, xPosition] = position.split("-");
|
|
216
|
+
return xPosition === "left" ? "left" : xPosition === "right" ? "right" : yPosition === "top" ? "up" : "down";
|
|
217
|
+
}
|
|
218
|
+
const ToastRoot = React.forwardRef(function (props, ref) {
|
|
219
|
+
const {
|
|
220
|
+
children,
|
|
221
|
+
position = "bottom-right",
|
|
222
|
+
duration = TOAST_LIFETIME,
|
|
223
|
+
gap = TOAST_GAP,
|
|
224
|
+
visibleToasts = VISIBLE_TOASTS_AMOUNT,
|
|
225
|
+
swipeDirection: swipeDirectionProp = "auto",
|
|
226
|
+
swipeThreshold = 50,
|
|
227
|
+
closeButton = !1,
|
|
228
|
+
theme: themeProp,
|
|
229
|
+
reducedMotion: reducedMotionProp,
|
|
230
|
+
icons
|
|
231
|
+
} = props,
|
|
232
|
+
reducedMotion = (0, import_useReducedMotion.useReducedMotion)(reducedMotionProp),
|
|
233
|
+
[toasts, setToasts] = React.useState([]),
|
|
234
|
+
[heights, setHeights] = React.useState({}),
|
|
235
|
+
[expanded, setExpanded] = React.useState(!1),
|
|
236
|
+
[interacting, setInteracting] = React.useState(!1),
|
|
237
|
+
setToastHeight = React.useCallback((toastId, height) => {
|
|
238
|
+
setHeights(prev => ({
|
|
239
|
+
...prev,
|
|
240
|
+
[toastId]: height
|
|
241
|
+
}));
|
|
242
|
+
}, []),
|
|
243
|
+
removeToastHeight = React.useCallback(toastId => {
|
|
244
|
+
setHeights(prev => {
|
|
245
|
+
const next = {
|
|
246
|
+
...prev
|
|
247
|
+
};
|
|
248
|
+
return delete next[toastId], next;
|
|
249
|
+
});
|
|
250
|
+
}, []),
|
|
251
|
+
dismissCooldownRef = React.useRef(!1),
|
|
252
|
+
dismissCooldownTimerRef = React.useRef(null),
|
|
253
|
+
triggerDismissCooldown = () => {
|
|
254
|
+
dismissCooldownRef.current = !0, dismissCooldownTimerRef.current && clearTimeout(dismissCooldownTimerRef.current), dismissCooldownTimerRef.current = setTimeout(() => {
|
|
255
|
+
dismissCooldownRef.current = !1;
|
|
256
|
+
}, 800);
|
|
257
|
+
},
|
|
258
|
+
isInDismissCooldown = () => dismissCooldownRef.current;
|
|
259
|
+
React.useEffect(() => import_ToastState.ToastState.subscribe(toast => {
|
|
260
|
+
if (toast.dismiss) {
|
|
261
|
+
setToasts(toasts2 => toasts2.map(t => t.id === toast.id ? {
|
|
262
|
+
...t,
|
|
263
|
+
delete: !0
|
|
264
|
+
} : t));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
setToasts(toasts2 => {
|
|
268
|
+
const idx = toasts2.findIndex(t => t.id === toast.id);
|
|
269
|
+
return idx !== -1 ? [...toasts2.slice(0, idx), {
|
|
270
|
+
...toasts2[idx],
|
|
271
|
+
...toast
|
|
272
|
+
}, ...toasts2.slice(idx + 1)] : [toast, ...toasts2];
|
|
273
|
+
});
|
|
274
|
+
}), []), React.useEffect(() => {
|
|
275
|
+
toasts.length <= 1 && !dismissCooldownRef.current && setExpanded(!1);
|
|
276
|
+
}, [toasts.length]);
|
|
277
|
+
const removeToast = React.useCallback(toastToRemove => {
|
|
278
|
+
setToasts(toasts2 => (toasts2.find(t => t.id === toastToRemove.id)?.delete || import_ToastState.ToastState.dismiss(toastToRemove.id), toasts2.filter(({
|
|
279
|
+
id
|
|
280
|
+
}) => id !== toastToRemove.id)));
|
|
281
|
+
}, []),
|
|
282
|
+
swipeDirection = resolveSwipeDirection(swipeDirectionProp, position),
|
|
283
|
+
currentTheme = (0, import_core.useThemeName)(),
|
|
284
|
+
resolvedTheme = themeProp === "system" || !themeProp ? currentTheme?.includes("dark") ? "dark" : "light" : themeProp,
|
|
285
|
+
contextValue = {
|
|
286
|
+
toasts,
|
|
287
|
+
heights,
|
|
288
|
+
setToastHeight,
|
|
289
|
+
removeToastHeight,
|
|
290
|
+
expanded,
|
|
291
|
+
setExpanded,
|
|
292
|
+
interacting,
|
|
293
|
+
setInteracting,
|
|
294
|
+
triggerDismissCooldown,
|
|
295
|
+
isInDismissCooldown,
|
|
296
|
+
removeToast,
|
|
297
|
+
position,
|
|
298
|
+
duration,
|
|
299
|
+
gap,
|
|
300
|
+
visibleToasts,
|
|
301
|
+
swipeDirection,
|
|
302
|
+
swipeThreshold,
|
|
303
|
+
closeButton,
|
|
304
|
+
reducedMotion,
|
|
305
|
+
icons
|
|
306
|
+
};
|
|
307
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
|
|
308
|
+
...contextValue,
|
|
309
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
310
|
+
name: resolvedTheme,
|
|
311
|
+
children
|
|
312
|
+
})
|
|
313
|
+
});
|
|
314
|
+
}),
|
|
315
|
+
ToastViewportFrame = (0, import_core.styled)(import_core.View, {
|
|
316
|
+
name: "ToastViewport",
|
|
317
|
+
variants: {
|
|
318
|
+
unstyled: {
|
|
319
|
+
false: {
|
|
320
|
+
position: import_constants.isWeb ? "fixed" : "absolute",
|
|
321
|
+
zIndex: 1e5,
|
|
322
|
+
pointerEvents: "box-none",
|
|
323
|
+
maxWidth: "100%",
|
|
324
|
+
width: 356,
|
|
325
|
+
minHeight: 1
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
defaultVariants: {
|
|
330
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
331
|
+
}
|
|
332
|
+
}),
|
|
333
|
+
ToastViewport = ToastViewportFrame.styleable(function (props, ref) {
|
|
334
|
+
const {
|
|
335
|
+
offset = VIEWPORT_OFFSET,
|
|
336
|
+
hotkey = ["altKey", "KeyT"],
|
|
337
|
+
label = "Notifications",
|
|
338
|
+
portalToRoot = !0,
|
|
339
|
+
children,
|
|
340
|
+
...rest
|
|
341
|
+
} = props,
|
|
342
|
+
ctx = useToastContext(),
|
|
343
|
+
listRef = React.useRef(null),
|
|
344
|
+
hoverTimeoutRef = React.useRef(null),
|
|
345
|
+
hoverCooldownRef = React.useRef(!1),
|
|
346
|
+
[yPosition, xPosition] = ctx.position.split("-"),
|
|
347
|
+
offsetStyles = React.useMemo(() => {
|
|
348
|
+
const styles = {},
|
|
349
|
+
defaultOffset = typeof offset == "number" ? offset : VIEWPORT_OFFSET,
|
|
350
|
+
offsetObj = typeof offset == "object" ? offset : {
|
|
351
|
+
top: defaultOffset,
|
|
352
|
+
right: defaultOffset,
|
|
353
|
+
bottom: defaultOffset,
|
|
354
|
+
left: defaultOffset
|
|
355
|
+
};
|
|
356
|
+
return yPosition === "top" ? styles.top = offsetObj.top ?? defaultOffset : styles.bottom = offsetObj.bottom ?? defaultOffset, xPosition === "left" ? styles.left = offsetObj.left ?? defaultOffset : xPosition === "right" ? styles.right = offsetObj.right ?? defaultOffset : (styles.left = "50%", styles.transform = "translateX(-50%)"), styles;
|
|
357
|
+
}, [offset, yPosition, xPosition]);
|
|
358
|
+
if (React.useEffect(() => {
|
|
359
|
+
if (!import_constants.isWeb) return;
|
|
360
|
+
const handleKeyDown = event => {
|
|
361
|
+
hotkey.length > 0 && hotkey.every(key => event[key] || event.code === key) && (ctx.setExpanded(!0), listRef.current?.focus()), event.code === "Escape" && ctx.setExpanded(!1);
|
|
362
|
+
};
|
|
363
|
+
return document.addEventListener("keydown", handleKeyDown), () => document.removeEventListener("keydown", handleKeyDown);
|
|
364
|
+
}, [hotkey]), ctx.toasts.length === 0) return null;
|
|
365
|
+
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, ""),
|
|
366
|
+
content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastViewportFrame, {
|
|
367
|
+
ref: listRef,
|
|
368
|
+
"aria-label": `${label} ${hotkeyLabel}`,
|
|
369
|
+
tabIndex: -1,
|
|
370
|
+
"aria-live": "polite",
|
|
371
|
+
style: offsetStyles,
|
|
372
|
+
"data-y-position": yPosition,
|
|
373
|
+
"data-x-position": xPosition,
|
|
374
|
+
onMouseEnter: () => {
|
|
375
|
+
ctx.toasts.length > 1 && !ctx.interacting && !hoverCooldownRef.current && (hoverTimeoutRef.current = setTimeout(() => ctx.setExpanded(!0), 50));
|
|
376
|
+
},
|
|
377
|
+
onMouseLeave: () => {
|
|
378
|
+
hoverTimeoutRef.current && (clearTimeout(hoverTimeoutRef.current), hoverTimeoutRef.current = null), !ctx.interacting && !ctx.isInDismissCooldown() && ctx.setExpanded(!1);
|
|
379
|
+
},
|
|
380
|
+
onPointerDown: () => {
|
|
381
|
+
hoverTimeoutRef.current && (clearTimeout(hoverTimeoutRef.current), hoverTimeoutRef.current = null), ctx.setInteracting(!0);
|
|
382
|
+
},
|
|
383
|
+
onPointerUp: () => ctx.setInteracting(!1),
|
|
384
|
+
onPointerCancel: () => ctx.setInteracting(!1),
|
|
385
|
+
...rest,
|
|
386
|
+
children
|
|
387
|
+
});
|
|
388
|
+
return portalToRoot && import_constants.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
|
|
389
|
+
children: content
|
|
390
|
+
}) : content;
|
|
391
|
+
});
|
|
392
|
+
function ToastList({
|
|
393
|
+
renderItem
|
|
394
|
+
}) {
|
|
395
|
+
const ctx = useToastContext();
|
|
396
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
|
|
397
|
+
children: ctx.toasts.map((toast, index) => {
|
|
398
|
+
const handleClose = () => {
|
|
399
|
+
toast.dismissible !== !1 && (toast.onDismiss?.(toast), ctx.removeToast(toast));
|
|
400
|
+
},
|
|
401
|
+
itemContextValue = {
|
|
402
|
+
toast,
|
|
403
|
+
handleClose
|
|
404
|
+
};
|
|
405
|
+
return renderItem ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
|
|
406
|
+
value: itemContextValue,
|
|
407
|
+
children: renderItem({
|
|
408
|
+
toast,
|
|
409
|
+
index,
|
|
410
|
+
handleClose
|
|
411
|
+
})
|
|
412
|
+
}, toast.id) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
|
|
413
|
+
value: itemContextValue,
|
|
414
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemInner, {
|
|
415
|
+
toast,
|
|
416
|
+
index,
|
|
417
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultToastContent, {
|
|
418
|
+
toast
|
|
419
|
+
})
|
|
420
|
+
})
|
|
421
|
+
}, toast.id);
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
function DefaultToastContent({
|
|
426
|
+
toast
|
|
427
|
+
}) {
|
|
428
|
+
const ctx = useToastContext(),
|
|
429
|
+
{
|
|
430
|
+
handleClose
|
|
431
|
+
} = useToastItemContext(),
|
|
432
|
+
toastType = toast.type ?? "default",
|
|
433
|
+
title = typeof toast.title == "function" ? toast.title() : toast.title,
|
|
434
|
+
description = typeof toast.description == "function" ? toast.description() : toast.description;
|
|
435
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.XStack, {
|
|
436
|
+
alignItems: "flex-start",
|
|
437
|
+
gap: "$3",
|
|
438
|
+
children: [toastType !== "default" && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastIcon, {}), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.YStack, {
|
|
439
|
+
flex: 1,
|
|
440
|
+
gap: "$1",
|
|
441
|
+
children: [title && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastTitle, {
|
|
442
|
+
children: title
|
|
443
|
+
}), description && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastDescription, {
|
|
444
|
+
children: description
|
|
445
|
+
}), (toast.action || toast.cancel) && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.XStack, {
|
|
446
|
+
gap: "$2",
|
|
447
|
+
marginTop: "$2",
|
|
448
|
+
children: [toast.cancel && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastActionFrame, {
|
|
449
|
+
backgroundColor: "transparent",
|
|
450
|
+
onPress: e => {
|
|
451
|
+
toast.cancel?.onClick?.(e), handleClose();
|
|
452
|
+
},
|
|
453
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
|
|
454
|
+
size: "$2",
|
|
455
|
+
color: "$color11",
|
|
456
|
+
children: toast.cancel.label
|
|
457
|
+
})
|
|
458
|
+
}), toast.action && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastActionFrame, {
|
|
459
|
+
backgroundColor: "$color12",
|
|
460
|
+
hoverStyle: {
|
|
461
|
+
backgroundColor: "$color11"
|
|
462
|
+
},
|
|
463
|
+
pressStyle: {
|
|
464
|
+
backgroundColor: "$color10"
|
|
465
|
+
},
|
|
466
|
+
onPress: e => {
|
|
467
|
+
toast.action?.onClick?.(e), e.defaultPrevented || handleClose();
|
|
468
|
+
},
|
|
469
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
|
|
470
|
+
size: "$2",
|
|
471
|
+
fontWeight: "600",
|
|
472
|
+
color: "$background",
|
|
473
|
+
children: toast.action.label
|
|
474
|
+
})
|
|
475
|
+
})]
|
|
476
|
+
})]
|
|
477
|
+
}), ctx.closeButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastClose, {})]
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
const ToastPositionWrapper = (0, import_core.styled)(import_stacks.YStack, {
|
|
481
|
+
name: "ToastPositionWrapper",
|
|
482
|
+
pointerEvents: "auto",
|
|
483
|
+
position: "absolute",
|
|
484
|
+
left: 0,
|
|
485
|
+
right: 0,
|
|
486
|
+
opacity: 1,
|
|
487
|
+
scale: 1,
|
|
488
|
+
y: 0,
|
|
489
|
+
x: 0
|
|
490
|
+
}),
|
|
491
|
+
ToastItemFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
492
|
+
name: "ToastItem",
|
|
493
|
+
userSelect: "none",
|
|
494
|
+
cursor: "grab",
|
|
495
|
+
focusable: !0,
|
|
496
|
+
variants: {
|
|
497
|
+
unstyled: {
|
|
498
|
+
false: {
|
|
499
|
+
backgroundColor: "$background",
|
|
500
|
+
borderRadius: "$4",
|
|
501
|
+
paddingHorizontal: "$4",
|
|
502
|
+
paddingVertical: "$3",
|
|
503
|
+
borderWidth: 1,
|
|
504
|
+
borderColor: "$borderColor",
|
|
505
|
+
shadowColor: "rgba(0, 0, 0, 0.15)",
|
|
506
|
+
shadowOffset: {
|
|
507
|
+
width: 0,
|
|
508
|
+
height: 4
|
|
509
|
+
},
|
|
510
|
+
shadowRadius: 12,
|
|
511
|
+
focusVisibleStyle: {
|
|
512
|
+
outlineWidth: 2,
|
|
513
|
+
outlineColor: "$color8",
|
|
514
|
+
outlineStyle: "solid"
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
defaultVariants: {
|
|
520
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
function DragWrapper({
|
|
524
|
+
animatedStyle,
|
|
525
|
+
gestureHandlers,
|
|
526
|
+
AnimatedView,
|
|
527
|
+
dragRef,
|
|
528
|
+
children
|
|
529
|
+
}) {
|
|
530
|
+
return import_constants.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
|
|
531
|
+
ref: dragRef,
|
|
532
|
+
style: {
|
|
533
|
+
flex: 1,
|
|
534
|
+
display: "flex",
|
|
535
|
+
flexDirection: "column",
|
|
536
|
+
userSelect: "none",
|
|
537
|
+
WebkitUserSelect: "none",
|
|
538
|
+
touchAction: "none",
|
|
539
|
+
cursor: "grab"
|
|
540
|
+
},
|
|
541
|
+
...gestureHandlers,
|
|
542
|
+
children
|
|
543
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
|
|
544
|
+
style: [{
|
|
545
|
+
flex: 1
|
|
546
|
+
}, animatedStyle],
|
|
547
|
+
...gestureHandlers,
|
|
548
|
+
children
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
const ToastItemInner = ToastItemFrame.styleable(function (props, ref) {
|
|
552
|
+
const {
|
|
553
|
+
toast,
|
|
554
|
+
index,
|
|
555
|
+
children,
|
|
556
|
+
...rest
|
|
557
|
+
} = props,
|
|
558
|
+
ctx = useToastContext(),
|
|
559
|
+
[mounted, setMounted] = React.useState(!1),
|
|
560
|
+
[removed, setRemoved] = React.useState(!1),
|
|
561
|
+
[swipeOut, setSwipeOut] = React.useState(!1),
|
|
562
|
+
closeTimerRef = React.useRef(null),
|
|
563
|
+
closeTimerStartRef = React.useRef(0),
|
|
564
|
+
lastPauseTimeRef = React.useRef(0),
|
|
565
|
+
remainingTimeRef = React.useRef(toast.duration ?? ctx.duration),
|
|
566
|
+
isFront = index === 0,
|
|
567
|
+
isVisible = index < ctx.visibleToasts,
|
|
568
|
+
toastType = toast.type ?? "default",
|
|
569
|
+
dismissible = toast.dismissible !== !1,
|
|
570
|
+
duration = toast.duration ?? ctx.duration,
|
|
571
|
+
[yPosition] = ctx.position.split("-"),
|
|
572
|
+
isTop = yPosition === "top",
|
|
573
|
+
toastsHeightBefore = React.useMemo(() => {
|
|
574
|
+
let total = 0;
|
|
575
|
+
for (let i = 0; i < index; i++) {
|
|
576
|
+
const toastId = ctx.toasts[i]?.id;
|
|
577
|
+
toastId != null && (total += ctx.heights[toastId] ?? 55);
|
|
578
|
+
}
|
|
579
|
+
return total;
|
|
580
|
+
}, [ctx.toasts, ctx.heights, index]),
|
|
581
|
+
startTimer = React.useCallback(() => {
|
|
582
|
+
duration === Number.POSITIVE_INFINITY || toastType === "loading" || (closeTimerStartRef.current = Date.now(), closeTimerRef.current = setTimeout(() => {
|
|
583
|
+
toast.onAutoClose?.(toast), setRemoved(!0), setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
|
|
584
|
+
}, remainingTimeRef.current));
|
|
585
|
+
}, [duration, toastType, toast, ctx.removeToast]),
|
|
586
|
+
pauseTimer = (0, import_core.useEvent)(() => {
|
|
587
|
+
if (closeTimerRef.current && clearTimeout(closeTimerRef.current), lastPauseTimeRef.current < closeTimerStartRef.current) {
|
|
588
|
+
const elapsed = Date.now() - closeTimerStartRef.current;
|
|
589
|
+
remainingTimeRef.current = Math.max(0, remainingTimeRef.current - elapsed);
|
|
590
|
+
}
|
|
591
|
+
lastPauseTimeRef.current = Date.now();
|
|
592
|
+
}),
|
|
593
|
+
resumeTimer = (0, import_core.useEvent)(() => {
|
|
594
|
+
startTimer();
|
|
595
|
+
});
|
|
596
|
+
React.useEffect(() => {
|
|
597
|
+
setMounted(!0);
|
|
598
|
+
}, []), React.useEffect(() => {
|
|
599
|
+
toast.delete && (setRemoved(!0), setTimeout(() => {
|
|
600
|
+
ctx.removeToast(toast);
|
|
601
|
+
}, TIME_BEFORE_UNMOUNT));
|
|
602
|
+
}, [toast.delete, toast, ctx.removeToast]), React.useEffect(() => (ctx.expanded || ctx.interacting ? pauseTimer() : startTimer(), () => {
|
|
603
|
+
closeTimerRef.current && clearTimeout(closeTimerRef.current);
|
|
604
|
+
}), [ctx.expanded, ctx.interacting, startTimer]), React.useEffect(() => {
|
|
605
|
+
remainingTimeRef.current = duration;
|
|
606
|
+
}, [duration]);
|
|
607
|
+
const {
|
|
608
|
+
setDragOffset,
|
|
609
|
+
springBack,
|
|
610
|
+
animateOut,
|
|
611
|
+
animatedStyle,
|
|
612
|
+
AnimatedView,
|
|
613
|
+
dragRef
|
|
614
|
+
} = (0, import_useToastAnimations.useToastAnimations)({
|
|
615
|
+
reducedMotion: ctx.reducedMotion
|
|
616
|
+
}),
|
|
617
|
+
{
|
|
618
|
+
isDragging,
|
|
619
|
+
gestureHandlers
|
|
620
|
+
} = (0, import_useAnimatedDragGesture.useAnimatedDragGesture)({
|
|
621
|
+
direction: ctx.swipeDirection,
|
|
622
|
+
threshold: ctx.swipeThreshold,
|
|
623
|
+
disabled: !dismissible || toastType === "loading",
|
|
624
|
+
expanded: ctx.expanded,
|
|
625
|
+
onDragStart: pauseTimer,
|
|
626
|
+
onDragMove: setDragOffset,
|
|
627
|
+
onDismiss: (exitDirection, velocity) => {
|
|
628
|
+
ctx.triggerDismissCooldown(), setSwipeOut(!0), toast.onDismiss?.(toast), setRemoved(!0), animateOut(exitDirection, velocity, () => {
|
|
629
|
+
ctx.removeToast(toast);
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
onCancel: () => {
|
|
633
|
+
springBack(() => {
|
|
634
|
+
resumeTimer();
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
}),
|
|
638
|
+
handleLayout = React.useCallback(event => {
|
|
639
|
+
const {
|
|
640
|
+
height
|
|
641
|
+
} = event.nativeEvent.layout;
|
|
642
|
+
ctx.setToastHeight(toast.id, height);
|
|
643
|
+
}, [toast.id, ctx.setToastHeight]);
|
|
644
|
+
React.useEffect(() => () => {
|
|
645
|
+
ctx.removeToastHeight(toast.id);
|
|
646
|
+
}, [toast.id, ctx.removeToastHeight]);
|
|
647
|
+
const handleClose = React.useCallback(() => {
|
|
648
|
+
dismissible && (toast.onDismiss?.(toast), setRemoved(!0), setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT));
|
|
649
|
+
}, [dismissible, toast, ctx.removeToast]),
|
|
650
|
+
frontToastId = ctx.toasts[0]?.id,
|
|
651
|
+
frontToastHeight = frontToastId != null ? ctx.heights[frontToastId] ?? 55 : 55,
|
|
652
|
+
stackScale = !ctx.expanded && !isFront ? 1 - index * 0.05 : 1,
|
|
653
|
+
expandedOffset = toastsHeightBefore + index * ctx.gap,
|
|
654
|
+
peekVisible = 10,
|
|
655
|
+
stackY = ctx.expanded ? isTop ? expandedOffset : -expandedOffset : isFront ? 0 : isTop ? peekVisible * index : -peekVisible * index,
|
|
656
|
+
computedOpacity = removed || index >= ctx.visibleToasts ? 0 : !ctx.expanded && index === ctx.visibleToasts - 1 ? 0.5 : 1,
|
|
657
|
+
computedZIndex = removed ? 0 : ctx.visibleToasts - index + 1,
|
|
658
|
+
computedHeight = !ctx.expanded && !isFront ? frontToastHeight : void 0,
|
|
659
|
+
computedPointerEvents = index >= ctx.visibleToasts ? "none" : "auto",
|
|
660
|
+
gapFillerHeight = ctx.expanded ? ctx.gap + 1 : 0,
|
|
661
|
+
dataAttributes = {
|
|
662
|
+
"data-mounted": mounted ? "true" : "false",
|
|
663
|
+
"data-removed": removed ? "true" : "false",
|
|
664
|
+
"data-swipe-out": swipeOut ? "true" : "false",
|
|
665
|
+
"data-visible": isVisible ? "true" : "false",
|
|
666
|
+
"data-front": isFront ? "true" : "false",
|
|
667
|
+
"data-index": String(index),
|
|
668
|
+
"data-type": toastType,
|
|
669
|
+
"data-expanded": ctx.expanded ? "true" : "false"
|
|
670
|
+
};
|
|
671
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastPositionWrapper, {
|
|
672
|
+
ref,
|
|
673
|
+
...dataAttributes,
|
|
674
|
+
onLayout: handleLayout,
|
|
675
|
+
transition: isDragging || ctx.reducedMotion ? void 0 : "200ms",
|
|
676
|
+
y: stackY,
|
|
677
|
+
scale: stackScale,
|
|
678
|
+
opacity: computedOpacity,
|
|
679
|
+
zIndex: computedZIndex,
|
|
680
|
+
height: computedHeight,
|
|
681
|
+
overflow: computedHeight ? "hidden" : void 0,
|
|
682
|
+
pointerEvents: computedPointerEvents,
|
|
683
|
+
top: isTop ? 0 : void 0,
|
|
684
|
+
bottom: isTop ? void 0 : 0,
|
|
685
|
+
...(import_constants.isWeb && !isFront && !ctx.expanded && {
|
|
686
|
+
style: {
|
|
687
|
+
transformOrigin: isTop ? "top center" : "bottom center"
|
|
688
|
+
}
|
|
689
|
+
}),
|
|
690
|
+
enterStyle: ctx.reducedMotion ? {
|
|
691
|
+
opacity: 0
|
|
692
|
+
} : {
|
|
693
|
+
opacity: 0,
|
|
694
|
+
y: isTop ? -10 : 10,
|
|
695
|
+
scale: 0.95
|
|
696
|
+
},
|
|
697
|
+
exitStyle: ctx.reducedMotion ? {
|
|
698
|
+
opacity: 0
|
|
699
|
+
} : swipeOut ? {
|
|
700
|
+
opacity: 0,
|
|
701
|
+
x: 0,
|
|
702
|
+
y: 0,
|
|
703
|
+
scale: 1
|
|
704
|
+
} : {
|
|
705
|
+
opacity: 0,
|
|
706
|
+
y: stackY,
|
|
707
|
+
scale: stackScale
|
|
708
|
+
},
|
|
709
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DragWrapper, {
|
|
710
|
+
animatedStyle,
|
|
711
|
+
gestureHandlers,
|
|
712
|
+
AnimatedView,
|
|
713
|
+
dragRef,
|
|
714
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(ToastItemFrame, {
|
|
715
|
+
role: "status",
|
|
716
|
+
"aria-live": "polite",
|
|
717
|
+
"aria-atomic": !0,
|
|
718
|
+
tabIndex: 0,
|
|
719
|
+
...(import_constants.isWeb && {
|
|
720
|
+
onKeyDown: event => {
|
|
721
|
+
event.key === "Escape" && dismissible && handleClose();
|
|
722
|
+
}
|
|
723
|
+
}),
|
|
724
|
+
...rest,
|
|
725
|
+
children: [ctx.expanded && gapFillerHeight > 0 && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
726
|
+
position: "absolute",
|
|
727
|
+
left: 0,
|
|
728
|
+
right: 0,
|
|
729
|
+
height: gapFillerHeight,
|
|
730
|
+
pointerEvents: "auto",
|
|
731
|
+
...(isTop ? {
|
|
732
|
+
top: "100%"
|
|
733
|
+
} : {
|
|
734
|
+
bottom: "100%"
|
|
735
|
+
})
|
|
736
|
+
}), children]
|
|
737
|
+
})
|
|
738
|
+
})
|
|
739
|
+
});
|
|
740
|
+
}),
|
|
741
|
+
ToastTitle = (0, import_core.styled)(import_text.SizableText, {
|
|
742
|
+
name: "ToastTitle",
|
|
743
|
+
variants: {
|
|
744
|
+
unstyled: {
|
|
745
|
+
false: {
|
|
746
|
+
color: "$color",
|
|
747
|
+
fontWeight: "600",
|
|
748
|
+
size: "$4"
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
defaultVariants: {
|
|
753
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
754
|
+
}
|
|
755
|
+
}),
|
|
756
|
+
ToastDescription = (0, import_core.styled)(import_text.SizableText, {
|
|
757
|
+
name: "ToastDescription",
|
|
758
|
+
variants: {
|
|
759
|
+
unstyled: {
|
|
760
|
+
false: {
|
|
761
|
+
color: "$color11",
|
|
762
|
+
size: "$2"
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
defaultVariants: {
|
|
767
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
768
|
+
}
|
|
769
|
+
}),
|
|
770
|
+
ToastCloseFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
771
|
+
name: "ToastClose",
|
|
772
|
+
render: "button",
|
|
773
|
+
alignItems: "center",
|
|
774
|
+
justifyContent: "center",
|
|
775
|
+
cursor: "pointer",
|
|
776
|
+
variants: {
|
|
777
|
+
unstyled: {
|
|
778
|
+
false: {
|
|
779
|
+
width: 20,
|
|
780
|
+
height: 20,
|
|
781
|
+
borderRadius: "$10",
|
|
782
|
+
backgroundColor: "$color5",
|
|
783
|
+
hoverStyle: {
|
|
784
|
+
backgroundColor: "$color6"
|
|
785
|
+
},
|
|
786
|
+
pressStyle: {
|
|
787
|
+
backgroundColor: "$color7"
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
defaultVariants: {
|
|
793
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
794
|
+
}
|
|
795
|
+
}),
|
|
796
|
+
ToastClose = ToastCloseFrame.styleable(function (props, ref) {
|
|
797
|
+
let handleClose;
|
|
798
|
+
try {
|
|
799
|
+
handleClose = useToastItemContext().handleClose;
|
|
800
|
+
} catch {}
|
|
801
|
+
const ctx = useToastContext();
|
|
802
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCloseFrame, {
|
|
803
|
+
ref,
|
|
804
|
+
"aria-label": "Close toast",
|
|
805
|
+
onPress: handleClose,
|
|
806
|
+
...props,
|
|
807
|
+
children: props.children ?? ctx.icons?.close ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultCloseIcon, {})
|
|
808
|
+
});
|
|
809
|
+
}),
|
|
810
|
+
ToastActionFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
811
|
+
name: "ToastAction",
|
|
812
|
+
render: "button",
|
|
813
|
+
alignItems: "center",
|
|
814
|
+
justifyContent: "center",
|
|
815
|
+
cursor: "pointer",
|
|
816
|
+
variants: {
|
|
817
|
+
unstyled: {
|
|
818
|
+
false: {
|
|
819
|
+
borderRadius: "$2",
|
|
820
|
+
paddingHorizontal: "$2",
|
|
821
|
+
height: 24,
|
|
822
|
+
backgroundColor: "$color5",
|
|
823
|
+
hoverStyle: {
|
|
824
|
+
backgroundColor: "$color6"
|
|
825
|
+
},
|
|
826
|
+
pressStyle: {
|
|
827
|
+
backgroundColor: "$color7"
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
defaultVariants: {
|
|
833
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
834
|
+
}
|
|
835
|
+
}),
|
|
836
|
+
ToastAction = ToastActionFrame.styleable(function (props, ref) {
|
|
837
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastActionFrame, {
|
|
838
|
+
ref,
|
|
839
|
+
...props
|
|
840
|
+
});
|
|
841
|
+
});
|
|
842
|
+
function ToastIcon(props) {
|
|
843
|
+
const ctx = useToastContext();
|
|
844
|
+
let toast;
|
|
845
|
+
try {
|
|
846
|
+
toast = useToastItemContext().toast;
|
|
847
|
+
} catch {
|
|
848
|
+
return null;
|
|
849
|
+
}
|
|
850
|
+
if (!toast) return null;
|
|
851
|
+
if (toast.icon !== void 0) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
852
|
+
flexShrink: 0,
|
|
853
|
+
marginTop: "$0.5",
|
|
854
|
+
children: toast.icon
|
|
855
|
+
});
|
|
856
|
+
const toastType = toast.type ?? "default",
|
|
857
|
+
icon = {
|
|
858
|
+
default: null,
|
|
859
|
+
success: ctx.icons?.success ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultSuccessIcon, {}),
|
|
860
|
+
error: ctx.icons?.error ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultErrorIcon, {}),
|
|
861
|
+
warning: ctx.icons?.warning ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultWarningIcon, {}),
|
|
862
|
+
info: ctx.icons?.info ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultInfoIcon, {}),
|
|
863
|
+
loading: ctx.icons?.loading ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultLoadingIcon, {})
|
|
864
|
+
}[toastType];
|
|
865
|
+
return icon ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
866
|
+
flexShrink: 0,
|
|
867
|
+
marginTop: "$0.5",
|
|
868
|
+
children: icon
|
|
869
|
+
}) : null;
|
|
870
|
+
}
|
|
871
|
+
function useToasts() {
|
|
872
|
+
const ctx = useToastContext();
|
|
873
|
+
return {
|
|
874
|
+
toasts: ctx.toasts,
|
|
875
|
+
expanded: ctx.expanded,
|
|
876
|
+
position: ctx.position
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
function useToastItem() {
|
|
880
|
+
return useToastItemContext();
|
|
881
|
+
}
|
|
882
|
+
const Toast = (0, import_helpers.withStaticProperties)(ToastRoot, {
|
|
883
|
+
Viewport: ToastViewport,
|
|
884
|
+
List: ToastList,
|
|
885
|
+
Item: ToastItemInner,
|
|
886
|
+
Title: ToastTitle,
|
|
887
|
+
Description: ToastDescription,
|
|
888
|
+
Close: ToastClose,
|
|
889
|
+
Action: ToastAction,
|
|
890
|
+
Icon: ToastIcon
|
|
891
|
+
});
|