Skip to content

Commit

Permalink
feat(CommandPalette): handle empty-state
Browse files Browse the repository at this point in the history
  • Loading branch information
Haythamasalama committed Jun 9, 2023
1 parent f0b24ba commit eecf8c5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<UCommandPalette :groups="[]">
<template #empty-state>
<div class="flex flex-col items-center justify-center gap-3">
<UIcon name="i-heroicons-magnifying-glass-20-solid" class="w-6 h-6 text-gray-400" />
<span class="text-sm text-center text-gray-900 dark:text-white">We couldn't find any items!</span>
<div>
<UButton label="Add item" />
<UButton label="Clear Search" class="ml-2" color="primary" variant="outline"/>
</div>
</div>
</template>
</UCommandPalette>
</template>
38 changes: 38 additions & 0 deletions docs/content/5.navigation/2.command-palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,44 @@ padding: false
Take a look at the component!
::

## Slots

### `empty-state`

Use the `#empty-state` slot to customize the empty state.

::component-example{class="grid"}
---
padding: false
overflowClass: 'overflow-x-auto'
---

#default
:command-palette-example-empty-slot{class="flex-1"}

#code
```vue
<script setup>
const items = [...]
</script>
<template>
<UCommandPalette :groups="items">
<template #empty-state>
<div class="flex flex-col items-center justify-center gap-3">
<UIcon name="i-heroicons-magnifying-glass-20-solid" class="w-6 h-6 text-gray-400" />
<span class="text-sm text-center text-gray-900 dark:text-white">We couldn't find any items!</span>
<div>
<UButton label="Add item" />
<UButton label="Clear Search" class="ml-2" color="primary" variant="outline"/>
</div>
</div>
</template>
</UCommandPalette>
</template>
```
::

## Props

:component-props
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/components/navigation/CommandPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
</ComboboxOptions>

<div v-else-if="emptyState" :class="ui.emptyState.wrapper">
<UIcon v-if="emptyState.icon" :name="emptyState.icon" :class="ui.emptyState.icon" aria-hidden="true" />
<p :class="query ? ui.emptyState.queryLabel : ui.emptyState.label">
{{ query ? emptyState.queryLabel : emptyState.label }}
</p>
<slot name="empty-state">
<UIcon v-if="emptyState.icon" :name="emptyState.icon" :class="ui.emptyState.icon" aria-hidden="true" />
<p :class="query ? ui.emptyState.queryLabel : ui.emptyState.label">
{{ query ? emptyState.queryLabel : emptyState.label }}
</p>
</slot>
</div>
</div>
</Combobox>
Expand Down

0 comments on commit eecf8c5

Please sign in to comment.