This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathLoading.react.js
147 lines (130 loc) · 3.91 KB
/
Loading.react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import GraphSpinner from '../fragments/Loading/spinners/GraphSpinner.jsx';
import DefaultSpinner from '../fragments/Loading/spinners/DefaultSpinner.jsx';
import CubeSpinner from '../fragments/Loading/spinners/CubeSpinner.jsx';
import CircleSpinner from '../fragments/Loading/spinners/CircleSpinner.jsx';
import DotSpinner from '../fragments/Loading/spinners/DotSpinner.jsx';
function getSpinner(spinnerType) {
switch (spinnerType) {
case 'graph':
return GraphSpinner;
case 'cube':
return CubeSpinner;
case 'circle':
return CircleSpinner;
case 'dot':
return DotSpinner;
default:
return DefaultSpinner;
}
}
const hiddenContainer = {visibility: 'hidden', position: 'relative'};
const coveringSpinner = {
visibility: 'visible',
position: 'absolute',
top: '0',
height: '100%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
};
/**
* A Loading component that wraps any other component and displays a spinner until the wrapped component has rendered.
*/
export default class Loading extends Component {
render() {
const {
loading_state,
color,
className,
style,
fullscreen,
debug,
type: spinnerType,
} = this.props;
const isLoading = loading_state && loading_state.is_loading;
const Spinner = isLoading && getSpinner(spinnerType);
return (
<div style={isLoading ? hiddenContainer : {}}>
{this.props.children}
<div style={isLoading ? coveringSpinner : {}}>
{isLoading && (
<Spinner
className={className}
style={style}
status={loading_state}
color={color}
debug={debug}
fullscreen={fullscreen}
/>
)}
</div>
</div>
);
}
}
Loading._dashprivate_isLoadingComponent = true;
Loading.defaultProps = {
type: 'default',
color: '#119DFF',
};
Loading.propTypes = {
/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string,
/**
* Array that holds components to render
*/
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
/**
* Property that determines which spinner to show
* one of 'graph', 'cube', 'circle', 'dot', or 'default'.
*/
type: PropTypes.oneOf(['graph', 'cube', 'circle', 'dot', 'default']),
/**
* Boolean that makes the spinner display full-screen
*/
fullscreen: PropTypes.bool,
/**
* If true, the spinner will display the component_name and prop_name
* while loading
*/
debug: PropTypes.bool,
/**
* Additional CSS class for the spinner root DOM node
*/
className: PropTypes.string,
/**
* Additional CSS styling for the spinner root DOM node
*/
style: PropTypes.object,
/**
* Primary colour used for the loading spinners
*/
color: PropTypes.string,
/**
* Object that holds the loading state object coming from dash-renderer
*/
loading_state: PropTypes.shape({
/**
* Determines if the component is loading or not
*/
is_loading: PropTypes.bool,
/**
* Holds which property is loading
*/
prop_name: PropTypes.string,
/**
* Holds the name of the component that is loading
*/
component_name: PropTypes.string,
}),
};