// Categorized example gallery, shown as a modal. Groups examples by their // catalog category and lets the user load one (which populates the editor and // runs it). import { useEffect } from 'react' import { CATEGORY_ORDER, type Category } from './catalog.ts' import type { Example } from './index.ts' export interface ExamplesModalProps { examples: Example[] onPick: (id: string) => void onClose: () => void } export default function ExamplesModal({ examples, onPick, onClose }: ExamplesModalProps) { useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) const byCategory = new Map() for (const ex of examples) { const list = byCategory.get(ex.category) ?? [] list.push(ex) byCategory.set(ex.category, list) } return (
e.stopPropagation()}>

Examples

{examples.length} sequences from pulseq's demoSeq
{CATEGORY_ORDER.filter((c) => byCategory.has(c)).map((category) => (

{category}

{byCategory.get(category)!.map((ex) => ( ))}
))}
) }