Skip to content

Commit 696ad5b

Browse files
author
liyuan-meng
committed
🐛[Popover]支持配置自定义图标和图标样式
1 parent 71f892c commit 696ad5b

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

src/components/popover/demos/basic.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export default function PopoverDemo() {
4848
<Button>文字 + Icon</Button>
4949
</Popover>
5050
{split}
51+
<Popover
52+
trigger={trigger}
53+
content="这是一段文字描述"
54+
iconStyle={{ color: '#e74949' }}
55+
showIcon >
56+
<Button>自定义图标</Button>
57+
</Popover>
58+
{split}
5159
<Popover
5260
trigger={trigger}
5361
size="small"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
order: 1
3+
title: Popover
4+
desc: 默认样式
5+
---
6+
7+
```jsx
8+
import React, { useState, useEffect } from 'react';
9+
import { Button, Popover, Message, Checkbox } from 'cloud-react';
10+
11+
export default function PopoverDemo() {
12+
const [isClick, setIsClick] = useState(true);
13+
const [trigger, setTrigger] = useState('hover');
14+
15+
useEffect(() => {
16+
setTrigger(isClick ? 'click' : 'hover');
17+
}, [isClick]);
18+
19+
const split = <p style={{ height: 10 }} />
20+
21+
return (
22+
<div>
23+
<Popover
24+
trigger="click"
25+
content="这是一段文字描述"
26+
iconStyle={{ color: '#555BB3' }}
27+
showIcon >
28+
<Button>确认</Button>
29+
</Popover>
30+
{split}
31+
<Popover
32+
trigger="click"
33+
content="这是一段文字描述"
34+
iconStyle={{ color: '#fd830a' }}
35+
showIcon >
36+
<Button>提示</Button>
37+
</Popover>
38+
{split}
39+
<Popover
40+
trigger="click"
41+
content="这是一段文字描述"
42+
iconStyle={{ color: '#e74949' }}
43+
showIcon >
44+
<Button>高危提醒</Button>
45+
</Popover>
46+
{split}
47+
<Popover
48+
trigger="click"
49+
content="这是一段文字描述"
50+
iconType="shop-line"
51+
iconStyle={{ color: 'rgba(0,0,0,.65)' }}
52+
showIcon >
53+
<Button>自定义图标</Button>
54+
</Popover>
55+
</div>
56+
);
57+
}
58+
```

src/components/popover/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function Popover(props) {
1919
content,
2020
showIcon,
2121
iconTpl,
22+
iconType,
23+
iconStyle,
2224
showCancelBtn,
2325
showConfirmBtn,
2426
cancelBtnText,
@@ -82,7 +84,7 @@ function Popover(props) {
8284
<section className={`${classSelector}-content`}>
8385
{showIcon
8486
&& (iconTpl || (
85-
<Icon className={`${classSelector}-icon`} type="info_1" />
87+
<Icon className={`${classSelector}-icon`} style={iconStyle} type={iconType || 'info_1'} />
8688
))}
8789

8890
<div className={`${classSelector}-main-content`}>
@@ -165,6 +167,8 @@ Popover.propTypes = {
165167
content: PropTypes.any,
166168
showIcon: PropTypes.bool,
167169
iconTpl: PropTypes.any,
170+
iconType: PropTypes.string,
171+
iconStyle: PropTypes.object,
168172
showCancelBtn: PropTypes.bool,
169173
showConfirmBtn: PropTypes.bool,
170174
cancelBtnText: PropTypes.string,
@@ -184,6 +188,8 @@ Popover.defaultProps = {
184188
content: '',
185189
showIcon: false,
186190
iconTpl: '',
191+
iconType: '',
192+
iconStyle: {},
187193
showCancelBtn: false,
188194
showConfirmBtn: false,
189195
cancelBtnText: '取消',

src/components/popover/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ group:
2626
| content | 内容 | string | '' |
2727
| showIcon | 是否展示图标 | boolean | false |
2828
| iconTpl | 自定义图标 | Element | '' |
29+
| iconType | 自定义图标,可直接传入组件库的图标类型 | string | '' |
30+
| iconStyle | 图标样式,配置 iconTpl 时,该值无效 | object | {} |
2931
| showCancelBtn | 是否展示取消按钮 | boolean | false |
3032
| showConfirmBtn | 是否展示确认按钮 | boolean | false |
3133
| cancelBtnText | 取消按钮自定义文本 | string | '取消' |
@@ -41,6 +43,9 @@ group:
4143
### 基础使用
4244
<embed src="@components/popover/demos/basic.md" />
4345

46+
### 自定义图标
47+
<embed src="@components/popover/demos/customIcon.md" />
48+
4449
### 支持配置 Tooltip 参数,详细请参考 Tooltip 说明文档
4550

4651

0 commit comments

Comments
 (0)