added dominant color to ListItem component

pull/22/head^2
NoisyBoy-9 2019-07-26 18:14:07 +04:30
parent 815b1eb65a
commit f63f0b41ac
1 changed files with 20 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<template>
<li>
<div class="song">
<img :src="item.artwork" alt="Artwork">
<img @load="onLoad" :src="item.artwork" alt="Artwork">
{{item.title}}
</div>
@ -16,9 +16,21 @@
</template>
<script>
import color from 'dominant-color'
export default {
name: 'ListItem',
props: ['item']
props: ['item'],
methods: {
onLoad () {
let img = this.$el.getElementsByTagName('img')[0]
let list = this.$el.getElementsByTagName('li')[0]
color(img.src, {format: 'hex'}, (_, color) => {
list.style.backgroundColor = `#${color}`
})
}
}
}
</script>
@ -35,6 +47,12 @@ li
align-items: center
flex: 1 0 50%
img
width: 4rem
height: 4rem
margin-right: .6rem
border-radius: 50%
div.artist
display: flex
align-items: center
@ -46,10 +64,5 @@ li
justify-content: center
flex: 1 0 15%
img
width: 4rem
height: 4rem
margin-right: .6rem
border-radius: 10rem
</style>