Last active
May 20, 2022 06:56
-
-
Save gazpachu/bb72d02c83280f08abd9278cfdb9d8f0 to your computer and use it in GitHub Desktop.
Pure CSS Animated Circular Progress Bar
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
<Progress> | |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 34 34"> | |
<ProgressSurface cx="16" cy="16" r="15.9155" /> | |
<ProgressBar | |
cx="16" | |
cy="16" | |
r="15.9155" | |
strokeDashoffset={percentProgress} | |
/> | |
</svg> | |
<ProgressText>{`${percentProgress}%`}</ProgressText> | |
</Progress> |
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
export const Progress = styled.div` | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
svg { | |
height: 200px; | |
width: 200px; | |
transform: rotate(-90deg); | |
overflow: visible; | |
} | |
`; | |
export const ProgressSurface = styled.circle` | |
fill: none; | |
stroke: ${({ theme }) => theme.colors.canvas}; | |
stroke-width: 4; | |
`; | |
export const ProgressBar = styled.circle` | |
fill: none; | |
stroke: ${({ theme }) => theme.colors.primary}; | |
stroke-width: 4; | |
stroke-dasharray: 100 100; | |
stroke-linecap: round; | |
transition: stroke-dashoffset 1s ease-in-out; | |
`; | |
export const ProgressText = styled.div` | |
position: absolute; | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Preview: