{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"photo-cards-grid-with-image-parallax-inside-frames","type":"registry:block","title":"Photo Cards Grid With Image Parallax Inside Frames","description":"","dependencies":[],"files":[{"path":"components/we-inc/photo-cards-grid-with-image-parallax-inside-frames.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst SHIFT = 9; // how far each photo drifts inside its frame, in % of the photo height\nconst CLASSES = [\n  { title: \"Wheel basics\", meta: \"Six Tuesday evenings\", price: \"$240\", img: \"https://images.pexels.com/photos/6611421/pexels-photo-6611421.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Stacked handmade mugs and plates in pale and terracotta glazes on a studio shelf\" },\n  { title: \"Glazing day\", meta: \"One Saturday, 10 to 4\", price: \"$95\", img: \"https://images.pexels.com/photos/7375048/pexels-photo-7375048.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Unglazed ceramic mugs on a worktable beside brushes and small pots of glaze\" },\n  { title: \"Tall forms\", meta: \"Four Thursday evenings\", price: \"$210\", img: \"https://images.pexels.com/photos/29286721/pexels-photo-29286721.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"A row of tall, unglazed clay vases drying on wooden boards in a workshop\" },\n  { title: \"Open studio\", meta: \"Any weekday afternoon\", price: \"$30\", img: \"https://images.pexels.com/photos/8063803/pexels-photo-8063803.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Rows of unfinished cream mugs waiting on shelves to be glazed\" },\n];\n\nexport default function PhotoCardsGridWithImageParallaxInsideFrames() {\n  const box = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const el = box.current;\n    if (!el) return;\n    const imgs = Array.from(el.querySelectorAll<HTMLImageElement>(\".w6crd-img\"));\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let frame = 0;\n    let on = true;\n    const draw = () => {\n      frame = 0;\n      el.classList.toggle(\"w6crd-moved\", el.scrollTop > 8);\n      if (reduce) return;\n      const b = el.getBoundingClientRect(); // page scroll: use { top: 0, height: innerHeight }\n      const c = b.top + b.height / 2;\n      imgs.forEach((img) => {\n        const r = img.parentElement!.getBoundingClientRect();\n        const p = Math.max(-1, Math.min(1, (r.top + r.height / 2 - c) / (b.height / 2 + r.height / 2)));\n        img.style.transform = `translate3d(0,${(-p * SHIFT).toFixed(2)}%,0)`;\n      });\n    };\n    const req = () => {\n      if (on && !frame) frame = requestAnimationFrame(draw);\n    };\n    const io = new IntersectionObserver(([e]) => {\n      on = e.isIntersecting;\n      if (on) req();\n    });\n    io.observe(el);\n    el.addEventListener(\"scroll\", req, { passive: true });\n    window.addEventListener(\"resize\", req);\n    req();\n    return () => {\n      cancelAnimationFrame(frame);\n      io.disconnect();\n      el.removeEventListener(\"scroll\", req);\n      window.removeEventListener(\"resize\", req);\n    };\n  }, []);\n\n  return (\n    <div\n      ref={box}\n      tabIndex={0}\n      role=\"region\"\n      aria-label=\"Fernhill Clay Studio classes, scrollable preview\"\n      className=\"w6crd relative h-[620px] overflow-y-auto overscroll-contain bg-[#f4efe6] text-[#2b2420] outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#9a4a2c]\"\n    >\n      <style>{`\n        .w6crd-img { will-change: transform; }\n        .w6crd-hint { transition: opacity .5s ease; }\n        .w6crd-moved .w6crd-hint { opacity: 0; }\n        @media (prefers-reduced-motion: reduce) { .w6crd-img { will-change: auto; } }\n      `}</style>\n      <div className=\"w6crd-hint pointer-events-none absolute right-4 top-4 rounded-full bg-[#2b2420]/80 px-3 py-1.5 text-xs font-medium text-[#f4efe6]\" aria-hidden=\"true\">Scroll inside</div>\n      <div className=\"mx-auto max-w-5xl px-5 pb-16 pt-14 sm:px-8\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.24em] text-[#9a4a2c]\">Fernhill Clay Studio</p>\n        <div className=\"mt-3 flex flex-wrap items-end justify-between gap-4\">\n          <h2 className=\"max-w-md text-3xl font-semibold leading-tight sm:text-4xl\">Autumn classes at the wheel</h2>\n          <p className=\"max-w-xs text-sm leading-relaxed text-[#5b4c42]\">Small groups of six, clay and firing included, aprons on the hook by the door.</p>\n        </div>\n        <ul className=\"mt-10 grid gap-x-6 gap-y-10 sm:grid-cols-2\">\n          {CLASSES.map((c, i) => (\n            <li key={c.title} className={i % 2 ? \"sm:mt-16\" : \"\"}>\n              <a href=\"#\" className=\"group block rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#9a4a2c] focus-visible:ring-offset-4 focus-visible:ring-offset-[#f4efe6]\">\n                <div className=\"relative aspect-[4/3] overflow-hidden rounded-lg bg-[#ddd2c2] shadow-[0_18px_40px_-24px_rgba(43,36,32,0.6)]\">\n                  <img src={c.img} alt={c.alt} width={900} height={675} className=\"w6crd-img absolute inset-x-0 top-[-12%] h-[124%] w-full object-cover\" />\n                </div>\n                <div className=\"mt-4 flex items-baseline justify-between gap-4\">\n                  <h3 className=\"text-lg font-semibold group-hover:underline\">{c.title}</h3>\n                  <span className=\"text-sm font-semibold text-[#9a4a2c]\">{c.price}</span>\n                </div>\n                <p className=\"mt-1 text-sm text-[#5b4c42]\">{c.meta}</p>\n              </a>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </div>\n  );\n}\n"}]}
