Skip to content

Commit

Permalink
feat(CommandPalette): handle empty-state (#271)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
  • Loading branch information
Haythamasalama and benjamincanac committed Jun 12, 2023
1 parent b4a96a8 commit 652af93
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<UCommandPalette>
<template #empty-state>
<div class="flex flex-col items-center justify-center py-6 gap-3">
<span class="italic text-sm">Nothing here!</span>
<UButton label="Add item" />
</div>
</template>
</UCommandPalette>
</template>
34 changes: 34 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,40 @@ padding: false
Take a look at the component!
::

## Slots

### `empty-state` :u-badge{label="Edge" class="ml-2 align-text-bottom !rounded-full"}

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 groups = [...]
</script>
<template>
<UCommandPalette :groups="groups">
<template #empty-state>
<div class="flex flex-col items-center justify-center py-6 gap-3">
<span class="italic text-sm">Nothing here!</span>
<UButton label="Add item" />
</div>
</template>
</UCommandPalette>
</template>
```
::

## Props

:component-props
Expand Down
16 changes: 10 additions & 6 deletions src/runtime/components/navigation/CommandPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@
</CommandPaletteGroup>
</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>
</div>
<template v-else-if="emptyState">
<slot name="empty-state">
<div :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>
</div>
</slot>
</template>
</div>
</Combobox>
</template>
Expand Down

1 comment on commit 652af93

@vercel
Copy link

@vercel vercel bot commented on 652af93 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxtlabs.vercel.app
ui-git-dev-nuxtlabs.vercel.app
ui.nuxtlabs.com

Please sign in to comment.