Skip to content

Commit 9a1b6be

Browse files
author
wangshuhan
committed
feat: empty-component
1 parent 7cef2c3 commit 9a1b6be

5 files changed

Lines changed: 128 additions & 3 deletions

File tree

12.4 KB
Loading

src/components/Empty/index.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.haki-empty-root {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
justify-content: center;
6+
}
7+
8+
.haki-empty-root .haki-empty-image {
9+
width: 160px;
10+
height: 160px;
11+
}
12+
13+
.haki-empty-root .haki-empty-title {
14+
margin-top: 8px;
15+
font-size: 16px;
16+
font-weight: 600;
17+
color: #333;
18+
line-height: 24px;
19+
}
20+
21+
.haki-empty-root .haki-empty-description {
22+
margin-top: 4px;
23+
font-size: 14px;
24+
color: #666;
25+
line-height: 21px;
26+
}
27+
28+
.haki-empty-root .haki-empty-button {
29+
min-width: 80px;
30+
height: 32px;
31+
margin-top: 16px;
32+
padding: 0 16px;
33+
font-size: 14px;
34+
color: #fff;
35+
line-height: 32px;
36+
text-align: center;
37+
background-color: #06605a;
38+
border-radius: 6px;
39+
box-sizing: border-box;
40+
cursor: pointer;
41+
transition: background-color 0.3s ease;
42+
}
43+
44+
.haki-empty-root .haki-empty-button:hover {
45+
background-color: #207a74;
46+
}
47+
48+
.haki-empty-root .haki-empty-button:active {
49+
background-color: #004747;
50+
}

src/components/Empty/index.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,43 @@ group:
1111

1212
空状态时的展示占位图。
1313

14+
## 示例
15+
16+
仅图片
17+
1418
```jsx
1519
import { Empty } from 'react-haki';
1620

17-
export default () => <Empty title="Hello dumi!" />;
21+
export default () => <Empty />;
1822
```
23+
24+
全展示
25+
26+
```jsx
27+
import { Empty } from 'react-haki';
28+
29+
export default () => (
30+
<Empty
31+
title="无内容"
32+
description="请刷新页面重试"
33+
buttonText="刷新"
34+
onClick={() => {
35+
location.reload();
36+
}}
37+
/>
38+
);
39+
```
40+
41+
## Empty
42+
43+
### 属性
44+
45+
| 属性 | 说明 | 类型 | 默认值 |
46+
| ----------- | ------------ | --------------------- | ------ |
47+
| image | 占位图 | `string` | - |
48+
| title | 标题 | `string` | - |
49+
| description | 描述 | `string` | - |
50+
| buttonText | 按钮文案 | `string` | - |
51+
| onClick | 按钮点击事件 | `() => void` | - |
52+
| className | 类名 | `string` | - |
53+
| style | 根元素样式 | `React.CSSProperties` | - |

src/components/Empty/index.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
import React, { type FC } from 'react';
2+
import emptyImage from './assets/empty.png';
3+
import './index.css';
24

3-
const Empty: FC<{ title: string }> = (props) => <h4>{props.title}</h4>;
5+
interface EmptyProps {
6+
image?: string;
7+
title?: string;
8+
description?: string;
9+
buttonText?: string;
10+
onClick?: () => void;
11+
className?: string;
12+
style?: React.CSSProperties;
13+
}
14+
15+
const Empty: FC<EmptyProps> = (props) => {
16+
const { title, description, image, buttonText, onClick, className, style } =
17+
props;
18+
19+
return (
20+
<div className={`haki-empty-root ${className}`} style={style}>
21+
<img className="haki-empty-image" src={image || emptyImage} alt="" />
22+
{title && <div className="haki-empty-title">{title}</div>}
23+
{description && (
24+
<div className="haki-empty-description">{description}</div>
25+
)}
26+
{buttonText && (
27+
<div className="haki-empty-button" onClick={onClick}>
28+
{buttonText}
29+
</div>
30+
)}
31+
</div>
32+
);
33+
};
434

535
export default Empty;

src/components/Foo/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ group:
1111

1212
This is an example component.
1313

14+
## 示例
15+
1416
```jsx
1517
import { Foo } from 'react-haki';
1618

17-
export default () => <Foo title="Hello dumi!" />
19+
export default () => <Foo title="Hello dumi!" />;
1820
```
21+
22+
## Foo
23+
24+
### 属性
25+
26+
| 属性 | 说明 | 类型 | 默认值 |
27+
| ----- | ------------ | -------- | ------ |
28+
| title | 内容(必填) | `string` | - |

0 commit comments

Comments
 (0)