@tamagui/toast 2.0.0-rc.8 → 2.0.0

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