Skip to content

Commit

Permalink
Merge pull request #3272 from nextcloud/fix/avatar-on-complex-background
Browse files Browse the repository at this point in the history
Fix non-user avatar on complex background
  • Loading branch information
raimund-schluessler authored Sep 20, 2022
2 parents 228e254 + acdd3f2 commit c0156cd
Showing 1 changed file with 49 additions and 16 deletions.
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 {
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

0 comments on commit c0156cd

Please sign in to comment.