import React from 'react'; import { getWebProps } from 'react-native-unistyles/web'; import { progressStyles } from './Progress.styles'; import type { ProgressProps } from './types'; /** * Visual indicator for task completion or loading status. * Supports linear and circular types with determinate or indeterminate states. */ const Progress: React.FC = ({ value = 0, max = 100, type = 'linear', intent = 'primary', size = 'md', indeterminate = false, showLabel = false, label, rounded = true, style, testID, id, }) => { const percentage = Math.min(Math.max((value / max) * 100, 0), 100); // Apply variants (for size, intent, and rounded) progressStyles.useVariants({ size, intent, rounded, }); // Linear progress const containerProps = getWebProps([progressStyles.container as any, style as any]); const trackProps = getWebProps([progressStyles.linearTrack as any]); const barProps = getWebProps([progressStyles.linearBar as any, { width: `${percentage}%` }]); const indeterminateProps = getWebProps([progressStyles.indeterminateBar as any]); const labelProps = getWebProps([progressStyles.label as any]); const getCircularSize = () => { if (size === 'sm') return 32; if (size === 'lg') return 64; return 48; }; if (type === 'circular') { const circularSize = getCircularSize(); const strokeWidth = size === 'sm' ? 3 : size === 'lg' ? 5 : 4; const radius = (circularSize - strokeWidth) / 2; const circumference = radius * 2 * Math.PI; const strokeDashoffset = indeterminate ? circumference * 0.25 : circumference - (percentage / 100) * circumference; const computedContainerProps = getWebProps([ progressStyles.circularContainer as any, style as any, { display: 'inline-flex' } ]); const circularLabelProps = getWebProps([progressStyles.circularLabel as any]); const trackColorProps = getWebProps([progressStyles.circularTrack as any]); const barColorProps = getWebProps([progressStyles.circularBar as any]); return (
{/* Track circle (background) */} {/* Progress circle (foreground) - apply the className to get intent color */} {showLabel && ( {label || `${Math.round(percentage)}%`} )}
); } return ( <>
{indeterminate ? (
) : (
)}
{showLabel && ( {label || `${Math.round(percentage)}%`} )}
{indeterminate && ( )} ); }; export default Progress;