luna-command-palette
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Luna Command Palette

Command palette.

Demo

https://luna.liriliri.io/?path=/story/command-palette

Install

Add the following script and style to your page.

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/luna-command-palette/luna-command-palette.css" />
<script src="//cdn.jsdelivr.net/npm/luna-command-palette/luna-command-palette.js"></script>

You can also get it on npm.

npm install luna-command-palette --save
import 'luna-command-palette/luna-command-palette.css'
import LunaCommandPalette from 'luna-command-palette'

Usage

const container = document.getElementById('container')
const commandPalette = new LunaCommandPalette(container, { 
  placeholder: 'Type a command',
  shortcut: 'Ctrl+P',
  commands: [
    {
      title: 'Reload Page',
      shortcut: 'Ctrl+R',
      handler(e) {
        if (e && e.preventDefault) {
          e.preventDefault()
        }
        location.reload()
      }
    }
  ]
})
commandPalette.show()

Configuration

  • placeholder(string): Search input placeholder.
  • shortcut(string): Keyboard shortcut for opening the command palette.
  • commands(array): Commands to show.

Command:

  • title(string): Command title.
  • handler(function): Function to execute if command is triggered.
  • shortcut(string): Shortcut to trigger command.

Api

show(): void

Show command palette.

hide(): void

Hide command palette.

Readme

Keywords

Package Sidebar

Install

npm i luna-command-palette

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

175 kB

Total Files

12

Last publish

Collaborators

  • surunzi