refactor: update Notification component to use message and type props

This commit is contained in:
Md Asif 2024-12-24 00:40:12 +05:30
parent f7fea99f30
commit 8b34a69dca

View File

@ -3,49 +3,46 @@ import { Copy } from "lucide-react";
import { motion } from "motion/react";
import PropTypes from "prop-types";
function Notification({ notification }) {
return <motion.div
initial={{ y: 15, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: 15, opacity: 0 }}
className={clsx(
function Notification({ message, type }) {
return (
<motion.div
initial={{ y: 15, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: 15, opacity: 0 }}
className={clsx(
"p-2 pl-8 mb-8 font-body text-lg border-2 rounded-3xl flex items-center gap-2",
notification.type === "error"
? "bg-error-surface text-white border-error"
: notification.type === "success"
? "bg-success text-white border-green-700"
: notification.type === "warning"
? "bg-warning-surface text-white border-warning"
: ""
)}
>
{notification.message.split(":").map((msg, index) => {
type === "error"
? "bg-error-surface text-white border-error"
: type === "success"
? "bg-success text-white border-green-700"
: type === "warning"
? "bg-warning-surface text-white border-warning"
: ""
)}
>
{message.split(":").map((msg, index) => {
return index === 1 ? (
<span key={index} className="border-b border-dashed">
{msg}
</span>
<span key={index} className="border-b border-dashed">
{msg}
</span>
) : (
<span key={index}>{msg}</span>
<span key={index}>{msg}</span>
);
})}
{notification.message.split(":")[1] && (
})}
{message.split(":")[1] && (
<Copy
cursor={"pointer"}
size={15}
onClick={navigator.clipboard.writeText(
notification.message.split(":")[1].trim()
)}
cursor={"pointer"}
size={15}
onClick={navigator.clipboard.writeText(message.split(":")[1].trim())}
/>
)}
</motion.div>;
)}
</motion.div>
);
}
Notification.propTypes = {
notification: PropTypes.shape({
visible: PropTypes.bool,
message: PropTypes.string,
type: PropTypes.string,
}),
message: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
};
export default Notification;