11import { useLocale } from "@/locales" ;
22import { useEffect , useState } from "react" ;
33
4- function TimeUnit ( { time, timeString, index = 0 } : { time : number ; timeString : string , index ?: number } ) {
5- // "w-1/2 max-auto bg-cerise py-2.5 rounded-full"
6- return (
7- < div className = { `w-16 h-32 sm:w-24 sm:h-48
8- flex flex-col bg-cover bg-16
9- ${
10- index == 2 && "bg-[url('/img/ballonger/ballong_2.svg')]"
11- ||
12- index == 3 && "bg-[url('/img/ballonger/ballong_3.svg')]"
13- ||
14- index == 4 && "bg-[url('/img/ballonger/ballong_4.svg')]"
15- ||
16- "bg-[url('/img/ballonger/ballong_1.svg')]"
17- } `} >
18-
19- < div className = "w-16 h-20 sm:w-24 sm:h-[7.75rem]
20- flex flex-col items-center justify-center" >
21- < div className = "text-white text-xl sm:text-4xl leading-[1.25rem] sm:leading-[1.75rem] text-center" >
22- { time }
23- </ div >
24- < div className = "text-white text-xs sm:text-lg text-center" >
25- { timeString }
26- </ div >
27- </ div >
28-
29- </ div >
30-
31-
4+ function TimeUnit ( { time, timeString, } : { time : number ; timeString : string ; } ) {
5+ return (
6+ < div className = "flex flex-col items-center text-center" >
7+ < div className = "text-white text-3xl sm:text-4xl leading-none" >
8+ { time }
9+ </ div >
10+ < div className = "text-white text-sm sm:text-lg mt-1" >
11+ { timeString }
12+ </ div >
13+ </ div >
3214 ) ;
3315}
3416
@@ -40,38 +22,46 @@ export function Countdown() {
4022 const [ minutes , setMinutes ] = useState ( 0 ) ;
4123 const [ seconds , setSeconds ] = useState ( 0 ) ;
4224
43- useEffect ( ( ) => {
44- const target = new Date ( "10/8/2026 10:00:00+02:00" ) // vilket datum är d-dagen?
45- const interval = setInterval ( ( ) => {
25+ useEffect ( ( ) => {
26+ const target = new Date ( "10/8/2026 10:00:00+02:00" ) ;
27+ const interval = setInterval ( ( ) => {
4628 const now = new Date ( ) ;
4729 const difference = target . getTime ( ) - now . getTime ( ) ;
48-
49-
30+
5031 const d_diff = difference / ( 1000 * 60 * 60 * 24 ) ;
51- const d = difference < 0 ? Math . ceil ( d_diff ) : Math . floor ( d_diff ) ;
52- setDays ( d )
32+ setDays ( difference < 0 ? Math . ceil ( d_diff ) : Math . floor ( d_diff ) ) ;
33+
34+ const h_diff =
35+ ( difference % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ;
36+ setHours ( difference < 0 ? Math . ceil ( h_diff ) : Math . floor ( h_diff ) ) ;
5337
54- const h_diff = ( difference % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 )
55- const h = difference < 0 ? Math . ceil ( h_diff ) : Math . floor ( h_diff ) ;
56- setHours ( h )
38+ const m_diff = ( difference % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) ;
39+ setMinutes ( difference < 0 ? Math . ceil ( m_diff ) : Math . floor ( m_diff ) ) ;
5740
58- const m_diff = ( difference % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 )
59- const m = difference < 0 ? Math . ceil ( m_diff ) : Math . floor ( m_diff )
60- setMinutes ( m )
41+ const s_diff = ( difference % ( 1000 * 60 ) ) / 1000 ;
42+ setSeconds ( difference < 0 ? Math . ceil ( s_diff ) : Math . floor ( s_diff ) ) ;
43+ } , 1000 ) ;
6144
62- const s_diff = ( difference % ( 1000 * 60 ) ) / 1000
63- const s = difference < 0 ? Math . ceil ( s_diff ) : Math . floor ( s_diff )
64- setSeconds ( s )
65- } , 1000 )
66- return ( ) => clearInterval ( interval )
67- } , [ ] ) ;
45+ return ( ) => clearInterval ( interval ) ;
46+ } , [ ] ) ;
6847
6948 return (
70- < div className = "hover:cursor-default gap-5 columns-4 flex items-center justify-center" >
71- < TimeUnit time = { days } timeString = { t . home . countDown . days } index = { 1 } />
72- < TimeUnit time = { hours } timeString = { t . home . countDown . hours } index = { 2 } />
73- < TimeUnit time = { minutes } timeString = { t . home . countDown . minutes } index = { 3 } />
74- < TimeUnit time = { seconds } timeString = { t . home . countDown . seconds } index = { 4 } />
49+ < div className = "hover:cursor-default flex items-center justify-center" >
50+
51+ < TimeUnit time = { days } timeString = { t . home . countDown . days } />
52+
53+ < div className = "mx-6 h-14 w-[3px] bg-cerise" />
54+
55+ < TimeUnit time = { hours } timeString = { t . home . countDown . hours } />
56+
57+ < div className = "mx-6 h-14 w-[3px] bg-cerise" />
58+
59+ < TimeUnit time = { minutes } timeString = { t . home . countDown . minutes } />
60+
61+ < div className = "mx-6 h-14 w-[3px] bg-cerise" />
62+
63+ < TimeUnit time = { seconds } timeString = { t . home . countDown . seconds } />
64+
7565 </ div >
7666 ) ;
7767}
0 commit comments