{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"cast-iron-finger-post-navigation-with-painted-arms-that-swing-round-the-post-to-point-at-the-chosen-page","type":"registry:component","title":"Cast Iron Finger Post Navigation with Painted Arms That Swing Round the Post to Point at the Chosen Page","description":"Signpost menu with painted arms on a cast iron post: the one you pick swings round the post in 3D to point the way. Copy the React code or HTML free.","dependencies":[],"files":[{"path":"components/we-inc/cast-iron-finger-post-navigation-with-painted-arms-that-swing-round-the-post-to-point-at-the-chosen-page.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Everything a visitor is likely to change sits here.\nconst places = [\n  { label: \"Work\", miles: \"2\", note: \"Selected projects, newest first\" },\n  { label: \"Studio\", miles: \"¾\", note: \"Who we are, how a job runs\" },\n  { label: \"Journal\", miles: \"5\", note: \"Workshop notes, most weeks\" },\n  { label: \"Contact\", miles: \"1½\", note: \"Write, call or come by\" },\n];\nconst START = 2; // the arm that points the way at load\nconst AWAY = [197, 166, 203, 170]; // where each arm rests when it is not chosen (180 is flat left)\nconst PAINT = \"#f6f3ea\"; // arm and post\nconst INK = \"#15171a\"; // lettering, rims and bands\nconst SPRING = { pull: 46, drag: 5.4 }; // lower the drag for a looser collar that swings longer\nconst DEMO = true; // turn the arms by itself until a visitor does\n\nconst layoutFor = (narrow: boolean) =>\n  narrow\n    ? { W: 372, H: 620, cx: 186, len: 168, h: 50, pitch: 66, top: 136, font: 14.5, small: 12, tip: 18, post: 26 }\n    : { W: 880, H: 660, cx: 440, len: 330, h: 68, pitch: 88, top: 152, font: 29, small: 23, tip: 30, post: 36 };\n\nconst GRAIN = `url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")`;\nconst IRON = \"linear-gradient(90deg,#030303 0%,#1d1f21 16%,#5a5e62 34%,#787d82 40%,#2c2e30 58%,#0b0b0c 82%,#000 100%)\";\nconst WHITE = \"linear-gradient(90deg,#8b8c84 0%,#d9d7cc 12%,#fdfcf6 30%,#ffffff 38%,#f1eee4 56%,#c2c0b4 80%,#8e8e85 100%)\";\n\nexport default function FingerPostNavigation() {\n  const frame = useRef<HTMLDivElement>(null);\n  const arms = useRef<(HTMLLIElement | null)[]>([]);\n  const [narrow, setNarrow] = useState(false);\n  const [scale, setScale] = useState(1);\n  const [chosen, setChosen] = useState(START);\n  const live = useRef({ chosen: START, hover: -1, touched: false });\n  const L = layoutFor(narrow);\n\n  useEffect(() => {\n    const el = frame.current;\n    if (!el) return;\n    const fit = () => {\n      const slim = el.clientWidth < 700;\n      setNarrow(slim);\n      setScale(Math.min(1, el.clientWidth / layoutFor(slim).W));\n    };\n    fit();\n    const ro = new ResizeObserver(fit);\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  useEffect(() => {\n    const el = frame.current;\n    if (!el) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const goal = (i: number) => (i === live.current.chosen ? 0 : AWAY[i % AWAY.length] - (live.current.hover === i ? 16 : 0));\n    // Each arm is a heavy casting on a loose collar: an angle, a speed, and a spring towards where it should point.\n    const state = places.map((_, i) => ({ a: goal(i) + (reduce ? 0 : i === START ? 26 : i % 2 ? -7 : 8), v: 0 }));\n    const lx = -0.52, lz = 0.64; // the sun: over the left shoulder\n    const paint = () => {\n      state.forEach((s, i) => {\n        const node = arms.current[i];\n        if (!node) return;\n        const r = (s.a * Math.PI) / 180;\n        const facing = Math.cos(r) >= 0 ? 1 : -1;\n        const lambert = Math.max(0, facing * (-Math.sin(r) * lx + Math.cos(r) * lz));\n        node.style.transform = `rotateY(${(-s.a).toFixed(2)}deg)`;\n        node.style.setProperty(\"--shade\", (0.3 * (1 - Math.min(1, lambert / 0.72))).toFixed(3));\n        node.style.setProperty(\"--gloss\", `${(50 + facing * Math.sin(r) * 150).toFixed(1)}%`);\n      });\n    };\n    let raf = 0, last = 0, seen = true, timer = 0;\n    const tick = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.032, last ? (now - last) / 1000 : 0.016);\n      last = now;\n      state.forEach((s, i) => {\n        if (reduce) { s.a = goal(i); return; }\n        const wind = Math.sin(now / 900 + i * 1.7) * 3.2 + Math.sin(now / 310 + i * 4.1) * 1.1; // a breeze never lets them sit dead still\n        s.v += ((goal(i) - s.a) * SPRING.pull - s.v * SPRING.drag + wind) * dt;\n        s.a += s.v * dt;\n      });\n      paint();\n      if (seen && !document.hidden && !reduce) raf = requestAnimationFrame(tick);\n    };\n    const wake = () => { if (!raf && seen && !document.hidden) { last = 0; raf = requestAnimationFrame(tick); } };\n    const io = new IntersectionObserver(([e]) => { seen = e.isIntersecting; wake(); });\n    io.observe(el);\n    document.addEventListener(\"visibilitychange\", wake);\n    el.addEventListener(\"fingerpost-wake\", wake);\n    if (DEMO && !reduce) {\n      timer = window.setTimeout(function next() {\n        if (live.current.touched) return;\n        live.current.chosen = (live.current.chosen + 1) % places.length;\n        setChosen(live.current.chosen);\n        timer = window.setTimeout(next, 3100);\n      }, 3500);\n    }\n    paint();\n    wake();\n    return () => { cancelAnimationFrame(raf); clearTimeout(timer); io.disconnect(); document.removeEventListener(\"visibilitychange\", wake); el.removeEventListener(\"fingerpost-wake\", wake); };\n  }, []);\n\n  const point = (i: number) => {\n    live.current.touched = true;\n    live.current.chosen = i;\n    setChosen(i);\n    frame.current?.dispatchEvent(new Event(\"fingerpost-wake\"));\n  };\n  const lean = (i: number) => { live.current.hover = i; frame.current?.dispatchEvent(new Event(\"fingerpost-wake\")); };\n\n  const hub = L.post / 2 - 3; // the arm starts just inside the collar\n  const finger = `polygon(0 0, calc(100% - ${L.tip}px) 0, 100% 50%, calc(100% - ${L.tip}px) 100%, 0 100%)`;\n  const fingerBack = `polygon(${L.tip}px 0, 100% 0, 100% 100%, ${L.tip}px 100%, 0 50%)`;\n  const lettering = { color: INK, fontSize: L.font, letterSpacing: narrow ? \"0.03em\" : \"0.07em\", textShadow: \"0 1.4px 0.6px rgba(0,0,0,0.38), 0 -0.6px 0 rgba(255,255,255,0.55), 1px 0 0 rgba(0,0,0,0.25)\" };\n\n  const face = (p: (typeof places)[number], back: boolean) => (\n    <span\n      aria-hidden={back || undefined}\n      className=\"absolute inset-0 block\"\n      style={{ transform: back ? \"rotateY(180deg) translateZ(4px)\" : \"translateZ(4px)\", backfaceVisibility: \"hidden\", WebkitBackfaceVisibility: \"hidden\", filter: \"drop-shadow(0 1px 0 rgba(0,0,0,0.35))\" }}\n    >\n      {/* the raised rim, then the painted field inside it */}\n      <span className=\"absolute inset-0 block\" style={{ clipPath: back ? fingerBack : finger, background: `linear-gradient(180deg,#6a6f74 0,#33363a 3px,${INK} 40%,#000)` }} />\n      <span\n        className={`absolute block ${back ? \"flex-row-reverse\" : \"\"} flex items-center justify-between font-sans font-extrabold uppercase`}\n        style={{ inset: 4, clipPath: back ? fingerBack : finger, background: `linear-gradient(180deg,#ffffff 0%,${PAINT} 30%,${PAINT} 66%,#e2decf 100%)`, paddingLeft: back ? L.tip + 2 : L.post * 0.85, paddingRight: back ? L.post * 0.85 : L.tip + 2 }}\n      >\n        <span className=\"relative z-10\" style={lettering}>{p.label}</span>\n        <span className=\"relative z-10 tabular-nums\" style={{ ...lettering, fontSize: L.small, letterSpacing: \"0.02em\" }}>{p.miles}</span>\n        <span className=\"pointer-events-none absolute inset-0 block mix-blend-multiply opacity-[0.18]\" style={{ backgroundImage: GRAIN, backgroundSize: \"140px 140px\" }} />\n        <span className=\"pointer-events-none absolute inset-0 block\" style={{ background: \"linear-gradient(180deg,rgba(0,0,0,0.3) 0,rgba(0,0,0,0) 5px,rgba(0,0,0,0) calc(100% - 3px),rgba(255,255,255,0.7) 100%)\" }} />\n        {/* wet gloss paint: a soft bar of sky that slides along the arm as it turns */}\n        <span className=\"pointer-events-none absolute inset-0 block\" style={{ background: \"linear-gradient(100deg,rgba(255,255,255,0) 30%,rgba(255,255,255,0.75) 47%,rgba(255,255,255,0.1) 53%,rgba(255,255,255,0) 70%)\", backgroundSize: \"220% 100%\", backgroundPosition: \"var(--gloss,50%) 0\", opacity: 0.7 }} />\n        <span className=\"pointer-events-none absolute inset-0 block\" style={{ background: \"#1a2026\", opacity: \"var(--shade,0)\" }} />\n      </span>\n      {/* the two bolts that clamp the arm to its collar */}\n      {[0.27, 0.73].map((y) => (\n        <span key={y} className=\"absolute block rounded-full\" style={{ width: 8, height: 8, top: `calc(${y * 100}% - 4px)`, [back ? \"right\" : \"left\"]: L.post * 0.36, background: \"radial-gradient(circle at 35% 30%,#8d9196,#2a2c2e 55%,#050505)\", boxShadow: \"0 1px 1px rgba(0,0,0,0.5)\" }} />\n      ))}\n    </span>\n  );\n\n  return (\n    <div ref={frame} className=\"relative w-full overflow-clip bg-[#dfe4df]\" style={{ minHeight: L.H * scale }}>\n      <style>{`\n        .finger-post-arm:focus-visible .finger-post-ring { opacity: 1; }\n        @media (prefers-reduced-motion: reduce) { .finger-post-note { transition: none !important; } }\n      `}</style>\n      {/* a hazy morning: sky, far hills out of focus, grain */}\n      <div className=\"pointer-events-none absolute inset-0\" style={{ background: \"radial-gradient(120% 80% at 50% 8%,#f3f4ee 0%,#e3e8e3 45%,#cfd8d2 100%)\" }} />\n      <div className=\"pointer-events-none absolute inset-x-[-10%] bottom-[-8%] h-[30%] rounded-[50%] bg-[#a9b8ac]\" style={{ filter: \"blur(38px)\", opacity: 0.75 }} />\n      <div className=\"pointer-events-none absolute bottom-[-12%] left-[38%] h-[26%] w-[80%] rounded-[50%] bg-[#8fa294]\" style={{ filter: \"blur(46px)\", opacity: 0.7 }} />\n      <div className=\"pointer-events-none absolute inset-0 opacity-[0.22] mix-blend-multiply\" style={{ backgroundImage: GRAIN }} />\n\n      <div className=\"absolute left-1/2 top-0\" style={{ width: L.W, height: L.H, marginLeft: -(L.W * scale) / 2, transform: `scale(${scale})`, transformOrigin: \"0 0\" }}>\n        <div className=\"absolute inset-0\" style={{ perspective: 1500, perspectiveOrigin: `50% ${L.top - 40}px` }}>\n          <div className=\"pointer-events-none absolute inset-0\" style={{ transformStyle: \"preserve-3d\" }}>\n            {/* the post: white gloss over cast iron, black bands at the foot */}\n            <div className=\"absolute\" style={{ left: L.cx - L.post / 2, top: L.top - L.h / 2 - 34, width: L.post, bottom: -4, background: WHITE, boxShadow: \"0 0 0 0.5px rgba(40,40,30,0.5)\" }}>\n              <div className=\"absolute inset-0 opacity-[0.16] mix-blend-multiply\" style={{ backgroundImage: GRAIN, backgroundSize: \"120px 120px\" }} />\n              {[0, 2].map((b) => (\n                <div key={b} className=\"absolute inset-x-[-1px]\" style={{ top: L.pitch * (places.length - 1) + L.h + 86 + b * 56, height: 56, background: IRON }} />\n              ))}\n            </div>\n            {/* finial: a stepped cap and a painted ball */}\n            <div className=\"absolute rounded-[3px]\" style={{ left: L.cx - L.post / 2 - 5, top: L.top - L.h / 2 - 42, width: L.post + 10, height: 10, background: IRON, boxShadow: \"0 2px 3px rgba(0,0,0,0.35)\" }} />\n            <div className=\"absolute\" style={{ left: L.cx - 5, top: L.top - L.h / 2 - 54, width: 10, height: 14, background: IRON }} />\n            <div className=\"absolute rounded-full\" style={{ left: L.cx - L.post * 0.62, top: L.top - L.h / 2 - 54 - L.post * 1.16, width: L.post * 1.24, height: L.post * 1.24, background: \"radial-gradient(circle at 34% 26%,#ffffff 0%,#ffffff 9%,#f6f3e9 24%,#dedbce 55%,#a5a59a 84%,#7c7d75 100%)\", boxShadow: \"inset -2px -3px 5px rgba(0,0,0,0.25), 0 2px 3px rgba(0,0,0,0.3)\" }}>\n              <div className=\"absolute inset-0 rounded-full opacity-[0.14] mix-blend-multiply\" style={{ backgroundImage: GRAIN, backgroundSize: \"90px 90px\" }} />\n            </div>\n            {/* one iron collar per arm */}\n            {places.map((p, i) => (\n              <div key={p.label} className=\"absolute rounded-[4px]\" style={{ left: L.cx - L.post / 2 - 6, top: L.top + i * L.pitch - L.h / 2 - 5, width: L.post + 12, height: L.h + 10, background: IRON, boxShadow: \"inset 0 1.5px 0 rgba(255,255,255,0.28), inset 0 -2px 0 rgba(0,0,0,0.6), 0 3px 4px rgba(0,0,0,0.35)\" }} />\n            ))}\n\n            <nav aria-label=\"Main\" className=\"absolute inset-0\" style={{ transformStyle: \"preserve-3d\" }}>\n              <ul className=\"absolute inset-0 m-0 list-none p-0\" style={{ transformStyle: \"preserve-3d\" }}>\n                {places.map((p, i) => (\n                  <li\n                    key={p.label}\n                    ref={(n) => { arms.current[i] = n; }}\n                    className=\"absolute\"\n                    style={{ left: L.cx, top: L.top + i * L.pitch - L.h / 2, width: L.len, height: L.h, transformOrigin: \"0 50%\", transformStyle: \"preserve-3d\", transform: `rotateY(${-(i === START ? 0 : AWAY[i % AWAY.length])}deg)`, willChange: \"transform\" }}\n                  >\n                    <a\n                      href=\"#\"\n                      aria-current={i === chosen ? \"page\" : undefined}\n                      onClick={(e) => { e.preventDefault(); point(i); }}\n                      onPointerEnter={() => lean(i)}\n                      onPointerLeave={() => lean(-1)}\n                      onFocus={() => lean(i)}\n                      onBlur={() => lean(-1)}\n                      className=\"finger-post-arm pointer-events-auto absolute block outline-none focus-visible:outline-none\"\n                      style={{ left: hub, right: 0, top: 0, bottom: 0, transformStyle: \"preserve-3d\" }}\n                    >\n                      {face(p, false)}\n                      {face(p, true)}\n                      {/* the top edge of the casting, seen from slightly above */}\n                      <span aria-hidden=\"true\" className=\"absolute left-0 block\" style={{ top: 0, right: L.tip, height: 8, transformOrigin: \"50% 0\", transform: \"translateZ(4px) rotateX(-90deg)\", background: \"linear-gradient(180deg,#2b2d30,#0c0d0e)\" }} />\n                      <span aria-hidden=\"true\" className=\"finger-post-ring pointer-events-none absolute -inset-2 block rounded-lg border-[3px] border-[#c2410c] opacity-0\" style={{ transform: \"translateZ(14px)\" }} />\n                    </a>\n                  </li>\n                ))}\n              </ul>\n            </nav>\n          </div>\n        </div>\n      </div>\n\n      <p aria-live=\"polite\" className=\"finger-post-note absolute inset-x-0 m-0 text-center font-mono text-[10px] uppercase tracking-[0.12em] sm:text-[11px] sm:tracking-[0.18em] text-[#3b4640]\" style={{ bottom: 22 }}>\n        <span className=\"inline-block rounded-full bg-[#eef1ec]/90 px-4 py-2 shadow-[0_1px_0_rgba(255,255,255,0.8)_inset,0_6px_18px_-8px_rgba(40,60,50,0.5)]\">\n          <b className=\"font-bold text-[#15171a]\">{places[chosen].label}</b>\n          <span className=\"mx-2 text-[#7b8a82]\">/</span>\n          {places[chosen].note}\n        </span>\n      </p>\n    </div>\n  );\n}\n"}]}
