|
1 | | -import { Toast } from 'heroui-native'; |
| 1 | +import { Button, Toast, useToaster } from 'heroui-native'; |
| 2 | +import { useEffect, useState } from 'react'; |
2 | 3 | import { View } from 'react-native'; |
3 | 4 | import type { UsageVariant } from '../../../components/component-presentation/types'; |
4 | 5 | import { UsageVariantFlatList } from '../../../components/component-presentation/usage-variant-flatlist'; |
@@ -68,12 +69,143 @@ const AllVariantsContent = () => { |
68 | 69 |
|
69 | 70 | // ------------------------------------------------------------------------------ |
70 | 71 |
|
| 72 | +const InteractiveDemoContent = () => { |
| 73 | + const toast = useToaster(); |
| 74 | + |
| 75 | + const myToast = toast.prepare({ |
| 76 | + component: (id) => ( |
| 77 | + <Toast variant="accent" className="flex-row items-center gap-3"> |
| 78 | + <View className="flex-1"> |
| 79 | + <Toast.Label>Interactive Toast</Toast.Label> |
| 80 | + <Toast.Description> |
| 81 | + Use buttons below to control this toast |
| 82 | + </Toast.Description> |
| 83 | + </View> |
| 84 | + <Toast.Action onPress={() => toast.hide(id)}>Close</Toast.Action> |
| 85 | + </Toast> |
| 86 | + ), |
| 87 | + }); |
| 88 | + |
| 89 | + return ( |
| 90 | + <View className="flex-1 px-5"> |
| 91 | + <View className="flex-1 justify-center gap-3"> |
| 92 | + <Button onPress={() => toast.show(myToast)} variant="primary"> |
| 93 | + Show Toast |
| 94 | + </Button> |
| 95 | + |
| 96 | + <Button onPress={() => toast.hide(myToast)} variant="secondary"> |
| 97 | + Hide Toast |
| 98 | + </Button> |
| 99 | + |
| 100 | + <Button onPress={() => toast.remove(myToast)} variant="destructive"> |
| 101 | + Remove Toast |
| 102 | + </Button> |
| 103 | + </View> |
| 104 | + </View> |
| 105 | + ); |
| 106 | +}; |
| 107 | + |
| 108 | +// ------------------------------------------------------------------------------ |
| 109 | + |
| 110 | +const MultipleToastsContent = () => { |
| 111 | + const toast = useToaster(); |
| 112 | + |
| 113 | + const toast1 = toast.prepare({ |
| 114 | + component: (id: string) => ( |
| 115 | + <Toast |
| 116 | + variant="default" |
| 117 | + placement="top" |
| 118 | + className="flex-row items-center gap-3" |
| 119 | + > |
| 120 | + <View className="flex-1"> |
| 121 | + <Toast.Label>Toast 1</Toast.Label> |
| 122 | + <Toast.Description>First toast at top</Toast.Description> |
| 123 | + </View> |
| 124 | + <Toast.Action onPress={() => toast.hide(id)}>Close</Toast.Action> |
| 125 | + </Toast> |
| 126 | + ), |
| 127 | + }); |
| 128 | + |
| 129 | + const toast2 = toast.prepare({ |
| 130 | + component: (id: string) => ( |
| 131 | + <Toast |
| 132 | + variant="accent" |
| 133 | + placement="top" |
| 134 | + className="flex-row items-center gap-3" |
| 135 | + > |
| 136 | + <View className="flex-1"> |
| 137 | + <Toast.Label>Toast 2</Toast.Label> |
| 138 | + <Toast.Description>Second toast at top</Toast.Description> |
| 139 | + </View> |
| 140 | + <Toast.Action onPress={() => toast.hide(id)}>Close</Toast.Action> |
| 141 | + </Toast> |
| 142 | + ), |
| 143 | + }); |
| 144 | + |
| 145 | + const toast3 = toast.prepare({ |
| 146 | + component: (id: string) => ( |
| 147 | + <Toast |
| 148 | + variant="success" |
| 149 | + placement="bottom" |
| 150 | + className="flex-row items-center gap-3" |
| 151 | + > |
| 152 | + <View className="flex-1"> |
| 153 | + <Toast.Label>Toast 3</Toast.Label> |
| 154 | + <Toast.Description>Third toast at bottom</Toast.Description> |
| 155 | + </View> |
| 156 | + <Toast.Action onPress={() => toast.hide(id)}>Close</Toast.Action> |
| 157 | + </Toast> |
| 158 | + ), |
| 159 | + }); |
| 160 | + |
| 161 | + const allToasts = [toast1, toast2, toast3]; |
| 162 | + |
| 163 | + return ( |
| 164 | + <View className="flex-1 px-5"> |
| 165 | + <View className="flex-1 justify-center gap-3"> |
| 166 | + <Button |
| 167 | + onPress={() => allToasts.forEach((id) => toast.show(id))} |
| 168 | + variant="primary" |
| 169 | + > |
| 170 | + Show All Toasts |
| 171 | + </Button> |
| 172 | + |
| 173 | + <Button |
| 174 | + onPress={() => allToasts.forEach((id) => toast.hide(id))} |
| 175 | + variant="secondary" |
| 176 | + > |
| 177 | + Hide All Toasts |
| 178 | + </Button> |
| 179 | + |
| 180 | + <Button |
| 181 | + onPress={() => allToasts.forEach((id) => toast.remove(id))} |
| 182 | + variant="destructive" |
| 183 | + > |
| 184 | + Remove All Toasts |
| 185 | + </Button> |
| 186 | + </View> |
| 187 | + </View> |
| 188 | + ); |
| 189 | +}; |
| 190 | + |
| 191 | +// ------------------------------------------------------------------------------ |
| 192 | + |
71 | 193 | const TOAST_VARIANTS: UsageVariant[] = [ |
| 194 | + // { |
| 195 | + // value: 'all-variants', |
| 196 | + // label: 'All variants', |
| 197 | + // content: <AllVariantsContent />, |
| 198 | + // }, |
72 | 199 | { |
73 | | - value: 'all-variants', |
74 | | - label: 'All variants', |
75 | | - content: <AllVariantsContent />, |
| 200 | + value: 'interactive-demo', |
| 201 | + label: 'Interactive Demo', |
| 202 | + content: <InteractiveDemoContent />, |
76 | 203 | }, |
| 204 | + // { |
| 205 | + // value: 'multiple-toasts', |
| 206 | + // label: 'Multiple Toasts', |
| 207 | + // content: <MultipleToastsContent />, |
| 208 | + // }, |
77 | 209 | ]; |
78 | 210 |
|
79 | 211 | export default function ToastScreen() { |
|
0 commit comments