mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
40 lines
1.0 KiB
Vue
40 lines
1.0 KiB
Vue
<script setup lang="ts">
|
|
const searchTerm = ref('')
|
|
|
|
const { data: users, status } = await useFetch('https://jsonplaceholder.typicode.com/users', {
|
|
params: { q: searchTerm },
|
|
transform: (data: { id: number, name: string, email: string }[]) => {
|
|
return data?.map(user => ({ id: user.id, label: user.name, suffix: user.email, avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` } })) || []
|
|
},
|
|
lazy: true
|
|
})
|
|
|
|
const groups = computed(() => [{
|
|
id: 'users',
|
|
label: searchTerm.value ? `Users matching “${searchTerm.value}”...` : 'Users',
|
|
items: users.value || [],
|
|
ignoreFilter: true
|
|
}])
|
|
</script>
|
|
|
|
<template>
|
|
<UDrawer :handle="false">
|
|
<UButton
|
|
label="Search users..."
|
|
color="neutral"
|
|
variant="subtle"
|
|
icon="i-lucide-search"
|
|
/>
|
|
|
|
<template #content>
|
|
<UCommandPalette
|
|
v-model:search-term="searchTerm"
|
|
:loading="status === 'pending'"
|
|
:groups="groups"
|
|
placeholder="Search users..."
|
|
class="h-80"
|
|
/>
|
|
</template>
|
|
</UDrawer>
|
|
</template>
|