debian-mirror-gitlab/app/assets/javascripts/design_management/components/design_scaler.vue

77 lines
1.6 KiB
Vue
Raw Normal View History

2020-05-24 23:13:21 +05:30
<script>
2021-01-29 00:20:46 +05:30
import { GlButtonGroup, GlButton } from '@gitlab/ui';
2020-05-24 23:13:21 +05:30
const DEFAULT_SCALE = 1;
const MIN_SCALE = 1;
2021-11-11 11:23:49 +05:30
const ZOOM_LEVELS = 5;
2020-05-24 23:13:21 +05:30
export default {
components: {
2021-01-29 00:20:46 +05:30
GlButtonGroup,
GlButton,
2020-05-24 23:13:21 +05:30
},
2021-11-11 11:23:49 +05:30
props: {
maxScale: {
type: Number,
required: true,
},
},
2020-05-24 23:13:21 +05:30
data() {
return {
scale: DEFAULT_SCALE,
};
},
computed: {
disableReset() {
return this.scale <= MIN_SCALE;
},
disableDecrease() {
return this.scale === DEFAULT_SCALE;
},
disableIncrease() {
2021-11-11 11:23:49 +05:30
return this.scale >= this.maxScale;
},
stepSize() {
return (this.maxScale - MIN_SCALE) / ZOOM_LEVELS;
2020-05-24 23:13:21 +05:30
},
},
methods: {
setScale(scale) {
if (scale < MIN_SCALE) {
return;
}
this.scale = Math.round(scale * 100) / 100;
this.$emit('scale', this.scale);
},
incrementScale() {
2021-11-11 11:23:49 +05:30
this.setScale(Math.min(this.scale + this.stepSize, this.maxScale));
2020-05-24 23:13:21 +05:30
},
decrementScale() {
2021-11-11 11:23:49 +05:30
this.setScale(Math.max(this.scale - this.stepSize, MIN_SCALE));
2020-05-24 23:13:21 +05:30
},
resetScale() {
this.setScale(DEFAULT_SCALE);
},
},
};
</script>
<template>
2021-01-29 00:20:46 +05:30
<gl-button-group class="gl-z-index-1">
2021-04-29 21:17:54 +05:30
<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"
/>
2021-01-29 00:20:46 +05:30
</gl-button-group>
2020-05-24 23:13:21 +05:30
</template>