{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "category-carousel",
  "title": "Category Carousel",
  "description": "A shop-by-category row of round photo bubbles that scrolls, drags and snaps, with arrows, a scroll progress bar, New badges and a Sale bubble; picking a category slides a ring onto it and swaps in that category's products with quick add buttons.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/category-carousel/category-carousel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useMotionValue, useReducedMotion, useSpring, useTransform } 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 interface CarouselCategory {\n  id: string;\n  name: string;\n  count: number;\n  /** Leave out for a text bubble (used for Sale). */\n  image?: string;\n  /** How much to enlarge the photo inside the circle. */\n  zoom?: number;\n  isNew?: boolean;\n  label?: string;\n}\nexport interface CarouselProduct {\n  id: string;\n  name: string;\n  price: number;\n  was?: number;\n  image: string;\n  categories: string[];\n}\n\nexport interface CategoryCarouselProps {\n  title?: string;\n  subtitle?: string;\n  categories?: CarouselCategory[];\n  products?: CarouselProduct[];\n  defaultCategory?: string;\n  currency?: string;\n  onSelect?: (category: CarouselCategory) => void;\n  onAdd?: (product: CarouselProduct) => 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\", tile: \"#F1F1F1\", accent: \"#7CDE6A\", accentText: \"#0B1A08\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", 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\", tile: \"#F1F1F1\", accent: \"#2F9E44\", accentText: \"#FFFFFF\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", ring: \"rgba(0,0,0,0.45)\" },\n};\n\nconst L = \"/demo/blocks/product-list\";\nconst CATEGORIES: CarouselCategory[] = [\n  { id: \"sale\", name: \"Sale\", count: 3, label: \"−40%\" },\n  { id: \"audio\", name: \"Audio\", count: 2, image: `${L}/headphones.webp`, zoom: 2 },\n  { id: \"watches\", name: \"Watches\", count: 1, image: \"/demo/blocks/product-detail/watch-1.webp\", zoom: 1.05, isNew: true },\n  { id: \"desk\", name: \"Desk setup\", count: 3, image: `${L}/stand.webp`, zoom: 1.45 },\n  { id: \"lighting\", name: \"Lighting\", count: 1, image: `${L}/lamp.webp`, zoom: 1.75 },\n  { id: \"bags\", name: \"Bags\", count: 1, image: `${L}/backpack.webp`, zoom: 2 },\n  { id: \"running\", name: \"Running\", count: 1, image: `${L}/shoe.webp`, zoom: 1.5 },\n  { id: \"hydration\", name: \"Hydration\", count: 1, image: `${L}/bottle.webp`, zoom: 1.8, isNew: true },\n  { id: \"stationery\", name: \"Stationery\", count: 1, image: `${L}/notebook.webp`, zoom: 2 },\n  { id: \"earbuds\", name: \"Earbuds\", count: 1, image: `${L}/earbuds.webp`, zoom: 1.8 },\n];\nconst PRODUCTS: CarouselProduct[] = [\n  { id: \"headphones\", name: \"Studio Headphones\", price: 199, image: `${L}/headphones.webp`, categories: [\"audio\"] },\n  { id: \"earbuds\", name: \"Wireless Earbuds\", price: 129, image: \"/demo/wireless-earbuds.webp\", categories: [\"audio\", \"earbuds\"] },\n  { id: \"watch\", name: \"Minimal Watch\", price: 79, was: 129, image: \"/demo/minimal-watch.webp\", categories: [\"watches\", \"sale\"] },\n  { id: \"stand\", name: \"Laptop Stand\", price: 49, was: 89, image: \"/demo/laptop-stand.webp\", categories: [\"desk\", \"sale\"] },\n  { id: \"notebook\", name: \"Dot Notebook\", price: 24, image: \"/demo/notebook.webp\", categories: [\"desk\", \"stationery\"] },\n  { id: \"lamp\", name: \"Desk Lamp\", price: 59, image: `${L}/lamp.webp`, categories: [\"desk\", \"lighting\"] },\n  { id: \"backpack\", name: \"Day Backpack\", price: 89, image: `${L}/backpack.webp`, categories: [\"bags\"] },\n  { id: \"shoes\", name: \"Running Shoes\", price: 99, was: 149, image: \"/demo/running-shoes.webp\", categories: [\"running\", \"sale\"] },\n  { id: \"bottle\", name: \"Insulated Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\", categories: [\"hydration\"] },\n];\n\nconst money = (n: number, c: string) => `${c}${n.toFixed(2)}`;\n\nexport function CategoryCarousel({\n  title = \"Shop by category\",\n  subtitle = \"Ten corners of the store, one tap away.\",\n  categories = CATEGORIES,\n  products = PRODUCTS,\n  defaultCategory = \"audio\",\n  currency = \"$\",\n  onSelect,\n  onAdd,\n  theme = \"dark\",\n  className,\n}: CategoryCarouselProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const tabRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const [active, setActive] = React.useState(defaultCategory);\n  const [added, setAdded] = React.useState<string[]>([]);\n  const [edges, setEdges] = React.useState({ start: true, end: false });\n  const drag = React.useRef<{ x: number; left: number; moved: boolean; id: number } | null>(null);\n  const suppressClick = React.useRef(false);\n\n  // Scroll progress: thumb size is the visible share, position follows scrollLeft.\n  const ratio = useMotionValue(1);\n  const progress = useMotionValue(0);\n  const smooth = useSpring(progress, { stiffness: 300, damping: 40 });\n  const thumbLeft = useTransform([smooth, ratio] as const, ([v, r]: number[]) => `${v * (1 - r) * 100}%`);\n  const thumbWidth = useTransform(ratio, (r) => `${Math.max(12, r * 100)}%`);\n\n  const measure = React.useCallback(() => {\n    const el = trackRef.current;\n    if (!el) return;\n    const max = el.scrollWidth - el.clientWidth;\n    ratio.set(el.scrollWidth ? el.clientWidth / el.scrollWidth : 1);\n    progress.set(max > 0 ? el.scrollLeft / max : 0);\n    setEdges((e) => {\n      const next = { start: el.scrollLeft <= 2, end: el.scrollLeft >= max - 2 };\n      return e.start === next.start && e.end === next.end ? e : next;\n    });\n  }, [ratio, progress]);\n  React.useEffect(() => {\n    const el = trackRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => measure());\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [measure]);\n\n  const scrollByPage = (dir: 1 | -1) => {\n    const el = trackRef.current;\n    if (!el) return;\n    el.scrollBy({ left: dir * el.clientWidth * 0.8, behavior: reduce ? \"auto\" : \"smooth\" });\n  };\n  const select = (i: number, focus = false) => {\n    const c = categories[i];\n    if (!c) return;\n    setActive(c.id);\n    onSelect?.(c);\n    const tab = tabRefs.current[i];\n    if (focus) tab?.focus({ preventScroll: true });\n    tab?.scrollIntoView({ behavior: reduce ? \"auto\" : \"smooth\", block: \"nearest\", inline: \"nearest\" });\n  };\n  const onKey = (e: React.KeyboardEvent, i: number) => {\n    const last = categories.length - 1;\n    const to = e.key === \"ArrowRight\" ? Math.min(last, i + 1) : e.key === \"ArrowLeft\" ? Math.max(0, i - 1) : e.key === \"Home\" ? 0 : e.key === \"End\" ? last : null;\n    if (to === null) return;\n    e.preventDefault();\n    select(to, true);\n  };\n\n  // Mouse drag to scroll; touch and trackpads scroll natively.\n  const onPointerDown = (e: React.PointerEvent) => {\n    if (e.pointerType !== \"mouse\" || e.button !== 0 || !trackRef.current) return;\n    drag.current = { x: e.clientX, left: trackRef.current.scrollLeft, moved: false, id: e.pointerId };\n  };\n  const onPointerMove = (e: React.PointerEvent) => {\n    const d = drag.current;\n    const el = trackRef.current;\n    if (!d || !el) return;\n    const dx = e.clientX - d.x;\n    if (!d.moved && Math.abs(dx) > 5) {\n      d.moved = true;\n      el.setPointerCapture(d.id);\n      // Snapping fights a manual drag; turn it off until the mouse is released.\n      el.style.scrollSnapType = \"none\";\n    }\n    if (d.moved) el.scrollLeft = d.left - dx;\n  };\n  const endDrag = () => {\n    if (drag.current?.moved) {\n      suppressClick.current = true;\n      if (trackRef.current) trackRef.current.style.scrollSnapType = \"\";\n    }\n    drag.current = null;\n  };\n\n  const activeIndex = Math.max(0, categories.findIndex((c) => c.id === active));\n  const current = categories[activeIndex];\n  const items = products.filter((x) => x.categories.includes(current?.id ?? \"\"));\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const fade = `linear-gradient(90deg, ${edges.start ? \"#000\" : \"transparent\"} 0, #000 48px, #000 calc(100% - 48px), ${edges.end ? \"#000\" : \"transparent\"} 100%)`;\n\n  const arrow = (dir: 1 | -1) => (\n    <button type=\"button\" onClick={() => scrollByPage(dir)} disabled={dir === -1 ? edges.start : edges.end} aria-label={dir === -1 ? \"Scroll categories left\" : \"Scroll categories right\"} className={cn(\"grid h-10 w-10 cursor-pointer place-items-center rounded-full border bg-transparent transition-opacity disabled:cursor-default disabled:opacity-30\", focus)} style={{ borderColor: p.line, color: p.title, ...ring }}>\n      <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" style={{ transform: dir === 1 ? \"rotate(180deg)\" : undefined }}>\n        <path d=\"m15 18-6-6 6-6\" />\n      </svg>\n    </button>\n  );\n\n  return (\n    <section className={cn(\"@container w-full py-12\", className)} style={{ background: p.bg, color: p.title }}>\n      <div className=\"mx-auto max-w-6xl px-4 @[640px]:px-8\">\n        <div className=\"flex items-end justify-between gap-4\">\n          <div>\n            <h2 className=\"m-0 text-[28px] leading-tight font-semibold tracking-[-0.02em] @[640px]:text-[34px]\">{title}</h2>\n            <p className=\"m-0 mt-1.5 text-[14.5px]\" style={{ color: p.body }}>\n              {subtitle}\n            </p>\n          </div>\n          <div className=\"hidden shrink-0 gap-2 @[560px]:flex\">\n            {arrow(-1)}\n            {arrow(1)}\n          </div>\n        </div>\n\n        {/* Track */}\n        <div\n          ref={trackRef}\n          role=\"tablist\"\n          aria-label=\"Categories\"\n          onScroll={measure}\n          onPointerDown={onPointerDown}\n          onPointerMove={onPointerMove}\n          onPointerUp={endDrag}\n          onPointerCancel={endDrag}\n          onClickCapture={(e) => {\n            if (suppressClick.current) {\n              e.stopPropagation();\n              e.preventDefault();\n              suppressClick.current = false;\n            }\n          }}\n          className=\"-mx-4 mt-7 flex snap-x snap-mandatory scroll-px-4 gap-4 overflow-x-auto px-4 pt-2 pb-3 [scrollbar-width:none] select-none @[640px]:-mx-2 @[640px]:scroll-px-2 @[640px]:gap-6 @[640px]:px-2 [&::-webkit-scrollbar]:hidden\"\n          style={{ WebkitMaskImage: fade, maskImage: fade }}\n        >\n          {categories.map((c, i) => {\n            const on = c.id === active;\n            return (\n              <button\n                key={c.id}\n                ref={(el) => {\n                  tabRefs.current[i] = el;\n                }}\n                type=\"button\"\n                role=\"tab\"\n                id={`${uid}-tab-${c.id}`}\n                aria-selected={on}\n                aria-controls={`${uid}-panel`}\n                tabIndex={on ? 0 : -1}\n                onClick={() => select(i)}\n                onKeyDown={(e) => onKey(e, i)}\n                className=\"group flex w-[88px] shrink-0 cursor-pointer snap-start flex-col items-center gap-2.5 border-0 bg-transparent p-0 outline-none @[640px]:w-[112px]\"\n                style={{ color: p.title }}\n              >\n                <span className=\"relative grid h-[88px] w-[88px] place-items-center @[640px]:h-[112px] @[640px]:w-[112px]\">\n                  {on && <motion.span layoutId={`${uid}-ring`} className=\"absolute -inset-[5px] rounded-full border-2\" style={{ borderColor: p.accent }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 34 }} />}\n                  <span className=\"absolute -inset-[5px] rounded-full border-2 border-transparent group-focus-visible:border-[var(--fr)]\" style={{ [\"--fr\" as string]: p.ring }} aria-hidden=\"true\" />\n                  <span className=\"relative h-full w-full overflow-hidden rounded-full transition-transform duration-300 group-hover:scale-[1.04] group-active:scale-[0.97]\" style={{ background: c.image ? p.tile : p.accent }}>\n                    {c.image ? (\n                      // eslint-disable-next-line @next/next/no-img-element\n                      <img src={c.image} alt=\"\" draggable={false} className=\"absolute inset-0 h-full w-full object-contain transition-transform duration-500 group-hover:scale-[1.08]\" style={{ transform: `scale(${c.zoom ?? 1})`, transformOrigin: \"50% 50%\" }} />\n                    ) : (\n                      <span className=\"grid h-full w-full place-items-center text-[22px] font-bold tracking-[-0.03em] @[640px]:text-[26px]\" style={{ color: p.accentText }}>\n                        {c.label}\n                      </span>\n                    )}\n                  </span>\n                  {c.isNew && (\n                    <span className=\"absolute -top-1 -right-1 rounded-full px-1.5 py-0.5 text-[10px] font-bold tracking-[0.04em] uppercase\" style={{ background: p.buttonBg, color: p.buttonText }}>\n                      New\n                    </span>\n                  )}\n                </span>\n                <span className=\"flex flex-col items-center\">\n                  <span className=\"text-[13.5px] font-medium whitespace-nowrap\" style={{ color: on ? p.title : p.body }}>\n                    {c.name}\n                  </span>\n                  <span className=\"text-[11.5px]\" style={{ color: p.muted }}>\n                    {c.count} {c.count === 1 ? \"item\" : \"items\"}\n                  </span>\n                </span>\n              </button>\n            );\n          })}\n        </div>\n\n        {/* Scroll progress */}\n        <div aria-hidden=\"true\" className=\"relative mt-3 h-[3px] overflow-hidden rounded-full\" style={{ background: p.line }}>\n          <motion.span className=\"absolute inset-y-0 rounded-full\" style={{ left: thumbLeft, width: thumbWidth, background: p.title }} />\n        </div>\n\n        {/* Products in the selected category */}\n        <div id={`${uid}-panel`} role=\"tabpanel\" aria-labelledby={`${uid}-tab-${current?.id}`} className=\"mt-9\">\n          <div className=\"flex items-baseline justify-between gap-3\">\n            <p className=\"m-0 text-[15px] font-semibold\" aria-live=\"polite\">\n              {current?.name} <span style={{ color: p.muted }}>· {items.length} {items.length === 1 ? \"product\" : \"products\"}</span>\n            </p>\n            <a href=\"#\" onClick={(e) => e.preventDefault()} className={cn(\"rounded text-[13px] font-medium underline-offset-4 hover:underline\", focus)} style={{ color: p.body, ...ring }}>\n              Shop all {current?.name} →\n            </a>\n          </div>\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            <motion.ul key={current?.id} className=\"m-0 mt-4 grid list-none grid-cols-2 gap-3 p-0 @[760px]:grid-cols-4 @[760px]:gap-4\" initial={reduce ? false : { opacity: 0, y: 14 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -8 }} transition={{ duration: 0.28, ease: [0.22, 1, 0.36, 1] }}>\n              {items.map((x, i) => {\n                const isAdded = added.includes(x.id);\n                return (\n                  <motion.li key={x.id} className=\"overflow-hidden rounded-2xl\" style={{ background: p.card }} initial={reduce ? false : { opacity: 0, y: 12 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: reduce ? 0 : 0.05 * i, duration: 0.3 }}>\n                    <div className=\"relative aspect-[4/3] overflow-hidden\" style={{ background: p.tile }}>\n                      {/* eslint-disable-next-line @next/next/no-img-element */}\n                      <img src={x.image} alt={x.name} className=\"absolute inset-0 h-full w-full object-cover\" />\n                      {x.was && (\n                        <span className=\"absolute top-2.5 left-2.5 rounded-full px-2 py-0.5 text-[11px] font-bold\" style={{ background: p.accent, color: p.accentText }}>\n                          −{Math.round((1 - x.price / x.was) * 100)}%\n                        </span>\n                      )}\n                    </div>\n                    <div className=\"flex items-end justify-between gap-2 p-3.5\">\n                      <div className=\"min-w-0\">\n                        <p className=\"m-0 truncate text-[14px] font-medium\">{x.name}</p>\n                        <p className=\"m-0 mt-0.5 text-[13.5px] tabular-nums\">\n                          {money(x.price, currency)}\n                          {x.was && (\n                            <s className=\"ml-1.5 text-[12.5px]\" style={{ color: p.muted }}>\n                              {money(x.was, currency)}\n                            </s>\n                          )}\n                        </p>\n                      </div>\n                      <motion.button\n                        type=\"button\"\n                        aria-label={isAdded ? `${x.name} added to cart` : `Add ${x.name} to cart`}\n                        aria-pressed={isAdded}\n                        onClick={() => {\n                          if (isAdded) return;\n                          setAdded((a) => [...a, x.id]);\n                          onAdd?.(x);\n                        }}\n                        whileTap={reduce ? undefined : { scale: 0.9 }}\n                        className={cn(\"grid h-9 w-9 shrink-0 cursor-pointer place-items-center rounded-full border-0\", focus)}\n                        style={{ background: isAdded ? p.accent : p.buttonBg, color: isAdded ? p.accentText : p.buttonText, ...ring, [\"--tw-ring-offset-color\" as string]: p.card }}\n                      >\n                        <AnimatePresence mode=\"wait\" initial={false}>\n                          <motion.svg key={isAdded ? \"ok\" : \"plus\"} width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" initial={reduce ? false : { scale: 0.4, rotate: -60, opacity: 0 }} animate={{ scale: 1, rotate: 0, opacity: 1 }} exit={reduce ? undefined : { scale: 0.4, opacity: 0 }} transition={{ duration: 0.18 }}>\n                            <path d={isAdded ? \"m5 12 5 5 9-10\" : \"M12 5v14M5 12h14\"} />\n                          </motion.svg>\n                        </AnimatePresence>\n                      </motion.button>\n                    </div>\n                  </motion.li>\n                );\n              })}\n            </motion.ul>\n          </AnimatePresence>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}