Welcome to mirror list, hosted at ThFree Co, Russian Federation.

slot_switch.vue « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 641b09e0982e691db066749f2e20a42b306dddb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<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() {
      // eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
      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>