Files
heroui-vue/apps/docs/demos/avatar-group-sizes.vue
T

83 lines
2.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
Avatar,
AvatarGroup,
AvatarImage,
AvatarFallback,
} from "@heroui-vue/components";
const users = [
{
id: 1,
image:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
name: "张明",
},
{
id: 2,
image:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
name: "李华",
},
{
id: 3,
image:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
name: "王芳",
},
{
id: 4,
image:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg",
name: "刘洋",
},
{
id: 5,
image:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg",
name: "陈静",
},
];
function initialsFromName(name: string) {
const parts = name.split(/\s+/).filter(Boolean);
if (parts.length >= 2) {
return parts.map((n) => n[0]).join("");
}
return name.slice(0, 2);
}
</script>
<template>
<div class="flex flex-col items-center gap-6">
<div class="flex flex-col items-center gap-2">
<p class="text-sm text-muted">小号</p>
<AvatarGroup size="sm">
<Avatar v-for="user in users.slice(0, 4)" :key="user.id">
<AvatarImage :alt="`${user.name} 的头像`" :src="user.image" />
<AvatarFallback>{{ initialsFromName(user.name) }}</AvatarFallback>
</Avatar>
</AvatarGroup>
</div>
<div class="flex flex-col items-center gap-2">
<p class="text-sm text-muted">中号(默认)</p>
<AvatarGroup size="md">
<Avatar v-for="user in users.slice(0, 4)" :key="user.id">
<AvatarImage :alt="`${user.name} 的头像`" :src="user.image" />
<AvatarFallback>{{ initialsFromName(user.name) }}</AvatarFallback>
</Avatar>
</AvatarGroup>
</div>
<div class="flex flex-col items-center gap-2">
<p class="text-sm text-muted">大号</p>
<AvatarGroup size="lg">
<Avatar v-for="user in users.slice(0, 4)" :key="user.id">
<AvatarImage :alt="`${user.name} 的头像`" :src="user.image" />
<AvatarFallback>{{ initialsFromName(user.name) }}</AvatarFallback>
</Avatar>
</AvatarGroup>
</div>
</div>
</template>