summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/content_editor/components/wrappers/media.vue
blob: 37119bdd0661e554ad617f78188c6073dc5e44d7 (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
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { NodeViewWrapper } from '@tiptap/vue-2';

const tagNameMap = {
  image: 'img',
  video: 'video',
  audio: 'audio',
};

export default {
  name: 'MediaWrapper',
  components: {
    NodeViewWrapper,
    GlLoadingIcon,
  },
  props: {
    node: {
      type: Object,
      required: true,
    },
  },
  computed: {
    tagName() {
      return tagNameMap[this.node.type.name] || 'img';
    },
  },
};
</script>
<template>
  <node-view-wrapper class="gl-display-inline-block">
    <span class="gl-relative" :class="{ [`media-container ${tagName}-container`]: true }">
      <gl-loading-icon v-if="node.attrs.uploading" class="gl-absolute gl-left-50p gl-top-half" />
      <component
        :is="tagName"
        data-testid="media"
        :class="{
          'gl-max-w-full gl-h-auto': tagName !== 'audio',
          'gl-opacity-5': node.attrs.uploading,
        }"
        :title="node.attrs.title || node.attrs.alt"
        :alt="node.attrs.alt"
        :src="node.attrs.src"
        controls="true"
      />
      <a v-if="tagName !== 'img'" :href="node.attrs.canonicalSrc || node.attrs.src" @click.prevent>
        {{ node.attrs.title || node.attrs.alt }}
      </a>
    </span>
  </node-view-wrapper>
</template>