|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import { Box, Button, Flex } from '@chakra-ui/react'; |
| 4 | +import { Meta } from '@storybook/react'; |
| 5 | +import { toast } from 'sonner'; |
| 6 | + |
| 7 | +import { toastCustom } from '@/components/Toast'; |
| 8 | + |
| 9 | +export default { |
| 10 | + title: 'Components/Toast', |
| 11 | + decorators: [ |
| 12 | + (Story) => ( |
| 13 | + <Box h="10rem"> |
| 14 | + <Story /> |
| 15 | + </Box> |
| 16 | + ), |
| 17 | + ], |
| 18 | +} satisfies Meta; |
| 19 | + |
| 20 | +export const Default = () => { |
| 21 | + const handleOpenToast = (props: { status: 'success' | 'error' | 'info' }) => { |
| 22 | + toastCustom({ |
| 23 | + status: props.status, |
| 24 | + title: 'Ceci est un titre de toast', |
| 25 | + }); |
| 26 | + }; |
| 27 | + |
| 28 | + return ( |
| 29 | + <Flex gap={4}> |
| 30 | + <Button size="md" onClick={() => handleOpenToast({ status: 'success' })}> |
| 31 | + Success toast |
| 32 | + </Button> |
| 33 | + <Button size="md" onClick={() => handleOpenToast({ status: 'error' })}> |
| 34 | + Error toast |
| 35 | + </Button> |
| 36 | + <Button size="md" onClick={() => handleOpenToast({ status: 'info' })}> |
| 37 | + Info toast |
| 38 | + </Button> |
| 39 | + </Flex> |
| 40 | + ); |
| 41 | +}; |
| 42 | + |
| 43 | +export const WithDescription = () => { |
| 44 | + const handleOpenToast = (props: { status: 'success' | 'error' | 'info' }) => { |
| 45 | + toastCustom({ |
| 46 | + status: props.status, |
| 47 | + title: 'Ceci est un titre de toast', |
| 48 | + description: |
| 49 | + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis id porta lacus. Nunc tellus ipsum, blandit commodo neque at, eleifend facilisis arcu. Phasellus nec pretium sapien.', |
| 50 | + }); |
| 51 | + }; |
| 52 | + return ( |
| 53 | + <Flex gap={4}> |
| 54 | + <Button size="md" onClick={() => handleOpenToast({ status: 'success' })}> |
| 55 | + Success toast with descrition |
| 56 | + </Button> |
| 57 | + <Button size="md" onClick={() => handleOpenToast({ status: 'error' })}> |
| 58 | + Error toast with descrition |
| 59 | + </Button> |
| 60 | + <Button size="md" onClick={() => handleOpenToast({ status: 'info' })}> |
| 61 | + Info toast with descrition |
| 62 | + </Button> |
| 63 | + </Flex> |
| 64 | + ); |
| 65 | +}; |
| 66 | + |
| 67 | +export const WithActions = () => { |
| 68 | + const handleOpenToast = (props: { status: 'success' | 'error' | 'info' }) => { |
| 69 | + toastCustom({ |
| 70 | + status: props.status, |
| 71 | + title: 'Ceci est un titre de toast', |
| 72 | + actions: ( |
| 73 | + <Button onClick={() => toast.dismiss()}>Fermer les toasts</Button> |
| 74 | + ), |
| 75 | + }); |
| 76 | + }; |
| 77 | + return ( |
| 78 | + <Flex gap={4}> |
| 79 | + <Button size="md" onClick={() => handleOpenToast({ status: 'success' })}> |
| 80 | + Success toast with actions |
| 81 | + </Button> |
| 82 | + <Button size="md" onClick={() => handleOpenToast({ status: 'error' })}> |
| 83 | + Error toast with actions |
| 84 | + </Button> |
| 85 | + <Button size="md" onClick={() => handleOpenToast({ status: 'info' })}> |
| 86 | + Info toast with with actions |
| 87 | + </Button> |
| 88 | + </Flex> |
| 89 | + ); |
| 90 | +}; |
| 91 | + |
| 92 | +export const HideIcon = () => { |
| 93 | + const handleOpenToast = (props: { status: 'success' | 'error' | 'info' }) => { |
| 94 | + toastCustom({ |
| 95 | + status: props.status, |
| 96 | + title: 'Ceci est un titre de toast', |
| 97 | + hideIcon: true, |
| 98 | + }); |
| 99 | + }; |
| 100 | + return ( |
| 101 | + <Flex gap={4}> |
| 102 | + <Button size="md" onClick={() => handleOpenToast({ status: 'success' })}> |
| 103 | + Success toast without icon |
| 104 | + </Button> |
| 105 | + <Button size="md" onClick={() => handleOpenToast({ status: 'error' })}> |
| 106 | + Error toast with without icon |
| 107 | + </Button> |
| 108 | + <Button size="md" onClick={() => handleOpenToast({ status: 'info' })}> |
| 109 | + Info toast with without icon |
| 110 | + </Button> |
| 111 | + </Flex> |
| 112 | + ); |
| 113 | +}; |
0 commit comments