@hanzogui/toast 2.0.0-rc.41-hanzoai.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Toast.cjs +178 -0
- package/dist/cjs/Toast.native.js +181 -0
- package/dist/cjs/Toast.native.js.map +1 -0
- package/dist/cjs/ToastAnnounce.cjs +103 -0
- package/dist/cjs/ToastAnnounce.native.js +111 -0
- package/dist/cjs/ToastAnnounce.native.js.map +1 -0
- package/dist/cjs/ToastComposable.cjs +933 -0
- package/dist/cjs/ToastComposable.native.js +1025 -0
- package/dist/cjs/ToastComposable.native.js.map +1 -0
- package/dist/cjs/ToastImperative.cjs +119 -0
- package/dist/cjs/ToastImperative.native.js +130 -0
- package/dist/cjs/ToastImperative.native.js.map +1 -0
- package/dist/cjs/ToastImpl.cjs +354 -0
- package/dist/cjs/ToastImpl.native.js +364 -0
- package/dist/cjs/ToastImpl.native.js.map +1 -0
- package/dist/cjs/ToastItemFrame.cjs +143 -0
- package/dist/cjs/ToastItemFrame.native.js +148 -0
- package/dist/cjs/ToastItemFrame.native.js.map +1 -0
- package/dist/cjs/ToastPortal.cjs +49 -0
- package/dist/cjs/ToastPortal.native.js +52 -0
- package/dist/cjs/ToastPortal.native.js.map +1 -0
- package/dist/cjs/ToastProvider.cjs +150 -0
- package/dist/cjs/ToastProvider.native.js +161 -0
- package/dist/cjs/ToastProvider.native.js.map +1 -0
- package/dist/cjs/ToastState.cjs +311 -0
- package/dist/cjs/ToastState.native.js +324 -0
- package/dist/cjs/ToastState.native.js.map +1 -0
- package/dist/cjs/ToastViewport.cjs +319 -0
- package/dist/cjs/ToastViewport.native.js +343 -0
- package/dist/cjs/ToastViewport.native.js.map +1 -0
- package/dist/cjs/Toaster.cjs +87 -0
- package/dist/cjs/Toaster.native.js +91 -0
- package/dist/cjs/Toaster.native.js.map +1 -0
- package/dist/cjs/constants.cjs +30 -0
- package/dist/cjs/constants.native.js +33 -0
- package/dist/cjs/constants.native.js.map +1 -0
- package/dist/cjs/createNativeToast.cjs +59 -0
- package/dist/cjs/createNativeToast.native.js +60 -0
- package/dist/cjs/createNativeToast.native.js.map +1 -0
- package/dist/cjs/dispatchNativeToast.cjs +47 -0
- package/dist/cjs/dispatchNativeToast.native.js +52 -0
- package/dist/cjs/dispatchNativeToast.native.js.map +1 -0
- package/dist/cjs/index.cjs +20 -0
- package/dist/cjs/index.native.js +23 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/types.cjs +18 -0
- package/dist/cjs/types.native.js +21 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/cjs/useAnimatedDragGesture.cjs +214 -0
- package/dist/cjs/useAnimatedDragGesture.native.js +224 -0
- package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/cjs/useReducedMotion.cjs +74 -0
- package/dist/cjs/useReducedMotion.native.js +83 -0
- package/dist/cjs/useReducedMotion.native.js.map +1 -0
- package/dist/cjs/useToastAnimations.cjs +294 -0
- package/dist/cjs/useToastAnimations.native.js +304 -0
- package/dist/cjs/useToastAnimations.native.js.map +1 -0
- package/dist/cjs/v2.cjs +36 -0
- package/dist/cjs/v2.native.js +39 -0
- package/dist/cjs/v2.native.js.map +1 -0
- package/dist/esm/Toast.mjs +137 -0
- package/dist/esm/Toast.mjs.map +1 -0
- package/dist/esm/Toast.native.js +137 -0
- package/dist/esm/Toast.native.js.map +1 -0
- package/dist/esm/ToastAnnounce.mjs +66 -0
- package/dist/esm/ToastAnnounce.mjs.map +1 -0
- package/dist/esm/ToastAnnounce.native.js +71 -0
- package/dist/esm/ToastAnnounce.native.js.map +1 -0
- package/dist/esm/ToastComposable.mjs +895 -0
- package/dist/esm/ToastComposable.mjs.map +1 -0
- package/dist/esm/ToastComposable.native.js +984 -0
- package/dist/esm/ToastComposable.native.js.map +1 -0
- package/dist/esm/ToastImperative.mjs +80 -0
- package/dist/esm/ToastImperative.mjs.map +1 -0
- package/dist/esm/ToastImperative.native.js +88 -0
- package/dist/esm/ToastImperative.native.js.map +1 -0
- package/dist/esm/ToastImpl.mjs +316 -0
- package/dist/esm/ToastImpl.mjs.map +1 -0
- package/dist/esm/ToastImpl.native.js +323 -0
- package/dist/esm/ToastImpl.native.js.map +1 -0
- package/dist/esm/ToastItemFrame.mjs +114 -0
- package/dist/esm/ToastItemFrame.mjs.map +1 -0
- package/dist/esm/ToastItemFrame.native.js +116 -0
- package/dist/esm/ToastItemFrame.native.js.map +1 -0
- package/dist/esm/ToastPortal.mjs +24 -0
- package/dist/esm/ToastPortal.mjs.map +1 -0
- package/dist/esm/ToastPortal.native.js +24 -0
- package/dist/esm/ToastPortal.native.js.map +1 -0
- package/dist/esm/ToastProvider.mjs +110 -0
- package/dist/esm/ToastProvider.mjs.map +1 -0
- package/dist/esm/ToastProvider.native.js +118 -0
- package/dist/esm/ToastProvider.native.js.map +1 -0
- package/dist/esm/ToastState.mjs +285 -0
- package/dist/esm/ToastState.mjs.map +1 -0
- package/dist/esm/ToastState.native.js +295 -0
- package/dist/esm/ToastState.native.js.map +1 -0
- package/dist/esm/ToastViewport.mjs +280 -0
- package/dist/esm/ToastViewport.mjs.map +1 -0
- package/dist/esm/ToastViewport.native.js +301 -0
- package/dist/esm/ToastViewport.native.js.map +1 -0
- package/dist/esm/Toaster.mjs +51 -0
- package/dist/esm/Toaster.mjs.map +1 -0
- package/dist/esm/Toaster.native.js +52 -0
- package/dist/esm/Toaster.native.js.map +1 -0
- package/dist/esm/constants.mjs +4 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/constants.native.js +4 -0
- package/dist/esm/constants.native.js.map +1 -0
- package/dist/esm/createNativeToast.mjs +32 -0
- package/dist/esm/createNativeToast.mjs.map +1 -0
- package/dist/esm/createNativeToast.native.js +30 -0
- package/dist/esm/createNativeToast.native.js.map +1 -0
- package/dist/esm/dispatchNativeToast.mjs +22 -0
- package/dist/esm/dispatchNativeToast.mjs.map +1 -0
- package/dist/esm/dispatchNativeToast.native.js +24 -0
- package/dist/esm/dispatchNativeToast.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/dist/esm/useAnimatedDragGesture.mjs +178 -0
- package/dist/esm/useAnimatedDragGesture.mjs.map +1 -0
- package/dist/esm/useAnimatedDragGesture.native.js +185 -0
- package/dist/esm/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/esm/useReducedMotion.mjs +38 -0
- package/dist/esm/useReducedMotion.mjs.map +1 -0
- package/dist/esm/useReducedMotion.native.js +44 -0
- package/dist/esm/useReducedMotion.native.js.map +1 -0
- package/dist/esm/useToastAnimations.mjs +258 -0
- package/dist/esm/useToastAnimations.mjs.map +1 -0
- package/dist/esm/useToastAnimations.native.js +265 -0
- package/dist/esm/useToastAnimations.native.js.map +1 -0
- package/dist/esm/v2.mjs +6 -0
- package/dist/esm/v2.mjs.map +1 -0
- package/dist/esm/v2.native.js +6 -0
- package/dist/esm/v2.native.js.map +1 -0
- package/dist/jsx/Toast.mjs +137 -0
- package/dist/jsx/Toast.mjs.map +1 -0
- package/dist/jsx/Toast.native.js +181 -0
- package/dist/jsx/Toast.native.js.map +1 -0
- package/dist/jsx/ToastAnnounce.mjs +66 -0
- package/dist/jsx/ToastAnnounce.mjs.map +1 -0
- package/dist/jsx/ToastAnnounce.native.js +111 -0
- package/dist/jsx/ToastAnnounce.native.js.map +1 -0
- package/dist/jsx/ToastComposable.mjs +895 -0
- package/dist/jsx/ToastComposable.mjs.map +1 -0
- package/dist/jsx/ToastComposable.native.js +1025 -0
- package/dist/jsx/ToastComposable.native.js.map +1 -0
- package/dist/jsx/ToastImperative.mjs +80 -0
- package/dist/jsx/ToastImperative.mjs.map +1 -0
- package/dist/jsx/ToastImperative.native.js +130 -0
- package/dist/jsx/ToastImperative.native.js.map +1 -0
- package/dist/jsx/ToastImpl.mjs +316 -0
- package/dist/jsx/ToastImpl.mjs.map +1 -0
- package/dist/jsx/ToastImpl.native.js +364 -0
- package/dist/jsx/ToastImpl.native.js.map +1 -0
- package/dist/jsx/ToastItemFrame.mjs +114 -0
- package/dist/jsx/ToastItemFrame.mjs.map +1 -0
- package/dist/jsx/ToastItemFrame.native.js +148 -0
- package/dist/jsx/ToastItemFrame.native.js.map +1 -0
- package/dist/jsx/ToastPortal.mjs +24 -0
- package/dist/jsx/ToastPortal.mjs.map +1 -0
- package/dist/jsx/ToastPortal.native.js +52 -0
- package/dist/jsx/ToastPortal.native.js.map +1 -0
- package/dist/jsx/ToastProvider.mjs +110 -0
- package/dist/jsx/ToastProvider.mjs.map +1 -0
- package/dist/jsx/ToastProvider.native.js +161 -0
- package/dist/jsx/ToastProvider.native.js.map +1 -0
- package/dist/jsx/ToastState.mjs +285 -0
- package/dist/jsx/ToastState.mjs.map +1 -0
- package/dist/jsx/ToastState.native.js +324 -0
- package/dist/jsx/ToastState.native.js.map +1 -0
- package/dist/jsx/ToastViewport.mjs +280 -0
- package/dist/jsx/ToastViewport.mjs.map +1 -0
- package/dist/jsx/ToastViewport.native.js +343 -0
- package/dist/jsx/ToastViewport.native.js.map +1 -0
- package/dist/jsx/Toaster.mjs +51 -0
- package/dist/jsx/Toaster.mjs.map +1 -0
- package/dist/jsx/Toaster.native.js +91 -0
- package/dist/jsx/Toaster.native.js.map +1 -0
- package/dist/jsx/constants.mjs +4 -0
- package/dist/jsx/constants.mjs.map +1 -0
- package/dist/jsx/constants.native.js +33 -0
- package/dist/jsx/constants.native.js.map +1 -0
- package/dist/jsx/createNativeToast.mjs +32 -0
- package/dist/jsx/createNativeToast.mjs.map +1 -0
- package/dist/jsx/createNativeToast.native.js +60 -0
- package/dist/jsx/createNativeToast.native.js.map +1 -0
- package/dist/jsx/dispatchNativeToast.mjs +22 -0
- package/dist/jsx/dispatchNativeToast.mjs.map +1 -0
- package/dist/jsx/dispatchNativeToast.native.js +52 -0
- package/dist/jsx/dispatchNativeToast.native.js.map +1 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +23 -0
- package/dist/jsx/index.native.js.map +1 -0
- package/dist/jsx/types.mjs +2 -0
- package/dist/jsx/types.mjs.map +1 -0
- package/dist/jsx/types.native.js +21 -0
- package/dist/jsx/types.native.js.map +1 -0
- package/dist/jsx/useAnimatedDragGesture.mjs +178 -0
- package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -0
- package/dist/jsx/useAnimatedDragGesture.native.js +224 -0
- package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -0
- package/dist/jsx/useReducedMotion.mjs +38 -0
- package/dist/jsx/useReducedMotion.mjs.map +1 -0
- package/dist/jsx/useReducedMotion.native.js +83 -0
- package/dist/jsx/useReducedMotion.native.js.map +1 -0
- package/dist/jsx/useToastAnimations.mjs +258 -0
- package/dist/jsx/useToastAnimations.mjs.map +1 -0
- package/dist/jsx/useToastAnimations.native.js +304 -0
- package/dist/jsx/useToastAnimations.native.js.map +1 -0
- package/dist/jsx/v2.mjs +6 -0
- package/dist/jsx/v2.mjs.map +1 -0
- package/dist/jsx/v2.native.js +39 -0
- package/dist/jsx/v2.native.js.map +1 -0
- package/package.json +83 -0
- package/src/Toast.tsx +219 -0
- package/src/ToastAnnounce.tsx +103 -0
- package/src/ToastComposable.tsx +1380 -0
- package/src/ToastImperative.tsx +192 -0
- package/src/ToastImpl.tsx +514 -0
- package/src/ToastItemFrame.tsx +136 -0
- package/src/ToastPortal.tsx +19 -0
- package/src/ToastProvider.tsx +204 -0
- package/src/ToastState.ts +398 -0
- package/src/ToastViewport.tsx +430 -0
- package/src/Toaster.tsx +181 -0
- package/src/constants.ts +2 -0
- package/src/createNativeToast.native.tsx +33 -0
- package/src/createNativeToast.tsx +42 -0
- package/src/dispatchNativeToast.ts +43 -0
- package/src/index.ts +3 -0
- package/src/types.ts +71 -0
- package/src/useAnimatedDragGesture.native.ts +255 -0
- package/src/useAnimatedDragGesture.ts +319 -0
- package/src/useReducedMotion.ts +59 -0
- package/src/useToastAnimations.ts +377 -0
- package/src/v2.ts +31 -0
- package/types/Toast.d.ts +84 -0
- package/types/Toast.d.ts.map +1 -0
- package/types/ToastAnnounce.d.ts +18 -0
- package/types/ToastAnnounce.d.ts.map +1 -0
- package/types/ToastComposable.d.ts +199 -0
- package/types/ToastComposable.d.ts.map +1 -0
- package/types/ToastImperative.d.ts +95 -0
- package/types/ToastImperative.d.ts.map +1 -0
- package/types/ToastImpl.d.ts +109 -0
- package/types/ToastImpl.d.ts.map +1 -0
- package/types/ToastItemFrame.d.ts +25 -0
- package/types/ToastItemFrame.d.ts.map +1 -0
- package/types/ToastPortal.d.ts +8 -0
- package/types/ToastPortal.d.ts.map +1 -0
- package/types/ToastProvider.d.ts +92 -0
- package/types/ToastProvider.d.ts.map +1 -0
- package/types/ToastState.d.ts +179 -0
- package/types/ToastState.d.ts.map +1 -0
- package/types/ToastViewport.d.ts +75 -0
- package/types/ToastViewport.d.ts.map +1 -0
- package/types/Toaster.d.ts +112 -0
- package/types/Toaster.d.ts.map +1 -0
- package/types/constants.d.ts +3 -0
- package/types/constants.d.ts.map +1 -0
- package/types/createNativeToast.d.ts +9 -0
- package/types/createNativeToast.d.ts.map +1 -0
- package/types/createNativeToast.native.d.ts +5 -0
- package/types/createNativeToast.native.d.ts.map +1 -0
- package/types/dispatchNativeToast.d.ts +12 -0
- package/types/dispatchNativeToast.d.ts.map +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/types.d.ts +61 -0
- package/types/types.d.ts.map +1 -0
- package/types/useAnimatedDragGesture.d.ts +33 -0
- package/types/useAnimatedDragGesture.d.ts.map +1 -0
- package/types/useAnimatedDragGesture.native.d.ts +33 -0
- package/types/useAnimatedDragGesture.native.d.ts.map +1 -0
- package/types/useReducedMotion.d.ts +6 -0
- package/types/useReducedMotion.d.ts.map +1 -0
- package/types/useToastAnimations.d.ts +50 -0
- package/types/useToastAnimations.d.ts.map +1 -0
- package/types/v2.d.ts +10 -0
- package/types/v2.d.ts.map +1 -0
- package/v2/index.cjs +2 -0
- package/v2/index.js +2 -0
- package/v2/index.native.cjs +2 -0
- package/v2/index.native.js +2 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared visual styled components for toast items.
|
|
3
|
+
* Shared across web and native — imported by ToastComposable.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { styled } from '@hanzogui/core'
|
|
7
|
+
import { XStack, YStack } from '@hanzogui/stacks'
|
|
8
|
+
import { SizableText } from '@hanzogui/text'
|
|
9
|
+
|
|
10
|
+
/* -------------------------------------------------------------------------------------------------
|
|
11
|
+
* ToastPositionWrapper - handles absolute positioning and stacking animations
|
|
12
|
+
* On web: uses Hanzogui transition/enterStyle/exitStyle
|
|
13
|
+
* On native: replaced by Animated.View with useAnimatedStyle
|
|
14
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
15
|
+
|
|
16
|
+
export const ToastPositionWrapper = styled(YStack, {
|
|
17
|
+
name: 'ToastPositionWrapper',
|
|
18
|
+
pointerEvents: 'auto',
|
|
19
|
+
position: 'absolute',
|
|
20
|
+
left: 0,
|
|
21
|
+
right: 0,
|
|
22
|
+
opacity: 1,
|
|
23
|
+
scale: 1,
|
|
24
|
+
y: 0,
|
|
25
|
+
x: 0,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
/* -------------------------------------------------------------------------------------------------
|
|
29
|
+
* ToastItemFrame - visual styling for the toast
|
|
30
|
+
* Shared across web and native — the visual appearance of the toast card.
|
|
31
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
32
|
+
|
|
33
|
+
export const ToastItemFrame = styled(YStack, {
|
|
34
|
+
name: 'ToastItem',
|
|
35
|
+
userSelect: 'none',
|
|
36
|
+
cursor: 'default',
|
|
37
|
+
focusable: true,
|
|
38
|
+
|
|
39
|
+
variants: {
|
|
40
|
+
unstyled: {
|
|
41
|
+
false: {
|
|
42
|
+
backgroundColor: '$background',
|
|
43
|
+
borderRadius: '$6',
|
|
44
|
+
paddingHorizontal: '$4',
|
|
45
|
+
paddingVertical: '$3',
|
|
46
|
+
borderWidth: 1,
|
|
47
|
+
borderColor: '$borderColor',
|
|
48
|
+
shadowColor: 'rgba(0, 0, 0, 0.15)',
|
|
49
|
+
shadowOffset: { width: 0, height: 4 },
|
|
50
|
+
shadowRadius: 12,
|
|
51
|
+
focusVisibleStyle: {
|
|
52
|
+
outlineWidth: 2,
|
|
53
|
+
outlineColor: '$color8',
|
|
54
|
+
outlineStyle: 'solid',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
} as const,
|
|
59
|
+
|
|
60
|
+
defaultVariants: {
|
|
61
|
+
unstyled: process.env.HANZOGUI_HEADLESS === '1',
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
/* -------------------------------------------------------------------------------------------------
|
|
66
|
+
* ToastCloseFrame
|
|
67
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
68
|
+
|
|
69
|
+
export const ToastCloseFrame = styled(XStack, {
|
|
70
|
+
name: 'ToastClose',
|
|
71
|
+
render: 'button',
|
|
72
|
+
alignItems: 'center',
|
|
73
|
+
justifyContent: 'center',
|
|
74
|
+
cursor: 'pointer',
|
|
75
|
+
|
|
76
|
+
variants: {
|
|
77
|
+
unstyled: {
|
|
78
|
+
false: {
|
|
79
|
+
width: 18,
|
|
80
|
+
height: 18,
|
|
81
|
+
borderRadius: '$10',
|
|
82
|
+
backgroundColor: '$background',
|
|
83
|
+
borderWidth: 1,
|
|
84
|
+
borderColor: '$borderColor',
|
|
85
|
+
shadowColor: 'rgba(0, 0, 0, 0.08)',
|
|
86
|
+
shadowOffset: { width: 0, height: 1 },
|
|
87
|
+
shadowRadius: 3,
|
|
88
|
+
hoverStyle: { backgroundColor: '$color3' },
|
|
89
|
+
pressStyle: { backgroundColor: '$color4' },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
} as const,
|
|
93
|
+
|
|
94
|
+
defaultVariants: {
|
|
95
|
+
unstyled: process.env.HANZOGUI_HEADLESS === '1',
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
/* -------------------------------------------------------------------------------------------------
|
|
100
|
+
* ToastActionFrame - for action/cancel buttons with text
|
|
101
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
102
|
+
|
|
103
|
+
export const ToastActionFrame = styled(XStack, {
|
|
104
|
+
name: 'ToastAction',
|
|
105
|
+
render: 'button',
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
cursor: 'pointer',
|
|
109
|
+
|
|
110
|
+
variants: {
|
|
111
|
+
unstyled: {
|
|
112
|
+
false: {
|
|
113
|
+
borderRadius: '$2',
|
|
114
|
+
paddingHorizontal: '$2',
|
|
115
|
+
height: 24,
|
|
116
|
+
backgroundColor: '$color5',
|
|
117
|
+
hoverStyle: { backgroundColor: '$color6' },
|
|
118
|
+
pressStyle: { backgroundColor: '$color7' },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
} as const,
|
|
122
|
+
|
|
123
|
+
defaultVariants: {
|
|
124
|
+
unstyled: process.env.HANZOGUI_HEADLESS === '1',
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
/* -------------------------------------------------------------------------------------------------
|
|
129
|
+
* DefaultCloseIcon
|
|
130
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
131
|
+
|
|
132
|
+
export const DefaultCloseIcon = () => (
|
|
133
|
+
<SizableText size="$1" color="$color11">
|
|
134
|
+
✕
|
|
135
|
+
</SizableText>
|
|
136
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isWeb } from '@hanzogui/constants'
|
|
2
|
+
import { Portal } from '@hanzogui/portal'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import { ReprogapateToastProvider, type ToastProviderContextValue } from './ToastProvider'
|
|
5
|
+
|
|
6
|
+
export function ToastPortal(props: {
|
|
7
|
+
children: ReactNode
|
|
8
|
+
zIndex?: number
|
|
9
|
+
context: ToastProviderContextValue
|
|
10
|
+
}) {
|
|
11
|
+
const { context, children, zIndex } = props
|
|
12
|
+
let content = children
|
|
13
|
+
if (!isWeb) {
|
|
14
|
+
content = (
|
|
15
|
+
<ReprogapateToastProvider context={context}>{children}</ReprogapateToastProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
return <Portal zIndex={zIndex || Number.MAX_SAFE_INTEGER}>{content}</Portal>
|
|
19
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { createCollection } from '@hanzogui/collection'
|
|
2
|
+
import type { NativeValue, HanzoguiElement } from '@hanzogui/core'
|
|
3
|
+
import { createStyledContext } from '@hanzogui/core'
|
|
4
|
+
import { startTransition } from '@hanzogui/start-transition'
|
|
5
|
+
import * as React from 'react'
|
|
6
|
+
|
|
7
|
+
import { TOAST_CONTEXT } from './constants'
|
|
8
|
+
import type { ToastImperativeOptions } from './ToastImperative'
|
|
9
|
+
import { ToastImperativeProvider } from './ToastImperative'
|
|
10
|
+
import type { BurntToastOptions } from './types'
|
|
11
|
+
|
|
12
|
+
/* -------------------------------------------------------------------------------------------------
|
|
13
|
+
* ToastProvider
|
|
14
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
15
|
+
|
|
16
|
+
const PROVIDER_NAME = 'ToastProvider'
|
|
17
|
+
|
|
18
|
+
const [Collection, useCollection] = createCollection<HanzoguiElement>('Toast')
|
|
19
|
+
|
|
20
|
+
export type SwipeDirection =
|
|
21
|
+
| 'vertical'
|
|
22
|
+
| 'up'
|
|
23
|
+
| 'down'
|
|
24
|
+
| 'horizontal'
|
|
25
|
+
| 'left'
|
|
26
|
+
| 'right'
|
|
27
|
+
| 'auto'
|
|
28
|
+
|
|
29
|
+
export type ToastProviderContextValue = {
|
|
30
|
+
id: string
|
|
31
|
+
toastScope: string
|
|
32
|
+
label: string
|
|
33
|
+
duration: number
|
|
34
|
+
swipeDirection: SwipeDirection
|
|
35
|
+
swipeThreshold: number
|
|
36
|
+
toastCount: number
|
|
37
|
+
viewports: Record<string, HanzoguiElement | null>
|
|
38
|
+
onViewportChange(name: string, viewport: HanzoguiElement): void
|
|
39
|
+
onToastAdd(): void
|
|
40
|
+
onToastRemove(): void
|
|
41
|
+
isFocusedToastEscapeKeyDownRef: React.MutableRefObject<boolean>
|
|
42
|
+
isClosePausedRef: React.MutableRefObject<boolean>
|
|
43
|
+
options: ToastImperativeOptions
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type ToastScopes = string
|
|
47
|
+
|
|
48
|
+
type ScopedProps<P> = Omit<P, 'scope'> & { scope?: ToastScopes }
|
|
49
|
+
|
|
50
|
+
const { Provider: ToastProviderProvider, useStyledContext: useToastProviderContext } =
|
|
51
|
+
createStyledContext<ToastProviderContextValue>(
|
|
52
|
+
// since we always provide this we can avoid setting here
|
|
53
|
+
{} as ToastProviderContextValue,
|
|
54
|
+
'Toast__'
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
interface ToastProviderProps {
|
|
58
|
+
children?: React.ReactNode
|
|
59
|
+
/**
|
|
60
|
+
* An author-localized label for each toast. Used to help screen reader users
|
|
61
|
+
* associate the interruption with a toast.
|
|
62
|
+
* @defaultValue 'Notification'
|
|
63
|
+
*/
|
|
64
|
+
label?: string
|
|
65
|
+
/**
|
|
66
|
+
* Time in milliseconds that each toast should remain visible for.
|
|
67
|
+
* @defaultValue 5000
|
|
68
|
+
*/
|
|
69
|
+
duration?: number
|
|
70
|
+
/**
|
|
71
|
+
* Direction of pointer swipe that should close the toast.
|
|
72
|
+
* @defaultValue 'right'
|
|
73
|
+
*/
|
|
74
|
+
swipeDirection?: SwipeDirection
|
|
75
|
+
/**
|
|
76
|
+
* Distance in pixels that the swipe must pass before a close is triggered.
|
|
77
|
+
* @defaultValue 50
|
|
78
|
+
*/
|
|
79
|
+
swipeThreshold?: number
|
|
80
|
+
/**
|
|
81
|
+
* @defaultValue unique generated identifier
|
|
82
|
+
*/
|
|
83
|
+
id?: string
|
|
84
|
+
/**
|
|
85
|
+
* Will show a native toast if is true or is set to the current platform. On iOS, it wraps `SPIndicator` and `SPAlert`. On Android, it wraps `ToastAndroid`. On web, it wraps Notification API. Mobile's native features are handled by `burnt`.
|
|
86
|
+
* Only works with the imperative `useToast` hook.
|
|
87
|
+
*/
|
|
88
|
+
native?: NativeValue
|
|
89
|
+
/**
|
|
90
|
+
* Options for the burnt package if you're using native toasts on mobile
|
|
91
|
+
*/
|
|
92
|
+
burntOptions?: Omit<BurntToastOptions, 'title' | 'message' | 'duration'>
|
|
93
|
+
/**
|
|
94
|
+
* Options for the notification API if you're using native toasts on web
|
|
95
|
+
*/
|
|
96
|
+
notificationOptions?: NotificationOptions
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const ToastProvider: React.FC<ToastProviderProps> = (
|
|
100
|
+
props: ScopedProps<ToastProviderProps>
|
|
101
|
+
) => {
|
|
102
|
+
const {
|
|
103
|
+
scope = TOAST_CONTEXT,
|
|
104
|
+
id: providedId,
|
|
105
|
+
burntOptions,
|
|
106
|
+
native,
|
|
107
|
+
notificationOptions,
|
|
108
|
+
label = 'Notification',
|
|
109
|
+
duration = 5000,
|
|
110
|
+
swipeDirection = 'right',
|
|
111
|
+
swipeThreshold = 50,
|
|
112
|
+
children,
|
|
113
|
+
} = props
|
|
114
|
+
const backupId = React.useId()
|
|
115
|
+
const id = providedId ?? backupId
|
|
116
|
+
const [viewports, setViewports] = React.useState<
|
|
117
|
+
ToastProviderContextValue['viewports']
|
|
118
|
+
>({})
|
|
119
|
+
const [toastCount, setToastCount] = React.useState(0)
|
|
120
|
+
const isFocusedToastEscapeKeyDownRef = React.useRef(false)
|
|
121
|
+
const isClosePausedRef = React.useRef(false)
|
|
122
|
+
|
|
123
|
+
const handleViewportChange = React.useCallback(
|
|
124
|
+
(name: string, viewport: HanzoguiElement | null) => {
|
|
125
|
+
startTransition(() => {
|
|
126
|
+
setViewports((prev) => ({ ...prev, [name]: viewport }))
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
[]
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
// memo context to avoid expensive re-renders
|
|
133
|
+
const options = React.useMemo(() => {
|
|
134
|
+
return {
|
|
135
|
+
duration,
|
|
136
|
+
burntOptions,
|
|
137
|
+
native,
|
|
138
|
+
notificationOptions,
|
|
139
|
+
}
|
|
140
|
+
// nested simple object so JSON.stringify
|
|
141
|
+
}, [JSON.stringify([duration, burntOptions, native, notificationOptions])])
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<Collection.Provider scope={scope}>
|
|
145
|
+
<ToastProviderProvider
|
|
146
|
+
scope={scope}
|
|
147
|
+
id={id}
|
|
148
|
+
label={label}
|
|
149
|
+
duration={duration}
|
|
150
|
+
swipeDirection={swipeDirection}
|
|
151
|
+
swipeThreshold={swipeThreshold}
|
|
152
|
+
toastCount={toastCount}
|
|
153
|
+
viewports={viewports}
|
|
154
|
+
onViewportChange={handleViewportChange}
|
|
155
|
+
onToastAdd={React.useCallback(() => {
|
|
156
|
+
startTransition(() => {
|
|
157
|
+
setToastCount((prevCount) => prevCount + 1)
|
|
158
|
+
})
|
|
159
|
+
}, [])}
|
|
160
|
+
onToastRemove={React.useCallback(() => {
|
|
161
|
+
startTransition(() => {
|
|
162
|
+
setToastCount((prevCount) => prevCount - 1)
|
|
163
|
+
})
|
|
164
|
+
}, [])}
|
|
165
|
+
isFocusedToastEscapeKeyDownRef={isFocusedToastEscapeKeyDownRef}
|
|
166
|
+
isClosePausedRef={isClosePausedRef}
|
|
167
|
+
options={options}
|
|
168
|
+
>
|
|
169
|
+
<ToastImperativeProvider options={options}>{children}</ToastImperativeProvider>
|
|
170
|
+
</ToastProviderProvider>
|
|
171
|
+
</Collection.Provider>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function ReprogapateToastProvider(props: {
|
|
176
|
+
children: React.ReactNode
|
|
177
|
+
context: ToastProviderContextValue
|
|
178
|
+
}) {
|
|
179
|
+
const { children, context } = props
|
|
180
|
+
return (
|
|
181
|
+
<Collection.Provider scope={context.toastScope}>
|
|
182
|
+
<ToastProviderProvider {...context}>
|
|
183
|
+
<ToastImperativeProvider options={context.options}>
|
|
184
|
+
{children}
|
|
185
|
+
</ToastImperativeProvider>
|
|
186
|
+
</ToastProviderProvider>
|
|
187
|
+
</Collection.Provider>
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
ToastProvider.propTypes = {
|
|
192
|
+
label(props) {
|
|
193
|
+
if (props.label && typeof props.label === 'string' && !props.label.trim()) {
|
|
194
|
+
const error = `Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`
|
|
195
|
+
return new Error(error)
|
|
196
|
+
}
|
|
197
|
+
return null
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
ToastProvider.displayName = PROVIDER_NAME
|
|
202
|
+
|
|
203
|
+
export { Collection, ToastProvider, useCollection, useToastProviderContext }
|
|
204
|
+
export type { ScopedProps, ToastProviderProps }
|