Spaces:
Running
Running
File size: 1,625 Bytes
2c27cf6 | 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 | import { useEffect, useState } from 'react'
const stats = [
{ value: 500, suffix: '+', label: 'Happy Clients' },
{ value: 99.9, suffix: '%', label: 'Uptime Guarantee' },
{ value: 150, suffix: 'M+', label: 'API Requests/Day' },
{ value: 24, suffix: '/7', label: 'Expert Support' }
]
export default function Stats() {
const [counts, setCounts] = useState(stats.map(() => 0))
useEffect(() => {
const duration = 2000
const steps = 60
const increment = stats.map(stat => stat.value / steps)
let step = 0
const timer = setInterval(() => {
step++
setCounts(prev => prev.map((count, i) => {
if (step >= steps) return stats[i].value
return Math.min(count + increment[i], stats[i].value)
}))
if (step >= steps) clearInterval(timer)
}, duration / steps)
return () => clearInterval(timer)
}, [])
return (
<section id="stats" className="py-20 px-4">
<div className="container mx-auto">
<div className="bg-gradient-to-r from-primary-600/20 to-primary-800/20 border border-primary-500/20 rounded-2xl p-8 lg:p-12">
<div className="grid grid-cols-2 lg:grid-cols-4 gap-8">
{stats.map((stat, index) => (
<div key={index} className="text-center">
<p className="text-4xl lg:text-5xl font-bold gradient-text mb-2">
{counts[index].toFixed(index === 1 ? 1 : 0)}{stat.suffix}
</p>
<p className="text-dark-300">{stat.label}</p>
</div>
))}
</div>
</div>
</div>
</section>
)
} |