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>
|