-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadarSpinner.js
More file actions
94 lines (87 loc) · 2.2 KB
/
RadarSpinner.js
File metadata and controls
94 lines (87 loc) · 2.2 KB
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
89
90
91
92
93
94
import { styled } from '@linaria/react';
import { addRefProps } from '../utils/index';
const Radar = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
position: relative;
* {
box-sizing: border-box;
}
.circle {
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
animation: radar-spinner-animation ${(props) => props.animationDuration}ms
infinite;
}
.circle:nth-child(1) {
padding: ${(props) => props.borderWidth * 2 * 0}px;
animation-delay: ${(props) => props.animationDuration * 0.15}ms;
}
.circle:nth-child(2) {
padding: ${(props) => props.borderWidth * 2 * 1}px;
animation-delay: ${(props) => props.animationDuration * 0.15}ms;
}
.circle:nth-child(3) {
padding: ${(props) => props.borderWidth * 2 * 2}px;
animation-delay: ${(props) => props.animationDuration * 0.15}ms;
}
.circle:nth-child(4) {
padding: ${(props) => props.borderWidth * 2 * 3}px;
animation-delay: 0ms;
}
.circle-inner,
.circle-inner-container {
height: 100%;
width: 100%;
border-radius: 50%;
border: ${(props) => props.borderWidth}px solid transparent;
}
.circle-inner {
border-left-color: ${(props) => props.color};
border-right-color: ${(props) => props.color};
}
@keyframes radar-spinner-animation {
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(0deg);
}
}
`;
function generateSpinners(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="circle">
<div className="circle-inner-container">
<div className="circle-inner" />
</div>
</div>
));
}
const RadarSpinnerBase = ({
size = 110,
color = '#fff',
animationDuration = 2000,
className = '',
innerRef,
...props
}) => {
const borderWidth = (size * 5) / 110;
return (
<Radar
ref={innerRef}
size={size}
color={color}
animationDuration={animationDuration}
className={`radar-spinner${className ? ' ' + className : ''}`}
borderWidth={borderWidth}
{...props}
>
{generateSpinners(4)}
</Radar>
);
};
export const RadarSpinner = addRefProps(RadarSpinnerBase);