Spaces:
Sleeping
Sleeping
Download web/src/components/architecture/Chapter.tsx from TBM99/CoverageCheck: direct link, hf CLI and curl.
- Browser
- Download file 5.04 kB
-
https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/web/src/components/architecture/Chapter.tsx
- Command line
-
hf download hf://spaces/TBM99/CoverageCheck/web/src/components/architecture/Chapter.tsx
-
curl -L -o Chapter.tsx https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/web/src/components/architecture/Chapter.tsx
5.04 kB
| import { forwardRef } from 'react' | |
| import type { ArchChapter, ArchStep } from '@/lib/types' | |
| import { cn } from '@/lib/utils' | |
| import { Diagram } from './Diagrams' | |
| /** One chapter (one level of detail): its steps on the left, read top to bottom, and its | |
| * diagram pinned on the right (on a phone, above the steps). The active step (the one | |
| * being read, or the one clicked) lights up the boxes it talks about. */ | |
| export function Chapter({ | |
| chapter, | |
| number, | |
| active, | |
| onStep, | |
| stepRef, | |
| }: { | |
| chapter: ArchChapter | |
| number: number | |
| active: number // the step being read in this chapter, -1 for none | |
| onStep: (i: number) => void | |
| stepRef: (i: number, el: HTMLElement | null) => void | |
| }) { | |
| const lit = active >= 0 ? chapter.steps[active].highlight : null | |
| return ( | |
| <section id={chapter.id} className="scroll-mt-4 border-t pt-10"> | |
| <div className="mb-6 max-w-2xl"> | |
| <p className="text-xs font-semibold tracking-wide text-primary uppercase">Step {number}</p> | |
| <h2 className="text-2xl font-semibold tracking-tight">{chapter.title}</h2> | |
| <p className="mt-1 text-muted-foreground">{chapter.lead}</p> | |
| </div> | |
| <div className="grid gap-8 lg:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]"> | |
| <div className="order-2 lg:order-1"> | |
| {chapter.steps.map((s, i) => ( | |
| <Step key={s.id} ref={(el) => stepRef(i, el)} step={s} active={i === active} onClick={() => onStep(i)} /> | |
| ))} | |
| </div> | |
| <div className="order-1 lg:order-2"> | |
| <figure className="rounded-2xl border bg-muted/40 p-4 lg:sticky lg:top-4" aria-label={`Diagram: ${chapter.title}`}> | |
| <figcaption className="mb-3 flex items-baseline justify-between gap-2"> | |
| <span className="text-sm font-semibold">{chapter.title}</span> | |
| <span className="text-[11px] text-muted-foreground"> | |
| {chapter.diagram.kind === 'grid' ? 'Lit row: the step you are reading · — : no such step' : 'Lit boxes: the step you are reading'} | |
| </span> | |
| </figcaption> | |
| <Diagram diagram={chapter.diagram} lit={lit} /> | |
| </figure> | |
| </div> | |
| </div> | |
| </section> | |
| ) | |
| } | |
| const Step = forwardRef<HTMLDivElement, { step: ArchStep; active: boolean; onClick: () => void }>(function Step( | |
| { step, active, onClick }, | |
| ref, | |
| ) { | |
| const d = step.details | |
| const hasDetails = d.numbers.length > 0 || d.example || d.tried.length > 0 || d.files.length > 0 | |
| return ( | |
| <div ref={ref} className="pb-10 lg:min-h-[38vh]"> | |
| <div | |
| role="button" | |
| tabIndex={0} | |
| onClick={onClick} | |
| onKeyDown={(e) => (e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), onClick())} | |
| aria-pressed={active} | |
| className={cn( | |
| 'cursor-pointer rounded-xl border-l-4 py-1 pl-4 transition-colors outline-none focus-visible:ring-2 focus-visible:ring-primary', | |
| active ? 'border-primary' : 'border-transparent hover:border-border', | |
| )} | |
| > | |
| <p className={cn('text-lg leading-snug font-semibold', !active && 'text-foreground/80')}>{step.point}</p> | |
| <p className="mt-2 leading-relaxed text-muted-foreground">{step.body}</p> | |
| </div> | |
| {hasDetails && ( | |
| <details className="mt-3 ml-5 text-sm"> | |
| <summary className="cursor-pointer text-xs font-medium text-primary">Details: numbers, a real example, what we tried</summary> | |
| <div className="mt-3 space-y-4"> | |
| {d.numbers.length > 0 && ( | |
| <dl className="grid gap-x-6 gap-y-1.5 sm:grid-cols-2"> | |
| {d.numbers.map((x) => ( | |
| <div key={x.label} className="border-b pb-1.5"> | |
| <dt className="text-xs text-muted-foreground">{x.label}</dt> | |
| <dd className="font-medium break-words">{x.value}</dd> | |
| </div> | |
| ))} | |
| </dl> | |
| )} | |
| {d.example && ( | |
| <div> | |
| <p className="mb-1 text-xs font-medium text-muted-foreground">Real example · {d.example.title}</p> | |
| <pre className="rounded-lg bg-muted p-3 font-mono text-xs leading-relaxed whitespace-pre-wrap break-words">{d.example.body}</pre> | |
| </div> | |
| )} | |
| {d.tried.length > 0 && ( | |
| <div> | |
| <p className="mb-1 text-xs font-medium text-muted-foreground">Tried or considered, and rejected</p> | |
| <ul className="list-disc space-y-1 pl-5"> | |
| {d.tried.map((t) => ( | |
| <li key={t}>{t}</li> | |
| ))} | |
| </ul> | |
| </div> | |
| )} | |
| {d.files.length > 0 && ( | |
| <div className="flex flex-wrap gap-1.5"> | |
| {d.files.map((f) => ( | |
| <code key={f} className="rounded-md bg-muted px-1.5 py-0.5 text-[11px]"> | |
| {f} | |
| </code> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| </details> | |
| )} | |
| </div> | |
| ) | |
| }) | |