mirror of
https://github.com/hanzoai/site.git
synced 2026-11-21 01:07:08 +00:00
- every colour, radius and timing from Hanzo's deck, declared once per stylesheet; no springs, no tile shadows - scale rhythm: h1 84px settling to 52 as the journey begins; headings rest at 26px; figures 64px (Air 220); a group's figure grows to 84px only while its group is the moment - the black room rises as a rounded card inside the gutters and opens past the edges (transform only) - kit Cta (data-cta, data-thumb) for every ask, kit CodeBlock for every command - facts and homes become rows (no three equal boxes); the ring names its step instead of a counter - the proof strip (95.6%, 3.02x, 2.0x, each to its measurement) before the Band - the chapter index sits under the words; pinned scenes ask the site bar to step aside - docs/requests/platform.md: the desktop ask pill floats over content (MASTER 3.2 rule 6) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DqUybC36ncJibdZBGwqLx8
78 lines
3.7 KiB
React
78 lines
3.7 KiB
React
'use client';
|
|
/* PinChapters (v2; owned by the Platform + Cloud chat). Apple's sticky chapter scene: the words pin on the left while
|
|
the picture on the right changes, and one chapter comes in as the last goes out (the picture wipes up from below as
|
|
the old one leaves through the top; the words make a short rise). Scroll drives it; the numbered index jumps to a
|
|
chapter and shows how far through it you are. Keyboard focus inside a chapter scrolls to it.
|
|
Phones (≤ 900px) and reduced motion get a plain vertical story: every chapter in flow, words then picture.
|
|
|
|
Usage:
|
|
<PinChapters label="Planes" className="my-pc" chapters={[
|
|
{ id: 'compute', tab: 'Compute', copy: <MyWords />, visual: <MyPicture /> }, …
|
|
]} />
|
|
- Every chapter is in the HTML at all times (inactive ones are faded, never removed), so parity holds.
|
|
- Theme with CSS on your className: --pc-acc (index accent), --pc-per (scroll length per chapter, default 90vh). */
|
|
import { useEffect, useRef, useState } from 'react';
|
|
import { motion, useScroll, useMotionValueEvent, useTransform } from 'motion/react';
|
|
import './PinChapters.css';
|
|
|
|
const clamp = (v, a = 0, b = 1) => Math.min(b, Math.max(a, v));
|
|
|
|
export default function PinChapters({ chapters, label, className = '' }) {
|
|
const track = useRef(null);
|
|
const n = chapters.length;
|
|
const [at, setAt] = useState(0);
|
|
const { scrollYProgress } = useScroll({ target: track, offset: ['start start', 'end end'] });
|
|
const local = useTransform(scrollYProgress, (v) => clamp(v * n - Math.min(n - 1, Math.floor(v * n))));
|
|
useMotionValueEvent(scrollYProgress, 'change', (v) => {
|
|
const i = Math.min(n - 1, Math.max(0, Math.floor(v * n)));
|
|
setAt((a) => (a === i ? a : i));
|
|
});
|
|
const pinned = useRef(true);
|
|
useEffect(() => {
|
|
const mq = matchMedia('(max-width: 899px), (prefers-reduced-motion: reduce)');
|
|
const on = () => { pinned.current = !mq.matches; };
|
|
on();
|
|
mq.addEventListener('change', on);
|
|
return () => mq.removeEventListener('change', on);
|
|
}, []);
|
|
const go = (i, smooth = true) => {
|
|
const el = track.current;
|
|
if (!el || !pinned.current) return;
|
|
const top = el.getBoundingClientRect().top + scrollY;
|
|
const y = top + (el.offsetHeight - innerHeight) * ((i + 0.35) / n);
|
|
if (window.__lenis) window.__lenis.scrollTo(y, { immediate: !smooth, force: true });
|
|
else scrollTo({ top: y, behavior: smooth ? 'smooth' : 'auto' });
|
|
};
|
|
return (
|
|
<div ref={track} className={'pc ' + className} style={{ '--pc-n': n }}>
|
|
<div className="pc-stage">
|
|
<div className="pc-grid">
|
|
<nav className="pc-idx" aria-label={label}>
|
|
{chapters.map((c, i) => (
|
|
<button key={c.id} type="button" className={i === at ? 'on' : ''} aria-current={i === at ? 'step' : undefined} onClick={() => go(i)}>
|
|
<span className="pc-n">{String(i + 1).padStart(2, '0')}</span>
|
|
<span className="pc-t">{c.tab}</span>
|
|
{i === at && (
|
|
<motion.i layoutId={'pc-bar-' + (label || 'x')} className="pc-bar" transition={{ duration: 0.3, ease: [0.4, 0, 0.2, 1] }} aria-hidden="true">
|
|
<motion.b style={{ scaleX: local }} />
|
|
</motion.i>
|
|
)}
|
|
</button>
|
|
))}
|
|
</nav>
|
|
{chapters.map((c, i) => (
|
|
<div key={c.id} id={c.id} className="pc-copy" style={{ '--i': i }} data-on={i === at} data-past={i < at} onFocus={() => i !== at && go(i, false)}>
|
|
{c.copy}
|
|
</div>
|
|
))}
|
|
{chapters.map((c, i) => (
|
|
<div key={c.id + '-v'} className="pc-vis" style={{ '--i': i }} data-on={i === at} data-past={i < at}>
|
|
{c.visual}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|