1
1
import React from 'react' ;
2
+ import { ContainerConfig } from '../types' ;
2
3
3
- export interface ChartLoadingConfig {
4
+ interface ChartLoadingConfig extends Pick < ContainerConfig , 'loadingTemplate' | 'loading' > {
4
5
/**
5
6
* @title 主题
6
7
* @description 配置主题颜色
7
8
*/
8
- theme ?: string | object ;
9
- /**
10
- * @title 加载模板
11
- * @description 图表加载
12
- */
13
- loadingTemplate ?: React . ReactElement ;
9
+ theme ?: string ;
14
10
}
15
11
16
- const shadowLoading = ( ele : HTMLElement ) => {
12
+ const shadowLoading = ( ele : HTMLElement , style = { } ) => {
17
13
if ( typeof document === 'undefined' ) {
18
14
return 'loading' ;
19
15
}
16
+ let overStyle = "" ;
17
+ if ( style ) {
18
+ Object . keys ( style ) . forEach ( ( key ) => {
19
+ overStyle += `${ key } : ${ style [ key ] } ;\n` ;
20
+ } ) ;
21
+ }
20
22
const shadowRoot = ele . attachShadow ( { mode : 'open' } ) ;
21
23
const shadowDiv = document . createElement ( 'div' ) ;
22
24
const shadowStyle = document . createElement ( 'style' ) ;
@@ -34,6 +36,7 @@ const shadowLoading = (ele: HTMLElement) => {
34
36
border-radius: 50%;
35
37
background: #ccc;
36
38
animation-timing-function: cubic-bezier(0, 1, 1, 0);
39
+ ${ overStyle }
37
40
}
38
41
.loading div:nth-child(1) {
39
42
left: 8px;
@@ -82,12 +85,13 @@ const shadowLoading = (ele: HTMLElement) => {
82
85
shadowRoot . appendChild ( shadowDiv ) ;
83
86
} ;
84
87
85
- export const ChartLoading = ( { loadingTemplate, theme = 'light' } : ChartLoadingConfig ) => {
88
+ export const ChartLoading = ( { loadingTemplate, theme = 'light' , loading } : ChartLoadingConfig ) => {
86
89
const shadow = React . useRef < HTMLDivElement > ( null ) ;
90
+ const { container = { } , icon = { } } = typeof loading === 'object' ? loading : { } ;
87
91
88
92
React . useEffect ( ( ) => {
89
93
if ( ! loadingTemplate && shadow . current ) {
90
- shadowLoading ( shadow . current ) ;
94
+ shadowLoading ( shadow . current , icon ) ;
91
95
}
92
96
} , [ ] ) ;
93
97
const renderLoading = ( ) => {
@@ -108,7 +112,8 @@ export const ChartLoading = ({ loadingTemplate, theme = 'light' }: ChartLoadingC
108
112
left : 0 ,
109
113
top : 0 ,
110
114
zIndex : 99 ,
111
- backgroundColor : theme === 'dark' ? 'rgb(20, 20, 20)' : 'rgb(255, 255, 255)' ,
115
+ background : theme === 'dark' ? 'rgb(20, 20, 20)' : 'rgb(255, 255, 255)' ,
116
+ ...container
112
117
} }
113
118
>
114
119
{ renderLoading ( ) }
0 commit comments