Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit dd553cf

Browse files
committed
✨ feat: 提供自定义加载图形接口
1 parent 8b55263 commit dd553cf

File tree

4 files changed

+60
-37
lines changed

4 files changed

+60
-37
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
import PageLoading from '@arvinxu/page-loading';
4+
5+
const Loading = () => {
6+
return (
7+
<div style={{ height: 300 }}>
8+
<PageLoading loader={<div>loading...</div>} id={'custom'} />
9+
</div>
10+
);
11+
};
12+
13+
export default Loading;

docs/components/common/page-loading.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ group:
99
# PageLoading
1010

1111
页面加载组件,特性:
12+
1213
- 支持全屏;
1314
- 吸顶加载进度条;
1415
- 自定义主色;
15-
- (TODO)自定义加载图形;
16+
- 自定义加载图形;
1617

1718
## 使用案例
1819

@@ -36,6 +37,10 @@ group:
3637

3738
<code src="./examples/PageLoading/LoadingState" />
3839

40+
### 自定义加载图形
41+
42+
<code src="./examples/PageLoading/CustomLoader" />
43+
3944
###
4045

4146
<API src="../../../packages/page-loading/src/index.tsx"></API>

packages/page-loading/src/index.tsx

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSSProperties, FC } from 'react';
1+
import type { CSSProperties, FC, ReactNode } from 'react';
22
import React from 'react';
33
import classNames from 'classnames';
44

@@ -7,15 +7,27 @@ import 'multi-nprogress/nprogress.css';
77
import { useProgress } from './useProgress';
88
import './style.less';
99

10-
const clsPrefix = 'avx-page-loading';
11-
1210
export interface PageLoadingProps {
11+
/**
12+
* 进度条 id。(可选)
13+
* 如果存在多个 PageLoading 组件,需要指定 id 以区分进度条
14+
*
15+
*/
16+
id?: string;
17+
18+
/**
19+
* 加载状态
20+
*/
21+
loading?: boolean;
22+
/**
23+
* 自定义加载图形
24+
*/
25+
loader?: ReactNode;
1326
/**
1427
* 是否全屏(可选)
1528
* @default false
1629
*/
1730
fullscreen?: boolean;
18-
1931
/**
2032
* 显示加载进度条(可选)
2133
* @default true
@@ -32,18 +44,6 @@ export interface PageLoadingProps {
3244
* @default #f3f4f6
3345
*/
3446
backgroundColor?: string;
35-
36-
/**
37-
* 进度条 id。(可选)
38-
* 如果存在多个 PageLoading 组件,需要指定 id 以区分进度条
39-
*
40-
*/
41-
id?: string;
42-
43-
/**
44-
* 加载状态
45-
*/
46-
loading?: boolean;
4747
}
4848

4949
const PageLoading: FC<PageLoadingProps> = ({
@@ -54,6 +54,7 @@ const PageLoading: FC<PageLoadingProps> = ({
5454
backgroundColor = '#f5f5f5',
5555
loading = true,
5656
children,
57+
loader,
5758
}) => {
5859
// 控制 Progress 显示
5960
useProgress(id, { color, enable: progress, loading, fullscreen });
@@ -68,28 +69,29 @@ const PageLoading: FC<PageLoadingProps> = ({
6869
<div
6970
id={id}
7071
className={classNames(
71-
`${clsPrefix}-container`,
72-
fullscreen ? `${clsPrefix}-fullscreen` : null,
72+
'avx-page-loading-container',
73+
fullscreen ? 'avx-page-loading-fullscreen' : '',
7374
)}
7475
style={{ background: backgroundColor }}
7576
>
76-
<div className={`${clsPrefix}-content`}>
77-
<div className={`${clsPrefix}-item`} style={colorStyle} />
78-
<div
79-
className={classNames(
80-
`${clsPrefix}-item`,
81-
`${clsPrefix}-animation-delay`,
82-
)}
83-
style={colorStyle}
84-
/>
85-
<div
86-
className={classNames(
87-
`${clsPrefix}-item`,
88-
`${clsPrefix}-animation-delay`,
89-
)}
90-
style={colorStyle}
91-
/>
92-
<div className={`${clsPrefix}-item`} style={colorStyle} />
77+
<div className="avx-page-loading-loader">
78+
{loader || (
79+
<div className="avx-page-loading-content">
80+
<div className="avx-page-loading-item" style={colorStyle} />
81+
<div
82+
className="avx-page-loading-item avx-page-loading-animation-delay"
83+
style={colorStyle}
84+
/>
85+
<div
86+
className={classNames(
87+
'avx-page-loading-item',
88+
'avx-page-loading-animation-delay',
89+
)}
90+
style={colorStyle}
91+
/>
92+
<div className="avx-page-loading-item" style={colorStyle} />
93+
</div>
94+
)}
9395
</div>
9496
</div>
9597
);

packages/page-loading/src/style.less

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
z-index: 9900;
2323
}
2424

25+
&-loader {
26+
margin: auto;
27+
}
28+
2529
&-content {
2630
display: flex;
2731
flex-direction: row;
@@ -30,7 +34,6 @@
3034
justify-content: space-around;
3135
width: 36px;
3236
height: 36px;
33-
margin: auto;
3437
}
3538

3639
&-item {

0 commit comments

Comments
 (0)