<div class="demo-row">
<ray-button id="demo-palette-open" variant="default">Open command palette</ray-button>
<span id="demo-palette-out" style="color: var(--ray-muted-foreground); font-size: var(--ray-font-size-sm)"></span>
</div>
<ray-command-palette id="demo-palette" hotkey=""></ray-command-palette>
<p class="demo-muted" style="margin: 0">On this site <ray-kbd size="xs">⌘K</ray-kbd> belongs to the docs search in the header — another <code>ray-command-palette</code>, over the components and guides. This one has <code>hotkey=""</code> and opens with the button.</p>
<script type="module">
const palette = document.getElementById("demo-palette");
const say = (text) => { document.getElementById("demo-palette-out").textContent = text; };
palette.actions = [
{ id: "new", label: "New file", group: "File", icon: "file", shortcut: "⌘ N", onSelect: () => say("New file") },
{ id: "open", label: "Open file…", group: "File", icon: "folder", shortcut: "⌘ O", keywords: ["load"], onSelect: () => say("Open file") },
{ id: "save", label: "Save", group: "File", icon: "check", shortcut: "⌘ S", disabled: true },
{ id: "run", label: "Run program", description: "ray run src/main.ray", group: "Raylang", icon: "play", onSelect: () => say("ray run") },
{ id: "test", label: "Run tests", description: "ray test", group: "Raylang", icon: "circle-check", onSelect: () => say("ray test") },
{ id: "fmt", label: "Format document", description: "ray fmt", group: "Raylang", icon: "terminal", keywords: ["prettier", "style"], onSelect: () => say("ray fmt") },
{ id: "theme", label: "Toggle theme", group: "View", icon: "moon", onSelect: () => say("Theme") },
{ id: "list", label: "List releases", description: "/repos/ray/releases", group: "Requests", prefix: method("GET", "green"), onSelect: () => say("GET") },
{ id: "create", label: "Create release", description: "/repos/ray/releases", group: "Requests", prefix: method("POST", "blue"), onSelect: () => say("POST") },
];
function method(name, color) {
const badge = document.createElement("ray-badge");
Object.assign(badge, { size: "xs", color, variant: "light" });
badge.textContent = name;
badge.style.minWidth = "3rem";
return badge;
}
document.getElementById("demo-palette-open").addEventListener("click", () => palette.show());
</script>
import type { CSSProperties } from "react";
import { RayButton, RayCommandPalette, RayKbd } from "@raylang/react";
export function CommandPaletteExample() {
return (
<>
<div className="demo-row">
<RayButton id="demo-palette-open" variant="default">Open command palette</RayButton>
<span id="demo-palette-out" style={{ color: "var(--ray-muted-foreground)", fontSize: "var(--ray-font-size-sm)" } as CSSProperties} />
</div>
<RayCommandPalette id="demo-palette" hotkey="" />
<p className="demo-muted" style={{ margin: "0" }}>On this site <RayKbd size="xs">⌘K</RayKbd> belongs to the docs search in the header — another <code>ray-command-palette</code>, over the components and guides. This one has <code>hotkey=""</code> and opens with the button.</p>
</>
);
}
<template>
<div class="demo-row">
<RayButton id="demo-palette-open" variant="default">Open command palette</RayButton>
<span id="demo-palette-out" style="color: var(--ray-muted-foreground); font-size: var(--ray-font-size-sm)"></span>
</div>
<RayCommandPalette id="demo-palette" hotkey="" />
<p class="demo-muted" style="margin: 0">On this site <RayKbd size="xs">⌘K</RayKbd> belongs to the docs search in the header — another <code>ray-command-palette</code>, over the components and guides. This one has <code>hotkey=""</code> and opens with the button.</p>
</template>