Getting Started
Components52
- Accordion
- Alert
- Alert Dialog
- Attachment
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Collapsible
- Command
- Context Menu
- Data Table
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
No results found.
Suggestions
Calendar
Search Emoji
Calculator
Settings
Profile⌘P
Billing⌘B
Settings⌘S
"use client"
import {
CalculatorIcon,
CalendarIcon,
CreditCardIcon,
SettingsIcon,
SmileIcon,
UserIcon,
} from "lucide-react"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command"
export function CommandDemo() {
return (
<Command className="max-w-sm shadow-[0_1px_2px_rgb(0_0_0/0.04)] ring-1 ring-border">
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem>
<CalendarIcon />
<span>Calendar</span>
</CommandItem>
<CommandItem>
<SmileIcon />
<span>Search Emoji</span>
</CommandItem>
<CommandItem disabled>
<CalculatorIcon />
<span>Calculator</span>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem>
<UserIcon />
<span>Profile</span>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem>
<CreditCardIcon />
<span>Billing</span>
<CommandShortcut>⌘B</CommandShortcut>
</CommandItem>
<CommandItem>
<SettingsIcon />
<span>Settings</span>
<CommandShortcut>⌘S</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
)
}Installation#
pnpm dlx shadcn@latest add https://ui.ikramhasan.com/r/command.json
Usage#
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command"<Command className="max-w-sm rounded-lg border">
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem>Calendar</CommandItem>
<CommandItem>Search Emoji</CommandItem>
<CommandItem>Calculator</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem>Profile</CommandItem>
<CommandItem>Billing</CommandItem>
<CommandItem>Settings</CommandItem>
</CommandGroup>
</CommandList>
</Command>Examples#
Dialog (⌘J)#
Command Palette
Search for a command to run...
"use client"
import * as React from "react"
import {
CalculatorIcon,
CalendarIcon,
LogOutIcon,
SearchIcon,
SettingsIcon,
SmileIcon,
UserIcon,
} from "lucide-react"
import { Button } from "@/components/ui/button"
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
export function CommandDialogDemo() {
return <CommandPalette />
}
function CommandPalette() {
const [open, setOpen] = React.useState(false)
React.useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "j" && (e.metaKey || e.ctrlKey)) {
e.preventDefault()
setOpen((open) => !open)
}
}
document.addEventListener("keydown", down)
return () => document.removeEventListener("keydown", down)
}, [])
return (
<>
<Button
variant="secondary"
className="w-64 justify-start pr-1.5 pl-2.5 font-normal text-muted-foreground"
onClick={() => setOpen(true)}
>
<SearchIcon data-icon="inline-start" />
Search...
<KbdGroup className="ml-auto">
<Kbd>⌘</Kbd>
<Kbd>J</Kbd>
</KbdGroup>
</Button>
<CommandDialog open={open} onOpenChange={setOpen}>
<Command>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem onSelect={() => setOpen(false)}>
<CalendarIcon />
<span>Calendar</span>
</CommandItem>
<CommandItem onSelect={() => setOpen(false)}>
<SmileIcon />
<span>Search Emoji</span>
</CommandItem>
<CommandItem onSelect={() => setOpen(false)}>
<CalculatorIcon />
<span>Calculator</span>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Account">
<CommandItem onSelect={() => setOpen(false)}>
<UserIcon />
<span>Profile</span>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem onSelect={() => setOpen(false)}>
<SettingsIcon />
<span>Settings</span>
<CommandShortcut>⌘,</CommandShortcut>
</CommandItem>
<CommandItem onSelect={() => setOpen(false)}>
<LogOutIcon />
<span>Log out</span>
<CommandShortcut>⇧⌘Q</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</CommandDialog>
</>
)
}Checked items#
No themes found.
Theme
Light
Dark
System
"use client"
import * as React from "react"
import { MoonIcon, SettingsIcon, SunIcon } from "lucide-react"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command"
export function CommandCheckedItems() {
return <ThemePicker />
}
const themes = [
{ value: "light", label: "Light", icon: SunIcon },
{ value: "dark", label: "Dark", icon: MoonIcon },
{ value: "system", label: "System", icon: SettingsIcon },
]
function ThemePicker() {
const [theme, setTheme] = React.useState("light")
return (
<Command className="max-w-60 ring-1 ring-border">
<CommandInput placeholder="Change theme..." />
<CommandList>
<CommandEmpty>No themes found.</CommandEmpty>
<CommandGroup heading="Theme">
{themes.map(({ value, label, icon: Icon }) => (
<CommandItem
key={value}
value={value}
data-checked={theme === value}
onSelect={setTheme}
>
<Icon />
{label}
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
)
}Many items#
No documents found.
Documents
Quarterly report 1
Quarterly report 2
Quarterly report 3
Quarterly report 4
Quarterly report 5
Quarterly report 6
Quarterly report 7
Quarterly report 8
Quarterly report 9
Quarterly report 10
Quarterly report 11
Quarterly report 12
Quarterly report 13
Quarterly report 14
Quarterly report 15
Quarterly report 16
Quarterly report 17
Quarterly report 18
Quarterly report 19
Quarterly report 20
Quarterly report 21
Quarterly report 22
Quarterly report 23
Quarterly report 24
"use client"
import { FileTextIcon } from "lucide-react"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command"
export function CommandManyItems() {
return (
<Command className="max-w-sm ring-1 ring-border">
<CommandInput placeholder="Search documents..." />
<CommandList>
<CommandEmpty>No documents found.</CommandEmpty>
<CommandGroup heading="Documents">
{Array.from({ length: 24 }, (_, i) => (
<CommandItem key={i}>
<FileTextIcon />
<span>Quarterly report {i + 1}</span>
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
)
}API Reference#
Command is built on the Base UI Command primitive. See the Base UI documentation for every prop.