import * as React from 'react'; import classNames from 'classnames'; import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; export interface ProgressProps { prefixCls: string; percent: number; } export default function Progress({ percent, prefixCls }: ProgressProps) { const dotClassName = `${prefixCls}-dot`; const holderClassName = `${dotClassName}-holder`; const hideClassName = `${holderClassName}-hidden`; const [render, setRender] = React.useState(false); // ==================== Visible ===================== useLayoutEffect(() => { if (percent !== 0) { setRender(true); } }, [percent !== 0]); // ==================== Progress ==================== const safePtg = Math.max(Math.min(percent, 100), 0); const viewSize = 100; const borderWidth = viewSize / 5; const radius = viewSize / 2 - borderWidth / 2; const circumference = radius * 2 * Math.PI; const renderCircle = (circleClassName?: string, style?: React.CSSProperties) => ( ); // ===================== Render ===================== if (!render) { return null; } return ( {renderCircle(`${dotClassName}-circle-bg`)} {renderCircle('', { strokeDasharray: `${(circumference * safePtg) / 100} ${ (circumference * (100 - safePtg)) / 100 }`, strokeDashoffset: `${circumference / 4}`, })} ); }