shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Avatar

An image element with a fallback for representing the user.

@axadrn AA
@joerdav JD
@axadrn AA
@a-h AH
@joerdav JD
+3
package examples import "github.com/axadrn/shadcn-templ/v2/components/avatar"

Installation

shadcn-templ add avatar

Usage

import "github.com/axadrn/shadcn-templ/v2/components/avatar"
@avatar.Avatar() {	@avatar.Image(avatar.ImageProps{Src: "https://github.com/axadrn.png"})	@avatar.Fallback() {		AA	}}

Composition

Use the following composition to build an Avatar:

avatar.Avatar├── avatar.Image├── avatar.Fallback└── avatar.Badge

Use the following composition to build an avatar.Group:

avatar.Group├── avatar.Avatar│   ├── avatar.Image│   ├── avatar.Fallback│   └── avatar.Badge├── avatar.Avatar│   ├── avatar.Image│   ├── avatar.Fallback│   └── avatar.Badge└── avatar.GroupCount

Basic

A basic avatar component with an image and a fallback.

@axadrn AA
package examples import "github.com/axadrn/shadcn-templ/v2/components/avatar"

Badge

Use the avatar.Badge component to add a badge to the avatar. The badge is positioned at the bottom right of the avatar.

@axadrn AA
package examples import "github.com/axadrn/shadcn-templ/v2/components/avatar"

Use the Class prop to add custom styles to the badge such as custom colors, sizes, etc.

@avatar.Avatar() {	@avatar.Image(avatar.ImageProps{Src: "https://github.com/axadrn.png", Alt: "@axadrn"})	@avatar.Fallback() {		AA	}	@avatar.Badge(avatar.BadgeProps{Class: "bg-green-600 dark:bg-green-800"})}

Badge with Icon

You can also use an icon inside avatar.Badge.

@axadrn AA
package examples import (

Avatar Group

Use the avatar.Group component to add a group of avatars.

@axadrn AA
@a-h AH
@joerdav JD
package examples import "github.com/axadrn/shadcn-templ/v2/components/avatar"

Avatar Group Count

Use avatar.GroupCount to add a count to the group.

@axadrn AA
@a-h AH
@joerdav JD
+3
package examples import "github.com/axadrn/shadcn-templ/v2/components/avatar"

Avatar Group with Icon

You can also use an icon inside avatar.GroupCount.

@axadrn AA
@a-h AH
@joerdav JD
package examples import (

Sizes

Use the Size prop to change the size of the avatar.

@axadrn AA
@axadrn AA
@axadrn AA
package examples import "github.com/axadrn/shadcn-templ/v2/components/avatar"

You can use the Avatar component as a trigger for a dropdown menu.

package examples import (

API Reference

Avatar

The Avatar component is the root component that wraps the avatar image and fallback.

Prop Type Default
Size SizeDefault | SizeSm | SizeLg SizeDefault
Class string -

Image

The avatar.Image component displays the avatar image.

Prop Type Default
Src string -
Alt string -
Class string -

Fallback

The avatar.Fallback component displays a fallback when the image fails to load.

Prop Type Default
Class string -

Badge

The avatar.Badge component displays a badge indicator on the avatar, typically positioned at the bottom right.

Prop Type Default
Class string -

Group

The avatar.Group component displays a group of avatars with overlapping styling.

Prop Type Default
Class string -

GroupCount

The avatar.GroupCount component displays a count indicator in an avatar group, typically showing the number of additional avatars.

Prop Type Default
Class string -