summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/code_block.vue
blob: 1928bf6dac51d7c4b7965535092f2f6d6afe6ea7 (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
<script>
export default {
  name: 'CodeBlock',
  props: {
    code: {
      type: String,
      required: true,
    },
    maxHeight: {
      type: String,
      required: false,
      default: 'initial',
    },
  },
  computed: {
    styleObject() {
      const { maxHeight } = this;
      const isScrollable = maxHeight !== 'initial';
      const scrollableStyles = {
        maxHeight,
        overflowY: 'auto',
      };

      return isScrollable ? scrollableStyles : null;
    },
  },
};
</script>
<template>
  <pre class="code-block rounded" :style="styleObject"><code class="d-block">{{ code }}</code></pre>
</template>