Avatar
Neo-brutalist avatar component for displaying user profile images with fallback support. Includes Avatar, AvatarImage, and AvatarFallback sub-components, supporting multiple variants, sizes, shapes, and status indicators.
Demo
尺寸
形状
带图片
变体
状态
工牌吊孔(lanyard)
Installation
pnpm dlx brutx-vue@latest add avatarUsage
<script setup>
import { Avatar, AvatarImage, AvatarFallback } from 'brutx-ui-vue'
</script>
<template>
<Avatar size="default" shape="square">
<AvatarImage src="/avatar.jpg" alt="User avatar" />
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</template>Fallback Behavior
When the image fails to load, AvatarFallback is automatically displayed:
<script setup>
import { Avatar, AvatarImage, AvatarFallback } from 'brutx-ui-vue'
</script>
<template>
<Avatar>
<AvatarImage src="/broken-url.jpg" alt="User" />
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</template>Status Indicator
Renders a small status dot at the bottom-right corner of the avatar (w-3 h-3 rounded-full border-3 border-brutal-bg). Not rendered when status="none" (default).
| Status | Color | Description |
|---|---|---|
online | bg-brutal-success | Online (green) |
offline | bg-brutal-muted | Offline (gray) |
busy | bg-brutal-destructive | Busy (red) |
none | — | Not rendered (default) |
<script setup>
import { Avatar, AvatarFallback } from 'brutx-ui-vue'
</script>
<template>
<div class="flex items-center gap-4">
<Avatar size="lg" status="online">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
<Avatar size="lg" status="offline">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
<Avatar size="lg" status="busy">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</div>
</template>Variants
Controls the background color of the avatar root container and AvatarFallback, passed down to sub-components via provide/inject.
| Variant | Root Container Background | Fallback Background |
|---|---|---|
default | bg-brutal-muted/20 | bg-brutal-muted |
primary | bg-brutal-primary/20 | bg-brutal-primary |
secondary | bg-brutal-secondary/20 | bg-brutal-secondary |
accent | bg-brutal-accent/20 | bg-brutal-accent |
<script setup>
import { Avatar, AvatarFallback } from 'brutx-ui-vue'
</script>
<template>
<div class="flex items-center gap-4">
<Avatar size="lg" variant="default">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
<Avatar size="lg" variant="primary">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
<Avatar size="lg" variant="secondary">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
<Avatar size="lg" variant="accent">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</div>
</template>Sizes
| Size | Dimensions |
|---|---|
sm | h-8 w-8 (32px) |
default | h-10 w-10 (40px) |
lg | h-14 w-14 (56px) |
xl | h-20 w-20 (80px) |
Shapes
| Shape | Description |
|---|---|
square | No border radius (default) |
rounded | Uses the --brutal-radius token |
<script setup>
import { Avatar, AvatarFallback } from 'brutx-ui-vue'
</script>
<template>
<Avatar size="lg" shape="rounded">
<AvatarFallback>JD</AvatarFallback>
</Avatar>
</template>Sub-components
| Component | Description |
|---|---|
Avatar | Root container providing size, shape, variant, and status context |
AvatarImage | Avatar image that automatically hides on load failure |
AvatarFallback | Fallback content that automatically shows when the image is not visible |
API Reference
Avatar
| Name | Type | Default | Description |
|---|---|---|---|
variant | "accent" | "default" | "primary" | "secondary" | undefined | "default" | Sets the color variant used by the avatar fallback content. |
DetailsDeclared typeNonNullable<"default" | "primary" | "secondary" | "accent" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/avatar/Avatar.vue | |||
size | "default" | "lg" | "sm" | "xl" | undefined | "default" | Sets the size of the avatar container and its content. |
DetailsDeclared typeNonNullable<"default" | "lg" | "sm" | "xl" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/avatar/Avatar.vue | |||
shape | "rounded" | "square" | undefined | "square" | Sets the avatar container to a square or rounded shape. |
DetailsDeclared typeNonNullable<"square" | "rounded" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/avatar/Avatar.vue | |||
status | AvatarStatus | undefined | "none" | Sets the status indicator at the avatar’s lower-right corner; none hides the indicator. |
DetailsDeclared typeAvatarStatus | undefined Literal values
Referenced types AvatarStatus Type definition — AvatarStatustype AvatarStatus = 'online' | 'offline' | 'busy' | 'none' Default value details
Sourcepackages/ui/src/components/avatar/Avatar.vue | |||
lanyard | boolean | undefined | false | Shows a decorative lanyard grommet at the top; the decoration is hidden from the accessibility tree. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/avatar/Avatar.vue | |||
class | string | undefined | undefined | CSS classes added to the avatar root container. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/avatar/Avatar.vue | |||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | Composes the AvatarImage and AvatarFallback subcomponents. |
DetailsDeclared type{}Sourcepackages/ui/src/components/avatar/Avatar.vue | ||
AvatarFallback
| Name | Type | Default | Description |
|---|---|---|---|
delayMs | number | undefined | undefined | Sets the delay before fallback content appears while the image is loading or unavailable; it appears immediately when omitted. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/avatar/AvatarFallback.vue | |||
class | string | undefined | undefined | CSS classes added to the fallback content root. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/avatar/AvatarFallback.vue | |||
asChild | boolean | undefined | undefined | Merges the root element’s semantics and attributes into the single default-slot child; when enabled, as is ignored. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/avatar/AvatarFallback.vue | |||
as | AsTag | Component | undefined | "span" | Specifies the HTML tag or Vue component rendered as the root; asChild takes precedence. |
DetailsDeclared typeAsTag | Component | undefined Literal values
Default value details
Sourcepackages/ui/src/components/avatar/AvatarFallback.vue | |||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | Text, an icon, or other fallback content shown when the image is unavailable. |
DetailsDeclared type{}Sourcepackages/ui/src/components/avatar/AvatarFallback.vue | ||
AvatarImage
| Name | Type | Default | Description |
|---|---|---|---|
src | string | undefined | undefined | The URL of the avatar image. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/avatar/AvatarImage.vue | |||
alt | string | undefined | "" | Alternative text for the image; the default empty string treats it as decorative content. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/avatar/AvatarImage.vue | |||
class | string | undefined | undefined | CSS classes added to the avatar image element. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/avatar/AvatarImage.vue | |||
Accessibility
- ARIA Attributes: The status dot uses
role="status"(a live region) with an innersr-onlytext carrying the status label; label changes on status or language switches are announced by screen readers - Internationalization: Status labels provide localized text via i18n:
online-> "Online"offline-> "Offline"busy-> "Busy"