Avatar
Display user profile images, initials or fallback icons.
Sizes
size is in pixels. The default is 40.
Types
The avatar shows the image from src. Without one, or when it fails to load, it shows up to two initials from fallbackText on a gradient. showInitials={false} keeps only the gradient, and fallback replaces it with your own node.
User avatar
UserAvatar is the avatar for a person: round, 20 px by default, with a user icon when there is no image. alt is both the accessible label and the fallback text.
Installation
pnpm dlx shadcn@latest add @narakui/avatarAdd "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/avatar.json.
Usage
import { Avatar } from '@/components/ui/avatar';
<Avatar fallbackText="John Doe" />Avatar Properties
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Additional CSS classes to apply to the avatar container |
src | string | { src: string } | — | URL or static-import object of the image to display |
fallbackText | string | Required | Accessible label for the avatar, and the source of the initials shown when there is no image or it fails to load |
showInitials | boolean | true | Show letter initials in the fallback |
fallback | ReactNode | — | Custom node rendered when the image is missing or fails |
imageAlt | string | 'Avatar' | Alt text for the avatar image |
imageRole | 'presentation' | 'none' | — | ARIA role applied to the avatar image |
size | number | 40 | Size of the avatar in pixels |
isLoading | boolean | false | Show loading skeleton state |
textSize | 'small' | 'large' | 'large' | Size of the fallback text |
imagePriority | boolean | false | Load the image eagerly with high fetch priority |
UserAvatar Properties
| Prop | Type | Default | Description |
|---|---|---|---|
alt | string | Required | Accessible label and fallback text |
src | string | { src: string } | — | URL or static-import object of the profile image |
size | number | 20 | Size of the avatar in pixels |
className | string | — | Additional CSS classes to apply to the avatar |