incr/resources/js/components/Display/ProgressBar.tsx

65 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-07-12 19:59:22 +02:00
import { cn } from '@/lib/utils';
2025-07-13 00:30:19 +02:00
interface Milestone {
target: number;
description: string;
created_at: string;
}
2025-07-12 19:59:22 +02:00
interface ProgressBarProps {
2025-07-13 00:30:19 +02:00
currentShares: number;
milestones: Milestone[];
2025-07-12 19:59:22 +02:00
className?: string;
onClick?: () => void;
}
export default function ProgressBar({
2025-07-13 00:30:19 +02:00
currentShares,
milestones,
2025-07-12 19:59:22 +02:00
className,
onClick
}: ProgressBarProps) {
2025-07-13 00:30:19 +02:00
// Get the first milestone (lowest target) for progress calculation
const firstMilestone = milestones.length > 0 ? milestones[0] : null;
// Calculate progress percentage
const progressPercentage = firstMilestone
? Math.min((currentShares / firstMilestone.target) * 100, 100)
: 0;
2025-07-12 19:59:22 +02:00
return (
<div
className={cn(
2025-07-13 00:30:19 +02:00
"bg-black cursor-pointer",
2025-07-12 19:59:22 +02:00
"transition-all duration-300",
2025-07-13 00:30:19 +02:00
"p-8",
2025-07-12 19:59:22 +02:00
className
)}
onClick={onClick}
>
2025-07-13 00:30:19 +02:00
{/* Progress Bar Container */}
<div className="w-full">
{/* Old-school progress bar with overlaid text */}
<div className="w-full border-4 border-red-500 p-2 bg-black relative overflow-hidden">
{/* Inner container */}
<div className="relative h-8">
{/* Progress fill */}
<div
className="absolute top-0 left-0 h-full bg-red-500 transition-all duration-500 ease-out"
style={{ width: `${progressPercentage}%` }}
/>
{/* Text overlay */}
{firstMilestone && (
<div className="relative h-full flex items-center justify-center">
{/* Base text (red on black background) */}
<div className="text-red-500 font-mono text-sm font-bold mix-blend-difference relative z-10">
{progressPercentage.toFixed(1)}%
</div>
</div>
)}
</div>
</div>
2025-07-12 19:59:22 +02:00
</div>
</div>
);
}