src/lib/ui/toast.ts

Total Symbols
2
Lines of Code
22
Avg Complexity
1.5
Symbol Types
2

Symbols by Kind

type 1
function 1

All Symbols

Name Kind Visibility Status Lines Signature
ToastType type exported- 6-6 type ToastType
showToast function exported- 8-21 showToast(message: string, type: ToastType = "success"): : void

Full Source

/**
 * Toast notification utility — shows a temporary message in the UI.
 * Framework-agnostic, works in popup, options and devtools panel.
 */

export type ToastType = "success" | "error" | "info" | "warning";

export function showToast(message: string, type: ToastType = "success"): void {
  const existing = document.querySelector(".toast");
  if (existing) existing.remove();

  const toast = document.createElement("div");
  toast.className = `toast toast-${type}`;
  toast.textContent = message;
  document.body.appendChild(toast);

  setTimeout(() => {
    toast.style.opacity = "0";
    setTimeout(() => toast.remove(), 300);
  }, 2500);
}