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