Commit c45159f1 authored by quentin.vrel's avatar quentin.vrel

minor changes to avatar

parent 61428d5a
<template> <template>
<div :style="style" aria-hidden="true"> <div :style="style" aria-hidden="true">
<!-- this img is not displayed; it is used to detect failure-to-load of div background image --> <!-- this img is not displayed; it is used to detect failure-to-load of div background image -->
<img v-if="this.isImage" style="display: none" :src="this.src"/> <img v-if="this.isImage" style="display: none" :src="'avatar/'+this.pathToImage"/>
<span v-show="!this.isImage">{{ userInitial }}</span> <span v-show="!this.isImage">{{ userInitial }}</span>
</div> </div>
</template> </template>
...@@ -35,10 +35,10 @@ export default { ...@@ -35,10 +35,10 @@ export default {
type: Boolean type: Boolean
}, },
size: { size: {
type: Number, type: [Number, String],
default: 50 default: 50
}, },
src: { pathToImage: {
type: String type: String
}, },
rounded: { rounded: {
...@@ -80,7 +80,7 @@ export default { ...@@ -80,7 +80,7 @@ export default {
} }
}, },
isImage () { isImage () {
return !this.imgError && Boolean(this.src) return Boolean(this.pathToImage)
}, },
style () { style () {
...@@ -96,11 +96,9 @@ export default { ...@@ -96,11 +96,9 @@ export default {
textAlign: 'center', textAlign: 'center',
userSelect: 'none' userSelect: 'none'
} }
const imgBackgroundAndFontStyle = { const imgBackgroundAndFontStyle = {
background: `transparent url('${this.src}') no-repeat scroll 0% 0% / ${this.size}px ${this.size}px content-box border-box` background: `transparent url('avatar/${this.pathToImage}') no-repeat scroll 0% 0% / ${this.size}px ${this.size}px content-box border-box`
} }
const initialBackgroundAndFontStyle = { const initialBackgroundAndFontStyle = {
backgroundColor: this.background, backgroundColor: this.background,
font: `${Math.floor(this.size / 2.5)}px/${this.size}px Helvetica, Arial, sans-serif`, font: `${Math.floor(this.size / 2.5)}px/${this.size}px Helvetica, Arial, sans-serif`,
...@@ -126,43 +124,7 @@ export default { ...@@ -126,43 +124,7 @@ export default {
}, },
methods: { methods: {
initial: getInitials, initial: getInitials
onImgError () {
this.imgError = true
},
randomBackgroundColor (seed, colors) {
return colors[seed % (colors.length)]
},
lightenColor (hex, amt) {
// From https://css-tricks.com/snippets/javascript/lighten-darken-color/
var usePound = false
if (hex[0] === '#') {
hex = hex.slice(1)
usePound = true
}
var num = parseInt(hex, 16)
var r = (num >> 16) + amt
if (r > 255) r = 255
else if (r < 0) r = 0
var b = ((num >> 8) & 0x00FF) + amt
if (b > 255) b = 255
else if (b < 0) b = 0
var g = (num & 0x0000FF) + amt
if (g > 255) g = 255
else if (g < 0) g = 0
return (usePound ? '#' : '') + (g | (b << 8) | (r << 16)).toString(16)
}
} }
} }
</script> </script>
<template> <template>
<div class="vue-user-ribon--wrap" aria-hidden="true"> <div class="vue-user-ribon--wrap" aria-hidden="true">
<p>Vous êtres connecté <strong>{{username}}</strong>.</p> <p>Vous êtres connecté <strong>{{username}}</strong>.</p>
<avatar :username="this.username" :src="this.pathToImage"/> <avatar :username="this.username" :pathToImage="this.pathToImage"/>
<button class="logout-button" v-on:click="logout"> <button class="logout-button" v-on:click="logout">
<img src="icons/logout.svg" height="40"/> <img src="icons/logout.svg" height="40"/>
</button> </button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment