{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "product-quick-view-block",
  "title": "Product Quick View Block",
  "description": "A product grid with quick view: hover a card for a 'Quick view' button that opens a dialog with an image gallery, rating, price, color and size choices, quantity and add to cart, plus previous / next to browse the grid without closing it.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/product-quick-view-block/product-quick-view-block.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, 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 QuickViewProduct {\n  id: string;\n  title: string;\n  category: string;\n  price: number;\n  compareAtPrice?: number;\n  rating: number;\n  reviews: number;\n  description: string;\n  images: string[];\n  colors?: { name: string; hex: string }[];\n  sizes?: string[];\n}\n\nexport interface ProductQuickViewBlockProps {\n  title?: string;\n  products?: QuickViewProduct[];\n  currency?: string;\n  /** Return a Promise to keep the dialog button busy until the cart updates. */\n  onAddToCart?: (item: { product: QuickViewProduct; color?: string; size?: string; quantity: number }) => void | Promise<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)\", panel: \"#141414\", photo: \"#F1F1F1\", scrim: \"rgba(0,0,0,0.65)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", sale: \"#FF6B57\", ring: \"rgba(255,255,255,0.5)\" },\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)\", panel: \"#FFFFFF\", photo: \"#F1F1F1\", scrim: \"rgba(10,10,10,0.45)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", sale: \"#D9480F\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst PRODUCTS: QuickViewProduct[] = [\n  { id: \"watch\", title: \"Minimal Watch\", category: \"Accessories\", price: 79, compareAtPrice: 129, rating: 4.9, reviews: 864, description: \"A slim matte-black case on a soft leather strap. Japanese quartz, 3 ATM, and nothing on the dial you don't need.\", images: [\"/demo/blocks/product-detail/watch-1.webp\", \"/demo/blocks/product-detail/watch-2.webp\", \"/demo/blocks/product-detail/watch-3.webp\", \"/demo/blocks/product-detail/watch-4.webp\"], colors: [{ name: \"Black\", hex: \"#1A1A1A\" }, { name: \"Silver\", hex: \"#C9CBCF\" }, { name: \"Olive\", hex: \"#5E6B4E\" }], sizes: [\"36mm\", \"40mm\", \"42mm\"] },\n  { id: \"earbuds\", title: \"Wireless Earbuds\", category: \"Audio\", price: 129, rating: 4.8, reviews: 1846, description: \"Noise cancelling buds with 8 hours per charge and 30 with the pocket case. IPX4, so rain and runs are fine.\", images: [\"/demo/wireless-earbuds.webp\"], colors: [{ name: \"Black\", hex: \"#1A1A1A\" }, { name: \"Stone\", hex: \"#D8D3CB\" }] },\n  { id: \"shoes\", title: \"Running Shoes\", category: \"Running\", price: 99, compareAtPrice: 149, rating: 4.6, reviews: 640, description: \"Light mesh uppers, a responsive foam midsole and a grippy outsole for road and track.\", images: [\"/demo/running-shoes.webp\"], sizes: [\"40\", \"41\", \"42\", \"43\", \"44\", \"45\"] },\n  { id: \"bottle\", title: \"Insulated Water Bottle\", category: \"Drinkware\", price: 39, rating: 4.8, reviews: 2210, description: \"Keeps drinks cold for 24 hours or hot for 12. Powder-coated steel with a leak-proof loop cap.\", images: [\"/demo/insulated-water-bottle.webp\"], sizes: [\"500 ml\", \"750 ml\"] },\n];\n\nexport function ProductQuickViewBlock({ title = \"New this week\", products = PRODUCTS, currency = \"$\", onAddToCart, theme = \"dark\", className }: ProductQuickViewBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [openIndex, setOpenIndex] = React.useState<number | null>(null);\n  const [dir, setDir] = React.useState(1);\n  const [img, setImg] = React.useState(0);\n  const [color, setColor] = React.useState<string | undefined>();\n  const [size, setSize] = React.useState<string | undefined>();\n  const [qty, setQty] = React.useState(1);\n  const [state, setState] = React.useState<\"idle\" | \"loading\" | \"added\">(\"idle\");\n  const triggers = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const dialogRef = React.useRef<HTMLDivElement>(null);\n  const focusOnce = React.useCallback((el: HTMLButtonElement | null) => el?.focus({ preventScroll: true }), []);\n  const product = openIndex !== null ? products[openIndex] : null;\n  const money = (n: number) => `${currency}${n.toFixed(2)}`;\n\n  const show = React.useCallback(\n    (i: number, d = 1) => {\n      const pr = products[i];\n      setDir(d);\n      setOpenIndex(i);\n      setImg(0);\n      setColor(pr.colors?.[0]?.name);\n      setSize(pr.sizes?.[Math.floor((pr.sizes.length - 1) / 2)]);\n      setQty(1);\n      setState(\"idle\");\n    },\n    [products],\n  );\n  const close = React.useCallback(() => {\n    const i = openIndex;\n    setOpenIndex(null);\n    if (i !== null) setTimeout(() => triggers.current[i]?.focus(), 0);\n  }, [openIndex]);\n\n  React.useEffect(() => {\n    if (openIndex === null) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") close();\n      if (e.key === \"Tab\" && dialogRef.current) {\n        const f = dialogRef.current.querySelectorAll<HTMLElement>(\"button:not([disabled]), a[href], input\");\n        if (!f.length) return;\n        const first = f[0];\n        const last = f[f.length - 1];\n        if (e.shiftKey && document.activeElement === first) {\n          e.preventDefault();\n          last.focus();\n        } else if (!e.shiftKey && document.activeElement === last) {\n          e.preventDefault();\n          first.focus();\n        }\n      }\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [openIndex, close]);\n  React.useEffect(() => {\n    if (state !== \"added\") return;\n    const t = setTimeout(() => setState(\"idle\"), 2200);\n    return () => clearTimeout(t);\n  }, [state]);\n\n  const add = async () => {\n    if (!product || state === \"loading\") return;\n    setState(\"loading\");\n    try {\n      await (onAddToCart ? onAddToCart({ product, color, size, quantity: qty }) : new Promise((r) => setTimeout(r, reduce ? 0 : 650)));\n      setState(\"added\");\n    } catch {\n      setState(\"idle\");\n    }\n  };\n  const step = (d: 1 | -1) => openIndex !== null && show((openIndex + d + products.length) % products.length, d);\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.panel } 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 relative w-full\", className)} style={{ background: p.bg, color: p.title }}>\n      <div className=\"mx-auto max-w-6xl px-4 py-12 @[640px]:px-8\">\n        <h2 className=\"m-0 text-[28px] font-semibold tracking-[-0.03em] @[640px]:text-[34px]\">{title}</h2>\n        <ul className=\"m-0 mt-6 grid list-none grid-cols-2 gap-4 p-0 @[860px]:grid-cols-4\">\n          {products.map((pr, i) => (\n            <li key={pr.id} className=\"group min-w-0\">\n              <div className=\"relative aspect-[4/5] overflow-hidden rounded-2xl\" style={{ background: p.photo }}>\n                {/* eslint-disable-next-line @next/next/no-img-element */}\n                <img src={pr.images[0]} alt={pr.title} className=\"h-full w-full object-cover transition-transform duration-500 group-hover:scale-105\" />\n                {pr.compareAtPrice && (\n                  <span className=\"absolute top-3 left-3 rounded-full px-2.5 py-1 text-[11px] font-semibold text-white\" style={{ background: p.sale }}>\n                    −{Math.round((1 - pr.price / pr.compareAtPrice) * 100)}%\n                  </span>\n                )}\n                <button\n                  ref={(el) => {\n                    triggers.current[i] = el;\n                  }}\n                  type=\"button\"\n                  onClick={() => show(i)}\n                  aria-haspopup=\"dialog\"\n                  className={cn(\"absolute right-3 bottom-3 left-3 flex h-10 cursor-pointer items-center justify-center gap-2 rounded-full border-0 bg-white/95 text-[13px] font-semibold text-[#111] shadow-lg backdrop-blur transition-all duration-300 @[860px]:translate-y-3 @[860px]:opacity-0 @[860px]:group-focus-within:translate-y-0 @[860px]:group-focus-within:opacity-100 @[860px]:group-hover:translate-y-0 @[860px]:group-hover:opacity-100\", focus)}\n                  style={ring}\n                >\n                  <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                    <path d=\"M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12Z\" />\n                    <circle cx=\"12\" cy=\"12\" r=\"3\" />\n                  </svg>\n                  Quick view\n                </button>\n              </div>\n              <p className=\"m-0 mt-3 text-[12px]\" style={{ color: p.muted }}>\n                {pr.category}\n              </p>\n              <div className=\"mt-0.5 flex items-baseline justify-between gap-2\">\n                <span className=\"truncate text-[14px] font-medium\">{pr.title}</span>\n                <span className=\"shrink-0 text-[14px] font-semibold tabular-nums\">{money(pr.price)}</span>\n              </div>\n            </li>\n          ))}\n        </ul>\n      </div>\n\n      <AnimatePresence>\n        {product && (\n          <motion.div key=\"scrim\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} className=\"absolute inset-0 z-20 flex items-start justify-center overflow-y-auto px-3 py-4 @[640px]:py-6\" style={{ background: p.scrim }} onMouseDown={(e) => e.target === e.currentTarget && close()}>\n            <motion.div\n              ref={dialogRef}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-t`}\n              initial={reduce ? false : { opacity: 0, y: 16, scale: 0.97 }}\n              animate={{ opacity: 1, y: 0, scale: 1 }}\n              exit={reduce ? undefined : { opacity: 0, y: 10, scale: 0.98 }}\n              transition={{ type: \"spring\", stiffness: 420, damping: 34 }}\n              className=\"relative my-auto w-full max-w-[860px] overflow-hidden rounded-3xl border shadow-[0_30px_80px_-24px_rgba(0,0,0,0.7)]\"\n              style={{ background: p.panel, borderColor: p.line, color: p.title }}\n            >\n              <div className=\"absolute top-3 right-3 z-10 flex gap-1.5\">\n                <button type=\"button\" onClick={() => step(-1)} aria-label=\"Previous product\" className={cn(\"grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0 bg-white/90 text-[#111] shadow\", focus)} style={ring}>\n                  ‹\n                </button>\n                <button type=\"button\" onClick={() => step(1)} aria-label=\"Next product\" className={cn(\"grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0 bg-white/90 text-[#111] shadow\", focus)} style={ring}>\n                  ›\n                </button>\n                <button type=\"button\" ref={focusOnce} onClick={close} aria-label=\"Close quick view\" className={cn(\"grid h-9 w-9 cursor-pointer place-items-center rounded-full border-0 bg-white/90 text-[#111] shadow\", focus)} style={ring}>\n                  <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"M6 6l12 12M18 6 6 18\" />\n                  </svg>\n                </button>\n              </div>\n              <AnimatePresence mode=\"popLayout\" initial={false} custom={dir}>\n                <motion.div key={product.id} initial={reduce ? false : { opacity: 0, x: dir * 40 }} animate={{ opacity: 1, x: 0 }} exit={reduce ? undefined : { opacity: 0, x: dir * -40 }} transition={{ duration: 0.3, ease: [0.22, 1, 0.36, 1] }} className=\"grid grid-cols-1 @[640px]:grid-cols-2\">\n                  <div className=\"p-3 pb-0 @[640px]:p-3\">\n                    <div className=\"relative aspect-square overflow-hidden rounded-2xl\" style={{ background: p.photo }}>\n                      <AnimatePresence mode=\"popLayout\" initial={false}>\n                        <motion.img key={product.images[img]} src={product.images[img]} alt={`${product.title}, image ${img + 1} of ${product.images.length}`} className=\"absolute inset-0 h-full w-full object-cover\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} transition={{ duration: 0.25 }} />\n                      </AnimatePresence>\n                    </div>\n                    {product.images.length > 1 && (\n                      <div className=\"mt-2 grid grid-cols-4 gap-2\">\n                        {product.images.map((src, i) => (\n                          <button key={src} type=\"button\" onClick={() => setImg(i)} aria-label={`Show image ${i + 1}`} aria-pressed={img === i} className={cn(\"aspect-square cursor-pointer overflow-hidden rounded-xl border-2 p-0\", focus)} style={{ borderColor: img === i ? p.title : \"transparent\", background: p.photo, ...ring }}>\n                            {/* eslint-disable-next-line @next/next/no-img-element */}\n                            <img src={src} alt=\"\" className=\"h-full w-full object-cover\" style={{ opacity: img === i ? 1 : 0.6 }} />\n                          </button>\n                        ))}\n                      </div>\n                    )}\n                  </div>\n                  <div className=\"flex flex-col p-6 @[640px]:pt-14\">\n                    <p className=\"m-0 text-[12px]\" style={{ color: p.muted }}>\n                      {product.category}\n                    </p>\n                    <h3 id={`${uid}-t`} className=\"m-0 mt-1 text-[26px] font-semibold tracking-[-0.02em]\">\n                      {product.title}\n                    </h3>\n                    <p className=\"m-0 mt-1.5 flex items-center gap-1.5 text-[12.5px]\" style={{ color: p.muted }}>\n                      <span style={{ color: p.title }}>★ {product.rating.toFixed(1)}</span> · {product.reviews.toLocaleString(\"en-US\")} reviews\n                    </p>\n                    <p className=\"m-0 mt-3 flex items-baseline gap-2\">\n                      <span className=\"text-[22px] font-semibold tabular-nums\">{money(product.price)}</span>\n                      {product.compareAtPrice && (\n                        <span className=\"text-[14px] tabular-nums line-through\" style={{ color: p.muted }}>\n                          {money(product.compareAtPrice)}\n                        </span>\n                      )}\n                    </p>\n                    <p className=\"m-0 mt-3 text-[14px] leading-relaxed\" style={{ color: p.body }}>\n                      {product.description}\n                    </p>\n                    {product.colors && (\n                      <fieldset className=\"m-0 mt-5 border-0 p-0\">\n                        <legend className=\"p-0 text-[12.5px]\" style={{ color: p.muted }}>\n                          Color: <span style={{ color: p.title }}>{color}</span>\n                        </legend>\n                        <div className=\"mt-2 flex gap-2\">\n                          {product.colors.map((c) => (\n                            <label key={c.name} className=\"cursor-pointer rounded-full p-0.5 has-[:focus-visible]:ring-2\" style={{ boxShadow: color === c.name ? `0 0 0 2px ${p.title}` : \"none\", ...ring }}>\n                              <input type=\"radio\" name={`${uid}-color`} checked={color === c.name} onChange={() => setColor(c.name)} className=\"sr-only\" aria-label={c.name} />\n                              <span className=\"block h-7 w-7 rounded-full border\" style={{ background: c.hex, borderColor: p.line }} />\n                            </label>\n                          ))}\n                        </div>\n                      </fieldset>\n                    )}\n                    {product.sizes && (\n                      <fieldset className=\"m-0 mt-4 border-0 p-0\">\n                        <legend className=\"p-0 text-[12.5px]\" style={{ color: p.muted }}>\n                          Size: <span style={{ color: p.title }}>{size}</span>\n                        </legend>\n                        <div className=\"mt-2 flex flex-wrap gap-1.5\">\n                          {product.sizes.map((s) => (\n                            <label key={s} className=\"cursor-pointer has-[:focus-visible]:ring-2\" style={ring}>\n                              <input type=\"radio\" name={`${uid}-size`} checked={size === s} onChange={() => setSize(s)} className=\"sr-only\" />\n                              <span className=\"flex h-9 min-w-[48px] items-center justify-center rounded-full border px-3 text-[12.5px] transition-colors\" style={{ borderColor: size === s ? p.title : p.line, background: size === s ? p.buttonBg : \"transparent\", color: size === s ? p.buttonText : p.title }}>\n                                {s}\n                              </span>\n                            </label>\n                          ))}\n                        </div>\n                      </fieldset>\n                    )}\n                    <div className=\"mt-6 flex gap-2\">\n                      <div className=\"flex h-12 items-center rounded-full border\" style={{ borderColor: p.line }}>\n                        <button type=\"button\" onClick={() => setQty((q) => Math.max(1, q - 1))} disabled={qty <= 1} aria-label=\"Decrease quantity\" className={cn(\"grid h-12 w-10 cursor-pointer place-items-center rounded-l-full border-0 bg-transparent text-[17px] disabled:opacity-30\", focus)} style={{ color: p.title, ...ring }}>\n                          −\n                        </button>\n                        <span className=\"w-6 text-center text-[14px] tabular-nums\" aria-live=\"polite\">\n                          {qty}\n                        </span>\n                        <button type=\"button\" onClick={() => setQty((q) => Math.min(9, q + 1))} aria-label=\"Increase quantity\" className={cn(\"grid h-12 w-10 cursor-pointer place-items-center rounded-r-full border-0 bg-transparent text-[17px]\", focus)} style={{ color: p.title, ...ring }}>\n                          +\n                        </button>\n                      </div>\n                      <button type=\"button\" onClick={add} aria-live=\"polite\" className={cn(\"flex h-12 flex-1 cursor-pointer items-center justify-center gap-2 rounded-full border-0 text-[14px] font-semibold\", focus)} style={{ background: state === \"added\" ? p.accent : p.buttonBg, color: state === \"added\" ? \"#0A0A0A\" : p.buttonText, transition: \"background-color .25s\", ...ring }}>\n                        {state === \"loading\" ? <motion.span className=\"h-4 w-4 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.7, ease: \"linear\" }} aria-label=\"Adding\" /> : state === \"added\" ? \"✓ Added to cart\" : `Add to cart · ${money(product.price * qty)}`}\n                      </button>\n                    </div>\n                    <a href=\"#\" className={cn(\"mt-4 w-fit text-[13px] underline-offset-4 hover:underline\", focus)} style={{ color: p.body, ...ring }}>\n                      View full details →\n                    </a>\n                  </div>\n                </motion.div>\n              </AnimatePresence>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default ProductQuickViewBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}