Files
projet_gestion_commande/frontend-prep/src/components/Toast.tsx
T

55 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useState } from "react";
import "./Toast.css";
interface ToastProps {
message: string;
type?: "success" | "error" | "warning" | "info";
duration?: number;
onClose?: () => void;
}
export function Toast({
message,
type = "success",
duration = 3000,
onClose,
}: ToastProps) {
const [isVisible, setIsVisible] = useState(true);
useEffect(() => {
const timer = setTimeout(() => {
setIsVisible(false);
onClose?.();
}, duration);
return () => clearTimeout(timer);
}, [duration, onClose]);
if (!isVisible) return null;
const getIcon = () => {
const icons = {
success: "✓",
error: "✕",
warning: "⚠",
info: "",
};
return icons[type];
};
return (
<div className={`toast toast-${type}`}>
<div className="toast-content">
<div className="toast-icon">{getIcon()}</div>
<div className="toast-message">{message}</div>
</div>
<div
className="toast-progress"
style={{ animationDuration: `${duration}ms` }}
/>
</div>
);
}
export default Toast;