@@ -41,13 +41,6 @@ const Spinner = props => {
41
41
42
42
const isSpinnerColor = spinnerColors . has ( color ) ;
43
43
44
- // this spacing is consistent with the behaviour of dcc.Loading
45
- // it can be overridden with spinnerStyle
46
- const defaultSpinnerStyle = children
47
- ? { display : 'block' , margin : '1rem auto' }
48
- : { } ;
49
- const spinnerStyle = { ...defaultSpinnerStyle , ...spinner_style } ;
50
-
51
44
const fullscreenStyle = {
52
45
position : 'fixed' ,
53
46
width : '100vw' ,
@@ -59,35 +52,70 @@ const Spinner = props => {
59
52
justifyContent : 'center' ,
60
53
alignItems : 'center' ,
61
54
zIndex : 99 ,
55
+ visibility : 'visible' ,
62
56
...fullscreen_style
63
57
} ;
64
58
65
- if ( ! children || ( loading_state && loading_state . is_loading ) ) {
66
- if ( fullscreen ) {
67
- return (
68
- < div className = { fullscreenClassName } style = { fullscreenStyle } >
69
- < RSSpinner
70
- color = { isSpinnerColor ? color : null }
71
- style = { { color : ! isSpinnerColor && color , ...spinnerStyle } }
72
- className = { spinnerClassName }
73
- { ...omit ( [ 'setProps' ] , otherProps ) }
74
- />
75
- </ div >
76
- ) ;
77
- }
59
+ const SpinnerDiv = style => (
60
+ < RSSpinner
61
+ color = { isSpinnerColor ? color : null }
62
+ style = { { color : ! isSpinnerColor && color , ...style } }
63
+ className = { spinnerClassName }
64
+ { ...omit ( [ 'setProps' ] , otherProps ) }
65
+ />
66
+ ) ;
67
+ // Defaulted styles above to the situation where spinner has no children
68
+ // now include properties if spinner has children
69
+ if ( children ) {
70
+ // include covering style additions
71
+ const coveringStyle = {
72
+ visibility : 'visible' ,
73
+ position : 'absolute' ,
74
+ top : 0 ,
75
+ height : '100%' ,
76
+ width : '100%' ,
77
+ display : 'flex' ,
78
+ justifyContent : 'center' ,
79
+ alignItems : 'center'
80
+ } ;
81
+
82
+ const hiddenStyle = {
83
+ visibility : 'hidden' ,
84
+ position : 'relative'
85
+ } ;
86
+
87
+ const spinnerStyle = {
88
+ display : 'block' ,
89
+ margin : '1rem auto' ,
90
+ ...spinner_style
91
+ } ;
92
+
93
+ const showSpinner = loading_state && loading_state . is_loading ;
94
+
78
95
return (
79
- < RSSpinner
80
- color = { isSpinnerColor ? color : null }
81
- style = { { color : ! isSpinnerColor && color , ...spinnerStyle } }
82
- className = { spinnerClassName }
83
- { ...omit ( [ 'setProps' ] , otherProps ) }
84
- />
96
+ < div style = { showSpinner ? hiddenStyle : { } } >
97
+ { children }
98
+ { showSpinner && (
99
+ < div
100
+ style = { fullscreen ? fullscreenStyle : coveringStyle }
101
+ className = { fullscreen && fullscreenClassName }
102
+ >
103
+ < SpinnerDiv style = { spinnerStyle } />
104
+ </ div >
105
+ ) }
106
+ </ div >
85
107
) ;
86
108
}
87
- if ( type ( children ) !== 'Object' || type ( children ) !== 'Function' ) {
88
- return < Fragment > { children } </ Fragment > ;
109
+
110
+ if ( fullscreen ) {
111
+ return (
112
+ < div className = { fullscreenClassName } style = { fullscreenStyle } >
113
+ < SpinnerDiv style = { spinner_style } />
114
+ </ div >
115
+ ) ;
89
116
}
90
- return children ;
117
+
118
+ return < SpinnerDiv style = { spinner_style } /> ;
91
119
} ;
92
120
93
121
Spinner . _dashprivate_isLoadingComponent = true ;
0 commit comments