{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "masonry-product-grid",
  "title": "Masonry Product Grid",
  "description": "A Pinterest-style product wall of mixed-height photos with a collection card, customer quotes and a shipping note woven in, category filters that reflow the columns with animation, a Cozy / Compact density switch, wishlist hearts and a hover bar to add to cart.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/masonry-product-grid/masonry-product-grid.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\ntype Ratio = \"1/1\" | \"3/4\" | \"4/5\" | \"2/3\" | \"4/3\" | \"3/2\";\nexport type MasonryTile =\n  | { kind: \"product\"; id: string; name: string; price: number; was?: number; image: string; ratio: Ratio; category: string; focus?: string; tag?: string }\n  | { kind: \"story\"; id: string; ratio: Ratio; kicker: string; title: string; cta: string; category?: string }\n  | { kind: \"quote\"; id: string; ratio: Ratio; quote: string; author: string; product: string; category?: string }\n  | { kind: \"note\"; id: string; ratio: Ratio; title: string; detail: string; category?: string };\n\nexport interface MasonryProductGridProps {\n  title?: string;\n  tiles?: MasonryTile[];\n  categories?: string[];\n  currency?: string;\n  onAdd?: (id: 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\", chip: \"rgba(255,255,255,0.06)\", tile: \"#F1F1F1\", accent: \"#7CDE6A\", accentText: \"#0B1A08\", 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: \"#F4F3EF\", chip: \"rgba(0,0,0,0.05)\", tile: \"#F1F1F1\", accent: \"#2F9E44\", accentText: \"#FFFFFF\", ring: \"rgba(0,0,0,0.45)\" },\n};\n\nconst L = \"/demo/blocks/product-list\";\nconst TILES: MasonryTile[] = [\n  { kind: \"product\", id: \"bottle\", name: \"Insulated Bottle\", price: 39, image: \"/demo/insulated-water-bottle.webp\", ratio: \"2/3\", category: \"Outdoor\", tag: \"Best seller\" },\n  { kind: \"product\", id: \"stand\", name: \"Laptop Stand\", price: 49, was: 89, image: \"/demo/laptop-stand.webp\", ratio: \"4/3\", category: \"Desk\" },\n  { kind: \"story\", id: \"desk-edit\", ratio: \"4/5\", kicker: \"Collection\", title: \"The desk edit\", cta: \"Shop 21 pieces\", category: \"Desk\" },\n  { kind: \"product\", id: \"earbuds\", name: \"Wireless Earbuds\", price: 129, image: \"/demo/wireless-earbuds.webp\", ratio: \"1/1\", category: \"Audio\" },\n  { kind: \"product\", id: \"watch\", name: \"Minimal Watch\", price: 79, was: 129, image: \"/demo/minimal-watch.webp\", ratio: \"3/4\", category: \"Watches\" },\n  { kind: \"quote\", id: \"q1\", ratio: \"1/1\", quote: \"Survived two winters of trail runs and still looks new.\", author: \"Ines, Lisbon\", product: \"Running Shoes\", category: \"Outdoor\" },\n  { kind: \"product\", id: \"shoes\", name: \"Running Shoes\", price: 99, was: 149, image: \"/demo/running-shoes.webp\", ratio: \"4/5\", category: \"Outdoor\", focus: \"40% 50%\" },\n  { kind: \"product\", id: \"notebook\", name: \"Dot Notebook\", price: 24, image: \"/demo/notebook.webp\", ratio: \"3/4\", category: \"Desk\" },\n  { kind: \"product\", id: \"headphones\", name: \"Studio Headphones\", price: 199, image: `${L}/headphones.webp`, ratio: \"1/1\", category: \"Audio\", tag: \"New\" },\n  { kind: \"note\", id: \"ship\", ratio: \"3/2\", title: \"Free shipping over $75\", detail: \"Free returns for 30 days, too.\", category: undefined },\n  { kind: \"product\", id: \"lamp\", name: \"Desk Lamp\", price: 59, image: `${L}/lamp.webp`, ratio: \"2/3\", category: \"Desk\" },\n  { kind: \"product\", id: \"watch-steel\", name: \"Minimal Watch 38mm\", price: 89, image: \"/demo/blocks/product-detail/watch-2.webp\", ratio: \"1/1\", category: \"Watches\" },\n  { kind: \"product\", id: \"backpack\", name: \"Day Backpack\", price: 89, image: `${L}/backpack.webp`, ratio: \"4/5\", category: \"Outdoor\" },\n  { kind: \"quote\", id: \"q2\", ratio: \"4/3\", quote: \"The stand fixed my neck. Not exaggerating.\", author: \"Dev, Leeds\", product: \"Laptop Stand\", category: \"Desk\" },\n];\nconst CATEGORIES = [\"All\", \"Audio\", \"Desk\", \"Outdoor\", \"Watches\"];\n\nconst ratioNum = (r: Ratio) => {\n  const [w, h] = r.split(\"/\").map(Number);\n  return h / w;\n};\n// Greedy masonry: each tile goes to the currently shortest column. Pure, so the server and\n// the browser agree; the column count is picked by container queries, not by measuring.\nfunction columns<T extends { ratio: Ratio }>(items: T[], n: number) {\n  const cols: T[][] = Array.from({ length: n }, () => []);\n  const heights = new Array(n).fill(0);\n  for (const it of items) {\n    const i = heights.indexOf(Math.min(...heights));\n    cols[i].push(it);\n    heights[i] += ratioNum(it.ratio) + 0.06;\n  }\n  return cols;\n}\nconst money = (n: number, c: string) => `${c}${n % 1 ? n.toFixed(2) : n}`;\n\nexport function MasonryProductGrid({ title = \"Fresh finds\", tiles = TILES, categories = CATEGORIES, currency = \"$\", onAdd, theme = \"dark\", className }: MasonryProductGridProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [filter, setFilter] = React.useState(\"All\");\n  const [compact, setCompact] = React.useState(false);\n  const [saved, setSaved] = React.useState<string[]>([\"earbuds\"]);\n  const [added, setAdded] = React.useState<string[]>([]);\n  const sectionRef = React.useRef<HTMLElement>(null);\n  // null until mounted: the first paint uses container queries, then one measured layout takes over.\n  const [width, setWidth] = React.useState<number | null>(null);\n  React.useEffect(() => {\n    const el = sectionRef.current;\n    if (!el) return;\n    // The section is the @container, so measure it (not the padded grid) to match the CSS breakpoints.\n    const ro = new ResizeObserver(([e]) => setWidth(e.borderBoxSize?.[0]?.inlineSize ?? e.contentRect.width));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const shown = tiles.filter((t) => filter === \"All\" || t.category === filter || (t.kind === \"note\" && !t.category));\n  const productCount = shown.filter((t) => t.kind === \"product\").length;\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  // Which layout shows at which container width. Compact adds one column everywhere.\n  const layouts: { n: number; cls: string }[] = compact\n    ? [\n        { n: 3, cls: \"grid @[640px]:hidden\" },\n        { n: 4, cls: \"hidden @[640px]:grid @[960px]:hidden\" },\n        { n: 5, cls: \"hidden @[960px]:grid\" },\n      ]\n    : [\n        { n: 2, cls: \"grid @[640px]:hidden\" },\n        { n: 3, cls: \"hidden @[640px]:grid @[960px]:hidden\" },\n        { n: 4, cls: \"hidden @[960px]:grid\" },\n      ];\n\n  const tile = (t: MasonryTile, layout: number, animated: boolean, small = false) => {\n    const key = `${layout}-${t.id}`;\n    const motionOn = animated && !reduce;\n    const common = motionOn\n      ? { layout: \"position\" as const, layoutId: `${uid}-${layout}-${t.id}`, initial: { opacity: 0, scale: 0.94 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.94 }, transition: { type: \"spring\" as const, stiffness: 240, damping: 30 } }\n      : { initial: false as const };\n    const box = { aspectRatio: t.ratio.replace(\"/\", \" / \") };\n\n    if (t.kind === \"story\")\n      return (\n        <motion.li key={key} {...common} className=\"relative overflow-hidden rounded-2xl\" style={{ ...box, background: p.accent, color: p.accentText }}>\n          <a href=\"#\" onClick={(e) => e.preventDefault()} className={cn(\"group/story flex h-full flex-col justify-between no-underline outline-none focus-visible:ring-2 focus-visible:ring-inset\", small ? \"p-3\" : \"p-4 @[640px]:p-5\")} style={{ color: p.accentText, [\"--tw-ring-color\" as string]: p.accentText }}>\n            <span className={cn(\"text-[11px] font-semibold tracking-[0.14em] uppercase opacity-70\", small && \"text-[9.5px] tracking-[0.1em]\")}>{t.kicker}</span>\n            <span>\n              <span className={cn(\"block leading-[1.02] font-semibold tracking-[-0.03em]\", small ? \"text-[17px]\" : \"text-[26px] @[640px]:text-[32px]\")}>{t.title}</span>\n              <span className={cn(\"mt-3 inline-flex items-center gap-1.5 text-[13px] font-semibold\", small && \"mt-2 text-[11.5px]\")}>\n                {small ? \"Shop\" : t.cta}\n                <span className=\"transition-transform duration-300 group-hover/story:translate-x-1\" aria-hidden=\"true\">\n                  →\n                </span>\n              </span>\n            </span>\n          </a>\n        </motion.li>\n      );\n    if (t.kind === \"quote\")\n      return (\n        <motion.li key={key} {...common} className={cn(\"relative flex flex-col justify-between overflow-hidden rounded-2xl border\", small ? \"p-3\" : \"p-4 @[640px]:p-5\")} style={{ ...box, background: p.card, borderColor: p.line }}>\n          <span className={cn(\"font-serif leading-none\", small ? \"hidden\" : \"text-[40px]\")} style={{ color: p.accent }} aria-hidden=\"true\">\n            “\n          </span>\n          <figure className=\"m-0\">\n            <blockquote className={cn(\"m-0 leading-snug font-medium\", small ? \"line-clamp-3 text-[11.5px]\" : \"text-[15px] @[640px]:text-[16.5px]\")}>{t.quote}</blockquote>\n            <figcaption className={cn(\"mt-3 text-[12px]\", small && \"sr-only\")} style={{ color: p.muted }}>\n              {t.author} · on {t.product}\n            </figcaption>\n          </figure>\n        </motion.li>\n      );\n    if (t.kind === \"note\")\n      return (\n        <motion.li key={key} {...common} className={cn(\"relative flex flex-col justify-end overflow-hidden rounded-2xl border border-dashed\", small ? \"p-3\" : \"p-4 @[640px]:p-5\")} style={{ ...box, borderColor: p.line }}>\n          <svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" style={{ color: p.accent }}>\n            <path d=\"M3 7h11v9H3zM14 10h4l3 3v3h-7M7 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM17 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4z\" />\n          </svg>\n          <span className={cn(\"mt-2 font-semibold\", small ? \"text-[12px] leading-tight\" : \"text-[15px]\")}>{t.title}</span>\n          <span className={cn(\"mt-0.5 text-[12.5px]\", small && \"sr-only\")} style={{ color: p.body }}>\n            {t.detail}\n          </span>\n        </motion.li>\n      );\n\n    const isSaved = saved.includes(t.id);\n    const isAdded = added.includes(t.id);\n    return (\n      <motion.li key={key} {...common} className=\"group relative overflow-hidden rounded-2xl\" style={{ ...box, background: p.tile }}>\n        {/* eslint-disable-next-line @next/next/no-img-element */}\n        <img src={t.image} alt={t.name} loading=\"lazy\" className=\"absolute inset-0 h-full w-full object-cover transition-transform duration-700 ease-[cubic-bezier(0.22,1,0.36,1)] group-hover:scale-[1.05]\" style={{ objectPosition: t.focus ?? \"50% 50%\" }} />\n        {t.tag && (\n          <span className=\"absolute top-2.5 left-2.5 rounded-full px-2 py-0.5 text-[10.5px] font-bold tracking-[0.04em] uppercase\" style={{ background: \"#111111\", color: \"#FFFFFF\" }}>\n            {t.tag}\n          </span>\n        )}\n        <motion.button\n          type=\"button\"\n          aria-label={isSaved ? `Remove ${t.name} from wishlist` : `Save ${t.name} to wishlist`}\n          aria-pressed={isSaved}\n          onClick={() => setSaved((s) => (isSaved ? s.filter((x) => x !== t.id) : [...s, t.id]))}\n          whileTap={reduce ? undefined : { scale: 0.85 }}\n          className={cn(\"absolute z-10 grid cursor-pointer place-items-center rounded-full border-0 outline-none focus-visible:ring-2\", small ? \"top-1.5 right-1.5 h-7 w-7\" : \"top-2.5 right-2.5 h-8 w-8\")}\n          style={{ background: \"rgba(255,255,255,0.88)\", color: isSaved ? \"#E5484D\" : \"#111111\", [\"--tw-ring-color\" as string]: \"#111111\" }}\n        >\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill={isSaved ? \"currentColor\" : \"none\"} stroke=\"currentColor\" strokeWidth=\"2\" strokeLinejoin=\"round\" aria-hidden=\"true\">\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          </svg>\n        </motion.button>\n        {/* Price pill at rest, full bar on hover / focus */}\n        <span className=\"pointer-events-none absolute bottom-2 left-2 rounded-full px-2 py-0.5 text-[11.5px] font-semibold tabular-nums transition-opacity duration-200 group-focus-within:opacity-0 group-hover:opacity-0\" style={{ background: \"rgba(255,255,255,0.92)\", color: \"#111111\" }}>\n          {money(t.price, currency)}\n          {t.was && <s className=\"ml-1 font-normal opacity-50\">{money(t.was, currency)}</s>}\n        </span>\n        <div className=\"absolute inset-x-2 bottom-2 flex translate-y-3 items-center gap-2 rounded-xl p-2 pl-3 opacity-0 backdrop-blur-md transition-all duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] group-focus-within:translate-y-0 group-focus-within:opacity-100 group-hover:translate-y-0 group-hover:opacity-100\" style={{ background: \"rgba(17,17,17,0.82)\", color: \"#FFFFFF\" }}>\n          <span className=\"min-w-0 flex-1\">\n            <span className=\"block truncate text-[13px] font-medium\">{t.name}</span>\n            <span className=\"block text-[12px] tabular-nums opacity-70\">\n              {money(t.price, currency)}\n              {t.was && <s className=\"ml-1\">{money(t.was, currency)}</s>}\n            </span>\n          </span>\n          <button\n            type=\"button\"\n            aria-label={isAdded ? `${t.name} added to cart` : `Add ${t.name} to cart`}\n            onClick={() => {\n              if (isAdded) return;\n              setAdded((a) => [...a, t.id]);\n              onAdd?.(t.id);\n            }}\n            className=\"grid h-8 w-8 shrink-0 cursor-pointer place-items-center rounded-lg border-0 outline-none focus-visible:ring-2\"\n            style={{ background: isAdded ? p.accent : \"#FFFFFF\", color: isAdded ? p.accentText : \"#111111\", [\"--tw-ring-color\" as string]: \"#FFFFFF\" }}\n          >\n            <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d={isAdded ? \"m5 12 5 5 9-10\" : \"M12 5v14M5 12h14\"} />\n            </svg>\n          </button>\n        </div>\n      </motion.li>\n    );\n  };\n\n  return (\n    <section ref={sectionRef} 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-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-[14px] tabular-nums\" style={{ color: p.body }} aria-live=\"polite\">\n              {productCount} products{filter !== \"All\" ? ` in ${filter}` : \"\"}\n            </p>\n          </div>\n          <div role=\"radiogroup\" aria-label=\"Grid density\" className=\"flex rounded-full border p-0.5\" style={{ borderColor: p.line }}>\n            {[\n              { v: false, label: \"Cozy\", icon: \"M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z\" },\n              { v: true, label: \"Compact\", icon: \"M3 3h5v5H3zM9.5 3h5v5h-5zM16 3h5v5h-5zM3 9.5h5v5H3zM9.5 9.5h5v5h-5zM16 9.5h5v5h-5zM3 16h5v5H3zM9.5 16h5v5h-5zM16 16h5v5h-5z\" },\n            ].map((o) => {\n              const on = compact === o.v;\n              return (\n                <button key={o.label} type=\"button\" role=\"radio\" aria-checked={on} aria-label={o.label} onClick={() => setCompact(o.v)} className=\"relative grid h-8 w-10 cursor-pointer place-items-center rounded-full border-0 bg-transparent outline-none focus-visible:ring-2\" style={{ color: on ? p.bg : p.body, ...ring }}>\n                  {on && <motion.span layoutId={`${uid}-density`} className=\"absolute inset-0 rounded-full\" style={{ background: p.title }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 38 }} />}\n                  <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\" className=\"relative\">\n                    <path d={o.icon} />\n                  </svg>\n                </button>\n              );\n            })}\n          </div>\n        </div>\n\n        <div className=\"mt-5 flex gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\" role=\"radiogroup\" aria-label=\"Filter by category\">\n          {categories.map((c) => {\n            const on = c === filter;\n            return (\n              <button key={c} type=\"button\" role=\"radio\" aria-checked={on} onClick={() => setFilter(c)} className={cn(\"relative h-9 shrink-0 cursor-pointer rounded-full border-0 px-4 text-[13px] font-medium\", focus)} style={{ background: on ? \"transparent\" : p.chip, color: on ? p.bg : p.body, ...ring }}>\n                {on && <motion.span layoutId={`${uid}-filter`} className=\"absolute inset-0 rounded-full\" style={{ background: p.title }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 480, damping: 36 }} />}\n                <span className=\"relative\">{c}</span>\n              </button>\n            );\n          })}\n        </div>\n\n        <div className=\"mt-6\">\n          {width === null ? (\n            // Server render and first paint: every column count, one shown per container width.\n            layouts.map(({ n, cls }) => (\n              <div key={n} className={cn(\"items-start gap-3 @[640px]:gap-4\", cls)} style={{ gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))` }}>\n                {columns(shown, n).map((col, ci) => (\n                  <ul key={ci} className=\"m-0 flex list-none flex-col gap-3 p-0 @[640px]:gap-4\">\n                    {col.map((t) => tile(t, n, false))}\n                  </ul>\n                ))}\n              </div>\n            ))\n          ) : (\n            <LayoutGroup id={uid}>\n              {(() => {\n                const n = (width >= 960 ? 4 : width >= 640 ? 3 : 2) + (compact ? 1 : 0);\n                // Narrow columns get the compact text tiles.\n                const small = (width - (width >= 640 ? 64 : 32)) / n < 170;\n                return (\n                  <div className=\"grid items-start gap-3 @[640px]:gap-4\" style={{ gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))` }}>\n                    {columns(shown, n).map((col, ci) => (\n                      <ul key={ci} className=\"m-0 flex list-none flex-col gap-3 p-0 @[640px]:gap-4\">\n                        <AnimatePresence mode=\"popLayout\" initial={false}>\n                          {col.map((t) => tile(t, 0, true, small))}\n                        </AnimatePresence>\n                      </ul>\n                    ))}\n                  </div>\n                );\n              })()}\n            </LayoutGroup>\n          )}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}