{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast-stack",
  "type": "registry:ui",
  "title": "Toast Stack",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Stacked viewport notification toasts supporting 6 viewport positions (top/bottom + left/center/right), hover fan-out, and auto-dismiss.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/toast-stack.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useCallback, useEffect } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\nimport {\n  AlertTriangle,\n  Bell,\n  CheckCircle2,\n  Info,\n  Trash2,\n  X,\n  XCircle,\n} from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ToastVariant = \"default\" | \"success\" | \"error\" | \"warning\";\n\nexport type ToastPosition =\n  | \"top-left\"\n  | \"top-center\"\n  | \"top-right\"\n  | \"bottom-left\"\n  | \"bottom-center\"\n  | \"bottom-right\";\n\nexport interface ToastItem {\n  id: string;\n  title: string;\n  description?: string;\n  variant?: ToastVariant;\n  actionLabel?: string;\n  onAction?: () => void;\n}\n\nexport interface ToastStackProps {\n  /** Viewport position of the toast stack */\n  position?: ToastPosition;\n  /** Initial toast items displayed in the stack */\n  initialToasts?: ToastItem[];\n  /** Maximum visible toasts in the stack */\n  maxVisible?: number;\n  /** Automatically dismiss toasts after duration (paused on hover) */\n  autoDismiss?: boolean;\n  /** Auto-dismiss duration in milliseconds. Default: 4500 */\n  duration?: number;\n  /** Render toasts fixed to the viewport via portal (default: true) */\n  viewportPortal?: boolean;\n  /** Additional container class names */\n  className?: string;\n}\n\nconst ALL_POSITIONS: ToastPosition[] = [\n  \"top-left\",\n  \"top-center\",\n  \"top-right\",\n  \"bottom-left\",\n  \"bottom-center\",\n  \"bottom-right\",\n];\n\nconst POSITION_CLASSES: Record<ToastPosition, string> = {\n  \"top-left\": \"top-5 left-5 items-start\",\n  \"top-center\": \"top-5 left-1/2 -translate-x-1/2 items-center\",\n  \"top-right\": \"top-5 right-5 items-end\",\n  \"bottom-left\": \"bottom-5 left-5 items-start\",\n  \"bottom-center\": \"bottom-5 left-1/2 -translate-x-1/2 items-center\",\n  \"bottom-right\": \"bottom-5 right-5 items-end\",\n};\n\nfunction getVariantIcon(variant: ToastVariant = \"default\") {\n  switch (variant) {\n    case \"success\":\n      return (\n        <CheckCircle2 className=\"h-4 w-4 shrink-0 text-black dark:text-white\" />\n      );\n    case \"error\":\n      return <XCircle className=\"h-4 w-4 shrink-0 text-black dark:text-white\" />;\n    case \"warning\":\n      return (\n        <AlertTriangle className=\"h-4 w-4 shrink-0 text-black dark:text-white\" />\n      );\n    default:\n      return <Info className=\"h-4 w-4 shrink-0 text-neutral-500\" />;\n  }\n}\n\nexport function ToastStack({\n  position = \"bottom-right\",\n  initialToasts = [],\n  maxVisible = 4,\n  autoDismiss = true,\n  duration = 4500,\n  viewportPortal = true,\n  className,\n}: ToastStackProps) {\n  const shouldReduceMotion = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  const [activePosition, setActivePosition] = useState<ToastPosition>(position);\n  const [toasts, setToasts] = useState<ToastItem[]>(initialToasts);\n  const [expanded, setExpanded] = useState(false);\n\n  useEffect(() => {\n    setMounted(true);\n  }, []);\n\n  useEffect(() => {\n    setActivePosition(position);\n  }, [position]);\n\n  // Auto-dismiss timer (pauses while user hovers the stack)\n  useEffect(() => {\n    if (!autoDismiss || expanded || toasts.length === 0) return;\n    const timer = setTimeout(() => {\n      setToasts((prev) => prev.slice(0, -1));\n    }, duration);\n    return () => clearTimeout(timer);\n  }, [autoDismiss, duration, expanded, toasts]);\n\n  const pushToast = useCallback(\n    (variant: ToastVariant, posOverride?: ToastPosition) => {\n      const targetPos = posOverride || activePosition;\n      if (posOverride) setActivePosition(posOverride);\n\n      const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;\n      const presets: Record<ToastVariant, { title: string; description: string }> = {\n        default: {\n          title: `Notification (${targetPos})`,\n          description: \"Hover the stack to pause auto-dismiss and expand.\",\n        },\n        success: {\n          title: \"Deployment Succeeded\",\n          description: `Anchored at ${targetPos} of your viewport.`,\n        },\n        warning: {\n          title: \"Rate Limit Approaching\",\n          description: \"85% of your hourly API quota has been used.\",\n        },\n        error: {\n          title: \"Build Failed\",\n          description: \"Check the terminal logs for details.\",\n        },\n      };\n\n      setToasts((prev) => [\n        { id, variant, ...presets[variant] },\n        ...prev.slice(0, 7),\n      ]);\n    },\n    [activePosition]\n  );\n\n  const dismissToast = useCallback((id: string) => {\n    setToasts((prev) => prev.filter((t) => t.id !== id));\n  }, []);\n\n  const visibleToasts = toasts.slice(0, maxVisible);\n  const isTop = activePosition.startsWith(\"top\");\n  const directionMultiplier = isTop ? 1 : -1;\n\n  const viewportOverlay = (\n    <div\n      role=\"region\"\n      aria-live=\"polite\"\n      aria-label=\"Viewport notifications\"\n      onMouseEnter={() => setExpanded(true)}\n      onMouseLeave={() => setExpanded(false)}\n      className={cn(\n        \"pointer-events-none fixed z-[9999] flex w-full max-w-sm flex-col px-4 sm:px-0\",\n        POSITION_CLASSES[activePosition]\n      )}\n    >\n      <div className=\"relative w-full\">\n        <AnimatePresence initial={false}>\n          {visibleToasts.map((toast, index) => {\n            const yOffset =\n              directionMultiplier * (expanded ? index * 74 : index * 12);\n            const scale = expanded ? 1 : 1 - index * 0.04;\n            const opacity = index >= maxVisible ? 0 : 1 - index * 0.15;\n\n            return (\n              <motion.div\n                key={toast.id}\n                layout\n                initial={\n                  shouldReduceMotion\n                    ? { opacity: 0 }\n                    : {\n                        opacity: 0,\n                        y: isTop ? -24 : 24,\n                        scale: 0.94,\n                      }\n                }\n                animate={{\n                  opacity,\n                  y: yOffset,\n                  scale,\n                  zIndex: maxVisible - index,\n                }}\n                exit={\n                  shouldReduceMotion\n                    ? { opacity: 0 }\n                    : {\n                        opacity: 0,\n                        scale: 0.92,\n                        transition: { duration: 0.15 },\n                      }\n                }\n                transition={{\n                  type: \"spring\",\n                  stiffness: 400,\n                  damping: 30,\n                }}\n                style={{\n                  [isTop ? \"top\" : \"bottom\"]: 0,\n                }}\n                className=\"pointer-events-auto absolute left-0 right-0 flex items-start justify-between gap-3 rounded-xl border border-neutral-200 bg-white p-3.5 text-black shadow-2xl dark:border-[#262626] dark:bg-[#0C0C0C] dark:text-white\"\n              >\n                <div className=\"flex min-w-0 items-start gap-2.5\">\n                  <div className=\"mt-0.5\">{getVariantIcon(toast.variant)}</div>\n                  <div className=\"min-w-0\">\n                    <div className=\"truncate text-xs font-semibold text-black dark:text-white\">\n                      {toast.title}\n                    </div>\n                    {toast.description && (\n                      <p className=\"mt-0.5 truncate text-[11px] text-neutral-500 dark:text-neutral-400\">\n                        {toast.description}\n                      </p>\n                    )}\n                  </div>\n                </div>\n\n                <button\n                  type=\"button\"\n                  onClick={() => dismissToast(toast.id)}\n                  aria-label=\"Dismiss notification\"\n                  className=\"shrink-0 cursor-pointer rounded-md p-1 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-black dark:hover:bg-[#1A1A1A] dark:hover:text-white\"\n                >\n                  <X className=\"h-3.5 w-3.5\" />\n                </button>\n              </motion.div>\n            );\n          })}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n\n  return (\n    <div\n      className={cn(\n        \"flex w-full max-w-md flex-col items-center gap-4\",\n        className\n      )}\n    >\n      {/* Position Selector Grid */}\n      <div className=\"w-full rounded-2xl border border-neutral-200 bg-white p-4 dark:border-[#222222] dark:bg-[#0A0A0A]\">\n        <div className=\"mb-2.5 flex items-center justify-between font-mono text-[10px] uppercase tracking-wider text-neutral-400\">\n          <span>Viewport Position ({toasts.length} active)</span>\n          <div className=\"flex items-center gap-2\">\n            {toasts.length > 0 && (\n              <button\n                type=\"button\"\n                onClick={() => setToasts([])}\n                className=\"inline-flex cursor-pointer items-center gap-1 text-neutral-400 hover:text-black dark:hover:text-white\"\n              >\n                <Trash2 className=\"h-3 w-3\" />\n                <span>Clear</span>\n              </button>\n            )}\n            <span className=\"text-black dark:text-white\">{activePosition}</span>\n          </div>\n        </div>\n\n        <div className=\"grid grid-cols-3 gap-1.5\">\n          {ALL_POSITIONS.map((pos) => {\n            const isSelected = activePosition === pos;\n            return (\n              <button\n                key={pos}\n                type=\"button\"\n                onClick={() => {\n                  setActivePosition(pos);\n                  pushToast(\"default\", pos);\n                }}\n                className={cn(\n                  \"cursor-pointer rounded-lg border px-2.5 py-2 font-mono text-[10px] transition-colors\",\n                  isSelected\n                    ? \"border-black bg-black text-white dark:border-white dark:bg-white dark:text-black\"\n                    : \"border-neutral-200 bg-neutral-50 text-neutral-600 hover:border-black hover:text-black dark:border-[#222222] dark:bg-[#111111] dark:text-neutral-400 dark:hover:border-white dark:hover:text-white\"\n                )}\n              >\n                {pos}\n              </button>\n            );\n          })}\n        </div>\n\n        {/* Variant Triggers */}\n        <div className=\"mt-3 flex flex-wrap items-center justify-between gap-1.5 border-t border-neutral-200 pt-3 dark:border-[#1F1F1F]\">\n          {([\"success\", \"default\", \"warning\", \"error\"] as ToastVariant[]).map(\n            (variant) => (\n              <button\n                key={variant}\n                type=\"button\"\n                onClick={() => pushToast(variant)}\n                className=\"inline-flex flex-1 cursor-pointer items-center justify-center gap-1 rounded-lg border border-neutral-200 bg-white px-2.5 py-1.5 font-mono text-[10px] capitalize text-black transition-colors hover:border-black dark:border-[#262626] dark:bg-[#121212] dark:text-white dark:hover:border-white\"\n              >\n                <Bell className=\"h-3 w-3 text-neutral-400\" />\n                <span>{variant}</span>\n              </button>\n            )\n          )}\n        </div>\n      </div>\n\n      {viewportPortal && mounted && createPortal(viewportOverlay, document.body)}\n    </div>\n  );\n}\n\nexport default ToastStack;\n",
      "type": "registry:ui",
      "target": "components/ui/toast-stack.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
