Skip to content

refactor(NcChip): use defineSlots for proper slot definition #6792

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 27 additions & 9 deletions src/components/NcChip/NcChip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export default {
'nc-chip--no-icon': !hasIcon(),
}">
<span v-if="hasIcon()" class="nc-chip__icon">
<!-- @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. -->
<slot name="icon">
<!-- The default icon wrapper uses a size of 18px to ensure the icon is not clipped by the round chip style -->
<NcIconSvgWrapper v-if="iconPath || iconSvg"
Expand All @@ -88,7 +87,6 @@ export default {
</slot>
</span>
<span class="nc-chip__text">
<!-- @slot The default slot can be used to set the text that is shown -->
<slot>{{ text }}</slot>
</span>
<NcActions v-if="canClose || hasActions()"
Expand All @@ -103,15 +101,16 @@ export default {
</template>
{{ ariaLabelClose }}
</NcActionButton>
<!-- @slot The actions slot can be used to add custom actions to the chips actions -->
<slot name="actions" />
</NcActions>
</div>
</template>

<script setup lang="ts">
import type { Slot } from 'vue'

import { mdiClose } from '@mdi/js'
import { computed, useSlots } from 'vue'
import { computed } from 'vue'
import { t } from '../../l10n.js'

import NcActions from '../NcActions/NcActions.vue'
Expand Down Expand Up @@ -162,8 +161,30 @@ const props = withDefaults(defineProps<{
variant: 'secondary',
})

const emit = defineEmits(['close'])
const slots = useSlots()
const emit = defineEmits<{
/**
* Emitted when the close button is clicked
*/
close: []
}>()

const slots = defineSlots<{
/**
* The actions slot can be used to add custom actions to the chips actions.
*/
actions?: Slot
/**
* The default slot can be used to set the text that is shown.
*/
default?: 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.
*/
icon?: Slot
}>()

const canClose = computed(() => !props.noClose)
const hasActions = () => Boolean(slots.actions?.())
Expand All @@ -173,9 +194,6 @@ const hasIcon = () => Boolean(props.iconPath || props.iconSvg || !!slots.icon?.(
* Handle closing the chip (pressing the X-button)
*/
function onClose() {
/**
* Emitted when the close button is clicked
*/
emit('close')
}
</script>
Expand Down
Loading