dropdown_value.vue 1.2 KB
Newer Older
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
<script>
import tooltip from '~/vue_shared/directives/tooltip';

export default {
  directives: {
    tooltip,
  },
  props: {
    labels: {
      type: Array,
      required: true,
    },
    labelFilterBasePath: {
      type: String,
      required: true,
    },
  },
  computed: {
    isEmpty() {
      return this.labels.length === 0;
    },
  },
  methods: {
    labelFilterUrl(label) {
      return `${this.labelFilterBasePath}?label_name[]=${encodeURIComponent(label.title)}`;
    },
    labelStyle(label) {
      return {
        color: label.textColor,
        backgroundColor: label.color,
      };
    },
  },
};
</script>

<template>
  <div class="hide-collapsed value issuable-show-labels">
    <span
      v-if="isEmpty"
      class="text-secondary"
    >
      <slot>{{ __('None') }}</slot>
    </span>
    <a
      v-else
      v-for="label in labels"
      :key="label.id"
      :href="labelFilterUrl(label)"
    >
      <span
        v-tooltip
        class="label color-label"
        data-placement="bottom"
        data-container="body"
        :style="labelStyle(label)"
        :title="label.description"
      >
        {{ label.title }}
      </span>
    </a>
  </div>
</template>