koel/resources/assets/js/components/profile-preferences/ThemeCard.vue

70 lines
1.4 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<div
:class="{ selected: theme.selected }"
2022-04-21 22:51:48 +00:00
:data-testid="`theme-card-${theme.id}`"
2022-04-15 14:24:30 +00:00
:style="thumbnailStyles"
:title="`Set current them to ${name}`"
2022-04-21 22:51:48 +00:00
class="theme"
role="button"
2022-04-15 14:24:30 +00:00
@click="$emit('selected', theme)"
>
<div class="name">{{ name }}</div>
</div>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-04-21 22:51:48 +00:00
import { toRefs } from 'vue'
2022-04-15 14:24:30 +00:00
import { slugToTitle } from '@/utils'
2022-04-15 17:00:08 +00:00
const props = defineProps<{ theme: Theme }>()
const { theme } = toRefs(props)
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
const name = theme.value.name ? theme.value.name : slugToTitle(theme.value.id)
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
const thumbnailStyles: Record<string, string> = {
'background-color': theme.value.thumbnailColor
}
2022-04-15 17:00:08 +00:00
2022-04-21 22:51:48 +00:00
if (theme.value.thumbnailUrl) {
thumbnailStyles['background-image'] = `url(${theme.value.thumbnailUrl})`
}
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss" scoped>
.theme {
height: 100%;
background-position: center;
background-size: cover;
position: relative;
cursor: pointer;
border-radius: 5px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, .1);
&.selected {
border: 2px solid rgba(255, 255, 255, .5);
}
&:hover {
.name {
opacity: 1;
}
}
.name {
position: absolute;
height: 100%;
width: 100%;
bottom: 0;
left: 0;
display: flex;
place-items: center;
place-content: center;
font-size: 1.5rem;
background: rgba(0, 0, 0, .2);
opacity: 0;
transition: .3s opacity;
}
}
</style>