mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-25 09:20:36 +01:00
docs: add CommandPalette async search example
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
<script setup>
|
||||||
|
const groups = computed(() => {
|
||||||
|
return [{
|
||||||
|
key: 'users',
|
||||||
|
label: q => q && `Users matching “${q}”...`,
|
||||||
|
search: async (q) => {
|
||||||
|
if (!q) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = await $fetch(`https://jsonplaceholder.typicode.com/users`, { params: { q } })
|
||||||
|
|
||||||
|
return users.map(user => ({ id: user.id, label: user.name, suffix: user.email }))
|
||||||
|
}
|
||||||
|
}].filter(Boolean)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UCommandPalette :groups="groups" :autoselect="false" />
|
||||||
|
</template>
|
||||||
@@ -261,6 +261,43 @@ You can also highlight the matches in the command by setting the `fuse.fuseOptio
|
|||||||
Try it yourself in this documentation's search by pressing :badge-shortcut{value="meta"} :badge-shortcut{value="K" class="ml-1"}.
|
Try it yourself in this documentation's search by pressing :badge-shortcut{value="meta"} :badge-shortcut{value="K" class="ml-1"}.
|
||||||
::
|
::
|
||||||
|
|
||||||
|
## Async search
|
||||||
|
|
||||||
|
You can also pass an `async` function to the `search` property of a group to perform an async search. The function will receive the query as its first argument and should return an array of commands.
|
||||||
|
|
||||||
|
::component-example
|
||||||
|
---
|
||||||
|
padding: false
|
||||||
|
---
|
||||||
|
|
||||||
|
#default
|
||||||
|
:command-palette-example-async{class="h-[274px]"}
|
||||||
|
#code
|
||||||
|
```vue
|
||||||
|
<script setup>
|
||||||
|
const groups = computed(() => {
|
||||||
|
return [{
|
||||||
|
key: 'users',
|
||||||
|
label: q => q && `Users matching “${q}”...`,
|
||||||
|
search: async (q) => {
|
||||||
|
if (!q) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = await $fetch(`https://jsonplaceholder.typicode.com/users`, { params: { q } })
|
||||||
|
|
||||||
|
return users.map(user => ({ id: user.id, label: user.name, suffix: user.email }))
|
||||||
|
}
|
||||||
|
}].filter(Boolean)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UCommandPalette :groups="groups" />
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
::
|
||||||
|
|
||||||
## Themes
|
## Themes
|
||||||
|
|
||||||
Our theming system provides a lot of flexibility to customize the component. Here is some examples of what you can do.
|
Our theming system provides a lot of flexibility to customize the component. Here is some examples of what you can do.
|
||||||
|
|||||||
Reference in New Issue
Block a user