-
Notifications
You must be signed in to change notification settings - Fork 7
/
LoaderPulse.jsx
62 lines (52 loc) · 1.55 KB
/
LoaderPulse.jsx
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
import cx from 'classnames';
import { Linear, TimelineMax } from 'gsap/TweenMax';
import PropTypes from 'prop-types';
import React from 'react';
class LoaderPulse extends React.Component {
componentDidMount() {
const $loader = this.loader;
const $loaderPulses = $loader.querySelectorAll('.loader-pulse__pulse');
$loader.timeline = new TimelineMax({
paused: this.props.pause,
})
.staggerTo($loaderPulses, 0.25, {
opacity: 1,
repeat: -1,
repeatDelay: 0.25,
yoyo: true,
scale: 1.25,
ease: Linear.easeNone,
}, 0.125, 'loader');
}
componentDidUpdate() {
const $loader = this.loader;
if (this.props.pause) {
$loader.timeline.pause();
} else if ($loader.timeline.paused() && !this.props.pause) {
$loader.timeline.play();
}
}
render() {
const { className, type } = this.props;
const classes = cx('loader-pulse', className, {
'loader-pulse--default': type === 'default',
'loader-pulse--secondary': type === 'secondary',
'loader-pulse--accent': type === 'accent',
});
return (
<div className={classes} ref={ref => (this.loader = ref)}>
<span className="loader-pulse__pulse" /><span className="loader-pulse__pulse" /><span className="loader-pulse__pulse" />
</div>
);
}
}
LoaderPulse.propTypes = {
className: PropTypes.string,
pause: PropTypes.bool,
type: PropTypes.oneOf(['default', 'secondary', 'accent']),
};
LoaderPulse.defaultProps = {
pause: false,
type: 'default',
};
export default LoaderPulse;