Chewypixel component
Command
A command palette whose highlight glides between results as you move through them.
Installation
npx shadcn@latest add https://chewypixel.io/r/command.jsonUsage
"use client";
import { useEffect, useState } from "react";
import {
CommandDialog,
CommandEmpty,
CommandFooter,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command";
const pages = ["Dashboard", "Orders", "Customers", "Settings"];
export function CommandMenu() {
const [open, setOpen] = useState(false);
useEffect(() => {
function onKeyDown(event: KeyboardEvent) {
if (event.key === "k" && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
setOpen((current) => !current);
}
}
document.addEventListener("keydown", onKeyDown);
return () => document.removeEventListener("keydown", onKeyDown);
}, []);
return (
<CommandDialog open={open} onOpenChange={setOpen}>
<CommandInput placeholder="Search pages…" />
<CommandList>
<CommandEmpty>No sweet matches. Try another page name.</CommandEmpty>
<CommandGroup heading="Pages">
{pages.map((page) => (
<CommandItem key={page} value={page} onSelect={() => setOpen(false)}>
{page}
</CommandItem>
))}
</CommandGroup>
</CommandList>
<CommandFooter />
</CommandDialog>
);
}Props
valueA unique value for the item. The gliding highlight needs it; items without one get a plain highlight. Goes on CommandItem.
string
onSelectCalled when the item is clicked or picked with Enter. Goes on CommandItem.
(value: string) => void
openWhether the palette is open. Goes on CommandDialog, along with onOpenChange.
boolean
titleThe dialog's title for screen readers. Goes on CommandDialog, along with description.
string = "Search"
Released under the MIT License.
More components
- CollapsibleA section that opens and closes by animating its height.
- Image LightboxA thumbnail that flies out to a larger view in the middle of the screen, over a lightly blurred page.
- Segmented ControlMutually exclusive options with a highlight that slides to the selected one.
- TabsUnderline tabs. The underline slides to the active tab and resizes to fit its label.
See them in a real app
These components come from Mochi, our admin dashboard template built with Next.js, shadcn/ui and Motion.