summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/content_editor/components/top_toolbar.vue
blob: d3363ce092ba1dc8828bc7a06b75f1ada26cb87b (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<script>
import Tracking from '~/tracking';
import { CONTENT_EDITOR_TRACKING_LABEL, TOOLBAR_CONTROL_TRACKING_ACTION } from '../constants';
import { ContentEditor } from '../services/content_editor';
import Divider from './divider.vue';
import ToolbarButton from './toolbar_button.vue';
import ToolbarLinkButton from './toolbar_link_button.vue';
import ToolbarTextStyleDropdown from './toolbar_text_style_dropdown.vue';

const trackingMixin = Tracking.mixin({
  label: CONTENT_EDITOR_TRACKING_LABEL,
});

export default {
  components: {
    ToolbarButton,
    ToolbarTextStyleDropdown,
    ToolbarLinkButton,
    Divider,
  },
  mixins: [trackingMixin],
  props: {
    contentEditor: {
      type: ContentEditor,
      required: true,
    },
  },
  methods: {
    trackToolbarControlExecution({ contentType: property, value }) {
      this.track(TOOLBAR_CONTROL_TRACKING_ACTION, {
        property,
        value,
      });
    },
  },
};
</script>
<template>
  <div
    class="gl-display-flex gl-justify-content-end gl-pb-3 gl-pt-0 gl-border-b-solid gl-border-b-1 gl-border-b-gray-200"
  >
    <toolbar-text-style-dropdown
      data-testid="text-styles"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <divider />
    <toolbar-button
      data-testid="bold"
      content-type="bold"
      icon-name="bold"
      editor-command="toggleBold"
      :label="__('Bold text')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-button
      data-testid="italic"
      content-type="italic"
      icon-name="italic"
      editor-command="toggleItalic"
      :label="__('Italic text')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-button
      data-testid="strike"
      content-type="strike"
      icon-name="strikethrough"
      editor-command="toggleStrike"
      :label="__('Strikethrough')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-button
      data-testid="code"
      content-type="code"
      icon-name="code"
      editor-command="toggleCode"
      :label="__('Code')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-link-button
      data-testid="link"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <divider />
    <toolbar-button
      data-testid="blockquote"
      content-type="blockquote"
      icon-name="quote"
      editor-command="toggleBlockquote"
      :label="__('Insert a quote')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-button
      data-testid="code-block"
      content-type="codeBlock"
      icon-name="doc-code"
      editor-command="toggleCodeBlock"
      :label="__('Insert a code block')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-button
      data-testid="bullet-list"
      content-type="bulletList"
      icon-name="list-bulleted"
      editor-command="toggleBulletList"
      :label="__('Add a bullet list')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
    <toolbar-button
      data-testid="ordered-list"
      content-type="orderedList"
      icon-name="list-numbered"
      editor-command="toggleOrderedList"
      :label="__('Add a numbered list')"
      :tiptap-editor="contentEditor.tiptapEditor"
      @execute="trackToolbarControlExecution"
    />
  </div>
</template>