pnpx starwind@latest add avatar
npx starwind@latest add avatar
yarn dlx starwind@latest add avatar
---import { Avatar, AvatarImage, AvatarFallback } from "@/components/starwind/avatar";---<Avatar size="sm"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar size="md"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar size="lg"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar>
---import { Avatar, AvatarImage, AvatarFallback } from "@/components/starwind/avatar";---<Avatar variant="default"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar variant="primary"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar variant="secondary"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar variant="info"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar variant="success"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar variant="warning"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar><Avatar variant="error"> <AvatarImage src="https://i.pravatar.cc/150?u=a04258a2462d826712d" alt="John Doe" /> <AvatarFallback>JD</AvatarFallback></Avatar>
Rather than passing an image URL, you can also pass an imported image to the AvatarImage
component. This will optimize the image using the astro:assets <Image/>
component.
---import { Avatar, AvatarImage, AvatarFallback } from "@/components/starwind/avatar";import GigaChad from "@/assets/images/giga-chad.jpg";---<Avatar> <AvatarImage image={GigaChad} alt="GC" /> <AvatarFallback>GC</AvatarFallback></Avatar>
When an image fails to load or isn’t provided, the fallback content will be displayed.
---import { Avatar, AvatarImage, AvatarFallback } from "@/components/starwind/avatar";---<Avatar> <AvatarImage src="invalid-url.png" alt="Web Reaper" /> <AvatarFallback>WR</AvatarFallback></Avatar>
The root component that serves as a container for avatar content. It renders a styled figure element with configurable size and variant options.
size
: Controls the size of the avatar.variant
: Sets the visual style of the avatar border.Prop | Type | Default |
---|---|---|
size | "sm" | "md" | "lg" | "md" |
variant | "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "default" |
The component accepts all standard HTML attributes for <div>
elements.
Displays an image within the Avatar component. This component handles both remote images via URL and local imported images.
src
: URL of the image to display (use this or image
, not both).image
: An imported image (use this or src
, not both).alt
: Alternative text description of the image (required for accessibility).Prop | Type | Default |
---|---|---|
src | string | - |
image | ImageMetadata | - |
alt | string | Required |
Either src
or image
must be provided, but not both. The alt
attribute is required for accessibility.
Renders fallback content (typically initials) when the avatar image fails to load or isn’t provided.
The component accepts all standard HTML attributes for <div>
elements.
Tip
The AvatarFallback component is automatically displayed when an image fails to load.
VariantProps
from tailwind-variants
. This provides greater type safety and cleans up component frontmatter.tailwind-variants
now implemented. This uses tailwind-merge
under the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using the “class” prop.