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

Add md icon slot to Avatar component #2722

Merged
merged 2 commits into from
Jun 13, 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
43 changes: 36 additions & 7 deletions src/components/Avatar/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@
<avatar url="https://nextcloud.com/wp-content/themes/next/assets/img/common/nextcloud-square-logo.png" />
```

### Avatar with material design icon

```
<template>
<avatar>
<template #icon>
<AccountMultiple :size="20" decorative />
</template>
</AppNavigationNew>
</template>
<script>
import AccountMultiple from 'vue-material-design-icons/AccountMultiple'

export default {
components: {
AccountMultiple,
},
}
</script>
```

</docs>
<template>
<div ref="main"
Expand All @@ -50,12 +71,15 @@
:role="disableMenu ? '' : 'button'"
v-on="!disableMenu ? { click: toggleMenu } : {}"
@keydown.enter="toggleMenu">
<!-- Avatar icon or image -->
<div v-if="iconClass" :class="iconClass" class="avatar-class-icon" />
<img v-else-if="isAvatarLoaded && !userDoesNotExist"
:src="avatarUrlLoaded"
:srcset="avatarSrcSetLoaded"
alt="">
<!-- @slot Icon slot -->
<slot name="icon">
<!-- Avatar icon or image -->
<div v-if="iconClass" :class="iconClass" class="avatar-class-icon" />
<img v-else-if="isAvatarLoaded && !userDoesNotExist"
:src="avatarUrlLoaded"
:srcset="avatarSrcSetLoaded"
alt="">
</slot>

<!-- Contact menu -->
<Popover v-if="hasMenu"
Expand Down Expand Up @@ -84,7 +108,7 @@
:class="'avatardiv__user-status--' + userStatus.status" />

<!-- Show the letter if no avatar nor icon class -->
<div v-if="userDoesNotExist && !iconClass" class="unknown">
<div v-if="userDoesNotExist && !(iconClass || $slots.icon)" class="unknown">
{{ initials }}
</div>
</div>
Expand Down Expand Up @@ -681,6 +705,11 @@ export default {
object-fit: cover;
}

.material-design-icon {
width: var(--size);
height: var(--size);
}

.avatardiv__user-status {
position: absolute;
right: -4px;
Expand Down