|Design System

Core Component

Toast

Ephemeral notification for success confirmations, warnings, and errors. Appears briefly, then dismisses.

Preview

Conversation saved

Context window 90% full

Model updated to Claude 3.5

Source

Full component implementation using the design system tokens.

tsx
"use client";

import { X, CheckCircle2, AlertTriangle, AlertCircle, Info } from "lucide-react";

const variantStyles = {
  success: { bg: "bg-green-500/10 border-green-500/20", icon: CheckCircle2, iconColor: "text-green-500" },
  warning: { bg: "bg-amber-500/10 border-amber-500/20", icon: AlertTriangle, iconColor: "text-amber-500" },
  error: { bg: "bg-red-500/10 border-red-500/20", icon: AlertCircle, iconColor: "text-red-500" },
  info: { bg: "bg-blue-500/10 border-blue-500/20", icon: Info, iconColor: "text-blue-500" },
};

export function DSToast({
  variant = "info",
  title,
  description,
  onDismiss,
}: {
  variant?: "success" | "warning" | "error" | "info";
  title: string;
  description?: string;
  onDismiss?: () => void;
}) {
  const style = variantStyles[variant];
  const Icon = style.icon;

  return (
    <div
      className={`flex items-start gap-3 px-4 py-3 rounded-xl border ${style.bg} max-w-sm w-full`}
      role={variant === "error" ? "alert" : "status"}
    >
      <Icon className={`w-5 h-5 shrink-0 mt-0.5 ${style.iconColor}`} />
      <div className="flex-1 min-w-0">
        <p className="text-sm font-medium text-foreground">{title}</p>
        {description && (
          <p className="text-xs text-secondary mt-0.5">{description}</p>
        )}
      </div>
      {onDismiss && (
        <button
          onClick={onDismiss}
          className="shrink-0 p-0.5 text-tertiary hover:text-foreground transition-colors"
          aria-label="Dismiss"
        >
          <X className="w-4 h-4" />
        </button>
      )}
    </div>
  );
}

Props

All available props with types and defaults.

PropTypeDescription
title*stringToast heading
variant'success' | 'warning' | 'error' | 'info'Semantic color variant
descriptionstringOptional secondary text
onDismiss() => voidDismiss callback — shows close button when provided

Variants

Success

Positive confirmation — action completed.

Conversation saved

tsx
<DSToast variant="success" title="Conversation saved" />

Error

Something failed — needs attention.

tsx
<DSToast
  variant="error"
  title="Generation failed"
  description="Rate limit exceeded. Try again in 30s."
/>

Warning

Caution — approaching limits or degraded state.

Context window 90% full

tsx
<DSToast variant="warning" title="Context window 90% full" />

Info

Neutral information — updates, tips.

Model updated to Claude 3.5

tsx
<DSToast variant="info" title="Model updated to Claude 3.5" />

Prompt Guide

Prompt Guide — Toast

Use for

  • Success confirmations (saved, copied, sent)
  • Error notifications (generation failed, rate limited)
  • Warning alerts (context window limits, quota approaching)
  • Info updates (model changed, feature enabled)

Don't use for

  • Persistent status — use Badge instead
  • Complex interactions requiring user input — use Modal
  • Inline validation — use Input error state

AI Context

Toasts in AI interfaces confirm fleeting events: 'Response copied', 'Conversation saved', 'Model switched'. Error toasts are critical for API failures — 'Rate limit exceeded. Try again in 30s.' gives the user actionable info. Auto-dismiss success/info after 3s, but keep error/warning visible until dismissed.