mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:21:13 +00:00
* Type scripts under strict Playwright's API the checks use is declared in host.ts (the package is the app repo's); caught errors read through why(). tabs-tree.test waits for the typed tabsTree. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the shared components under strict Window globals (__lenis, __hzHold, google) and the two react-dom calls are declared in components/*.d.ts, since @types/react-dom is not a dependency and the lockfile is frozen. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type components/v2 under strict Props, state, refs and DOM events in the 93 v2 files. A2Motion's easing tuples are as const. Two real bugs: x-archimedes/MaskLines imported a NoJs that does not exist, and x-hypatia/PinChapters returned the element from a ref callback, which React 19 reads as a cleanup. AppSheet no longer sets aria-label to a JSX label. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type components/home under strict The race, cost and frontier figures, the plan cards, the repository card and the product stories take Run, Models and Plan types from lib. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the hero devices and the app routes under strict HeroScene and its parts describe hero-scenes.json; the [slug] pages take params as a Promise, and metadata and viewport carry Next's types. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Give the integrations previews their Preview type Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Use the bench Card type for the closing cards Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
58 lines
3.2 KiB
TypeScript
58 lines
3.2 KiB
TypeScript
'use client';
|
||
/* Drawer — "see the spec": detail lives in a sheet you open (Cloud 4 chat; VISION.md "one idea per screen").
|
||
Usage: <Drawer label="See the console" title="Example console">…detail…</Drawer>
|
||
A button opens a sheet from the right (from the bottom on phones). Escape, the scrim and × close it; focus moves into
|
||
the sheet, Tab stays inside it, and focus returns to the button. The sheet's content is always in the HTML (inert while closed), so nothing is lost. */
|
||
import { useEffect, useRef, useState } from 'react';
|
||
import type { ReactNode } from 'react';
|
||
import { createPortal } from 'react-dom';
|
||
import './x-hamilton/Launch.css';
|
||
|
||
interface DrawerProps {
|
||
label: string;
|
||
title?: string;
|
||
children?: ReactNode;
|
||
className?: string;
|
||
}
|
||
|
||
export default function Drawer({ label, title, children, className = '' }: DrawerProps) {
|
||
const [open, setOpen] = useState(false);
|
||
const [host, setHost] = useState<HTMLElement | null>(null);
|
||
const btn = useRef<HTMLButtonElement>(null);
|
||
const sheet = useRef<HTMLDivElement>(null);
|
||
useEffect(() => setHost(document.body), []);
|
||
useEffect(() => {
|
||
if (!open) return;
|
||
window.__lenis?.stop();
|
||
const t = setTimeout(() => sheet.current?.querySelector<HTMLElement>('.l2-sheet-x')?.focus(), 60);
|
||
const key = (e: KeyboardEvent) => {
|
||
if (e.key === 'Escape') { setOpen(false); return; }
|
||
if (e.key !== 'Tab' || !sheet.current) return; // keep focus inside the sheet while it is open
|
||
const f = [...sheet.current.querySelectorAll<HTMLElement>('a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])')];
|
||
if (!f.length) return;
|
||
if (e.shiftKey && document.activeElement === f[0]) { e.preventDefault(); f[f.length - 1].focus(); }
|
||
else if (!e.shiftKey && (document.activeElement === f[f.length - 1] || !sheet.current.contains(document.activeElement))) { e.preventDefault(); f[0].focus(); }
|
||
};
|
||
addEventListener('keydown', key);
|
||
return () => { clearTimeout(t); removeEventListener('keydown', key); window.__lenis?.start(); btn.current?.focus({ preventScroll: true }); };
|
||
}, [open]);
|
||
const panel = (
|
||
<>
|
||
<div className={'l2-scrim' + (open ? ' on' : '')} onClick={() => setOpen(false)} aria-hidden="true" />
|
||
<div ref={sheet} className={'l2-sheet' + (open ? ' on' : '')} role="dialog" aria-modal={open ? 'true' : undefined} aria-label={title || label} aria-hidden={!open} inert={!open} data-lenis-prevent>
|
||
<div className="l2-sheet-bar"><p>{title || label}</p><button type="button" className="l2-sheet-x" onClick={() => setOpen(false)} aria-label="Close">×</button></div>
|
||
<div className="l2-sheet-body">{children}</div>
|
||
</div>
|
||
</>
|
||
);
|
||
return (
|
||
<>
|
||
<button ref={btn} type="button" className={'l2-drawer-btn ' + className} aria-haspopup="dialog" aria-expanded={open} onClick={() => setOpen(true)}>
|
||
{label}
|
||
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3 8h9M8.5 4.5 12 8l-3.5 3.5" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg>
|
||
</button>
|
||
{host ? createPortal(panel, host) : <div hidden>{children}</div>}
|
||
</>
|
||
);
|
||
}
|