-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathProgressBar.js
61 lines (55 loc) · 1.29 KB
/
ProgressBar.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
/* eslint-disable no-unused-vars */
import React from "react";
import styled from "styled-components";
import { COLORS } from "../../constants";
import VisuallyHidden from "../VisuallyHidden";
const SIZES = {
small: {
"--height": "8px",
"--padding": "0px",
"--radius": "4px",
},
medium: {
"--height": "12px",
"--radius": "4px",
"--padding": "0px",
},
large: {
"--height": "16px",
"--radius": "8px",
"--padding": "4px",
},
};
const Wrapper = styled.div`
background-color: ${COLORS.transparentGray15};
border-radius: var(--radius);
padding: var(--padding);
`;
const BarWrapper = styled.div`
border-radius: 4px;
/* Hide overflow when bar is nearly full */
overflow: hidden;
`;
const Bar = styled.div`
background-color: ${COLORS.primary};
border-radius: 4px 0 0 4px;
height: var(--height);
width: ${(props) => props.value}%;
`;
const ProgressBar = ({ value, size }) => {
const styles = SIZES[size];
if (!styles) {
throw new Error(`Unknown size passed to ProgressBar: ${size}`);
}
return (
<>
<Wrapper style={styles}>
<BarWrapper style={styles}>
<Bar style={styles} value={value} />
</BarWrapper>
</Wrapper>
<VisuallyHidden>{value}%</VisuallyHidden>
</>
);
};
export default ProgressBar;