Skip to content

Commit

Permalink
feat(table): add slot for empty state (#260)
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 authored Jun 9, 2023
1 parent 4e5e614 commit f7a34c8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
30 changes: 30 additions & 0 deletions docs/components/content/examples/TableExampleEmptySlot.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup>
const columns = [{
key: 'name',
label: 'Name'
}, {
key: 'title',
label: 'Title'
}, {
key: 'email',
label: 'Email'
}, {
key: 'role',
label: 'Role'
}, {
key: 'actions'
}]
const people = []
</script>

<template>
<UTable :rows="people" :columns="columns">
<template #empty-state>
<div class="flex flex-col items-center justify-center py-6 gap-3">
<span class="italic text-sm">No one here!</span>
<UButton label="Add people" />
</div>
</template>
</UTable>
</template>
33 changes: 33 additions & 0 deletions docs/content/4.data/1.table.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,39 @@ const selected = ref([people[1]])
```
::

### `empty-state`

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

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

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

#code
```vue
<script setup>
const columns = [...]
const people = [...]
</script>
<template>
<UTable :rows="people" :columns="columns">
<template #empty-state>
<div class="flex flex-col items-center justify-center py-6 gap-3">
<span class="italic text-sm">No one here!</span>
<UButton label="Add people" />
</div>
</template>
</UTable>
</template>
```
::

## Props

:component-props
Expand Down
14 changes: 8 additions & 6 deletions src/runtime/components/data/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@

<tr v-if="emptyState && !rows.length">
<td :colspan="columns.length">
<div :class="ui.emptyState.wrapper">
<UIcon v-if="emptyState.icon" :name="emptyState.icon" :class="ui.emptyState.icon" aria-hidden="true" />
<p :class="ui.emptyState.label">
{{ emptyState.label }}
</p>
</div>
<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="ui.emptyState.label">
{{ emptyState.label }}
</p>
</div>
</slot>
</td>
</tr>
</tbody>
Expand Down

1 comment on commit f7a34c8

@vercel
Copy link

@vercel vercel bot commented on f7a34c8 Jun 9, 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-git-dev-nuxtlabs.vercel.app
ui-nuxtlabs.vercel.app
ui.nuxtlabs.com

Please sign in to comment.