import { useState, useEffect } from 'react'
const TOAST_TTL = 7000 // ms before auto-dismiss; paused when error is expanded
export default function ToastStack({ toasts, onDismiss }) {
if (!toasts.length) return null
return (
{toasts.map(t => (
))}
)
}
function Toast({ toast, onDismiss }) {
const [expanded, setExpanded] = useState(false)
// Auto-dismiss after TTL; paused while error detail is expanded
useEffect(() => {
if (expanded) return
const timer = setTimeout(() => onDismiss(toast.id), TOAST_TTL)
return () => clearTimeout(timer)
}, [expanded, toast.id, onDismiss])
const short = toast.locator
? (toast.locator.length > 48 ? toast.locator.slice(0, 45) + '\u2026' : toast.locator)
: null
return (
✕
Capture failed
{short && {short} }
{toast.errorText && (
setExpanded(v => !v)}
>
{expanded ? 'Hide' : 'View error'}
)}
onDismiss(toast.id)}
aria-label="Dismiss"
>
×
{expanded && toast.errorText && (
{toast.errorText}
)}
)
}