Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessible EmptyContent component #2867

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions src/components/EmptyContent/EmptyContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,36 @@
### Basic use

Use this component to display a message about an empty content.
An icon and a title are mandatory.
Providing an additional description is strongly advised.
Providing an icon, title, and a description is strongly advised.

```
<EmptyContent icon="icon-comment">
<EmptyContent>
No comments
<template #icon>
<Comment />
</template>
<template #desc>No comments in here</template>
</EmptyContent>
```
```
<template>
<EmptyContent>
Network error
<template #icon><Airplane /></template>
<template #icon>
<Airplane />
</template>
<template #desc>Unable to load the list</template>
</EmptyContent>
</template>

<script>
import Airplane from 'vue-material-design-icons/Airplane'
import Comment from 'vue-material-design-icons/Comment'

export default {
components: {
Airplane
Airplane,
Comment,
}
}
</script>
Expand All @@ -57,15 +63,15 @@ export default {

<template>
<div class="empty-content" role="note">
<div class="empty-content__icon" :class="icon" role="img">
<!-- @slot Optional icon slot -->
<div v-if="hasIcon" class="empty-content__icon">
<!-- @slot Optional material design icon -->
<slot name="icon" />
</div>
<h2 class="empty-content__title">
<!-- @slot Mandatory title -->
<h2 v-if="hasTitle" class="empty-content__title">
<!-- @slot Optional title -->
<slot />
</h2>
<p v-show="$slots.desc">
<p v-if="hasDescription">
<!-- @slot Optional description -->
<slot name="desc" />
</p>
Expand All @@ -75,13 +81,29 @@ export default {
<script>
export default {
name: 'EmptyContent',
props: {
/**
* The main icon illustration
*/
icon: {
type: String,
default: '',

data() {
return {
/**
* Making sure the slots are reactive
*/
slots: this.$slots,
}
},

computed: {
hasIcon() {
return this.slots.icon !== undefined
},

hasTitle() {
return this.slots?.default !== undefined
&& this.slots?.default[0]?.text
},

hasDescription() {
return this.slots?.desc !== undefined
&& this.slots?.desc[0]?.text
},
},
}
Expand Down Expand Up @@ -117,5 +139,4 @@ export default {
text-align: center;
}
}

</style>