Welcome to mirror list, hosted at ThFree Co, Russian Federation.

design_scaler.vue « components « design_management « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af3d4453a6a564c9339674ed424b745e9eb03217 (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
<script>
import { GlButtonGroup, GlButton } from '@gitlab/ui';

const DEFAULT_SCALE = 1;
const MIN_SCALE = 1;
const ZOOM_LEVELS = 5;

export default {
  components: {
    GlButtonGroup,
    GlButton,
  },
  props: {
    maxScale: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      scale: DEFAULT_SCALE,
    };
  },
  computed: {
    disableReset() {
      return this.scale <= MIN_SCALE;
    },
    disableDecrease() {
      return this.scale === DEFAULT_SCALE;
    },
    disableIncrease() {
      return this.scale >= this.maxScale;
    },
    stepSize() {
      return (this.maxScale - MIN_SCALE) / ZOOM_LEVELS;
    },
  },
  methods: {
    setScale(scale) {
      if (scale < MIN_SCALE) {
        return;
      }

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

<template>
  <gl-button-group class="gl-z-index-1">
    <gl-button
      icon="dash"
      :disabled="disableDecrease"
      :aria-label="__('Decrease')"
      @click="decrementScale"
    />
    <gl-button icon="redo" :disabled="disableReset" :aria-label="__('Reset')" @click="resetScale" />
    <gl-button
      icon="plus"
      :disabled="disableIncrease"
      :aria-label="__('Increase')"
      @click="incrementScale"
    />
  </gl-button-group>
</template>