Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-user avatar on complex background #3272

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions src/components/NcAvatar/NcAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ export default {
<NcAvatar display-name="Robbie Hyeon-Jeong" :is-no-user="true" />
```

### Avatar on complex background

```
<template>
<div class="avatar-background">
<NcAvatar class="avatar" :is-no-user="true" display-name="Cecilia Rohese" />
</div>
</template>
<style scoped>
.avatar-background {
width: 80px;
height: 60px;
background: linear-gradient(to bottom, #0057b8 0%, #0057b8 49.99%, #ffd700 50%, #ffd700 100%);
}

.avatar {
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
margin: 15px 25px;
}
</style>
```

</docs>
<template>
<div ref="main"
Expand Down Expand Up @@ -136,8 +157,12 @@ export default {
:class="'avatardiv__user-status--' + userStatus.status" />

<!-- Show the letter if no avatar nor icon class -->
<div v-if="userDoesNotExist && !(iconClass || $slots.icon)" :style="initialsStyle" class="unknown">
{{ initials }}
<div v-if="userDoesNotExist && !(iconClass || $slots.icon)"
:style="initialsWrapperStyle"
class="avatardiv__initials-wrapper">
<div :style="initialsStyle" class="unknown">
{{ initials }}
</div>
</div>
</div>
</template>
Expand Down Expand Up @@ -405,13 +430,14 @@ export default {
lineHeight: this.size + 'px',
fontSize: Math.round(this.size * 0.55) + 'px',
}

if (!this.iconClass && !this.avatarSrcSetLoaded) {
const rgb = usernameToColor(this.getUserIdentifier)
style.backgroundColor = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', 0.1)'
}
return style
},
initialsWrapperStyle() {
const { r, g, b } = usernameToColor(this.getUserIdentifier)
return {
backgroundColor: `rgba(${r}, ${g}, ${b}, 0.1)`,
}
},
initialsStyle() {
const { r, g, b } = usernameToColor(this.getUserIdentifier)
return {
Expand Down Expand Up @@ -681,7 +707,7 @@ export default {

&--unknown {
position: relative;
background-color: var(--color-text-maxcontrast);
background-color: var(--color-main-background);
}

&:not(&--unknown) {
Expand Down Expand Up @@ -716,14 +742,21 @@ export default {
}
}

> .unknown {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
text-align: center;
font-weight: normal;
.avatardiv__initials-wrapper {
height: var(--size);
width: var(--size);
background-color: var(--color-main-background);
border-radius: 50%;

.unknown {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
text-align: center;
font-weight: normal;
}
}

img {
Expand Down