Last active
December 10, 2017 14:24
-
-
Save ManUtopiK/d3cf8f04d787dceaeb20eea120a0e0cc to your computer and use it in GitHub Desktop.
Brightness reverted color computed. Vue component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="header" :style="style"> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'Header', | |
props: { | |
index: { | |
type: Number | |
}, | |
withButton: { | |
type: Boolean, | |
default: false | |
}, | |
color: { | |
type: Object, | |
default: () => { | |
return null | |
} | |
} | |
}, | |
computed: { | |
brightness () { | |
let { r, g, b } = this.color | |
return 0.299 * r + 0.587 * g + 0.114 * b | |
}, | |
style () { | |
if (this.color) { | |
let { r, g, b } = this.color | |
let background = `rgb(${r}, ${g}, ${b})` | |
let shadow = `rgba(${r}, ${g}, ${b}, 0.5)` | |
return { | |
'background-color': background, | |
'box-shadow': `0px 6px 20px ${shadow}`, | |
'color': this.brightness > 180 ? '#777' : '#f3f3f3' | |
} | |
} | |
return null | |
} | |
} | |
} | |
</script> | |
<style lang="scss"> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment