35 lines
761 B
TypeScript
35 lines
761 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-success',
|
|
error: 'bg-error',
|
|
warning: 'bg-warning',
|
|
info: 'bg-primary',
|
|
}[type];
|
|
|
|
return (
|
|
<div
|
|
className={`fixed bottom-4 right-4 ${bgColor} text-foreground px-4 py-2 shadow-lg z-50 animate-fade-in`}
|
|
role="alert"
|
|
aria-live="polite"
|
|
>
|
|
{message}
|
|
</div>
|
|
);
|
|
}
|