2020-07-28 10:03:53 +08:00
|
|
|
---
|
|
|
|
title: Icon 图标
|
2021-01-07 23:35:03 +08:00
|
|
|
description:
|
2020-07-28 10:03:53 +08:00
|
|
|
type: 0
|
|
|
|
group: ⚙ 组件
|
|
|
|
menuName: Icon
|
2021-01-07 23:35:03 +08:00
|
|
|
icon:
|
2020-07-28 10:03:53 +08:00
|
|
|
order: 50
|
|
|
|
---
|
2021-01-07 23:35:03 +08:00
|
|
|
|
2021-04-19 11:30:35 +08:00
|
|
|
> 在 React 项目中使用 Icon 需要引入 `@fortawesome/fontawesome-free`,然后在代码中 `import '@fortawesome/fontawesome-free/css/all.css'`,还有相关的 webpack 配置,具体请参考 [amis-react-starter](https://github.com/aisuda/amis-react-starter) 里的配置
|
2021-01-27 18:26:04 +08:00
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
## 基本使用
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
```schema
|
2020-07-28 10:03:53 +08:00
|
|
|
{
|
|
|
|
"type": "page",
|
|
|
|
"body": {
|
|
|
|
"type": "icon",
|
|
|
|
"icon": "cloud"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
## 颜色及大小调整
|
|
|
|
|
|
|
|
icon 基于字体实现,所以可以通过[文字颜色](../../../style/typography/text-color)或[大小](../../../style/typography/font-size)来控制它。
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
|
|
|
"body": {
|
|
|
|
"type": "icon",
|
|
|
|
"icon": "cloud",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2020-07-28 10:03:53 +08:00
|
|
|
|
2021-01-28 16:30:38 +08:00
|
|
|
## 使用图标链接
|
|
|
|
|
|
|
|
icon 还可以使用 URL 地址,可以从 [iconfont](https://www.iconfont.cn/) 等网站下载图表的 svg 文件上传到服务器,然后使用对应的地址,比如
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type": "page",
|
|
|
|
"body": {
|
|
|
|
"type": "icon",
|
2021-01-28 17:04:31 +08:00
|
|
|
"icon": "https://suda.cdn.bcebos.com/images%2F2021-01%2Fdiamond.svg"
|
2021-01-28 16:30:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-03-29 11:49:40 +08:00
|
|
|
## 使用 v5/v6 版本的 fontawesome
|
|
|
|
|
|
|
|
`icon`默认支持[fontawesome v4](https://fontawesome.com/v4/icons/),如果想要支持 v5 以及 v6 版本的 fontawesome 请设置`vendor`为空字符串。
|
|
|
|
|
|
|
|
### fontawesome v5 版本
|
|
|
|
|
|
|
|
v5 用 far/fas 等表示前缀,可参考官网[示例](https://fontawesome.com/v5/search?m=free)
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type":"page",
|
|
|
|
"body":[
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-address-book",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-address-book",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-address-book",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-address-book",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "divider",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-bell",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-bell",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-bell",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-bell",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "divider",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-plus",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-plus",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-plus",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-plus",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "divider",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-question-circle",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-question-circle",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"far fa-question-circle",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fas fa-question-circle",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### fontawesome v6 版本
|
|
|
|
|
|
|
|
v6 用 fa-regular / fa-solid 等表示前缀,可参考官网[示例](https://fontawesome.com/search?m=free)
|
|
|
|
|
|
|
|
```schema
|
|
|
|
{
|
|
|
|
"type":"page",
|
|
|
|
"body":[
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fa-regular fa-address-book",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fa-solid fa-address-book",
|
|
|
|
"vendor":""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fa-regular fa-address-book",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type":"icon",
|
|
|
|
"icon":"fa-solid fa-address-book",
|
|
|
|
"vendor":"",
|
|
|
|
"className": "text-info text-xl"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-01-28 16:30:38 +08:00
|
|
|
## 属性表
|
|
|
|
|
2022-08-16 12:44:53 +08:00
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
| --------- | ------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------- |
|
|
|
|
| type | `string` | `icon` | 指定组件类型 |
|
|
|
|
| className | `string` | | 外层 CSS 类名 |
|
|
|
|
| icon | [模板](../../docs/concepts/template) | | icon 名称,支持 [fontawesome v4](https://fontawesome.com/v4/icons/) 或 通过 registerIcon 注册的 icon、或使用 url |
|
|
|
|
| vendor | `string` | | icon 类型,默认为`fa`, 表示 fontawesome v4。也支持 iconfont, 如果是 fontawesome v5 以上版本或者其他框架可以设置为空字符串 |
|
2023-01-05 10:11:28 +08:00
|
|
|
|
|
|
|
## 事件表
|
|
|
|
|
|
|
|
> 2.6.1 及以上版本
|
|
|
|
|
|
|
|
当前组件会对外派发以下事件,可以通过`onEvent`来监听这些事件,并通过`actions`来配置执行的动作,详细查看[事件动作](../../docs/concepts/event-action)。
|
|
|
|
|
2023-02-16 16:39:24 +08:00
|
|
|
| 事件名称 | 事件参数 | 说明 |
|
|
|
|
| ---------- | -------------------------------------- | -------------- |
|
|
|
|
| click | `nativeEvent: MouseEvent` 鼠标事件对象 | 点击时触发 |
|
|
|
|
| mouseenter | `nativeEvent: MouseEvent` 鼠标事件对象 | 鼠标移入时触发 |
|
|
|
|
| mouseleave | `nativeEvent: MouseEvent` 鼠标事件对象 | 鼠标移出时触发 |
|