Created
August 27, 2021 21:10
-
-
Save sebastiancarlos/ebfad356275c0b86cc8e4f0e43b33983 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
import { useEffect, useRef } from "react"; | |
// Render an SVG Circle Progress set to the provided progress percentage. | |
export const CircleProgress = ({ progress = 0 }) => { | |
const pieElement = useRef(null); | |
// Update SVG every time the progress prop changes. | |
useEffect(() => { | |
pieElement.current.style.setProperty("--progress", progress); | |
}, [progress]); | |
return ( | |
<svg width="50" height="50" viewBox="0 0 100 100"> | |
<circle r="50" cx="50" cy="50" className="pie-background" /> | |
<circle | |
ref={pieElement} | |
r="25" | |
cx="50" | |
cy="50" | |
transform="rotate(-90) translate(-100)" | |
className="pie" | |
/> | |
</svg> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment