{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pull-down-wall-chart-tabs-on-spring-rollers-that-snap-up-to-uncover-the-chart-hanging-behind","type":"registry:block","title":"Pull-Down Wall Chart Tabs on Spring Rollers That Snap up to Uncover the Chart Hanging Behind","description":"Tabs built as a rack of schoolroom wall charts: each chart snaps up onto its spring roller to uncover the one hanging behind. Free React and HTML to copy.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/pull-down-wall-chart-tabs-on-spring-rollers-that-snap-up-to-uncover-the-chart-hanging-behind.tsx","type":"registry:component","content":"import { useEffect, useId, useRef, useState, type KeyboardEvent } from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform } from \"framer-motion\";\n\n/** One wall chart per tab, front roller first. `tab` is the word in the brass holder on its bottom slat. */\nconst school = { name: \"Saltmarsh Sailing School\", hint: \"Pull a brass tab to change the chart\" };\nconst charts = [\n  { tab: \"Clouds\", title: \"Reading the sky\", paper: \"#dfe8ea\", text: \"#1f2a33\", ink: \"#1d3f66\", tone: \"#3f7fc4\", photo: \"https://images.pexels.com/photos/8726326/pexels-photo-8726326.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Tall white cumulus clouds piling up against a deep blue sky\", fig: \"Cumulus building before noon\", body: \"Flat-bottomed heaps that stay small mean a settled afternoon. When they grow taller than they are wide before lunch, expect gusts underneath them and reef early.\", notes: [\"Small and scattered: fair\", \"Towering by noon: squalls\", \"Anvil on top: stay ashore\"] },\n  { tab: \"Tides\", title: \"Working the tide\", paper: \"#efe5cf\", text: \"#2a251d\", ink: \"#0f5257\", tone: \"#1c7f8a\", photo: \"https://images.pexels.com/photos/9940655/pexels-photo-9940655.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Turquoise sea breaking white over dark rocks, seen from directly above\", fig: \"The ebb over Gull Ledge\", body: \"The harbour dries for two hours either side of low water. Leave on the flood so that a grounding lifts you off again, and keep clear of the bar when the ebb runs against an onshore wind.\", notes: [\"Flood: the water is rising\", \"Ebb: the water is falling\", \"Slack: the pause between\"] },\n  { tab: \"Knots\", title: \"Three good knots\", paper: \"#e9d3ae\", text: \"#2a2118\", ink: \"#7a2f22\", tone: \"#8f9aa3\", photo: \"https://images.pexels.com/photos/2347466/pexels-photo-2347466.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Thick grey mooring rope knotted round a steel rail\", fig: \"A stern line made fast\", body: \"Learn three before you learn thirty. A bowline for a loop that will not slip, a clove hitch for a fender, and a round turn with two half hitches for anything you want to find again in the morning.\", notes: [\"Bowline: a fixed loop\", \"Clove hitch: quick to adjust\", \"Round turn: takes the strain\"] },\n  { tab: \"Lights\", title: \"Lights after dark\", paper: \"#1c2b3d\", text: \"#e9e1cc\", ink: \"#f0c46a\", tone: \"#e9e2d6\", photo: \"https://images.pexels.com/photos/12323409/pexels-photo-12323409.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"A pale lighthouse tower above a sand dune in hazy evening light\", fig: \"The dune light at dusk\", body: \"Every light has a rhythm of its own, printed on the chart beside it. Count the flashes against your watch for a full minute before you trust the name you have given it.\", notes: [\"Fl: one flash at a time\", \"Oc: lit, with short darks\", \"Iso: light and dark equal\"] },\n];\n\n// Two sets of measurements in pixels: one for desks, one for phones.\nconst WIDE = { w: 720, L: 486, pad: 34, holder: 112, title: 42, text: 15.5, lead: 24, photoH: 262, two: true };\nconst SLIM = { w: 300, L: 580, pad: 16, holder: 60, title: 26, text: 12.5, lead: 19, photoH: 150, two: false };\ntype Dims = typeof WIDE;\nconst STEP = 44; // each roller hangs this much lower than the one in front of it\nconst ROLL = 24; // roller diameter\nconst SLAT = 26; // the black bar along the bottom of each chart\nconst EXT = 22; // how far a roller runs past the paper at each end\nconst TOP = 44;\n\nconst svgUrl = (body: string, w: number, h: number) => `url(\"data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}'>${body}</svg>`)}\")`;\nconst PAPER = svgUrl(`<filter id='p'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.36  0 0 0 0 0.26  0 0 0 0 0.1  0 0 0 0.6 -0.17'/></filter><rect width='240' height='240' filter='url(#p)'/>`, 240, 240);\nconst PLASTER = svgUrl(`<filter id='w'><feTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' seed='11'/><feColorMatrix values='0 0 0 0 0.12  0 0 0 0 0.16  0 0 0 0 0.12  0 0 0 0.34 -0.12'/></filter><rect width='300' height='300' filter='url(#w)'/>`, 300, 300);\nconst WOOD = svgUrl(`<filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.006 0.5' numOctaves='3' seed='8'/><feColorMatrix values='0 0 0 0 0.25  0 0 0 0 0.12  0 0 0 0 0.03  1.6 0 0 0 -0.62'/></filter><rect width='700' height='40' filter='url(#g)'/>`, 700, 40);\nconst BRASS = \"linear-gradient(180deg, #fff3c4 0%, #e2bf68 20%, #b98d33 55%, #8a6519 80%, #d9b660 100%)\";\n\nfunction Chart({ i, d, up, wait, reduce, active, uid, onPick, onKey, onFocus, setRef }: { i: number; d: Dims; up: boolean; wait: number; reduce: boolean; active: boolean; uid: string; onPick: () => void; onKey: (e: KeyboardEvent) => void; onFocus: (on: boolean) => void; setRef: (el: HTMLButtonElement | null) => void }) {\n  const c = charts[i];\n  const upY = ROLL + 4 - ROLL / 2 - (d.L - SLAT); // rolled: only the slat is left showing under the roller\n  const y = useMotionValue(up ? upY : 0);\n  const rattle = useMotionValue(0);\n  const fat = useTransform(y, [upY, 0], [1.42, 1]);\n  const swing = useTransform(rattle, (v) => v * 5);\n  const was = useRef(up);\n\n  useEffect(() => {\n    if (was.current === up || reduce) {\n      was.current = up;\n      y.set(up ? upY : 0);\n      return;\n    }\n    was.current = up;\n    let live = true;\n    let tail: { stop: () => void } | null = null;\n    // going up the spring takes it, faster and faster, and the slat rattles against the roller; coming down a hand pulls it\n    const run = up ? animate(y, upY, { duration: 0.44, delay: wait, ease: [0.6, 0, 0.9, 0.5] }) : animate(y, 0, { type: \"spring\", stiffness: 150, damping: 15, mass: 0.9, delay: wait });\n    run.then(() => {\n      if (live) tail = animate(rattle, up ? [0, -1.6, 1.2, -0.7, 0.3, 0] : [0, 0.5, -0.3, 0], { duration: up ? 0.7 : 0.5, ease: \"easeOut\" });\n    });\n    return () => {\n      live = false;\n      run.stop();\n      tail?.stop();\n    };\n  }, [up, reduce, upY, wait, y, rattle]);\n\n  const left = EXT + 14;\n  const holderLeft = d.pad - 6 + (i * (d.w - 2 * d.pad + 12 - d.holder)) / (charts.length - 1);\n  return (\n    <div className=\"absolute\" style={{ left: 0, top: TOP + i * STEP, width: d.w + 2 * left, height: d.L + 80 }}>\n      {/* the paper is cut off at the middle of its roller, which is where it winds on */}\n      <div className=\"absolute inset-0\" style={{ clipPath: `inset(${ROLL / 2}px -40px -90px -40px)` }}>\n        <motion.div className=\"absolute\" style={{ left, top: ROLL / 2, width: d.w, height: d.L, y, rotate: rattle, transformOrigin: \"50% 100%\" }}>\n          <div className=\"absolute inset-0\" style={{ background: c.paper, backgroundImage: `linear-gradient(180deg, rgba(40,26,8,0.42) 0, rgba(40,26,8,0.12) 22px, rgba(40,26,8,0) 60px), linear-gradient(90deg, rgba(60,40,10,0.16), rgba(60,40,10,0) 7%, rgba(255,255,255,0.14) 40%, rgba(60,40,10,0) 90%, rgba(60,40,10,0.2)), repeating-linear-gradient(180deg, rgba(90,60,20,0) 0 71px, rgba(60,40,10,0.09) 71px 72px, rgba(255,255,255,0.1) 72px 73px), ${PAPER}`, boxShadow: \"0 10px 22px rgba(22,28,20,0.38), 0 2px 4px rgba(22,28,20,0.3)\" }} />\n          {/* cloth tape down both edges */}\n          {[0, 1].map((s) => (\n            <span key={s} aria-hidden=\"true\" className=\"absolute inset-y-0 block w-[5px]\" style={{ [s ? \"right\" : \"left\"]: 0, background: \"linear-gradient(90deg, #14110f, #37322d 45%, #1b1816)\", boxShadow: s ? \"-1px 0 0 rgba(0,0,0,0.25)\" : \"1px 0 0 rgba(0,0,0,0.25)\" }} />\n          ))}\n\n          <div id={`${uid}-p${i}`} role=\"tabpanel\" aria-labelledby={`${uid}-t${i}`} aria-hidden={!active} className=\"absolute inset-x-0 top-0 font-serif\" style={{ padding: `26px ${d.pad}px 0`, color: c.text }}>\n            <div className=\"flex items-baseline justify-between gap-3 font-mono uppercase tracking-[0.2em]\" style={{ fontSize: d.two ? 10 : 8.5, color: c.ink }}>\n              <span>Plate {[\"I\", \"II\", \"III\", \"IV\", \"V\", \"VI\"][i]}</span>\n              <span aria-hidden=\"true\">{school.name}</span>\n            </div>\n            <h3 className=\"m-0 font-serif font-bold leading-none tracking-[-0.01em]\" style={{ fontSize: d.title, color: c.ink, marginTop: d.two ? 10 : 8 }}>\n              {c.title}\n            </h3>\n            <div aria-hidden=\"true\" className=\"mt-3 h-[5px]\" style={{ borderTop: `2px solid ${c.ink}`, borderBottom: `1px solid ${c.ink}` }} />\n            <div className={d.two ? \"mt-4 grid grid-cols-[1.02fr_1fr] gap-6\" : \"mt-3\"}>\n              <figure className=\"m-0\">\n                <div className=\"p-[4px]\" style={{ border: `1px solid ${c.ink}` }}>\n                  <img src={c.photo} alt={c.alt} width={600} height={400} loading=\"eager\" className=\"block w-full object-cover\" style={{ height: d.photoH, background: c.tone }} />\n                </div>\n                <figcaption className=\"mt-[6px] italic\" style={{ fontSize: d.two ? 12 : 11, color: c.ink }}>\n                  Fig. {i + 1}. {c.fig}\n                </figcaption>\n              </figure>\n              <div style={{ marginTop: d.two ? -3 : 10 }}>\n                <p className=\"m-0\" style={{ fontSize: d.text, lineHeight: `${d.lead}px` }}>\n                  {c.body}\n                </p>\n                <ol className=\"m-0 mt-3 list-none p-0 font-mono\" style={{ fontSize: d.two ? 11.5 : 10.5 }}>\n                  {c.notes.map((n, k) => (\n                    <li key={n} className=\"flex items-center gap-2 py-[5px]\" style={{ borderTop: `1px solid ${c.ink}55` }}>\n                      <span aria-hidden=\"true\" className=\"grid h-[17px] w-[17px] shrink-0 place-items-center rounded-full text-[9px] font-bold\" style={{ background: c.ink, color: c.paper }}>\n                        {k + 1}\n                      </span>\n                      {n}\n                    </li>\n                  ))}\n                </ol>\n              </div>\n            </div>\n          </div>\n          <p aria-hidden=\"true\" className=\"absolute inset-x-0 m-0 text-center font-mono uppercase tracking-[0.24em]\" style={{ bottom: SLAT + 5, fontSize: 7, color: c.text, opacity: 0.6 }}>\n            Chart {i + 1} of {charts.length} · Hang out of direct sun\n          </p>\n\n          {/* the bottom slat, with the tab on it */}\n          <div className=\"absolute rounded-[3px]\" style={{ left: -5, right: -5, bottom: 0, height: SLAT, background: \"#1b1816\", backgroundImage: `linear-gradient(180deg, rgba(255,255,255,0.32) 0, rgba(255,255,255,0.06) 4px, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%), ${WOOD}`, backgroundSize: \"auto, 100% 100%\", boxShadow: \"0 5px 8px rgba(15,20,14,0.45), inset 0 0 0 0.5px rgba(0,0,0,0.9)\" }}>\n            <button\n              type=\"button\"\n              ref={setRef}\n              id={`${uid}-t${i}`}\n              role=\"tab\"\n              aria-selected={active}\n              aria-controls={`${uid}-p${i}`}\n              tabIndex={active ? 0 : -1}\n              onClick={onPick}\n              onKeyDown={onKey}\n              onFocus={() => onFocus(true)}\n              onBlur={() => onFocus(false)}\n              className=\"group absolute top-[-2px] block cursor-pointer rounded-[4px] outline-none focus-visible:ring-2 focus-visible:ring-[#12365c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f3ead6]\"\n              style={{ left: holderLeft + 5, width: d.holder, height: SLAT + 22 }}\n            >\n              <span aria-hidden=\"true\" className=\"absolute inset-x-0 top-[5px] block rounded-[2.5px] p-[3px]\" style={{ height: 20, background: BRASS, boxShadow: \"0 2px 3px rgba(0,0,0,0.7), inset 0 0 0 0.5px rgba(70,44,0,0.9), inset 0 1px 0 rgba(255,250,220,0.7)\" }}>\n                <span className=\"grid h-full place-items-center rounded-[1px] font-mono font-bold uppercase leading-none transition-colors\" style={{ fontSize: d.two ? 9.5 : 8, letterSpacing: d.two ? \"0.2em\" : \"0.1em\", background: active ? \"#fbf4e1\" : \"#e6dbc2\", color: active ? \"#a3271b\" : \"#2a251d\", boxShadow: \"inset 0 1.5px 2.5px rgba(50,28,0,0.6)\" }}>\n                  {c.tab}\n                </span>\n              </span>\n              <motion.span aria-hidden=\"true\" className=\"absolute left-1/2 block\" style={{ top: SLAT - 3, width: 16, height: 22, marginLeft: -8, rotate: swing, transformOrigin: \"50% 2px\" }}>\n                <span className=\"absolute left-1/2 top-0 block h-[7px] w-[3px] -translate-x-1/2 rounded-b-[2px]\" style={{ background: \"linear-gradient(90deg, #7a5814, #f3d98a, #8a6519)\" }} />\n                <span className=\"absolute inset-x-0 bottom-0 block h-[16px] rounded-full transition-transform duration-200 group-hover:translate-y-[2px]\" style={{ border: \"3px solid #c9a24a\", borderTopColor: \"#f6e3a1\", borderBottomColor: \"#8a6519\", boxShadow: \"0 2px 3px rgba(0,0,0,0.5), inset 0 1px 1px rgba(0,0,0,0.35)\" }} />\n              </motion.span>\n            </button>\n          </div>\n        </motion.div>\n      </div>\n\n      {/* the roller: varnished wood, fatter while the chart is wound on it, brass at both ends */}\n      <div aria-hidden=\"true\" className=\"absolute\" style={{ left: 14, right: 14, top: 0, height: ROLL }}>\n        <motion.div className=\"absolute inset-0 rounded-[3px]\" style={{ scaleY: fat, background: \"#a8642b\", backgroundImage: `linear-gradient(180deg, rgba(40,16,0,0.5) 0%, rgba(255,226,170,0.75) 20%, rgba(255,210,150,0.15) 40%, rgba(40,16,0,0.25) 70%, rgba(20,8,0,0.75) 100%), ${WOOD}`, backgroundSize: \"auto, 100% 100%\", boxShadow: \"0 7px 9px rgba(15,20,14,0.5), inset 0 0 0 0.5px rgba(40,16,0,0.8)\" }} />\n        {[0, 1].map((s) => (\n          <span key={s} className=\"absolute block rounded-[2px]\" style={{ [s ? \"right\" : \"left\"]: -7, top: 4, width: 13, height: ROLL - 8, background: BRASS, boxShadow: \"0 2px 3px rgba(0,0,0,0.5), inset 0 0 0 0.5px rgba(70,44,0,0.9)\" }} />\n        ))}\n      </div>\n    </div>\n  );\n}\n\nexport default function PullDownWallChartTabs() {\n  const reduce = !!useReducedMotion();\n  const uid = useId();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const tabs = useRef<(HTMLButtonElement | null)[]>([]);\n  const [slim, setSlim] = useState(false);\n  const [scale, setScale] = useState(1);\n  const [sel, setSel] = useState({ now: 1, was: 1 });\n  const idle = useRef({ touched: false, paused: false });\n\n  const d = slim ? SLIM : WIDE;\n  const n = charts.length;\n  const W = d.w + 2 * (EXT + 14);\n  const H = TOP + (n - 1) * STEP + ROLL / 2 + d.L + 34;\n\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    if (!wrap) return;\n    const measure = () => {\n      const w = wrap.clientWidth;\n      const narrow = w < 760;\n      setSlim(narrow);\n      setScale(Math.min(1, (w - 8) / ((narrow ? SLIM : WIDE).w + 2 * (EXT + 14))));\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(wrap);\n    return () => ro.disconnect();\n  }, []);\n\n  // until someone touches it, the charts go up one at a time and then all come back down\n  useEffect(() => {\n    if (reduce) return;\n    const s = idle.current;\n    const t = window.setInterval(() => {\n      if (s.touched || s.paused || document.hidden) return;\n      setSel((v) => ({ now: (v.now + 1) % n, was: v.now }));\n    }, 3300);\n    return () => window.clearInterval(t);\n  }, [reduce, n]);\n\n  const pick = (i: number, focusIt = false) => {\n    idle.current.touched = true;\n    setSel((v) => (v.now === i ? v : { now: i, was: v.now }));\n    if (focusIt) tabs.current[i]?.focus();\n  };\n  const onKey = (i: number) => (e: KeyboardEvent) => {\n    const to = e.key === \"ArrowRight\" || e.key === \"ArrowDown\" ? (i + 1) % n : e.key === \"ArrowLeft\" || e.key === \"ArrowUp\" ? (i + n - 1) % n : e.key === \"Home\" ? 0 : e.key === \"End\" ? n - 1 : -1;\n    if (to < 0) return;\n    e.preventDefault();\n    pick(to, true);\n  };\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#9fae9c]\">\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ backgroundImage: `radial-gradient(80% 70% at 42% 30%, rgba(238,244,232,0.6) 0%, rgba(200,212,196,0.12) 48%, rgba(60,78,62,0.42) 100%), ${PLASTER}` }} />\n      <div ref={wrapRef} onPointerEnter={() => (idle.current.paused = true)} onPointerLeave={() => (idle.current.paused = false)} className=\"relative mx-auto w-full max-w-[1100px]\" style={{ height: Math.round(H * scale) + (slim ? 104 : 84) }}>\n        <h2 className=\"sr-only\">{school.name}: wall charts</h2>\n        <div role=\"tablist\" aria-label=\"Wall charts\" aria-owns={charts.map((_, i) => `${uid}-t${i}`).join(\" \")} />\n        <div className=\"absolute left-1/2 top-0\" style={{ width: W, height: H, transformOrigin: \"50% 0\", transform: `translateX(-50%) scale(${scale})` }}>\n          {/* what the whole rack throws on the wall */}\n          <div aria-hidden=\"true\" className=\"absolute\" style={{ left: 30, top: TOP + 26, width: d.w + 30, height: d.L + (n - 1) * STEP, background: \"rgba(30,44,32,0.42)\", filter: \"blur(26px)\" }} />\n          {/* two flat steel hangers screwed to the wall */}\n          {[0, 1].map((s) => (\n            <div key={s} aria-hidden=\"true\" className=\"absolute rounded-[4px]\" style={{ [s ? \"right\" : \"left\"]: 2, top: TOP - 26, width: 22, height: (n - 1) * STEP + ROLL + 46, background: \"linear-gradient(90deg, #15181a 0%, #3b4144 30%, #565d61 46%, #23272a 72%, #0c0e0f 100%)\", boxShadow: \"3px 6px 10px rgba(20,30,22,0.5), inset 0 1px 0 rgba(255,255,255,0.25)\" }}>\n              {[9, (n - 1) * STEP + ROLL + 29].map((t) => (\n                <span key={t} className=\"absolute left-1/2 block h-[9px] w-[9px] -translate-x-1/2 rounded-full\" style={{ top: t, background: \"radial-gradient(circle at 35% 30%, #e8ecee, #6d7477 55%, #24282a)\", boxShadow: \"0 1px 1px rgba(0,0,0,0.8), inset 0 0 0 0.5px #0c0e0f\" }}>\n                  <span className=\"absolute left-[1.5px] top-[4px] block h-[1px] w-[6px] rotate-[30deg] bg-[#16191b]\" />\n                </span>\n              ))}\n            </div>\n          ))}\n          {/* drawn back to front, so the nearest chart covers the ones behind it */}\n          {charts\n            .map((_, i) => i)\n            .reverse()\n            .map((i) => {\n              const up = i < sel.now;\n              const wait = sel.now > sel.was ? Math.max(0, i - sel.was) * 0.13 : Math.max(0, sel.was - 1 - i) * 0.13;\n              return <Chart key={i} i={i} d={d} up={up} wait={wait} reduce={reduce} active={sel.now === i} uid={uid} onPick={() => pick(i)} onKey={onKey(i)} onFocus={(on) => (idle.current.paused = on)} setRef={(el) => (tabs.current[i] = el)} />;\n            })}\n        </div>\n        <p className=\"absolute bottom-5 left-5 m-0 font-mono text-[11px] uppercase leading-relaxed tracking-[0.18em] text-[#33402f] sm:bottom-7 sm:left-8\">\n          <span className=\"text-[#141c13]\">{school.name}</span>\n          <span className=\"block\">{school.hint}</span>\n        </p>\n      </div>\n      {/* afternoon light through a window somewhere to the left: two soft bars across wall and charts alike */}\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 overflow-hidden\" style={{ mixBlendMode: \"soft-light\" }}>\n        {[0, 1].map((k) => (\n          <span key={k} className=\"absolute block\" style={{ left: `${k ? 46 : 8}%`, top: \"-30%\", width: k ? \"30%\" : \"26%\", height: \"170%\", transform: \"rotate(24deg)\", background: \"linear-gradient(90deg, rgba(255,246,214,0), rgba(255,246,214,0.85) 18%, rgba(255,246,214,0.85) 82%, rgba(255,246,214,0))\", filter: \"blur(26px)\", opacity: 0.42 }} />\n        ))}\n      </div>\n    </section>\n  );\n}\n"}]}
