|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { useEffect, useState } from "react" |
| 4 | + |
| 5 | +import { cn } from "@/lib/utils/cn" |
| 6 | + |
| 7 | +interface CountDownProps { |
| 8 | + className?: string |
| 9 | +} |
| 10 | + |
| 11 | +const CountDown = ({ className }: CountDownProps) => { |
| 12 | + const [timeLeft, setTimeLeft] = useState({ |
| 13 | + days: 0, |
| 14 | + hours: 0, |
| 15 | + minutes: 0, |
| 16 | + seconds: 0, |
| 17 | + }) |
| 18 | + const [isExpired, setIsExpired] = useState(false) |
| 19 | + |
| 20 | + useEffect(() => { |
| 21 | + const targetDate = new Date("2025-07-30T15:44:00Z") |
| 22 | + |
| 23 | + const calculateTimeLeft = () => { |
| 24 | + const now = new Date() |
| 25 | + const difference = targetDate.getTime() - now.getTime() |
| 26 | + |
| 27 | + if (difference > 0) { |
| 28 | + setIsExpired(false) |
| 29 | + setTimeLeft({ |
| 30 | + days: Math.floor(difference / (1000 * 60 * 60 * 24)), |
| 31 | + hours: Math.floor((difference / (1000 * 60 * 60)) % 24), |
| 32 | + minutes: Math.floor((difference / 1000 / 60) % 60), |
| 33 | + seconds: Math.floor((difference / 1000) % 60), |
| 34 | + }) |
| 35 | + } else { |
| 36 | + setIsExpired(true) |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + calculateTimeLeft() |
| 41 | + |
| 42 | + // Update every second |
| 43 | + const timer = setInterval(calculateTimeLeft, 1000) |
| 44 | + |
| 45 | + return () => clearInterval(timer) |
| 46 | + }, []) |
| 47 | + |
| 48 | + if (isExpired) { |
| 49 | + return ( |
| 50 | + <div className="text-center text-2xl font-bold"> |
| 51 | + Ethereum is 10 years old! 🚀 |
| 52 | + </div> |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + return ( |
| 57 | + <div className="flex items-center justify-center gap-10"> |
| 58 | + <div |
| 59 | + className={cn( |
| 60 | + "flex h-20 w-20 flex-col items-center justify-center rounded-2xl border text-center [box-shadow:-2.372px_2.372px_14.234px_1.186px_rgba(52,43,64,0.02),-18.979px_18.979px_14.234px_-3.559px_rgba(52,43,64,0.02),-37.958px_37.958px_28.469px_-7.117px_rgba(52,43,64,0.02),-47.448px_47.448px_47.448px_-14.234px_rgba(88,55,131,0.04)] dark:bg-[#171717]", |
| 61 | + className |
| 62 | + )} |
| 63 | + > |
| 64 | + <div className="font-mono text-4xl font-bold text-accent-a"> |
| 65 | + {timeLeft.days} |
| 66 | + </div> |
| 67 | + <div className="font-mono text-xs text-accent-a">days</div> |
| 68 | + </div> |
| 69 | + <div |
| 70 | + className={cn( |
| 71 | + "flex h-20 w-20 flex-col items-center justify-center rounded-2xl border text-center [box-shadow:-2.372px_2.372px_14.234px_1.186px_rgba(52,43,64,0.02),-18.979px_18.979px_14.234px_-3.559px_rgba(52,43,64,0.02),-37.958px_37.958px_28.469px_-7.117px_rgba(52,43,64,0.02),-47.448px_47.448px_47.448px_-14.234px_rgba(88,55,131,0.04)] dark:bg-[#171717]", |
| 72 | + className |
| 73 | + )} |
| 74 | + > |
| 75 | + <div className="font-mono text-4xl font-bold text-accent-a"> |
| 76 | + {timeLeft.hours} |
| 77 | + </div> |
| 78 | + <div className="font-mono text-xs text-accent-a">hours</div> |
| 79 | + </div> |
| 80 | + <div |
| 81 | + className={cn( |
| 82 | + "flex h-20 w-20 flex-col items-center justify-center rounded-2xl border text-center [box-shadow:-2.372px_2.372px_14.234px_1.186px_rgba(52,43,64,0.02),-18.979px_18.979px_14.234px_-3.559px_rgba(52,43,64,0.02),-37.958px_37.958px_28.469px_-7.117px_rgba(52,43,64,0.02),-47.448px_47.448px_47.448px_-14.234px_rgba(88,55,131,0.04)] dark:bg-[#171717]", |
| 83 | + className |
| 84 | + )} |
| 85 | + > |
| 86 | + <div className="font-mono text-4xl font-bold text-accent-a"> |
| 87 | + {timeLeft.minutes} |
| 88 | + </div> |
| 89 | + <div className="font-mono text-xs text-accent-a">minutes</div> |
| 90 | + </div> |
| 91 | + <div |
| 92 | + className={cn( |
| 93 | + "hidden h-20 w-20 flex-col items-center justify-center rounded-2xl border text-center [box-shadow:-2.372px_2.372px_14.234px_1.186px_rgba(52,43,64,0.02),-18.979px_18.979px_14.234px_-3.559px_rgba(52,43,64,0.02),-37.958px_37.958px_28.469px_-7.117px_rgba(52,43,64,0.02),-47.448px_47.448px_47.448px_-14.234px_rgba(88,55,131,0.04)] lg:flex dark:bg-[#171717]", |
| 94 | + className |
| 95 | + )} |
| 96 | + > |
| 97 | + <div className="font-mono text-4xl font-bold text-accent-a"> |
| 98 | + {timeLeft.seconds} |
| 99 | + </div> |
| 100 | + <div className="font-mono text-xs text-accent-a">seconds</div> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + ) |
| 104 | +} |
| 105 | + |
| 106 | +export default CountDown |
0 commit comments