All files / repo/src/components/Sidebar/SidebarVolumeControl SidebarVolumeControl.vue

0% Statements 0/39
100% Branches 1/1
100% Functions 1/1
0% Lines 0/39

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                                                                                                                   
<template>
  <div
    class="volume-control"
    :style="{
      '--val': localVolume,
      '--min': 0,
      '--max': 100,
      '--pos': `calc((var(--val) - var(--min)) / (var(--max) - var(--min)) * 100%)`,
    }"
  >
    <div class="volume-header">
      <span class="volume-label">{{ $t('volumeControl.title') }}</span>
      <Button :handleClick="toggleMute" :aria-label="isMuted ? 'speaker off' : 'speaker on'" :className="clsx('speaker', { muted: isMuted })" variant="round">
        <LazyImage :src="./`/images/speaker${isMuted ? '-muted' : ''}.svg`" :alt="`speaker${isMuted ? '-muted' : ''}`" />
      </Button>
    </div>
 
    <div class="volume-slider-wrapper">
      <input
        type="range"
        class="range-volume"
        min="0"
        max="100"
        step="1"
        v-model.number="localVolume"
        @input="onVolumeChange"
        aria-label="Głośność"
        list="volume-ticks"
      />
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { useSoundStore } from '@/stores/useSoundStore';
import { clsx } from 'clsx';
import { storeToRefs } from 'pinia';
import { ref, watch } from 'vue';
 
const soundStore = useSoundStore();
const { isMuted, volume } = storeToRefs(soundStore);
const { toggleMute, setVolume } = soundStore;
 
const localVolume = ref(Math.round(volume.value * 100));
 
watch(volume, (v) => {
  if (!isMuted.value) {
    localVolume.value = Math.round(v * 100);
  }
});
 
function onVolumeChange() {
  setVolume(localVolume.value / 100);
}
</script>
 
<style scoped src="././SidebarVolumeControl.scss" />