import React, { useEffect, useRef } from "react"; const CircularProgressIndicator = ({ value, color }) => { const svgRef = useRef(null); useEffect(() => { if (!svgRef.current) return; // Получаем элемент SVG const svg = svgRef.current; const circle = svg.querySelector("circle"); // Рассчитываем длину окружности const circumference = circle.getAttribute("r") * 2 * Math.PI; // Устанавливаем начальное значение (0%) circle.style.strokeDasharray = `${circumference} ${circumference}`; circle.style.strokeDashoffset = circumference; // Анимируем заполнение setTimeout(() => { const offset = circumference - (value / 100) * circumference; circle.style.transition = "stroke-dashoffset 500ms ease-in-out"; circle.style.strokeDashoffset = offset; }, 0); }, [value]); console.log(color) switch(color){ case "green": color = "#1eeb07" break; case "red": color = "#fc4a03" break; case "yellow": color = "#f0fc03" break; case "orange": color = "#ff9f43" break; } return (
{/* SVG для кругового прогресс-бара */} {/* Текст в центре круга */}
{value}
%
); }; export default CircularProgressIndicator;