{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon-category-nav",
  "title": "Icon Category Nav",
  "description": "A store category bar of line icons with labels that keeps as many categories as fit and folds the rest into a More menu as the width changes, with a little hover animation per icon, a sliding underline on the current category and a subcategory strip below.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/icon-category-nav/icon-category-nav.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, type Variants } 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\ntype IconName = \"spark\" | \"headphones\" | \"watch\" | \"laptop\" | \"lamp\" | \"bag\" | \"shoe\" | \"mountain\" | \"mug\" | \"gift\" | \"tag\";\nexport interface NavCategory {\n  id: string;\n  name: string;\n  icon: IconName;\n  count: number;\n  subcategories?: string[];\n  highlight?: boolean;\n}\n\nexport interface IconCategoryNavProps {\n  store?: string;\n  categories?: NavCategory[];\n  defaultCategory?: string;\n  onSelect?: (category: NavCategory) => void;\n  onSubcategory?: (category: NavCategory, sub: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", title: \"#FFFFFF\", muted: \"rgba(255,255,255,0.45)\", body: \"rgba(255,255,255,0.62)\", line: \"rgba(255,255,255,0.12)\", card: \"#161616\", hover: \"rgba(255,255,255,0.06)\", menu: \"#141414\", accent: \"#7CDE6A\", accentText: \"#0B1A08\", chip: \"rgba(255,255,255,0.06)\", ring: \"rgba(255,255,255,0.55)\" },\n  light: { bg: \"#FFFFFF\", title: \"#111111\", muted: \"rgba(0,0,0,0.45)\", body: \"rgba(0,0,0,0.62)\", line: \"rgba(0,0,0,0.1)\", card: \"#F7F7F5\", hover: \"rgba(0,0,0,0.04)\", menu: \"#FFFFFF\", accent: \"#2F9E44\", accentText: \"#FFFFFF\", chip: \"rgba(0,0,0,0.05)\", ring: \"rgba(0,0,0,0.45)\" },\n};\n\nconst CATEGORIES: NavCategory[] = [\n  { id: \"new\", name: \"New in\", icon: \"spark\", count: 18, subcategories: [\"This week\", \"Restocks\", \"Coming soon\"] },\n  { id: \"audio\", name: \"Audio\", icon: \"headphones\", count: 24, subcategories: [\"Headphones\", \"Earbuds\", \"Speakers\", \"Cables & cases\"] },\n  { id: \"watches\", name: \"Watches\", icon: \"watch\", count: 9, subcategories: [\"Leather\", \"Steel\", \"Straps\"] },\n  { id: \"desk\", name: \"Desk\", icon: \"laptop\", count: 31, subcategories: [\"Stands\", \"Notebooks\", \"Organisers\", \"Mats\"] },\n  { id: \"lighting\", name: \"Lighting\", icon: \"lamp\", count: 12, subcategories: [\"Desk lamps\", \"Clip lights\", \"Bulbs\"] },\n  { id: \"bags\", name: \"Bags\", icon: \"bag\", count: 16, subcategories: [\"Backpacks\", \"Totes\", \"Pouches\"] },\n  { id: \"running\", name: \"Running\", icon: \"shoe\", count: 14, subcategories: [\"Road\", \"Trail\", \"Socks\"] },\n  { id: \"outdoor\", name: \"Outdoor\", icon: \"mountain\", count: 22, subcategories: [\"Bottles\", \"Shells\", \"Camp\"] },\n  { id: \"home\", name: \"Home\", icon: \"mug\", count: 27, subcategories: [\"Mugs\", \"Throws\", \"Plants\"] },\n  { id: \"gifts\", name: \"Gifts\", icon: \"gift\", count: 40, subcategories: [\"Under $50\", \"For runners\", \"Gift cards\"] },\n  { id: \"sale\", name: \"Sale\", icon: \"tag\", count: 33, subcategories: [\"Up to 30% off\", \"Last sizes\", \"Bundles\"], highlight: true },\n];\n\n// Each icon has its own little hover move.\nconst ICONS: Record<IconName, { paths: string[]; hover: Variants[\"hover\"] }> = {\n  spark: { paths: [\"M12 3c.5 4.3 2.7 6.5 7 7-4.3.5-6.5 2.7-7 7-.5-4.3-2.7-6.5-7-7 4.3-.5 6.5-2.7 7-7Z\", \"M19 3v3M17.5 4.5h3\"], hover: { rotate: 90, scale: 1.1 } },\n  headphones: { paths: [\"M4 15v-3a8 8 0 0 1 16 0v3\", \"M4 15h3v5H5a1 1 0 0 1-1-1zM20 15h-3v5h2a1 1 0 0 0 1-1z\"], hover: { y: [0, -2, 0, -1, 0], transition: { duration: 0.5 } } },\n  watch: { paths: [\"M8 7V3h8v4M8 17v4h8v-4\", \"M12 6.5a5.5 5.5 0 1 1 0 11 5.5 5.5 0 0 1 0-11ZM12 9.5V12l1.8 1.2\"], hover: { rotate: [0, -12, 10, -6, 0], transition: { duration: 0.6 } } },\n  laptop: { paths: [\"M5 6h14v9H5z\", \"M3 18h18l-1.5-3h-15z\"], hover: { y: -2, scale: 1.06 } },\n  lamp: { paths: [\"M7 21h10M12 21v-8l5-6\", \"M14 4l5 3-2 3-5-3z\", \"M17.5 10.5 19 13\"], hover: { rotate: [0, -8, 0], transition: { duration: 0.5 } } },\n  bag: { paths: [\"M6 8h12l-1 12H7z\", \"M9 8V6a3 3 0 0 1 6 0v2\"], hover: { y: [0, -3, 0], transition: { duration: 0.4 } } },\n  shoe: { paths: [\"M3 16c0-3 1-7 2-9 2 1 4 1 6 0 1 3 4 5 8 6a2 2 0 0 1 2 2v1z\", \"M3 16v2h18v-2\"], hover: { x: [0, 3, 0], rotate: [0, -6, 0], transition: { duration: 0.45 } } },\n  mountain: { paths: [\"m3 19 6-10 4 6 2-3 6 7z\", \"M16 6.5a1.5 1.5 0 1 0 0-.01\"], hover: { scale: 1.08 } },\n  mug: { paths: [\"M5 8h11v8a4 4 0 0 1-4 4H9a4 4 0 0 1-4-4z\", \"M16 10h1.5a2.5 2.5 0 0 1 0 5H16\", \"M9 3c-.8 1 .8 2 0 3M12 3c-.8 1 .8 2 0 3\"], hover: { rotate: [0, 6, -4, 0], transition: { duration: 0.5 } } },\n  gift: { paths: [\"M4 10h16v10H4zM3 7h18v3H3zM12 7v13\", \"M12 7c-2-3-6-3-6 0M12 7c2-3 6-3 6 0\"], hover: { scale: [1, 1.12, 0.96, 1.04, 1], transition: { duration: 0.5 } } },\n  tag: { paths: [\"M3 12V4h8l10 10-8 8z\", \"M7.5 8.5a1 1 0 1 0 0-.01\"], hover: { rotate: [0, -14, 8, 0], transition: { duration: 0.5 } } },\n};\n\nfunction Icon({ name, size = 22 }: { name: IconName; size?: number }) {\n  const icon = ICONS[name];\n  return (\n    <motion.svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" variants={{ rest: { rotate: 0, scale: 1, x: 0, y: 0 }, hover: icon.hover }} style={{ originX: 0.5, originY: 0.5 }}>\n      {icon.paths.map((d) => (\n        <path key={d} d={d} />\n      ))}\n    </motion.svg>\n  );\n}\n\nexport function IconCategoryNav({ store = \"Northline\", categories = CATEGORIES, defaultCategory = \"audio\", onSelect, onSubcategory, theme = \"dark\", className }: IconCategoryNavProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const rowRef = React.useRef<HTMLDivElement>(null);\n  const measureRef = React.useRef<HTMLDivElement>(null);\n  const moreRef = React.useRef<HTMLButtonElement>(null);\n  const [active, setActive] = React.useState(defaultCategory);\n  const [fit, setFit] = React.useState(categories.length);\n  const [menuOpen, setMenuOpen] = React.useState(false);\n  const [sub, setSub] = React.useState<string | null>(null);\n\n  // Priority+ : measure every item once in a hidden row, then show as many as fit and\n  // move the rest into More. The active item is always kept visible.\n  React.useEffect(() => {\n    const row = rowRef.current;\n    const measure = measureRef.current;\n    if (!row || !measure) return;\n    const calc = () => {\n      const widths = [...measure.children].map((el) => (el as HTMLElement).offsetWidth);\n      const moreW = (measure.lastElementChild as HTMLElement | null)?.offsetWidth ?? 80;\n      const items = widths.slice(0, -1);\n      const avail = row.clientWidth;\n      const total = items.reduce((a, b) => a + b, 0);\n      if (total <= avail) return setFit(items.length);\n      let used = moreW;\n      let n = 0;\n      for (const w of items) {\n        if (used + w > avail) break;\n        used += w;\n        n++;\n      }\n      setFit(Math.max(1, n));\n    };\n    const ro = new ResizeObserver(calc);\n    ro.observe(row);\n    return () => ro.disconnect();\n  }, [categories]);\n\n  React.useEffect(() => {\n    if (!menuOpen) return;\n    const close = (e: PointerEvent) => {\n      if (!(e.target as HTMLElement).closest(\"[data-icon-nav-more]\")) setMenuOpen(false);\n    };\n    const key = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setMenuOpen(false);\n        moreRef.current?.focus();\n      }\n    };\n    window.addEventListener(\"pointerdown\", close);\n    window.addEventListener(\"keydown\", key);\n    return () => {\n      window.removeEventListener(\"pointerdown\", close);\n      window.removeEventListener(\"keydown\", key);\n    };\n  }, [menuOpen]);\n\n  const activeIndex = Math.max(0, categories.findIndex((c) => c.id === active));\n  // Keep the active category in the bar: if it would overflow, swap it into the last visible slot.\n  const order = categories.map((_, i) => i);\n  if (activeIndex >= fit && fit > 0) {\n    order.splice(activeIndex, 1);\n    order.splice(fit - 1, 0, activeIndex);\n  }\n  const shown = order.slice(0, fit).map((i) => categories[i]);\n  const hidden = order.slice(fit).map((i) => categories[i]);\n  const current = categories[activeIndex];\n\n  const choose = (c: NavCategory) => {\n    setActive(c.id);\n    setSub(null);\n    setMenuOpen(false);\n    onSelect?.(c);\n  };\n  const ring = { [\"--tw-ring-color\" as string]: p.ring } as React.CSSProperties;\n\n  const item = (c: NavCategory, measuring = false) => {\n    const on = !measuring && c.id === active;\n    return (\n      <motion.button\n        key={c.id}\n        type=\"button\"\n        tabIndex={measuring ? -1 : undefined}\n        aria-current={on ? \"page\" : undefined}\n        onClick={measuring ? undefined : () => choose(c)}\n        initial=\"rest\"\n        animate=\"rest\"\n        whileHover={reduce || measuring ? undefined : \"hover\"}\n        whileFocus={reduce || measuring ? undefined : \"hover\"}\n        className=\"relative flex h-[76px] shrink-0 cursor-pointer flex-col items-center justify-center gap-1.5 rounded-xl border-0 bg-transparent px-3.5 outline-none hover:bg-[var(--h)] focus-visible:ring-2 focus-visible:ring-inset @[640px]:px-4\"\n        style={{ color: on ? p.title : c.highlight ? p.accent : p.body, [\"--h\" as string]: p.hover, ...ring }}\n      >\n        <Icon name={c.icon} />\n        <span className=\"text-[12.5px] font-medium whitespace-nowrap\">{c.name}</span>\n        {on && <motion.span layoutId={`${uid}-bar`} className=\"absolute inset-x-3 -bottom-px h-[2px] rounded-full\" style={{ background: p.title }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n      </motion.button>\n    );\n  };\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }}>\n      {/* Store bar */}\n      <div className=\"border-b\" style={{ borderColor: p.line }}>\n        <div className=\"mx-auto flex h-14 max-w-6xl items-center justify-between px-4 @[640px]:px-8\">\n          <span className=\"text-[17px] font-semibold\">{store}</span>\n          <span className=\"flex items-center gap-4 text-[13px]\" style={{ color: p.body }}>\n            <span className=\"hidden @[480px]:inline\">Help</span>\n            <span>Account</span>\n            <span>Cart (2)</span>\n          </span>\n        </div>\n      </div>\n\n      {/* Icon nav */}\n      <nav aria-label=\"Shop by category\" className=\"relative border-b\" style={{ borderColor: p.line }}>\n        <div className=\"mx-auto max-w-6xl px-2 @[640px]:px-6\">\n          {/* Hidden copy used only to measure item widths */}\n          <div ref={measureRef} aria-hidden=\"true\" className=\"pointer-events-none invisible absolute flex h-0 overflow-hidden\">\n            {categories.map((c) => item(c, true))}\n            <span className=\"flex h-[76px] shrink-0 items-center px-4 text-[12.5px] font-medium\">More 99</span>\n          </div>\n\n          <div ref={rowRef} className=\"flex items-stretch\">\n            <ul className=\"m-0 flex min-w-0 list-none items-stretch overflow-hidden p-0\">\n              {shown.map((c) => (\n                <li key={c.id} className=\"flex\">\n                  {item(c)}\n                </li>\n              ))}\n            </ul>\n            {hidden.length > 0 && (\n              <div className=\"relative ml-auto flex\" data-icon-nav-more>\n                <motion.button\n                  ref={moreRef}\n                  type=\"button\"\n                  aria-haspopup=\"menu\"\n                  aria-expanded={menuOpen}\n                  aria-controls={`${uid}-more`}\n                  onClick={() => setMenuOpen((o) => !o)}\n                  initial=\"rest\"\n                  animate=\"rest\"\n                  whileHover={reduce ? undefined : \"hover\"}\n                  className=\"flex h-[76px] shrink-0 cursor-pointer flex-col items-center justify-center gap-1.5 rounded-xl border-0 bg-transparent px-4 outline-none hover:bg-[var(--h)] focus-visible:ring-2 focus-visible:ring-inset\"\n                  style={{ color: menuOpen ? p.title : p.body, [\"--h\" as string]: p.hover, ...ring }}\n                >\n                  <span className=\"relative\">\n                    <motion.svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\" variants={{ rest: { rotate: 0 }, hover: { rotate: 90 } }} animate={menuOpen ? { rotate: 90 } : undefined}>\n                      <circle cx=\"5\" cy=\"12\" r=\"1.8\" />\n                      <circle cx=\"12\" cy=\"12\" r=\"1.8\" />\n                      <circle cx=\"19\" cy=\"12\" r=\"1.8\" />\n                    </motion.svg>\n                    <span className=\"absolute -top-1.5 -right-3 grid h-4 min-w-4 place-items-center rounded-full px-1 text-[10px] font-bold\" style={{ background: p.title, color: p.bg }}>\n                      {hidden.length}\n                    </span>\n                  </span>\n                  <span className=\"text-[12.5px] font-medium\">More</span>\n                </motion.button>\n                <AnimatePresence>\n                  {menuOpen && (\n                    <motion.div\n                      id={`${uid}-more`}\n                      role=\"menu\"\n                      aria-label=\"More categories\"\n                      initial={reduce ? false : { opacity: 0, y: -6, scale: 0.97 }}\n                      animate={{ opacity: 1, y: 0, scale: 1 }}\n                      exit={reduce ? undefined : { opacity: 0, y: -4, scale: 0.98 }}\n                      transition={{ duration: 0.16 }}\n                      className=\"absolute top-full right-0 z-30 mt-2 max-h-[min(340px,70vh)] w-[230px] origin-top-right overflow-y-auto overscroll-contain rounded-2xl border p-1.5 shadow-[0_24px_50px_-18px_rgba(0,0,0,0.6)]\"\n                      style={{ background: p.menu, borderColor: p.line }}\n                      onKeyDown={(e) => {\n                        if (e.key !== \"ArrowDown\" && e.key !== \"ArrowUp\") return;\n                        e.preventDefault();\n                        const els = [...e.currentTarget.querySelectorAll<HTMLElement>(\"[role=menuitem]\")];\n                        const i = els.indexOf(document.activeElement as HTMLElement);\n                        els[(i + (e.key === \"ArrowDown\" ? 1 : -1) + els.length) % els.length]?.focus();\n                      }}\n                    >\n                      {hidden.map((c, i) => (\n                        <motion.button\n                          key={c.id}\n                          type=\"button\"\n                          role=\"menuitem\"\n                          ref={(el) => {\n                            if (i === 0 && el && !el.dataset.f) {\n                              el.dataset.f = \"1\";\n                              el.focus({ preventScroll: true });\n                            }\n                          }}\n                          onClick={() => choose(c)}\n                          initial={reduce ? false : { opacity: 0, x: 8 }}\n                          animate={{ opacity: 1, x: 0 }}\n                          transition={{ delay: reduce ? 0 : 0.03 * i }}\n                          className=\"flex h-11 w-full cursor-pointer items-center gap-3 rounded-xl border-0 bg-transparent px-3 text-left text-[13.5px] outline-none hover:bg-[var(--h)] focus-visible:bg-[var(--h)]\"\n                          style={{ color: c.highlight ? p.accent : p.title, [\"--h\" as string]: p.hover }}\n                        >\n                          <Icon name={c.icon} size={18} />\n                          <span className=\"flex-1\">{c.name}</span>\n                          <span className=\"text-[11.5px] tabular-nums\" style={{ color: p.muted }}>\n                            {c.count}\n                          </span>\n                        </motion.button>\n                      ))}\n                    </motion.div>\n                  )}\n                </AnimatePresence>\n              </div>\n            )}\n          </div>\n        </div>\n      </nav>\n\n      {/* Selected category strip */}\n      <div className=\"mx-auto max-w-6xl px-4 py-7 @[640px]:px-8\">\n        <AnimatePresence mode=\"wait\" initial={false}>\n          <motion.div key={current?.id} initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -6 }} transition={{ duration: 0.2 }}>\n            <p className=\"m-0 text-[12px] tracking-[0.12em] uppercase\" style={{ color: p.muted }}>\n              {store} / {current?.name}\n              {sub ? ` / ${sub}` : \"\"}\n            </p>\n            <div className=\"mt-2 flex flex-wrap items-baseline gap-x-3 gap-y-1\">\n              <h2 className=\"m-0 text-[28px] leading-tight font-semibold tracking-[-0.02em] @[640px]:text-[34px]\">{sub ?? current?.name}</h2>\n              <span className=\"text-[14px] tabular-nums\" style={{ color: p.body }} aria-live=\"polite\">\n                {current?.count} products\n              </span>\n            </div>\n            <div className=\"mt-4 flex flex-wrap gap-2\" role=\"group\" aria-label={`${current?.name} subcategories`}>\n              {[`All ${current?.name.toLowerCase()}`, ...(current?.subcategories ?? [])].map((s, i) => {\n                const on = i === 0 ? sub === null : sub === s;\n                return (\n                  <motion.button\n                    key={s}\n                    type=\"button\"\n                    aria-pressed={on}\n                    onClick={() => {\n                      const next = i === 0 ? null : s;\n                      setSub(next);\n                      if (next && current) onSubcategory?.(current, next);\n                    }}\n                    initial={reduce ? false : { opacity: 0, y: 6 }}\n                    animate={{ opacity: 1, y: 0 }}\n                    transition={{ delay: reduce ? 0 : 0.04 * i }}\n                    className=\"h-9 cursor-pointer rounded-full border px-4 text-[13px] font-medium outline-none focus-visible:ring-2\"\n                    style={{ background: on ? p.title : p.chip, borderColor: on ? p.title : \"transparent\", color: on ? p.bg : p.body, ...ring }}\n                  >\n                    {s}\n                  </motion.button>\n                );\n              })}\n            </div>\n          </motion.div>\n        </AnimatePresence>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}