summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/design_management/components/design_scaler.vue
blob: 8d26f84641e3e50cdbd3fa0120a30659c24eb139 (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
<script>
import { GlIcon } from '@gitlab/ui';

const SCALE_STEP_SIZE = 0.2;
const DEFAULT_SCALE = 1;
const MIN_SCALE = 1;
const MAX_SCALE = 2;

export default {
  components: {
    GlIcon,
  },
  data() {
    return {
      scale: DEFAULT_SCALE,
    };
  },
  computed: {
    disableReset() {
      return this.scale <= MIN_SCALE;
    },
    disableDecrease() {
      return this.scale === DEFAULT_SCALE;
    },
    disableIncrease() {
      return this.scale >= MAX_SCALE;
    },
  },
  methods: {
    setScale(scale) {
      if (scale < MIN_SCALE) {
        return;
      }

      this.scale = Math.round(scale * 100) / 100;
      this.$emit('scale', this.scale);
    },
    incrementScale() {
      this.setScale(this.scale + SCALE_STEP_SIZE);
    },
    decrementScale() {
      this.setScale(this.scale - SCALE_STEP_SIZE);
    },
    resetScale() {
      this.setScale(DEFAULT_SCALE);
    },
  },
};
</script>

<template>
  <div class="design-scaler btn-group" role="group">
    <button class="btn" :disabled="disableDecrease" @click="decrementScale">
      <span class="gl-display-flex gl-justify-content-center gl-align-items-center gl-icon s16">
        –
      </span>
    </button>
    <button class="btn" :disabled="disableReset" @click="resetScale">
      <gl-icon name="redo" />
    </button>
    <button class="btn" :disabled="disableIncrease" @click="incrementScale">
      <gl-icon name="plus" />
    </button>
  </div>
</template>