-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathIntersectingCirclesSpinner.js
117 lines (108 loc) · 2.68 KB
/
IntersectingCirclesSpinner.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const IntersectingCircles = styled.div`
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
position: relative;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
* {
box-sizing: border-box;
}
.spinnerBlock {
animation: intersecting-circles-spinners-animation
${(props) => props.animationDuration}ms linear infinite;
transform-origin: center;
display: block;
height: ${(props) => props.circleSize}px;
width: ${(props) => props.circleSize}px;
}
.circle {
display: block;
border: 2px solid ${(props) => props.color};
border-radius: 50%;
height: 100%;
width: 100%;
position: absolute;
left: 0;
top: 0;
}
.circle:nth-child(1) {
left: 0;
top: 0;
}
.circle:nth-child(2) {
left: ${(props) => props.circleSize * -0.36}px;
top: ${(props) => props.circleSize * 0.2}px;
}
.circle:nth-child(3) {
left: ${(props) => props.circleSize * -0.36}px;
top: ${(props) => props.circleSize * -0.2}px;
}
.circle:nth-child(4) {
left: 0;
top: ${(props) => props.circleSize * -0.36}px;
}
.circle:nth-child(5) {
left: ${(props) => props.circleSize * 0.36}px;
top: ${(props) => props.circleSize * -0.2}px;
}
.circle:nth-child(6) {
left: ${(props) => props.circleSize * 0.36}px;
top: ${(props) => props.circleSize * 0.2}px;
}
.circle:nth-child(7) {
left: 0;
top: ${(props) => props.circleSize * 0.36}px;
}
@keyframes intersecting-circles-spinners-animation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
function generateCircles(num) {
return Array.from({ length: num }).map((val, index) => (
<span key={index} className="circle" />
));
}
const IntersectingCirclesSpinner = ({
size = 70,
color = '#fff',
animationDuration = 1200,
className = '',
style,
...props
}) => {
const circleSize = size / 2;
return (
<IntersectingCircles
size={size}
color={color}
animationDuration={animationDuration}
className={`intersecting-circles-spinner${
className ? ' ' + className : ''
}`}
style={style}
circleSize={circleSize}
{...props}
>
<div className="spinnerBlock">{generateCircles(7)}</div>
</IntersectingCircles>
);
};
IntersectingCirclesSpinner.propTypes = propTypes;
export default IntersectingCirclesSpinner;