components/command-menu/examples.tsx
42 lines and 10 functions in DrDustinEdwards/capsomer, at commit d3966cc on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| Live | 9 to 41 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| ran | 12 to 12 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:12> | 12 to 12 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| search | 17 to 24 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:18> | 18 to 24 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:19> | 19 to 22 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:20> | 20 to 20 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:21> | 21 to 21 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:23> | 23 to 23 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
| <anonymous:30> | 30 to 30 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: mutation testing has not run on this repo yet |
Imports
It imports components/command-menu/command-menu.react.tsx. No module of this repo imports it.
Source
// Mounts the React command menu's live-search specimen: the catalog is searched as the person
// types, through a fake source that answers after 300 ms. Titles are samples.
import { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";
import { CommandMenu, type Command } from "./command-menu.react.tsx";
const CATALOG = ["The Left Hand of Darkness", "The Dispossessed", "A Wizard of Earthsea", "Middlemarch", "The Remains of the Day", "Piranesi"];
function Live() {
const [open, setOpen] = useState(true);
const [said, setSaid] = useState("");
const ran = (label: string) => () => setSaid(`Ran: ${label}`);
const commands: Command[] = [
{ id: "go-library", label: "Your library", group: "Go to", run: ran("Your library") },
{ id: "go-diary", label: "Diary", group: "Go to", run: ran("Diary") },
];
const search = (q: string, signal: AbortSignal) =>
new Promise<Command[]>((resolve, reject) => {
const t = setTimeout(() => {
const hits = CATALOG.filter((b) => b.toLowerCase().includes(q.toLowerCase()));
resolve([{ id: "search-all", label: `Search all results for “${q}”`, group: "Search", run: ran(`Search ${q}`) }, ...hits.map((b) => ({ id: `book-${b}`, label: b, group: "Books", run: ran(b) }))]);
}, 300);
signal.addEventListener("abort", () => (clearTimeout(t), reject(signal.reason)));
});
return (
<>
<main className="specimen-page" tabIndex={-1}>
<h1>Home</h1>
<p>
<button type="button" className="cap-btn" onClick={() => setOpen(true)}>
Search
</button>
</p>
<p role="status" data-specimen-part="said">
{said}
</p>
</main>
<CommandMenu open={open} onOpenChange={setOpen} commands={commands} search={search} label="Search books" placeholder="Search books and pages" bindKeys={false} />
</>
);
}
for (const el of Array.from(document.querySelectorAll<HTMLElement>("[data-mount]"))) {
if (el.dataset.mount === "live") createRoot(el).render(<StrictMode><Live /></StrictMode>);
}