-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b3f52c
commit 3fed35a
Showing
7 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
Alert, | ||
AlertDescription, | ||
AlertTitle, | ||
Flex, | ||
Icon, | ||
IconButton, | ||
type UseToastOptions, | ||
} from "@chakra-ui/react"; | ||
import { type ReactNode } from "react"; | ||
|
||
import { | ||
AlertCircleIcon, | ||
AlertOctagonIcon, | ||
AlertTriangleIcon, | ||
CheckCircleIcon, | ||
CloseIcon, | ||
} from "../../assets/icons"; | ||
import { useColor } from "../../styles/useColor"; | ||
|
||
type CustomToastProps = { | ||
onClose: () => void; | ||
} & UseToastOptions; | ||
|
||
export const CustomToast = (props: CustomToastProps): ReactNode => { | ||
const color = useColor(); | ||
|
||
const { status, id, title, isClosable, onClose, description } = props; | ||
|
||
const ids = id | ||
? { | ||
root: `toast-${id}`, | ||
title: `toast-${id}-title`, | ||
description: `toast-${id}-description`, | ||
} | ||
: undefined; | ||
|
||
const AlertIcon = () => { | ||
switch (props.status) { | ||
case "info": | ||
return <AlertCircleIcon />; | ||
case "success": | ||
return <CheckCircleIcon />; | ||
case "error": | ||
return <AlertTriangleIcon />; | ||
case "warning": | ||
return <AlertOctagonIcon />; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
return ( | ||
<Alert addRole={false} id={ids?.root} status={status}> | ||
<Icon as={AlertIcon} /> | ||
<Flex width="full" marginLeft="6px"> | ||
{title && <AlertTitle id={ids?.title}>{title}</AlertTitle>} | ||
{description && ( | ||
<AlertDescription marginRight="12px" id={ids?.description}> | ||
{description} | ||
</AlertDescription> | ||
)} | ||
</Flex> | ||
{isClosable && ( | ||
<IconButton | ||
boxSize="24px" | ||
marginLeft="auto" | ||
color={color("400")} | ||
aria-label="Close toast" | ||
icon={<CloseIcon />} | ||
onClick={onClose} | ||
variant="empty" | ||
/> | ||
)} | ||
</Alert> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./CustomToast"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3fed35a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.