CommandPalette
⌘K command menu: search, grouped results, keyboard first.
Code
import * as React from 'react';
import { CommandPalette } from '@fruit-labs/design';
export default function Demo() {
return (
<div
style={{
position: 'relative',
height: 430,
borderRadius: 20,
overflow: 'hidden',
background: 'var(--bg)',
}}
>
<CommandPalette
open
contained
{...{
onClose() {},
}}
groups={[
{
label: 'Suggestions',
items: [
{
label: 'New project',
icon: 'plus',
shortcut: '⌘N',
},
{
label: 'Invite people',
icon: 'person',
shortcut: '⌘I',
},
{
label: 'Toggle dark mode',
icon: 'moon',
},
],
},
{
label: 'Projects',
items: [
{
label: 'Website refresh',
icon: 'grid',
},
{
label: 'Mobile onboarding',
icon: 'grid',
},
],
},
]}
/>
</div>
);
}Install
From npm:
npm install @fruit-labs/design
import { CommandPalette } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/command-palette.jsonGuidelines
- Open with
useHotkey('k', ...). Group by Suggestions, then entities.
Props
| Prop | Type | Required |
|---|---|---|
open | boolean | Yes |
onClose | () => void | No |
groups | Array<{ label: string; items: Array<{ label: string; icon?: string; shortcut?: string; onSelect?: () => void }> }> | Yes |
placeholder | string | No |
label | string | No |
contained | boolean | No |