All files / src/components/shared VerticalSliderSelector.vue

100% Statements 19/19
100% Branches 2/2
100% Functions 9/9
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 86 87 88 89 90 91 92 93 94    1x                       20x     20x   20x                                       11x                     11x       11x 11x   11x   16x     1x       11x 16x   5x 5x 5x 4x                                          
<template>
  <v-slider
    v-model="sliderValue"
    :thumb-label="showThumb"
    :min="min"
    :max="max"
    direction="vertical"
    :style="`--thumbBackgroundColor: ${bgColor}`"
    thumb-color="blue"
    :thumb-size="16"
    hide-details
    class="vertical-slider-selector"
  >
    <template #append>
      <div class="text-white py-1 my-0 text-center">{{ max }}</div>
    </template>
    <template #prepend>
      <div class="text-white py-1 my-0 text-center">{{ min }}</div>
    </template>
    <template v-slot:thumb-label="{ modelValue }">
      <span>{{ Math.floor(modelValue) }}</span>
    </template>
  </v-slider>
</template>
 
<script setup lang="ts">
import { computed, ref, unref, watch } from 'vue';
 
export interface Props {
  value: number;
  loading?: boolean;
  label?: string;
  lower?: number;
  upper?: number;
  min?: number;
  max?: number;
  bgColor?: string;
}
 
const props = withDefaults(defineProps<Props>(), {
  value: 0,
  loading: false,
  label: 'Test',
  lower: 0,
  upper: 100,
  min: -99999,
  max: 99999,
  bgColor: '#000',
});
 
const emit = defineEmits<{
  'update:value': [number];
}>();
 
const showThumb = ref<'always' | boolean>(true);
const showThumbTimeout = ref<number>();
 
const sliderValue = computed({
  get() {
    return Math.floor(props.value);
  },
  set(value: number) {
    emit('update:value', Math.floor(value));
  },
});
 
watch(
  () => sliderValue.value,
  () => {
    clearTimeout(unref(showThumbTimeout));
    showThumb.value = 'always';
    showThumbTimeout.value = setTimeout(() => {
      showThumb.value = false;
    }, 1000);
  },
);
</script>
 
<style lang="scss">
.vertical-slider-selector {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
}
 
.vertical-slider-selector .v-slider-thumb__label {
  transform: translateY(-0px) translateX(-32px) translateX(-100%)
    rotate(-180deg) !important;
  & div {
    transform: rotate(180deg);
  }
}
</style>