-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCirclesToRhombusesSpinner.js
More file actions
95 lines (87 loc) · 2.16 KB
/
CirclesToRhombusesSpinner.js
File metadata and controls
95 lines (87 loc) · 2.16 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
95
import { styled } from '@linaria/react';
import { addRefProps } from '../utils/index';
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%;
}
}
`;
function generateRhombusChildren(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="circle" />
));
}
const CirclesToRhombusesSpinnerBase = ({
size = 15,
color = '#fff',
animationDuration = 1200,
className = '',
innerRef,
...props
}) => {
const circleMarginLeft = size * 1.125;
const circleNum = 3;
const delay = 150;
return (
<CircleRhombus
ref={innerRef}
size={size}
color={color}
animationDuration={animationDuration}
className={`circles-to-rhombuses-spinner${
className ? ' ' + className : ''
}`}
circleMarginLeft={circleMarginLeft}
delay={delay}
circleNum={circleNum}
{...props}
>
{generateRhombusChildren(circleNum)}
</CircleRhombus>
);
};
export const CirclesToRhombusesSpinner = addRefProps(CirclesToRhombusesSpinnerBase);