@tamagui/toast 2.7.7 → 3.0.0-beta.643.1

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