ptitlutins/app/components/atoms/Avatar.vue
2026-06-10 23:37:21 +02:00

46 lines
910 B
Vue

<template>
<span
class="avatar"
:style="{ width: `${size}px`, height: `${size}px`, fontSize: `${size * 0.38}px` }"
:title="name"
>
{{ initials }}
</span>
</template>
<script setup lang="ts">
const props = withDefaults(
defineProps<{
/** Full display name; initials are derived from it. */
name: string
/** Diameter in px. */
size?: number
}>(),
{ size: 32 },
)
const initials = computed(() =>
props.name
.split(/\s+/)
.filter(Boolean)
.slice(0, 2)
.map((w) => w[0]?.toUpperCase() ?? "")
.join(""),
)
</script>
<style scoped>
.avatar {
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: var(--radius-pill);
background: var(--color-8);
color: var(--color-2);
font-family: var(--font-body);
font-weight: var(--weight-semibold);
line-height: 1;
flex-shrink: 0;
user-select: none;
}
</style>