@hanzogui/toast 8.3.1 → 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 +48 -44
- 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
|
@@ -0,0 +1,849 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Toast = void 0;
|
|
4
|
+
exports.useToasts = useToasts;
|
|
5
|
+
exports.useToastItem = useToastItem;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const animate_presence_1 = require("@hanzogui/animate-presence");
|
|
9
|
+
const constants_1 = require("@hanzogui/constants");
|
|
10
|
+
const native_1 = require("@hanzogui/native");
|
|
11
|
+
const core_1 = require("@hanzogui/core");
|
|
12
|
+
const helpers_1 = require("@hanzogui/helpers");
|
|
13
|
+
const portal_1 = require("@hanzogui/portal");
|
|
14
|
+
const stacks_1 = require("@hanzogui/stacks");
|
|
15
|
+
const text_1 = require("@hanzogui/text");
|
|
16
|
+
const React = tslib_1.__importStar(require("react"));
|
|
17
|
+
const ToastState_ts_1 = require("./ToastState.js");
|
|
18
|
+
const dispatchNativeToast_ts_1 = require("./dispatchNativeToast.js");
|
|
19
|
+
const useAnimatedDragGesture_ts_1 = require("./useAnimatedDragGesture.js");
|
|
20
|
+
const useToastAnimations_ts_1 = require("./useToastAnimations.js");
|
|
21
|
+
const useReducedMotion_ts_1 = require("./useReducedMotion.js");
|
|
22
|
+
const ToastItemFrame_tsx_1 = require("./ToastItemFrame.js");
|
|
23
|
+
// defaults
|
|
24
|
+
const VISIBLE_TOASTS_AMOUNT = 4;
|
|
25
|
+
const VIEWPORT_OFFSET = 16;
|
|
26
|
+
const TOAST_GAP = 14;
|
|
27
|
+
const TOAST_LIFETIME = 4000;
|
|
28
|
+
const FIXED_TOAST_HEIGHT = 72;
|
|
29
|
+
const TIME_BEFORE_UNMOUNT = 200;
|
|
30
|
+
const DEFAULT_HOTKEY = ['altKey', 'KeyT'];
|
|
31
|
+
const ToastContext = (0, core_1.createStyledContext)({}, 'Toast__');
|
|
32
|
+
const useToastContextValue = ToastContext.useStyledContext;
|
|
33
|
+
function hasToastContext(ctx) {
|
|
34
|
+
return (!!ctx &&
|
|
35
|
+
Array.isArray(ctx.toasts) &&
|
|
36
|
+
typeof ctx.setToastHeight === 'function' &&
|
|
37
|
+
typeof ctx.removeToast === 'function');
|
|
38
|
+
}
|
|
39
|
+
function useToastContext(consumerName) {
|
|
40
|
+
const ctx = useToastContextValue();
|
|
41
|
+
if (!hasToastContext(ctx)) {
|
|
42
|
+
throw new Error(`\`${consumerName}\` must be used within \`Toast\``);
|
|
43
|
+
}
|
|
44
|
+
return ctx;
|
|
45
|
+
}
|
|
46
|
+
const ToastItemContext = React.createContext(null);
|
|
47
|
+
function useToastItemContext() {
|
|
48
|
+
const ctx = React.useContext(ToastItemContext);
|
|
49
|
+
if (!ctx) {
|
|
50
|
+
throw new Error('useToastItemContext must be used within Toast.Item or Toast.List');
|
|
51
|
+
}
|
|
52
|
+
return ctx;
|
|
53
|
+
}
|
|
54
|
+
function resolveSwipeDirection(direction, position) {
|
|
55
|
+
if (direction !== 'auto')
|
|
56
|
+
return direction;
|
|
57
|
+
const [yPosition, xPosition] = position.split('-');
|
|
58
|
+
if (!constants_1.isWeb) {
|
|
59
|
+
// on native, always use vertical swipe to avoid conflicting with
|
|
60
|
+
// iOS/Android navigation back gesture (horizontal edge swipe)
|
|
61
|
+
return yPosition === 'top' ? 'up' : 'down';
|
|
62
|
+
}
|
|
63
|
+
if (xPosition === 'left')
|
|
64
|
+
return 'left';
|
|
65
|
+
if (xPosition === 'right')
|
|
66
|
+
return 'right';
|
|
67
|
+
// center positions: horizontal swipe feels most natural
|
|
68
|
+
return 'horizontal';
|
|
69
|
+
}
|
|
70
|
+
const ToastRoot = React.forwardRef(function ToastRoot(props, _ref) {
|
|
71
|
+
const { children, position = 'bottom-right', duration = TOAST_LIFETIME, gap = TOAST_GAP, visibleToasts = VISIBLE_TOASTS_AMOUNT, swipeDirection: swipeDirectionProp = 'auto', swipeThreshold = 50, toastHeight = FIXED_TOAST_HEIGHT, closeButton = false, expand = false, theme: themeProp, reducedMotion: reducedMotionProp, native = false, burntOptions, notificationOptions, icons, } = props;
|
|
72
|
+
const reducedMotion = (0, useReducedMotion_ts_1.useReducedMotion)(reducedMotionProp);
|
|
73
|
+
const [toasts, setToasts] = React.useState([]);
|
|
74
|
+
const [heights, setHeights] = React.useState({});
|
|
75
|
+
const [localExpanded, setExpanded] = React.useState(false);
|
|
76
|
+
const expanded = expand || localExpanded;
|
|
77
|
+
const [interacting, setInteracting] = React.useState(false);
|
|
78
|
+
// Lock height updates during expand/collapse CSS transition to prevent
|
|
79
|
+
// font-loading onLayout corrections from restarting the animation mid-flight.
|
|
80
|
+
// useLayoutEffect fires before paint, so the lock is set before any onLayout callbacks.
|
|
81
|
+
const heightsLockedRef = React.useRef(false);
|
|
82
|
+
const prevExpandedRef = React.useRef(expanded);
|
|
83
|
+
React.useLayoutEffect(() => {
|
|
84
|
+
if (prevExpandedRef.current !== expanded) {
|
|
85
|
+
heightsLockedRef.current = true;
|
|
86
|
+
prevExpandedRef.current = expanded;
|
|
87
|
+
}
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
heightsLockedRef.current = false;
|
|
90
|
+
}, 350);
|
|
91
|
+
return () => clearTimeout(timer);
|
|
92
|
+
}, [expanded]);
|
|
93
|
+
// Round + skip small changes to prevent cascading re-renders from
|
|
94
|
+
// sub-pixel onLayout jitter during font loading or CSS transitions
|
|
95
|
+
const setToastHeight = React.useCallback((toastId, height) => {
|
|
96
|
+
if (heightsLockedRef.current)
|
|
97
|
+
return;
|
|
98
|
+
const rounded = Math.round(height);
|
|
99
|
+
setHeights((prev) => {
|
|
100
|
+
const existing = prev[toastId];
|
|
101
|
+
if (existing != null && Math.abs(existing - rounded) <= 2)
|
|
102
|
+
return prev;
|
|
103
|
+
return { ...prev, [toastId]: rounded };
|
|
104
|
+
});
|
|
105
|
+
}, []);
|
|
106
|
+
const removeToastHeight = React.useCallback((toastId) => {
|
|
107
|
+
setHeights((prev) => {
|
|
108
|
+
if (!(toastId in prev))
|
|
109
|
+
return prev;
|
|
110
|
+
const next = { ...prev };
|
|
111
|
+
delete next[toastId];
|
|
112
|
+
return next;
|
|
113
|
+
});
|
|
114
|
+
}, []);
|
|
115
|
+
// Cooldown after dismiss - prevents collapse while stack rebalances
|
|
116
|
+
const dismissCooldownRef = React.useRef(false);
|
|
117
|
+
const dismissCooldownTimerRef = React.useRef(null);
|
|
118
|
+
const triggerDismissCooldown = React.useCallback(() => {
|
|
119
|
+
dismissCooldownRef.current = true;
|
|
120
|
+
if (dismissCooldownTimerRef.current) {
|
|
121
|
+
clearTimeout(dismissCooldownTimerRef.current);
|
|
122
|
+
}
|
|
123
|
+
dismissCooldownTimerRef.current = setTimeout(() => {
|
|
124
|
+
dismissCooldownRef.current = false;
|
|
125
|
+
}, 800);
|
|
126
|
+
}, []);
|
|
127
|
+
const isInDismissCooldown = React.useCallback(() => dismissCooldownRef.current, []);
|
|
128
|
+
// Store object props in refs so the subscription effect doesn't
|
|
129
|
+
// re-subscribe on every render when consumers pass inline objects.
|
|
130
|
+
const burntOptionsRef = React.useRef(burntOptions);
|
|
131
|
+
const notificationOptionsRef = React.useRef(notificationOptions);
|
|
132
|
+
React.useEffect(() => {
|
|
133
|
+
burntOptionsRef.current = burntOptions;
|
|
134
|
+
}, [burntOptions]);
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
notificationOptionsRef.current = notificationOptions;
|
|
137
|
+
}, [notificationOptions]);
|
|
138
|
+
// subscribe to toast state
|
|
139
|
+
React.useEffect(() => {
|
|
140
|
+
return ToastState_ts_1.ToastState.subscribe((toast) => {
|
|
141
|
+
if (toast.dismiss) {
|
|
142
|
+
setToasts((toasts) => toasts.map((t) => (t.id === toast.id ? { ...t, delete: true } : t)));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Native dispatch: intercept before entering state so no in-app toast renders.
|
|
146
|
+
// On failure (e.g. permission denied), falls through to in-app.
|
|
147
|
+
if (native) {
|
|
148
|
+
const handled = (0, dispatchNativeToast_ts_1.dispatchNativeToast)(toast, {
|
|
149
|
+
duration,
|
|
150
|
+
burntOptions: burntOptionsRef.current,
|
|
151
|
+
notificationOptions: notificationOptionsRef.current,
|
|
152
|
+
});
|
|
153
|
+
if (handled)
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
setToasts((toasts) => {
|
|
157
|
+
const idx = toasts.findIndex((t) => t.id === toast.id);
|
|
158
|
+
if (idx !== -1) {
|
|
159
|
+
return [
|
|
160
|
+
...toasts.slice(0, idx),
|
|
161
|
+
{ ...toasts[idx], ...toast },
|
|
162
|
+
...toasts.slice(idx + 1),
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
return [toast, ...toasts];
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}, [native, duration]);
|
|
169
|
+
// collapse when 1 toast left, or when a new toast is added while expanded
|
|
170
|
+
const prevToastCountRef = React.useRef(toasts.length);
|
|
171
|
+
React.useEffect(() => {
|
|
172
|
+
const prevCount = prevToastCountRef.current;
|
|
173
|
+
prevToastCountRef.current = toasts.length;
|
|
174
|
+
if (toasts.length <= 1 && !dismissCooldownRef.current) {
|
|
175
|
+
setExpanded(false);
|
|
176
|
+
}
|
|
177
|
+
else if (toasts.length > prevCount && expanded) {
|
|
178
|
+
// new toast added while expanded — collapse to show the new front toast
|
|
179
|
+
setExpanded(false);
|
|
180
|
+
}
|
|
181
|
+
}, [toasts.length, expanded]);
|
|
182
|
+
const removeToast = React.useCallback((toastToRemove) => {
|
|
183
|
+
setToasts((toasts) => {
|
|
184
|
+
if (!toasts.find((t) => t.id === toastToRemove.id)?.delete) {
|
|
185
|
+
ToastState_ts_1.ToastState.dismiss(toastToRemove.id);
|
|
186
|
+
}
|
|
187
|
+
return toasts.filter(({ id }) => id !== toastToRemove.id);
|
|
188
|
+
});
|
|
189
|
+
}, []);
|
|
190
|
+
const swipeDirection = resolveSwipeDirection(swipeDirectionProp, position);
|
|
191
|
+
const currentTheme = (0, core_1.useThemeName)();
|
|
192
|
+
const resolvedTheme = themeProp === 'system' || !themeProp
|
|
193
|
+
? currentTheme?.includes('dark')
|
|
194
|
+
? 'dark'
|
|
195
|
+
: 'light'
|
|
196
|
+
: themeProp;
|
|
197
|
+
const contextValue = {
|
|
198
|
+
toasts,
|
|
199
|
+
heights,
|
|
200
|
+
setToastHeight,
|
|
201
|
+
removeToastHeight,
|
|
202
|
+
expanded,
|
|
203
|
+
setExpanded,
|
|
204
|
+
interacting,
|
|
205
|
+
setInteracting,
|
|
206
|
+
triggerDismissCooldown,
|
|
207
|
+
isInDismissCooldown,
|
|
208
|
+
removeToast,
|
|
209
|
+
position,
|
|
210
|
+
duration,
|
|
211
|
+
gap,
|
|
212
|
+
visibleToasts,
|
|
213
|
+
swipeDirection,
|
|
214
|
+
swipeThreshold,
|
|
215
|
+
toastHeight,
|
|
216
|
+
closeButton,
|
|
217
|
+
reducedMotion,
|
|
218
|
+
native,
|
|
219
|
+
burntOptions,
|
|
220
|
+
notificationOptions,
|
|
221
|
+
icons,
|
|
222
|
+
};
|
|
223
|
+
return ((0, jsx_runtime_1.jsx)(ToastContext.Provider, { ...contextValue, children: (0, jsx_runtime_1.jsx)(core_1.Theme, { name: resolvedTheme, children: children }) }));
|
|
224
|
+
});
|
|
225
|
+
/* -------------------------------------------------------------------------------------------------
|
|
226
|
+
* ToastViewport
|
|
227
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
228
|
+
const ToastViewportFrame = (0, core_1.styled)(core_1.View, {
|
|
229
|
+
name: 'ToastViewport',
|
|
230
|
+
variants: {
|
|
231
|
+
unstyled: {
|
|
232
|
+
false: {
|
|
233
|
+
position: constants_1.isWeb ? 'fixed' : 'absolute',
|
|
234
|
+
zIndex: 100000,
|
|
235
|
+
pointerEvents: 'box-none',
|
|
236
|
+
maxWidth: '100%',
|
|
237
|
+
...(constants_1.isWeb && { width: 356 }),
|
|
238
|
+
minHeight: 1,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
defaultVariants: {
|
|
243
|
+
unstyled: process.env.GUI_HEADLESS === '1',
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
const ToastViewport = ToastViewportFrame.styleable(function ToastViewport(props, ref) {
|
|
247
|
+
const { offset = VIEWPORT_OFFSET, hotkey = DEFAULT_HOTKEY, label = 'Notifications', portalToRoot = true, portalZIndex = Number.MAX_SAFE_INTEGER, children, ...rest } = props;
|
|
248
|
+
const ctx = useToastContext('Toast.Viewport');
|
|
249
|
+
const listRef = React.useRef(null);
|
|
250
|
+
const hoverTimeoutRef = React.useRef(null);
|
|
251
|
+
const hoverCooldownRef = React.useRef(false);
|
|
252
|
+
const deferredCollapseRef = React.useRef(null);
|
|
253
|
+
const mouseInsideRef = React.useRef(false);
|
|
254
|
+
const [yPosition, xPosition] = ctx.position.split('-');
|
|
255
|
+
// offset styles
|
|
256
|
+
// on native, get safe area insets to avoid status bar / Dynamic Island / home indicator
|
|
257
|
+
// use insets from GuiProvider (passed via useConfiguration)
|
|
258
|
+
// same pattern as Slider — works on native when GuiProvider has insets prop
|
|
259
|
+
const { insets: safeInsets } = (0, core_1.useConfiguration)();
|
|
260
|
+
const offsetStyles = React.useMemo(() => {
|
|
261
|
+
const styles = {};
|
|
262
|
+
const defaultOffset = typeof offset === 'number' ? offset : VIEWPORT_OFFSET;
|
|
263
|
+
const offsetObj = typeof offset === 'object'
|
|
264
|
+
? offset
|
|
265
|
+
: {
|
|
266
|
+
top: defaultOffset,
|
|
267
|
+
right: defaultOffset,
|
|
268
|
+
bottom: defaultOffset,
|
|
269
|
+
left: defaultOffset,
|
|
270
|
+
};
|
|
271
|
+
const safeTop = safeInsets?.top ?? 0;
|
|
272
|
+
const safeBottom = safeInsets?.bottom ?? 0;
|
|
273
|
+
// if safe area already provides spacing, skip the offset to avoid double padding
|
|
274
|
+
const topOffset = safeTop > 0 ? safeTop : (offsetObj.top ?? defaultOffset);
|
|
275
|
+
const bottomOffset = safeBottom > 0 ? safeBottom : (offsetObj.bottom ?? defaultOffset);
|
|
276
|
+
if (yPosition === 'top')
|
|
277
|
+
styles.top = topOffset;
|
|
278
|
+
else
|
|
279
|
+
styles.bottom = bottomOffset;
|
|
280
|
+
if (constants_1.isWeb) {
|
|
281
|
+
if (xPosition === 'left')
|
|
282
|
+
styles.left = offsetObj.left ?? defaultOffset;
|
|
283
|
+
else if (xPosition === 'right')
|
|
284
|
+
styles.right = offsetObj.right ?? defaultOffset;
|
|
285
|
+
else {
|
|
286
|
+
styles.left = '50%';
|
|
287
|
+
styles.transform = 'translateX(-50%)';
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
// native: always set both left + right so viewport fills screen
|
|
292
|
+
// (no fixed width on native — left/right offsets define the width)
|
|
293
|
+
styles.left = offsetObj.left ?? defaultOffset;
|
|
294
|
+
styles.right = offsetObj.right ?? defaultOffset;
|
|
295
|
+
}
|
|
296
|
+
return styles;
|
|
297
|
+
}, [offset, yPosition, xPosition]);
|
|
298
|
+
// hotkey
|
|
299
|
+
React.useEffect(() => {
|
|
300
|
+
if (!constants_1.isWeb)
|
|
301
|
+
return;
|
|
302
|
+
const handleKeyDown = (event) => {
|
|
303
|
+
const isHotkeyPressed = hotkey.length > 0 &&
|
|
304
|
+
hotkey.every((key) => event[key] || event.code === key);
|
|
305
|
+
if (isHotkeyPressed) {
|
|
306
|
+
ctx.setExpanded(true);
|
|
307
|
+
listRef.current?.focus();
|
|
308
|
+
}
|
|
309
|
+
// Escape is handled by individual toast items via onKeyDown
|
|
310
|
+
// which dismisses the focused toast with cooldown (keeps stack expanded)
|
|
311
|
+
};
|
|
312
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
313
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
314
|
+
}, [hotkey]);
|
|
315
|
+
if (ctx.toasts.length === 0)
|
|
316
|
+
return null;
|
|
317
|
+
const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
|
|
318
|
+
const content = ((0, jsx_runtime_1.jsx)(ToastViewportFrame, { ref: listRef, "aria-label": `${label} ${hotkeyLabel}`, tabIndex: -1, "aria-live": "polite", style: offsetStyles, "data-y-position": yPosition, "data-x-position": xPosition, ...(constants_1.isWeb
|
|
319
|
+
? {
|
|
320
|
+
onMouseEnter: () => {
|
|
321
|
+
mouseInsideRef.current = true;
|
|
322
|
+
if (deferredCollapseRef.current) {
|
|
323
|
+
clearTimeout(deferredCollapseRef.current);
|
|
324
|
+
deferredCollapseRef.current = null;
|
|
325
|
+
}
|
|
326
|
+
if (ctx.toasts.length > 1 &&
|
|
327
|
+
!ctx.interacting &&
|
|
328
|
+
!hoverCooldownRef.current) {
|
|
329
|
+
hoverTimeoutRef.current = setTimeout(() => ctx.setExpanded(true), 50);
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
onMouseLeave: () => {
|
|
333
|
+
mouseInsideRef.current = false;
|
|
334
|
+
if (hoverTimeoutRef.current) {
|
|
335
|
+
clearTimeout(hoverTimeoutRef.current);
|
|
336
|
+
hoverTimeoutRef.current = null;
|
|
337
|
+
}
|
|
338
|
+
if (!ctx.interacting && !ctx.isInDismissCooldown()) {
|
|
339
|
+
ctx.setExpanded(false);
|
|
340
|
+
}
|
|
341
|
+
else if (ctx.isInDismissCooldown()) {
|
|
342
|
+
// During dismiss cooldown, defer collapse until well after
|
|
343
|
+
// the exit animation completes to prevent mid-animation bounce.
|
|
344
|
+
// The cooldown is 800ms, spring exit is ~500ms — 1200ms covers both.
|
|
345
|
+
if (deferredCollapseRef.current) {
|
|
346
|
+
clearTimeout(deferredCollapseRef.current);
|
|
347
|
+
}
|
|
348
|
+
deferredCollapseRef.current = setTimeout(() => {
|
|
349
|
+
deferredCollapseRef.current = null;
|
|
350
|
+
if (!mouseInsideRef.current) {
|
|
351
|
+
ctx.setExpanded(false);
|
|
352
|
+
}
|
|
353
|
+
}, 1200);
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
onPointerDown: () => {
|
|
357
|
+
if (hoverTimeoutRef.current) {
|
|
358
|
+
clearTimeout(hoverTimeoutRef.current);
|
|
359
|
+
hoverTimeoutRef.current = null;
|
|
360
|
+
}
|
|
361
|
+
ctx.setInteracting(true);
|
|
362
|
+
},
|
|
363
|
+
onPointerUp: () => ctx.setInteracting(false),
|
|
364
|
+
onPointerCancel: () => ctx.setInteracting(false),
|
|
365
|
+
}
|
|
366
|
+
: {
|
|
367
|
+
onPress: () => {
|
|
368
|
+
if (ctx.toasts.length > 1) {
|
|
369
|
+
ctx.setExpanded((prev) => !prev);
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
}), ...(constants_1.isWeb && {
|
|
373
|
+
onFocus: (event) => {
|
|
374
|
+
// keyboard focus entered — expand stack and pause timers
|
|
375
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
376
|
+
if (ctx.toasts.length > 1) {
|
|
377
|
+
ctx.setExpanded(true);
|
|
378
|
+
}
|
|
379
|
+
ctx.setInteracting(true);
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
onBlur: (event) => {
|
|
383
|
+
// focus left the toaster — collapse and resume timers
|
|
384
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
385
|
+
ctx.setInteracting(false);
|
|
386
|
+
if (!ctx.isInDismissCooldown()) {
|
|
387
|
+
ctx.setExpanded(false);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
}), ...rest, children: children }));
|
|
392
|
+
if (portalToRoot) {
|
|
393
|
+
return ((0, jsx_runtime_1.jsx)(portal_1.Portal, { zIndex: portalZIndex, children: (0, jsx_runtime_1.jsx)(ToastContext.Provider, { ...ctx, children: content }) }));
|
|
394
|
+
}
|
|
395
|
+
return content;
|
|
396
|
+
});
|
|
397
|
+
function ToastList({ renderItem }) {
|
|
398
|
+
const ctx = useToastContext('Toast.List');
|
|
399
|
+
// render all toasts — hidden ones have opacity 0 but stay mounted
|
|
400
|
+
// so they smoothly transition when visible toasts are dismissed
|
|
401
|
+
const maxRender = ctx.toasts.length;
|
|
402
|
+
return ((0, jsx_runtime_1.jsx)(animate_presence_1.AnimatePresence, { children: ctx.toasts.slice(0, maxRender).map((toast, index) => {
|
|
403
|
+
const handleClose = () => {
|
|
404
|
+
if (toast.dismissible === false)
|
|
405
|
+
return;
|
|
406
|
+
toast.onDismiss?.(toast);
|
|
407
|
+
ctx.removeToast(toast);
|
|
408
|
+
};
|
|
409
|
+
const itemContextValue = {
|
|
410
|
+
toast,
|
|
411
|
+
handleClose,
|
|
412
|
+
};
|
|
413
|
+
if (!renderItem) {
|
|
414
|
+
return ((0, jsx_runtime_1.jsx)(ToastItemContext.Provider, { value: itemContextValue, children: (0, jsx_runtime_1.jsx)(ToastItemInner, { toast: toast, index: index, children: (0, jsx_runtime_1.jsx)(DefaultToastContent, { toast: toast }) }) }, toast.id));
|
|
415
|
+
}
|
|
416
|
+
return ((0, jsx_runtime_1.jsx)(ToastItemContext.Provider, { value: itemContextValue, children: renderItem({ toast, index, handleClose }) }, toast.id));
|
|
417
|
+
}) }));
|
|
418
|
+
}
|
|
419
|
+
/* -------------------------------------------------------------------------------------------------
|
|
420
|
+
* DefaultToastContent - default rendering for toast items
|
|
421
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
422
|
+
function DefaultToastContent({ toast }) {
|
|
423
|
+
const ctx = useToastContext('Toast.Item');
|
|
424
|
+
const { handleClose } = useToastItemContext();
|
|
425
|
+
const toastType = toast.type ?? 'default';
|
|
426
|
+
const dismissible = toast.dismissible !== false;
|
|
427
|
+
const title = typeof toast.title === 'function' ? toast.title() : toast.title;
|
|
428
|
+
const description = typeof toast.description === 'function' ? toast.description() : toast.description;
|
|
429
|
+
return ((0, jsx_runtime_1.jsxs)(stacks_1.XStack, { alignItems: "flex-start", gap: "$3", children: [(0, jsx_runtime_1.jsx)(ToastIcon, {}), (0, jsx_runtime_1.jsxs)(stacks_1.YStack, { flex: 1, gap: "$1", children: [title && (0, jsx_runtime_1.jsx)(ToastTitle, { children: title }), description && (0, jsx_runtime_1.jsx)(ToastDescription, { children: description }), (toast.action || toast.cancel) && ((0, jsx_runtime_1.jsxs)(stacks_1.XStack, { gap: "$2", marginTop: "$2", children: [toast.cancel && ((0, jsx_runtime_1.jsx)(ToastItemFrame_tsx_1.ToastActionFrame, { backgroundColor: "transparent", onPress: (e) => {
|
|
430
|
+
toast.cancel?.onClick?.(e);
|
|
431
|
+
handleClose();
|
|
432
|
+
}, children: (0, jsx_runtime_1.jsx)(text_1.SizableText, { size: "$2", color: "$color11", children: toast.cancel.label }) })), toast.action && ((0, jsx_runtime_1.jsx)(ToastItemFrame_tsx_1.ToastActionFrame, { backgroundColor: "$color12", hoverStyle: { backgroundColor: '$color11' }, pressStyle: { backgroundColor: '$color10' }, onPress: (e) => {
|
|
433
|
+
toast.action?.onClick?.(e);
|
|
434
|
+
if (!e.defaultPrevented) {
|
|
435
|
+
handleClose();
|
|
436
|
+
}
|
|
437
|
+
}, children: (0, jsx_runtime_1.jsx)(text_1.SizableText, { size: "$2", fontWeight: "600", color: "$background", children: toast.action.label }) }))] }))] }), ctx.closeButton && dismissible && (0, jsx_runtime_1.jsx)(ToastClose, {})] }));
|
|
438
|
+
}
|
|
439
|
+
function DragWrapper({ animatedStyle, gestureHandlers, gesture, AnimatedView, dragRef, children, }) {
|
|
440
|
+
if (constants_1.isWeb) {
|
|
441
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: dragRef, style: {
|
|
442
|
+
flex: 1,
|
|
443
|
+
display: 'flex',
|
|
444
|
+
flexDirection: 'column',
|
|
445
|
+
userSelect: 'none',
|
|
446
|
+
WebkitUserSelect: 'none',
|
|
447
|
+
touchAction: 'none',
|
|
448
|
+
cursor: 'default',
|
|
449
|
+
}, ...gestureHandlers, children: children }));
|
|
450
|
+
}
|
|
451
|
+
// when RNGH gesture is available, wrap with GestureDetector + plain View
|
|
452
|
+
// (GestureDetector needs a native View to attach handlers to)
|
|
453
|
+
if (gesture) {
|
|
454
|
+
const gh = (0, native_1.getGestureHandler)();
|
|
455
|
+
const GestureDetector = gh.state.GestureDetector;
|
|
456
|
+
if (GestureDetector) {
|
|
457
|
+
return ((0, jsx_runtime_1.jsx)(GestureDetector, { gesture: gesture, children: (0, jsx_runtime_1.jsx)(core_1.View, { style: { flex: 1 }, ...{ collapsable: false }, children: (0, jsx_runtime_1.jsx)(AnimatedView, { style: [{ flex: 1 }, animatedStyle], children: children }) }) }));
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// fallback: PanResponder handlers
|
|
461
|
+
return ((0, jsx_runtime_1.jsx)(AnimatedView, { style: [{ flex: 1 }, animatedStyle], ...gestureHandlers, children: children }));
|
|
462
|
+
}
|
|
463
|
+
const ToastItemInner = ToastItemFrame_tsx_1.ToastItemFrame.styleable(function ToastItem(props, ref) {
|
|
464
|
+
const { toast, index, children, ...rest } = props;
|
|
465
|
+
const ctx = useToastContext('Toast.Item');
|
|
466
|
+
const [mounted, setMounted] = React.useState(false);
|
|
467
|
+
const [removed, setRemoved] = React.useState(false);
|
|
468
|
+
const [swipeOut, setSwipeOut] = React.useState(false);
|
|
469
|
+
// Freeze the Y offset when dismiss starts so the exiting toast doesn't jump
|
|
470
|
+
// as other toasts rebalance
|
|
471
|
+
const [offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0);
|
|
472
|
+
// Freeze stackY at swipe time — context re-renders recalculate stackY
|
|
473
|
+
// but the exiting toast should stay at its pre-removal position
|
|
474
|
+
const swipeExitYRef = React.useRef(null);
|
|
475
|
+
const closeTimerRef = React.useRef(null);
|
|
476
|
+
const closeTimerStartRef = React.useRef(0);
|
|
477
|
+
const lastPauseTimeRef = React.useRef(0);
|
|
478
|
+
const remainingTimeRef = React.useRef(toast.duration ?? ctx.duration);
|
|
479
|
+
const isFront = index === 0;
|
|
480
|
+
const isVisible = index < ctx.visibleToasts;
|
|
481
|
+
const toastType = toast.type ?? 'default';
|
|
482
|
+
const dismissible = toast.dismissible !== false;
|
|
483
|
+
const duration = toast.duration ?? ctx.duration;
|
|
484
|
+
const [yPosition] = ctx.position.split('-');
|
|
485
|
+
const isTop = yPosition === 'top';
|
|
486
|
+
// web: dynamic heights (CSS transitions run off main thread, no FPS concern)
|
|
487
|
+
// native: fixed height (avoids React state re-render cascade on JS thread)
|
|
488
|
+
const expandedOffset = constants_1.isWeb
|
|
489
|
+
? (() => {
|
|
490
|
+
let totalHeight = 0;
|
|
491
|
+
let activeCount = 0;
|
|
492
|
+
for (let i = 0; i < index; i++) {
|
|
493
|
+
const toastId = ctx.toasts[i]?.id;
|
|
494
|
+
if (toastId == null)
|
|
495
|
+
continue;
|
|
496
|
+
const h = ctx.heights[toastId];
|
|
497
|
+
if (h === 0)
|
|
498
|
+
continue;
|
|
499
|
+
totalHeight += h ?? ctx.toastHeight;
|
|
500
|
+
activeCount++;
|
|
501
|
+
}
|
|
502
|
+
return totalHeight + activeCount * ctx.gap;
|
|
503
|
+
})()
|
|
504
|
+
: index * (ctx.toastHeight + ctx.gap);
|
|
505
|
+
// Refs for stable access in callbacks — avoids putting expandedOffset/expanded
|
|
506
|
+
// in deps which would cause timer restarts on every height measurement
|
|
507
|
+
const expandedOffsetRef = React.useRef(expandedOffset);
|
|
508
|
+
expandedOffsetRef.current = expandedOffset;
|
|
509
|
+
const isExpandedRef = React.useRef(ctx.expanded);
|
|
510
|
+
isExpandedRef.current = ctx.expanded;
|
|
511
|
+
// timer — no height-zeroing needed here because auto-dismiss only fires
|
|
512
|
+
// when not expanded/interacting (timer is paused during hover)
|
|
513
|
+
const startTimer = React.useCallback(() => {
|
|
514
|
+
if (duration === Number.POSITIVE_INFINITY || toastType === 'loading')
|
|
515
|
+
return;
|
|
516
|
+
closeTimerStartRef.current = Date.now();
|
|
517
|
+
closeTimerRef.current = setTimeout(() => {
|
|
518
|
+
toast.onAutoClose?.(toast);
|
|
519
|
+
setRemoved(true);
|
|
520
|
+
setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
|
|
521
|
+
}, remainingTimeRef.current);
|
|
522
|
+
}, [duration, toastType, toast, ctx.removeToast]);
|
|
523
|
+
const pauseTimer = (0, core_1.useEvent)(() => {
|
|
524
|
+
if (closeTimerRef.current) {
|
|
525
|
+
clearTimeout(closeTimerRef.current);
|
|
526
|
+
}
|
|
527
|
+
if (lastPauseTimeRef.current < closeTimerStartRef.current) {
|
|
528
|
+
const elapsed = Date.now() - closeTimerStartRef.current;
|
|
529
|
+
remainingTimeRef.current = Math.max(0, remainingTimeRef.current - elapsed);
|
|
530
|
+
}
|
|
531
|
+
lastPauseTimeRef.current = Date.now();
|
|
532
|
+
});
|
|
533
|
+
const resumeTimer = (0, core_1.useEvent)(() => {
|
|
534
|
+
if (ctx.expanded || ctx.interacting)
|
|
535
|
+
return;
|
|
536
|
+
remainingTimeRef.current = duration;
|
|
537
|
+
startTimer();
|
|
538
|
+
});
|
|
539
|
+
React.useEffect(() => {
|
|
540
|
+
setMounted(true);
|
|
541
|
+
}, []);
|
|
542
|
+
// handle deletion — only zero height when expanded (Sonner rebalance)
|
|
543
|
+
React.useEffect(() => {
|
|
544
|
+
if (toast.delete) {
|
|
545
|
+
setRemoved(true);
|
|
546
|
+
if (isExpandedRef.current) {
|
|
547
|
+
setOffsetBeforeRemove(expandedOffsetRef.current);
|
|
548
|
+
}
|
|
549
|
+
setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
|
|
550
|
+
}
|
|
551
|
+
}, [toast.delete, toast, ctx.removeToast]);
|
|
552
|
+
React.useEffect(() => {
|
|
553
|
+
// all toasts have independent timers (same as Sonner)
|
|
554
|
+
// stagger comes from creation time differences
|
|
555
|
+
if (ctx.expanded || ctx.interacting) {
|
|
556
|
+
pauseTimer();
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
startTimer();
|
|
560
|
+
}
|
|
561
|
+
return () => {
|
|
562
|
+
if (closeTimerRef.current)
|
|
563
|
+
clearTimeout(closeTimerRef.current);
|
|
564
|
+
};
|
|
565
|
+
}, [ctx.expanded, ctx.interacting, startTimer]);
|
|
566
|
+
// reset remaining time when duration changes
|
|
567
|
+
React.useEffect(() => {
|
|
568
|
+
remainingTimeRef.current = duration;
|
|
569
|
+
}, [duration]);
|
|
570
|
+
// animations
|
|
571
|
+
const { setDragOffset, springBack, animateOut, animatedStyle, AnimatedView, dragRef, } = (0, useToastAnimations_ts_1.useToastAnimations)({
|
|
572
|
+
reducedMotion: ctx.reducedMotion,
|
|
573
|
+
swipeAxis: ctx.swipeDirection === 'up' ||
|
|
574
|
+
ctx.swipeDirection === 'down' ||
|
|
575
|
+
ctx.swipeDirection === 'vertical'
|
|
576
|
+
? 'vertical'
|
|
577
|
+
: 'horizontal',
|
|
578
|
+
});
|
|
579
|
+
const { isDragging, gestureHandlers, gesture } = (0, useAnimatedDragGesture_ts_1.useAnimatedDragGesture)({
|
|
580
|
+
direction: ctx.swipeDirection,
|
|
581
|
+
threshold: ctx.swipeThreshold,
|
|
582
|
+
disabled: !dismissible || toastType === 'loading',
|
|
583
|
+
expanded: ctx.expanded,
|
|
584
|
+
onDragStart: pauseTimer,
|
|
585
|
+
onDragMove: setDragOffset,
|
|
586
|
+
onDismiss: (exitDirection, velocity) => {
|
|
587
|
+
// Trigger cooldown to prevent collapse while stack rebalances
|
|
588
|
+
ctx.triggerDismissCooldown();
|
|
589
|
+
setSwipeOut(true);
|
|
590
|
+
toast.onDismiss?.(toast);
|
|
591
|
+
// freeze stackY at swipe time — after removeToast, context re-renders
|
|
592
|
+
// recalculate expandedOffset with the wrong toast array
|
|
593
|
+
swipeExitYRef.current = isExpandedRef.current
|
|
594
|
+
? isTop
|
|
595
|
+
? expandedOffsetRef.current
|
|
596
|
+
: -expandedOffsetRef.current
|
|
597
|
+
: isFront
|
|
598
|
+
? 0
|
|
599
|
+
: isTop
|
|
600
|
+
? ctx.gap * index
|
|
601
|
+
: -ctx.gap * index;
|
|
602
|
+
setRemoved(true);
|
|
603
|
+
ctx.removeToast(toast);
|
|
604
|
+
animateOut(exitDirection, velocity);
|
|
605
|
+
},
|
|
606
|
+
onCancel: () => {
|
|
607
|
+
springBack(() => {
|
|
608
|
+
resumeTimer();
|
|
609
|
+
});
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
// measure height (web only — native uses fixed height)
|
|
613
|
+
const handleLayout = React.useCallback((event) => {
|
|
614
|
+
if (!constants_1.isWeb)
|
|
615
|
+
return;
|
|
616
|
+
if (removed)
|
|
617
|
+
return;
|
|
618
|
+
if (!ctx.expanded && index !== 0)
|
|
619
|
+
return;
|
|
620
|
+
const { height } = event.nativeEvent.layout;
|
|
621
|
+
ctx.setToastHeight(toast.id, height);
|
|
622
|
+
}, [toast.id, ctx.setToastHeight, index, ctx.expanded, removed]);
|
|
623
|
+
// remove height on unmount (web only)
|
|
624
|
+
React.useEffect(() => {
|
|
625
|
+
if (!constants_1.isWeb)
|
|
626
|
+
return;
|
|
627
|
+
return () => {
|
|
628
|
+
ctx.removeToastHeight(toast.id);
|
|
629
|
+
};
|
|
630
|
+
}, [toast.id, ctx.removeToastHeight]);
|
|
631
|
+
const handleClose = React.useCallback(() => {
|
|
632
|
+
if (!dismissible)
|
|
633
|
+
return;
|
|
634
|
+
ctx.triggerDismissCooldown();
|
|
635
|
+
toast.onDismiss?.(toast);
|
|
636
|
+
setRemoved(true);
|
|
637
|
+
if (isExpandedRef.current) {
|
|
638
|
+
setOffsetBeforeRemove(expandedOffsetRef.current);
|
|
639
|
+
}
|
|
640
|
+
setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
|
|
641
|
+
}, [dismissible, toast, ctx.removeToast, ctx.triggerDismissCooldown]);
|
|
642
|
+
const itemContextValue = React.useMemo(() => ({ toast, handleClose }), [toast, handleClose]);
|
|
643
|
+
// front toast height for collapsed stacking (web only)
|
|
644
|
+
let frontToastHeight = -1;
|
|
645
|
+
if (constants_1.isWeb) {
|
|
646
|
+
for (const t of ctx.toasts) {
|
|
647
|
+
const h = ctx.heights[t.id];
|
|
648
|
+
if (h != null && h > 0) {
|
|
649
|
+
frontToastHeight = h;
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
const stackScale = !ctx.expanded && !isFront ? 1 - index * 0.05 : 1;
|
|
655
|
+
// When removed, freeze Y at the saved offset so the exiting toast doesn't jump
|
|
656
|
+
// as other toasts rebalance (Sonner: --offset uses offsetBeforeRemove when removed)
|
|
657
|
+
const activeExpandedOffset = removed ? offsetBeforeRemove : expandedOffset;
|
|
658
|
+
const stackY = ctx.expanded
|
|
659
|
+
? isTop
|
|
660
|
+
? activeExpandedOffset
|
|
661
|
+
: -activeExpandedOffset
|
|
662
|
+
: isFront
|
|
663
|
+
? 0
|
|
664
|
+
: isTop
|
|
665
|
+
? ctx.gap * index
|
|
666
|
+
: -ctx.gap * index;
|
|
667
|
+
const computedOpacity = removed && !swipeOut ? 0 : index >= ctx.visibleToasts ? 0 : 1;
|
|
668
|
+
const computedZIndex = removed ? 0 : ctx.visibleToasts - index + 1;
|
|
669
|
+
// web: use measured height for smooth expand/collapse transitions
|
|
670
|
+
// native: fixed height, no constraint needed
|
|
671
|
+
const computedHeight = constants_1.isWeb
|
|
672
|
+
? ctx.expanded
|
|
673
|
+
? ctx.heights[toast.id] || undefined
|
|
674
|
+
: !isFront && frontToastHeight > 0
|
|
675
|
+
? frontToastHeight
|
|
676
|
+
: undefined
|
|
677
|
+
: undefined;
|
|
678
|
+
const computedPointerEvents = index >= ctx.visibleToasts ? 'none' : 'auto';
|
|
679
|
+
// gap filler for hover stability
|
|
680
|
+
const gapFillerHeight = ctx.expanded ? ctx.gap + 1 : 0;
|
|
681
|
+
// data attributes
|
|
682
|
+
const dataAttributes = {
|
|
683
|
+
'data-mounted': mounted ? 'true' : 'false',
|
|
684
|
+
'data-removed': removed ? 'true' : 'false',
|
|
685
|
+
'data-swipe-out': swipeOut ? 'true' : 'false',
|
|
686
|
+
'data-visible': isVisible ? 'true' : 'false',
|
|
687
|
+
'data-front': isFront ? 'true' : 'false',
|
|
688
|
+
'data-index': String(index),
|
|
689
|
+
'data-type': toastType,
|
|
690
|
+
'data-expanded': ctx.expanded ? 'true' : 'false',
|
|
691
|
+
};
|
|
692
|
+
return ((0, jsx_runtime_1.jsx)(ToastItemFrame_tsx_1.ToastPositionWrapper, { ref: ref, testID: rest.testID, accessibilityLabel: rest.accessibilityLabel, ...dataAttributes, transition: isDragging || ctx.reducedMotion ? undefined : removed ? '200ms' : '400ms', animateOnly: constants_1.isWeb ? ['transform', 'opacity', 'height'] : ['transform', 'opacity'], y: stackY, scale: stackScale, opacity: computedOpacity, zIndex: computedZIndex, height: computedHeight, overflow: "visible", pointerEvents: computedPointerEvents, top: isTop ? 0 : undefined, bottom: isTop ? undefined : 0, ...(constants_1.isWeb &&
|
|
693
|
+
!isFront && {
|
|
694
|
+
style: { transformOrigin: isTop ? 'top center' : 'bottom center' },
|
|
695
|
+
}), enterStyle: ctx.reducedMotion ? { opacity: 0 } : { opacity: 0, y: isTop ? -80 : 80 }, exitStyle: ctx.reducedMotion
|
|
696
|
+
? { opacity: 0 }
|
|
697
|
+
: swipeOut
|
|
698
|
+
? { opacity: 0, y: swipeExitYRef.current ?? stackY, scale: stackScale }
|
|
699
|
+
: { opacity: 0, y: stackY, scale: stackScale }, children: (0, jsx_runtime_1.jsx)(DragWrapper, { animatedStyle: animatedStyle, gestureHandlers: gestureHandlers, gesture: gesture, AnimatedView: AnimatedView, dragRef: dragRef, children: (0, jsx_runtime_1.jsxs)(ToastItemFrame_tsx_1.ToastItemFrame
|
|
700
|
+
// The one hook a stylesheet can reach a toast by.
|
|
701
|
+
//
|
|
702
|
+
// A toast is floating chrome — it is over the page or it is nothing
|
|
703
|
+
// — so a design system wants to give it the same material every
|
|
704
|
+
// other floating surface wears. It had no handle at all: `Toaster`
|
|
705
|
+
// accepts sonner's `className`/`style`/`classNames` and documents
|
|
706
|
+
// them as INERT, and nothing else here reaches the DOM node. So the
|
|
707
|
+
// one surface that is unambiguously floating was the one surface a
|
|
708
|
+
// sheet could not select, and it kept a hand-rolled
|
|
709
|
+
// `rgba(0,0,0,0.15)` drop that is very nearly invisible on a dark
|
|
710
|
+
// ground — the exact defect an elevation ladder exists to end.
|
|
711
|
+
//
|
|
712
|
+
// `data-slot` rather than a class or a prop because it needs no
|
|
713
|
+
// decision from a call site: a toast is glass because it IS a toast.
|
|
714
|
+
// gui forwards unrecognised props to the DOM node and native drops
|
|
715
|
+
// them, which is what makes this cross-platform safe.
|
|
716
|
+
, { "data-slot": "toast", role: "status", "aria-live": "polite", "aria-atomic": true, tabIndex: 0, onLayout: handleLayout, ...(constants_1.isWeb && {
|
|
717
|
+
onKeyDown: (event) => {
|
|
718
|
+
if (event.key === 'Escape' && dismissible) {
|
|
719
|
+
// move focus to the next toast before dismissing
|
|
720
|
+
const current = event.currentTarget;
|
|
721
|
+
const container = current.closest('[aria-label]');
|
|
722
|
+
if (container) {
|
|
723
|
+
const focusables = container.querySelectorAll('[tabindex="0"]');
|
|
724
|
+
const arr = Array.from(focusables);
|
|
725
|
+
const idx = arr.indexOf(current);
|
|
726
|
+
const next = arr[idx + 1] || arr[idx - 1];
|
|
727
|
+
next?.focus();
|
|
728
|
+
}
|
|
729
|
+
handleClose();
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
}), ...rest, children: [ctx.expanded && gapFillerHeight > 0 && ((0, jsx_runtime_1.jsx)(core_1.View, { position: "absolute", left: 0, right: 0, height: gapFillerHeight, pointerEvents: "auto", ...(isTop ? { top: '100%' } : { bottom: '100%' }) })), (0, jsx_runtime_1.jsx)(ToastItemContext.Provider, { value: itemContextValue, children: children })] }) }) }));
|
|
733
|
+
});
|
|
734
|
+
/* -------------------------------------------------------------------------------------------------
|
|
735
|
+
* ToastTitle
|
|
736
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
737
|
+
const ToastTitle = (0, core_1.styled)(text_1.SizableText, {
|
|
738
|
+
name: 'ToastTitle',
|
|
739
|
+
variants: {
|
|
740
|
+
unstyled: {
|
|
741
|
+
false: {
|
|
742
|
+
color: '$color',
|
|
743
|
+
fontWeight: '600',
|
|
744
|
+
size: '$4',
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
},
|
|
748
|
+
defaultVariants: {
|
|
749
|
+
unstyled: process.env.GUI_HEADLESS === '1',
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
/* -------------------------------------------------------------------------------------------------
|
|
753
|
+
* ToastDescription
|
|
754
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
755
|
+
const ToastDescription = (0, core_1.styled)(text_1.SizableText, {
|
|
756
|
+
name: 'ToastDescription',
|
|
757
|
+
variants: {
|
|
758
|
+
unstyled: {
|
|
759
|
+
false: {
|
|
760
|
+
color: '$color11',
|
|
761
|
+
size: '$2',
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
defaultVariants: {
|
|
766
|
+
unstyled: process.env.GUI_HEADLESS === '1',
|
|
767
|
+
},
|
|
768
|
+
});
|
|
769
|
+
/* -------------------------------------------------------------------------------------------------
|
|
770
|
+
* ToastClose - auto-wired to dismiss current toast
|
|
771
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
772
|
+
const ToastClose = ToastItemFrame_tsx_1.ToastCloseFrame.styleable(function ToastClose(props, ref) {
|
|
773
|
+
// try to get handleClose from context, but allow manual override
|
|
774
|
+
let handleClose;
|
|
775
|
+
try {
|
|
776
|
+
const itemCtx = useToastItemContext();
|
|
777
|
+
handleClose = itemCtx.handleClose;
|
|
778
|
+
}
|
|
779
|
+
catch {
|
|
780
|
+
// not inside a Toast.Item context, require manual onPress
|
|
781
|
+
}
|
|
782
|
+
const ctx = useToastContext('Toast.Close');
|
|
783
|
+
return ((0, jsx_runtime_1.jsx)(ToastItemFrame_tsx_1.ToastCloseFrame, { ref: ref, "aria-label": "Close toast", onPress: handleClose, ...props, children: props.children ?? ctx.icons?.close ?? (0, jsx_runtime_1.jsx)(ToastItemFrame_tsx_1.DefaultCloseIcon, {}) }));
|
|
784
|
+
});
|
|
785
|
+
/* -------------------------------------------------------------------------------------------------
|
|
786
|
+
* ToastAction
|
|
787
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
788
|
+
const ToastAction = ToastItemFrame_tsx_1.ToastActionFrame.styleable(function ToastAction(props, ref) {
|
|
789
|
+
return (0, jsx_runtime_1.jsx)(ToastItemFrame_tsx_1.ToastActionFrame, { ref: ref, ...props });
|
|
790
|
+
});
|
|
791
|
+
/* -------------------------------------------------------------------------------------------------
|
|
792
|
+
* ToastIcon - renders icon based on toast type
|
|
793
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
794
|
+
function ToastIcon(props) {
|
|
795
|
+
const ctx = useToastContext('Toast.Icon');
|
|
796
|
+
let toast;
|
|
797
|
+
try {
|
|
798
|
+
const itemCtx = useToastItemContext();
|
|
799
|
+
toast = itemCtx.toast;
|
|
800
|
+
}
|
|
801
|
+
catch {
|
|
802
|
+
// not inside a Toast.Item context
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
if (!toast)
|
|
806
|
+
return null;
|
|
807
|
+
// if custom icon provided on toast, use it
|
|
808
|
+
if (toast.icon !== undefined) {
|
|
809
|
+
return ((0, jsx_runtime_1.jsx)(core_1.View, { flexShrink: 0, marginTop: "$0.5", children: toast.icon }));
|
|
810
|
+
}
|
|
811
|
+
const toastType = toast.type ?? 'default';
|
|
812
|
+
// only show icons if explicitly provided via icons prop (no built-in defaults)
|
|
813
|
+
const icon = ctx.icons?.[toastType] ?? null;
|
|
814
|
+
if (!icon)
|
|
815
|
+
return null;
|
|
816
|
+
return ((0, jsx_runtime_1.jsx)(core_1.View, { flexShrink: 0, marginTop: "$0.5", children: icon }));
|
|
817
|
+
}
|
|
818
|
+
/* -------------------------------------------------------------------------------------------------
|
|
819
|
+
* useToasts hook for rendering
|
|
820
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
821
|
+
function useToasts() {
|
|
822
|
+
const ctx = useToastContext('useToasts');
|
|
823
|
+
return {
|
|
824
|
+
toasts: ctx.toasts,
|
|
825
|
+
expanded: ctx.expanded,
|
|
826
|
+
position: ctx.position,
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
/* -------------------------------------------------------------------------------------------------
|
|
830
|
+
* useToastItem hook for accessing current toast in custom content
|
|
831
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
832
|
+
function useToastItem() {
|
|
833
|
+
return useToastItemContext();
|
|
834
|
+
}
|
|
835
|
+
/* -------------------------------------------------------------------------------------------------
|
|
836
|
+
* Export
|
|
837
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
838
|
+
ToastRoot.displayName = 'Toast';
|
|
839
|
+
exports.Toast = (0, helpers_1.withStaticProperties)(ToastRoot, {
|
|
840
|
+
Viewport: ToastViewport,
|
|
841
|
+
List: ToastList,
|
|
842
|
+
Item: ToastItemInner,
|
|
843
|
+
Title: ToastTitle,
|
|
844
|
+
Description: ToastDescription,
|
|
845
|
+
Close: ToastClose,
|
|
846
|
+
Action: ToastAction,
|
|
847
|
+
Icon: ToastIcon,
|
|
848
|
+
});
|
|
849
|
+
//# sourceMappingURL=ToastComposable.js.map
|