Skip to content

Commit 49b9b37

Browse files
feat: #337 add statusTag loading (#341)
* feat: #337 add statusTag loading * fix: statusTag unit test * refactor: optimized statusTag loading
1 parent b85838a commit 49b9b37

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

src/statusTag/__tests__/index.test.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ describe('test StatusTag suite', () => {
1515
});
1616
test('should render StatusTag render correct type', () => {
1717
const { container } = render(<StatusTag type="run">完成</StatusTag>);
18-
expect(container.firstChild!.firstChild).toHaveClass(`${prefixCls}__run`);
18+
expect(container.querySelector(`.${prefixCls}__run`)).toBeInTheDocument();
1919
});
2020
test('should render StatusTag render correct color', () => {
2121
const { container } = render(<StatusTag color="#2177b8">完成</StatusTag>);
22-
const textWapper = container.firstChild!.firstChild;
22+
const textWapper = container.querySelector(`.${prefixCls}__default`);
2323
expect(textWapper).toHaveStyle({ background: '#2177b8' });
2424
});
2525
test('should render StatusTag render correct text', () => {
2626
const { container } = render(<StatusTag>自定义文案</StatusTag>);
2727
const textWapper = container.querySelector(`.${prefixCls}__text`)!;
2828
expect(textWapper.innerHTML).toEqual('自定义文案');
2929
});
30+
test('should render StatusTag loading', () => {
31+
const { container } = render(<StatusTag loading>自定义文案</StatusTag>);
32+
const loadingWapper = container.querySelector(`.ant-spin-spinning`)!;
33+
expect(loadingWapper).toBeInTheDocument();
34+
});
3035
});

src/statusTag/demos/loading.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { Space } from 'antd';
3+
import { StatusTag } from 'dt-react-component';
4+
5+
export default () => {
6+
return (
7+
<Space direction="vertical">
8+
<StatusTag type="success" showBorder={false} loading>
9+
成功
10+
</StatusTag>
11+
<StatusTag type="run" loading>
12+
运行中
13+
</StatusTag>
14+
</Space>
15+
);
16+
};

src/statusTag/index.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ StatusTag 组件作用于任务运行状态效果展示
1818

1919
<code src="./demos/basic.tsx" description="内置五种不同的 `type` ">基础使用</code>
2020
<code src="./demos/status.tsx" description="用于表示状态的小圆点">状态点</code>
21-
<code src="./demos/colorful.tsx" description="我们添加了多种预设色彩的状态样式,用作不同场景使用。如果预设值不能满足你的需求,可以设置为具体的色值">自定义状态</code>
2221
<code src="./demos/border.tsx" description="通过设置 `showBorder={false}` 可以隐藏外边框,默认为存在外边框">外边框</code>
22+
<code src="./demos/colorful.tsx" description="我们添加了多种预设色彩的状态样式,用作不同场景使用。如果预设值不能满足你的需求,可以设置为具体的色值">自定义状态</code>
23+
<code src="./demos/loading.tsx" description="通过设置 `loading` 可以设置加载中的状态标签">加载中</code>
2324

2425
## API
2526

@@ -31,3 +32,4 @@ StatusTag 组件作用于任务运行状态效果展示
3132
| showBorder | 是否展示外面的 border | `boolean` | `true` |
3233
| color | 自定义颜色(当 type 所支持的颜色不满足时可用,优先级更高) | `string` | - |
3334
| onClick | 点击事件 | `() => void` | - |
35+
| loading | 设置状态标签载入状态 | `boolean` | `false` |

src/statusTag/index.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React, { ReactNode, CSSProperties, HTMLAttributes } from 'react';
2+
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
3+
import { Spin } from 'antd';
24
import classNames from 'classnames';
35
import './style.scss';
46

@@ -9,12 +11,20 @@ export interface IStatusTagProps extends HTMLAttributes<HTMLDivElement> {
911
className?: string;
1012
showBorder?: boolean;
1113
color?: string;
14+
loading?: boolean;
1215
children?: ReactNode;
1316
onClick?: () => void;
1417
}
1518

1619
const StatusTag: React.FC<IStatusTagProps> = function StatusTag(props) {
17-
const { className, type = 'success', showBorder = true, color, ...other } = props;
20+
const {
21+
className,
22+
type = 'success',
23+
showBorder = true,
24+
color,
25+
loading = false,
26+
...other
27+
} = props;
1828
const prefixCls = 'dtc-statusTag';
1929

2030
const classes = classNames(`${prefixCls}`, className, {
@@ -27,7 +37,11 @@ const StatusTag: React.FC<IStatusTagProps> = function StatusTag(props) {
2737

2838
return (
2939
<div {...other} className={classes}>
30-
<div className={statusClass} style={style} />
40+
{loading ? (
41+
<Spin spinning indicator={<LoadingOutlined />} size="small" />
42+
) : (
43+
<div className={statusClass} style={style} />
44+
)}
3145
<span className={`${prefixCls}__text`}>{props.children}</span>
3246
</div>
3347
);

0 commit comments

Comments
 (0)