2017-05-28 14:20:59 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
subtitle: 头像
|
|
|
|
|
title: Avatar
|
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
|
|
|
|
---
|
|
|
|
|
|
2017-06-09 15:00:44 +08:00
|
|
|
|
用来代表用户或事物,支持图片、图标或字符展示。
|
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
|
|
|
|
|
|
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
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| maxCount | 显示的最大头像个数 | number | - | |
|
|
|
|
|
| maxPopoverPlacement | 多余头像气泡弹出位置 | `top` \| `bottom` | `top` | |
|
2021-09-29 08:43:06 +08:00
|
|
|
|
| maxPopoverTrigger | 设置多余头像 Popover 的触发方式 | `hover` \| `focus` \| `click` | `hover` | 4.17.0 |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| maxStyle | 多余头像样式 | CSSProperties | - | |
|
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
|
|
|
|
|
|
|
|
|
## Design Token
|
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Avatar"></ComponentTokenTable>
|