Files
AetherForge/server/web/src/components/Toast/ToastStack.tsx
AetherForge f795ff2b47
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Shorten notification dwell time and add dismissible toast stack.
2026-06-07 18:22:27 -07:00

53 lines
1.6 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 { useToast } from '../../context/ToastContext';
import type { ToastLevel } from '../../context/ToastContext';
import './ToastStack.css';
const LEVEL_LABEL: Record<ToastLevel, string> = {
info: 'INFO',
success: 'OK',
warn: 'WARN',
error: 'ERROR',
};
export default function ToastStack() {
const { toasts, dismissToast, clearAllToasts } = useToast();
if (toasts.length === 0) return null;
return (
<div className="toast-stack" role="region" aria-label="Notifications" data-testid="toast-stack">
{toasts.length > 1 && (
<button
type="button"
className="toast-clear-all"
onClick={clearAllToasts}
aria-label="Clear all notifications"
>
Clear all
</button>
)}
<ul className="toast-list">
{toasts.map((toast) => (
<li key={toast.id} className={`toast-item toast-${toast.level}`} role="status">
<div className="toast-body">
<span className="toast-level font-tech">{LEVEL_LABEL[toast.level]}</span>
<div className="toast-text">
<span className="toast-message">{toast.message}</span>
{toast.detail ? <span className="toast-detail">{toast.detail}</span> : null}
</div>
</div>
<button
type="button"
className="toast-dismiss"
onClick={() => dismissToast(toast.id)}
aria-label="Dismiss notification"
>
×
</button>
</li>
))}
</ul>
</div>
);
}