Merge pull request #4320 from Ocelot-Social-Community/4236-avatar-has-border

fix: 🍰 Fixing The Avatars unwanted Border
This commit is contained in:
Wolfgang Huß 2021-03-31 15:45:22 +02:00 committed by GitHub
commit 1066f67c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 10 deletions

View File

@ -46,6 +46,7 @@
</template> </template>
</dropdown> </dropdown>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import Dropdown from '~/components/Dropdown' import Dropdown from '~/components/Dropdown'
@ -118,6 +119,7 @@ export default {
}, },
} }
</script> </script>
<style lang="scss"> <style lang="scss">
.avatar-menu { .avatar-menu {
margin: $space-xxx-small 0px 0px $space-xx-small; margin: $space-xxx-small 0px 0px $space-xx-small;

View File

@ -4,6 +4,7 @@ import StoryRouter from 'storybook-vue-router'
import UserAvatar from '~/components/_new/generic/UserAvatar/UserAvatar' import UserAvatar from '~/components/_new/generic/UserAvatar/UserAvatar'
import helpers from '~/storybook/helpers' import helpers from '~/storybook/helpers'
import { user } from '~/components/UserTeaser/UserTeaser.story.js' import { user } from '~/components/UserTeaser/UserTeaser.story.js'
import imageFile from './storybook/critical-avatar-white-background.png'
helpers.init() helpers.init()
const anonymousUser = { const anonymousUser = {
@ -13,45 +14,64 @@ const anonymousUser = {
} }
const userWithoutAvatar = { const userWithoutAvatar = {
...user, ...user,
avatar: null,
name: 'Ana Paula Nunes Marques', name: 'Ana Paula Nunes Marques',
avatar: null,
}
const userWithAvatar = {
...user,
name: 'Jochen Image',
avatar: { url: imageFile },
} }
storiesOf('UserAvatar', module) storiesOf('UserAvatar', module)
.addDecorator(withA11y) .addDecorator(withA11y)
.addDecorator(helpers.layout) .addDecorator(helpers.layout)
.addDecorator(StoryRouter()) .addDecorator(StoryRouter())
.add('with image', () => ({ .add('normal, with image', () => ({
components: { UserAvatar }, components: { UserAvatar },
data: () => ({ data: () => ({
user, user: userWithAvatar,
}), }),
template: '<user-avatar :user="user" />', template: '<user-avatar :user="user" />',
})) }))
.add('without image, anonymous user', () => ({ .add('normal without image, anonymous user', () => ({
components: { UserAvatar }, components: { UserAvatar },
data: () => ({ data: () => ({
user: anonymousUser, user: anonymousUser,
}), }),
template: '<user-avatar :user="user" />', template: '<user-avatar :user="user" />',
})) }))
.add('without image, user initials', () => ({ .add('normal without image, user initials', () => ({
components: { UserAvatar }, components: { UserAvatar },
data: () => ({ data: () => ({
user: userWithoutAvatar, user: userWithoutAvatar,
}), }),
template: '<user-avatar :user="user" />', template: '<user-avatar :user="user" />',
})) }))
.add('small, with image', () => ({
components: { UserAvatar },
data: () => ({
user: userWithAvatar,
}),
template: '<user-avatar :user="user" size="small"/>',
}))
.add('small', () => ({ .add('small', () => ({
components: { UserAvatar }, components: { UserAvatar },
data: () => ({ data: () => ({
user, user: userWithoutAvatar,
}), }),
template: '<user-avatar :user="user" size="small"/>', template: '<user-avatar :user="user" size="small"/>',
})) }))
.add('large, with image', () => ({
components: { UserAvatar },
data: () => ({
user: userWithAvatar,
}),
template: '<user-avatar :user="user" size="large"/>',
}))
.add('large', () => ({ .add('large', () => ({
components: { UserAvatar }, components: { UserAvatar },
data: () => ({ data: () => ({
user, user: userWithoutAvatar,
}), }),
template: '<user-avatar :user="user" size="large"/>', template: '<user-avatar :user="user" size="large"/>',
})) }))

View File

@ -1,9 +1,10 @@
<template> <template>
<div :class="['user-avatar', size && `--${this.size}`]"> <div :class="['user-avatar', size && `--${this.size}`, !isAvatar && '--no-image']">
<!-- '--no-image' is neccessary, because otherwise we still have a little unwanted boarder araund the image for images with white backgrounds -->
<span class="initials">{{ userInitials }}</span> <span class="initials">{{ userInitials }}</span>
<base-icon v-if="isAnonymous" name="eye-slash" /> <base-icon v-if="isAnonymous" name="eye-slash" />
<img <img
v-if="user && user.avatar" v-if="isAvatar"
:src="user.avatar | proxyApiUrl" :src="user.avatar | proxyApiUrl"
class="image" class="image"
:alt="user.name" :alt="user.name"
@ -33,6 +34,10 @@ export default {
isAnonymous() { isAnonymous() {
return !this.user || !this.user.name || this.user.name.toLowerCase() === 'anonymous' return !this.user || !this.user.name || this.user.name.toLowerCase() === 'anonymous'
}, },
isAvatar() {
// TODO may we could test as well if the image is reachable? otherwise the background gets white and the initails can not be read
return this.user && this.user.avatar
},
userInitials() { userInitials() {
if (this.isAnonymous) return '' if (this.isAnonymous) return ''
@ -49,7 +54,7 @@ export default {
width: $size-avatar-base; width: $size-avatar-base;
border-radius: 50%; border-radius: 50%;
overflow: hidden; overflow: hidden;
background-color: $color-primary-dark; background-color: $background-color-base;
color: $text-color-primary-inverse; color: $text-color-primary-inverse;
&.--small { &.--small {
@ -63,6 +68,10 @@ export default {
font-size: $font-size-xx-large; font-size: $font-size-xx-large;
} }
&.--no-image {
background-color: $color-primary-dark;
}
> .initials, > .initials,
> .base-icon { > .base-icon {
position: absolute; position: absolute;
@ -77,6 +86,7 @@ export default {
height: 100%; height: 100%;
object-fit: cover; object-fit: cover;
object-position: center; object-position: center;
background-color: $background-color-base;
} }
} }
</style> </style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB