-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSpinner.component.tsx
65 lines (52 loc) · 1.32 KB
/
Spinner.component.tsx
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
import * as React from "react";
import { SpinnerService, spinnerService } from './spinner.service';
export interface ISpinnerProps {
name: string,
spinnerService?: SpinnerService
group?: string,
loadingImage?: string,
show?: boolean,
style?: object
}
export interface ISpinnerState {
show: boolean
}
export class SpinnerComponent extends React.Component<ISpinnerProps, ISpinnerState> {
private spinnerService = spinnerService;
set show(show: boolean) {
this.setState({ show });
}
get show() {
return this.state.show;
}
get name() {
return this.props.name;
}
get group() {
return this.props.group;
}
componentWillMount() {
this.setState({
show: this.props.hasOwnProperty('show') ? this.props.show : false
});
if (this.props.hasOwnProperty('spinnerService')) {
this.spinnerService = this.props.spinnerService;
}
this.spinnerService._register(this);
}
componentWillUnmount() {
this.spinnerService._unregister(this);
}
render() {
if (this.state.show) {
const { loadingImage } = this.props;
return (
<div style={{ display: 'inline-block' }}>
{ loadingImage && <img src={loadingImage} /> }
{ this.props.children }
</div>
);
}
return (<div style={{ display: 'inline-block' }}></div>);
}
}