@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
package/src/Toast.tsx DELETED
@@ -1,219 +0,0 @@
1
- import { AnimatePresence } from '@tamagui/animate-presence'
2
- import type { GetProps, NativePlatform, NativeValue, TamaguiElement } from '@tamagui/core'
3
- import { styled, useEvent } from '@tamagui/core'
4
- import { composeEventHandlers, withStaticProperties } from '@tamagui/helpers'
5
- import { YStack } from '@tamagui/stacks'
6
- import { SizableText } from '@tamagui/text'
7
- import { useControllableState } from '@tamagui/use-controllable-state'
8
- import * as React from 'react'
9
- import { ToastAnnounceExclude } from './ToastAnnounce'
10
- import type { CustomData } from './ToastImperative'
11
- import { useToast, useToastController, useToastState } from './ToastImperative'
12
- import type { ToastExtraProps, ToastProps } from './ToastImpl'
13
- import { ToastImpl, ToastImplFrame, useToastInteractiveContext } from './ToastImpl'
14
- import type { ScopedProps, ToastProviderProps } from './ToastProvider'
15
- import { ToastProvider } from './ToastProvider'
16
- import type { ToastViewportProps } from './ToastViewport'
17
- import { ToastViewport } from './ToastViewport'
18
-
19
- /* -------------------------------------------------------------------------------------------------
20
- * ToastTitle
21
- * -----------------------------------------------------------------------------------------------*/
22
-
23
- const TITLE_NAME = 'ToastTitle'
24
-
25
- const ToastTitle = styled(SizableText, {
26
- name: TITLE_NAME,
27
-
28
- variants: {
29
- unstyled: {
30
- false: {
31
- color: '$color',
32
- size: '$4',
33
- },
34
- },
35
- } as const,
36
-
37
- defaultVariants: {
38
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
39
- },
40
- })
41
-
42
- type ToastTitleProps = GetProps<typeof ToastTitle>
43
-
44
- /* -------------------------------------------------------------------------------------------------
45
- * ToastDescription
46
- * -----------------------------------------------------------------------------------------------*/
47
-
48
- const DESCRIPTION_NAME = 'ToastDescription'
49
-
50
- const ToastDescription = styled(SizableText, {
51
- name: DESCRIPTION_NAME,
52
-
53
- variants: {
54
- unstyled: {
55
- false: {
56
- color: '$color11',
57
- size: '$1',
58
- },
59
- },
60
- } as const,
61
-
62
- defaultVariants: {
63
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
64
- },
65
- })
66
-
67
- type ToastDescriptionProps = GetProps<typeof ToastDescription>
68
-
69
- /* -------------------------------------------------------------------------------------------------
70
- * ToastAction
71
- * -----------------------------------------------------------------------------------------------*/
72
-
73
- const ACTION_NAME = 'ToastAction'
74
-
75
- type ToastActionProps = ScopedProps<
76
- ToastCloseProps & {
77
- /**
78
- * A short description for an alternate way to carry out the action. For screen reader users
79
- * who will not be able to navigate to the button easily/quickly.
80
- * @example <ToastAction altText="Goto account settings to updgrade">Upgrade</ToastAction>
81
- * @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
82
- */
83
- altText: string
84
- }
85
- >
86
-
87
- const ToastAction = React.forwardRef<TamaguiElement, ScopedProps<ToastActionProps>>(
88
- function ToastAction(props, forwardedRef) {
89
- const { altText, ...actionProps } = props
90
- if (!altText) return null
91
- return (
92
- <ToastAnnounceExclude altText={altText} asChild>
93
- <ToastClose {...actionProps} ref={forwardedRef} />
94
- </ToastAnnounceExclude>
95
- )
96
- }
97
- )
98
-
99
- ToastAction.propTypes = {
100
- altText(props) {
101
- if (!props.altText) {
102
- return new Error(`Missing prop \`altText\` expected on \`${ACTION_NAME}\``)
103
- }
104
- return null
105
- },
106
- }
107
-
108
- /* -------------------------------------------------------------------------------------------------
109
- * ToastClose
110
- * -----------------------------------------------------------------------------------------------*/
111
-
112
- const CLOSE_NAME = 'ToastClose'
113
-
114
- const ToastCloseFrame = styled(YStack, {
115
- name: CLOSE_NAME,
116
- render: 'button',
117
- })
118
-
119
- type ToastCloseFrameProps = GetProps<typeof ToastCloseFrame>
120
- type ToastCloseProps = ScopedProps<ToastCloseFrameProps & {}>
121
-
122
- const ToastClose = React.forwardRef<TamaguiElement, ToastCloseProps>(
123
- function ToastClose(props, forwardedRef) {
124
- const { scope, ...closeProps } = props
125
- const interactiveContext = useToastInteractiveContext(scope)
126
-
127
- return (
128
- <ToastAnnounceExclude asChild>
129
- <ToastCloseFrame
130
- aria-label="Close"
131
- {...closeProps}
132
- ref={forwardedRef}
133
- onPress={composeEventHandlers(props.onPress as any, interactiveContext.onClose)}
134
- />
135
- </ToastAnnounceExclude>
136
- )
137
- }
138
- )
139
-
140
- /* -------------------------------------------------------------------------------------------------
141
- * Toast
142
- * -----------------------------------------------------------------------------------------------*/
143
-
144
- const ToastComponent = ToastImplFrame.styleable<ToastExtraProps>(
145
- function Toast(props, forwardedRef) {
146
- const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props
147
- const [open, setOpen] = useControllableState({
148
- prop: openProp,
149
- defaultProp: defaultOpen ?? true,
150
- onChange: onOpenChange,
151
- strategy: 'most-recent-wins',
152
- })
153
-
154
- const currentToast = useToastState()
155
- const { hide } = useToastController()
156
-
157
- const id = React.useId()
158
- const onPause = useEvent(props.onPause)
159
- const onResume = useEvent(props.onResume)
160
- const isHide = currentToast?.hide === true
161
- const shouldShow = (forceMount || open) && !isHide
162
-
163
- return (
164
- <AnimatePresence key={id}>
165
- {shouldShow ? (
166
- <ToastImpl
167
- id={id}
168
- open={open}
169
- {...toastProps}
170
- ref={forwardedRef}
171
- onClose={() => {
172
- setOpen(false)
173
- hide()
174
- }}
175
- onPause={onPause}
176
- onResume={onResume}
177
- onSwipeEnd={composeEventHandlers(props.onSwipeEnd, (event) => {
178
- setOpen(false)
179
- })}
180
- />
181
- ) : null}
182
- </AnimatePresence>
183
- )
184
- }
185
- )
186
-
187
- const Toast = withStaticProperties(ToastComponent, {
188
- Title: ToastTitle,
189
- Description: ToastDescription,
190
- Action: ToastAction,
191
- Close: ToastClose,
192
- })
193
-
194
- /* ---------------------------------------------------------------------------------------------- */
195
-
196
- export {
197
- Toast,
198
- ToastProvider,
199
- ToastViewport,
200
- //
201
- // imperative
202
- useToast,
203
- useToastController,
204
- useToastState,
205
- }
206
- export type {
207
- // imperative
208
- CustomData,
209
- ToastActionProps,
210
- ToastCloseProps,
211
- ToastDescriptionProps,
212
- NativePlatform as ToastNativePlatform,
213
- // backwards
214
- NativeValue as ToastNativeValue,
215
- ToastProps,
216
- ToastProviderProps,
217
- ToastTitleProps,
218
- ToastViewportProps,
219
- }
@@ -1,103 +0,0 @@
1
- import { useIsomorphicLayoutEffect } from '@tamagui/constants'
2
- import type { GetProps, TamaguiElement } from '@tamagui/core'
3
- import { View, Text, styled, useEvent } from '@tamagui/core'
4
- import { Portal } from '@tamagui/portal'
5
- import { startTransition } from '@tamagui/start-transition'
6
- import { VisuallyHidden } from '@tamagui/visually-hidden'
7
- import * as React from 'react'
8
-
9
- import type { ScopedProps } from './ToastProvider'
10
- import { useToastProviderContext } from './ToastProvider'
11
-
12
- const ToastAnnounceExcludeFrame = styled(View, {
13
- name: 'ToastAnnounceExclude',
14
- })
15
-
16
- type ToastAnnounceExcludeFrameProps = GetProps<typeof ToastAnnounceExcludeFrame>
17
-
18
- type ToastAnnounceExcludeExtraProps = {
19
- altText?: string
20
- }
21
-
22
- type ToastAnnounceExcludeProps = ToastAnnounceExcludeFrameProps &
23
- ToastAnnounceExcludeExtraProps
24
-
25
- const ToastAnnounceExclude = React.forwardRef<TamaguiElement, ToastAnnounceExcludeProps>(
26
- (props, forwardedRef) => {
27
- const { altText, ...announceExcludeProps } = props
28
-
29
- return (
30
- <ToastAnnounceExcludeFrame
31
- data-toast-announce-exclude=""
32
- data-toast-announce-alt={altText || undefined}
33
- {...announceExcludeProps}
34
- ref={forwardedRef}
35
- />
36
- )
37
- }
38
- )
39
-
40
- /* -----------------------------------------------------------------------------------------------*/
41
-
42
- interface ToastAnnounceProps
43
- extends
44
- Omit<GetProps<typeof VisuallyHidden>, 'children'>,
45
- ScopedProps<{ children: string[] }> {}
46
-
47
- const ToastAnnounce: React.FC<ToastAnnounceProps> = (
48
- props: ScopedProps<ToastAnnounceProps>
49
- ) => {
50
- const { scope, children, ...announceProps } = props
51
- const context = useToastProviderContext(scope)
52
- const [renderAnnounceText, setRenderAnnounceText] = React.useState(false)
53
- const [isAnnounced, setIsAnnounced] = React.useState(false)
54
-
55
- // render text content in the next frame to ensure toast is announced in NVDA
56
- useNextFrame(() => {
57
- startTransition(() => {
58
- setRenderAnnounceText(true)
59
- })
60
- })
61
-
62
- // cleanup after announcing
63
- React.useEffect(() => {
64
- const timer = setTimeout(() => setIsAnnounced(true), 1000)
65
- return () => clearTimeout(timer)
66
- }, [])
67
-
68
- return isAnnounced ? null : (
69
- <Portal>
70
- <VisuallyHidden {...announceProps}>
71
- {renderAnnounceText && (
72
- <Text>
73
- {context.label} {children}
74
- </Text>
75
- )}
76
- </VisuallyHidden>
77
- </Portal>
78
- )
79
- }
80
-
81
- /* -----------------------------------------------------------------------------------------------*/
82
-
83
- function useNextFrame(callback = () => {}) {
84
- const fn = useEvent(callback)
85
- useIsomorphicLayoutEffect(() => {
86
- let raf1 = 0
87
- let raf2 = 0
88
- raf1 = requestAnimationFrame(() => {
89
- raf2 = requestAnimationFrame(fn)
90
- })
91
- return () => {
92
- cancelAnimationFrame(raf1)
93
- cancelAnimationFrame(raf2)
94
- }
95
- }, [fn])
96
- }
97
-
98
- export {
99
- ToastAnnounce,
100
- ToastAnnounceExclude,
101
- type ToastAnnounceExcludeProps,
102
- type ToastAnnounceProps,
103
- }
@@ -1,192 +0,0 @@
1
- import type { NativePlatform, NativeValue } from '@tamagui/core'
2
- import { isAndroid, isIos, isWeb } from '@tamagui/core'
3
- import React from 'react'
4
- import { createNativeToast } from './createNativeToast'
5
- import type { CreateNativeToastOptions, NativeToastRef } from './types'
6
-
7
- export interface ToastImperativeOptions extends Omit<
8
- CreateNativeToastOptions,
9
- 'message'
10
- > {
11
- /**
12
- * Will show a native toast if is true or is set to the current platform. On iOS, it wraps `SPIndicator` and `SPAlert`. On Android, it wraps `ToastAndroid`. On web, it wraps Notification API. Mobile's native features are handled by `burnt`.
13
- */
14
- native?: NativeValue
15
- }
16
-
17
- /**
18
- * Override this in your application to get custom toast fields.
19
- *
20
- * e.g.
21
- * ```ts
22
- * declare module '@tamagui/toast' {
23
- * interface CustomData {
24
- * preset: 'error' | 'success'
25
- * isUrgent: true
26
- * }
27
- * }
28
- *```
29
- * You will get auto-completion:
30
- * ```ts
31
- * toast.show("Message", { preset: 'error', isUrgent: true })
32
- * ```
33
- */
34
- export interface CustomData {
35
- [key: string]: any
36
- }
37
-
38
- type ShowOptions = CreateNativeToastOptions &
39
- CustomData & {
40
- /**
41
- * Used when need custom data
42
- */
43
- customData?: CustomData
44
- /**
45
- * Overrides the native option on `ToastImperativeProvider`
46
- */
47
- native?: NativeValue
48
- /**
49
- * Which viewport to send this toast to. This is only intended to be used with custom toasts and you should wire it up when creating the toast.
50
- */
51
- viewportName?: string | 'default'
52
- }
53
-
54
- type ToastData = { title: string; id: string } & ShowOptions & {
55
- isHandledNatively: boolean
56
- } & CustomData
57
-
58
- interface ToastContextI {
59
- nativeToast: NativeToastRef | null
60
-
61
- /**
62
- * Call it to show a new toast. If you're using native toasts, you can pass native options using \`burntOptions\` or \`notificationOptions\` depending on the native platform (mobile/web).
63
- */
64
- show: (title: string, options?: ShowOptions) => boolean
65
-
66
- /**
67
- * Call it to hide the currently displayed toast.
68
- *
69
- * _NOTE_: does not work on Android native toasts
70
- *
71
- * _NOTE_: hides the last toast on web notification toasts
72
- */
73
- hide: () => void
74
-
75
- options?: ToastImperativeOptions
76
- }
77
-
78
- const ToastContext = React.createContext<ToastContextI>({} as any)
79
- const ToastCurrentContext = React.createContext<ToastData | null>(null)
80
-
81
- export const useToastController = () => {
82
- return React.useContext(ToastContext)
83
- }
84
-
85
- export const useToastState = () => {
86
- return React.useContext(ToastCurrentContext)
87
- }
88
-
89
- /** @deprecated use `useToastController` and `useToastState` instead to avoid performance pitfalls */
90
- export const useToast = () => {
91
- return {
92
- ...useToastController(),
93
- currentToast: useToastState(),
94
- }
95
- }
96
-
97
- interface ToastImperativeProviderProps {
98
- children: React.ReactNode
99
- /**
100
- * Used to provide defaults to imperative API. Options can be overwritten when calling `show()`.
101
- */
102
- options: ToastImperativeOptions
103
- }
104
-
105
- export const ToastImperativeProvider = ({
106
- children,
107
- options,
108
- }: ToastImperativeProviderProps) => {
109
- const counterRef = React.useRef(0)
110
-
111
- const [toast, setToast] = React.useState<ToastData | null>(null)
112
-
113
- const [lastNativeToastRef, setLastNativeToastRef] =
114
- React.useState<ToastContextI['nativeToast']>(null)
115
-
116
- const show = React.useCallback<ToastContextI['show']>(
117
- (title, showOptions) => {
118
- const native = showOptions?.native ?? options.native
119
- const isWebNative = Array.isArray(native)
120
- ? native.includes('web')
121
- : native === 'web'
122
- const isMobileNative = Array.isArray(native)
123
- ? native.includes('mobile')
124
- : native === 'mobile'
125
- const isAndroidNative =
126
- isMobileNative ||
127
- (Array.isArray(native) ? native.includes('android') : native === 'android')
128
- const isIosNative =
129
- isMobileNative ||
130
- (Array.isArray(native) ? native.includes('ios') : native === 'ios')
131
-
132
- const isHandledNatively =
133
- native === true ||
134
- (isWeb && isWebNative) ||
135
- (!isWeb && isMobileNative) ||
136
- (isAndroid && isAndroidNative) ||
137
- (isIos && isIosNative)
138
-
139
- if (isHandledNatively) {
140
- const nativeToastResult = createNativeToast(title, showOptions ?? {})
141
- if (typeof nativeToastResult === 'object' && nativeToastResult.nativeToastRef) {
142
- setLastNativeToastRef(nativeToastResult.nativeToastRef)
143
- }
144
- }
145
- counterRef.current++
146
- setToast({
147
- ...showOptions?.customData,
148
- ...showOptions,
149
- viewportName: showOptions?.viewportName ?? 'default',
150
- title,
151
- id: counterRef.current.toString(),
152
- isHandledNatively,
153
- })
154
- return true
155
- },
156
- [setToast, JSON.stringify(options.native || null)]
157
- )
158
-
159
- const hide = React.useCallback(() => {
160
- lastNativeToastRef?.close()
161
- setToast((prev) => {
162
- if (!prev) return null
163
- return {
164
- ...prev,
165
- hide: true,
166
- }
167
- })
168
-
169
- setTimeout(() => {
170
- setToast(null)
171
- }, 100)
172
- }, [setToast, lastNativeToastRef])
173
-
174
- const contextValue = React.useMemo(() => {
175
- return {
176
- show,
177
- hide,
178
- nativeToast: lastNativeToastRef,
179
- options,
180
- }
181
- }, [show, hide, lastNativeToastRef, JSON.stringify(options || null)])
182
-
183
- return (
184
- <ToastContext.Provider value={contextValue}>
185
- <ToastCurrentContext.Provider value={toast}>
186
- {children}
187
- </ToastCurrentContext.Provider>
188
- </ToastContext.Provider>
189
- )
190
- }
191
-
192
- export type { NativePlatform, NativeValue, ToastImperativeProviderProps }