Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript
1.4 KB
Raw Blame
import type { ToastStackProps } from './types'

// Each toast div sets its own role (role="status" for info/success,
// role="alert" for error). Those roles carry implicit aria-live values
// (polite for status, assertive for alert), so we do NOT set aria-live on
// the container -- duplicating it caused double-announcements on screen
// readers for error toasts.
export function ToastStack({ items, onDismiss }: ToastStackProps) {
  if (!items.length) return null

  return (
    <aside className="toast-stack">
      {items.map(item => (
        <div
          key={item.id}
          role={item.tone === 'error' ? 'alert' : 'status'}
          className={`toast tone-${item.tone}`}
        >
          <span aria-hidden className="toast-icon">
            {item.tone === 'success'
              ? '●'
              : item.tone === 'error'
                ? '!'
                : item.tone === 'warn'
                  ? '▲'
                  : 'i'}
          </span>
          <span className="toast-body">{item.text}</span>
          {item.action ? (
            <button
              type="button"
              className="toast-action"
              onClick={() => {
                item.action?.onAction()
                onDismiss?.(item.id)
              }}
            >
              {item.action.label}
            </button>
          ) : null}
        </div>
      ))}
    </aside>
  )
}

export type { ToastStackProps } from './types'