'use client' import React, { useEffect, useRef, useState } from 'react' import styles from './styles.module.css' import { getGlobalStyle } from '../../../helpers' import { Icon } from '../../atoms' interface CircularProgressProps { size: number strokeWidth: number progress: number progressBar: string progressBorder: string progressLimit?: number } export const CircularProgress: React.FC = ({ size, strokeWidth, progress, progressBar, progressBorder, progressLimit = 100 }: CircularProgressProps) => { const progressRef = useRef(null) const [offset, setOffset] = useState(0) const center = size / 2 const radius = size / 2 - strokeWidth / 2 const circumference = 2 * Math.PI * radius const [tooltipPosition, setTooltipPosition] = useState({ x: 0, y: 0 }) const tooltipRef = useRef(null) const handleTooltipPosition = (event: { nativeEvent: { offsetX: any, offsetY: any } }): void => { const { offsetX, offsetY } = event.nativeEvent setTooltipPosition({ x: offsetX, y: offsetY }) } useEffect(() => { const limitedProgress = Math.min(progress, progressLimit) // Limitar el progreso al valor máximo const progressOffset = ((100 - limitedProgress) / 100) * circumference setOffset(progressOffset) progressRef.current.style.transition = 'stroke-dashoffset 0.5s ease-out' }, [circumference, progress, progressLimit]) return (
{progress >= progressLimit ? : `${progress}%`}
setTooltipPosition({ x: 0, y: 0 })} > = 100 ? getGlobalStyle('--color-icons-success') : progressBar} strokeWidth={strokeWidth} r={radius} cx={center} cy={center} strokeDasharray={circumference} strokeDashoffset={offset} strokeLinecap="round" /> {tooltipPosition.x !== 0 && tooltipPosition.y !== 0 && (
{progress > progressLimit ? : `${progress}%`}
)}
) }