{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cookie-banner",
  "type": "registry:component",
  "title": "Cookie Banner",
  "description": "A consent card with Accept all, Reject non-essential and a Customize panel of category switches. It slides up on mount.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "site",
    "cookie",
    "consent",
    "privacy",
    "gdpr",
    "banner",
    "preferences"
  ],
  "docs": "https://hyperblur.dev/effects/cookie-banner",
  "files": [
    {
      "path": "registry/hyperblur/cookie-banner.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cookie-banner.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type CookiePlacement = \"bottom-left\" | \"bottom-center\" | \"inline\";\n\nexport interface CookiePreferences {\n  necessary: true;\n  analytics: boolean;\n  marketing: boolean;\n}\n\nexport interface CookieBannerProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\" | \"onChange\" | \"title\"> {\n  title?: string;\n  description?: string;\n  placement?: CookiePlacement;\n  defaultPreferences?: { analytics?: boolean; marketing?: boolean };\n  onChange?: (preferences: CookiePreferences) => void;\n  policyHref?: string;\n  accent?: string;\n}\n\nconst categories: { id: \"necessary\" | \"analytics\" | \"marketing\"; label: string; description: string }[] = [\n  { id: \"necessary\", label: \"Necessary\", description: \"Sign-in, security and load balancing. Always on.\" },\n  { id: \"analytics\", label: \"Analytics\", description: \"Anonymous usage stats that help us improve pages.\" },\n  { id: \"marketing\", label: \"Marketing\", description: \"Measures campaigns and personalizes ads.\" },\n];\n\nconst css = `\n.hb-ckb {\n  --hb-ckb-a: #2f7bff;\n  container: hb-ckb / inline-size;\n  box-sizing: border-box;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n}\n.hb-ckb *, .hb-ckb *::before, .hb-ckb *::after { box-sizing: border-box; }\n.hb-ckb[data-placement=\"bottom-left\"],\n.hb-ckb[data-placement=\"bottom-center\"] {\n  position: fixed;\n  bottom: 16px;\n  z-index: 2147482000;\n  width: min(420px, calc(100vw - 32px));\n}\n.hb-ckb[data-placement=\"bottom-left\"] { left: 16px; }\n.hb-ckb[data-placement=\"bottom-center\"] { left: 0; right: 0; margin: 0 auto; width: min(560px, calc(100vw - 32px)); }\n.hb-ckb-card {\n  padding: 16px;\n  border-radius: 16px;\n  background: #111111;\n  box-shadow: inset 0 0 0 1px #2a2a2a, 0 18px 50px rgba(0, 0, 0, 0.5);\n  animation: hb-ckb-in 0.5s cubic-bezier(0.2, 0.9, 0.2, 1) both;\n}\n.hb-ckb[data-closing=\"true\"] .hb-ckb-card { animation: hb-ckb-out 0.28s cubic-bezier(0.4, 0, 1, 1) forwards; }\n.hb-ckb-head { display: flex; align-items: center; gap: 9px; min-width: 0; }\n.hb-ckb-icon {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 26px;\n  height: 26px;\n  border-radius: 8px;\n  background: color-mix(in srgb, var(--hb-ckb-a) 15%, transparent);\n  color: color-mix(in srgb, var(--hb-ckb-a) 55%, #fff);\n}\n.hb-ckb-icon svg { width: 15px; height: 15px; }\n.hb-ckb-title { margin: 0; color: #fff; font-size: 14.5px; font-weight: 600; letter-spacing: -0.005em; }\n.hb-ckb-desc { margin: 8px 0 0; color: #a1a1a1; font-size: 13px; line-height: 1.5; }\n.hb-ckb-desc a { color: #d4d4d4; text-underline-offset: 3px; }\n.hb-ckb-desc a:hover { color: #fff; }\n.hb-ckb-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }\n.hb-ckb-btn {\n  flex: 1 1 0;\n  min-width: max-content;\n  height: 36px;\n  margin: 0;\n  padding: 0 14px;\n  border: 0;\n  border-radius: 10px;\n  background: #1c1c1c;\n  box-shadow: inset 0 0 0 1px #2e2e2e;\n  color: #ededed;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 550;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: background 0.2s ease, transform 0.15s ease, filter 0.2s ease;\n}\n.hb-ckb-btn:hover { background: #242424; }\n.hb-ckb-btn:active { transform: scale(0.97); }\n.hb-ckb-btn[data-primary=\"true\"] {\n  background: var(--hb-ckb-a);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);\n  color: #fff;\n}\n.hb-ckb-btn[data-primary=\"true\"]:hover { filter: brightness(1.1); }\n.hb-ckb-more {\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  flex: none;\n  margin: 0 0 0 auto;\n  padding: 3px 4px;\n  border: 0;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 12.5px;\n  cursor: pointer;\n  transition: color 0.2s ease;\n}\n.hb-ckb-more:hover { color: #fff; }\n.hb-ckb-more svg { width: 11px; height: 11px; transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.2, 1); }\n.hb-ckb-more[aria-expanded=\"true\"] svg { transform: rotate(180deg); }\n.hb-ckb-btn:focus-visible,\n.hb-ckb-more:focus-visible,\n.hb-ckb-sw:focus-visible,\n.hb-ckb-desc a:focus-visible {\n  outline: 2px solid var(--hb-ckb-a);\n  outline-offset: 2px;\n  border-radius: 8px;\n}\n.hb-ckb-panel {\n  display: grid;\n  grid-template-rows: 0fr;\n  visibility: hidden;\n  transition: grid-template-rows 0.35s cubic-bezier(0.2, 0.9, 0.2, 1), visibility 0s linear 0.35s;\n}\n.hb-ckb-panel[data-open=\"true\"] {\n  grid-template-rows: 1fr;\n  visibility: visible;\n  transition: grid-template-rows 0.35s cubic-bezier(0.2, 0.9, 0.2, 1), visibility 0s;\n}\n.hb-ckb-inner { min-height: 0; overflow: hidden; }\n.hb-ckb-list { margin: 12px 0 0; padding: 0; list-style: none; border-top: 1px solid #222; }\n.hb-ckb-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid #222; }\n.hb-ckb-txt { min-width: 0; }\n.hb-ckb-lbl { display: flex; align-items: center; gap: 6px; color: #f2f2f2; font-size: 13px; font-weight: 550; }\n.hb-ckb-lbl svg { width: 11px; height: 11px; color: #6b6b6b; }\n.hb-ckb-sub { display: block; margin-top: 2px; color: #8f8f8f; font-size: 12px; line-height: 1.4; }\n.hb-ckb-sw {\n  position: relative;\n  flex: none;\n  width: 38px;\n  height: 22px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 999px;\n  background: #2c2c2c;\n  cursor: pointer;\n  transition: background 0.25s ease;\n}\n.hb-ckb-sw::after {\n  content: \"\";\n  position: absolute;\n  top: 3px;\n  left: 3px;\n  width: 16px;\n  height: 16px;\n  border-radius: 50%;\n  background: #fff;\n  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);\n  transition: transform 0.3s cubic-bezier(0.3, 1.4, 0.5, 1);\n}\n.hb-ckb-sw[aria-checked=\"true\"] { background: var(--hb-ckb-a); }\n.hb-ckb-sw[aria-checked=\"true\"]::after { transform: translateX(16px); }\n.hb-ckb-sw[aria-disabled=\"true\"] { cursor: not-allowed; opacity: 0.55; }\n.hb-ckb-save { width: 100%; margin-top: 12px; flex: none; }\n@keyframes hb-ckb-in {\n  from { opacity: 0; transform: translateY(28px) scale(0.98); }\n  to { opacity: 1; transform: none; }\n}\n@keyframes hb-ckb-out {\n  to { opacity: 0; transform: translateY(20px) scale(0.98); }\n}\n@container hb-ckb (max-width: 299px) {\n  .hb-ckb-btn { flex-basis: 100%; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ckb-card, .hb-ckb[data-closing=\"true\"] .hb-ckb-card { animation: none; }\n  .hb-ckb[data-closing=\"true\"] .hb-ckb-card { opacity: 0; }\n  .hb-ckb-btn, .hb-ckb-more svg, .hb-ckb-panel, .hb-ckb-sw, .hb-ckb-sw::after { transition: none; }\n}\n`;\n\nexport function CookieBanner({\n  title = \"We value your privacy\",\n  description = \"We use cookies to run the site and understand how it is used. Choose what you allow.\",\n  placement = \"inline\",\n  defaultPreferences,\n  onChange,\n  policyHref,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: CookieBannerProps) {\n  const uid = React.useId();\n  const [prefs, setPrefs] = React.useState({\n    analytics: defaultPreferences?.analytics ?? false,\n    marketing: defaultPreferences?.marketing ?? false,\n  });\n  const [expanded, setExpanded] = React.useState(false);\n  const [closing, setClosing] = React.useState(false);\n  const [gone, setGone] = React.useState(false);\n\n  React.useEffect(() => {\n    if (!closing) return;\n    const id = window.setTimeout(() => setGone(true), 300);\n    return () => window.clearTimeout(id);\n  }, [closing]);\n\n  if (gone) return null;\n\n  function commit(next: { analytics: boolean; marketing: boolean }) {\n    setPrefs(next);\n    setClosing(true);\n    onChange?.({ necessary: true, ...next });\n  }\n\n  const rootStyle = { \"--hb-ckb-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div\n      className={`hb-ckb ${className}`}\n      data-placement={placement}\n      data-closing={closing ? \"true\" : \"false\"}\n      style={rootStyle}\n      {...rest}\n    >\n      <style href=\"hb-cookie-banner\" precedence=\"default\">{css}</style>\n      <section className=\"hb-ckb-card\" role=\"region\" aria-labelledby={`${uid}-t`} aria-describedby={`${uid}-d`}>\n        <div className=\"hb-ckb-head\">\n          <span className=\"hb-ckb-icon\" aria-hidden=\"true\">\n            <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n              <path d=\"M12 3a9 9 0 1 0 9 9 4 4 0 0 1-4-4 4 4 0 0 1-4-4 1 1 0 0 0-1-1z\" />\n              <path d=\"M8.5 11.5h.01M12 16h.01M15.5 13h.01\" />\n            </svg>\n          </span>\n          <h2 className=\"hb-ckb-title\" id={`${uid}-t`}>{title}</h2>\n          <button\n            type=\"button\"\n            className=\"hb-ckb-more\"\n            aria-expanded={expanded}\n            aria-controls={`${uid}-p`}\n            onClick={() => setExpanded((v) => !v)}\n          >\n            Customize\n            <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"m3 4.5 3 3 3-3\" />\n            </svg>\n          </button>\n        </div>\n        <p className=\"hb-ckb-desc\" id={`${uid}-d`}>\n          {description}\n          {policyHref && (\n            <>\n              {\" \"}\n              <a href={policyHref}>Cookie policy</a>\n            </>\n          )}\n        </p>\n        <div className=\"hb-ckb-actions\">\n          <button type=\"button\" className=\"hb-ckb-btn\" data-primary=\"true\" onClick={() => commit({ analytics: true, marketing: true })}>\n            Accept all\n          </button>\n          <button type=\"button\" className=\"hb-ckb-btn\" onClick={() => commit({ analytics: false, marketing: false })}>\n            Reject non-essential\n          </button>\n        </div>\n        <div className=\"hb-ckb-panel\" id={`${uid}-p`} data-open={expanded ? \"true\" : \"false\"}>\n          <div className=\"hb-ckb-inner\">\n            <ul className=\"hb-ckb-list\">\n              {categories.map((cat) => {\n                const key = cat.id;\n                const locked = key === \"necessary\";\n                const on = key === \"necessary\" ? true : prefs[key];\n                return (\n                  <li className=\"hb-ckb-row\" key={cat.id}>\n                    <div className=\"hb-ckb-txt\">\n                      <span className=\"hb-ckb-lbl\" id={`${uid}-${cat.id}`}>\n                        {cat.label}\n                        {locked && (\n                          <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                            <rect x=\"2.5\" y=\"5.5\" width=\"7\" height=\"5\" rx=\"1.2\" />\n                            <path d=\"M4 5.5V4a2 2 0 0 1 4 0v1.5\" />\n                          </svg>\n                        )}\n                      </span>\n                      <span className=\"hb-ckb-sub\" id={`${uid}-${cat.id}-d`}>{cat.description}</span>\n                    </div>\n                    <button\n                      type=\"button\"\n                      role=\"switch\"\n                      className=\"hb-ckb-sw\"\n                      aria-checked={on}\n                      aria-disabled={locked}\n                      aria-labelledby={`${uid}-${cat.id}`}\n                      aria-describedby={`${uid}-${cat.id}-d`}\n                      tabIndex={expanded ? 0 : -1}\n                      onClick={() => {\n                        if (key !== \"necessary\") setPrefs((p) => ({ ...p, [key]: !p[key] }));\n                      }}\n                    />\n                  </li>\n                );\n              })}\n            </ul>\n            <button type=\"button\" className=\"hb-ckb-btn hb-ckb-save\" tabIndex={expanded ? 0 : -1} onClick={() => commit(prefs)}>\n              Save preferences\n            </button>\n          </div>\n        </div>\n      </section>\n    </div>\n  );\n}\n"
    }
  ]
}