A searchable list of options or actions, inline or as a palette.
Listbox
A searchable listbox: type to filter the groups, arrows to move, Enter to choose; the chosen value is checked.
<script setup>
import { ref } from 'vue';
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@aisgroup/design/ui/command';
const value = ref('m-inspection-02');
</script>
<template>
<Command v-model="value" class="max-w-sm border">
<CommandInput placeholder="Search models" />
<CommandList>
<CommandEmpty>No model matches.</CommandEmpty>
<CommandGroup heading="PCB inspection">
<CommandItem value="m-inspection-01">m-inspection-01</CommandItem>
<CommandItem value="m-inspection-02">m-inspection-02</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Tortilla line">
<CommandItem value="m-food-01">m-food-01</CommandItem>
<CommandItem value="m-food-02">m-food-02</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</template>Palette
A command palette in a dialog, opened by its button or Ctrl K (Cmd K on a Mac): search, then run with Enter.
<script setup>
import { ref } from 'vue';
import { useEventListener } from '@vueuse/core';
import { DatabaseIcon, PlusIcon, SearchIcon, SettingsIcon, BoxIcon } from '@lucide/vue';
import { Button } from '@aisgroup/design/ui/button';
import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@aisgroup/design/ui/command';
import { Kbd } from '@aisgroup/design/ui/kbd';
const open = ref(false);
useEventListener('keydown', (e) => {
if (e.key.toLowerCase() === 'k' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); open.value = !open.value; }
});
</script>
<template>
<Button variant="outline" class="w-64 justify-start text-muted-foreground" @click="open = true">
<SearchIcon data-icon="inline-start" />Search<Kbd class="ml-auto">Ctrl K</Kbd>
</Button>
<CommandDialog v-model:open="open">
<CommandInput placeholder="Type a command or search" />
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
<CommandGroup heading="Create">
<CommandItem value="new-dataset" @select="open = false"><PlusIcon />New dataset</CommandItem>
<CommandItem value="new-model" @select="open = false"><PlusIcon />New model</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Go to">
<CommandItem value="datasets" @select="open = false"><DatabaseIcon />Datasets</CommandItem>
<CommandItem value="models" @select="open = false"><BoxIcon />Models</CommandItem>
<CommandItem value="settings" @select="open = false"><SettingsIcon />Settings</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>
</template>