Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Created August 27, 2021 21:10
Show Gist options
  • Save sebastiancarlos/ebfad356275c0b86cc8e4f0e43b33983 to your computer and use it in GitHub Desktop.
Save sebastiancarlos/ebfad356275c0b86cc8e4f0e43b33983 to your computer and use it in GitHub Desktop.
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