-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
LoopingRhombusesSpinner.js
88 lines (79 loc) · 2.12 KB
/
LoopingRhombusesSpinner.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
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
const LoadingRhombus = styled.div`
width: ${(props) => props.size * 4}px;
height: ${(props) => props.size}px;
position: relative;
* {
box-sizing: border-box;
}
.rhombus {
height: ${(props) => props.size}px;
width: ${(props) => props.size}px;
background-color: ${(props) => props.color};
left: ${(props) => props.size * 4}px;
position: absolute;
margin: 0 auto;
border-radius: 2px;
transform: translateY(0) rotate(45deg) scale(0);
animation: looping-rhombuses-spinner-animation
${(props) => props.animationDuration}ms linear infinite;
}
.rhombus:nth-child(1) {
animation-delay: calc(${(props) => props.animationDuration}ms * 1 / -1.5);
}
.rhombus:nth-child(2) {
animation-delay: calc(${(props) => props.animationDuration}ms * 2 / -1.5);
}
.rhombus:nth-child(3) {
animation-delay: calc(${(props) => props.animationDuration}ms * 3 / -1.5);
}
@keyframes looping-rhombuses-spinner-animation {
0% {
transform: translateX(0) rotate(45deg) scale(0);
}
50% {
transform: translateX(-233%) rotate(45deg) scale(1);
}
100% {
transform: translateX(-466%) rotate(45deg) scale(0);
}
}
`;
const propTypes = {
size: PropTypes.number,
animationDuration: PropTypes.number,
color: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object,
};
function generateSpinners(num) {
return Array.from({ length: num }).map((val, index) => (
<div key={index} className="rhombus" />
));
}
const LoopingRhombusesSpinner = ({
size = 15,
color = '#fff',
animationDuration = 2500,
className = '',
style,
...props
}) => {
const num = 3;
return (
<LoadingRhombus
size={size}
color={color}
animationDuration={animationDuration}
className={`looping-rhombuses-spinner${className ? ' ' + className : ''}`}
style={style}
{...props}
>
{generateSpinners(num)}
</LoadingRhombus>
);
};
LoopingRhombusesSpinner.propTypes = propTypes;
export default LoopingRhombusesSpinner;