imetting_frontend/src/components/Toast.jsx

39 lines
990 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import React, { useEffect } from 'react';
import { CheckCircle, XCircle, AlertCircle, Info } from 'lucide-react';
import './Toast.css';
const Toast = ({ message, type = 'info', duration = 3000, onClose }) => {
useEffect(() => {
if (duration > 0) {
const timer = setTimeout(() => {
onClose();
}, duration);
return () => clearTimeout(timer);
}
}, [duration, onClose]);
const getIcon = () => {
switch (type) {
case 'success':
return <CheckCircle size={20} />;
case 'error':
return <XCircle size={20} />;
case 'warning':
return <AlertCircle size={20} />;
case 'info':
default:
return <Info size={20} />;
}
};
return (
<div className={`toast toast-${type}`}>
<div className="toast-icon">{getIcon()}</div>
<div className="toast-message">{message}</div>
<button className="toast-close" onClick={onClose}>×</button>
</div>
);
};
export default Toast;