feat(table): add slot for empty state (#260)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Haytham A. Salama
2023-06-09 18:06:42 +03:00
committed by GitHub
parent 4e5e614eb4
commit f7a34c8fee
3 changed files with 71 additions and 6 deletions

View File

@@ -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>

View File

@@ -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 ## Props
:component-props :component-props

View File

@@ -36,12 +36,14 @@
<tr v-if="emptyState && !rows.length"> <tr v-if="emptyState && !rows.length">
<td :colspan="columns.length"> <td :colspan="columns.length">
<div :class="ui.emptyState.wrapper"> <slot name="empty-state">
<UIcon v-if="emptyState.icon" :name="emptyState.icon" :class="ui.emptyState.icon" aria-hidden="true" /> <div :class="ui.emptyState.wrapper">
<p :class="ui.emptyState.label"> <UIcon v-if="emptyState.icon" :name="emptyState.icon" :class="ui.emptyState.icon" aria-hidden="true" />
{{ emptyState.label }} <p :class="ui.emptyState.label">
</p> {{ emptyState.label }}
</div> </p>
</div>
</slot>
</td> </td>
</tr> </tr>
</tbody> </tbody>