Components
Command
Built on Base UIA searchable list of actions, on the page or in a dialog.
Nothing run yet.
Installation
npx nook-ui@latest add commandPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Command" component to this project, exactly as Nook ships it.
A searchable list of actions, on the page or in a dialog.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add command`. It writes `components/ui/command.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/command.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { CalendarIcon, PlusIcon, SearchIcon, SidebarIcon } from "@/components/icons";
import { Button } from "@/components/ui/button";
import { CommandDialog, type CommandGroup } from "@/components/ui/command";
const GROUPS: CommandGroup[] = [
{
heading: "Actions",
items: [
{ value: "new-task", label: "New task", icon: <PlusIcon />, shortcut: "N", keywords: ["create", "add"] },
{ value: "schedule", label: "Schedule a review", icon: <CalendarIcon />, keywords: ["meeting", "date"] },
{ value: "toggle-sidebar", label: "Hide sidebar", icon: <SidebarIcon />, shortcut: "⌘B" },
],
},
{
heading: "Go to",
items: [
{ value: "inbox", label: "Inbox", keywords: ["messages"] },
{ value: "projects", label: "Projects" },
{ value: "reports", label: "Reports", keywords: ["charts", "numbers"] },
{ value: "billing", label: "Billing", disabled: true },
],
},
];
export default function CommandDefault() {
const [open, setOpen] = React.useState(false);
const [last, setLast] = React.useState<string | null>(null);
React.useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
if (event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
setOpen((value) => !value);
}
};
window.addEventListener("keydown", onKeyDown);
return () => window.removeEventListener("keydown", onKeyDown);
}, []);
return (
<div className="flex flex-col items-center gap-3">
<Button variant="outline" onClick={() => setOpen(true)}>
<SearchIcon />
Search or run a command
<kbd className="font-mono text-xs text-muted-foreground">⌘K</kbd>
</Button>
<p aria-live="polite" className="text-sm text-muted-foreground">
{last ? `Ran: ${last}` : "Nothing run yet."}
</p>
<CommandDialog open={open} onOpenChange={setOpen} groups={GROUPS} onSelect={(item) => setLast(item.label)} />
</div>
);
}
```
API
- `Command`: The search field and the list.
- `groups` (`{ heading?: string; items: CommandItem[] }[]`): The items, in groups. An item has `value`, `label` and optionally `icon`, `shortcut`, `keywords`, `disabled`, `onSelect`.
- `onSelect` (`(item: CommandItem) => void`): Called with the chosen item.
- `placeholder` (`string`): Hint in the search field.
- `emptyText` (`string`, default "Nothing matches."): Shown when nothing matches.
- `label` (`string`, default "Command menu"): Names the field for assistive tech.
- `CommandDialog`: The same, in a dialog. Closes once an item is chosen.
- `open` (`boolean`): Whether the dialog is open.
- `onOpenChange` (`(open: boolean) => void`): Called when it opens or closes.
- `title` (`string`, default "Command menu"): The dialog title, for assistive tech.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The search field has role=combobox and controls a listbox; focus stays in the field. Arrow keys move, Home and End jump, Enter runs the item, Escape closes the dialog. Disabled items are skipped.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import * as React from "react";
import { CalendarIcon, PlusIcon, SearchIcon, SidebarIcon } from "@/components/icons";
import { Button } from "@/components/ui/button";
import { CommandDialog, type CommandGroup } from "@/components/ui/command";
const GROUPS: CommandGroup[] = [
{
heading: "Actions",
items: [
{ value: "new-task", label: "New task", icon: <PlusIcon />, shortcut: "N", keywords: ["create", "add"] },
{ value: "schedule", label: "Schedule a review", icon: <CalendarIcon />, keywords: ["meeting", "date"] },
{ value: "toggle-sidebar", label: "Hide sidebar", icon: <SidebarIcon />, shortcut: "⌘B" },
],
},
{
heading: "Go to",
items: [
{ value: "inbox", label: "Inbox", keywords: ["messages"] },
{ value: "projects", label: "Projects" },
{ value: "reports", label: "Reports", keywords: ["charts", "numbers"] },
{ value: "billing", label: "Billing", disabled: true },
],
},
];
export default function CommandDefault() {
const [open, setOpen] = React.useState(false);
const [last, setLast] = React.useState<string | null>(null);
React.useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
if (event.key.toLowerCase() === "k" && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
setOpen((value) => !value);
}
};
window.addEventListener("keydown", onKeyDown);
return () => window.removeEventListener("keydown", onKeyDown);
}, []);
return (
<div className="flex flex-col items-center gap-3">
<Button variant="outline" onClick={() => setOpen(true)}>
<SearchIcon />
Search or run a command
<kbd className="font-mono text-xs text-muted-foreground">⌘K</kbd>
</Button>
<p aria-live="polite" className="text-sm text-muted-foreground">
{last ? `Ran: ${last}` : "Nothing run yet."}
</p>
<CommandDialog open={open} onOpenChange={setOpen} groups={GROUPS} onSelect={(item) => setLast(item.label)} />
</div>
);
}Examples
On the page
Assign to
Maya Chen
Arif Rahman
Lena Fischer
Sam Okafor
Grouped, inline
Recent files
Q3 roadmap.md
Invoice template
Folders
Client work
People
Ana Souza
Settings
Workspace settings⌘,
Nothing found
Argentina
Brazil
Chile
Colombia
Peru
Uruguay
Shortcuts and disabled
Document
Bold⌘B
Italic⌘I
Insert link⌘K
Publish (needs a title)
Go to a page
You are on: Home
Props
Command
The search field and the list.
| Prop | Type | Default | Description |
|---|---|---|---|
| groups | { heading?: string; items: CommandItem[] }[] | – | The items, in groups. An item has `value`, `label` and optionally `icon`, `shortcut`, `keywords`, `disabled`, `onSelect`. |
| onSelect | (item: CommandItem) => void | – | Called with the chosen item. |
| placeholder | string | – | Hint in the search field. |
| emptyText | string | "Nothing matches." | Shown when nothing matches. |
| label | string | "Command menu" | Names the field for assistive tech. |
CommandDialog
The same, in a dialog. Closes once an item is chosen.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | – | Whether the dialog is open. |
| onOpenChange | (open: boolean) => void | – | Called when it opens or closes. |
| title | string | "Command menu" | The dialog title, for assistive tech. |
Accessibility
The search field has role=combobox and controls a listbox; focus stays in the field. Arrow keys move, Home and End jump, Enter runs the item, Escape closes the dialog. Disabled items are skipped.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.