{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"announcement-bar","type":"registry:ui","title":"Announcement bar","description":"Slim top bar that rotates promo messages with a link and collapses smoothly when dismissed.","dependencies":["lucide-react","motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/announcement-bar/announcement-bar.tsx","type":"registry:ui","target":"components/facade/announcement-bar.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { ArrowRight, X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface Announcement {\n  text: string;\n  /** Optional short lead, rendered bold, e.g. \"New\". */\n  badge?: string;\n  href?: string;\n  linkLabel?: string;\n}\n\nexport interface AnnouncementBarProps {\n  /** Messages to rotate through. Defaults to a small local-business example set. */\n  messages?: Announcement[];\n  /** Milliseconds per message. */\n  interval?: number;\n  dismissible?: boolean;\n  /** Called after the bar has collapsed. */\n  onDismiss?: () => void;\n  /** Visual style. */\n  tone?: \"brand\" | \"dark\" | \"subtle\";\n  className?: string;\n}\n\nconst TONES = {\n  brand: \"bg-brand text-brand-foreground\",\n  dark: \"bg-primary text-primary-foreground\",\n  subtle: \"bg-muted text-foreground\",\n} as const;\n\nconst DEFAULT_MESSAGES: Announcement[] = [\n  { badge: \"New\", text: \"Now booking spring appointments across Austin.\", href: \"#book\", linkLabel: \"Book now\" },\n  { badge: \"Offer\", text: \"Free estimates on every project through March 31.\", href: \"#quote\", linkLabel: \"Get a quote\" },\n];\n\nconst EASE = [0.16, 1, 0.3, 1] as const;\n\nexport function AnnouncementBar({\n  messages = DEFAULT_MESSAGES,\n  interval = 4500,\n  dismissible = true,\n  onDismiss,\n  tone = \"dark\",\n  className,\n}: AnnouncementBarProps) {\n  const reduce = useReducedMotion();\n  const [index, setIndex] = React.useState(0);\n  const [open, setOpen] = React.useState(true);\n  const [paused, setPaused] = React.useState(false);\n\n  React.useEffect(() => {\n    if (messages.length < 2 || paused || !open) return;\n    const id = window.setInterval(() => setIndex((i) => (i + 1) % messages.length), interval);\n    return () => window.clearInterval(id);\n  }, [messages.length, interval, paused, open]);\n\n  const msg = messages[index % Math.max(1, messages.length)];\n  if (!msg) return null;\n\n  return (\n    <AnimatePresence initial={false} onExitComplete={onDismiss}>\n      {open && (\n        <motion.div\n          key=\"bar\"\n          role=\"region\"\n          aria-label=\"Announcements\"\n          initial={{ height: 0 }}\n          animate={{ height: \"auto\" }}\n          exit={{ height: 0, transition: { duration: reduce ? 0 : 0.4, ease: EASE } }}\n          className={cn(\"relative w-full overflow-hidden\", TONES[tone], className)}\n          onMouseEnter={() => setPaused(true)}\n          onMouseLeave={() => setPaused(false)}\n          onFocus={() => setPaused(true)}\n          onBlur={() => setPaused(false)}\n        >\n          <motion.div\n            exit={{ opacity: 0 }}\n            transition={{ duration: 0.15 }}\n            className=\"mx-auto flex min-h-11 max-w-[1120px] items-center gap-3 px-4 py-2 sm:px-6\"\n          >\n            {/* Spacer keeps the text centered against the dismiss button */}\n            {dismissible && <span className=\"w-7 shrink-0\" aria-hidden />}\n\n            <div className=\"relative flex min-w-0 flex-1 items-center justify-center\" aria-live=\"polite\">\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                <motion.p\n                  key={index}\n                  initial={reduce ? { opacity: 0 } : { opacity: 0, y: 6 }}\n                  animate={{ opacity: 1, y: 0 }}\n                  exit={reduce ? { opacity: 0 } : { opacity: 0, y: -6 }}\n                  transition={{ duration: 0.5, ease: EASE }}\n                  className=\"flex min-w-0 flex-wrap items-center justify-center gap-x-2.5 gap-y-0.5 text-[13px] leading-snug sm:flex-nowrap\"\n                >\n                  {msg.badge && (\n                    <span className=\"hidden shrink-0 font-semibold sm:inline\">{msg.badge}</span>\n                  )}\n                  <span className=\"min-w-0 text-center opacity-90 sm:truncate\">{msg.text}</span>\n                  {msg.href && (\n                    <a\n                      href={msg.href}\n                      className=\"group inline-flex shrink-0 items-center gap-1 rounded font-medium underline decoration-current/40 underline-offset-4 transition-colors hover:decoration-current focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current/60\"\n                    >\n                      {msg.linkLabel ?? \"Learn more\"}\n                      <ArrowRight\n                        className=\"size-3.5 transition-transform duration-300 group-hover:translate-x-0.5\"\n                        aria-hidden\n                      />\n                    </a>\n                  )}\n                </motion.p>\n              </AnimatePresence>\n            </div>\n\n            {dismissible && (\n              <button\n                type=\"button\"\n                onClick={() => setOpen(false)}\n                aria-label=\"Dismiss announcement\"\n                className=\"grid size-7 shrink-0 place-items-center rounded-full opacity-60 transition hover:bg-current/10 hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current/60\"\n              >\n                <X className=\"size-4\" aria-hidden />\n              </button>\n            )}\n          </motion.div>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n\nexport default AnnouncementBar;\n"}],"categories":["feedback"],"meta":{"tier":"free","demo":"\"use client\";\n\nimport * as React from \"react\";\nimport { Menu, Wrench } from \"lucide-react\";\nimport { AnnouncementBar, type Announcement } from \"./announcement-bar\";\n\nconst messages: Announcement[] = [\n  {\n    badge: \"Fall special\",\n    text: \"$79 furnace tune-up through November 30.\",\n    href: \"#book\",\n    linkLabel: \"Book now\",\n  },\n  {\n    badge: \"24/7\",\n    text: \"No heat? Emergency service across Denver metro, no overtime fees.\",\n    href: \"tel:+13035550133\",\n    linkLabel: \"Call (303) 555-0133\",\n  },\n  {\n    badge: \"Financing\",\n    text: \"0% APR for 18 months on new systems, approval in minutes.\",\n    href: \"#financing\",\n    linkLabel: \"Check rates\",\n  },\n];\n\nexport default function Demo() {\n  const [key, setKey] = React.useState(0);\n  const [dismissed, setDismissed] = React.useState(false);\n\n  return (\n    <div className=\"mx-auto w-full max-w-4xl p-4\">\n      <div className=\"overflow-hidden rounded-[22px] bg-background shadow-float\">\n        <AnnouncementBar key={key} messages={messages} onDismiss={() => setDismissed(true)} />\n        <header className=\"flex h-14 items-center justify-between border-b border-border px-5\">\n          <div className=\"flex items-center gap-2.5 text-[15px] font-semibold tracking-[-0.01em]\">\n            <span className=\"grid size-7 place-items-center rounded-lg bg-foreground text-background\">\n              <Wrench className=\"size-3.5\" aria-hidden />\n            </span>\n            Front Range Heating & Air\n          </div>\n          <nav className=\"hidden items-center gap-7 text-[14px] text-muted-foreground sm:flex\">\n            <span>Services</span>\n            <span>Maintenance plans</span>\n            <span>Reviews</span>\n            <span className=\"rounded-full bg-foreground px-4 py-1.5 text-[13px] font-medium text-background\">Get a quote</span>\n          </nav>\n          <Menu className=\"size-5 text-muted-foreground sm:hidden\" aria-hidden />\n        </header>\n        <div className=\"px-5 py-10\">\n          <div className=\"h-3 w-24 rounded-full bg-muted\" />\n          <div className=\"mt-4 h-7 w-3/4 max-w-md rounded-lg bg-muted\" />\n          <div className=\"mt-2 h-7 w-1/2 max-w-xs rounded-lg bg-muted\" />\n          {dismissed && (\n            <button\n              type=\"button\"\n              onClick={() => {\n                setDismissed(false);\n                setKey((k) => k + 1);\n              }}\n              className=\"mt-6 rounded-full bg-muted px-3.5 py-1.5 text-[13px] font-medium text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n            >\n              Show announcement again\n            </button>\n          )}\n        </div>\n      </div>\n    </div>\n  );\n}\n"}}