-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (53 loc) · 1.63 KB
/
Copy pathindex.js
File metadata and controls
59 lines (53 loc) · 1.63 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
import PropTypes from "prop-types";
import React from "react";
import styled, { keyframes } from "styled-components";
const rotate = () => keyframes`
to {
transform: rotate(450deg);
}
`;
const getBars = ({ countBars, color, size, sizeUnit }) => {
const bars = [];
for (let i = 0; i < countBars; i++) {
bars.push(<Bar color={color} size={size} key={i.toString()} sizeUnit={sizeUnit} index={i} />);
}
return bars;
};
export const CombSpinner = ({ size = 100, color = "#fff", loading = true, sizeUnit = "px" }) => {
const countBars = size / 9;
return (
loading && (
<Wrapper size={size} sizeUnit={sizeUnit}>
{getBars({
countBars,
color,
size,
sizeUnit,
})}
</Wrapper>
)
);
};
const Wrapper = styled.div`
position: relative;
width: ${props => `${props.size}${props.sizeUnit}`};
height: ${props => `${props.size / 5}${props.sizeUnit}`};
`;
const Bar = styled.div`
position: absolute;
left: 0;
width: ${props => `${props.size / 60}${props.sizeUnit}`};
height: ${props => `${props.size / 5}${props.sizeUnit}`};
left: ${props => `${props.index * 9}${props.sizeUnit}`};
transform-origin: center bottom;
transform: rotate(-90deg);
background-color: ${props => props.color};
animation: ${rotate} 3s ease infinite;
animation-delay: ${props => props.index * 0.05}s;
`;
CombSpinner.propTypes = {
loading: PropTypes.bool,
size: PropTypes.number,
color: PropTypes.string,
sizeUnit: PropTypes.string,
};