summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/markdown/toolbar_button.vue
blob: 5ca21522d33f53fa58d4b61aaedb42b6bb5ea60b (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
90
91
92
93
94
95
96
97
98
99
<script>
import { GlTooltipDirective, GlButton } from '@gitlab/ui';

export default {
  components: {
    GlButton,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    buttonTitle: {
      type: String,
      required: true,
    },
    icon: {
      type: String,
      required: true,
    },
    tag: {
      type: String,
      required: false,
      default: '',
    },
    tagBlock: {
      type: String,
      required: false,
      default: '',
    },
    tagSelect: {
      type: String,
      required: false,
      default: '',
    },
    prepend: {
      type: Boolean,
      required: false,
      default: false,
    },
    tagContent: {
      type: String,
      required: false,
      default: '',
    },
    cursorOffset: {
      type: Number,
      required: false,
      default: 0,
    },
    command: {
      type: String,
      required: false,
      default: '',
    },

    /**
     * A string (or an array of strings) of
     * [mousetrap](https://craig.is/killing/mice) keyboard shortcuts
     * that should be attached to this button. For example:
     * "command+k"
     * ...or...
     * ["command+k", "ctrl+k"]
     */
    shortcuts: {
      type: [String, Array],
      required: false,
      default: () => [],
    },
  },
  computed: {
    shortcutsString() {
      const shortcutArray = Array.isArray(this.shortcuts) ? this.shortcuts : [this.shortcuts];
      return JSON.stringify(shortcutArray);
    },
  },
};
</script>

<template>
  <gl-button
    v-gl-tooltip
    :data-md-tag="tag"
    :data-md-cursor-offset="cursorOffset"
    :data-md-select="tagSelect"
    :data-md-block="tagBlock"
    :data-md-tag-content="tagContent"
    :data-md-prepend="prepend"
    :data-md-shortcuts="shortcutsString"
    :data-md-command="command"
    :title="buttonTitle"
    :aria-label="buttonTitle"
    :icon="icon"
    type="button"
    category="tertiary"
    class="js-md"
    data-container="body"
    @click="$emit('click', $event)"
  />
</template>