summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/snippets/components/embed_dropdown.vue
blob: ad1b08a5a07a0eee53615f65ae9be0858c173312 (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
<script>
import {
  GlButton,
  GlDropdown,
  GlDropdownSectionHeader,
  GlDropdownText,
  GlFormInputGroup,
  GlTooltipDirective,
} from '@gitlab/ui';
import { escape as esc } from 'lodash';
import { __ } from '~/locale';

const MSG_EMBED = __('Embed');
const MSG_SHARE = __('Share');
const MSG_COPY = __('Copy');

export default {
  components: {
    GlButton,
    GlDropdown,
    GlDropdownSectionHeader,
    GlDropdownText,
    GlFormInputGroup,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    url: {
      type: String,
      required: true,
    },
  },
  computed: {
    sections() {
      return [
        // eslint-disable-next-line no-useless-escape
        { name: MSG_EMBED, value: `<script src="${esc(this.url)}.js"><\/script>` },
        { name: MSG_SHARE, value: this.url },
      ];
    },
  },
  MSG_EMBED,
  MSG_COPY,
};
</script>
<template>
  <gl-dropdown
    right
    :text="$options.MSG_EMBED"
    menu-class="gl-px-1! gl-pb-5! gl-dropdown-menu-wide"
  >
    <template v-for="{ name, value } in sections">
      <gl-dropdown-section-header :key="`header_${name}`" data-testid="header">{{
        name
      }}</gl-dropdown-section-header>
      <gl-dropdown-text
        :key="`input_${name}`"
        tag="div"
        class="gl-dropdown-text-py-0 gl-dropdown-text-block"
        data-testid="input"
      >
        <gl-form-input-group :value="value" readonly select-on-click :aria-label="name">
          <template #append>
            <gl-button
              v-gl-tooltip.hover
              :title="$options.MSG_COPY"
              :aria-label="$options.MSG_COPY"
              :data-clipboard-text="value"
              icon="copy-to-clipboard"
              data-qa-selector="copy_button"
              :data-qa-action="name"
            />
          </template>
        </gl-form-input-group>
      </gl-dropdown-text>
    </template>
  </gl-dropdown>
</template>