-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
52 lines (45 loc) · 1.48 KB
/
index.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
const React = require('react');
const PropTypes = require('prop-types');
var defaultLoadingComponent = () => React.createElement('div', null, 'Loading');
var defaultBaseComponent = React.PureComponent;
function loading({
LoadingComponent,
className,
loadingPropOptional = false,
fullDisplayName = false
} = {}) {
return function(Component = defaultBaseComponent) {
const Loading = class extends Component {
renderLoading(props = {}) {
if (this.props.loading) {
return React.createElement(
LoadingComponent || defaultLoadingComponent,
Object.assign(props, { className: props.className || className })
);
}
return undefined;
}
};
// Add loading PropType
Loading.propTypes = Object.assign(Component.propTypes || {}, {
loading: loadingPropOptional ? PropTypes.bool : PropTypes.bool.isRequired
});
// Change the display name
let displayName = Component.displayName || Component.name;
Loading.displayName = fullDisplayName ? `Loading(${displayName})` : displayName;
return Loading;
};
}
loading.getDefaultBaseComponent = function() {
return defaultBaseComponent;
};
loading.setDefaultBaseComponent = function(Component) {
defaultBaseComponent = Component;
};
loading.getDefaultLoadingComponent = function() {
return defaultLoadingComponent;
};
loading.setDefaultLoadingComponent = function(Component) {
defaultLoadingComponent = Component;
};
module.exports = loading;