-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathClock.tsx
More file actions
38 lines (32 loc) · 915 Bytes
/
Clock.tsx
File metadata and controls
38 lines (32 loc) · 915 Bytes
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
"use client"
import { useEffect, useState } from "react"
import {
dtNowLocaleFormatTime12hAmPm,
} from "@/lib/datetimeUtils"
export default function Clock({ darkMode = false }: { darkMode?: boolean }) {
const [time, setTime] = useState(getCurrentTimeFormatted())
useEffect(() => {
const interval = setInterval(() => {
setTime(getCurrentTimeFormatted())
}, 1000)
return () => clearInterval(interval)
}, [])
function getCurrentTimeFormatted() {
return dtNowLocaleFormatTime12hAmPm()
}
return (
<div
className={`${
!darkMode ? "bg-mosqueBrand-onPrimary" : ""
} p-7 2k:px-[1.5vw] 2k:py-[1.5vh] text-center md:text-left md:w-fit`}
>
<time
className={`text-5xl md:text-8xl 2k:text-10xl 4k:text-12xl font-bold ${
!darkMode ? "text-mosqueBrand" : "text-gray-500"
}`}
>
{time}
</time>
</div>
)
}