2017-05-28 14:20:59 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
title: Avatar
|
2024-03-22 14:22:42 +08:00
|
|
|
|
subtitle: 头像
|
|
|
|
|
description: 用来代表用户或事物,支持图片、图标或字符展示。
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*JJBSS5lBG4IAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*YbgyQaRGz-UAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
|
|
|
|
group:
|
|
|
|
|
title: 数据展示
|
|
|
|
|
order: 5
|
2017-05-28 14:20:59 +08:00
|
|
|
|
---
|
|
|
|
|
|
2018-08-31 17:03:27 +08:00
|
|
|
|
## 设计师专属
|
2018-08-29 10:51:21 +08:00
|
|
|
|
|
2020-10-19 16:45:17 +08:00
|
|
|
|
安装 [Kitchen Sketch 插件 💎](https://kitchen.alipay.com),一键填充高逼格头像和文本。
|
2018-08-29 10:51:21 +08:00
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
|
<code src="./demo/type.tsx">类型</code>
|
|
|
|
|
<code src="./demo/dynamic.tsx">自动调整字符大小</code>
|
|
|
|
|
<code src="./demo/badge.tsx">带徽标的头像</code>
|
|
|
|
|
<code src="./demo/group.tsx">Avatar.Group</code>
|
|
|
|
|
<code src="./demo/toggle-debug.tsx" debug>隐藏情况下计算字符对齐</code>
|
|
|
|
|
<code src="./demo/responsive.tsx">响应式尺寸</code>
|
|
|
|
|
<code src="./demo/fallback.tsx" debug>图片不存在时</code>
|
2023-05-26 17:59:13 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>组件 Token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2017-05-28 14:20:59 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2020-07-13 12:45:37 +08:00
|
|
|
|
### Avatar
|
|
|
|
|
|
2019-07-11 14:14:33 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| alt | 图像无法显示时的替代文本 | string | - | |
|
|
|
|
|
| gap | 字符类型距离左右两侧边界单位像素 | number | 4 | 4.3.0 |
|
2019-08-13 14:07:17 +08:00
|
|
|
|
| icon | 设置头像的自定义图标 | ReactNode | - | |
|
2020-01-17 17:23:48 +08:00
|
|
|
|
| shape | 指定头像的形状 | `circle` \| `square` | `circle` | |
|
2020-11-02 11:31:42 +08:00
|
|
|
|
| size | 设置头像的大小 | number \| `large` \| `small` \| `default` \| { xs: number, sm: number, ...} | `default` | 4.7.0 |
|
|
|
|
|
| src | 图片类头像的资源地址或者图片元素 | string \| ReactNode | - | ReactNode: 4.8.0 |
|
2019-11-20 20:31:43 +08:00
|
|
|
|
| srcSet | 设置图片类头像响应式资源地址 | string | - | |
|
2023-03-09 17:37:22 +08:00
|
|
|
|
| draggable | 图片是否允许拖动 | boolean \| `'true'` \| `'false'` | true | |
|
2021-07-06 12:16:46 +08:00
|
|
|
|
| crossOrigin | CORS 属性设置 | `'anonymous'` \| `'use-credentials'` \| `''` | - | 4.17.0 |
|
2019-11-20 20:31:43 +08:00
|
|
|
|
| onError | 图片加载失败的事件,返回 false 会关闭组件默认的 fallback 行为 | () => boolean | - | |
|
2020-06-12 15:26:40 +08:00
|
|
|
|
|
|
|
|
|
> Tip:你可以设置 `icon` 或 `children` 作为图片加载失败的默认 fallback 行为,优先级为 `icon` > `children`
|
2020-07-13 12:45:37 +08:00
|
|
|
|
|
|
|
|
|
### Avatar.Group (4.5.0+)
|
|
|
|
|
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
2024-06-01 14:44:53 +08:00
|
|
|
|
| max | 设置最多显示相关配置,`5.18.0` 前可使用 [参数](https://github.com/ant-design/ant-design/blob/9d134859becbdae5b9ce276f6d9af4264691d81f/components/avatar/group.tsx#L35-L38) | `{ count?: number; style?: CSSProperties; popover?: PopoverProps }` | - | 5.18.0 |
|
2020-10-24 22:00:43 +08:00
|
|
|
|
| size | 设置头像的大小 | number \| `large` \| `small` \| `default` \| { xs: number, sm: number, ...} | `default` | 4.8.0 |
|
2023-07-27 20:04:32 +08:00
|
|
|
|
| shape | 设置头像的形状 | `circle` \| `square` | `circle` | 5.8.0 |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Avatar"></ComponentTokenTable>
|