{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"vertical-drag-menu-slider-inside-a-phone-mockup","type":"registry:component","title":"Vertical Drag Menu Slider Inside a Phone Mockup","description":"","dependencies":[],"files":[{"path":"components/we-inc/vertical-drag-menu-slider-inside-a-phone-mockup.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst FRICTION = 0.94; // speed kept each frame after release\nconst RUBBER = 0.3; // how far the screen stretches past the first and last drink\nconst IDLE = 3000; // idle advance until the first interaction\n\nconst drinks = [\n  { name: \"Espresso\", note: \"Double shot, house blend with notes of cocoa and plum.\", price: \"3.20\", src: \"https://images.pexels.com/photos/4921556/pexels-photo-4921556.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"Hands holding a small ceramic cup of espresso, seen from above\" },\n  { name: \"Pour-over\", note: \"Single origin through a cloth filter, brewed to order.\", price: \"4.60\", src: \"https://images.pexels.com/photos/29507967/pexels-photo-29507967.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"Pour-over coffee through a cloth filter beside a cup on a wooden table\" },\n  { name: \"Latte\", note: \"Whole or oat milk, poured with a heart.\", price: \"3.90\", src: \"https://images.pexels.com/photos/459489/pexels-photo-459489.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"Latte with heart latte art in a pale blue cup and saucer\" },\n  { name: \"Iced coffee\", note: \"Slow steeped overnight, served over ice.\", price: \"4.10\", src: \"https://images.pexels.com/photos/39218055/pexels-photo-39218055.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"Glass of iced coffee with a straw on a sunlit table\" },\n  { name: \"Cappuccino\", note: \"Equal thirds, dusted with cocoa if you ask.\", price: \"3.70\", src: \"https://images.pexels.com/photos/997670/pexels-photo-997670.jpeg?auto=compress&cs=tinysrgb&w=700\", alt: \"Cappuccino with latte art in a black mug\" },\n];\n\nexport default function VerticalDragMenuSliderInsideAPhoneMockup() {\n  const root = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const R = root.current;\n    if (!R) return;\n    const sc = R.querySelector<HTMLElement>(\".w2pho-screen\")!, tr = R.querySelector<HTMLElement>(\".w2pho-track\")!;\n    const it = Array.from(R.querySelectorAll<HTMLElement>(\".w2pho-slide\")), dt = Array.from(R.querySelectorAll<HTMLElement>(\".w2pho-dots i\"));\n    const bt = Array.from(R.querySelectorAll<HTMLButtonElement>(\".w2pho-btn\")), lv = R.querySelector<HTMLElement>(\".w2pho-live\")!;\n    const n = it.length;\n    const rm = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let y = 0, v = 0, ty: number | null = 0, raf = 0, dn = false, sy = 0, y0 = 0, lt = 0, cur = 0, vis = true, au = 0, stopped = false;\n    const cl = (i: number) => Math.max(0, Math.min(n - 1, i));\n    const show = (i: number) => {\n      if (i === cur) return;\n      dt[cur].classList.remove(\"w2pho-on\"); dt[i].classList.add(\"w2pho-on\");\n      cur = i;\n      bt[0].disabled = i === 0; bt[1].disabled = i === n - 1;\n      it.forEach((e, k) => e.setAttribute(\"aria-hidden\", String(k !== i)));\n    };\n    // vertical track: drag, coast with friction, then ease onto the nearest drink\n    const loop = () => {\n      raf = 0;\n      const s = sc.offsetHeight, m = -(n - 1) * s;\n      if (!dn) {\n        if (ty == null) { y += v; v *= FRICTION; if (y > 0 || y < m) v *= 0.6; if (Math.abs(v) < 0.5) ty = cl(Math.round(-y / s)); }\n        if (ty != null) { const g = -ty * s; y = rm ? g : y + (g - y) * 0.15; if (Math.abs(g - y) < 0.5) y = g; }\n      }\n      const p = y > 0 ? y * RUBBER : y < m ? m + (y - m) * RUBBER : y;\n      tr.style.transform = `translate3d(0,${p}px,0)`;\n      show(cl(Math.round(-p / s)));\n      if (vis && (dn || ty == null || y !== -ty * s)) raf = requestAnimationFrame(loop);\n    };\n    const kick = () => { if (!raf) raf = requestAnimationFrame(loop); };\n    const go = (i: number, say?: boolean) => {\n      ty = cl(i); v = 0; kick();\n      if (say) lv.textContent = `Drink ${ty + 1} of ${n}: ${it[ty].querySelector(\"h3\")!.textContent}`;\n    };\n    const stop = () => { clearTimeout(au); stopped = true; };\n    const up = (e: PointerEvent) => { if (!dn) return; dn = false; if (rm || e.timeStamp - lt > 100) v = 0; ty = null; kick(); };\n    sc.onpointerdown = (e) => { stop(); dn = true; sy = e.clientY; y0 = y; v = 0; sc.setPointerCapture(e.pointerId); kick(); };\n    sc.onpointermove = (e) => { if (!dn) return; const d = e.clientY - sy; v = v * 0.5 + (y0 + d - y) * 0.5; y = y0 + d; lt = e.timeStamp; kick(); };\n    sc.onpointerup = sc.onpointercancel = up;\n    bt.forEach((b) => { b.onclick = () => { stop(); go(cur + Number(b.dataset.d), true); }; });\n    const keys: Record<string, number> = { ArrowUp: -1, ArrowLeft: -1, ArrowDown: 1, ArrowRight: 1 };\n    R.onkeydown = (e) => {\n      const i = e.key === \"Home\" ? 0 : e.key === \"End\" ? n - 1 : e.key in keys ? cur + keys[e.key] : null;\n      if (i == null) return;\n      e.preventDefault(); stop(); go(i, true);\n    };\n    R.onpointerenter = stop;\n    R.addEventListener(\"focusin\", stop);\n    const tick = () => { if (stopped) return; if (vis) go((cur + 1) % n); au = window.setTimeout(tick, IDLE); };\n    const start = () => { if (!stopped) au = window.setTimeout(tick, 2200); };\n    if (!rm) { if (document.readyState === \"complete\") start(); else window.addEventListener(\"load\", start); }\n    const io = new IntersectionObserver(([e]) => { vis = e.isIntersecting; if (vis) kick(); });\n    io.observe(R);\n    return () => {\n      stop(); io.disconnect(); cancelAnimationFrame(raf); window.removeEventListener(\"load\", start);\n      sc.onpointerdown = sc.onpointermove = sc.onpointerup = sc.onpointercancel = null;\n      bt.forEach((b) => { b.onclick = null; });\n      R.onkeydown = null; R.onpointerenter = null; R.removeEventListener(\"focusin\", stop);\n    };\n  }, []);\n\n  return (\n    <section ref={root} role=\"region\" aria-roledescription=\"carousel\" aria-label=\"Marrow Coffee menu\" className=\"overflow-hidden bg-[#26282c] px-4 py-14 text-[#f1ece4]\">\n      <style>{`\n        .w2pho-screen { touch-action: pan-x; cursor: grab; user-select: none; }\n        .w2pho-track { will-change: transform; }\n        .w2pho-screen:focus-visible, .w2pho-btn:focus-visible { outline: 2px solid #d79a6a; outline-offset: 4px; }\n        .w2pho-btn:disabled { opacity: .3; cursor: default; }\n        .w2pho-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.55); box-shadow: 0 0 0 1px rgba(0,0,0,.15); transition: transform .3s; }\n        .w2pho-dots i.w2pho-on { background: #fff; transform: scale(1.5); }\n        @media (prefers-reduced-motion: reduce) { .w2pho-dots i { transition: none; } }\n      `}</style>\n      <div className=\"mx-auto grid max-w-[940px] grid-cols-[minmax(0,1fr)] items-center gap-10 md:grid-cols-[minmax(0,1fr)_auto] md:gap-16\">\n        <div>\n          <p className=\"text-xs font-semibold uppercase tracking-[0.24em] text-[#d79a6a]\">Marrow Coffee, Leith Walk</p>\n          <h2 className=\"mt-3 text-[28px] font-semibold leading-tight tracking-tight sm:text-[42px]\">The bar menu, one drink per screen</h2>\n          <p className=\"mt-4 max-w-md text-base leading-relaxed text-[#c3bdb3]\">Swipe up and down inside the phone, or use the buttons and arrow keys. A quick flick carries on for a drink or two before it settles.</p>\n          <div className=\"mt-7 flex gap-2.5\">\n            {[-1, 1].map((d) => (\n              <button key={d} type=\"button\" data-d={d} disabled={d < 0} aria-label={d < 0 ? \"Previous drink\" : \"Next drink\"} className=\"w2pho-btn grid h-12 w-12 place-items-center rounded-[14px] border border-[#f1ece4]/30 hover:bg-[#f1ece4]/10\">\n                <svg viewBox=\"0 0 24 24\" width=\"20\" height=\"20\" aria-hidden=\"true\"><path d={d < 0 ? \"M5 15l7-7 7 7\" : \"M5 9l7 7 7-7\"} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" /></svg>\n              </button>\n            ))}\n          </div>\n        </div>\n        <div className=\"box-border h-[550px] w-[270px] justify-self-center rounded-[46px] bg-[#0e0f11] p-3 shadow-[0_0_0_2px_#3a3d42,0_40px_80px_-30px_rgba(0,0,0,.8)] min-[381px]:h-[590px] min-[381px]:w-[290px]\">\n          <div className=\"w2pho-screen relative h-full w-full overflow-hidden rounded-[34px] bg-[#f6f1ea]\" tabIndex={0}>\n            <ol className=\"w2pho-track m-0 h-full list-none p-0\">\n              {drinks.map((d, i) => (\n                <li key={d.name} className=\"w2pho-slide relative h-full text-[#26282c]\" role=\"group\" aria-roledescription=\"slide\" aria-label={`${i + 1} of ${drinks.length}`} aria-hidden={i > 0}>\n                  <img src={d.src} alt={d.alt} draggable={false} className=\"pointer-events-none block h-[70%] w-full object-cover\" />\n                  <div className=\"px-[22px] py-5\">\n                    <div className=\"flex items-baseline justify-between gap-3\">\n                      <h3 className=\"text-2xl font-semibold tracking-tight\">{d.name}</h3>\n                      <span className=\"text-base font-bold text-[#8a4f26]\">{d.price}</span>\n                    </div>\n                    <p className=\"mt-1.5 text-sm leading-normal text-[#55514b]\">{d.note}</p>\n                  </div>\n                </li>\n              ))}\n            </ol>\n            <div className=\"w2pho-dots absolute right-2.5 top-1/2 grid -translate-y-1/2 gap-1.5\" aria-hidden=\"true\">\n              {drinks.map((d, i) => <i key={d.name} className={i === 0 ? \"w2pho-on\" : \"\"} />)}\n            </div>\n          </div>\n        </div>\n        <p className=\"w2pho-live sr-only\" aria-live=\"polite\" />\n      </div>\n    </section>\n  );\n}\n"}]}
