@@ -11,6 +11,11 @@ import {
11
11
import styled from "styled-components" ;
12
12
import { codeControl } from "comps/controls/codeControl" ;
13
13
import { setFieldsNoTypeCheck } from "util/objectUtils" ;
14
+ import Skeleton from "antd/es/skeleton" ;
15
+ import { ReactNode , useContext , useMemo } from "react" ;
16
+ import { CompContext } from "../utils/compContext" ;
17
+ import LoadingOutlined from "@ant-design/icons/LoadingOutlined" ;
18
+ import { ThemeContext } from "../utils/themeContext" ;
14
19
15
20
const Wrapper = styled . div `
16
21
&,
@@ -23,6 +28,50 @@ const Wrapper = styled.div`
23
28
24
29
const __WITH_IS_LOADING = "__WITH_IS_LOADING" ;
25
30
31
+ const LoadingWrapper = ( {
32
+ isLoading,
33
+ children,
34
+ } : {
35
+ isLoading : boolean ,
36
+ children : ReactNode ,
37
+ } ) => {
38
+ const compState = useContext ( CompContext ) ;
39
+ const currentTheme = useContext ( ThemeContext ) ?. theme ;
40
+
41
+ const showLoading = useMemo ( ( ) => {
42
+ const themeDataIndicator = currentTheme ?. showDataLoadingIndicators ;
43
+ const compDataIndicator = compState . comp ?. comp . showDataLoadingIndicators ;
44
+
45
+ return isLoading ? (
46
+ compDataIndicator !== 'undefined' ? compDataIndicator : Boolean ( themeDataIndicator )
47
+ ) : false ;
48
+ } , [
49
+ isLoading ,
50
+ currentTheme ?. showDataLoadingIndicators ,
51
+ compState . comp ?. comp . showDataLoadingIndicators ,
52
+ ] ) ;
53
+
54
+ if ( currentTheme ?. dataLoadingIndicator === 'skeleton' ) {
55
+ return (
56
+ < Wrapper >
57
+ < Skeleton active loading = { showLoading } >
58
+ { children }
59
+ </ Skeleton >
60
+ </ Wrapper >
61
+ ) ;
62
+ }
63
+
64
+ return (
65
+ < Wrapper >
66
+ < Spin
67
+ spinning = { showLoading }
68
+ indicator = { < LoadingOutlined style = { { fontSize : 15 } } spin /> }
69
+ >
70
+ { children }
71
+ </ Spin >
72
+ </ Wrapper >
73
+ )
74
+ }
26
75
/**
27
76
* Unified increase isLoading effect
28
77
*/
@@ -38,16 +87,16 @@ export function withIsLoading<T extends MultiCompConstructor>(VariantComp: T): T
38
87
} ,
39
88
updateNodeFields : ( value : any ) => {
40
89
const fetchInfo = value [ __WITH_IS_LOADING ] as FetchInfo ;
41
- return { isLoading : fetchInfo . isFetching } ;
90
+ return { isLoading : fetchInfo ? .isFetching } ;
42
91
} ,
43
92
} ) ;
44
93
}
45
94
46
95
override getView ( ) {
47
96
return (
48
- < Wrapper >
49
- < Spin spinning = { this . isLoading } > { super . getView ( ) } </ Spin >
50
- </ Wrapper >
97
+ < LoadingWrapper isLoading = { this . isLoading } >
98
+ { super . getView ( ) }
99
+ </ LoadingWrapper >
51
100
) ;
52
101
}
53
102
}
0 commit comments