game_list/frontend/src/Toast.tsx
2025-12-18 19:23:05 +01:00

46 lines
920 B
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 React, { useEffect } from "react";
export type ToastType = "success" | "error" | "info";
interface ToastProps {
message: string;
type: ToastType;
onClose: () => void;
duration?: number;
}
export const Toast: React.FC<ToastProps> = ({
message,
type,
onClose,
duration = 3000,
}) => {
useEffect(() => {
const timer = setTimeout(() => {
onClose();
}, duration);
return () => clearTimeout(timer);
}, [onClose, duration]);
const getIcon = () => {
switch (type) {
case "success":
return "✓";
case "error":
return "✕";
default:
return "";
}
};
return (
<div className={`toast toast-${type}`}>
<span className="toast-icon">{getIcon()}</span>
<span className="toast-message">{message}</span>
<button className="toast-close" onClick={onClose}>
&times;
</button>
</div>
);
};