Skip to content

Commit e6c02b8

Browse files
committed
refactor(NcChip): use defineSlots for proper slot definition
This resolves 2 errors reported by Typescript when building the package (missing "private" type exports during the declaration creation). Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent d81f990 commit e6c02b8

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/components/NcChip/NcChip.vue

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export default {
7777
'nc-chip--no-icon': !hasIcon(),
7878
}">
7979
<span v-if="hasIcon()" class="nc-chip__icon">
80-
<!-- @slot The icon slot can be used to set the chip icon. Make sure that the icon is not exceeding a height of `24px`. For round icons a exact size of `24px` is recommended. -->
8180
<slot name="icon">
8281
<!-- The default icon wrapper uses a size of 18px to ensure the icon is not clipped by the round chip style -->
8382
<NcIconSvgWrapper v-if="iconPath || iconSvg"
@@ -88,7 +87,6 @@ export default {
8887
</slot>
8988
</span>
9089
<span class="nc-chip__text">
91-
<!-- @slot The default slot can be used to set the text that is shown -->
9290
<slot>{{ text }}</slot>
9391
</span>
9492
<NcActions v-if="canClose || hasActions()"
@@ -103,15 +101,16 @@ export default {
103101
</template>
104102
{{ ariaLabelClose }}
105103
</NcActionButton>
106-
<!-- @slot The actions slot can be used to add custom actions to the chips actions -->
107104
<slot name="actions" />
108105
</NcActions>
109106
</div>
110107
</template>
111108

112109
<script setup lang="ts">
110+
import type { Slot } from 'vue'
111+
113112
import { mdiClose } from '@mdi/js'
114-
import { computed, useSlots } from 'vue'
113+
import { computed } from 'vue'
115114
import { t } from '../../l10n.js'
116115
117116
import NcActions from '../NcActions/NcActions.vue'
@@ -162,8 +161,30 @@ const props = withDefaults(defineProps<{
162161
variant: 'secondary',
163162
})
164163
165-
const emit = defineEmits(['close'])
166-
const slots = useSlots()
164+
const emit = defineEmits<{
165+
/**
166+
* Emitted when the close button is clicked
167+
*/
168+
close: []
169+
}>()
170+
171+
const slots = defineSlots<{
172+
/**
173+
* The actions slot can be used to add custom actions to the chips actions.
174+
*/
175+
actions?: Slot
176+
/**
177+
* The default slot can be used to set the text that is shown.
178+
*/
179+
default?: Slot
180+
/**
181+
* The icon slot can be used to set the chip icon.
182+
*
183+
* Make sure that the icon is not exceeding a height of `24px`.
184+
* For round icons a exact size of `24px` is recommended.
185+
*/
186+
icon?: Slot
187+
}>()
167188
168189
const canClose = computed(() => !props.noClose)
169190
const hasActions = () => Boolean(slots.actions?.())
@@ -173,9 +194,6 @@ const hasIcon = () => Boolean(props.iconPath || props.iconSvg || !!slots.icon?.(
173194
* Handle closing the chip (pressing the X-button)
174195
*/
175196
function onClose() {
176-
/**
177-
* Emitted when the close button is clicked
178-
*/
179197
emit('close')
180198
}
181199
</script>

0 commit comments

Comments
 (0)