-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e4675
commit 9f2fb2d
Showing
4 changed files
with
88 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { useState } from 'react'; | ||
import { motion } from 'framer-motion'; | ||
|
||
interface BusinessStats { | ||
label: string; | ||
value: number; | ||
} | ||
|
||
const stats: BusinessStats[] = [ | ||
{ label: 'Clients', value: 120 }, | ||
{ label: 'Global Projects', value: 50 }, | ||
{ label: 'Satisfied Customers', value: 300 }, | ||
{ label: 'Years of Experience', value: 10 }, | ||
]; | ||
|
||
const BusinessCatalog = () => { | ||
return ( | ||
<motion.div | ||
className="grid border grid-cols-2 sm:flew-wrap md:flex text-four justify-around items-center"> | ||
{stats.map((stat) => ( | ||
<motion.div | ||
key={stat.label} | ||
variants={item} | ||
className="text-center m-4 p-4 shadow-md rounded-lg" | ||
whileInView={{ opacity: 1 }} | ||
initial={{ opacity: 0 }} | ||
viewport={{ once: true, amount: 0.5 }} // Trigger when 50% in view | ||
> | ||
<Counter targetValue={stat.value} /> | ||
<p className="text-sm">{stat.label}</p> | ||
</motion.div> | ||
))} | ||
</motion.div> | ||
); | ||
}; | ||
|
||
|
||
|
||
const Counter = ({ targetValue }: { targetValue: number }) => { | ||
const [count, setCount] = useState(0); | ||
|
||
const startCounting = () => { | ||
let currentValue = 0; | ||
const increment = Math.ceil(targetValue / 100); | ||
const interval = setInterval(() => { | ||
currentValue += increment; | ||
if (currentValue >= targetValue) { | ||
currentValue = targetValue; | ||
clearInterval(interval); | ||
} | ||
setCount(currentValue); | ||
}, 20); | ||
}; | ||
|
||
return ( | ||
<motion.h3 | ||
|
||
className="text-xl font-bold" | ||
whileInView={{ opacity: 1 }} | ||
initial={{ opacity: 0 }} | ||
viewport={{ once: true }} | ||
onViewportEnter={startCounting} | ||
> | ||
{count} | ||
</motion.h3> | ||
); | ||
}; | ||
|
||
export default BusinessCatalog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters