Skip to content

Commit ba11f4f

Browse files
JackWang032jialan
andauthored
Feat v4 empty (#295)
* feat: imporve Empty and test case * feat: optimize Empty docs --------- Co-authored-by: jialan <[email protected]>
1 parent e9051ef commit ba11f4f

File tree

11 files changed

+77
-62
lines changed

11 files changed

+77
-62
lines changed

jest.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ module.exports = {
33
preset: 'ts-jest',
44
testEnvironment: 'jsdom',
55
setupFilesAfterEnv: ['./tests/setupTests.js'],
6-
moduleNameMapper: {
6+
transform: {
77
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
8-
'<rootDir>/mock/mock.js',
8+
'<rootDir>/tests/fileTransformer.js',
9+
},
10+
moduleNameMapper: {
911
'\\.(css|scss|less)$': '<rootDir>/tests/styleMock.js',
1012
// make tests access in [email protected]
1113
'@babel/polyfill/lib/noConflict': '<rootDir>/tests/styleMock.js',

src/empty/__tests__/__snapshots__/empty.test.tsx.snap

Lines changed: 2 additions & 4 deletions
Large diffs are not rendered by default.

src/empty/emptyImg/empty_chart.png

7.47 KB
Loading
3.2 KB
Loading
15.7 KB
Loading
15 KB
Loading
9.49 KB
Loading
7.75 KB
Loading

src/empty/index.md

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,69 @@ demo:
1010

1111
## 何时使用
1212

13-
当目前没有数据时,用于显式的用户提示。初始化场景时的引导创建流程
13+
- 当目前没有数据时,用于显式的用户提示。
14+
- 初始化场景时的引导创建流程。
15+
- 内置 6 种空状态类型。
1416

1517
## 示例
1618

1719
```jsx
1820
/**
19-
* title="使用默认空状态"
21+
* title: "使用内置状态"
2022
*/
21-
import React from 'react';
23+
import React, { useState } from 'react';
2224
import { Empty } from 'dt-react-component';
25+
import { Radio, Space } from 'antd';
2326

24-
export default () => {
25-
return <Empty />;
26-
};
27-
```
27+
const options = [
28+
{ label: 'default', value: 'default' },
29+
{ label: 'project', value: 'project' },
30+
{ label: 'chart', value: 'chart' },
31+
{ label: 'search', value: 'search' },
32+
{ label: 'permission', value: 'permission' },
33+
{ label: 'overview', value: 'overview' },
34+
];
2835

29-
```jsx
30-
/**
31-
* title="使用别的空状态"
32-
*/
33-
import React from 'react';
34-
import { Empty } from 'dt-react-component';
35-
import { Divider } from 'antd';
36+
const getEmpty = (type) => {
37+
switch (type) {
38+
case 'default':
39+
return <Empty type="default" />;
40+
case 'project':
41+
return <Empty type="project" description="空项目" />;
42+
case 'chart':
43+
return <Empty type="chart" description="图表空数据" />;
44+
case 'search':
45+
return <Empty type="search" description="搜索无数据" />;
46+
case 'permission':
47+
return <Empty type="permission" description="无权限" />;
48+
case 'overview':
49+
return <Empty type="overview" description="description" />;
50+
default:
51+
return null;
52+
}
53+
};
3654

3755
export default () => {
56+
const [emptyType, setEmptyType] = useState('default');
3857
return (
3958
<>
40-
<Empty type="project" description="空项目" />
41-
<Divider />
42-
<Empty type="chart" description="图表空数据" />
43-
<Divider />
44-
<Empty type="search" description="搜索无数据" />
45-
<Divider />
46-
<Empty type="permission" description="无权限" />
47-
<Divider />
48-
<Empty type="overview" description="概览无数据" />
59+
<Space direction="vertical" style={{ width: '100%' }} size={16}>
60+
<Radio.Group
61+
defaultValue="default"
62+
optionType="button"
63+
options={options}
64+
onChange={(e) => setEmptyType(e.target.value)}
65+
/>
66+
{getEmpty(emptyType)}
67+
</Space>
4968
</>
5069
);
5170
};
5271
```
5372

5473
```jsx
5574
/**
56-
* title="使用自定义图片"
75+
* title: "使用自定义图片"
5776
*/
5877
import React from 'react';
5978
import { Empty } from 'dt-react-component';
@@ -68,7 +87,7 @@ export default () => {
6887

6988
```jsx
7089
/**
71-
* title="更多配置"
90+
* title: "更多配置"
7291
*/
7392
import React from 'react';
7493
import { Empty } from 'dt-react-component';
@@ -81,7 +100,7 @@ export default () => {
81100
<Empty
82101
height={60}
83102
imageStyle={{ height: 120 }}
84-
description="imageStyle 和 height 共同设置"
103+
description="使用继承自antd的属性imageStyle"
85104
/>
86105
</>
87106
);
@@ -90,11 +109,12 @@ export default () => {
90109

91110
## API
92111

93-
| 参数 | 说明 | 类型 | 默认值 |
94-
| ------ | ------------------------------------------ | ----------------- | --------- |
95-
| type | 默认展示图片的类型 | `string` | `default` |
96-
| image | 自定义图片(设置该参数时,默认的图片不生效) | `React.ReactNode` | - |
97-
| height | 图片大小(会被 imageStyle 中的 height 覆盖) | `number` | `80` |
112+
| 参数 | 说明 | 类型 | 默认值 |
113+
| ---------- | ------------------------------------------ | --------------------------------------------------------------------------- | --------- |
114+
| type | 默认展示图片的类型 | `default` \| `project` \| `chart` \| `search` \| `permission` \| `overview` | `default` |
115+
| height | 图片高度 | `number` | 80 |
116+
| image | 自定义图片(设置该参数时,默认的图片不生效) | `React.ReactNode` | - |
117+
| imageStyle | 自定义图片样式 | `React.CSSProperties` | - |
98118

99119
:::info
100120
其余属性[继承 antd4.x 的 Empty](https://ant.design/components/empty-cn/#API)

src/empty/index.tsx

Lines changed: 11 additions & 25 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)