# 头像 · JGuang UI

> 展示用户头像，并在图片不可用时提供回退内容。

- 页面: https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar
- 改编自: shadcn/ui 文档 (MIT) @ bc0705384b51252af26dcc65425b216bf5eb063c
- 说明：正文保留英文原文。

> 示例 `avatar-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Installation


  

**Command**


  

**Manual**


```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```


### Install the following dependencies:


```bash
npm install radix-ui
```


### Copy and paste the following code into your project.


[View complete source: components/ui/avatar.tsx](/r/jguang-ui/radix/avatar.json)


### Update the import paths to match your project setup.


## Usage

```tsx showLineNumbers
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
```

```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```

## Composition

Use the following composition to build an `Avatar`:

```text
Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge
```

Use the following composition to build an `AvatarGroup`:

```text
AvatarGroup
├── Avatar
│   ├── AvatarImage
│   ├── AvatarFallback
│   └── AvatarBadge
├── Avatar
│   ├── AvatarImage
│   ├── AvatarFallback
│   └── AvatarBadge
└── AvatarGroupCount
```

## Basic

A basic avatar component with an image and a fallback.


> 示例 `avatar-basic`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Badge

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


> 示例 `avatar-badge`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


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

```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```

## Badge with Icon

You can also use an icon inside `<AvatarBadge>`.


> 示例 `avatar-badge-icon`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Avatar Group

Use the `AvatarGroup` component to add a group of avatars.


> 示例 `avatar-group`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Avatar Group Count

Use `<AvatarGroupCount>` to add a count to the group.


> 示例 `avatar-group-count`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Avatar Group with Icon

You can also use an icon inside `<AvatarGroupCount>`.


> 示例 `avatar-group-count-icon`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Sizes

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


> 示例 `avatar-size`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## Dropdown

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


> 示例 `avatar-dropdown`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## RTL

To enable RTL support in JGuang UI, see the [RTL configuration guide](/systems/jguang-ui/docs/rtl).


> 示例 `avatar-rtl`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/avatar


## API Reference

### Avatar

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

| Prop        | Type                        | Default     |
| ----------- | --------------------------- | ----------- |
| `size`      | `"default" \| "sm" \| "lg"` | `"default"` |
| `className` | `string`                    | -           |

### AvatarImage

The `AvatarImage` component displays the avatar image. It accepts all Radix UI Avatar Image props.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `src`       | `string` | -       |
| `alt`       | `string` | -       |
| `className` | `string` | -       |

### AvatarFallback

The `AvatarFallback` component displays a fallback when the image fails to load. It accepts all Radix UI Avatar Fallback props.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### AvatarBadge

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

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### AvatarGroup

The `AvatarGroup` component displays a group of avatars with overlapping styling.

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

### AvatarGroupCount

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

| Prop        | Type     | Default |
| ----------- | -------- | ------- |
| `className` | `string` | -       |

For more information about Radix UI Avatar props, see the [Radix UI documentation](https://www.radix-ui.com/primitives/docs/components/avatar#api-reference).

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
