Skip to content

Commit 98e9a96

Browse files
committed
refactor(NcEmptyContent): migrate component to Typescript
- Typescript migration - Use CSS instead of computation of slots Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 9431eed commit 98e9a96

File tree

8 files changed

+72
-42
lines changed

8 files changed

+72
-42
lines changed

src/components/NcAppSidebar/NcAppSidebar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ import NcAppSidebarTabs from './NcAppSidebarTabs.vue'
715715
import NcActions from '../NcActions/index.js'
716716
import NcAppSidebarHeader from '../NcAppSidebarHeader/index.ts'
717717
import NcButton from '../NcButton/index.ts'
718-
import NcEmptyContent from '../NcEmptyContent/index.js'
718+
import NcEmptyContent from '../NcEmptyContent/index.ts'
719719
import NcLoadingIcon from '../NcLoadingIcon/index.js'
720720
import Focus from '../../directives/Focus/index.js'
721721
import { vOnClickOutside as ClickOutside } from '@vueuse/components'

src/components/NcDashboardWidget/NcDashboardWidget.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export default {
215215
<script>
216216
import NcAvatar from '../NcAvatar/index.js'
217217
import NcDashboardWidgetItem from '../NcDashboardWidgetItem/index.js'
218-
import NcEmptyContent from '../NcEmptyContent/index.js'
218+
import NcEmptyContent from '../NcEmptyContent/index.ts'
219219
220220
import Check from 'vue-material-design-icons/Check.vue'
221221

src/components/NcEmptyContent/NcEmptyContent.vue

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -121,57 +121,71 @@ export default {
121121
```
122122
</docs>
123123

124+
<script setup lang="ts">
125+
import type { Slot } from 'vue'
126+
127+
withDefaults(defineProps<{
128+
/**
129+
* A header message about an empty content shown.
130+
*
131+
* @example 'No comments'
132+
*/
133+
name?: string
134+
135+
/**
136+
* Desription of the empty content
137+
*
138+
* @example 'No comments yet, start the conversation!'
139+
*/
140+
description?: string
141+
}>(), {
142+
description: '',
143+
name: '',
144+
})
145+
146+
defineSlots<{
147+
/**
148+
* Optional slot for a button or the like
149+
*/
150+
action?: Slot
151+
152+
/**
153+
* Optional slot for adding an icon
154+
*/
155+
icon?: Slot
156+
157+
/**
158+
* Allow to add custom formatted name as an alternative to the name property.
159+
* The content passed shall be enclosed by a header element.
160+
*/
161+
name?: Slot
162+
163+
/**
164+
* Optional formatted description rendered inside a paragraph as an alternative to the description property.
165+
*/
166+
description?: Slot
167+
}>()
168+
</script>
169+
124170
<template>
125171
<div class="empty-content" role="note">
126-
<div v-if="$slots.icon" class="empty-content__icon" aria-hidden="true">
127-
<!-- @slot Optional material design icon -->
172+
<div class="empty-content__icon" aria-hidden="true">
128173
<slot name="icon" />
129174
</div>
130-
<!-- @slot Optional name if not set as property, shall be enclosed by a header element -->
131175
<slot name="name">
132-
<span v-if="name !== ''" class="empty-content__name">
133-
{{ name }}
134-
</span>
176+
<span class="empty-content__name" v-text="name" />
135177
</slot>
136-
<p v-if="description !== '' || $slots.description" class="empty-content__description">
137-
<!-- @slot Optional formatted description rendered inside a paragraph -->
178+
<p class="empty-content__description">
138179
<slot name="description">
139180
{{ description }}
140181
</slot>
141182
</p>
142-
<div v-if="$slots.action" class="empty-content__action">
143-
<!-- @slot Optional slot for a button or the like -->
183+
<div class="empty-content__action">
144184
<slot name="action" />
145185
</div>
146186
</div>
147187
</template>
148188

149-
<script>
150-
export default {
151-
name: 'NcEmptyContent',
152-
153-
props: {
154-
/**
155-
* A header message about an empty content shown
156-
* @example 'No comments'
157-
*/
158-
name: {
159-
type: String,
160-
default: '',
161-
},
162-
163-
/**
164-
* Desription of the empty content
165-
* @example 'No comments yet, start the conversation!'
166-
*/
167-
description: {
168-
type: String,
169-
default: '',
170-
},
171-
},
172-
}
173-
</script>
174-
175189
<style lang="scss" scoped>
176190
.empty-content {
177191
display: flex;
@@ -198,6 +212,10 @@ export default {
198212
background-position: center;
199213
background-size: 64px;
200214
215+
&:empty {
216+
display: none;
217+
}
218+
201219
:deep(svg) {
202220
width: 64px !important;
203221
height: 64px !important;
@@ -212,15 +230,27 @@ export default {
212230
font-weight: bold;
213231
font-size: 20px;
214232
line-height: 30px;
233+
234+
&:empty {
235+
display: none;
236+
}
215237
}
216238
217239
&__description {
218240
color: var(--color-text-maxcontrast);
241+
242+
&:empty {
243+
display: none;
244+
}
219245
}
220246
221247
&__action {
222248
margin-top: 8px;
223249
250+
&:empty {
251+
display: none;
252+
}
253+
224254
.modal-wrapper & {
225255
margin-top: 20px;
226256
display: flex;
File renamed without changes.

src/components/NcRichText/NcReferencePicker/NcProviderList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<script>
4545
import { searchProvider } from './../../../functions/reference/providerHelper.js'
4646
import { isUrl } from './utils.js'
47-
import NcEmptyContent from '../../NcEmptyContent/index.js'
47+
import NcEmptyContent from '../../NcEmptyContent/index.ts'
4848
import NcHighlight from '../../NcHighlight/index.js'
4949
import NcSelect from '../../NcSelect/index.js'
5050
import { t } from '../../../l10n.js'

src/components/NcRichText/NcReferencePicker/NcRawLinkInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<script>
3636
import NcReferenceWidget from '../NcReferenceWidget.vue'
3737
import { isUrl, delay } from './utils.js'
38-
import NcEmptyContent from '../../NcEmptyContent/index.js'
38+
import NcEmptyContent from '../../NcEmptyContent/index.ts'
3939
import NcLoadingIcon from '../../NcLoadingIcon/index.js'
4040
import NcTextField from '../../NcTextField/index.js'
4141
import { t } from '../../../l10n.js'

src/components/NcRichText/NcReferencePicker/NcSearch.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<script>
7171
import NcSearchResult from './NcSearchResult.vue'
7272
import { isUrl, delay } from './utils.js'
73-
import NcEmptyContent from '../../NcEmptyContent/index.js'
73+
import NcEmptyContent from '../../NcEmptyContent/index.ts'
7474
import NcSelect from '../../NcSelect/index.js'
7575
7676
import { t } from '../../../l10n.js'

src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export { default as NcDialog } from './NcDialog/index.js'
5353
export { default as NcDialogButton } from './NcDialogButton/index.js'
5454
export { default as NcEllipsisedOption } from './NcEllipsisedOption/index.js'
5555
export { default as NcEmojiPicker } from './NcEmojiPicker/index.js'
56-
export { default as NcEmptyContent } from './NcEmptyContent/index.js'
56+
export { default as NcEmptyContent } from './NcEmptyContent/index.ts'
5757
export { default as NcGuestContent } from './NcGuestContent/index.js'
5858
export { default as NcHeaderButton } from './NcHeaderButton/index'
5959
export { default as NcHeaderMenu } from './NcHeaderMenu/index.js'

0 commit comments

Comments
 (0)