2019-10-29 18:06:21 +00:00
|
|
|
<template>
|
2022-10-27 19:32:23 +00:00
|
|
|
<div class="avatar-container" :style="style" aria-hidden="true">
|
|
|
|
{{ userInitial }}
|
2019-10-29 18:06:21 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'Avatar',
|
|
|
|
props: {
|
|
|
|
username: {
|
|
|
|
type: String,
|
2020-02-16 10:16:26 +00:00
|
|
|
default: '',
|
2019-10-29 18:06:21 +00:00
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: Number,
|
|
|
|
default: 40,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
style() {
|
2022-10-27 19:32:23 +00:00
|
|
|
return {
|
2019-10-29 18:06:21 +00:00
|
|
|
fontSize: `${Math.floor(this.size / 2.5)}px`,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
userInitial() {
|
2022-10-27 19:32:23 +00:00
|
|
|
const parts = this.username.split(/[ -]/);
|
|
|
|
let initials = parts.reduce((acc, curr) => acc + curr.charAt(0), '');
|
|
|
|
|
2019-10-29 18:06:21 +00:00
|
|
|
if (initials.length > 2 && initials.search(/[A-Z]/) !== -1) {
|
|
|
|
initials = initials.replace(/[a-z]+/g, '');
|
|
|
|
}
|
2022-10-12 21:55:59 +00:00
|
|
|
initials = initials.substring(0, 2).toUpperCase();
|
2022-10-27 19:32:23 +00:00
|
|
|
|
2019-10-29 18:06:21 +00:00
|
|
|
return initials;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.avatar-container {
|
|
|
|
display: flex;
|
2022-10-27 19:32:23 +00:00
|
|
|
line-height: 100%;
|
2020-02-16 10:16:26 +00:00
|
|
|
font-weight: 500;
|
2019-10-29 18:06:21 +00:00
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
text-align: center;
|
2021-12-01 09:48:41 +00:00
|
|
|
background-image: linear-gradient(to top, var(--w-100) 0%, var(--w-75) 100%);
|
|
|
|
color: var(--w-600);
|
2019-10-29 18:06:21 +00:00
|
|
|
}
|
|
|
|
</style>
|