summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/content_editor/components/toolbar_button.vue
blob: 0af12812f3b63b1b90fe4919e98fbf28db8552ae (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 as GlTooltip } from '@gitlab/ui';
import { Editor as TiptapEditor } from '@tiptap/vue-2';

export default {
  components: {
    GlButton,
  },
  directives: {
    GlTooltip,
  },
  props: {
    iconName: {
      type: String,
      required: true,
    },
    tiptapEditor: {
      type: TiptapEditor,
      required: true,
    },
    contentType: {
      type: String,
      required: true,
    },
    label: {
      type: String,
      required: true,
    },
    editorCommand: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    isActive() {
      return this.tiptapEditor.isActive(this.contentType) && this.tiptapEditor.isFocused;
    },
  },
  methods: {
    execute() {
      const { contentType } = this;

      if (this.editorCommand) {
        this.tiptapEditor.chain()[this.editorCommand]().focus().run();
      }

      this.$emit('execute', { contentType });
    },
  },
};
</script>
<template>
  <gl-button
    v-gl-tooltip
    category="tertiary"
    size="small"
    class="gl-mx-2"
    :class="{ active: isActive }"
    :aria-label="label"
    :title="label"
    :icon="iconName"
    @click="execute"
  />
</template>