{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "announcement-bar",
  "title": "Announcement Bar",
  "description": "A campaign message with actions, dismissal, and remembered dismissal.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "https://uaiblocks.dev/r/uai-theme.json",
    "https://uaiblocks.dev/r/uai-utils.json"
  ],
  "files": [
    {
      "path": "src/registry/uai/components/announcement-bar.tsx",
      "content": "\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { ArrowRight, X } from \"lucide-react\";\nimport {\n  type ComponentProps,\n  createContext,\n  type Ref,\n  useContext,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/uai-utils\";\n\nexport const ANNOUNCEMENT_BAR_VARIANTS = [\"bar\", \"card\", \"pill\"] as const;\nexport type AnnouncementBarVariant = (typeof ANNOUNCEMENT_BAR_VARIANTS)[number];\nexport type AnnouncementBarProps = ComponentProps<\"section\"> & {\n  variant?: AnnouncementBarVariant;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Remembers dismissal in localStorage under this key. */\n  storageKey?: string;\n};\ntype AnnouncementContext = {\n  id: string;\n  variant: AnnouncementBarVariant;\n  dismiss: () => void;\n};\nconst Context = createContext<AnnouncementContext | null>(null);\nfunction useAnnouncement(part: string) {\n  const context = useContext(Context);\n  if (!context) throw new Error(`${part} must be used within AnnouncementBar`);\n  return context;\n}\nconst DISMISSED = \"dismissed\";\nfunction readDismissed(key: string) {\n  try {\n    return window.localStorage.getItem(key) === DISMISSED;\n  } catch {\n    return false;\n  }\n}\nfunction writeDismissed(key: string) {\n  try {\n    window.localStorage.setItem(key, DISMISSED);\n  } catch {\n    // Storage can be unavailable in private modes; dismissal still applies in memory.\n  }\n}\nfunction assignRef<T>(ref: Ref<T> | undefined, value: T) {\n  if (typeof ref === \"function\") ref(value);\n  else if (ref) ref.current = value;\n}\nconst announcementBarVariants = cva(\n  \"box-border flex min-w-0 animate-in items-center text-[13px]/[18px] text-foreground duration-240 ease-out-quint fade-in-0 slide-in-from-top-1 fill-mode-both data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:duration-150 data-[state=closed]:ease-out data-[state=closed]:fill-mode-forwards motion-reduce:animate-none [&_:is(a,button)]:focus-visible:outline-2 [&_:is(a,button)]:focus-visible:outline-offset-2 [&_:is(a,button)]:focus-visible:outline-ring\",\n  {\n    variants: {\n      variant: {\n        // The bar sits in flow, so it fades for as long as its row collapses.\n        bar: \"w-full flex-wrap gap-3 data-[state=closed]:duration-300 bg-[color-mix(in_oklab,var(--primary)_9%,var(--card))] py-2 pr-2.5 pl-4 shadow-[inset_0_-1px_0_color-mix(in_oklab,var(--primary)_16%,var(--border))]\",\n        card: \"w-full flex-wrap gap-3 rounded-[14px] border bg-card py-2.5 pr-2.5 pl-3.5\",\n        pill: \"mx-auto my-0 w-fit max-w-full flex-nowrap gap-2.5 rounded-full bg-card py-1 pr-1 pl-1.25 shadow-[0_0_0_1px_var(--border)]\",\n      },\n    },\n  },\n);\n\nexport function AnnouncementBar({\n  variant = \"bar\",\n  open,\n  defaultOpen = true,\n  onOpenChange,\n  storageKey,\n  children,\n  className,\n  ref,\n  ...props\n}: AnnouncementBarProps) {\n  const id = useId();\n  const [internal, setInternal] = useState(defaultOpen);\n  const current = open ?? internal;\n  // biome-ignore lint/correctness/useExhaustiveDependencies: only restore stored dismissal for a new key.\n  useEffect(() => {\n    if (!storageKey || !readDismissed(storageKey)) return;\n    if (open === undefined) setInternal(false);\n    else if (open) onOpenChange?.(false);\n  }, [storageKey]);\n  const bar = useRef<HTMLElement | null>(null);\n  const collapse = useRef<HTMLDivElement | null>(null);\n  // Stay mounted while the exit plays; reduced motion has no animation, so unmount at once.\n  const [rendered, setRendered] = useState(current);\n  if (current && !rendered) setRendered(true);\n  useEffect(() => {\n    if (current) return;\n    const node = bar.current;\n    const animation = node ? window.getComputedStyle(node).animationName : \"\";\n    if (!animation || animation === \"none\") return setRendered(false);\n    // The in-flow bar also gives its row back instead of letting content jump up.\n    collapse.current?.animate?.([{ gridTemplateRows: \"1fr\" }, { gridTemplateRows: \"0fr\" }], {\n      duration: 300,\n      easing: \"cubic-bezier(0.23, 1, 0.32, 1)\",\n      fill: \"forwards\",\n    });\n  }, [current]);\n  const dismiss = () => {\n    if (storageKey) writeDismissed(storageKey);\n    if (open === undefined) setInternal(false);\n    onOpenChange?.(false);\n  };\n  if (!current && !rendered) return null;\n  // Only a closing bar is wrapped, so an open bar stays a direct child (and can be sticky).\n  const closingBar = !current && variant === \"bar\";\n  const element = (\n    <section\n      aria-labelledby={`${id}-message`}\n      data-slot=\"announcement-bar\"\n      className={cn(announcementBarVariants({ variant }), className)}\n      {...props}\n      ref={(node) => {\n        bar.current = node;\n        assignRef(ref, node);\n      }}\n      data-variant={variant}\n      data-state={current ? \"open\" : \"closed\"}\n      inert={!current}\n      onAnimationEnd={(event) => {\n        props.onAnimationEnd?.(event);\n        if (event.target === event.currentTarget && !current) setRendered(false);\n      }}\n    >\n      {children}\n    </section>\n  );\n  return (\n    <Context.Provider value={{ id, variant, dismiss }}>\n      {closingBar ? (\n        <div ref={collapse} className=\"grid\">\n          <div className=\"min-h-0 overflow-hidden\">{element}</div>\n        </div>\n      ) : (\n        element\n      )}\n    </Context.Provider>\n  );\n}\n\nexport function AnnouncementBarLabel({ className, ...props }: ComponentProps<\"span\">) {\n  return (\n    <span\n      data-slot=\"announcement-bar-label\"\n      className={cn(\n        \"inline-flex h-5 flex-none items-center rounded-full bg-primary/16 px-2 text-[11.5px]/4 font-medium whitespace-nowrap text-primary-ink shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--primary)_28%,transparent)]\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport function AnnouncementBarMessage({ className, ref, ...props }: ComponentProps<\"p\">) {\n  const context = useAnnouncement(\"AnnouncementBarMessage\");\n  const message = useRef<HTMLParagraphElement | null>(null);\n  const truncates = context.variant === \"pill\" && props.title === undefined;\n  // The pill truncates its message, so expose the full text as a tooltip when it is cut off.\n  useEffect(() => {\n    const element = message.current;\n    if (!truncates || !element) return;\n    const update = () => {\n      if (element.scrollWidth > element.clientWidth) element.title = element.textContent ?? \"\";\n      else element.removeAttribute(\"title\");\n    };\n    update();\n    if (typeof ResizeObserver !== \"function\") return;\n    const observer = new ResizeObserver(update);\n    observer.observe(element);\n    return () => observer.disconnect();\n  }, [truncates]);\n  return (\n    <p\n      data-slot=\"announcement-bar-message\"\n      className={cn(\n        \"m-0 min-w-0 text-pretty\",\n        context.variant === \"pill\"\n          ? \"flex-[0_1_auto] truncate text-muted-foreground\"\n          : \"flex-[1_1_240px] text-foreground\",\n        className,\n      )}\n      {...props}\n      ref={(node) => {\n        message.current = node;\n        assignRef(ref, node);\n      }}\n      id={`${context.id}-message`}\n    />\n  );\n}\n\nexport function AnnouncementBarActions({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"announcement-bar-actions\"\n      className={cn(\"ml-auto flex items-center gap-1\", className)}\n      {...props}\n    />\n  );\n}\n\nconst actionVariants = cva(\n  \"inline-flex items-center gap-1 rounded-full font-medium whitespace-nowrap no-underline transition-[background-color,scale] duration-[120ms,140ms] ease-[ease-out,cubic-bezier(0.23,1,0.32,1)] focus-visible:ring-0 focus-visible:outline-solid active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100 [&_svg]:[transition:translate_140ms_cubic-bezier(0.23,1,0.32,1)] hover:[&_svg]:translate-x-0.5 motion-reduce:[&_svg]:transition-none motion-reduce:hover:[&_svg]:translate-x-0\",\n  {\n    variants: {\n      variant: {\n        bar: \"h-7 bg-primary pr-2.5 pl-3.5 text-[13px] text-primary-foreground hover:bg-primary hover:brightness-108 has-[>svg]:pr-2.5 has-[>svg]:pl-3.5\",\n        card: \"h-7 bg-secondary pr-2.5 pl-3.5 text-[13px] text-foreground hover:bg-[color-mix(in_oklab,var(--secondary)_85%,var(--foreground))] has-[>svg]:pr-2.5 has-[>svg]:pl-3.5\",\n        pill: \"h-6.5 bg-secondary pr-2.5 pl-3 text-[12.5px] text-foreground hover:bg-[color-mix(in_oklab,var(--secondary)_85%,var(--foreground))] has-[>svg]:pr-2.5 has-[>svg]:pl-3\",\n      },\n    },\n  },\n);\n\nexport function AnnouncementBarAction({ children, className, ...props }: ComponentProps<\"a\">) {\n  const context = useAnnouncement(\"AnnouncementBarAction\");\n  return (\n    <Button\n      asChild\n      variant={context.variant === \"bar\" ? \"default\" : \"secondary\"}\n      size=\"sm\"\n      className={cn(actionVariants({ variant: context.variant }), className)}\n    >\n      <a data-slot=\"announcement-bar-action\" {...props}>\n        {children}\n        <ArrowRight size={14} strokeWidth={1.75} aria-hidden=\"true\" className=\"size-3.5\" />\n      </a>\n    </Button>\n  );\n}\n\nexport function AnnouncementBarDismiss({\n  children = <X size={14} strokeWidth={1.75} aria-hidden=\"true\" className=\"size-3.5\" />,\n  onClick,\n  className,\n  ...props\n}: ComponentProps<\"button\">) {\n  const context = useAnnouncement(\"AnnouncementBarDismiss\");\n  const pill = context.variant === \"pill\";\n  return (\n    <Button\n      aria-label=\"Dismiss announcement\"\n      data-slot=\"announcement-bar-dismiss\"\n      variant=\"ghost\"\n      size=\"icon-sm\"\n      className={cn(\n        \"grid cursor-pointer place-items-center border-0 bg-transparent p-0 text-muted-foreground transition-[background-color,color,scale] duration-[120ms,120ms,140ms] ease-[ease-out,ease-out,cubic-bezier(0.23,1,0.32,1)] hover:text-foreground focus-visible:ring-0 focus-visible:outline-solid active:scale-[0.94] motion-reduce:transition-none motion-reduce:active:scale-100\",\n        pill ? \"size-6.5 rounded-full\" : \"size-7 rounded-lg\",\n        context.variant === \"bar\"\n          ? \"hover:bg-foreground/8 dark:hover:bg-foreground/8\"\n          : \"hover:bg-accent dark:hover:bg-accent\",\n        className,\n      )}\n      {...props}\n      type=\"button\"\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) context.dismiss();\n      }}\n    >\n      {children}\n    </Button>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/uai/announcement-bar.tsx"
    }
  ],
  "categories": [
    "marketing",
    "banner"
  ],
  "type": "registry:ui"
}