summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/editor/components/source_editor_toolbar_button.vue
blob: 194b482c12ef1fe85329f1e298ce07d531ccc2ab (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
<script>
import { GlButton, GlTooltipDirective } from '@gitlab/ui';

export default {
  name: 'SourceEditorToolbarButton',
  components: {
    GlButton,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    button: {
      type: Object,
      required: false,
      default() {
        return {};
      },
    },
  },
  computed: {
    icon() {
      return this.button.selected ? this.button.selectedIcon || this.button.icon : this.button.icon;
    },
    label() {
      return this.button.selected
        ? this.button.selectedLabel || this.button.label
        : this.button.label;
    },
    showButton() {
      return Object.entries(this.button).length > 0;
    },
  },
  methods: {
    clickHandler() {
      if (this.button.onClick) {
        this.button.onClick();
      }
      this.$emit('click');
    },
  },
};
</script>
<template>
  <gl-button
    v-if="showButton"
    v-gl-tooltip.hover
    :category="button.category"
    :variant="button.variant"
    type="button"
    :selected="button.selected"
    :icon="icon"
    :title="label"
    :aria-label="label"
    @click="clickHandler"
  />
</template>