summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/code_navigation/components/popover.vue
blob: b4d9bc7b1812cbd38b56b1bd731617a75d01a437 (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
<script>
import { GlDeprecatedButton } from '@gitlab/ui';

export default {
  components: {
    GlDeprecatedButton,
  },
  props: {
    position: {
      type: Object,
      required: true,
    },
    data: {
      type: Object,
      required: true,
    },
    definitionPathPrefix: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      offsetLeft: 0,
    };
  },
  computed: {
    positionStyles() {
      return {
        left: `${this.position.x - this.offsetLeft}px`,
        top: `${this.position.y + this.position.height}px`,
      };
    },
    definitionPath() {
      return (
        this.data.definition_path && `${this.definitionPathPrefix}/${this.data.definition_path}`
      );
    },
  },
  watch: {
    position: {
      handler() {
        this.$nextTick(() => this.updateOffsetLeft());
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    updateOffsetLeft() {
      this.offsetLeft = Math.max(
        0,
        this.$el.offsetLeft + this.$el.offsetWidth - window.innerWidth + 20,
      );
    },
  },
  colorScheme: gon?.user_color_scheme,
};
</script>

<template>
  <div
    :style="positionStyles"
    class="popover code-navigation-popover popover-font-size-normal gl-popover bs-popover-bottom show"
  >
    <div :style="{ left: `${offsetLeft}px` }" class="arrow"></div>
    <div v-for="(hover, index) in data.hover" :key="index" class="border-bottom">
      <pre
        v-if="hover.language"
        ref="code-output"
        :class="$options.colorScheme"
        class="border-0 bg-transparent m-0 code highlight"
        v-html="hover.value"
      ></pre>
      <p v-else ref="doc-output" class="p-3 m-0">
        {{ hover.value }}
      </p>
    </div>
    <div v-if="definitionPath" class="popover-body">
      <gl-deprecated-button :href="definitionPath" target="_blank" class="w-100" variant="default">
        {{ __('Go to definition') }}
      </gl-deprecated-button>
    </div>
  </div>
</template>