-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
SpringSpinner.js
88 lines (81 loc) · 2.14 KB
/
SpringSpinner.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
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const Spring = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
* {
box-sizing: border-box;
}
.spring-spinner-part {
overflow: hidden;
height: calc(${(props) => props.size}px / 2);
width: ${(props) => props.size}px;
}
.spring-spinner-part.bottom {
transform: rotate(180deg) scale(-1, 1);
}
.spring-spinner-rotator {
width: ${(props) => props.size}px;
height: ${(props) => props.size}px;
border: calc(${(props) => props.size}px / 7) solid transparent;
border-right-color: ${(props) => props.color};
border-top-color: ${(props) => props.color};
border-radius: 50%;
box-sizing: border-box;
animation: spring-spinner-animation ${(props) => props.animationDuration}ms
ease-in-out infinite;
transform: rotate(-200deg);
}
@keyframes spring-spinner-animation {
0% {
border-width: calc(${(props) => props.size}px / 7);
}
25% {
border-width: calc(${(props) => props.size}px / 23.33);
}
50% {
transform: rotate(115deg);
border-width: calc(${(props) => props.size}px / 7);
}
75% {
border-width: calc(${(props) => props.size}px / 23.33);
}
100% {
border-width: calc(${(props) => props.size}px / 7);
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
const SpringSpinner = ({
size = 70,
color = '#fff',
animationDuration = 3000,
className = '',
style,
...props
}) => (
<Spring
size={size}
color={color}
animationDuration={animationDuration}
className={`spring-spinner${className ? ' ' + className : ''}`}
style={style}
{...props}
>
<div className="spring-spinner-part top">
<div className="spring-spinner-rotator" />
</div>
<div className="spring-spinner-part bottom">
<div className="spring-spinner-rotator" />
</div>
</Spring>
);
SpringSpinner.propTypes = propTypes;
export default SpringSpinner;