| 49 | |
| 50 | /** The compact step list: one line per hop or call site, stepping moves the highlight. */ |
| 51 | export function PathSteps({ heading, note, steps, active, nameOf, lines, onStep, onClear }: { |
| 52 | heading: string; |
| 53 | note?: string; |
| 54 | steps: readonly ScopePathStep[]; |
| 55 | active: number; |
| 56 | nameOf: (id: number) => string; |
| 57 | /** Call order shows the call-site line; a path shows the hop. */ |
| 58 | lines: boolean; |
| 59 | onStep: (index: number) => void; |
| 60 | onClear: () => void; |
| 61 | }) { |
| 62 | return <section className="atlas-galaxy-path-panel" aria-label={text.panel} data-testid="atlas-galaxy-path-panel"> |
| 63 | <header> |
| 64 | <strong>{heading}</strong> |
| 65 | <button type="button" title={text.clearTitle} onClick={onClear}>{text.clear}</button> |
| 66 | </header> |
| 67 | {note && <p>{note}</p>} |
| 68 | {steps.length > 0 && <> |
| 69 | <ol>{steps.map((step, index) => <li key={`${index}:${step.edge.id ?? ''}`}> |
| 70 | <button type="button" data-active={index === active} aria-current={index === active ? 'step' : undefined} |
| 71 | onClick={() => onStep(index)}> |
| 72 | <span className="atlas-galaxy-path-hop">{lines |
| 73 | ? step.edge.line === undefined ? text.lineUnknown : text.line(step.edge.line) |
| 74 | : text.hop(index + 1)}</span> |
| 75 | <code>{text.step(nameOf(step.from), step.edge.type, nameOf(step.to), step.edge.source === step.from)}</code> |
| 76 | </button> |
| 77 | </li>)}</ol> |
| 78 | <footer> |
| 79 | <button type="button" disabled={active <= 0} onClick={() => onStep(active - 1)}>{text.previous}</button> |
| 80 | <span>{text.position(active + 1, steps.length)}</span> |
| 81 | <button type="button" disabled={active >= steps.length - 1} onClick={() => onStep(active + 1)}>{text.next}</button> |
| 82 | </footer> |
| 83 | </>} |
| 84 | </section>; |
| 85 | } |