gitlab-org--gitlab-foss/app/assets/javascripts/vue_shared/components/user_avatar/user_avatar_link.vue

104 lines
2.0 KiB
Vue
Raw Normal View History

2017-04-15 23:38:07 +00:00
<script>
/* This is a re-usable vue component for rendering a user avatar wrapped in
a clickable link (likely to the user's profile). The link, image, and
tooltip can be configured by props passed to this component.
Sample configuration:
<user-avatar-link
:link-href="userProfileUrl"
:img-src="userAvatarSrc"
:img-alt="tooltipText"
:img-size="20"
:tooltip-text="tooltipText"
:tooltip-placement="top"
:username="username"
2017-04-15 23:38:07 +00:00
/>
*/
import userAvatarImage from './user_avatar_image.vue';
import tooltip from '../../directives/tooltip';
2017-04-15 23:38:07 +00:00
export default {
name: 'UserAvatarLink',
components: {
userAvatarImage,
},
2018-01-04 19:07:28 +00:00
directives: {
tooltip,
},
2017-04-15 23:38:07 +00:00
props: {
linkHref: {
type: String,
required: false,
default: '',
},
imgSrc: {
type: String,
required: false,
default: '',
},
imgAlt: {
type: String,
required: false,
default: '',
},
imgCssClasses: {
type: String,
required: false,
default: '',
},
imgSize: {
type: Number,
required: false,
default: 20,
},
tooltipText: {
type: String,
required: false,
default: '',
},
tooltipPlacement: {
type: String,
required: false,
default: 'top',
},
username: {
type: String,
required: false,
default: '',
},
},
computed: {
2017-10-27 08:11:02 +00:00
shouldShowUsername() {
return this.username.length > 0;
},
avatarTooltipText() {
2017-10-27 08:11:02 +00:00
return this.shouldShowUsername ? '' : this.tooltipText;
},
},
2017-04-15 23:38:07 +00:00
};
</script>
<template>
<a
2018-06-11 09:49:47 +00:00
:href="linkHref"
class="user-avatar-link">
2017-04-15 23:38:07 +00:00
<user-avatar-image
:img-src="imgSrc"
:img-alt="imgAlt"
:css-classes="imgCssClasses"
:size="imgSize"
:tooltip-text="avatarTooltipText"
:tooltip-placement="tooltipPlacement"
/><span
2018-06-11 09:49:47 +00:00
v-if="shouldShowUsername"
v-tooltip
:title="tooltipText"
2017-04-15 23:38:07 +00:00
:tooltip-placement="tooltipPlacement"
2018-01-04 19:07:28 +00:00
>{{ username }}</span>
2017-04-15 23:38:07 +00:00
</a>
</template>