-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCirclesToRhombusesSpinner.js
105 lines (96 loc) · 2.35 KB
/
CirclesToRhombusesSpinner.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
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const CircleRhombus = styled.div`
height: ${(props) => props.size}px;
width: ${(props) =>
(props.size + props.circleMarginLeft) * props.circleNum}px;
display: flex;
align-items: center;
justify-content: center;
* {
box-sizing: border-box;
}
.circle {
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
margin-left: ${(props) => props.circleMarginLeft}px;
transform: rotate(45deg);
border-radius: 10%;
border: 3px solid ${(props) => props.color};
overflow: hidden;
background: transparent;
animation: circles-to-rhombuses-animation
${(props) => props.animationDuration}ms linear infinite;
}
.circle:nth-child(1) {
animation-delay: calc(${(props) => props.delay}ms * 1);
margin-left: 0;
}
.circle:nth-child(2) {
animation-delay: calc(${(props) => props.delay}ms * 2);
}
.circle:nth-child(3) {
animation-delay: calc(${(props) => props.delay}ms * 3);
}
@keyframes circles-to-rhombuses-animation {
0% {
border-radius: 10%;
}
17.5% {
border-radius: 10%;
}
50% {
border-radius: 100%;
}
93.5% {
border-radius: 10%;
}
100% {
border-radius: 10%;
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
function generateRhombusChildren(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="circle" />
));
}
const CirclesToRhombusesSpinner = ({
size = 15,
color = '#fff',
animationDuration = 1200,
className = '',
style,
...props
}) => {
const circleMarginLeft = size * 1.125;
const circleNum = 3;
const delay = 150;
return (
<CircleRhombus
size={size}
color={color}
animationDuration={animationDuration}
className={`circles-to-rhombuses-spinner${
className ? ' ' + className : ''
}`}
style={style}
circleMarginLeft={circleMarginLeft}
delay={delay}
circleNum={circleNum}
{...props}
>
{generateRhombusChildren(circleNum)}
</CircleRhombus>
);
};
CirclesToRhombusesSpinner.propTypes = propTypes;
export default CirclesToRhombusesSpinner;