import * as React from 'react'; import classNames from 'classnames'; import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; export interface ProgressProps { prefixCls: string; percent: number; } const viewSize = 100; const borderWidth = viewSize / 5; const radius = viewSize / 2 - borderWidth / 2; const circumference = radius * 2 * Math.PI; const position = 50; interface CircleProps { dotClassName?: string; style?: React.CSSProperties; hasCircleCls?: boolean; } const CustomCircle: React.FC> = (props) => { const { dotClassName, style, hasCircleCls } = props; return ( ); }; const Progress: React.FC> = ({ percent, prefixCls }) => { 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); // ===================== Render ===================== if (!render) { return null; } const circleStyle: React.CSSProperties = { strokeDashoffset: `${circumference / 4}`, strokeDasharray: `${(circumference * safePtg) / 100} ${ (circumference * (100 - safePtg)) / 100 }`, }; return ( ); }; export default Progress;