summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/droplab_dropdown_button.vue
blob: 7d49c87271d77e3ae6616b3cba13e17b9c8617ed (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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<script>
import { GlButton } from '@gitlab/ui';
import Icon from './icon.vue';

export default {
  components: {
    Icon,
    GlButton,
  },
  props: {
    size: {
      type: String,
      required: false,
      default: '',
    },
    primaryButtonClass: {
      type: String,
      required: false,
      default: '',
    },
    dropdownClass: {
      type: String,
      required: false,
      default: '',
    },
    actions: {
      type: Array,
      required: true,
    },
    defaultAction: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      selectedAction: this.defaultAction,
    };
  },
  computed: {
    selectedActionTitle() {
      return this.actions[this.selectedAction].title;
    },
    buttonSizeClass() {
      return `btn-${this.size}`;
    },
  },
  methods: {
    handlePrimaryActionClick() {
      this.$emit('onActionClick', this.actions[this.selectedAction]);
    },
    handleActionClick(selectedAction) {
      this.selectedAction = selectedAction;
      this.$emit('onActionSelect', selectedAction);
    },
  },
};
</script>

<template>
  <div class="btn-group droplab-dropdown comment-type-dropdown">
    <gl-button :class="primaryButtonClass" :size="size" @click.prevent="handlePrimaryActionClick">
      {{ selectedActionTitle }}
    </gl-button>
    <button
      :class="buttonSizeClass"
      type="button"
      class="btn dropdown-toggle pl-2 pr-2"
      data-display="static"
      data-toggle="dropdown"
    >
      <icon name="arrow-down" aria-label="toggle dropdown" />
    </button>
    <ul :class="dropdownClass" class="dropdown-menu dropdown-open-top">
      <template v-for="(action, index) in actions">
        <li :key="index" :class="{ 'droplab-item-selected': selectedAction === index }">
          <gl-button class="btn-transparent" @click.prevent="handleActionClick(index)">
            <i aria-hidden="true" class="fa fa-check icon"> </i>
            <div class="description">
              <strong>{{ action.title }}</strong>
              <p>{{ action.description }}</p>
            </div>
          </gl-button>
        </li>
        <li v-if="index === 0" :key="`${index}-separator`" class="divider droplab-item-ignore"></li>
      </template>
    </ul>
  </div>
</template>