-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
21 changed files
with
523 additions
and
118 deletions.
There are no files selected for viewing
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
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,33 @@ | ||
import { css } from "@styled-system/css"; | ||
|
||
export const ToastWrapper = css({ | ||
display: "flex", | ||
// position: "relative", // progress barλ₯Ό μν position μ€μ | ||
gap: "2", | ||
alignItems: "center", | ||
borderRadius: "lg", | ||
width: "fit-content", | ||
paddingBlock: "2", | ||
paddingInline: "4", | ||
color: "white", | ||
backgroundColor: "gray.700", | ||
boxShadow: "lg", | ||
// overflow: "hidden", // progress barκ° λμΉμ§ μλλ‘ | ||
transition: "all", | ||
transitionDuration: "300ms", | ||
}); | ||
|
||
export const CloseItemBox = css({ | ||
width: "15px", | ||
height: "15px", | ||
}); | ||
|
||
export const ToastProgress = css({ | ||
position: "absolute", | ||
left: "0px", | ||
bottom: "0px", | ||
borderRadius: "lg", | ||
width: "100%", | ||
height: "6px", | ||
backgroundColor: "blue", | ||
}); |
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,59 @@ | ||
import { motion } from "framer-motion"; | ||
import { useState, useEffect } from "react"; | ||
import CloseIcon from "@assets/icons/close.svg?react"; | ||
import { ToastWrapper, CloseItemBox, ToastProgress } from "./Toast.style"; | ||
|
||
interface ToastProps { | ||
message: string; | ||
duration?: number; | ||
onClose: () => void; | ||
} | ||
|
||
export const Toast = ({ message, duration = 3000, onClose }: ToastProps) => { | ||
const [isVisible, setIsVisible] = useState(true); | ||
const [isClosing, setIsClosing] = useState(false); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setIsClosing(true); | ||
setTimeout(() => { | ||
setIsVisible(false); | ||
onClose(); | ||
}, 300); | ||
}, duration); | ||
|
||
return () => clearTimeout(timer); | ||
}, [duration, onClose]); | ||
|
||
const handleClose = () => { | ||
setIsClosing(true); | ||
setTimeout(() => { | ||
setIsVisible(false); | ||
onClose(); | ||
}, 300); | ||
}; | ||
if (!isVisible) return null; | ||
return ( | ||
<motion.div | ||
className={ToastWrapper} | ||
style={{ | ||
opacity: isClosing ? 0 : 1, | ||
transform: isClosing ? "translateY(100%)" : "translateY(0)", | ||
transition: "all 0.3s ease-in-out", | ||
}} | ||
exit={{ opacity: 0 }} | ||
> | ||
<motion.div | ||
initial={{ width: "0%" }} | ||
animate={{ width: "100%" }} | ||
transition={{ duration: duration / 1000, ease: "easeOut" }} | ||
className={ToastProgress} | ||
/> | ||
|
||
<span className="text-sm">{message}</span> | ||
<div className={CloseItemBox} onClick={handleClose}> | ||
<CloseIcon /> | ||
</div> | ||
</motion.div> | ||
); | ||
}; |
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,11 @@ | ||
import { css } from "@styled-system/css"; | ||
|
||
export const ToastContainerStyle = css({ | ||
display: "flex", | ||
zIndex: "9999", | ||
position: "fixed", | ||
right: "6", | ||
bottom: "6", | ||
gap: "2", | ||
flexDirection: "column-reverse", | ||
}); |
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,23 @@ | ||
import { AnimatePresence } from "framer-motion"; | ||
import { useToastStore } from "@stores/useToastStore"; | ||
import { Toast } from "./Toast"; | ||
import { ToastContainerStyle } from "./ToastContainer.style"; | ||
|
||
export const ToastContainer = () => { | ||
const { toasts, removeToast } = useToastStore(); | ||
|
||
return ( | ||
<div className={ToastContainerStyle}> | ||
<AnimatePresence> | ||
{toasts.map((toast) => ( | ||
<Toast | ||
key={toast.id} | ||
message={toast.message} | ||
duration={toast.duration} | ||
onClose={() => removeToast(toast.id)} | ||
/> | ||
))} | ||
</AnimatePresence> | ||
</div> | ||
); | ||
}; |
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
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
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
Oops, something went wrong.