Spaces:
Running
Running
File size: 2,918 Bytes
d96d2a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import React, { useState, useEffect } from 'react';
import { CheckCircle2, Loader2, Circle } from 'lucide-react';
const AIProcessingSteps = ({ steps = [], onComplete, delay = 1200, activeStep = null }) => {
const [internalStep, setInternalStep] = useState(0);
const currentStep = activeStep !== null ? activeStep : internalStep;
useEffect(() => {
if (activeStep !== null) return; // Disable internal timer if controlled externally
if (internalStep < steps.length) {
const timer = setTimeout(() => {
setInternalStep(prev => prev + 1);
}, delay);
return () => clearTimeout(timer);
} else if (internalStep === steps.length) {
if (onComplete) {
const timer = setTimeout(() => {
onComplete();
}, 800);
return () => clearTimeout(timer);
}
}
}, [currentStep, steps.length, delay, onComplete]);
const progressPercentage = Math.min((currentStep / steps.length) * 100, 100);
return (
<>
<div className="w-full space-y-5 px-2">
{steps.map((step, index) => {
const isCompleted = currentStep > index;
const isActive = currentStep === index;
const isPending = currentStep < index;
return (
<div key={index} className={`flex items-center gap-4 transition-all duration-500 ${isPending ? 'opacity-40' : 'opacity-100'}`}>
<div className="flex-shrink-0 relative flex items-center justify-center w-6 h-6">
{isCompleted ? (
<CheckCircle2 className="w-5 h-5 text-emerald-500 transition-all duration-500 scale-100" />
) : isActive ? (
<Loader2 className="w-5 h-5 text-emerald-600 animate-spin" />
) : (
<Circle className="w-5 h-5 text-gray-300" />
)}
</div>
<span className={`text-sm font-semibold transition-colors duration-300 ${isCompleted ? 'text-gray-900' : isActive ? 'text-emerald-700' : 'text-gray-500'}`}>
{step}
</span>
</div>
);
})}
</div>
{/* Progress Bar */}
<div className="w-full h-1.5 bg-gray-50 absolute bottom-0 left-0">
<div
className="h-full bg-emerald-500 transition-all duration-700 ease-out"
style={{ width: `${progressPercentage}%` }}
></div>
</div>
</>
);
};
export default AIProcessingSteps;
|