-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathRotateSpin.jsx
42 lines (37 loc) · 1.03 KB
/
RotateSpin.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
import styled, { keyframes } from 'styled-components';
const loading = keyframes`
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
`;
function getColor(props) {
const d = document.createElement('div');
d.style.color = props.color;
document.body.appendChild(d);
const rgbcolor = window.getComputedStyle(d).color;
const match = /rgba?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*\d+[.d+]*)*\)/g.exec(rgbcolor);
const color = `${match[1]}, ${match[2]}, ${match[3]}`;
return color;
}
const RotateSpin = styled.div`
animation: ${props => `${loading} ${props.duration}s infinite linear`};
border: ${props => `1.1em solid rgba(${getColor(props)}, 0.2)`};
border-left: ${props => `1.1em solid ${props.color}`};
border-radius: 50%;
font-size: ${props => `${props.size}px`};
height: 10em;
margin: 60px auto;
position: relative;
text-indent: -9999em;
transform: translateZ(0);
width: 10em;
&:after {
border-radius: 50%;
height: 10em;
width: 10em;
}
`;
export default RotateSpin;