0.1.4 • Published 6 months ago

cmdk-lite v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

cmdk-lite

cmdk-lite is a command menu for React based on pacocoursey's cmdk but without any dependencies. cmdk-lite is library-agnostic, allowing you to choose how you want to render the command menu.

Install

pnpm install cmdk-lite

Use

import { Command } from 'cmdk-lite';

const CommandMenu = () => {
  return (
    <Command label="Command Menu">
      <Command.Input />
      <Command.List>
        <Command.Empty>No results found.</Command.Empty>

        <Command.Group heading="Letters">
          <Command.Item>a</Command.Item>
          <Command.Item>b</Command.Item>
          <Command.Separator />
          <Command.Item>c</Command.Item>
        </Command.Group>

        <Command.Item>Apple</Command.Item>
      </Command.List>
    </Command>
  );
};

If you want to render it in a dialog, you need to provide the dialog component yourself (because the library doesn't provide any). For example, using Material UI's Dialog component:

import { Command } from 'cmdk-lite';
import { Dialog } from '@mui/material';

const CommandMenu = () => {
  const [open, setOpen] = React.useState(false);

  // Toggle the menu when ⌘K is pressed
  React.useEffect(() => {
    const down = (e) => {
      if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
        e.preventDefault();
        setOpen((open) => !open);
      }
    };

    document.addEventListener('keydown', down);
    return () => document.removeEventListener('keydown', down);
  }, []);

  return (
    <Dialog open={open} onClose={() => setOpen(false)}>
      <Command.Input />
      <Command.List>
        <Command.Empty>No results found.</Command.Empty>

        <Command.Group heading="Letters">
          <Command.Item>a</Command.Item>
          <Command.Item>b</Command.Item>
          <Command.Separator />
          <Command.Item>c</Command.Item>
        </Command.Group>

        <Command.Item>Apple</Command.Item>
      </Command.List>
    </Dialog>
  );
};
0.1.4

6 months ago

0.1.2

8 months ago

0.1.3

8 months ago

0.1.0

8 months ago

0.1.1

8 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago