2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-04-21 12:04:27 +00:00
|
|
|
<div :class="containerClass" :aria-labelledby="ariaLabelledby" :aria-label="ariaLabel" v-bind="ptm('root')">
|
2023-04-27 12:18:17 +00:00
|
|
|
<slot>
|
2023-04-21 12:04:27 +00:00
|
|
|
<span v-if="label" class="p-avatar-text" v-bind="ptm('label')">{{ label }}</span>
|
|
|
|
<component v-else-if="$slots.icon" :is="$slots.icon" class="p-avatar-icon" v-bind="ptm('icon')" />
|
|
|
|
<span v-else-if="icon" :class="['p-avatar-icon', icon]" v-bind="ptm('icon')" />
|
|
|
|
<img v-else-if="image" :src="image" :alt="ariaLabel" @error="onError" v-bind="ptm('image')" />
|
2023-04-27 12:18:17 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-21 12:04:27 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'Avatar',
|
2023-04-21 12:04:27 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-14 11:26:01 +00:00
|
|
|
emits: ['error'],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: 'normal'
|
|
|
|
},
|
|
|
|
shape: {
|
|
|
|
type: String,
|
2022-09-14 11:26:01 +00:00
|
|
|
default: 'square'
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
'aria-labelledby': {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
'aria-label': {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onError() {
|
|
|
|
this.$emit('error');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-avatar p-component',
|
|
|
|
{
|
|
|
|
'p-avatar-image': this.image != null,
|
|
|
|
'p-avatar-circle': this.shape === 'circle',
|
|
|
|
'p-avatar-lg': this.size === 'large',
|
|
|
|
'p-avatar-xl': this.size === 'xlarge'
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.p-avatar {
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
width: 2rem;
|
|
|
|
height: 2rem;
|
|
|
|
font-size: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-avatar.p-avatar-image {
|
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-avatar.p-avatar-circle {
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-avatar-circle img {
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-avatar .p-avatar-icon {
|
|
|
|
font-size: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-avatar img {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|