|
1 | | -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import { Icon, CloseIcon } from '@/components/ui/icon'; |
3 | 3 | import { VStack } from '@/components/ui/vstack'; |
4 | 4 | import { Pressable } from '@/components/ui/pressable'; |
@@ -26,31 +26,46 @@ const ToastFigmaStory = ({ _placement = 'top', _colorMode, ...props }: any) => { |
26 | 26 | ); |
27 | 27 | }; |
28 | 28 |
|
29 | | -const ToastBasic = ({ placement = 'top', ...props }: any) => { |
| 29 | +const ToastBasic = ({ ...props }: any) => { |
30 | 30 | const toast = useToast(); |
| 31 | + const [toastId, setToastId] = useState<number>(0); |
| 32 | + |
| 33 | + const handleToast = () => { |
| 34 | + if (!toast.isActive(toastId)) { |
| 35 | + showNewToast(); |
| 36 | + } |
| 37 | + }; |
| 38 | + |
| 39 | + const showNewToast = () => { |
| 40 | + const newId = Math.random(); |
| 41 | + setToastId(newId); |
| 42 | + |
| 43 | + toast.show({ |
| 44 | + id: newId, |
| 45 | + placement: props.placement, |
| 46 | + duration: 3000, |
| 47 | + // duration: null, |
| 48 | + render: ({ id }) => { |
| 49 | + const uniqueToastId = `toast-${id}`; |
| 50 | + return ( |
| 51 | + <Toast nativeID={uniqueToastId} {...props} className="flex-row gap-3"> |
| 52 | + <VStack space="xs"> |
| 53 | + <ToastTitle>Hello World Toast</ToastTitle> |
| 54 | + <ToastDescription> |
| 55 | + Please create a support ticket from the support page |
| 56 | + </ToastDescription> |
| 57 | + </VStack> |
| 58 | + <Pressable onPress={() => toast.close(id)}> |
| 59 | + <Icon as={CloseIcon} className="stroke-background-200" /> |
| 60 | + </Pressable> |
| 61 | + </Toast> |
| 62 | + ); |
| 63 | + }, |
| 64 | + }); |
| 65 | + }; |
| 66 | + |
31 | 67 | return ( |
32 | | - <Button |
33 | | - onPress={() => { |
34 | | - toast.show({ |
35 | | - placement: placement, |
36 | | - duration: 3000, |
37 | | - // duration: null, |
38 | | - render: ({ id }) => { |
39 | | - const toastId = `toast-${id}`; |
40 | | - return ( |
41 | | - <> |
42 | | - <Toast nativeID={toastId} {...props}> |
43 | | - <ToastTitle>Toast Heading</ToastTitle> |
44 | | - <ToastDescription> |
45 | | - Lorem ipsum dolor sit amet consectetur. |
46 | | - </ToastDescription> |
47 | | - </Toast> |
48 | | - </> |
49 | | - ); |
50 | | - }, |
51 | | - }); |
52 | | - }} |
53 | | - > |
| 68 | + <Button onPress={handleToast}> |
54 | 69 | <ButtonText>Press Me</ButtonText> |
55 | 70 | </Button> |
56 | 71 | ); |
|
0 commit comments