31 lines · 1.9 KBRaw
| 1 | const GAP = 34; |
| 2 | const PAD = 16; |
| 3 | const MID = 16; |
| 4 | |
| 5 | /** The trace drawn as the refs line: one hollow station per card, a halo on the card in view. */ |
| 6 | export function TraceLine({ names, active, onSelect }: { names: readonly string[]; active: number; onSelect: (index: number) => void }) { |
| 7 | if (!names.length) return null; |
| 8 | const width = PAD * 2 + (names.length - 1) * GAP; |
| 9 | return ( |
| 10 | <div className="scroll-fade max-w-[22rem] shrink overflow-x-auto [scrollbar-width:none]"> |
| 11 | <svg width={width} height={MID * 2} viewBox={`0 0 ${width} ${MID * 2}`} role="group" aria-label={`Trace with ${names.length} ${names.length === 1 ? "step" : "steps"}`} className="block"> |
| 12 | <path d={`M${PAD - 8} ${MID} H${width - PAD + 8}`} stroke="var(--porcelain)" strokeWidth={3} strokeLinecap="round" fill="none" /> |
| 13 | {names.map((name, index) => { |
| 14 | const x = PAD + index * GAP; |
| 15 | const current = index === active; |
| 16 | return ( |
| 17 | <g key={index} role="button" tabIndex={0} aria-label={`Step ${index + 1}: ${name}`} aria-current={current ? "step" : undefined} className="cursor-pointer outline-none" onClick={() => onSelect(index)} onKeyDown={(event) => (event.key === "Enter" || event.key === " ") && onSelect(index)}> |
| 18 | <title>{name}</title> |
| 19 | <circle cx={x} cy={MID} r={14} fill="transparent" /> |
| 20 | {current && <circle cx={x} cy={MID} r={12} fill="none" stroke="var(--porcelain)" strokeWidth={1.5} strokeOpacity={0.55} />} |
| 21 | <circle cx={x} cy={MID} r={8} fill="var(--panel)" stroke="var(--porcelain)" strokeWidth={current ? 3 : 2} /> |
| 22 | <text x={x} y={MID + 3.5} textAnchor="middle" fontSize={10} fontWeight={600} fill={current ? "var(--ink)" : "var(--muted)"} className="tabular-nums"> |
| 23 | {index + 1} |
| 24 | </text> |
| 25 | </g> |
| 26 | ); |
| 27 | })} |
| 28 | </svg> |
| 29 | </div> |
| 30 | ); |
| 31 | } |