35 lines
774 B
TypeScript
35 lines
774 B
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
export interface ToastProps {
|
|
type: 'success' | 'error' | 'warning' | 'info';
|
|
message: string;
|
|
onClose: () => void;
|
|
duration?: number;
|
|
}
|
|
|
|
export function Toast({ type, message, onClose, duration = 3000 }: ToastProps) {
|
|
useEffect(() => {
|
|
const timer = setTimeout(onClose, duration);
|
|
return () => clearTimeout(timer);
|
|
}, [onClose, duration]);
|
|
|
|
const bgColor = {
|
|
success: 'bg-green-500',
|
|
error: 'bg-red-500',
|
|
warning: 'bg-yellow-500',
|
|
info: 'bg-blue-500',
|
|
}[type];
|
|
|
|
return (
|
|
<div
|
|
className={`fixed bottom-4 right-4 ${bgColor} text-white px-4 py-2 rounded shadow-none z-50 animate-fade-in`}
|
|
role="alert"
|
|
aria-live="polite"
|
|
>
|
|
{message}
|
|
</div>
|
|
);
|
|
}
|