• Stars
    star
    519
  • Rank 85,261 (Top 2 %)
  • Language Vue
  • License
    MIT License
  • Created about 2 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⌨️ A fast, composable, unstyled command palette interface for Vue.

Command Palette for Vue

vue-command-palette minzip package size vue-command-palette package version

A fast, composable, unstyled command + k interface (Command Palette) for Vue.

Preview

Preview

Concepts

Command palette interfaces are used to create a web experience where users can quickly get in charge with keyboard shortcuts, rather than using the mouse.

With macOS's Spotlight and Raycast's command palette experience in mind, vue-command-palette is designed to provide a fast, composable, unstyled command palette to your site.

Features

  • 🧩 Compound Component + Namespaced Components Design
  • 💄 Completely unstyled, but more customizable
  • 🔍 Fuzzy search support to find relevant command
  • ⌨️ keyboard shortcut support to bind custom keybindings to your command

Install

yarn add vue-command-palette
# or
pnpm add vue-command-palette

Usage

Then you can import the Command Compound Component in your project.

<template>
  <Command theme="custom">
    <Command.Input placeholder="Type a command or search..." />
    <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>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { Command } from 'vue-command-palette'
</script>

<style>
// import your custom css
@import '~/assets/css/custom.css';
</style>

or in a dialog:

<template>
  <Command.Dialog :visible="visible" theme="custom">
    <template #header>
      <Command.Input placeholder="Type a command or search..." />
    </template>
    <template #body>
      <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>
    </template>
  </Command.Dialog>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { Command } from 'vue-command-palette'

const visible = ref(false)
</script>

<style>
// import your custom css
@import '~/assets/css/custom.css';
</style>

Command + K or ?

Do I have to use command + K? No, it's just a convention that you can use any key binding to perform the Command Palette.

Tips, we use @vueuse/core to bind the keybindings

<script lang="ts" setup>
  import { watch } from 'vue'
  import { useMagicKeys } from '@vueuse/core'

  const keys = useMagicKeys()
  const CmdK = keys['Meta+K']

  watch(CmdK, (v) => {
    if (v) {
      console.log('Meta + K has been pressed')
      // do your own logic, maybe make dialog visible
    }
  })
</script>

Events

Name Description Parameters
select-item Every time an item is being selected in Command or Command.Dialog (item) => void

Styling

All namespaced components have a specific data-attribute starting with command- that can be used for styling.

eg:

div[command-root=''] {
  background: #ffffff;
}

Animation

Command.Dialog

Command.Dialog wraped by built-in components Transition, you can customize the animation using the name command-dialog .

Example Code

List Item Height

Animate height using the --command-list-height CSS variable.

Example Code

Namespaced components

With Namespaced components, You can use component tags with dots like <Foo.Bar> to refer to components nested under object properties. This is useful when you import multiple components from a single file.

Command [command-root=""]

The root component, Passes the theme props to set your own style.

<Command theme="custom">
  <!-- Contains other namespaced components -->
</Command>

Command.Dialog [command-dialog=""]

The root component with a dialog interface, Teleport dialog to body tag. Passes the theme props to set your own style, and visible props control whether render it.

<Command.Dialog :visible="visible" theme="custom">
  <!-- Contains other namespaced components -->
  <template #header></template>
  <template #body></template>
  <template #footer></template>
</Command.Dialog>

data-attribute within dialog

  • [command-dialog-mask] - the mask is always rendered.
  • [command-dialog-wrapper] - the wrapper on top of mask.
  • [command-dialog-header] - the parent of dialog header slot.
  • [command-dialog-body] - the parent of dialog body slot.
  • [command-dialog-footer] - the parent of dialog footer slot.

Command.Input [command-input=""]

Usually we need a input in the command palette to search sth.

<Command.Input
  placeholder="Type a command or search..."
  v-model:value="inputValue"
/>

Command.List [command-list=""]

Contains items and groups. Animate height using the --command-list-height CSS variable.

[command-list] {
  min-height: 300px;
  height: var(--command-list-height);
  max-height: 500px;
  transition: height 100ms ease;
}
<Command.List>
  <!-- Contains Group, Item, Empty -->
</Command.List>

Command.Group [command-group=""]

Group items ([command-group-items]) together with the given heading ([command-group-heading])

<Command.Group heading="Perference">
  <Command.Item>Toggle Dark Mode</Command.Item>
  <Command.Item>Change Language</Command.Item>
</Command.Group>

Command.Item [command-item=""]

Passed the data-value, we use data-value to fetch the value.

<Command.Item
  v-for="item in items"
  :data-value="item.label"
  :shortcut="item.shortcut"
  :perform="item.perform"
  @select="(itemInfo) => console.log('selected', itemInfo)"
  // the itemInfo.value is some as `data-value`
>
  {{ item.label }}
</Command.Item>

Command.Separator [command-separator=""]

Usually used to distinguish between different groups

Command.Empty [command-empty=""]

Automatically renders when there are no results for the search query.

Command.Loading [command-loading=""]

Your should manually control loading

Inspiration

  • cmdk - Fast, unstyled command menu React component.
  • kbar - fast, portable, and extensible cmd+k interface for your site.

License

MIT @xiaoluoboding

More Repositories

1

vue-sonner

🔔 An opinionated toast component for Vue.
Vue
763
star
2

bookmark.style

🪄 Turn any link into a stylish visual web bookmark, one-click to copy the beautiful web bookmark image.
Vue
310
star
3

ghost-theme-kaldorei

🎨 A Simple And Elegant Ghost Theme Derive From Default Theme Casper
CSS
291
star
4

vue-demo-collection

A collection of Vue.js demos
Vue
268
star
5

vue-smart-widget

🗃️Smart widget is a flexible and extensible content container component for Vue2.x / Vue3.x in Next branch.
JavaScript
186
star
6

vue-stroll

📜 Vue.js + Stroll.js. Awesome CSS list scroll effects for Vue2.x.
Vue
157
star
7

chrome-ext-starter

⚡️ Modernized Chrome Extension Manifest V3 Vite Starter Template
TypeScript
140
star
8

xiaoluoboding

My GitHub Profile. Before Fork it, Star it, Please. 😂
131
star
9

nuxt3-starter

💚 A Better Nuxt 3 Starter Template,generate by nuxi.
Vue
125
star
10

monthly

📖 聚焦前端,记录过去一个月看到的优秀的文章、工具,丰富前端技术栈。每月28日更新。你可以 Watch 它,相当于订阅。
Shell
105
star
11

repository-tree

🌲Pretty display directory tree view of a GitHub repository.
Vue
71
star
12

self-hosted-app-starter

🪄 A starter for the self-hosted app, help you to build your next full-stack project. https://sha-starter.onrender.com
Go
70
star
13

svg-animation-booklet

《SVG 动画开发实战》小册
Shell
60
star
14

vue-color-wheel

🎨 A color wheel picker for Vue
Vue
49
star
15

awesome-starless

A curated list of awesome repositories with few stargazers but has a huge users.
JavaScript
45
star
16

vercel-metafy

Easily scrape metadata from websites as a service using Vercel.
TypeScript
44
star
17

vue-sfc-sandbox

Vue SFC Sandbox, Sandbox as a Vue 3 component.
Vue
42
star
18

chrome-web-bookmark

One-click turn any link into a visual web bookmark, and it looks Like Twitter cards or Notion web bookmark.
Vue
42
star
19

tech-stack.tools

🗡️ Discover our curated list of creative tools to supercharge your next project.
CSS
39
star
20

skylines

My GitHub story in 3D. View a 3D model of your GitHub contribution graph.
Vue
34
star
21

vue-sfc2esm

Transpiled Vue SFC File to ES modules.
TypeScript
28
star
22

coolshapes-vue

100+ abstract shapes with gradient for design & dev project for Vue
Vue
20
star
23

vue3-starter

🖖 A Better Vue 3 Starter Template,generate by create-vue.
Vue
16
star
24

vuepress-tailwind-theme-starter

A starter of build VuePress Theme with TailwindCss.
Stylus
15
star
25

sql-repl

🔍 Just a SQL REPL for web.
Vue
14
star
26

vuex-stateshot

💾 A State Snapshot plugin on Actions/Mutations for Vuex3.1+.
JavaScript
13
star
27

metafy-svg

Easily crawl a website's metadata and generate SVG as a service.
TypeScript
13
star
28

tailwind-pre-processor

An implementation of tailwindcss using less / stylus / Sass/SCSS.
CSS
11
star
29

vscode-folder-size

📁 Shows the current file | folder size in the status bar for Visual Studio Code
TypeScript
8
star
30

element-demi

An adapter for using Element UI with Vue 2 / 3.
JavaScript
7
star
31

vue-library-starter

My minimal Vue library starter, built on top of Vite & Vue 3
Vue
7
star
32

yii2-guide-cn

Yii2.0 中文指南,Yii2.0 权威指南,Yii2.0 开发教程。
PHP
5
star
33

vue-digit-animation

A digit animation component with wheel/slide effect for Vue 3.
Vue
5
star
34

vue-dashboard

Build A Vue Dashboard Using Cube.js.
Vue
4
star
35

bugshot

团队内部使用,一款可以提交Bug附带截图功能到Redmine的Chrome插件。
JavaScript
4
star
36

algo-data-structures-patterns

📖 Learn data structures、algorithms、patterns using JavaScript.
JavaScript
3
star
37

vue-number-spinner

Number spinner component for Vue.js.
JavaScript
3
star
38

my-first-web3-demo

[WIP] Just for learning Web 3 Tech Stack.
Vue
2
star
39

netlify-metafy

Easily scrape metadata from websites as a service using Netlify.
JavaScript
2
star
40

vuepress-plugin-svg-sprite

🔌SVG Sprite plugin for Vuepress generate with svg-sprite-loader and optimised with svgo-loader
JavaScript
2
star
41

transpile-vue-sfc-to-es-modules

Transpile Vue SFC To ES Modules Slides, Built On Top Of Slidev.
CSS
2
star
42

t-to-g

1
star
43

marketing-website-demo

TypeScript
1
star
44

vue-i18n-practice

A Vue 3 demo for taking some practice use vue-i18n.
Vue
1
star
45

vite-vue2-template

⚡️ Starter template with Vite + Vue2, also support `<script setup>` style.
Vue
1
star
46

taro-echarts-sample

基于Taro使用ECharts示例
JavaScript
1
star
47

wepy-douban-demo

Just another douban weapp demo.
Vue
1
star
48

effective-javascript

68 Specific ways to harness the power of javascript.
1
star
49

image-hub-2021

My personal image hub for 2021.
1
star
50

vuepress-plugin-hero-pattern

🌠A Hero Patterns achievement for VuePress
Vue
1
star
51

astrolabe

Manage your GitHub Stars with One App
Vue
1
star
52

csspen

An interactive CSS demo with live editor and preview. build with Vue.js.
1
star