{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabbed-product-list",
  "title": "Tabbed Product List",
  "description": "A product grid with Best sellers, New arrivals, On sale and Top rated tabs: each tab sorts the products its own way and shows its own badge and detail line, cards reshuffle into place when you switch, with a hover quick add bar, a wishlist heart and Show more.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/tabbed-product-list/tabbed-product-list.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, LayoutGroup, motion, 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 interface TabbedProduct {\n  id: string;\n  name: string;\n  price: number;\n  was?: number;\n  image: string;\n  rating: number;\n  reviews: number;\n  sold: number;\n  /** Days since it was added to the store. */\n  addedDays: number;\n}\ntype TabId = \"best\" | \"new\" | \"sale\" | \"rated\";\n\nexport interface TabbedProductListProps {\n  title?: string;\n  products?: TabbedProduct[];\n  defaultTab?: TabId;\n  /** How many products show before \"Show more\". */\n  initial?: number;\n  currency?: string;\n  onAdd?: (product: TabbedProduct) => void;\n  onWishlist?: (product: TabbedProduct, saved: boolean) => 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)\", tile: \"#F1F1F1\", accent: \"#7CDE6A\", accentText: \"#0B1A08\", star: \"#F5C451\", 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)\", tile: \"#F1F1F1\", accent: \"#2F9E44\", accentText: \"#FFFFFF\", star: \"#E0A100\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", ring: \"rgba(0,0,0,0.45)\" },\n};\n\nconst L = \"/demo/blocks/product-list\";\nconst PRODUCTS: TabbedProduct[] = [\n  { id: \"earbuds\", name: \"Wireless Earbuds\", price: 129, image: \"/demo/wireless-earbuds.webp\", rating: 4.7, reviews: 412, sold: 1840, addedDays: 64 },\n  { id: \"watch\", name: \"Minimal Watch\", price: 79, was: 129, image: \"/demo/minimal-watch.webp\", rating: 4.8, reviews: 268, sold: 1210, addedDays: 120 },\n  { id: \"stand\", name: \"Laptop Stand\", price: 49, was: 89, image: \"/demo/laptop-stand.webp\", rating: 4.6, reviews: 530, sold: 2030, addedDays: 210 },\n  { id: \"shoes\", name: \"Running Shoes\", price: 99, was: 149, image: \"/demo/running-shoes.webp\", rating: 4.5, reviews: 187, sold: 640, addedDays: 9 },\n  { id: \"bottle\", name: \"Insulated Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\", rating: 4.9, reviews: 903, sold: 2890, addedDays: 300 },\n  { id: \"notebook\", name: \"Dot Notebook\", price: 24, image: \"/demo/notebook.webp\", rating: 4.8, reviews: 341, sold: 1520, addedDays: 2 },\n  { id: \"headphones\", name: \"Studio Headphones\", price: 199, image: `${L}/headphones.webp`, rating: 4.6, reviews: 154, sold: 420, addedDays: 5 },\n  { id: \"lamp\", name: \"Desk Lamp\", price: 59, was: 75, image: `${L}/lamp.webp`, rating: 4.4, reviews: 96, sold: 310, addedDays: 14 },\n  { id: \"backpack\", name: \"Day Backpack\", price: 89, image: `${L}/backpack.webp`, rating: 4.7, reviews: 219, sold: 870, addedDays: 3 },\n];\n\nconst TABS: { id: TabId; label: string; pick: (list: TabbedProduct[]) => TabbedProduct[] }[] = [\n  { id: \"best\", label: \"Best sellers\", pick: (l) => [...l].sort((a, b) => b.sold - a.sold) },\n  { id: \"new\", label: \"New arrivals\", pick: (l) => l.filter((x) => x.addedDays <= 30).sort((a, b) => a.addedDays - b.addedDays) },\n  { id: \"sale\", label: \"On sale\", pick: (l) => l.filter((x) => x.was).sort((a, b) => (b.was! - b.price) / b.was! - (a.was! - a.price) / a.was!) },\n  { id: \"rated\", label: \"Top rated\", pick: (l) => [...l].sort((a, b) => b.rating - a.rating || b.reviews - a.reviews) },\n];\n\nconst money = (n: number, c: string) => `${c}${n.toFixed(2)}`;\nconst compact = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(1).replace(/\\.0$/, \"\")}k` : String(n));\nconst ago = (d: number) => (d <= 1 ? \"Added today\" : d < 7 ? `Added ${d} days ago` : d < 14 ? \"Added last week\" : `Added ${Math.round(d / 7)} weeks ago`);\n\nfunction Stars({ value, color, empty }: { value: number; color: string; empty: string }) {\n  const id = React.useId();\n  return (\n    <span className=\"relative inline-flex\" aria-hidden=\"true\">\n      {[0, 1, 2, 3, 4].map((i) => {\n        const fill = Math.max(0, Math.min(1, value - i));\n        return (\n          <svg key={i} width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" className=\"shrink-0\">\n            <defs>\n              <linearGradient id={`${id}-${i}`}>\n                <stop offset={`${fill * 100}%`} stopColor={color} />\n                <stop offset={`${fill * 100}%`} stopColor={empty} />\n              </linearGradient>\n            </defs>\n            <path d=\"m12 2.8 2.8 5.8 6.3.9-4.6 4.4 1.1 6.3L12 17.2l-5.6 3 1.1-6.3-4.6-4.4 6.3-.9z\" fill={`url(#${id}-${i})`} />\n          </svg>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function TabbedProductList({ title = \"Shop the range\", products = PRODUCTS, defaultTab = \"best\", initial = 4, currency = \"$\", onAdd, onWishlist, theme = \"dark\", className }: TabbedProductListProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const tabRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const [tab, setTab] = React.useState<TabId>(defaultTab);\n  const [expanded, setExpanded] = React.useState(false);\n  const [added, setAdded] = React.useState<string[]>([]);\n  const [saved, setSaved] = React.useState<string[]>([\"bottle\"]);\n  const lists = React.useMemo(() => Object.fromEntries(TABS.map((t) => [t.id, t.pick(products)])) as Record<TabId, TabbedProduct[]>, [products]);\n  const list = lists[tab];\n  const visible = expanded ? list : list.slice(0, initial);\n\n  const choose = (id: TabId, focus = false) => {\n    setTab(id);\n    setExpanded(false);\n    if (focus) tabRefs.current[TABS.findIndex((t) => t.id === id)]?.focus();\n  };\n  const onKey = (e: React.KeyboardEvent, i: number) => {\n    const to = e.key === \"ArrowRight\" ? (i + 1) % TABS.length : e.key === \"ArrowLeft\" ? (i - 1 + TABS.length) % TABS.length : e.key === \"Home\" ? 0 : e.key === \"End\" ? TABS.length - 1 : null;\n    if (to === null) return;\n    e.preventDefault();\n    choose(TABS[to].id, true);\n  };\n\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\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 flex-wrap items-end justify-between gap-x-6 gap-y-4\">\n          <h2 className=\"m-0 text-[28px] leading-tight font-semibold tracking-[-0.02em] @[640px]:text-[34px]\">{title}</h2>\n          <a href=\"#\" onClick={(e) => e.preventDefault()} className={cn(\"rounded text-[13.5px] font-medium underline-offset-4 hover:underline\", focus)} style={{ color: p.body, ...ring }}>\n            View all products →\n          </a>\n        </div>\n\n        {/* Tabs */}\n        <div className=\"mt-6 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\">\n          <div role=\"tablist\" aria-label=\"Product lists\" className=\"flex min-w-max gap-1 border-b\" style={{ borderColor: p.line }}>\n            {TABS.map((t, i) => {\n              const on = t.id === tab;\n              return (\n                <button\n                  key={t.id}\n                  ref={(el) => {\n                    tabRefs.current[i] = el;\n                  }}\n                  type=\"button\"\n                  role=\"tab\"\n                  id={`${uid}-tab-${t.id}`}\n                  aria-selected={on}\n                  aria-controls={`${uid}-panel`}\n                  tabIndex={on ? 0 : -1}\n                  onClick={() => choose(t.id)}\n                  onKeyDown={(e) => onKey(e, i)}\n                  className=\"relative flex h-12 cursor-pointer items-center gap-2 border-0 bg-transparent px-3 text-[14px] font-medium whitespace-nowrap outline-none focus-visible:ring-2 focus-visible:ring-inset @[640px]:px-4\"\n                  style={{ color: on ? p.title : p.muted, [\"--tw-ring-color\" as string]: p.ring }}\n                >\n                  {t.label}\n                  <span className=\"rounded-full px-1.5 py-px text-[11px] tabular-nums\" style={{ background: on ? p.title : p.line, color: on ? p.bg : p.body }}>\n                    {lists[t.id].length}\n                  </span>\n                  {on && <motion.span layoutId={`${uid}-tab`} className=\"absolute inset-x-2 -bottom-px h-[2px] rounded-full\" style={{ background: p.title }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 480, damping: 38 }} />}\n                </button>\n              );\n            })}\n          </div>\n        </div>\n\n        {/* Grid */}\n        <div id={`${uid}-panel`} role=\"tabpanel\" aria-labelledby={`${uid}-tab-${tab}`} className=\"mt-6\">\n          <p className=\"sr-only\" aria-live=\"polite\">\n            {TABS.find((t) => t.id === tab)?.label}: showing {visible.length} of {list.length}\n          </p>\n          <LayoutGroup id={uid}>\n            <ul className=\"m-0 grid list-none grid-cols-2 gap-x-3 gap-y-7 p-0 @[760px]:grid-cols-4 @[760px]:gap-x-4\">\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                {visible.map((x, i) => {\n                  const isAdded = added.includes(x.id);\n                  const isSaved = saved.includes(x.id);\n                  const off = x.was ? Math.round((1 - x.price / x.was) * 100) : 0;\n                  return (\n                    <motion.li\n                      key={x.id}\n                      layout={reduce ? false : \"position\"}\n                      initial={reduce ? false : { opacity: 0, y: 16, scale: 0.98 }}\n                      animate={{ opacity: 1, y: 0, scale: 1 }}\n                      exit={reduce ? undefined : { opacity: 0, scale: 0.96 }}\n                      transition={{ type: \"spring\", stiffness: 260, damping: 30, delay: reduce ? 0 : Math.min(i, 8) * 0.035 }}\n                      className=\"group min-w-0\"\n                    >\n                      <div className=\"relative aspect-[4/5] overflow-hidden rounded-2xl\" 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 transition-transform duration-500 group-hover:scale-[1.04]\" />\n                        {/* Per-tab badge */}\n                        <span className=\"absolute top-3 left-3\">\n                          {tab === \"best\" && (\n                            <span className=\"grid h-7 min-w-7 place-items-center rounded-full px-2 font-mono text-[12px] font-bold\" style={{ background: \"#111111\", color: \"#FFFFFF\" }}>\n                              #{list.indexOf(x) + 1}\n                            </span>\n                          )}\n                          {tab === \"new\" && (\n                            <span className=\"rounded-full px-2.5 py-1 text-[11px] font-bold tracking-[0.06em] uppercase\" style={{ background: \"#111111\", color: \"#FFFFFF\" }}>\n                              New\n                            </span>\n                          )}\n                          {tab === \"sale\" && off > 0 && (\n                            <span className=\"rounded-full px-2.5 py-1 text-[11px] font-bold\" style={{ background: p.accent, color: p.accentText }}>\n                              −{off}%\n                            </span>\n                          )}\n                        </span>\n                        <motion.button\n                          type=\"button\"\n                          aria-label={isSaved ? `Remove ${x.name} from wishlist` : `Save ${x.name} to wishlist`}\n                          aria-pressed={isSaved}\n                          onClick={() => {\n                            setSaved((s) => (isSaved ? s.filter((y) => y !== x.id) : [...s, x.id]));\n                            onWishlist?.(x, !isSaved);\n                          }}\n                          whileTap={reduce ? undefined : { scale: 0.85 }}\n                          className=\"absolute top-3 right-3 grid h-8 w-8 cursor-pointer place-items-center rounded-full border-0 outline-none focus-visible:ring-2\"\n                          style={{ background: \"rgba(255,255,255,0.85)\", color: isSaved ? \"#E5484D\" : \"#111111\", [\"--tw-ring-color\" as string]: \"#111111\" }}\n                        >\n                          <motion.svg key={String(isSaved)} width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill={isSaved ? \"currentColor\" : \"none\"} stroke=\"currentColor\" strokeWidth=\"2\" strokeLinejoin=\"round\" aria-hidden=\"true\" initial={reduce || !isSaved ? false : { scale: 0.4 }} animate={{ scale: 1 }} transition={{ type: \"spring\", stiffness: 600, damping: 14 }}>\n                            <path d=\"M12 20s-7.5-4.6-7.5-10A4.3 4.3 0 0 1 12 7.6 4.3 4.3 0 0 1 19.5 10c0 5.4-7.5 10-7.5 10Z\" />\n                          </motion.svg>\n                        </motion.button>\n                        {/* Quick add slides up on hover; always visible on touch screens */}\n                        <div className=\"absolute inset-x-3 bottom-3 translate-y-[calc(100%+12px)] transition-transform duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] group-focus-within:translate-y-0 group-hover:translate-y-0 [@media(hover:none)]:translate-y-0\">\n                          <button\n                            type=\"button\"\n                            onClick={() => {\n                              if (isAdded) return;\n                              setAdded((a) => [...a, x.id]);\n                              onAdd?.(x);\n                            }}\n                            aria-label={isAdded ? `${x.name} added to cart` : `Add ${x.name} to cart`}\n                            className=\"flex h-10 w-full cursor-pointer items-center justify-center gap-2 rounded-xl border-0 text-[13px] font-semibold outline-none focus-visible:ring-2\"\n                            style={{ background: isAdded ? p.accent : \"#111111\", color: isAdded ? p.accentText : \"#FFFFFF\", [\"--tw-ring-color\" as string]: \"#FFFFFF\" }}\n                          >\n                            <AnimatePresence mode=\"wait\" initial={false}>\n                              <motion.span key={String(isAdded)} className=\"flex items-center gap-2\" initial={reduce ? false : { y: 10, opacity: 0 }} animate={{ y: 0, opacity: 1 }} exit={reduce ? undefined : { y: -10, opacity: 0 }} transition={{ duration: 0.16 }}>\n                                {isAdded ? (\n                                  <>\n                                    <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                                      <path d=\"m5 12 5 5 9-10\" />\n                                    </svg>\n                                    Added\n                                  </>\n                                ) : (\n                                  <>Quick add · {money(x.price, currency)}</>\n                                )}\n                              </motion.span>\n                            </AnimatePresence>\n                          </button>\n                        </div>\n                      </div>\n                      <div className=\"mt-3 px-0.5\">\n                        <p className=\"m-0 truncate text-[14.5px] font-medium\">{x.name}</p>\n                        <p className=\"m-0 mt-1 text-[14px] tabular-nums\">\n                          {money(x.price, currency)}\n                          {x.was && (\n                            <s className=\"ml-1.5 text-[13px]\" style={{ color: p.muted }}>\n                              {money(x.was, currency)}\n                            </s>\n                          )}\n                        </p>\n                        {/* Per-tab detail line */}\n                        <p className=\"m-0 mt-1.5 flex items-center gap-1.5 text-[12.5px]\" style={{ color: p.body }}>\n                          {tab === \"best\" && <>{compact(x.sold)} sold this year</>}\n                          {tab === \"new\" && <>{ago(x.addedDays)}</>}\n                          {tab === \"sale\" && x.was && (\n                            <span style={{ color: p.accent }}>\n                              You save {money(x.was - x.price, currency)}\n                            </span>\n                          )}\n                          {tab === \"rated\" && (\n                            <>\n                              <Stars value={x.rating} color={p.star} empty={p.line} />\n                              <span className=\"tabular-nums\">\n                                {x.rating.toFixed(1)} · {x.reviews} reviews\n                              </span>\n                            </>\n                          )}\n                        </p>\n                      </div>\n                    </motion.li>\n                  );\n                })}\n              </AnimatePresence>\n            </ul>\n          </LayoutGroup>\n\n          {list.length > initial && (\n            <div className=\"mt-8 flex flex-col items-center gap-3\">\n              <span className=\"text-[12.5px] tabular-nums\" style={{ color: p.muted }}>\n                Showing {visible.length} of {list.length}\n              </span>\n              <span className=\"h-[3px] w-40 overflow-hidden rounded-full\" style={{ background: p.line }} aria-hidden=\"true\">\n                <motion.span className=\"block h-full rounded-full\" style={{ background: p.title }} initial={false} animate={{ width: `${(visible.length / list.length) * 100}%` }} transition={{ duration: reduce ? 0 : 0.4 }} />\n              </span>\n              <button type=\"button\" onClick={() => setExpanded((e) => !e)} aria-expanded={expanded} aria-controls={`${uid}-panel`} className={cn(\"mt-1 h-11 cursor-pointer rounded-full border bg-transparent px-6 text-[14px] font-medium\", focus)} style={{ borderColor: p.line, color: p.title, ...ring }}>\n                {expanded ? \"Show less\" : `Show ${list.length - initial} more`}\n              </button>\n            </div>\n          )}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}