← catalogo / navigation/command-palettes
TW-NA-CP-02
Tailwind Plus
tailwind/application-ui/navigation/command-palettes/02-simple-with-padding
html: questa e' vue, sotto c'e' il sorgente.
@headlessui/vue@heroicons/vuevue<template>
<TransitionRoot :show="open" as="template" @after-leave="query = ''" appear>
<Dialog class="relative z-10" @close="open = false">
<TransitionChild as="template" enter="ease-out duration-300" enter-from="opacity-0" enter-to="" leave="ease-in duration-200" leave-from="" leave-to="opacity-0">
<div class="fixed inset-0 bg-gray-500/25 transition-opacity dark:bg-gray-900/50" />
</TransitionChild>
<div class="fixed inset-0 z-10 w-screen overflow-y-auto p-4 sm:p-6 md:p-20">
<TransitionChild as="template" enter="ease-out duration-300" enter-from="opacity-0 scale-95" enter-to=" scale-100" leave="ease-in duration-200" leave-from=" scale-100" leave-to="opacity-0 scale-95">
<DialogPanel class="mx-auto max-w-xl transform rounded-xl bg-white p-2 shadow-2xl outline-1 outline-black/5 transition-all dark:bg-gray-900 dark:-outline-offset-1 dark:outline-white/10">
<Combobox @update:modelValue="onSelect">
<ComboboxInput class="w-full rounded-md bg-gray-100 px-4 py-2.5 text-gray-900 outline-hidden placeholder:text-gray-500 sm:text-sm dark:bg-white/5 dark:text-white dark:placeholder:text-gray-400" placeholder="Search..." @change="query = $event.target.value" @blur="query = ''" />
<ComboboxOptions v-if="filteredPeople.length > 0" static class="-mb-2 max-h-72 scroll-py-2 overflow-y-auto py-2 text-sm text-gray-800 dark:text-gray-200">
<ComboboxOption v-for="person in filteredPeople" :key="person.id" :value="person" as="template" v-slot="{ active }">
<li :class="['cursor-default rounded-md px-4 py-2 select-none', active && 'bg-indigo-600 text-white outline-hidden dark:bg-indigo-500']">
{{ person.name }}
</li>
</ComboboxOption>
</ComboboxOptions>
<div v-if="query !== '' && filteredPeople.length === 0" class="px-4 py-14 text-center sm:px-14">
<UsersIcon class="mx-auto size-6 text-gray-400 dark:text-gray-500" aria-hidden="true" />
<p class="mt-4 text-sm text-gray-900 dark:text-gray-300">No people found using that search term.</p>
</div>
</Combobox>
</DialogPanel>
</TransitionChild>
</div>
</Dialog>
</TransitionRoot>
</template>
<script setup>
import { computed, ref } from 'vue'
import { UsersIcon } from '@heroicons/vue/24/outline'
import {
Combobox,
ComboboxInput,
ComboboxOptions,
ComboboxOption,
Dialog,
DialogPanel,
TransitionChild,
TransitionRoot,
} from '@headlessui/vue'
const people = [
{ id: 1, name: 'Leslie Alexander', url: '#' },
// More people...
]
const open = ref(true)
const query = ref('')
const filteredPeople = computed(() =>
query.value === ''
? []
: people.filter((person) => {
return person.name.toLowerCase().includes(query.value.toLowerCase())
}),
)
function onSelect(person) {
if (person) {
window.location = person.url
}
}
</script>