Last active
December 1, 2021 18:23
-
-
Save drio/c9d12eee065baf8b9e13018b725a2f38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-unused-vars */ | |
import React from "react"; | |
import styled from "styled-components"; | |
import { COLORS } from "../../constants"; | |
import VisuallyHidden from "../VisuallyHidden"; | |
const STYLES = { | |
small: { | |
height: 8, | |
padding: 0, | |
radius: 4, | |
}, | |
medium: { | |
height: 12, | |
padding: 0, | |
radius: 4, | |
}, | |
large: { | |
height: 16, | |
padding: 4, | |
radius: 8, | |
}, | |
}; | |
const ProgressBar = ({ value, size }) => { | |
const styles = STYLES[size]; | |
if (!styles) throw new Error(`No styles provided`); | |
return ( | |
<Wrapper | |
role="progressbar" | |
aria-valuenow="20" | |
aria-valuemin="0" | |
aria-valuemax="100" | |
style={{ | |
"--padding": styles.padding + "px", | |
"--radius": styles.radius + "px", | |
}} | |
> | |
<VisuallyHidden></VisuallyHidden> | |
<BarWrapper> | |
<Bar | |
style={{ | |
"--width": value + "%", | |
"--height": styles.height + "px", | |
}} | |
/> | |
</BarWrapper> | |
</Wrapper> | |
); | |
}; | |
const Wrapper = styled.div` | |
background-color: ${COLORS.transparentGray15}; | |
box-shadow: inset 0px 2px 4px ${COLORS.transparentGray35}; | |
padding: var(--padding); | |
border-radius: var(--radius); | |
`; | |
const BarWrapper = styled.div` | |
border-radius: 4px; | |
/* Trim off corners when progress bar is near end */ | |
overflow: hidden; | |
`; | |
const Bar = styled.div` | |
width: var(--width); | |
height: var(--height); | |
background-color: ${COLORS.primary}; | |
border-radius: 4px 0 0 4px; | |
`; | |
export default ProgressBar; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment