{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"steel-roller-shutter-stencilled-draft-that-rattles-up-to-show-a-lit-shop-window-holding-the-live-site","type":"registry:block","title":"Steel Roller Shutter Stencilled Draft That Rattles Up to Show a Lit Shop Window Holding the Live Site","description":"Publish toggle as a shopfront: a shutter marked DRAFT rattles up and the live site stands in the window. Free React and HTML code.","dependencies":[],"files":[{"path":"components/we-inc/steel-roller-shutter-stencilled-draft-that-rattles-up-to-show-a-lit-shop-window-holding-the-live-site.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// The site in the window. An invented bakery.\nconst site = {\n  name: \"Oat Street Bakery\",\n  links: [\"Bread\", \"Pastry\", \"Find us\"],\n  headline: \"Bread out of the oven at seven.\",\n  copy: \"Sourdough, rye and seeded loaves, baked through the night on Oat Street.\",\n  cta: \"See today's bake\",\n  photo: \"https://images.pexels.com/photos/30884563/pexels-photo-30884563.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n};\nconst STENCIL = \"DRAFT\"; // painted on the shutter\nconst BLUE = \"#4F98FB\";\nconst FONT = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\n\nconst W = 640; // width of the shutter box\nconst OW = 584, OH = 420; // the window opening\nconst SLAT = 24; // height of one slat\nconst TRAVEL = OH - 22; // the bottom rail stays in sight under the box\nconst HOLD = 9000; // how long the demo stays open before pulling the shutter down again\n\ntype Api = { set: (open: boolean) => void };\n\nexport default function SteelRollerShutter() {\n  const stage = useRef<HTMLDivElement>(null);\n  const root = useRef<HTMLDivElement>(null);\n  const curtain = useRef<HTMLDivElement>(null);\n  const api = useRef<Api | null>(null);\n  const [zoom, setZoom] = useState(1);\n  const [live, setLive] = useState(false);\n\n  useEffect(() => {\n    const st = stage.current, el = root.current, cur = curtain.current;\n    if (!st || !el || !cur) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const scale = () => Math.max(0.46, Math.min(1.08, (st.clientWidth - 16) / (W + 36)));\n    const fit = () => setZoom(scale());\n    fit();\n    const ro = new ResizeObserver(fit);\n    ro.observe(st);\n\n    // p: 0 shut, 1 fully rolled up. lit: how bright the shop lights are.\n    const s = { p: reduce ? 1 : 0, v: 0, to: reduce ? 1 : 0, drag: false, grabY: 0, grabP: 0, lastY: 0, lastT: 0, on: reduce, onAt: -1e9, lit: reduce ? 1 : 0, shake: 0, touched: -1e9, live: false };\n    const paint = () => {\n      el.style.setProperty(\"--p\", s.p.toFixed(4));\n      el.style.setProperty(\"--lit\", s.lit.toFixed(3));\n      cur.style.transform = `translate(${s.shake.toFixed(2)}px, ${(-s.p * TRAVEL).toFixed(2)}px)`;\n    };\n    const tell = () => { const now = s.to === 1; if (now !== s.live) { s.live = now; setLive(now); } };\n\n    let raf = 0, last = 0, seen = true, timer = 0, begin = () => {};\n    const frame = (now: number) => {\n      raf = 0;\n      const dt = Math.max(0.004, Math.min(0.032, (now - last) / 1000 || 0.016)); last = now;\n      if (!s.drag) {\n        // sprung roller going up, dead weight coming down, and a stop at each end that it bounces off\n        const pull = s.to === 1 ? 13 * (1.08 - s.p) + 1 : -5.5 - 16 * s.p;\n        s.v += (pull - 3.4 * s.v) * dt; s.p += s.v * dt;\n        if (s.p > 1) { s.p = 1; if (s.v > 0.25) s.shake = 2.6; s.v = s.v > 0.3 ? -s.v * 0.24 : 0; }\n        if (s.p < 0) { s.p = 0; if (s.v < -0.25) s.shake = 3.4; s.v = s.v < -0.3 ? -s.v * 0.2 : 0; }\n      }\n      s.shake *= -0.72; if (Math.abs(s.shake) < 0.08) s.shake = 0;\n      // the tubes inside catch a moment after the shutter clears them, and go out when it shuts\n      if (!s.on && s.p > 0.1) { s.on = true; s.onAt = now; }\n      if (s.on && s.p < 0.015 && s.to === 0) s.on = false;\n      const t = now - s.onAt;\n      s.lit = !s.on ? 0 : t < 70 ? 0.55 : t < 150 ? 0.08 : t < 230 ? 0.8 : t < 320 ? 0.3 : t < 380 ? 0.9 : 1;\n      paint();\n      const rest = !s.drag && s.shake === 0 && Math.abs(s.v) < 0.004 && (s.p === 0 || s.p === 1 || Math.abs(s.p - s.to) < 0.001) && (!s.on || t > 400);\n      if (rest) return;\n      if (seen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!raf) { last = performance.now(); raf = requestAnimationFrame(frame); } };\n    const go = (open: boolean) => {\n      s.to = open ? 1 : 0; tell();\n      if (reduce) { s.p = s.to; s.on = open; s.lit = open ? 1 : 0; paint(); return; }\n      s.v += open ? 0.5 : -0.2; wake();\n    };\n    api.current = { set: (open) => { s.touched = performance.now(); go(open); } };\n\n    const down = (e: PointerEvent) => {\n      if (reduce) return;\n      s.drag = true; s.touched = performance.now(); s.grabY = e.clientY; s.grabP = s.p; s.lastY = e.clientY; s.lastT = performance.now(); s.v = 0;\n      cur.setPointerCapture(e.pointerId); wake();\n    };\n    const move = (e: PointerEvent) => {\n      if (!s.drag) return;\n      const now = performance.now(), next = Math.max(0, Math.min(1, s.grabP - (e.clientY - s.grabY) / (TRAVEL * scale())));\n      s.v = ((next - s.p) / Math.max(0.008, (now - s.lastT) / 1000)) * 0.5; s.p = next; s.lastT = now;\n    };\n    const up = () => {\n      if (!s.drag) return;\n      s.drag = false; s.touched = performance.now();\n      s.v = Math.max(-2.5, Math.min(2.5, s.v));\n      s.to = s.v > 0.5 || (s.v > -0.5 && s.p > 0.4) ? 1 : 0; tell(); wake();\n    };\n    cur.addEventListener(\"pointerdown\", down);\n    cur.addEventListener(\"pointermove\", move);\n    window.addEventListener(\"pointerup\", up);\n    window.addEventListener(\"pointercancel\", up);\n\n    paint(); tell();\n    if (reduce) { s.to = 1; tell(); }\n    else {\n      // The demo: up, hold, down, wait. It stands down while someone is using the shutter.\n      const loop = (wait: number, open: boolean) => { timer = window.setTimeout(() => { if (seen && !document.hidden && performance.now() - s.touched > 8000) go(open); loop(open ? HOLD : 2400, !open); }, wait); };\n      // wait for the photograph, so the first thing anyone sees open is a finished window\n      begin = () => loop(380, true);\n      if (document.readyState === \"complete\") begin(); else window.addEventListener(\"load\", begin, { once: true });\n    }\n    const io = new IntersectionObserver(([entry]) => { seen = entry.isIntersecting; if (seen && (s.p !== s.to || s.drag)) wake(); });\n    io.observe(st);\n    const vis = () => { if (!document.hidden && s.p !== s.to) wake(); };\n    document.addEventListener(\"visibilitychange\", vis);\n    return () => {\n      cancelAnimationFrame(raf); window.clearTimeout(timer); window.removeEventListener(\"load\", begin); api.current = null;\n      ro.disconnect(); io.disconnect(); document.removeEventListener(\"visibilitychange\", vis);\n      cur.removeEventListener(\"pointerdown\", down); cur.removeEventListener(\"pointermove\", move);\n      window.removeEventListener(\"pointerup\", up); window.removeEventListener(\"pointercancel\", up);\n    };\n  }, []);\n\n  const BW = W + 36, BH = 56 + OH + 16 + 84; // box the whole shopfront is laid out in\n  const L = (BW - OW) / 2; // left edge of the opening\n\n  return (\n    <div\n      className=\"relative flex min-h-[560px] w-full flex-col items-center justify-center overflow-hidden bg-[#0B0D12] bg-[radial-gradient(80%_60%_at_50%_30%,#171B24_0%,#0B0D12_60%,#06070A_100%)] px-2 py-8 text-[#F6F4EF] sm:min-h-[800px]\"\n      style={{ fontFamily: FONT }}\n    >\n      <style>{`\n        .steel-roller-shutter-root { --p: 0; --lit: 0; }\n        @media (prefers-reduced-motion: reduce) { .steel-roller-shutter-root { --p: 1; --lit: 1; } }\n      `}</style>\n      <div ref={stage} className=\"relative flex w-full max-w-[1000px] justify-center\" style={{ height: BH * zoom }}>\n        <div ref={root} className=\"steel-roller-shutter-root relative shrink-0\" style={{ width: BW, height: BH, zoom }}>\n          {/* light the open shop throws on the wall round it and on the pavement */}\n          <div aria-hidden=\"true\" className=\"pointer-events-none absolute\" style={{ left: L - 150, top: -40, width: OW + 300, height: OH + 220, background: \"radial-gradient(closest-side,rgba(255,226,170,0.2),rgba(255,226,170,0.05) 60%,rgba(255,226,170,0))\", opacity: \"calc(var(--p) * var(--lit))\" }} />\n          <div aria-hidden=\"true\" className=\"pointer-events-none absolute\" style={{ left: L - 90, top: 56 + OH + 16, width: OW + 180, height: 84, clipPath: \"polygon(15% 0,85% 0,100% 100%,0 100%)\", background: \"linear-gradient(180deg,rgba(255,232,186,0.5),rgba(255,232,186,0.12) 55%,rgba(255,232,186,0))\", filter: \"blur(5px)\", opacity: \"calc(var(--p) * var(--lit))\" }} />\n\n          {/* the window: plate glass with the site standing in it */}\n          <div className=\"absolute overflow-hidden bg-[#14110c]\" style={{ left: L, top: 50, width: OW, height: OH + 6 }}>\n            <div role=\"img\" aria-label={`The ${site.name} homepage on show in a shop window`} className=\"absolute inset-0 bg-[#F6F4EF] text-[#0B0D12]\">\n              <div className=\"absolute left-[26px] right-[26px] top-[36px] flex h-[34px] items-center justify-between\">\n                <span className=\"flex items-center gap-[7px] whitespace-nowrap text-[14px] font-extrabold tracking-[-0.03em]\"><span className=\"h-[10px] w-[10px] rounded-full\" style={{ background: BLUE }} />{site.name}</span>\n                <span className=\"flex gap-[18px] text-[11.5px] font-bold text-[#0B0D12]/70\">{site.links.map((l) => <span key={l}>{l}</span>)}</span>\n              </div>\n              <div className=\"absolute left-[26px] top-[112px] w-[262px] text-[45px] font-extrabold leading-[0.95] tracking-[-0.05em]\">{site.headline}</div>\n              <div className=\"absolute left-[26px] top-[264px] w-[240px] text-[13px] font-semibold leading-[1.38] text-[#0B0D12]/70\">{site.copy}</div>\n              <div className=\"absolute left-[26px] top-[338px] flex h-[42px] items-center rounded-full bg-[#0B0D12] px-[20px] text-[13.5px] font-extrabold tracking-[-0.01em] text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.25),0_10px_16px_-10px_rgba(11,13,18,0.7)]\"><span className=\"mr-[8px] h-[7px] w-[7px] rounded-full\" style={{ background: BLUE }} />{site.cta}</div>\n              <div className=\"absolute right-[22px] top-[84px] h-[312px] w-[250px] overflow-hidden rounded-[18px] bg-[#8a5a2b]\">\n                <img src={site.photo} alt=\"\" width={1200} height={800} draggable={false} className=\"h-full w-full object-cover\" style={{ objectPosition: \"30% 40%\" }} />\n              </div>\n            </div>\n            {/* warm tubes overhead, the dark before they catch, and the street in the glass */}\n            <div className=\"absolute inset-0\" style={{ background: \"linear-gradient(180deg,rgba(255,214,150,0.3) 0%,rgba(255,214,150,0.06) 30%,rgba(255,214,150,0) 55%,rgba(40,24,6,0.1) 100%)\", mixBlendMode: \"multiply\" }} />\n            <div className=\"absolute inset-0 bg-[#07080b]\" style={{ opacity: \"calc(0.94 - var(--lit) * 0.94)\" }} />\n            <div className=\"absolute inset-0\" style={{ background: \"linear-gradient(104deg,rgba(255,255,255,0) 18%,rgba(190,214,255,0.16) 30%,rgba(255,255,255,0.03) 37%,rgba(255,255,255,0) 52%,rgba(190,214,255,0.1) 70%,rgba(255,255,255,0) 82%)\" }} />\n            <div className=\"absolute inset-0\" style={{ boxShadow: \"inset 0 0 0 2px #0a0b0e, inset 0 0 0 5px #2b2f36, inset 0 0 0 6px #0a0b0e, inset 0 26px 30px -18px rgba(0,0,0,0.75)\" }} />\n\n            {/* the shutter curtain */}\n            <div ref={curtain} className=\"absolute left-0 top-0 touch-none select-none\" style={{ width: OW, height: OH + 6, cursor: \"grab\", willChange: \"transform\" }}>\n              <div className=\"absolute inset-x-0 top-0\" style={{ height: OH - 22, backgroundColor: \"#565b63\", backgroundImage: `repeating-linear-gradient(180deg,#2c3037 0px,#a7adb5 2px,#8a9098 5px,#6b7179 11px,#4d525a 17px,#2a2d33 20.5px,#0b0c0f 22px,#08090b 23px,#2c3037 ${SLAT}px)` }}>\n                {/* wear: long streaks, a soft sheen, and the shadow of the box above */}\n                <div className=\"absolute inset-0 opacity-70\" style={{ backgroundImage: \"repeating-linear-gradient(90deg,rgba(255,255,255,0) 0 31px,rgba(255,255,255,0.05) 31px 33px,rgba(255,255,255,0) 33px 71px,rgba(0,0,0,0.1) 71px 74px,rgba(255,255,255,0) 74px 113px),linear-gradient(100deg,rgba(255,255,255,0) 20%,rgba(200,220,255,0.13) 38%,rgba(255,255,255,0) 54%,rgba(0,0,0,0.14) 100%)\" }} />\n                <div aria-hidden=\"true\" className=\"absolute inset-x-0 flex items-center justify-center\" style={{ top: 96, height: 168, WebkitMaskImage: `repeating-linear-gradient(180deg,#000 0 18px,rgba(0,0,0,0.35) 18px ${SLAT}px)`, maskImage: `repeating-linear-gradient(180deg,#000 0 18px,rgba(0,0,0,0.35) 18px ${SLAT}px)` }}>\n                  <span className=\"text-[136px] font-black leading-none tracking-[0.02em]\" style={{ color: \"rgba(246,244,239,0.86)\", textShadow: \"0 1px 0 rgba(0,0,0,0.35)\" }}>{STENCIL}</span>\n                </div>\n              </div>\n              {/* bottom rail with a pull handle and two shoot bolts */}\n              <div className=\"absolute inset-x-0\" style={{ top: OH - 22, height: 24, background: \"linear-gradient(180deg,#c3c8ce 0%,#8d939b 18%,#5d626a 55%,#383c43 86%,#17191d 100%)\", boxShadow: \"0 8px 12px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.6)\" }}>\n                <div className=\"absolute left-1/2 top-[6px] h-[12px] w-[92px] -translate-x-1/2 rounded-full\" style={{ background: \"linear-gradient(180deg,#0a0b0d,#2a2d33)\", boxShadow: \"inset 0 2px 3px rgba(0,0,0,0.9), 0 1px 0 rgba(255,255,255,0.45)\" }} />\n                {[18, OW - 30].map((x) => <span key={x} className=\"absolute top-[6px] h-[12px] w-[12px] rounded-full\" style={{ left: x, background: \"radial-gradient(circle at 36% 30%,#f2f4f6,#8a9098 45%,#2e3238)\", boxShadow: \"0 1px 1px rgba(0,0,0,0.7)\" }} />)}\n              </div>\n              <div className=\"absolute inset-x-0 bg-[#050608]\" style={{ top: OH + 2, height: 4 }} />\n            </div>\n          </div>\n\n          {/* guide rails, sill and the box the shutter rolls into */}\n          {[L - 14, L + OW - 2].map((x) => (\n            <div key={x} aria-hidden=\"true\" className=\"absolute\" style={{ left: x, top: 50, width: 16, height: OH + 8, background: \"linear-gradient(90deg,#1c1f24 0%,#8e949c 22%,#5a5f67 48%,#30343a 70%,#9197a0 86%,#22252a 100%)\", boxShadow: \"0 0 0 0.5px #000, 4px 0 8px -2px rgba(0,0,0,0.5)\" }} />\n          ))}\n          <div aria-hidden=\"true\" className=\"absolute\" style={{ left: L - 26, top: 56 + OH, width: OW + 52, height: 16, background: \"linear-gradient(180deg,#3a3d44 0%,#24262b 40%,#101114 100%)\", boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.22), 0 10px 14px rgba(0,0,0,0.6)\" }}>\n            <div className=\"absolute inset-0\" style={{ background: \"linear-gradient(180deg,rgba(255,226,170,0.55),rgba(255,226,170,0.1))\", opacity: \"calc(var(--p) * var(--lit))\" }} />\n          </div>\n          <div aria-hidden=\"true\" className=\"absolute rounded-[5px]\" style={{ left: (BW - W) / 2, top: 0, width: W, height: 56, background: \"linear-gradient(180deg,#6d737b 0%,#aeb4bc 7%,#858b93 20%,#5b6068 48%,#3a3e45 82%,#1e2025 100%)\", boxShadow: \"inset 0 0 0 1px rgba(0,0,0,0.75), inset 0 1.5px 0 rgba(255,255,255,0.5), 0 14px 20px -4px rgba(0,0,0,0.75)\" }}>\n            <div className=\"absolute inset-0 rounded-[5px] opacity-50\" style={{ backgroundImage: \"repeating-linear-gradient(0deg,rgba(255,255,255,0.1) 0 1px,rgba(0,0,0,0.12) 1px 2px)\" }} />\n            {[0, W - 22].map((x) => <div key={x} className=\"absolute top-0 h-full w-[22px]\" style={{ left: x, background: \"linear-gradient(90deg,rgba(0,0,0,0.35),rgba(255,255,255,0.14) 40%,rgba(0,0,0,0.4))\", borderRadius: 5 }} />)}\n            {[34, 220, W - 232, W - 46].map((x) => <span key={x} className=\"absolute top-[10px] h-[7px] w-[7px] rounded-full\" style={{ left: x, background: \"radial-gradient(circle at 36% 30%,#f2f4f6,#737981 55%,#22252a)\", boxShadow: \"0 1px 1px rgba(0,0,0,0.8)\" }} />)}\n            {/* pilot lamp: dark while the site is a draft, blue once it is open */}\n            <div className=\"absolute left-1/2 top-[15px] flex h-[26px] -translate-x-1/2 items-center gap-[9px] rounded-full bg-[#0b0c0f] pl-[8px] pr-[13px]\" style={{ boxShadow: \"inset 0 1px 2px rgba(0,0,0,0.9), 0 1px 0 rgba(255,255,255,0.3)\" }}>\n              <span className=\"relative block h-[12px] w-[12px] rounded-full\" style={{ background: \"radial-gradient(circle at 36% 30%,#3a4352,#12151b 70%)\", boxShadow: \"inset 0 0 0 1px #000\" }}>\n                <span className=\"absolute inset-0 rounded-full\" style={{ background: \"radial-gradient(circle at 36% 30%,#ffffff 0%,#a9d0ff 22%,#4F98FB 55%,#1f63c8 100%)\", boxShadow: \"0 0 10px 3px rgba(79,152,251,0.75), 0 0 28px 10px rgba(79,152,251,0.3)\", opacity: \"calc(var(--p) * var(--lit))\" }} />\n              </span>\n              <span className=\"text-[10px] font-extrabold uppercase tracking-[0.2em]\" style={{ color: live ? \"#F6F4EF\" : \"rgba(246,244,239,0.62)\" }}>{live ? \"Live\" : \"Draft\"}</span>\n            </div>\n          </div>\n        </div>\n      </div>\n\n      <div className=\"relative mt-1 flex items-center gap-[10px]\">\n        <button\n          type=\"button\"\n          aria-pressed={live}\n          onClick={() => api.current?.set(!live)}\n          className=\"flex h-[52px] items-center gap-[10px] rounded-full bg-[#F6F4EF] pl-[20px] pr-[24px] text-[15px] font-extrabold tracking-[-0.01em] text-[#0B0D12] shadow-[inset_0_-3px_0_rgba(11,13,18,0.14),0_18px_30px_-14px_rgba(0,0,0,0.9)] outline-none transition-transform duration-150 active:scale-[0.96] focus-visible:ring-2 focus-visible:ring-[#4F98FB] focus-visible:ring-offset-2 focus-visible:ring-offset-[#0B0D12] motion-reduce:transition-none\"\n        >\n          <span aria-hidden=\"true\" className=\"h-[9px] w-[9px] rounded-full\" style={{ background: live ? BLUE : \"#0B0D12\", boxShadow: live ? \"0 0 0 4px rgba(79,152,251,0.25)\" : \"none\" }} />\n          {live ? \"Back to draft\" : \"Go live\"}\n        </button>\n      </div>\n      <p aria-live=\"polite\" className=\"mt-[12px] text-center text-[12px] font-semibold tracking-[-0.005em] text-[#F6F4EF]/75\">\n        {live ? `${site.name}: shutter up, lights on, open to the street` : \"Draft: finished inside, shutter still down\"}\n      </p>\n    </div>\n  );\n}\n"}]}
