{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"css-only-stacking-cards-with-scroll-timeline","type":"registry:block","title":"CSS Only Stacking Cards With Scroll Timeline","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/css-only-stacking-cards-with-scroll-timeline.tsx","type":"registry:component","content":"import { useEffect, useRef, type CSSProperties } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst rooms = [\n  { no: \"Room 1\", title: \"Salt and slate\", text: \"Coastal paintings from the north shore, hung low so you meet the horizon at eye level.\", works: \"14 works\", bg: \"#ffffff\", ink: \"#1b2433\", sub: \"#4b5565\" },\n  { no: \"Room 2\", title: \"The weavers' table\", text: \"Hand-loomed wool from three generations of one family, laid flat under soft daylight.\", works: \"22 pieces\", bg: \"#1f3a5f\", ink: \"#f2f5f9\", sub: \"#c6d2e2\" },\n  { no: \"Room 3\", title: \"Small hours\", text: \"Night photographs of an empty market town, printed small and hung far apart.\", works: \"9 prints\", bg: \"#dfe6ee\", ink: \"#1b2433\", sub: \"#465163\" },\n  { no: \"Room 4\", title: \"Kiln marks\", text: \"Stoneware bowls shown with the shelves they were fired on, ash glaze and all.\", works: \"31 objects\", bg: \"#121a26\", ink: \"#eef2f7\", sub: \"#b4bfcd\" },\n];\n\nexport default function CssOnlyStackingCardsWithScrollTimeline() {\n  const reduce = useReducedMotion();\n  const deckRef = useRef<HTMLDivElement>(null);\n\n  // Only for browsers without scroll-driven animations: an IntersectionObserver marks a card once the next one pins over it.\n  useEffect(() => {\n    const deck = deckRef.current;\n    if (!deck || reduce || CSS.supports(\"animation-timeline: scroll()\")) return;\n    deck.setAttribute(\"data-fallback\", \"\");\n    const cards = Array.from(deck.querySelectorAll<HTMLElement>(\".w4cvt-card\"));\n    // A thin band from the top of the deck down to the pin line: a card inside it has pinned over the one before.\n    const band = deck.clientHeight - parseFloat(getComputedStyle(cards[0]).top) - 2;\n    const io = new IntersectionObserver(\n      (entries) => entries.forEach((e) => cards[cards.indexOf(e.target as HTMLElement) - 1]?.toggleAttribute(\"data-under\", e.isIntersecting)),\n      { root: deck, rootMargin: `0px 0px -${band}px 0px` },\n    );\n    cards.slice(1).forEach((c) => io.observe(c));\n    const onScroll = () => deck.toggleAttribute(\"data-scrolled\", deck.scrollTop > 8);\n    deck.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => { io.disconnect(); deck.removeEventListener(\"scroll\", onScroll); };\n  }, [reduce]);\n\n  return (\n    <section className=\"w4cvt-root flex flex-col\">\n      <style>{`\n        .w4cvt-root { height: 640px; background: #e8edf3; color: #1b2433; }\n        .w4cvt-deck { --h: 340px; --g: 24px; --p: 24px; position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: var(--p) 20px 150px; scrollbar-width: thin; scrollbar-color: #b9c4d2 transparent; }\n        .w4cvt-deck:focus-visible { outline: 3px solid #1f3a5f; outline-offset: -3px; }\n        .w4cvt-hint { position: sticky; top: 0; z-index: 20; height: 0; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }\n        .w4cvt-hint span { margin-top: -18px; padding: 3px 12px; border-radius: 999px; background: #1b2433; color: #f2f5f9; font-size: 12px; letter-spacing: .04em; }\n        .w4cvt-deck[data-scrolled] .w4cvt-hint { opacity: 0; }\n        .w4cvt-list { display: grid; gap: var(--g); max-width: 44rem; margin: 0 auto; padding: 0; list-style: none; }\n        .w4cvt-card { position: sticky; top: var(--p); height: var(--h); }\n        .w4cvt-face { height: 100%; transform-origin: 50% 0; }\n        .w4cvt-shade { position: absolute; inset: 0; border-radius: inherit; background: #0b111a; opacity: 0; pointer-events: none; }\n        .w4cvt-deck[data-fallback] .w4cvt-face, .w4cvt-deck[data-fallback] .w4cvt-shade { transition: transform .5s cubic-bezier(.2,.7,.2,1), opacity .5s ease; }\n        .w4cvt-deck[data-fallback] .w4cvt-card[data-under] .w4cvt-face { transform: scale(.92); }\n        .w4cvt-deck[data-fallback] .w4cvt-card[data-under] .w4cvt-shade { opacity: .45; }\n        @supports (animation-timeline: scroll()) {\n          .w4cvt-face, .w4cvt-shade { animation-timing-function: linear; animation-fill-mode: both; animation-timeline: scroll(nearest block);\n            animation-range: calc(var(--i) * (var(--h) + var(--g)) + var(--g)) calc((var(--i) + 1) * (var(--h) + var(--g))); }\n          .w4cvt-face { animation-name: w4cvt-sink; }\n          .w4cvt-shade { animation-name: w4cvt-dim; }\n          .w4cvt-card:last-child .w4cvt-face, .w4cvt-card:last-child .w4cvt-shade { animation: none; }\n          .w4cvt-hint { animation: w4cvt-hide linear both; animation-timeline: scroll(nearest block); animation-range: 0 40px; }\n        }\n        @keyframes w4cvt-sink { to { transform: scale(.92); } }\n        @keyframes w4cvt-dim { to { opacity: .45; } }\n        @keyframes w4cvt-hide { to { opacity: 0; } }\n        @media (prefers-reduced-motion: reduce) { .w4cvt-face, .w4cvt-shade, .w4cvt-hint { animation: none !important; transition: none !important; transform: none !important; } .w4cvt-shade { opacity: 0 !important; } .w4cvt-hint { display: none; } }\n      `}</style>\n      <div className=\"mx-auto w-full max-w-[44rem] px-5 pb-6 pt-10\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.22em] text-[#1f3a5f]\">Harlow Street Gallery, winter show</p>\n        <div className=\"mt-3 flex flex-wrap items-end justify-between gap-4\">\n          <h2 className=\"text-3xl font-semibold tracking-tight sm:text-4xl\">Four rooms, one floor</h2>\n          <a href=\"#\" className=\"inline-flex min-h-[44px] items-center rounded-full bg-[#1f3a5f] px-5 text-sm font-semibold text-white transition hover:bg-[#2b4c78] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1f3a5f] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e8edf3]\">Plan your visit</a>\n        </div>\n      </div>\n      <div ref={deckRef} className=\"w4cvt-deck\" tabIndex={0} role=\"region\" aria-label=\"Exhibition rooms, scrollable\">\n        <div className=\"w4cvt-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n        <ul className=\"w4cvt-list\">\n          {rooms.map((r, i) => (\n            <li key={r.title} className=\"w4cvt-card\" style={{ \"--i\": i } as CSSProperties}>\n              <article className=\"w4cvt-face relative flex flex-col rounded-3xl p-7 shadow-[0_24px_50px_-26px_rgba(15,23,42,0.55)] sm:p-9\" style={{ background: r.bg, color: r.ink }}>\n                <div className=\"flex items-center justify-between text-sm font-medium\" style={{ color: r.sub }}>\n                  <span>{r.no}</span><span>{r.works}</span>\n                </div>\n                <h3 className=\"mt-auto text-4xl font-semibold tracking-tight sm:text-5xl\">{r.title}</h3>\n                <p className=\"mt-4 max-w-md text-[15px] leading-relaxed\" style={{ color: r.sub }}>{r.text}</p>\n                <span className=\"w4cvt-shade\" aria-hidden=\"true\" />\n              </article>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </section>\n  );\n}\n"}]}
