Skip to content

Commit

Permalink
Merge pull request #3895 from nextcloud/feat/ncemptycontent-descripti…
Browse files Browse the repository at this point in the history
…on-slot

feat: Add slot for description of `NcEmptyContent`
  • Loading branch information
raimund-schluessler committed May 23, 2023
2 parents 7e14037 + 9b946d4 commit 7ebec9e
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/components/NcEmptyContent/NcEmptyContent.vue
Expand Up @@ -48,7 +48,8 @@ export default {
```

You can also customize the name using the `#name` slot
and add actions.
and add actions. But to keep the style consistent across Nextcloud
consider only using header elements as the root elements for the name slot.

```
<template>
Expand All @@ -59,7 +60,7 @@ and add actions.
</template>
<template #name>
<h1 class="empty-content__name">
No Comments
No comments
</h1>
</template>
<template #action>
Expand All @@ -73,6 +74,34 @@ and add actions.
<script>
import Comment from 'vue-material-design-icons/Comment'
export default {
components: {
Comment,
},
}
</script>
```

Similar to the `#name` slot, you could also use the `#description` slot.
The content will be rendered within a paragraph so you can use any inline element,
like a link.

```
<template>
<NcEmptyContent
name="No comments">
<template #icon>
<Comment />
</template>
<template #description>
<a href="https://en.wikipedia.org/wiki/Comment">What is even a comment?</a>
</template>
</NcEmptyContent>
</template>

<script>
import Comment from 'vue-material-design-icons/Comment'
export default {
components: {
Comment,
Expand All @@ -88,13 +117,17 @@ export default {
<!-- @slot Optional material design icon -->
<slot name="icon" />
</div>
<!-- @slot Optional name if not set as property, shall be enclosed by a header element -->
<slot name="name">
<h2 v-if="hasName" class="empty-content__name">
{{ name }}
</h2>
</slot>
<p v-if="hasDescription">
{{ description }}
<!-- @slot Optional formatted description rendered inside a paragraph -->
<slot name="description">
{{ description }}
</slot>
</p>
<div v-if="$slots.action" class="empty-content__action">
<!-- @slot Optional slot for a button or the like -->
Expand Down Expand Up @@ -123,8 +156,11 @@ export default {
hasName() {
return this.name !== ''
},
/**
* Check if a description is given as either property or slot
*/
hasDescription() {
return this.description !== ''
return this.description !== '' || this.$slots.description?.[0]
},
},
}
Expand Down

0 comments on commit 7ebec9e

Please sign in to comment.