{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mega-menu",
  "title": "Mega Menu",
  "description": "A pill navigation bar whose menus open one shared panel: it morphs to each menu's size, slides the content in from the side you moved to, and holds columns of icon links plus a featured card, with hover intent and keyboard support.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/mega-menu/mega-menu.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type MegaMenuSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface MegaMenuLink {\n  label: string;\n  description?: string;\n  href: string;\n  icon?: React.ReactNode;\n}\n\nexport interface MegaMenuColumn {\n  title?: string;\n  links: MegaMenuLink[];\n}\n\nexport interface MegaMenuFeatured {\n  eyebrow?: string;\n  title: string;\n  description?: string;\n  href: string;\n  cta?: string;\n  image?: string;\n}\n\nexport interface MegaMenuItem {\n  id: string;\n  label: string;\n  /** A plain link in the bar. Items with columns open a panel instead. */\n  href?: string;\n  columns?: MegaMenuColumn[];\n  featured?: MegaMenuFeatured;\n}\n\nexport interface MegaMenuProps {\n  items?: MegaMenuItem[];\n  /** Open one menu from the start (by id), e.g. for previews. */\n  defaultOpenId?: string | null;\n  size?: MegaMenuSize;\n  theme?: \"dark\" | \"light\";\n  /** Milliseconds the panel stays open after the pointer leaves, so crossing a gap doesn't close it. */\n  closeDelay?: number;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", faint: \"rgba(245,244,241,0.12)\", bar: \"rgba(255,255,255,0.03)\", panel: \"#0F0F0F\", hover: \"rgba(255,255,255,0.06)\", pill: \"rgba(255,255,255,0.09)\", border: \"rgba(255,255,255,0.1)\", focus: \"rgba(245,244,241,0.85)\", iconBg: \"rgba(255,255,255,0.05)\", card: \"#161616\", shadow: \"0 30px 70px rgba(0,0,0,0.55), 0 4px 14px rgba(0,0,0,0.35)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", faint: \"rgba(10,10,10,0.1)\", bar: \"#FFFFFF\", panel: \"#FFFFFF\", hover: \"rgba(10,10,10,0.045)\", pill: \"rgba(10,10,10,0.06)\", border: \"rgba(10,10,10,0.12)\", focus: \"rgba(10,10,10,0.85)\", iconBg: \"rgba(10,10,10,0.04)\", card: \"#F6F6F5\", shadow: \"0 30px 70px rgba(10,10,10,0.14), 0 4px 14px rgba(10,10,10,0.06)\" },\n};\n\nconst SIZES: Record<MegaMenuSize, { bar: number; font: number; small: number; radius: number; pad: number; icon: number; col: number }> = {\n  sm: { bar: 40, font: 13, small: 12, radius: 12, pad: 14, icon: 30, col: 210 },\n  md: { bar: 46, font: 14, small: 12.5, radius: 14, pad: 16, icon: 34, col: 232 },\n  lg: { bar: 52, font: 15, small: 13.5, radius: 16, pad: 18, icon: 38, col: 252 },\n};\n\nconst icon = (d: string) => (\n  <svg width=\"17\" height=\"17\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d={d} />\n  </svg>\n);\n\nconst DEFAULT_ITEMS: MegaMenuItem[] = [\n  {\n    id: \"product\",\n    label: \"Product\",\n    columns: [\n      {\n        title: \"Build\",\n        links: [\n          { label: \"Components\", description: \"300+ animated React pieces\", href: \"#\", icon: icon(\"M3 3h6v6H3zM11 3h6v6h-6zM3 11h6v6H3zM11 11h6v6h-6z\") },\n          { label: \"Blocks\", description: \"Whole sections, ready to drop in\", href: \"#\", icon: icon(\"M3 4h14v5H3zM3 11h6v5H3zM11 11h6v5h-6z\") },\n          { label: \"Pages\", description: \"Complete pages you can ship today\", href: \"#\", icon: icon(\"M5 2.5h7l3 3v12H5zM12 2.5v3h3M8 9h4M8 12h4\") },\n        ],\n      },\n      {\n        title: \"Workflow\",\n        links: [\n          { label: \"CLI\", description: \"Install any piece with one command\", href: \"#\", icon: icon(\"M3.5 6l3.5 4-3.5 4M9.5 14h7\") },\n          { label: \"AI prompts\", description: \"Rebuild it in your own stack\", href: \"#\", icon: icon(\"M10 2.5l1.8 4.2 4.2 1.8-4.2 1.8L10 14.5l-1.8-4.2L4 8.5l4.2-1.8zM15.5 13.5l.8 1.7 1.7.8-1.7.8-.8 1.7-.8-1.7-1.7-.8 1.7-.8z\") },\n          { label: \"Figma kit\", description: \"Every component, as layers\", href: \"#\", icon: icon(\"M7.5 2.5h5a2.5 2.5 0 0 1 0 5h-5a2.5 2.5 0 0 1 0-5zM7.5 7.5h5a2.5 2.5 0 1 1 0 5h-5M7.5 12.5A2.5 2.5 0 1 0 10 15v-2.5\") },\n        ],\n      },\n    ],\n    featured: { eyebrow: \"New\", title: \"Kits are here\", description: \"Sets of components that share one design language.\", href: \"#\", cta: \"Browse kits\" },\n  },\n  {\n    id: \"solutions\",\n    label: \"Solutions\",\n    columns: [\n      {\n        title: \"By team\",\n        links: [\n          { label: \"Startups\", description: \"Launch a polished site this week\", href: \"#\", icon: icon(\"M10 2.5c3 2 4.5 5 4.5 8.5L10 17.5 5.5 11C5.5 7.5 7 4.5 10 2.5zM10 9.5h.01M7 17.5h6\") },\n          { label: \"Agencies\", description: \"Reuse pieces across clients\", href: \"#\", icon: icon(\"M3 7h14v9.5H3zM7 7V4.5h6V7M3 11h14\") },\n          { label: \"Enterprise\", description: \"Licensing, security and support\", href: \"#\", icon: icon(\"M4 17.5V4.5l6-2 6 2v13M8 7.5h.01M12 7.5h.01M8 11h.01M12 11h.01M9 17.5v-3h2v3\") },\n        ],\n      },\n      {\n        title: \"By use case\",\n        links: [\n          { label: \"Marketing sites\", href: \"#\", icon: icon(\"M3 4h14v10H3zM7 17h6M10 14v3\") },\n          { label: \"SaaS dashboards\", href: \"#\", icon: icon(\"M3 3.5h14v13H3zM3 7.5h14M7.5 7.5v9\") },\n          { label: \"E-commerce\", href: \"#\", icon: icon(\"M3.5 3.5h2l2 9.5h8l1.5-6.5H6.5M8.5 16.5h.01M14.5 16.5h.01\") },\n        ],\n      },\n    ],\n  },\n  {\n    id: \"resources\",\n    label: \"Resources\",\n    columns: [\n      {\n        links: [\n          { label: \"Documentation\", description: \"Guides and API reference\", href: \"#\", icon: icon(\"M4 3.5h9l3 3v10H4zM7.5 9.5h5M7.5 12.5h5\") },\n          { label: \"Changelog\", description: \"What shipped this week\", href: \"#\", icon: icon(\"M10 5.5V10l3 2M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0z\") },\n          { label: \"Community\", description: \"Ask, share and get help\", href: \"#\", icon: icon(\"M6.5 9a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zM2.5 16c.4-2.4 2-3.7 4-3.7s3.6 1.3 4 3.7M13.5 9a2 2 0 1 0 0-4M14.5 12.3c1.6.3 2.7 1.6 3 3.7\") },\n        ],\n      },\n    ],\n    featured: { eyebrow: \"Guide\", title: \"Build a landing page in an hour\", description: \"From blank file to deployed, step by step.\", href: \"#\", cta: \"Read the guide\" },\n  },\n  { id: \"pricing\", label: \"Pricing\", href: \"#\" },\n];\n\nexport function MegaMenu({ items = DEFAULT_ITEMS, defaultOpenId = null, size = \"md\", theme = \"dark\", closeDelay = 140, className }: MegaMenuProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const closeTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const [openId, setOpenId] = React.useState<string | null>(defaultOpenId);\n  const [dir, setDir] = React.useState(0);\n  const menus = items.filter((i) => i.columns?.length);\n  const active = items.find((i) => i.id === openId && i.columns?.length) ?? null;\n\n  const open = React.useCallback(\n    (id: string | null) => {\n      if (closeTimer.current) clearTimeout(closeTimer.current);\n      const a = menus.findIndex((m) => m.id === openId);\n      const b = menus.findIndex((m) => m.id === id);\n      // Slide the new content in from the side it lives on in the bar.\n      setDir(a >= 0 && b >= 0 && a !== b ? (b > a ? 1 : -1) : 0);\n      setOpenId(id);\n    },\n    [menus, openId],\n  );\n\n  const scheduleClose = () => {\n    if (closeTimer.current) clearTimeout(closeTimer.current);\n    closeTimer.current = setTimeout(() => setOpenId(null), closeDelay);\n  };\n\n  React.useEffect(() => () => {\n    if (closeTimer.current) clearTimeout(closeTimer.current);\n  }, []);\n\n  React.useEffect(() => {\n    if (!openId) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        const trigger = rootRef.current?.querySelector<HTMLElement>(`[data-mm-trigger=\"${openId}\"]`);\n        setOpenId(null);\n        trigger?.focus();\n      }\n    };\n    const onDown = (e: PointerEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpenId(null);\n    };\n    document.addEventListener(\"keydown\", onKey);\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => {\n      document.removeEventListener(\"keydown\", onKey);\n      document.removeEventListener(\"pointerdown\", onDown);\n    };\n  }, [openId]);\n\n  // ArrowLeft/Right move along the bar; ArrowDown opens and steps into the panel.\n  const onBarKey = (e: React.KeyboardEvent, item: MegaMenuItem) => {\n    const triggers = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-mm-trigger]\") ?? []);\n    const i = triggers.indexOf(e.currentTarget as HTMLElement);\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      const next = triggers[(i + (e.key === \"ArrowRight\" ? 1 : -1) + triggers.length) % triggers.length];\n      next?.focus();\n      const id = next?.getAttribute(\"data-mm-trigger\");\n      if (openId && id && items.find((x) => x.id === id)?.columns?.length) open(id);\n    } else if (e.key === \"ArrowDown\" && item.columns?.length) {\n      e.preventDefault();\n      open(item.id);\n      requestAnimationFrame(() => rootRef.current?.querySelector<HTMLElement>(`#${CSS.escape(uid)}-panel a`)?.focus());\n    }\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative inline-flex h-fit flex-col items-center self-start\", className)}\n      style={{ fontFamily: \"Inter, sans-serif\" }}\n      onMouseLeave={scheduleClose}\n      onMouseEnter={() => closeTimer.current && clearTimeout(closeTimer.current)}\n    >\n      <nav aria-label=\"Main\">\n        <ul className=\"m-0 flex list-none items-center p-1\" style={{ gap: 2, borderRadius: 999, background: p.bar, border: `1px solid ${p.border}` }}>\n          {items.map((item) => {\n            const isOpen = item.id === openId && Boolean(item.columns?.length);\n            const common = {\n              \"data-mm-trigger\": item.id,\n              onKeyDown: (e: React.KeyboardEvent) => onBarKey(e, item),\n              className: \"relative flex cursor-pointer items-center border-none bg-transparent font-medium no-underline outline-none focus-visible:ring-2\",\n              style: { height: s.bar - 10, padding: \"0 14px\", gap: 6, borderRadius: 999, color: isOpen ? p.text : p.muted, fontSize: s.font, transition: \"color 0.16s ease\", [\"--tw-ring-color\" as string]: p.focus } as React.CSSProperties,\n            };\n            const pill = isOpen && <motion.span layoutId={reduce ? undefined : `${uid}-pill`} className=\"absolute inset-0\" style={{ borderRadius: 999, background: p.pill }} transition={{ type: \"spring\", stiffness: 520, damping: 40 }} />;\n            return (\n              <li key={item.id}>\n                {item.columns?.length ? (\n                  <button\n                    type=\"button\"\n                    {...common}\n                    aria-expanded={isOpen}\n                    aria-controls={isOpen ? `${uid}-panel` : undefined}\n                    onMouseEnter={() => open(item.id)}\n                    onClick={() => open(isOpen ? null : item.id)}\n                  >\n                    {pill}\n                    <span className=\"relative\">{item.label}</span>\n                    <svg className=\"relative\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" style={{ transform: `rotate(${isOpen ? 180 : 0}deg)`, transition: \"transform 0.2s ease\" }}>\n                      <path d=\"M4 6l4 4 4-4\" />\n                    </svg>\n                  </button>\n                ) : (\n                  <a href={item.href} {...common} onMouseEnter={() => open(null)} onMouseOver={(e) => (e.currentTarget.style.color = p.text)} onMouseOut={(e) => (e.currentTarget.style.color = p.muted)}>\n                    <span className=\"relative\">{item.label}</span>\n                  </a>\n                )}\n              </li>\n            );\n          })}\n        </ul>\n      </nav>\n\n      {/* A zero-width anchor centred under the bar: the panel inside takes its own content width and\n          stays centred on the bar, without a transform that would fight the panel's animation. */}\n      <div className=\"pointer-events-none absolute left-1/2 z-50 flex w-0 justify-center\" style={{ top: \"calc(100% + 10px)\" }}>\n      <AnimatePresence>\n        {active && (\n          <motion.div\n            key=\"panel\"\n            id={`${uid}-panel`}\n            layout={!reduce}\n            initial={reduce ? { opacity: 0 } : { opacity: 0, y: -6, scale: 0.98 }}\n            animate={{ opacity: 1, y: 0, scale: 1 }}\n            exit={reduce ? { opacity: 0 } : { opacity: 0, y: -6, scale: 0.98 }}\n            transition={{ duration: 0.2, ease: [0.22, 1, 0.36, 1], layout: { type: \"spring\", stiffness: 420, damping: 38 } }}\n            className=\"pointer-events-auto relative shrink-0 overflow-hidden\"\n            style={{ width: \"max-content\", maxWidth: \"calc(100vw - 24px)\", borderRadius: s.radius + 4, background: p.panel, border: `1px solid ${p.border}`, boxShadow: p.shadow, transformOrigin: \"top center\" }}\n          >\n            <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n              <motion.div\n                key={active.id}\n                custom={dir}\n                initial={reduce ? { opacity: 0 } : { opacity: 0, x: dir * 36 }}\n                animate={{ opacity: 1, x: 0 }}\n                exit={reduce ? { opacity: 0 } : { opacity: 0, x: dir * -36 }}\n                transition={{ duration: 0.22, ease: [0.22, 1, 0.36, 1] }}\n                className=\"flex flex-wrap\"\n                style={{ padding: s.pad - 6, gap: 6 }}\n              >\n                {active.columns?.map((col, ci) => (\n                  <div key={ci} className=\"flex flex-col\" style={{ width: s.col }}>\n                    {col.title && (\n                      <div className=\"font-semibold uppercase\" style={{ padding: \"8px 10px 6px\", color: p.muted, fontSize: 10.5, letterSpacing: \"0.07em\" }}>\n                        {col.title}\n                      </div>\n                    )}\n                    {col.links.map((link) => (\n                      <a\n                        key={link.label}\n                        href={link.href}\n                        className=\"flex items-start no-underline outline-none focus-visible:ring-2\"\n                        style={{ gap: 11, padding: \"8px 10px\", borderRadius: s.radius - 3, transition: \"background 0.14s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n                        onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)}\n                        onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n                        onFocus={(e) => (e.currentTarget.style.background = p.hover)}\n                        onBlur={(e) => (e.currentTarget.style.background = \"transparent\")}\n                      >\n                        {link.icon && (\n                          <span className=\"flex shrink-0 items-center justify-center\" style={{ width: s.icon, height: s.icon, borderRadius: s.radius - 5, background: p.iconBg, border: `1px solid ${p.faint}`, color: p.text }}>\n                            {link.icon}\n                          </span>\n                        )}\n                        <span className=\"flex min-w-0 flex-col\" style={{ paddingTop: link.description ? 0 : (s.icon - s.font * 1.4) / 2 }}>\n                          <span className=\"font-semibold\" style={{ color: p.text, fontSize: s.font, lineHeight: 1.4 }}>\n                            {link.label}\n                          </span>\n                          {link.description && <span style={{ color: p.muted, fontSize: s.small, lineHeight: 1.4 }}>{link.description}</span>}\n                        </span>\n                      </a>\n                    ))}\n                  </div>\n                ))}\n                {active.featured && (\n                  <a\n                    href={active.featured.href}\n                    className=\"group relative flex flex-col justify-end overflow-hidden no-underline outline-none focus-visible:ring-2\"\n                    style={{ width: s.col - 10, minHeight: 200, margin: 4, padding: s.pad, borderRadius: s.radius, background: p.card, border: `1px solid ${p.faint}`, [\"--tw-ring-color\" as string]: p.focus }}\n                  >\n                    {active.featured.image ? (\n                      // eslint-disable-next-line @next/next/no-img-element\n                      <img src={active.featured.image} alt=\"\" className=\"absolute inset-0 h-full w-full object-cover opacity-60 transition-transform duration-500 group-hover:scale-105\" />\n                    ) : (\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"absolute inset-0 transition-transform duration-500 group-hover:scale-105\"\n                        style={{ backgroundImage: `linear-gradient(${p.faint} 1px, transparent 1px), linear-gradient(90deg, ${p.faint} 1px, transparent 1px)`, backgroundSize: \"22px 22px\", maskImage: \"radial-gradient(circle at 70% 20%, black, transparent 75%)\", WebkitMaskImage: \"radial-gradient(circle at 70% 20%, black, transparent 75%)\" }}\n                      />\n                    )}\n                    <span className=\"relative flex flex-col\" style={{ gap: 4 }}>\n                      {active.featured.eyebrow && (\n                        <span className=\"self-start font-semibold\" style={{ padding: \"2px 8px\", borderRadius: 999, background: p.text, color: p.panel, fontSize: 10.5 }}>\n                          {active.featured.eyebrow}\n                        </span>\n                      )}\n                      <span className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font + 1.5, lineHeight: 1.3, marginTop: 4 }}>\n                        {active.featured.title}\n                      </span>\n                      {active.featured.description && <span style={{ color: p.muted, fontSize: s.small, lineHeight: 1.45 }}>{active.featured.description}</span>}\n                      {active.featured.cta && (\n                        <span className=\"font-semibold\" style={{ color: p.text, fontSize: s.small, marginTop: 6 }}>\n                          {active.featured.cta} <span className=\"inline-block transition-transform duration-200 group-hover:translate-x-0.5\">→</span>\n                        </span>\n                      )}\n                    </span>\n                  </a>\n                )}\n              </motion.div>\n            </AnimatePresence>\n          </motion.div>\n        )}\n      </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nexport default MegaMenu;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}