{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"testimonial-cards-stacking-with-alternating-tilt","type":"registry:block","title":"Testimonial Cards Stacking With Alternating Tilt","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/testimonial-cards-stacking-with-alternating-tilt.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst reviews = [\n  { quote: \"They planted our north bed with ferns and hellebores I would never have picked. Two winters on, it is the part of the garden people ask about.\", name: \"Imogen Barlow\", role: \"Garden in Hebden Bridge\", initials: \"IB\", tone: \"#c9d8b6\" },\n  { quote: \"The hedge plan came with a watering note pinned to every whip. Not one plant lost in a dry summer, which I did not think possible on our clay.\", name: \"Dev Rathore\", role: \"Allotment holder\", initials: \"DR\", tone: \"#e6cfa6\" },\n  { quote: \"I asked for low upkeep and they listened. The meadow strip gets one cut in September and looks better every year it is left alone.\", name: \"Ruth Ellery\", role: \"Cottage garden, Malton\", initials: \"RE\", tone: \"#d9b9a3\" },\n  { quote: \"Clear prices, a day booked and kept, and they swept the path before leaving. Small things, but they are why we called them back.\", name: \"Tomas Lindqvist\", role: \"Courtyard in York\", initials: \"TL\", tone: \"#bcd2cf\" },\n];\nconst TILT_REST = 1.6; // degrees each card keeps once settled (alternates left and right)\nconst TILT_ARRIVE = 3.5; // extra tilt while a card is still sliding in\nconst SCALE_STEP = 0.045; // shrink per card on top\nconst AUTO_PX_PER_SEC = 30; // demo scroll speed; 0 turns it off\n\nexport default function TestimonialCardsStackingWithAlternatingTilt() {\n  const reduce = useReducedMotion();\n  const boxRef = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const box = boxRef.current;\n    if (!box || reduce) return;\n    const cards = Array.from(box.querySelectorAll<HTMLElement>(\".w4tst-card\"));\n    let raf = 0;\n    const paint = () => {\n      raf = 0;\n      const top = box.getBoundingClientRect().top;\n      const cover = cards.map((c) => {\n        const d = c.getBoundingClientRect().top - top - parseFloat(getComputedStyle(c).top);\n        return Math.min(1, Math.max(0, 1 - d / c.offsetHeight));\n      });\n      cards.forEach((c, i) => {\n        let depth = 0;\n        for (let j = i + 1; j < cards.length; j++) depth += cover[j];\n        const turn = (i % 2 ? 1 : -1) * (TILT_REST + TILT_ARRIVE * (1 - cover[i]));\n        (c.firstElementChild as HTMLElement).style.transform = `rotate(${turn}deg) scale(${1 - SCALE_STEP * depth})`;\n        c.querySelector<HTMLElement>(\".w4tst-shade\")!.style.opacity = String(Math.min(0.5, 0.22 * depth));\n      });\n      box.toggleAttribute(\"data-scrolled\", box.scrollTop > 8);\n    };\n    const onScroll = () => { if (!raf) raf = requestAnimationFrame(paint); };\n    box.addEventListener(\"scroll\", onScroll, { passive: true });\n    paint();\n\n    let demo = 0, last = 0, pos = box.scrollTop, seen = true, done = !AUTO_PX_PER_SEC;\n    const step = (now: number) => {\n      const dt = last ? Math.min(now - last, 50) : 0;\n      last = now;\n      pos += (AUTO_PX_PER_SEC * dt) / 1000;\n      if (pos >= box.scrollHeight - box.clientHeight) { done = true; demo = 0; return; }\n      box.scrollTop = pos;\n      demo = requestAnimationFrame(step);\n    };\n    const start = () => { if (!done && seen && !demo) { last = 0; demo = requestAnimationFrame(step); } };\n    const stop = () => { cancelAnimationFrame(demo); demo = 0; };\n    const handOver = () => { done = true; stop(); };\n    const io = new IntersectionObserver(([e]) => { seen = e.isIntersecting; if (seen) start(); else stop(); });\n    io.observe(box);\n    const evs = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"] as const;\n    evs.forEach((ev) => box.addEventListener(ev, handOver, { passive: true }));\n    start();\n    return () => {\n      stop();\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      box.removeEventListener(\"scroll\", onScroll);\n      evs.forEach((ev) => box.removeEventListener(ev, handOver));\n    };\n  }, [reduce]);\n\n  return (\n    <section ref={boxRef} tabIndex={0} aria-label=\"Customer reviews, scrollable\" className=\"w4tst-root\">\n      <style>{`\n        .w4tst-root { height: 620px; overflow-y: auto; overflow-x: hidden; position: relative; background: #1e3a2c; color: #f4efe3; scrollbar-width: thin; scrollbar-color: #47624f transparent; }\n        .w4tst-root:focus-visible { outline: 3px solid #e6cfa6; outline-offset: -3px; }\n        .w4tst-hint { position: sticky; top: 0; z-index: 20; height: 0; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }\n        .w4tst-hint span { margin-top: 10px; padding: 4px 12px; border-radius: 999px; background: rgba(244,239,227,.92); color: #1e3a2c; font-size: 12px; letter-spacing: .04em; }\n        .w4tst-root[data-scrolled] .w4tst-hint { opacity: 0; }\n        .w4tst-card { position: sticky; top: 56px; }\n        .w4tst-face { transform-origin: 50% 40%; will-change: transform; }\n        .w4tst-card:nth-child(odd) .w4tst-face { transform: rotate(-1.6deg); }\n        .w4tst-card:nth-child(even) .w4tst-face { transform: rotate(1.6deg); }\n        .w4tst-shade { position: absolute; inset: 0; border-radius: inherit; background: #0c1a12; opacity: 0; pointer-events: none; }\n        @media (prefers-reduced-motion: reduce) { .w4tst-shade { opacity: 0 !important; } .w4tst-hint { display: none; } }\n      `}</style>\n      <div className=\"w4tst-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n      <div className=\"mx-auto max-w-2xl px-6 pb-24 pt-12\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#e6cfa6]\">Brackenfold Gardens</p>\n        <h2 className=\"mt-3 font-serif text-3xl leading-tight sm:text-4xl\">Notes from the people whose gardens we planted</h2>\n        <ul className=\"mt-10 grid gap-8\">\n          {reviews.map((r) => (\n            <li key={r.name} className=\"w4tst-card\">\n              <figure className=\"w4tst-face relative m-0 rounded-2xl bg-[#f6f1e4] p-7 text-[#1f2a22] shadow-[0_28px_50px_-24px_rgba(0,0,0,0.6)] sm:p-9\">\n                <svg viewBox=\"0 0 32 24\" className=\"h-6 w-8 text-[#5b7a52]\" aria-hidden=\"true\"><path fill=\"currentColor\" d=\"M0 24V14C0 6 4 1 12 0l1 4c-4 1-6 4-6 8h6v12H0zm19 0V14c0-8 4-13 12-14l1 4c-4 1-6 4-6 8h6v12H19z\" /></svg>\n                <blockquote className=\"mt-5 font-serif text-xl leading-relaxed sm:text-2xl\">{r.quote}</blockquote>\n                <figcaption className=\"mt-7 flex items-center gap-3\">\n                  <span className=\"grid h-11 w-11 place-items-center rounded-full text-sm font-semibold text-[#1f2a22]\" style={{ background: r.tone }} aria-hidden=\"true\">{r.initials}</span>\n                  <span><span className=\"block font-semibold\">{r.name}</span><span className=\"block text-sm text-[#55604f]\">{r.role}</span></span>\n                </figcaption>\n                <span className=\"w4tst-shade\" aria-hidden=\"true\" />\n              </figure>\n            </li>\n          ))}\n        </ul>\n        <a href=\"#\" className=\"mt-14 inline-flex min-h-[44px] items-center rounded-full bg-[#e6cfa6] px-6 text-sm font-semibold text-[#1e3a2c] transition hover:bg-[#f0dcb8] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f4efe3] focus-visible:ring-offset-2 focus-visible:ring-offset-[#1e3a2c]\">Book a garden visit</a>\n      </div>\n    </section>\n  );\n}\n"}]}
