{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"new-page-slides-up-over-the-old-one","type":"registry:block","title":"New Page Slides Up Over the Old One","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/new-page-slides-up-over-the-old-one.tsx","type":"registry:component","content":"import { useEffect, useLayoutEffect, useRef, useState, type MouseEvent } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Same styles as the plain HTML version; the comment at the top of STYLES names the values to change.\nconst STYLES = `\n  /* Change these: --w6stk-bg, --w6stk-ink, --w6stk-stone (accent), the .55s / .6s durations and the .92 scale\n     in the w6stk keyframes (how far the page underneath sinks back). */\n  .w6stk { --w6stk-bg: #1c1d1f; --w6stk-ink: #ece8e2; --w6stk-stone: #cdbca4;\n    height: 620px; display: flex; flex-direction: column; background: var(--w6stk-bg); color: var(--w6stk-ink);\n    font-family: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; overflow: hidden; }\n  .w6stk *, .w6stk *::before { box-sizing: border-box; }\n  .w6stk-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 24px; padding: 16px clamp(16px, 4vw, 44px); }\n  .w6stk-brand { margin: 0; font-size: .9375rem; font-weight: 600; letter-spacing: .02em; }\n  .w6stk-brand span { font-weight: 400; color: #a9a39b; }\n  .w6stk-nav { display: flex; gap: 4px; margin: 0 -10px; padding: 0; list-style: none; }\n  .w6stk-nav a { display: inline-flex; align-items: baseline; gap: 6px; min-height: 40px; padding: 10px; color: #b9b3ab; font-size: .9375rem; text-decoration: none; border-radius: 6px; }\n  .w6stk-nav small { font-size: .6875rem; color: #8d877f; font-variant-numeric: tabular-nums; }\n  .w6stk-nav a:hover, .w6stk-nav a[aria-current=\"page\"] { color: var(--w6stk-ink); }\n  .w6stk-nav a[aria-current=\"page\"] small { color: var(--w6stk-stone); }\n  .w6stk a:focus-visible, .w6stk h2:focus-visible { outline: 2px solid var(--w6stk-stone); outline-offset: 3px; }\n  .w6stk h2:focus { outline: none; }\n  .w6stk-stage { position: relative; flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; }\n  .w6stk-view { min-height: 100%; display: grid; background: #26272a; border-top: 1px solid #3a3b3f; }\n  .w6stk-view[hidden] { display: none; }\n  .w6stk-pic { overflow: hidden; aspect-ratio: 16 / 9; background: #333; }\n  .w6stk-pic img { display: block; width: 100%; height: 100%; object-fit: cover; }\n  .w6stk-txt { padding: 24px clamp(16px, 4vw, 44px) 28px; }\n  .w6stk-eye { margin: 0; font-size: .75rem; letter-spacing: .18em; text-transform: uppercase; color: var(--w6stk-stone); }\n  .w6stk h2 { margin: 10px 0 0; font-size: clamp(1.6rem, 3.2vw, 2.4rem); font-weight: 500; line-height: 1.1; letter-spacing: -.02em; max-width: 16ch; }\n  .w6stk-txt > p:not(.w6stk-eye) { margin: 14px 0 0; max-width: 32rem; font-size: 1rem; line-height: 1.6; color: #c9c4bc; }\n  .w6stk-facts { margin: 20px 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; border-top: 1px solid #3f4044; padding-top: 14px; }\n  .w6stk-facts dt { font-size: .75rem; color: #9d978f; }\n  .w6stk-facts dd { margin: 4px 0 0; font-size: .875rem; }\n  .w6stk-more { display: inline-flex; align-items: center; min-height: 44px; margin-top: 18px; padding: 0 18px; border: 1px solid #5a5b60; border-radius: 999px;\n    color: var(--w6stk-ink); font-size: .875rem; text-decoration: none; }\n  .w6stk-more:hover { border-color: var(--w6stk-stone); }\n  .w6stk-more::after { content: \"→\"; margin-left: 10px; color: var(--w6stk-stone); }\n  @media (min-width: 860px) {\n    .w6stk-view { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }\n    .w6stk-pic { aspect-ratio: auto; height: 100%; }\n    .w6stk-txt { align-self: center; padding: 32px 44px; }\n  }\n  @media (max-width: 480px) { .w6stk-facts { grid-template-columns: 1fr 1fr; } }\n\n  /* Forward: the new page slides up over the old one, which sinks back and darkens. Back: the top page slides away\n     downwards and the one underneath comes forward. Only the stage is named, and only during the change.\n     Separate pages: add  @view-transition { navigation: auto; }  and name the main element on every page. */\n  ::view-transition-group(w6stk-stage) { animation: none; overflow: clip; }\n  ::view-transition-old(w6stk-stage), ::view-transition-new(w6stk-stage) { mix-blend-mode: normal; }\n  ::view-transition-old(w6stk-stage) { animation: w6stk-sink .6s cubic-bezier(.3, 0, .2, 1) both; }\n  ::view-transition-new(w6stk-stage) { animation: w6stk-rise .6s cubic-bezier(.2, .8, .2, 1) both; }\n  :root[data-w6stk-dir=\"b\"]::view-transition-old(w6stk-stage) { z-index: 1; animation: w6stk-drop .55s cubic-bezier(.5, 0, .7, .4) both; }\n  :root[data-w6stk-dir=\"b\"]::view-transition-new(w6stk-stage) { animation: w6stk-lift .6s cubic-bezier(.2, .8, .2, 1) both; }\n  @keyframes w6stk-sink { to { transform: scale(.92); opacity: .25; } }\n  @keyframes w6stk-rise { from { transform: translateY(100%); } }\n  @keyframes w6stk-drop { to { transform: translateY(100%); } }\n  @keyframes w6stk-lift { from { transform: scale(.92); opacity: .25; } }\n  /* Fallback without view transitions: the new page rises a little and fades in. */\n  @keyframes w6stk-in { from { transform: translateY(40px); opacity: 0; } }\n  .w6stk[data-fb] .w6stk-view:not([hidden]) { animation: w6stk-in .5s cubic-bezier(.2, .8, .2, 1) both; }\n  @media (prefers-reduced-motion: reduce) {\n    ::view-transition-group(w6stk-stage), ::view-transition-old(w6stk-stage), ::view-transition-new(w6stk-stage) { animation: none; }\n    .w6stk .w6stk-view { animation: none !important; }\n  }\n`;\n\nconst PAGES = [\n  {\n    nav: \"Work\", eye: \"Selected work\", title: \"Houses that sit low in the land\", more: \"How we work\",\n    src: \"https://images.pexels.com/photos/6342356/pexels-photo-6342356.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"A white house with dark window frames on a rocky, planted hillside\",\n    text: \"A family house on a terraced slope, built around the old retaining walls rather than through them, with every room a step lower than the last.\",\n    facts: [[\"Year\", \"2025\"], [\"Area\", \"180 m²\"], [\"Built in\", \"Stone, lime, oak\"]],\n  },\n  {\n    nav: \"Studio\", eye: \"The studio\", title: \"Eleven people in a former print hall\", more: \"Start a project\",\n    src: \"https://images.pexels.com/photos/12780906/pexels-photo-12780906.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"A concrete hallway with lift doors in red frames and long bands of sunlight across the floor\",\n    text: \"Every project starts with a day on site and a model on the long table, and the same two partners stay with it until the keys are handed over.\",\n    facts: [[\"Founded\", \"2011\"], [\"Partners\", \"Ana Marrick, Joel Lowe\"], [\"Projects\", \"Homes, schools, workshops\"]],\n  },\n  {\n    nav: \"Contact\", eye: \"Contact\", title: \"Tell us about the site first\", more: \"Back to the work\",\n    src: \"https://images.pexels.com/photos/27953061/pexels-photo-27953061.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"Two plain white gabled houses against a clear blue sky\",\n    text: \"Send a few photos, the address and roughly what you hope for. We reply within a week, including when we are not the right fit.\",\n    facts: [[\"Phone\", \"020 7946 0321\"], [\"Studio\", \"Unit 4, Coldharbour Yard\"], [\"Hours\", \"Mon to Fri, 9 to 6\"]],\n  },\n];\nconst DEMO = [700, 1700, 3200]; // idle demo: ms before each automatic page change; [] turns it off\nconst useIso = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\nexport default function NewPageSlidesUpOverTheOldOne() {\n  const reduce = useReducedMotion();\n  const [cur, setCur] = useState(0);\n  const [fb, setFb] = useState(false);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const stageRef = useRef<HTMLDivElement>(null);\n  const heads = useRef<(HTMLHeadingElement | null)[]>([]);\n  const st = useRef({ cur: 0, busy: false, auto: DEMO.length > 0, focus: false });\n  const commit = useRef<null | (() => void)>(null);\n\n  // After React writes the new page: let the transition take its \"after\" snapshot, then move focus.\n  useIso(() => {\n    if (stageRef.current) stageRef.current.scrollTop = 0;\n    commit.current?.();\n    commit.current = null;\n    if (st.current.focus) { st.current.focus = false; heads.current[cur]?.focus({ preventScroll: true }); }\n  }, [cur]);\n\n  // A later page lands on top of the stack; an earlier one is uncovered from underneath.\n  const go = (i: number, person: boolean) => {\n    const s = st.current;\n    if (i === s.cur || s.busy) return;\n    const dir = i > s.cur ? \"f\" : \"b\";\n    s.cur = i;\n    s.focus = person;\n    const doc = document as any;\n    if (reduce || matchMedia(\"(prefers-reduced-motion: reduce)\").matches) { setCur(i); return; }\n    if (doc.startViewTransition && stageRef.current) {\n      s.busy = true;\n      const stage = stageRef.current, html = document.documentElement;\n      stage.style.setProperty(\"view-transition-name\", \"w6stk-stage\");\n      html.setAttribute(\"data-w6stk-dir\", dir);\n      doc.startViewTransition(() => new Promise<void>((done) => { commit.current = done; setCur(i); })).finished.finally(() => {\n        stage.style.removeProperty(\"view-transition-name\"); html.removeAttribute(\"data-w6stk-dir\"); s.busy = false;\n      });\n    } else { setFb(true); setCur(i); }\n  };\n  const goRef = useRef(go);\n  goRef.current = go;\n\n  // Idle demo: changes page now and then while the piece is on screen and nobody has used it.\n  useEffect(() => {\n    const root = rootRef.current;\n    if (!root || reduce || !DEMO.length) return;\n    let timer = 0, turns = 0, seen = false;\n    const tick = () => {\n      timer = 0;\n      if (!st.current.auto || !seen) return;\n      goRef.current((st.current.cur + 1) % PAGES.length, false);\n      turns++;\n      timer = window.setTimeout(tick, DEMO[Math.min(turns, DEMO.length - 1)]);\n    };\n    // The demo waits for the page to finish loading, so the first thing anyone sees is the resting view.\n    const kick = () => { if (seen && st.current.auto && !timer && document.readyState === \"complete\") timer = window.setTimeout(tick, DEMO[Math.min(turns, DEMO.length - 1)]); };\n    window.addEventListener(\"load\", kick);\n    const io = new IntersectionObserver((e) => {\n      seen = e[0].isIntersecting;\n      if (seen) kick(); else { clearTimeout(timer); timer = 0; }\n    });\n    io.observe(root);\n    const stop = () => { st.current.auto = false; };\n    root.addEventListener(\"pointerdown\", stop);\n    root.addEventListener(\"keydown\", stop);\n    return () => { io.disconnect(); clearTimeout(timer); window.removeEventListener(\"load\", kick); root.removeEventListener(\"pointerdown\", stop); root.removeEventListener(\"keydown\", stop); };\n  }, [reduce]);\n\n  const link = (i: number) => (e: MouseEvent) => { e.preventDefault(); st.current.auto = false; go(i, true); };\n\n  return (\n    <div className=\"w6stk\" ref={rootRef} data-fb={fb ? \"\" : undefined}>\n      <style>{STYLES}</style>\n      <header className=\"w6stk-top\">\n        <p className=\"w6stk-brand\">Marrick Lowe <span>Architects</span></p>\n        <nav aria-label=\"Practice pages\">\n          <ul className=\"w6stk-nav\">\n            {PAGES.map((p, i) => (\n              <li key={p.nav}>\n                <a href=\"#\" onClick={link(i)} aria-current={i === cur ? \"page\" : undefined}><small>{String(i + 1).padStart(2, \"0\")}</small>{p.nav}</a>\n              </li>\n            ))}\n          </ul>\n        </nav>\n      </header>\n      <div className=\"w6stk-stage\" ref={stageRef}>\n        {PAGES.map((p, i) => (\n          <section key={p.nav} className=\"w6stk-view\" aria-labelledby={`w6stk-h${i}`} hidden={i !== cur}>\n            <div className=\"w6stk-pic\"><img src={p.src} alt={p.alt} width={900} height={600} /></div>\n            <div className=\"w6stk-txt\">\n              <p className=\"w6stk-eye\">{p.eye}</p>\n              <h2 id={`w6stk-h${i}`} tabIndex={-1} ref={(el) => { heads.current[i] = el; }}>{p.title}</h2>\n              <p>{p.text}</p>\n              <dl className=\"w6stk-facts\">\n                {p.facts.map(([a, b]) => <div key={a}><dt>{a}</dt><dd>{b}</dd></div>)}\n              </dl>\n              <a className=\"w6stk-more\" href=\"#\" onClick={link((i + 1) % PAGES.length)}>{p.more}</a>\n            </div>\n          </section>\n        ))}\n      </div>\n    </div>\n  );\n}\n"}]}
