Skip to content

Commit 96edb4d

Browse files
authored
feat(statustag): support statusTag without icon (#523)
* feat(statustag): support statusTag without icon * feat(statustag): support custom style
1 parent d39128b commit 96edb4d

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

src/statusTag/__tests__/index.test.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ describe('test StatusTag suite', () => {
5555
const loadingWarper = container.querySelector(`.ant-spin-spinning`)!;
5656
expect(loadingWarper).toBeInTheDocument();
5757
});
58+
test('should render StatusTag no icon', () => {
59+
const { container } = render(<StatusTag icon={false}>自定义文案</StatusTag>);
60+
const loadingWarper = container.querySelector(`.${prefixCls}--icon`)!;
61+
expect(loadingWarper).not.toBeInTheDocument();
62+
});
5863
});

src/statusTag/demos/noIcon.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { Space } from 'antd';
3+
import { StatusTag } from 'dt-react-component';
4+
5+
export default () => {
6+
const presets = ['blue', 'yellow', 'green', 'gray', 'red', 'purple', 'cyan', 'pink'];
7+
8+
return (
9+
<Space direction="vertical">
10+
{presets.map((preset) => (
11+
<StatusTag key={preset} type="fill" color={preset} icon={false}>
12+
{preset}
13+
</StatusTag>
14+
))}
15+
</Space>
16+
);
17+
};

src/statusTag/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ StatusTag 组件作用于任务运行状态效果展示
1919
<code src="./demos/basic.tsx" description="内置6种不同的`color`,三种类型`default | outline | fill`,同时我们添加了多种预设色彩的状态样式,用作不同场景使用。如果预设值不能满足你的需求,可以设置为具体的色值">基础使用</code>
2020
<code src="./demos/status.tsx" description="用于表示状态的小圆点">状态点</code>
2121
<code src="./demos/loading.tsx" description="通过设置 `loading` 可以设置加载中的状态标签">加载中</code>
22-
<code src="./demos/icon.tsx" description="可以通过`icon`自定义图标">加载中</code>
22+
<code src="./demos/icon.tsx" description="可以通过`icon`自定义图标">自定义图标</code>
23+
<code src="./demos/noIcon.tsx" description="icon设置为除undefined之外假值等不展示图标">不展示图标</code>
2324

2425
## API
2526

src/statusTag/index.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ const StatusTag: React.FC<IStatusTagProps> = function StatusTag(props) {
7070
color = 'green',
7171
loading = false,
7272
background,
73+
style,
7374
...other
7475
} = props;
7576
const prefixCls = 'dtc-statusTag';
7677

78+
const showDefaultIcon = icon === undefined;
79+
7780
const classes = classNames(`${prefixCls}`, className, {
7881
[`${prefixCls}--border`]: type === 'outline',
7982
[`${prefixCls}--fill`]: type === 'fill',
@@ -100,13 +103,19 @@ const StatusTag: React.FC<IStatusTagProps> = function StatusTag(props) {
100103
};
101104

102105
return (
103-
<div {...other} className={classes} style={tagStyle}>
106+
<div {...other} className={classes} style={{ ...tagStyle, ...style }}>
104107
{loading ? (
105-
<Spin spinning indicator={<LoadingOutlined />} size="small" />
108+
<Spin
109+
spinning
110+
indicator={<LoadingOutlined className={`${prefixCls}__icon`} />}
111+
size="small"
112+
/>
106113
) : (
107-
<div className={`${prefixCls}__icon`}>
108-
<span {...getIconStyleAndClass()}>{icon ?? <></>}</span>
109-
</div>
114+
(icon || showDefaultIcon) && (
115+
<div className={`${prefixCls}__icon`}>
116+
<span {...getIconStyleAndClass()}>{icon ?? <></>}</span>
117+
</div>
118+
)
110119
)}
111120
<span className={`${prefixCls}__text`}>{props.children}</span>
112121
</div>

src/statusTag/style.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ $colors: (
5858
display: flex;
5959
align-items: center;
6060
font-size: 16px;
61+
margin-right: 8px;
6162
&--default {
6263
display: inline-block;
6364
width: 6px;
@@ -68,7 +69,6 @@ $colors: (
6869
&__text {
6970
font-size: 12px;
7071
font-weight: 400;
71-
margin-left: 8px;
7272
line-height: 22px;
7373
white-space: nowrap;
7474
}

0 commit comments

Comments
 (0)