import React, { memo, useEffect, useState } from "react";
const PROGRESS_MAX = 100;
const DEFAULT_PROGRESS_START = 70;
export const getProgressBarColorHexCode = (progress: number) => {
if (progress >= 90) {
return "#256FFF";
} else if (progress >= 80) {
return "#36B7FF";
} else if (progress >= 70) {
return "#00CC6A";
} else if (progress >= 60) {
return "#FFBC00";
} else if (progress >= 1) {
return "#FF455B";
} else {
return "";
}
};
const RingProgress = ({
progressEnd = 0,
size = 45,
loadingDuration = 1000, // ms
trackWidth = 10,
indicatorWidth = 10,
labelClassName = "",
}: {
progressStart?: number;
progressEnd: number;
size: number;
loadingDuration?: number;
trackWidth?: number;
indicatorWidth?: number;
labelClassName?: string;
}) => {
const isServerSide = typeof window === "undefined";
const roundedProgressEnd = Math.round(progressEnd);
const [progress, setProgress] = useState(
isServerSide
? roundedProgressEnd
: roundedProgressEnd >= DEFAULT_PROGRESS_START
? DEFAULT_PROGRESS_START
: roundedProgressEnd
);
useEffect(() => {
const loadingTimeout = setTimeout(() => {
if (progress >= roundedProgressEnd || progress >= PROGRESS_MAX) {
return;
}
setProgress(progress + 1);
}, loadingDuration / 100);
if (progress >= roundedProgressEnd || progress >= PROGRESS_MAX) {
clearTimeout(loadingTimeout);
}
return () => {
clearTimeout(loadingTimeout);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [progress]);
return (