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

source_editor_toolbar_button.vue « components « editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 38f586f077308bd4ca785da3fef627191899a525 (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
<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;
    },
  },
  mounted() {
    if (this.button.data) {
      Object.entries(this.button.data).forEach(([attr, value]) => {
        this.$el.dataset[attr] = value;
      });
    }
  },
  methods: {
    clickHandler(event) {
      if (this.button.onClick) {
        this.button.onClick(event);
      }
      this.$emit('click', event);
    },
  },
};
</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"
    :class="button.class"
    @click="clickHandler($event)"
  />
</template>