DocsComponentsTemplatesThemesGitHub

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.json

Guidelines

  • Open with useHotkey('k', ...). Group by Suggestions, then entities.

Props

PropTypeRequired
openbooleanYes
onClose() => voidNo
groupsArray<{ label: string; items: Array<{ label: string; icon?: string; shortcut?: string; onSelect?: () => void }> }>Yes
placeholderstringNo
labelstringNo
containedbooleanNo

Edit this example on GitHub