'use client';
import * as React from 'react';
import {
ActivityIcon,
BarChart3Icon,
BellIcon,
BookOpenIcon,
CalendarDaysIcon,
CircleHelpIcon,
ClipboardListIcon,
FlagIcon,
FolderKanbanIcon,
InboxIcon,
KeyboardIcon,
LayoutGridIcon,
LineChartIcon,
LogOutIcon,
PaletteIcon,
PieChartIcon,
SettingsIcon,
TimerIcon,
UsersRoundIcon,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from '@/components/ui/command';
import { Kbd } from '@/components/ui/kbd';
const navigateItems = [
{ icon: LayoutGridIcon, label: 'Home' },
{ icon: FolderKanbanIcon, label: 'Boards' },
{ icon: ClipboardListIcon, label: 'My work' },
{ icon: CalendarDaysIcon, label: 'Schedule' },
{ icon: UsersRoundIcon, label: 'People' },
{ icon: InboxIcon, label: 'Inbox' },
{ icon: BookOpenIcon, label: 'Wiki' },
{ icon: BellIcon, label: 'Activity' },
{ icon: TimerIcon, label: 'Timesheets' },
{ icon: FlagIcon, label: 'Milestones' },
];
const insightItems = [
{ icon: BarChart3Icon, label: 'Summary' },
{ icon: LineChartIcon, label: 'Velocity' },
{ icon: PieChartIcon, label: 'Workload' },
{ icon: ActivityIcon, label: 'Health score' },
];
const settingsItems = [
{ icon: SettingsIcon, label: 'Workspace settings' },
{ icon: PaletteIcon, label: 'Theme' },
{ icon: KeyboardIcon, label: 'Shortcuts' },
{ icon: CircleHelpIcon, label: 'Help center' },
{ icon: LogOutIcon, label: 'Log out' },
];
/**
* Command menu with grouped actions.
*/
export default function CommandMenu01() {
const [open, setOpen] = React.useState(true);
React.useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
setOpen((prev) => !prev);
}
};
document.addEventListener('keydown', down);
return () => document.removeEventListener('keydown', down);
}, []);
return (
<>
<Button onClick={() => setOpen(true)} type="button" variant="outline">
Open command menu
<Kbd className="ml-1">⌘K</Kbd>
</Button>
<CommandDialog
className="-translate-y-1/2 top-1/2"
description="Jump to a page or run an action"
onOpenChange={setOpen}
open={open}
showCloseButton={false}
title="Command menu"
>
<Command>
<CommandInput className="h-12" placeholder="Where do you want to go?" />
<CommandList className="h-[320px] max-h-[320px]">
<CommandEmpty>Nothing matches that search.</CommandEmpty>
<CommandGroup heading="Navigate">
{navigateItems.map((item) => (
<CommandItem key={item.label} onSelect={() => setOpen(false)}>
<item.icon className="mr-2 size-5" />
<span>{item.label}</span>
</CommandItem>
))}
</CommandGroup>
<CommandGroup heading="Insights">
{insightItems.map((item) => (
<CommandItem key={item.label} onSelect={() => setOpen(false)}>
<item.icon className="mr-2 size-5" />
<span>{item.label}</span>
</CommandItem>
))}
</CommandGroup>
<CommandGroup heading="Settings">
{settingsItems.map((item) => (
<CommandItem key={item.label} onSelect={() => setOpen(false)}>
<item.icon className="mr-2 size-5" />
<span>{item.label}</span>
</CommandItem>
))}
</CommandGroup>
</CommandList>
<div className="flex h-12 items-center justify-end border-t px-3">
<button
className="flex items-center gap-1 text-muted-foreground text-sm hover:text-foreground"
onClick={() => setOpen(false)}
type="button"
>
<span>Close</span>
<Kbd className="ml-1">Esc</Kbd>
</button>
</div>
</Command>
</CommandDialog>
</>
);
}