mirror of
https://github.com/hanzoai/site.git
synced 2026-11-21 01:07:08 +00:00
* Type page props, hook state and helper parameters from their call sites First pass of the strict typing of components/pages (About to cloudfam): destructured props get an interface built from the JSX that renders them, refs and state get their element and value types, plain parameters get the type their callers or body fix. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type pages (careers, calculator, blog, brand, cli) from their data and call sites Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the cloud pages from their scenes and hooks Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * wip * Type the remaining pages under strict Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
42 lines
1.8 KiB
TypeScript
42 lines
1.8 KiB
TypeScript
'use client';
|
|
/* Phone chapters for /captable (<= 900px): one compact table pins under the header and the six chapters scroll
|
|
under it. The chapter crossing the reading line lights its rows in the one table (01 / 06 … 06 / 06), so one
|
|
object changes instead of six copies of it stacking. Every word stays in the HTML. */
|
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
|
|
const two = (n: number) => String(n).padStart(2, '0');
|
|
|
|
interface PhoneStepsProps {
|
|
items: { t: ReactNode; d?: ReactNode }[];
|
|
stage: (at: number) => ReactNode;
|
|
label: string;
|
|
children?: ReactNode;
|
|
}
|
|
export default function PhoneSteps({ items, stage, label, children }: PhoneStepsProps) {
|
|
const ref = useRef<HTMLElement>(null);
|
|
const [at, setAt] = useState(0);
|
|
useEffect(() => {
|
|
const els = [...ref.current!.querySelectorAll('[data-pch]')];
|
|
const io = new IntersectionObserver((es) => es.forEach((e) => e.isIntersecting && setAt(Number((e.target as HTMLElement).dataset.pch))), { rootMargin: '-58% 0px -40% 0px' });
|
|
els.forEach((el) => io.observe(el));
|
|
return () => io.disconnect();
|
|
}, [items.length]);
|
|
return (
|
|
<section ref={ref} className="ct-pch" aria-label={label}>
|
|
{children}
|
|
<div className="bz-wrap ct-pch-wrap">
|
|
<div className="ct-pch-pin">{stage(at)}</div>
|
|
<ol className="ct-pch-list">
|
|
{items.map((it, i) => (
|
|
<li key={i} data-pch={i} className={'ct-pch-i' + (at === i ? ' on' : i < at ? ' past' : '')} aria-current={at === i ? 'step' : undefined}>
|
|
<h3 className="bz-headline">{it.t}</h3>
|
|
<p className="bz-kick"><span className="x-mono">{two(i + 1)} / {two(items.length)}</span></p>
|
|
{it.d && <p className="bz-body">{it.d}</p>}
|
|
</li>
|
|
))}
|
|
</ol>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|