counter started

This commit is contained in:
Kakabay 2024-12-18 18:30:13 +05:00
parent 7b786b5953
commit 6f92f2192f
3 changed files with 84 additions and 7 deletions

View File

@ -3,6 +3,7 @@
import { Queries } from '@/api/queries'; import { Queries } from '@/api/queries';
import Loader from '@/components/Loader'; import Loader from '@/components/Loader';
import LotteryWinnersSection from '@/components/lottery/LotteryWinnersSection'; import LotteryWinnersSection from '@/components/lottery/LotteryWinnersSection';
import RollingCounter from '@/components/lottery/RollingCounter/RollingCounter';
import LotteryCountDown from '@/components/lottery/countDown/LotteryCountDown'; import LotteryCountDown from '@/components/lottery/countDown/LotteryCountDown';
import LotteryCountDownAllert from '@/components/lottery/countDown/countDownAllert/LotteryCountDownAllert'; import LotteryCountDownAllert from '@/components/lottery/countDown/countDownAllert/LotteryCountDownAllert';
import LotteryForm from '@/components/lottery/form/LotteryForm'; import LotteryForm from '@/components/lottery/form/LotteryForm';
@ -26,16 +27,18 @@ const page = () => {
.finally(() => setIsLoading(false)); .finally(() => setIsLoading(false));
}, []); }, []);
if (isLoading) { // if (isLoading) {
return ( // return (
<div className="w-full h-screen flex justify-center items-center"> // <div className="w-full h-screen flex justify-center items-center">
<Loader /> // <Loader />
</div> // </div>
); // );
} // }
return ( return (
<div className="flex flex-col md:gap-[128px] gap-[80px] font-roboto md:pt-[64px] sm:pt-[48px] pt-[40px] pb-[128px] text-lightOnSurface"> <div className="flex flex-col md:gap-[128px] gap-[80px] font-roboto md:pt-[64px] sm:pt-[48px] pt-[40px] pb-[128px] text-lightOnSurface">
<RollingCounter numberString="8134523561" />
{data && ( {data && (
<section className=""> <section className="">
<div className="container"> <div className="container">

View File

@ -252,6 +252,10 @@ big {
@apply font-roboto text-[60px] leading-[70px] -tracking-[1%]; @apply font-roboto text-[60px] leading-[70px] -tracking-[1%];
} }
.numeric-display-1 {
@apply text-[80px] leading-[88px] -tracking-[1%] text-center font-normal font-roboto;
}
.wheel-circle { .wheel-circle {
background: url('/wheel-circle.svg'); background: url('/wheel-circle.svg');
background-position: center; background-position: center;

View File

@ -0,0 +1,70 @@
'use client';
import { motion } from 'framer-motion';
import { useEffect, useState } from 'react';
interface RollingCounterProps {
numberString: string; // A 10-character string, e.g., "05-12-34-56-78"
}
const RollingCounter: React.FC<RollingCounterProps> = ({ numberString }) => {
const [rollingValues, setRollingValues] = useState<number[]>([]);
const [isStopped, setIsStopped] = useState<boolean[]>([]); // Track stopped numbers
useEffect(() => {
// Parse input string into an array of numbers, removing hyphens
const targetNumbers = numberString
.replace(/-/g, '')
.split('')
.map((char) => parseInt(char, 10));
setRollingValues(targetNumbers);
setIsStopped(new Array(targetNumbers.length).fill(false));
}, [numberString]);
const getNumbers = () => Array.from({ length: 10 }, (_, i) => i);
return (
<div className="flex items-center justify-center bg-lightPrimary text-white py-4 px-6 rounded-full">
{rollingValues.map((targetValue, index) => (
<div key={index} className="flex items-center justify-center">
{/* Container to display numbers */}
<div className="overflow-hidden h-[180px] w-[77px] relative">
<motion.div
initial={{ y: '0%' }}
animate={{ y: `-${targetValue * 10}%` }}
transition={{
duration: 0.5 + index * 0.2,
ease: 'easeInOut',
}}
onAnimationComplete={() => {
// Mark this number as stopped
setIsStopped((prev) => {
const newStatus = [...prev];
newStatus[index] = true;
return newStatus;
});
}}
className="absolute top-1/2 -translate-y-1/2 flex flex-col -mt-[52px]">
{getNumbers().map((num) => (
<div
key={num}
className={`px-4 py-2 numeric-display-1 transition-colors duration-500 ${
isStopped[index] && num === targetValue
? 'text-white' // Stopped number
: 'text-[#B0B1CD]' // Rolling numbers
}`}>
{num}
</div>
))}
</motion.div>
</div>
{/* Add a hyphen every two digits */}
{(index + 1) % 2 === 0 && index !== rollingValues.length - 1 && (
<div className="w-[32px] h-[4px] bg-lightOnPrimary mx-5"></div>
)}
</div>
))}
</div>
);
};
export default RollingCounter;