Skip to content

Instantly share code, notes, and snippets.

@drio
Last active December 1, 2021 18:23
Show Gist options
  • Save drio/c9d12eee065baf8b9e13018b725a2f38 to your computer and use it in GitHub Desktop.
Save drio/c9d12eee065baf8b9e13018b725a2f38 to your computer and use it in GitHub Desktop.
/* 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