koel/resources/assets/js/components/ui/repeat-mode-switch.vue
2022-04-19 21:26:06 +02:00

51 lines
1.1 KiB
Vue

<template>
<button
class="control"
:class="preferences.repeatMode"
@click.prevent="changeRepeatMode"
:title="`Change repeat mode (current mode: ${readableRepeatMode})`"
data-testid="repeat-mode-switch"
>
<i class="fa fa-repeat"></i>
</button>
</template>
<script lang="ts" setup>
import { computed, reactive } from 'vue'
import { playback } from '@/services'
import { preferenceStore } from '@/stores'
const preferences = reactive(preferenceStore.state)
const readableRepeatMode = computed(() => preferences.repeatMode
.split('_')
.map(part => part[0].toUpperCase() + part.substring(1).toLowerCase())
.join(' ')
)
const changeRepeatMode = () => playback.changeRepeatMode()
</script>
<style lang="scss" scoped>
button {
position: relative;
&.REPEAT_ALL, &.REPEAT_ONE {
color: var(--color-highlight);
}
&.REPEAT_ONE::after {
content: "1";
position: absolute;
display: flex;
place-content: center;
place-items: center;
top: 0;
left: 0;
font-weight: 700;
font-size: .5rem;
width: 100%;
height: 100%;
}
}
</style>