{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "announcement-banner",
  "type": "registry:ui",
  "title": "Announcement Banner",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Slim, animated top banner that announces product releases, features, or offers with Snappy spring physics, smooth rotation, and collapse animations.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/announcement-banner.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useEffect, useRef } from \"react\";\nimport Link from \"next/link\";\nimport { motion, AnimatePresence, useReducedMotion } from \"framer-motion\";\nimport { ArrowRight, X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface AnnouncementMessage {\n  /** Unique identifier for the message */\n  id: string;\n  /** Main announcement copy */\n  text: string;\n  /** Optional chip label (e.g. \"New\", \"Update\", \"Sponsor\") */\n  badge?: string;\n  /** Destination URL */\n  href?: string;\n  /** Call to action link text. Defaults to \"Learn more\" */\n  linkLabel?: string;\n}\n\nexport type AnnouncementBannerVariant =\n  | \"default\"\n  | \"accent\"\n  | \"inverted\"\n  | \"glass\"\n  | \"fade\"\n  | \"outline\"\n  | \"highlight\";\n\nexport interface AnnouncementBannerProps {\n  /**\n   * One or more announcement messages.\n   * A single message renders a static banner. Multiple messages rotate automatically.\n   */\n  messages: AnnouncementMessage[];\n  /**\n   * Visual style variant.\n   * - \"default\": Subtle neutral tone matching light/dark site styling.\n   * - \"accent\": Teal accent tone.\n   * - \"inverted\": High-contrast monochrome (dark in light mode, light in dark mode).\n   * - \"glass\": Frosted translucent backdrop with subtle border.\n   * - \"fade\": Gradient horizontal fade.\n   * - \"outline\": Minimalist transparent background with crisp border.\n   * - \"highlight\": High-visibility warning/alert yellow.\n   * @default \"default\"\n   */\n  variant?: AnnouncementBannerVariant;\n  /**\n   * Whether the user can dismiss and close the banner.\n   * @default true\n   */\n  dismissible?: boolean;\n  /**\n   * localStorage key namespace for persisting dismissal.\n   * If the first message id changes, the banner reappears automatically.\n   * @default \"boseui-announcement\"\n   */\n  storageKey?: string;\n  /**\n   * Rotation interval in milliseconds when multiple messages are supplied.\n   * Pauses on pointer hover, keyboard focus, and when the browser tab is hidden.\n   * @default 5000\n   */\n  rotateInterval?: number;\n  /**\n   * If true, fixes to the top of the viewport when scrolling.\n   * Otherwise, scrolls with the page flow.\n   * @default false\n   */\n  sticky?: boolean;\n  /**\n   * Hooke's Law spring stiffness coefficient for enter, exit, and slide animations.\n   * Matches the Snappy preset.\n   * @default 380\n   */\n  stiffness?: number;\n  /**\n   * Spring damping coefficient controlling oscillation decay.\n   * Matches the Snappy preset.\n   * @default 24\n   */\n  damping?: number;\n  /**\n   * Callback fired when the banner is dismissed.\n   */\n  onDismiss?: () => void;\n  /**\n   * Optional custom background component (e.g. FlickeringGrid or subtle canvas).\n   */\n  background?: React.ReactNode;\n  /**\n   * Additional classes for the outer wrapper element.\n   */\n  className?: string;\n}\n\nexport function AnnouncementBanner({\n  messages,\n  variant = \"default\",\n  dismissible = true,\n  storageKey = \"boseui-announcement\",\n  rotateInterval = 5000,\n  sticky = false,\n  stiffness = 380,\n  damping = 24,\n  onDismiss,\n  background,\n  className,\n}: AnnouncementBannerProps) {\n  // SSR-safe state: null during hydration to prevent flash of already-dismissed banner\n  const [isDismissed, setIsDismissed] = useState<boolean | null>(null);\n  const [currentIndex, setCurrentIndex] = useState(0);\n  const [isHovered, setIsHovered] = useState(false);\n  const [isFocused, setIsFocused] = useState(false);\n\n  const bannerRef = useRef<HTMLDivElement | null>(null);\n  const shouldReduceMotion = useReducedMotion();\n\n  // Read dismissed state from localStorage on client mount\n  useEffect(() => {\n    if (!messages || messages.length === 0) {\n      setIsDismissed(true);\n      return;\n    }\n\n    const firstId = messages[0]?.id;\n    const key = `${storageKey}-${firstId}`;\n\n    try {\n      const stored = localStorage.getItem(key);\n      setIsDismissed(stored === \"true\");\n    } catch {\n      setIsDismissed(false);\n    }\n  }, [messages, storageKey]);\n\n  // Expose --announcement-height CSS variable on document.documentElement for sticky header offset\n  useEffect(() => {\n    if (typeof document === \"undefined\") return;\n\n    if (isDismissed === false && bannerRef.current) {\n      const updateHeight = () => {\n        if (bannerRef.current) {\n          const h = bannerRef.current.getBoundingClientRect().height;\n          document.documentElement.style.setProperty(\n            \"--announcement-height\",\n            `${h}px`\n          );\n        }\n      };\n\n      updateHeight();\n\n      const observer = new ResizeObserver(() => {\n        updateHeight();\n      });\n      observer.observe(bannerRef.current);\n\n      return () => {\n        observer.disconnect();\n        document.documentElement.style.removeProperty(\"--announcement-height\");\n      };\n    } else {\n      document.documentElement.style.removeProperty(\"--announcement-height\");\n    }\n  }, [isDismissed]);\n\n  // Auto-rotation timer: pauses on hover, focus, hidden tab, or reduced motion\n  useEffect(() => {\n    if (\n      !messages ||\n      messages.length <= 1 ||\n      shouldReduceMotion ||\n      isHovered ||\n      isFocused ||\n      isDismissed !== false\n    ) {\n      return;\n    }\n\n    const timer = setInterval(() => {\n      if (\n        typeof document !== \"undefined\" &&\n        document.visibilityState === \"hidden\"\n      ) {\n        return;\n      }\n      setCurrentIndex((prev) => (prev + 1) % messages.length);\n    }, rotateInterval);\n\n    return () => clearInterval(timer);\n  }, [\n    messages,\n    shouldReduceMotion,\n    isHovered,\n    isFocused,\n    isDismissed,\n    rotateInterval,\n  ]);\n\n  const handleDismiss = () => {\n    setIsDismissed(true);\n    onDismiss?.();\n\n    try {\n      const firstId = messages[0]?.id;\n      if (firstId) {\n        localStorage.setItem(`${storageKey}-${firstId}`, \"true\");\n      }\n    } catch {\n      // Storage unavailable or quota exceeded\n    }\n  };\n\n  // If pending hydration or no messages, render nothing to avoid flash\n  if (isDismissed === null || !messages || messages.length === 0) {\n    return null;\n  }\n\n  const currentMessage = messages[currentIndex] || messages[0];\n\n  const springConfig = {\n    type: \"spring\",\n    stiffness,\n    damping,\n  };\n\n  const variantStyles: Record<AnnouncementBannerVariant, string> = {\n    default:\n      \"bg-neutral-50/95 dark:bg-neutral-900/90 border-neutral-200/90 dark:border-neutral-800/90 text-neutral-800 dark:text-neutral-200\",\n    accent:\n      \"bg-teal-50/95 dark:bg-teal-950/40 border-teal-200/90 dark:border-teal-800/60 text-teal-950 dark:text-teal-100\",\n    inverted:\n      \"bg-neutral-950 text-neutral-100 border-neutral-800 dark:bg-white dark:text-neutral-950 dark:border-neutral-200\",\n    highlight:\n      \"bg-yellow-300 dark:bg-yellow-400 border-yellow-400 dark:border-yellow-500 text-neutral-950\",\n    glass:\n      \"bg-white/60 dark:bg-white/5 backdrop-blur-md border-white/50 dark:border-white/10 text-neutral-900 dark:text-neutral-100 shadow-sm\",\n    outline:\n      \"bg-transparent border-neutral-300 dark:border-neutral-700 text-neutral-800 dark:text-neutral-200\",\n    fade:\n      \"bg-gradient-to-r from-teal-50 via-white to-teal-50 dark:from-teal-950/50 dark:via-neutral-950 dark:to-teal-950/50 border-teal-200/90 dark:border-teal-900/60 text-neutral-900 dark:text-neutral-100\",\n  };\n\n  const badgeStyles: Record<AnnouncementBannerVariant, string> = {\n    default:\n      \"bg-neutral-200/70 dark:bg-neutral-800 border-neutral-300 dark:border-neutral-700 text-neutral-800 dark:text-neutral-200\",\n    accent:\n      \"bg-teal-100 dark:bg-teal-900/60 border-teal-300 dark:border-teal-700 text-teal-800 dark:text-teal-200\",\n    inverted:\n      \"bg-neutral-800 text-neutral-200 border-neutral-700 dark:bg-neutral-100 dark:text-neutral-800 dark:border-neutral-300\",\n    highlight:\n      \"bg-yellow-400/80 text-neutral-950 border-yellow-500 font-semibold\",\n    glass:\n      \"bg-neutral-200/50 dark:bg-white/10 border-neutral-300/60 dark:border-white/20 text-neutral-900 dark:text-white\",\n    outline:\n      \"bg-neutral-100 dark:bg-neutral-800 border-neutral-300 dark:border-neutral-700 text-neutral-800 dark:text-neutral-200\",\n    fade:\n      \"bg-teal-100/80 dark:bg-teal-900/50 border-teal-300/80 dark:border-teal-800/60 text-teal-900 dark:text-teal-200\",\n  };\n\n  const linkStyles: Record<AnnouncementBannerVariant, string> = {\n    default:\n      \"text-neutral-950 dark:text-white hover:text-neutral-900 dark:hover:text-neutral-100\",\n    accent:\n      \"text-teal-950 dark:text-teal-200 hover:text-teal-900 dark:hover:text-teal-100\",\n    inverted: \"text-white dark:text-neutral-950 font-semibold\",\n    highlight: \"text-neutral-950 font-bold hover:underline\",\n    glass:\n      \"text-neutral-950 dark:text-white font-medium hover:text-neutral-800 dark:hover:text-neutral-200\",\n    outline:\n      \"text-neutral-900 dark:text-white font-medium hover:text-neutral-700 dark:hover:text-neutral-300\",\n    fade:\n      \"text-teal-950 dark:text-teal-100 font-medium hover:text-teal-800 dark:hover:text-white\",\n  };\n\n  const closeStyles: Record<AnnouncementBannerVariant, string> = {\n    default:\n      \"text-neutral-500 hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-white hover:bg-neutral-200/50 dark:hover:bg-neutral-800/50 focus-visible:ring-neutral-400\",\n    accent:\n      \"text-teal-700 hover:text-teal-950 dark:text-teal-400 dark:hover:text-teal-100 hover:bg-teal-100 dark:hover:bg-teal-900/50 focus-visible:ring-teal-500\",\n    inverted:\n      \"text-neutral-400 hover:text-white dark:text-neutral-600 dark:hover:text-black hover:bg-neutral-800 dark:hover:bg-neutral-100 focus-visible:ring-neutral-400\",\n    highlight:\n      \"text-neutral-800 hover:text-neutral-950 hover:bg-yellow-400/60 focus-visible:ring-neutral-900\",\n    glass:\n      \"text-neutral-600 hover:text-neutral-950 dark:text-neutral-300 dark:hover:text-white hover:bg-neutral-200/40 dark:hover:bg-white/10 focus-visible:ring-neutral-400\",\n    outline:\n      \"text-neutral-500 hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 focus-visible:ring-neutral-400\",\n    fade:\n      \"text-teal-700 hover:text-teal-950 dark:text-teal-300 dark:hover:text-white hover:bg-teal-100/50 dark:hover:bg-teal-900/40 focus-visible:ring-teal-500\",\n  };\n\n  return (\n    <AnimatePresence mode=\"wait\">\n      {!isDismissed && (\n        <motion.aside\n          ref={bannerRef}\n          role=\"region\"\n          aria-label=\"Announcement\"\n          initial={\n            shouldReduceMotion ? { opacity: 0 } : { height: 0, opacity: 0 }\n          }\n          animate={\n            shouldReduceMotion\n              ? { opacity: 1 }\n              : { height: \"auto\", opacity: 1 }\n          }\n          exit={\n            shouldReduceMotion ? { opacity: 0 } : { height: 0, opacity: 0 }\n          }\n          transition={springConfig}\n          onMouseEnter={() => setIsHovered(true)}\n          onMouseLeave={() => setIsHovered(false)}\n          onFocus={() => setIsFocused(true)}\n          onBlur={() => setIsFocused(false)}\n          className={cn(\n            \"relative w-full overflow-hidden border-b backdrop-blur-sm\",\n            sticky && \"sticky top-0 z-[50]\",\n            variantStyles[variant],\n            className\n          )}\n        >\n          {/* Optional dogfooded background canvas / texture */}\n          {background && (\n            <div className=\"pointer-events-none absolute inset-0 z-0 overflow-hidden opacity-15\">\n              {background}\n            </div>\n          )}\n\n          {/* One-time soft shimmer sweep on initial load */}\n          {!shouldReduceMotion && (\n            <motion.div\n              aria-hidden=\"true\"\n              initial={{ x: \"-100%\" }}\n              animate={{ x: \"200%\" }}\n              transition={{ duration: 1.2, ease: \"easeInOut\", delay: 0.2 }}\n              className=\"pointer-events-none absolute inset-0 z-10 bg-gradient-to-r from-transparent via-white/10 dark:via-white/5 to-transparent\"\n            />\n          )}\n\n          {/* Banner content container */}\n          <motion.div\n            initial={\n              shouldReduceMotion ? { opacity: 0 } : { y: 6, opacity: 0 }\n            }\n            animate={{ y: 0, opacity: 1 }}\n            transition={springConfig}\n            className=\"relative z-10 mx-auto flex min-h-[40px] max-w-7xl items-center justify-center px-8 py-2 sm:px-12 md:py-2.5 text-xs sm:text-sm\"\n          >\n            {/* Center rotating announcement content */}\n            <div\n              className=\"flex items-center justify-center overflow-hidden py-0.5 text-center\"\n              aria-live=\"off\"\n            >\n              <AnimatePresence mode=\"wait\" initial={false}>\n                <motion.div\n                  key={currentMessage.id}\n                  initial={\n                    shouldReduceMotion\n                      ? { opacity: 0 }\n                      : { y: 8, opacity: 0 }\n                  }\n                  animate={{ y: 0, opacity: 1 }}\n                  exit={\n                    shouldReduceMotion\n                      ? { opacity: 0 }\n                      : { y: -8, opacity: 0 }\n                  }\n                  transition={springConfig}\n                  className=\"flex flex-wrap items-center justify-center gap-2\"\n                >\n                  {/* Badge pill */}\n                  {currentMessage.badge && (\n                    <span\n                      className={cn(\n                        \"inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-medium leading-none tracking-normal capitalize\",\n                        badgeStyles[variant]\n                      )}\n                    >\n                      {currentMessage.badge}\n                    </span>\n                  )}\n\n                  {/* Message body */}\n                  <span className=\"line-clamp-2 font-normal\">\n                    {currentMessage.text}\n                  </span>\n\n                  {/* Call to action link */}\n                  {currentMessage.href && (\n                    <Link\n                      href={currentMessage.href}\n                      className={cn(\n                        \"group inline-flex items-center gap-1 font-medium underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 rounded\",\n                        linkStyles[variant]\n                      )}\n                    >\n                      <span className=\"hidden min-[360px]:inline\">\n                        {currentMessage.linkLabel ?? \"Learn more\"}\n                      </span>\n                      <motion.span\n                        className=\"inline-block transition-transform duration-200 ease-out group-hover:translate-x-0.5\"\n                        aria-hidden=\"true\"\n                      >\n                        <ArrowRight className=\"h-3.5 w-3.5\" />\n                      </motion.span>\n                    </Link>\n                  )}\n                </motion.div>\n              </AnimatePresence>\n            </div>\n\n            {/* Right dismiss button */}\n            {dismissible && (\n              <div className=\"absolute right-2 top-1/2 -translate-y-1/2 sm:right-4 z-20\">\n                <motion.button\n                  type=\"button\"\n                  onClick={handleDismiss}\n                  whileHover={\n                    shouldReduceMotion ? undefined : { scale: 1.08 }\n                  }\n                  whileTap={\n                    shouldReduceMotion\n                      ? undefined\n                      : { scale: 0.92, rotate: 12 }\n                  }\n                  transition={{\n                    type: \"spring\",\n                    stiffness: 400,\n                    damping: 20,\n                  }}\n                  aria-label=\"Dismiss announcement\"\n                  className={cn(\n                    \"flex h-7 w-7 sm:h-6 sm:w-6 items-center justify-center rounded-md transition-colors\",\n                    \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1\",\n                    closeStyles[variant]\n                  )}\n                >\n                  <X className=\"h-3.5 w-3.5\" />\n                </motion.button>\n              </div>\n            )}\n          </motion.div>\n        </motion.aside>\n      )}\n    </AnimatePresence>\n  );\n}\n\nexport default AnnouncementBanner;\n",
      "type": "registry:ui",
      "target": "components/ui/announcement-banner.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"
    }
  ]
}
