Skip to content

Command

新粗野主义风格的命令面板组件,用于搜索和导航。基于 cmdk,通过 reka-ui 模式构建。

预览

Suggestions
Component Library
Installation

安装

pnpm dlx brutx@latest add command

用法

vue
<script setup>
import Command from '@/components/ui/Command.vue'
import CommandInput from '@/components/ui/CommandInput.vue'
import CommandList from '@/components/ui/CommandList.vue'
import CommandEmpty from '@/components/ui/CommandEmpty.vue'
import CommandGroup from '@/components/ui/CommandGroup.vue'
import CommandItem from '@/components/ui/CommandItem.vue'
import CommandSeparator from '@/components/ui/CommandSeparator.vue'
import CommandShortcut from '@/components/ui/CommandShortcut.vue'
</script>

<template>
    <Command>
        <CommandInput placeholder="Type a command or search..." />
        <CommandList>
            <CommandEmpty>No results found.</CommandEmpty>
            <CommandGroup heading="Suggestions">
                <CommandItem value="calendar">Calendar</CommandItem>
                <CommandItem value="search">Search Emoji</CommandItem>
                <CommandItem value="calculator">Calculator</CommandItem>
            </CommandGroup>
            <CommandSeparator />
            <CommandGroup heading="Settings">
                <CommandItem value="profile">Profile</CommandItem>
                <CommandItem value="billing">Billing</CommandItem>
                <CommandItem value="settings">Settings</CommandItem>
            </CommandGroup>
        </CommandList>
    </Command>
</template>

命令对话框

使用 CommandDialog 实现模态命令面板:

vue
<script setup>
import { ref } from 'vue'
import CommandDialog from '@/components/ui/CommandDialog.vue'
import CommandInput from '@/components/ui/CommandInput.vue'
import CommandList from '@/components/ui/CommandList.vue'
import CommandEmpty from '@/components/ui/CommandEmpty.vue'
import CommandGroup from '@/components/ui/CommandGroup.vue'
import CommandItem from '@/components/ui/CommandItem.vue'

const open = ref(false)
</script>

<template>
    <button @click="open = true">Open Command Palette</button>
    <CommandDialog v-model:open="open">
        <CommandInput placeholder="Type a command..." />
        <CommandList>
            <CommandEmpty>No results found.</CommandEmpty>
            <CommandGroup heading="Actions">
                <CommandItem value="new">New File</CommandItem>
                <CommandItem value="open">Open File</CommandItem>
            </CommandGroup>
        </CommandList>
    </CommandDialog>
</template>

子组件

组件说明
Command根容器
CommandDialog模态对话框包装器
CommandInput搜索输入框
CommandList可滚动列表容器
CommandEmpty无匹配结果时显示
CommandGroup带标题的分组区域
CommandItem可选项
CommandSeparator分组之间的视觉分隔线
CommandShortcut键盘快捷键提示

Props

CommandInput

属性类型默认值
modelValuestring
placeholderstring

CommandItem

属性类型默认值
valuestring
disabledboolean

CommandGroup

属性类型默认值
headingstring

CommandDialog

属性类型默认值
openboolean