{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "banner",
  "type": "registry:ui",
  "title": "Banner",
  "description": "A thin, full-width bar above the site header for a message that applies to the whole site: \"This site is still being written\", a scheduled outage, a new release. One line of text, an optional link, and an optional close button.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "feedback",
    "pattern"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/banner.tsx",
      "target": "components/ui/patterns/banner.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport { XIcon } from 'lucide-react';\n\n// @interlace/banner v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/banner\n// What changed since: https://ds.interlace.tools/c/banner#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — Banner\n *\n * A thin, full-width bar above the site header for a message that applies to\n * the whole site: \"This site is still being written\", a scheduled outage, a\n * new release. One line of text, an optional link, and an optional close\n * button.\n *\n * ## Anatomy\n *\n *   Banner                            (div role=region — data-tone, data-min-viewport=320)\n *     ├─ icon?                        (decorative, aria-hidden)\n *     ├─ children                     (the message; links inside are fine)\n *     ├─ action?                      (a link or button after the message)\n *     └─ dismiss button?              (when `dismissible`)\n *\n * ## Tones\n *\n * `muted` for neutral notices, `info`, `success`, `warning` and `highlight`.\n * The tone colours the bar; the words carry the meaning, so nothing depends\n * on colour alone. Every tone pairs a surface token with its `-foreground`.\n *\n * ## Dismissing\n *\n * `dismissible` adds a close button with an accessible name. The banner\n * manages its own visibility, or a caller controls it with `open` and\n * `onOpenChange` (for example to remember the choice in storage).\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `div` props                                          |\n * | R6   | data-slot per part      | banner / -message / -action / -dismiss                |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                     |\n * | R8   | Enums, not booleans     | `tone`                                               |\n * | R14  | Declares min viewport   | `data-min-viewport` + exported const                  |\n * | R19  | Tokens only             | tone surface + foreground pairs                       |\n * | R25  | Client component        | dismiss state                                        |\n * | R26  | A11y from native el     | labelled region, `<button>` with a name               |\n */\n\nimport * as React from 'react';\n\nimport { cn } from '@/lib/utils';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nexport type BannerTone = 'muted' | 'info' | 'success' | 'warning' | 'highlight';\n\nconst TONE: Record<BannerTone, string> = {\n  muted: 'bg-muted text-foreground border-border',\n  info: 'bg-info text-info-foreground border-transparent',\n  success: 'bg-success text-success-foreground border-transparent',\n  warning: 'bg-warning text-warning-foreground border-transparent',\n  highlight: 'bg-highlight text-highlight-foreground border-transparent',\n};\n\nexport interface BannerProps extends Omit<React.ComponentProps<'div'>, 'role'> {\n  /** Colour of the bar. The text carries the meaning. @default 'muted' */\n  tone?: BannerTone;\n  /** A decorative icon before the message. */\n  icon?: React.ReactNode;\n  /** A link or button after the message. */\n  action?: React.ReactNode;\n  /** Show a close button. @default false */\n  dismissible?: boolean;\n  /** Accessible name of the close button. @default 'Dismiss' */\n  dismissLabel?: string;\n  /** Accessible name of the banner region. @default 'Announcement' */\n  label?: string;\n  /** Controlled visibility. */\n  open?: boolean;\n  /** Called when the close button is pressed. */\n  onOpenChange?: (open: boolean) => void;\n}\n\nexport function Banner({\n  tone = 'muted',\n  icon,\n  action,\n  dismissible = false,\n  dismissLabel = 'Dismiss',\n  label = 'Announcement',\n  open: openProp,\n  onOpenChange,\n  className,\n  children,\n  ...props\n}: BannerProps) {\n  const [openState, setOpenState] = React.useState(true);\n  const open = openProp ?? openState;\n  if (!open) return null;\n\n  return (\n    <div\n      role=\"region\"\n      aria-label={label}\n      data-slot=\"banner\"\n      data-tone={tone}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('border-b px-4 py-2 text-sm', TONE[tone], className)}\n      {...props}\n    >\n      <div className=\"mx-auto flex max-w-(--container-wide) items-center justify-center gap-x-3 gap-y-1\">\n        {icon ? (\n          <span aria-hidden className=\"shrink-0 [&_svg]:size-4\">\n            {icon}\n          </span>\n        ) : null}\n        <p data-slot=\"banner-message\" className=\"text-center text-pretty [&_a]:font-medium [&_a]:underline [&_a]:underline-offset-2\">\n          {children}\n        </p>\n        {action ? (\n          <span data-slot=\"banner-action\" className=\"shrink-0 font-medium [&_a]:underline [&_a]:underline-offset-2\">\n            {action}\n          </span>\n        ) : null}\n        {dismissible ? (\n          <button\n            type=\"button\"\n            data-slot=\"banner-dismiss\"\n            aria-label={dismissLabel}\n            onClick={() => {\n              if (openProp === undefined) setOpenState(false);\n              onOpenChange?.(false);\n            }}\n            className=\"focus-visible:ring-ring -my-1 ml-auto inline-flex size-8 shrink-0 items-center justify-center rounded-md opacity-80 hover:opacity-100 focus-visible:ring-[3px] focus-visible:outline-hidden\"\n          >\n            <XIcon aria-hidden className=\"size-4\" />\n          </button>\n        ) : null}\n      </div>\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.0",
    "since": null
  },
  "docs": "## @interlace/banner\n\nInstalled to `components/ui/patterns/banner.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/banner';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/banner\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
