@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.
- package/dist/cjs/Toast.cjs +149 -141
- package/dist/cjs/Toast.native.js +149 -142
- package/dist/cjs/Toast.native.js.map +1 -1
- package/dist/cjs/ToastAnnounce.cjs +78 -72
- package/dist/cjs/ToastAnnounce.native.js +85 -79
- package/dist/cjs/ToastAnnounce.native.js.map +1 -1
- package/dist/cjs/ToastComposable.cjs +780 -591
- package/dist/cjs/ToastComposable.native.js +863 -706
- package/dist/cjs/ToastComposable.native.js.map +1 -1
- package/dist/cjs/ToastImperative.cjs +99 -80
- package/dist/cjs/ToastImperative.native.js +104 -96
- package/dist/cjs/ToastImperative.native.js.map +1 -1
- package/dist/cjs/ToastImpl.cjs +300 -238
- package/dist/cjs/ToastImpl.native.js +309 -271
- package/dist/cjs/ToastImpl.native.js.map +1 -1
- package/dist/cjs/ToastItemFrame.cjs +143 -0
- package/dist/cjs/ToastItemFrame.native.js +148 -0
- package/dist/cjs/ToastItemFrame.native.js.map +1 -0
- package/dist/cjs/ToastPortal.cjs +23 -18
- package/dist/cjs/ToastPortal.native.js +27 -22
- package/dist/cjs/ToastPortal.native.js.map +1 -1
- package/dist/cjs/ToastProvider.cjs +102 -98
- package/dist/cjs/ToastProvider.native.js +108 -106
- package/dist/cjs/ToastProvider.native.js.map +1 -1
- package/dist/cjs/ToastState.cjs +218 -155
- package/dist/cjs/ToastState.native.js +270 -203
- package/dist/cjs/ToastState.native.js.map +1 -1
- package/dist/cjs/ToastViewport.cjs +274 -233
- package/dist/cjs/ToastViewport.native.js +301 -273
- package/dist/cjs/ToastViewport.native.js.map +1 -1
- package/dist/cjs/Toaster.cjs +71 -233
- package/dist/cjs/Toaster.native.js +72 -289
- package/dist/cjs/Toaster.native.js.map +1 -1
- package/dist/cjs/constants.cjs +14 -12
- package/dist/cjs/constants.native.js +14 -12
- package/dist/cjs/constants.native.js.map +1 -1
- package/dist/cjs/createNativeToast.cjs +43 -35
- package/dist/cjs/createNativeToast.native.js +42 -30
- package/dist/cjs/createNativeToast.native.js.map +1 -1
- package/dist/cjs/dispatchNativeToast.cjs +47 -0
- package/dist/cjs/dispatchNativeToast.native.js +52 -0
- package/dist/cjs/dispatchNativeToast.native.js.map +1 -0
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +7 -5
- package/dist/cjs/types.native.js +7 -5
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useAnimatedDragGesture.cjs +184 -83
- package/dist/cjs/useAnimatedDragGesture.native.js +193 -79
- package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/cjs/useReducedMotion.cjs +44 -30
- package/dist/cjs/useReducedMotion.native.js +52 -43
- package/dist/cjs/useReducedMotion.native.js.map +1 -1
- package/dist/cjs/useToastAnimations.cjs +233 -155
- package/dist/cjs/useToastAnimations.native.js +246 -170
- package/dist/cjs/useToastAnimations.native.js.map +1 -1
- package/dist/cjs/v2.cjs +36 -0
- package/dist/cjs/v2.native.js +39 -0
- package/dist/cjs/v2.native.js.map +1 -0
- package/dist/esm/Toast.mjs +112 -106
- package/dist/esm/Toast.mjs.map +1 -1
- package/dist/esm/Toast.native.js +112 -107
- package/dist/esm/Toast.native.js.map +1 -1
- package/dist/esm/ToastAnnounce.mjs +46 -42
- package/dist/esm/ToastAnnounce.mjs.map +1 -1
- package/dist/esm/ToastAnnounce.native.js +52 -48
- package/dist/esm/ToastAnnounce.native.js.map +1 -1
- package/dist/esm/ToastComposable.mjs +742 -555
- package/dist/esm/ToastComposable.mjs.map +1 -1
- package/dist/esm/ToastComposable.native.js +825 -670
- package/dist/esm/ToastComposable.native.js.map +1 -1
- package/dist/esm/ToastImperative.mjs +71 -54
- package/dist/esm/ToastImperative.mjs.map +1 -1
- package/dist/esm/ToastImperative.native.js +76 -70
- package/dist/esm/ToastImperative.native.js.map +1 -1
- package/dist/esm/ToastImpl.mjs +261 -201
- package/dist/esm/ToastImpl.mjs.map +1 -1
- package/dist/esm/ToastImpl.native.js +270 -234
- package/dist/esm/ToastImpl.native.js.map +1 -1
- package/dist/esm/ToastItemFrame.mjs +114 -0
- package/dist/esm/ToastItemFrame.mjs.map +1 -0
- package/dist/esm/ToastItemFrame.native.js +116 -0
- package/dist/esm/ToastItemFrame.native.js.map +1 -0
- package/dist/esm/ToastPortal.mjs +8 -5
- package/dist/esm/ToastPortal.mjs.map +1 -1
- package/dist/esm/ToastPortal.native.js +12 -9
- package/dist/esm/ToastPortal.native.js.map +1 -1
- package/dist/esm/ToastProvider.mjs +71 -69
- package/dist/esm/ToastProvider.mjs.map +1 -1
- package/dist/esm/ToastProvider.native.js +77 -77
- package/dist/esm/ToastProvider.native.js.map +1 -1
- package/dist/esm/ToastState.mjs +205 -144
- package/dist/esm/ToastState.mjs.map +1 -1
- package/dist/esm/ToastState.native.js +258 -193
- package/dist/esm/ToastState.native.js.map +1 -1
- package/dist/esm/ToastViewport.mjs +238 -199
- package/dist/esm/ToastViewport.mjs.map +1 -1
- package/dist/esm/ToastViewport.native.js +265 -239
- package/dist/esm/ToastViewport.native.js.map +1 -1
- package/dist/esm/Toaster.mjs +45 -209
- package/dist/esm/Toaster.mjs.map +1 -1
- package/dist/esm/Toaster.native.js +46 -265
- package/dist/esm/Toaster.native.js.map +1 -1
- package/dist/esm/constants.mjs +2 -2
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/constants.native.js +2 -2
- package/dist/esm/constants.native.js.map +1 -1
- package/dist/esm/createNativeToast.mjs +29 -24
- package/dist/esm/createNativeToast.mjs.map +1 -1
- package/dist/esm/createNativeToast.native.js +27 -18
- package/dist/esm/createNativeToast.native.js.map +1 -1
- package/dist/esm/dispatchNativeToast.mjs +22 -0
- package/dist/esm/dispatchNativeToast.mjs.map +1 -0
- package/dist/esm/dispatchNativeToast.native.js +24 -0
- package/dist/esm/dispatchNativeToast.native.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/useAnimatedDragGesture.mjs +160 -61
- package/dist/esm/useAnimatedDragGesture.mjs.map +1 -1
- package/dist/esm/useAnimatedDragGesture.native.js +167 -55
- package/dist/esm/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/esm/useReducedMotion.mjs +18 -6
- package/dist/esm/useReducedMotion.mjs.map +1 -1
- package/dist/esm/useReducedMotion.native.js +25 -18
- package/dist/esm/useReducedMotion.native.js.map +1 -1
- package/dist/esm/useToastAnimations.mjs +206 -130
- package/dist/esm/useToastAnimations.mjs.map +1 -1
- package/dist/esm/useToastAnimations.native.js +218 -144
- package/dist/esm/useToastAnimations.native.js.map +1 -1
- package/dist/esm/v2.mjs +6 -0
- package/dist/esm/v2.mjs.map +1 -0
- package/dist/esm/v2.native.js +6 -0
- package/dist/esm/v2.native.js.map +1 -0
- package/dist/jsx/Toast.mjs +112 -106
- package/dist/jsx/Toast.mjs.map +1 -1
- package/dist/jsx/Toast.native.js +149 -142
- package/dist/jsx/Toast.native.js.map +1 -1
- package/dist/jsx/ToastAnnounce.mjs +46 -42
- package/dist/jsx/ToastAnnounce.mjs.map +1 -1
- package/dist/jsx/ToastAnnounce.native.js +85 -79
- package/dist/jsx/ToastAnnounce.native.js.map +1 -1
- package/dist/jsx/ToastComposable.mjs +742 -555
- package/dist/jsx/ToastComposable.mjs.map +1 -1
- package/dist/jsx/ToastComposable.native.js +863 -706
- package/dist/jsx/ToastComposable.native.js.map +1 -1
- package/dist/jsx/ToastImperative.mjs +71 -54
- package/dist/jsx/ToastImperative.mjs.map +1 -1
- package/dist/jsx/ToastImperative.native.js +104 -96
- package/dist/jsx/ToastImperative.native.js.map +1 -1
- package/dist/jsx/ToastImpl.mjs +261 -201
- package/dist/jsx/ToastImpl.mjs.map +1 -1
- package/dist/jsx/ToastImpl.native.js +309 -271
- package/dist/jsx/ToastImpl.native.js.map +1 -1
- package/dist/jsx/ToastItemFrame.mjs +114 -0
- package/dist/jsx/ToastItemFrame.mjs.map +1 -0
- package/dist/jsx/ToastItemFrame.native.js +148 -0
- package/dist/jsx/ToastItemFrame.native.js.map +1 -0
- package/dist/jsx/ToastPortal.mjs +8 -5
- package/dist/jsx/ToastPortal.mjs.map +1 -1
- package/dist/jsx/ToastPortal.native.js +27 -22
- package/dist/jsx/ToastPortal.native.js.map +1 -1
- package/dist/jsx/ToastProvider.mjs +71 -69
- package/dist/jsx/ToastProvider.mjs.map +1 -1
- package/dist/jsx/ToastProvider.native.js +108 -106
- package/dist/jsx/ToastProvider.native.js.map +1 -1
- package/dist/jsx/ToastState.mjs +205 -144
- package/dist/jsx/ToastState.mjs.map +1 -1
- package/dist/jsx/ToastState.native.js +270 -203
- package/dist/jsx/ToastState.native.js.map +1 -1
- package/dist/jsx/ToastViewport.mjs +238 -199
- package/dist/jsx/ToastViewport.mjs.map +1 -1
- package/dist/jsx/ToastViewport.native.js +301 -273
- package/dist/jsx/ToastViewport.native.js.map +1 -1
- package/dist/jsx/Toaster.mjs +45 -209
- package/dist/jsx/Toaster.mjs.map +1 -1
- package/dist/jsx/Toaster.native.js +72 -289
- package/dist/jsx/Toaster.native.js.map +1 -1
- package/dist/jsx/constants.mjs +2 -2
- package/dist/jsx/constants.mjs.map +1 -1
- package/dist/jsx/constants.native.js +14 -12
- package/dist/jsx/constants.native.js.map +1 -1
- package/dist/jsx/createNativeToast.mjs +29 -24
- package/dist/jsx/createNativeToast.mjs.map +1 -1
- package/dist/jsx/createNativeToast.native.js +42 -30
- package/dist/jsx/createNativeToast.native.js.map +1 -1
- package/dist/jsx/dispatchNativeToast.mjs +22 -0
- package/dist/jsx/dispatchNativeToast.mjs.map +1 -0
- package/dist/jsx/dispatchNativeToast.native.js +52 -0
- package/dist/jsx/dispatchNativeToast.native.js.map +1 -0
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -6
- package/dist/jsx/index.native.js +7 -5
- package/dist/jsx/types.native.js +7 -5
- package/dist/jsx/useAnimatedDragGesture.mjs +160 -61
- package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -1
- package/dist/jsx/useAnimatedDragGesture.native.js +193 -79
- package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/jsx/useReducedMotion.mjs +18 -6
- package/dist/jsx/useReducedMotion.mjs.map +1 -1
- package/dist/jsx/useReducedMotion.native.js +52 -43
- package/dist/jsx/useReducedMotion.native.js.map +1 -1
- package/dist/jsx/useToastAnimations.mjs +206 -130
- package/dist/jsx/useToastAnimations.mjs.map +1 -1
- package/dist/jsx/useToastAnimations.native.js +246 -170
- package/dist/jsx/useToastAnimations.native.js.map +1 -1
- package/dist/jsx/v2.mjs +6 -0
- package/dist/jsx/v2.mjs.map +1 -0
- package/dist/jsx/v2.native.js +39 -0
- package/dist/jsx/v2.native.js.map +1 -0
- package/package.json +42 -29
- package/src/ToastComposable.tsx +1380 -0
- package/src/ToastImpl.tsx +14 -2
- package/src/ToastItemFrame.tsx +136 -0
- package/src/ToastPortal.tsx +2 -2
- package/src/ToastProvider.tsx +8 -1
- package/src/ToastState.ts +398 -0
- package/src/ToastViewport.tsx +4 -3
- package/src/Toaster.tsx +181 -0
- package/src/createNativeToast.native.tsx +4 -0
- package/src/createNativeToast.tsx +18 -24
- package/src/dispatchNativeToast.ts +43 -0
- package/src/useAnimatedDragGesture.native.ts +255 -0
- package/src/useAnimatedDragGesture.ts +319 -0
- package/src/useReducedMotion.ts +59 -0
- package/src/useToastAnimations.ts +372 -0
- package/src/v2.ts +31 -0
- package/types/ToastComposable.d.ts +199 -0
- package/types/ToastComposable.d.ts.map +1 -1
- package/types/ToastImpl.d.ts.map +1 -1
- package/types/ToastItemFrame.d.ts +25 -0
- package/types/ToastItemFrame.d.ts.map +1 -0
- package/types/ToastPortal.d.ts.map +1 -1
- package/types/ToastProvider.d.ts +1 -1
- package/types/ToastProvider.d.ts.map +1 -1
- package/types/ToastState.d.ts +179 -0
- package/types/ToastState.d.ts.map +1 -1
- package/types/ToastViewport.d.ts.map +1 -1
- package/types/Toaster.d.ts +112 -0
- package/types/Toaster.d.ts.map +1 -1
- package/types/createNativeToast.d.ts +5 -0
- package/types/createNativeToast.d.ts.map +1 -1
- package/types/createNativeToast.native.d.ts +1 -0
- package/types/createNativeToast.native.d.ts.map +1 -1
- package/types/dispatchNativeToast.d.ts +12 -0
- package/types/dispatchNativeToast.d.ts.map +1 -0
- package/types/useAnimatedDragGesture.d.ts +33 -0
- package/types/useAnimatedDragGesture.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.native.d.ts +33 -0
- package/types/useAnimatedDragGesture.native.d.ts.map +1 -1
- package/types/useReducedMotion.d.ts +6 -0
- package/types/useToastAnimations.d.ts +50 -0
- package/types/useToastAnimations.d.ts.map +1 -1
- package/types/v2.d.ts +10 -0
- package/types/v2.d.ts.map +1 -0
- package/v2/index.cjs +2 -0
- package/v2/index.js +2 -0
- package/v2/index.native.cjs +2 -0
- package/v2/index.native.js +2 -0
- package/LICENSE +0 -21
- package/dist/cjs/Toast.js +0 -119
- package/dist/cjs/Toast.js.map +0 -6
- package/dist/cjs/ToastAnnounce.js +0 -72
- package/dist/cjs/ToastAnnounce.js.map +0 -6
- package/dist/cjs/ToastComposable.js +0 -548
- package/dist/cjs/ToastComposable.js.map +0 -6
- package/dist/cjs/ToastImperative.js +0 -71
- package/dist/cjs/ToastImperative.js.map +0 -6
- package/dist/cjs/ToastImpl.js +0 -227
- package/dist/cjs/ToastImpl.js.map +0 -6
- package/dist/cjs/ToastItem.cjs +0 -526
- package/dist/cjs/ToastItem.js +0 -409
- package/dist/cjs/ToastItem.js.map +0 -6
- package/dist/cjs/ToastItem.native.js +0 -614
- package/dist/cjs/ToastItem.native.js.map +0 -1
- package/dist/cjs/ToastPortal.js +0 -26
- package/dist/cjs/ToastPortal.js.map +0 -6
- package/dist/cjs/ToastProvider.js +0 -105
- package/dist/cjs/ToastProvider.js.map +0 -6
- package/dist/cjs/ToastState.js +0 -160
- package/dist/cjs/ToastState.js.map +0 -6
- package/dist/cjs/ToastViewport.js +0 -263
- package/dist/cjs/ToastViewport.js.map +0 -6
- package/dist/cjs/Toaster.js +0 -204
- package/dist/cjs/Toaster.js.map +0 -6
- package/dist/cjs/constants.js +0 -22
- package/dist/cjs/constants.js.map +0 -6
- package/dist/cjs/createNativeToast.js +0 -44
- package/dist/cjs/createNativeToast.js.map +0 -6
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/types.js +0 -14
- package/dist/cjs/types.js.map +0 -6
- package/dist/cjs/useAnimatedDragGesture.js +0 -97
- package/dist/cjs/useAnimatedDragGesture.js.map +0 -6
- package/dist/cjs/useDragGesture.cjs +0 -129
- package/dist/cjs/useDragGesture.js +0 -100
- package/dist/cjs/useDragGesture.js.map +0 -6
- package/dist/cjs/useDragGesture.native.js +0 -146
- package/dist/cjs/useDragGesture.native.js.map +0 -1
- package/dist/cjs/useReducedMotion.js +0 -53
- package/dist/cjs/useReducedMotion.js.map +0 -6
- package/dist/cjs/useToastAnimations.js +0 -144
- package/dist/cjs/useToastAnimations.js.map +0 -6
- package/dist/cjs/v1.cjs +0 -31
- package/dist/cjs/v1.js +0 -26
- package/dist/cjs/v1.js.map +0 -6
- package/dist/cjs/v1.native.js +0 -34
- package/dist/cjs/v1.native.js.map +0 -1
- package/dist/esm/Toast.js +0 -107
- package/dist/esm/Toast.js.map +0 -6
- package/dist/esm/ToastAnnounce.js +0 -55
- package/dist/esm/ToastAnnounce.js.map +0 -6
- package/dist/esm/ToastComposable.js +0 -543
- package/dist/esm/ToastComposable.js.map +0 -6
- package/dist/esm/ToastImperative.js +0 -50
- package/dist/esm/ToastImperative.js.map +0 -6
- package/dist/esm/ToastImpl.js +0 -225
- package/dist/esm/ToastImpl.js.map +0 -6
- package/dist/esm/ToastItem.js +0 -393
- package/dist/esm/ToastItem.js.map +0 -6
- package/dist/esm/ToastItem.mjs +0 -492
- package/dist/esm/ToastItem.mjs.map +0 -1
- package/dist/esm/ToastItem.native.js +0 -577
- package/dist/esm/ToastItem.native.js.map +0 -1
- package/dist/esm/ToastPortal.js +0 -13
- package/dist/esm/ToastPortal.js.map +0 -6
- package/dist/esm/ToastProvider.js +0 -87
- package/dist/esm/ToastProvider.js.map +0 -6
- package/dist/esm/ToastState.js +0 -144
- package/dist/esm/ToastState.js.map +0 -6
- package/dist/esm/ToastViewport.js +0 -250
- package/dist/esm/ToastViewport.js.map +0 -6
- package/dist/esm/Toaster.js +0 -188
- package/dist/esm/Toaster.js.map +0 -6
- package/dist/esm/constants.js +0 -6
- package/dist/esm/constants.js.map +0 -6
- package/dist/esm/createNativeToast.js +0 -28
- package/dist/esm/createNativeToast.js.map +0 -6
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -6
- package/dist/esm/useAnimatedDragGesture.js +0 -73
- package/dist/esm/useAnimatedDragGesture.js.map +0 -6
- package/dist/esm/useDragGesture.js +0 -76
- package/dist/esm/useDragGesture.js.map +0 -6
- package/dist/esm/useDragGesture.mjs +0 -95
- package/dist/esm/useDragGesture.mjs.map +0 -1
- package/dist/esm/useDragGesture.native.js +0 -109
- package/dist/esm/useDragGesture.native.js.map +0 -1
- package/dist/esm/useReducedMotion.js +0 -30
- package/dist/esm/useReducedMotion.js.map +0 -6
- package/dist/esm/useToastAnimations.js +0 -122
- package/dist/esm/useToastAnimations.js.map +0 -6
- package/dist/esm/v1.js +0 -17
- package/dist/esm/v1.js.map +0 -6
- package/dist/esm/v1.mjs +0 -3
- package/dist/esm/v1.mjs.map +0 -1
- package/dist/esm/v1.native.js +0 -3
- package/dist/esm/v1.native.js.map +0 -1
- package/dist/jsx/Toast.js +0 -107
- package/dist/jsx/Toast.js.map +0 -6
- package/dist/jsx/ToastAnnounce.js +0 -55
- package/dist/jsx/ToastAnnounce.js.map +0 -6
- package/dist/jsx/ToastComposable.js +0 -543
- package/dist/jsx/ToastComposable.js.map +0 -6
- package/dist/jsx/ToastImperative.js +0 -50
- package/dist/jsx/ToastImperative.js.map +0 -6
- package/dist/jsx/ToastImpl.js +0 -225
- package/dist/jsx/ToastImpl.js.map +0 -6
- package/dist/jsx/ToastItem.js +0 -393
- package/dist/jsx/ToastItem.js.map +0 -6
- package/dist/jsx/ToastItem.mjs +0 -492
- package/dist/jsx/ToastItem.mjs.map +0 -1
- package/dist/jsx/ToastItem.native.js +0 -614
- package/dist/jsx/ToastItem.native.js.map +0 -1
- package/dist/jsx/ToastPortal.js +0 -13
- package/dist/jsx/ToastPortal.js.map +0 -6
- package/dist/jsx/ToastProvider.js +0 -87
- package/dist/jsx/ToastProvider.js.map +0 -6
- package/dist/jsx/ToastState.js +0 -144
- package/dist/jsx/ToastState.js.map +0 -6
- package/dist/jsx/ToastViewport.js +0 -250
- package/dist/jsx/ToastViewport.js.map +0 -6
- package/dist/jsx/Toaster.js +0 -188
- package/dist/jsx/Toaster.js.map +0 -6
- package/dist/jsx/constants.js +0 -6
- package/dist/jsx/constants.js.map +0 -6
- package/dist/jsx/createNativeToast.js +0 -28
- package/dist/jsx/createNativeToast.js.map +0 -6
- package/dist/jsx/types.js +0 -1
- package/dist/jsx/types.js.map +0 -6
- package/dist/jsx/useAnimatedDragGesture.js +0 -73
- package/dist/jsx/useAnimatedDragGesture.js.map +0 -6
- package/dist/jsx/useDragGesture.js +0 -76
- package/dist/jsx/useDragGesture.js.map +0 -6
- package/dist/jsx/useDragGesture.mjs +0 -95
- package/dist/jsx/useDragGesture.mjs.map +0 -1
- package/dist/jsx/useDragGesture.native.js +0 -146
- package/dist/jsx/useDragGesture.native.js.map +0 -1
- package/dist/jsx/useReducedMotion.js +0 -30
- package/dist/jsx/useReducedMotion.js.map +0 -6
- package/dist/jsx/useToastAnimations.js +0 -122
- package/dist/jsx/useToastAnimations.js.map +0 -6
- package/dist/jsx/v1.js +0 -17
- package/dist/jsx/v1.js.map +0 -6
- package/dist/jsx/v1.mjs +0 -3
- package/dist/jsx/v1.mjs.map +0 -1
- package/dist/jsx/v1.native.js +0 -34
- package/dist/jsx/v1.native.js.map +0 -1
- package/types/ToastItem.d.ts.map +0 -1
- package/types/useDragGesture.d.ts.map +0 -1
- package/types/useDragGesture.native.d.ts.map +0 -1
- 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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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)
|
|
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
|
-
|
|
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,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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:
|
|
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
|
-
|
|
92
|
-
...toasts2
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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: [
|
|
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)
|
|
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)
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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
|
-
|
|
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)
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
-
})
|
|
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,
|