debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/slot_switch.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
673 B
Vue
Raw Normal View History

2019-12-26 22:10:19 +05:30
<script>
/**
* Allows to toggle slots based on an array of slot names.
*/
export default {
name: 'SlotSwitch',
props: {
activeSlotNames: {
type: Array,
required: true,
},
tagName: {
type: String,
required: false,
default: 'div',
},
},
computed: {
allSlotNames() {
2022-08-13 15:12:31 +05:30
// eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
2019-12-26 22:10:19 +05:30
return Object.keys(this.$slots);
},
},
};
</script>
<template>
<component :is="tagName">
<template v-for="slotName in allSlotNames">
<slot v-if="activeSlotNames.includes(slotName)" :name="slotName"></slot>
</template>
</component>
</template>