2024-12-03 14:07:00 +01:00
|
|
|
<template>
|
2025-04-10 18:44:53 +02:00
|
|
|
<Avatar :class="shape.value === 'square' && 'rounded-md'">
|
2024-12-03 14:07:00 +01:00
|
|
|
<AvatarFallback v-if="name">
|
|
|
|
|
{{ getInitials(name) }}
|
|
|
|
|
</AvatarFallback>
|
2024-12-07 18:16:58 +01:00
|
|
|
<AvatarImage v-if="src" :src="src" :alt="`${name}'s avatar`" />
|
2024-12-03 14:07:00 +01:00
|
|
|
</Avatar>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-12-04 14:34:09 +01:00
|
|
|
import { SettingIds } from "~/settings";
|
2024-12-03 14:07:00 +01:00
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
|
|
|
|
|
|
2025-04-10 18:44:53 +02:00
|
|
|
const { name } = defineProps<{
|
2024-12-03 14:07:00 +01:00
|
|
|
src?: string;
|
|
|
|
|
name?: string;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the initials of any string, even if it's not a name.
|
|
|
|
|
* If not a name, it will return the first two characters.
|
|
|
|
|
* @param name
|
|
|
|
|
*/
|
|
|
|
|
const getInitials = (name: string): string => {
|
|
|
|
|
const initials = name.match(/\b\w/g) || [];
|
|
|
|
|
|
|
|
|
|
const firstLetter = initials.shift() || name[0] || "";
|
|
|
|
|
const secondLetter = initials.pop() || name[1] || "";
|
|
|
|
|
|
|
|
|
|
return `${firstLetter}${secondLetter}`.toUpperCase();
|
|
|
|
|
};
|
2024-12-04 14:34:09 +01:00
|
|
|
|
|
|
|
|
const shape = useSetting(SettingIds.AvatarShape);
|
2024-12-16 17:25:52 +01:00
|
|
|
</script>
|