-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpringSpinner.js
78 lines (72 loc) · 1.96 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
import { styled } from '@linaria/react';
import { addRefProps } from '../utils/index';
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 SpringSpinnerBase = ({
size = 70,
color = '#fff',
animationDuration = 3000,
className = '',
innerRef,
...props
}) => (
<Spring
ref={innerRef}
size={size}
color={color}
animationDuration={animationDuration}
className={`spring-spinner${className ? ' ' + className : ''}`}
{...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>
);
export const SpringSpinner = addRefProps(SpringSpinnerBase);