Files
site/components/Phone.jsx
Claude a6d057f246 System: grey and silver tokens, neutral focus ring, one ask bar after the hero at every width
- app/system.css: brand deck tokens (greys, silvers, room tokens that flip under data-room=dark),
  motion and type tokens, metric-matched font fallbacks, skip link, button/link/card/tab/sheet/table
  states, skeleton/empty/error styles, reduced-motion final states
- components/Ask.jsx: one solid ask in Hanzo's words once the hero has gone by; reads data-thumb;
  the header's Try Hanzo turns outline while it shows (one solid on screen)
- globals.css: blue focus and green accents replaced with greys (0 UI hues)
- lib/motion.js: easing, duration and spring tokens

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DqUybA3gCfaruBE8tifYd5
2026-11-07 13:35:39 +00:00

88 lines
5.0 KiB
React

'use client';
/* The phone layer (mounted once in app/layout.jsx; phones and tablets ≤ 900 px only).
(1) The thumb bar now lives in components/Ask.jsx (one ask bar for every width); it still reads data-thumb and
data-dock exactly as before, so nothing on a page changes.
(2) Sibling swipe: a sideways swipe on a family page (a model, a role, a legal document, a repo) turns to the next or
previous one, with a hint that says where you are going; the page turns with a ~550 ms slide.
(3) Sheets: search and the header menus rise from the bottom (components/HeaderTools.jsx).
How to use it on a page:
- data-thumb on your main button or link (<Go to="/contact-sales" data-thumb="Talk to sales">…); see Ask.jsx;
- data-dock on your own fixed bottom bar, and the ask bar steps aside while it is there;
- data-swipe-own on anything that handles its own sideways swipe (rails, tables and carousels that scroll natively
are already left alone). */
import { useEffect, useRef, useState } from 'react';
import { usePathname } from 'next/navigation';
import { MODELS } from '../lib/models';
import './Layer.css';
const FLAG = MODELS.map((m) => '/' + m.slug);
const norm = (p) => '/' + p.split('/').filter(Boolean).join('/');
const wants = (p) => { const s = norm(p).split('/').filter(Boolean); return s.length === 2 || (s.length === 1 && FLAG.includes(norm(p))); };
// the page index is 150 KB, so it loads only on a phone, on a page that has siblings
export function siblings(path, SEARCH) {
const p = norm(path), s = p.split('/').filter(Boolean);
const TITLE = Object.fromEntries(SEARCH.map(([q, t]) => [q, t]));
const list = s.length === 1 && FLAG.includes(p) ? FLAG : s.length === 2 ? SEARCH.map(([q]) => q).filter((q) => q.split('/').filter(Boolean).length === 2 && q.startsWith('/' + s[0] + '/')) : null;
if (!list || list.length < 2) return null;
const i = list.indexOf(p);
if (i < 0) return null;
const at = (k) => list[(k + list.length) % list.length];
const name = (q) => TITLE[q] || q.split('/').pop().replace(/-/g, ' ');
return { prev: at(i - 1), next: at(i + 1), prevName: name(at(i - 1)), nextName: name(at(i + 1)) };
}
function go(href, dir) {
document.documentElement.dataset.dir = dir;
const a = document.createElement('a');
a.href = href; a.style.position = 'fixed'; a.style.width = a.style.height = '0';
document.body.appendChild(a); a.click(); a.remove(); // the morph layer turns the page
setTimeout(() => { delete document.documentElement.dataset.dir; }, 1200);
}
function Swipe({ path }) {
const [sib, setSib] = useState(null);
const [hint, setHint] = useState(null); // { dir, p }
const g = useRef(null);
useEffect(() => {
setSib(null);
if (!wants(path) || !matchMedia('(pointer: coarse)').matches) return;
let live = true;
import('../lib/search.json').then((m) => { if (live) setSib(siblings(path, m.default)); });
return () => { live = false; };
}, [path]);
useEffect(() => {
if (!sib) return;
const scroller = (el) => { for (let e = el; e && e !== document.body; e = e.parentElement) { if (e.matches?.('[data-swipe-own], input, textarea, select, .x-sheet, header')) return true; const s = getComputedStyle(e); if (/(auto|scroll)/.test(s.overflowX) && e.scrollWidth > e.clientWidth + 4) return true; } return false; };
const start = (e) => { const t = e.touches[0]; g.current = t.clientX < 28 || t.clientX > innerWidth - 28 || e.touches.length > 1 || scroller(e.target) ? null : { x: t.clientX, y: t.clientY, on: false }; };
const move = (e) => {
const s = g.current; if (!s) return;
const t = e.touches[0], dx = t.clientX - s.x, dy = t.clientY - s.y;
if (!s.on && Math.abs(dy) > 24) { g.current = null; setHint(null); return; }
if (Math.abs(dx) > 14 && Math.abs(dx) > Math.abs(dy) * 1.6) s.on = true;
if (s.on) setHint({ dir: dx < 0 ? 'next' : 'prev', p: Math.min(1, Math.abs(dx) / 110) });
s.dx = dx; s.dy = dy;
};
const end = () => {
const s = g.current; g.current = null;
if (s?.on && Math.abs(s.dx) > 110 && Math.abs(s.dy) < 70) go(s.dx < 0 ? sib.next : sib.prev, s.dx < 0 ? 'next' : 'prev');
setHint(null);
};
addEventListener('touchstart', start, { passive: true });
addEventListener('touchmove', move, { passive: true });
addEventListener('touchend', end); addEventListener('touchcancel', end);
return () => { removeEventListener('touchstart', start); removeEventListener('touchmove', move); removeEventListener('touchend', end); removeEventListener('touchcancel', end); };
}, [sib]);
if (!sib || !hint) return null;
const name = hint.dir === 'next' ? sib.nextName : sib.prevName;
return (
<div className={'x-swipe ' + hint.dir} style={{ opacity: 0.25 + hint.p * 0.75, transform: `translate(-50%, 0) scale(${0.92 + hint.p * 0.08})` }} aria-hidden="true">
{hint.dir === 'prev' && <i>←</i>}<span>{hint.p >= 1 ? 'Release for ' : ''}{name}</span>{hint.dir === 'next' && <i>→</i>}
</div>
);
}
export default function Phone() {
const path = usePathname();
return <Swipe path={path} />;
}