Skip to content

Commit 6fcb2d1

Browse files
committed
feat: clock face
1 parent c138a18 commit 6fcb2d1

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, { useEffect, useState } from 'react'
2+
3+
const ClockFace = () => {
4+
const [hours, setHours] = useState('00')
5+
const [minutes, setMinutes] = useState('00')
6+
const [seconds, setSeconds] = useState('00')
7+
const [amPm, setAmPm] = useState('AM')
8+
9+
useEffect(() => {
10+
const updateClock = () => {
11+
const currentTime = new Date()
12+
let hrs = currentTime.getHours()
13+
const mins = currentTime.getMinutes()
14+
const secs = currentTime.getSeconds()
15+
16+
setHours(`${hrs < 10 ? '0' : ''}${hrs > 12 ? hrs - 12 : hrs}`)
17+
setMinutes(`${mins < 10 ? '0' : ''}${mins}`)
18+
setSeconds(`${secs < 10 ? '0' : ''}${secs}`)
19+
setAmPm(hrs < 12 ? 'AM' : 'PM')
20+
}
21+
22+
updateClock()
23+
const interval = setInterval(updateClock, 1000)
24+
25+
return () => clearInterval(interval)
26+
}, [])
27+
28+
return (
29+
<div className="flex items-center justify-center">
30+
<div className="flex items-center justify-center pr-[10px]">
31+
<span className="text-center text-4xl font-bold">
32+
{hours}
33+
<span className="font-mono text-4xl font-bold">:</span>
34+
</span>
35+
<span className="text-center text-4xl font-bold">
36+
{minutes}
37+
<span className="font-mono text-4xl font-bold">:</span>
38+
</span>
39+
<span className="text-center text-4xl font-bold">{seconds}</span>
40+
<span className="mt-5 ml-3 font-sans text-xl font-bold">{amPm}</span>
41+
</div>
42+
</div>
43+
)
44+
}
45+
46+
export default ClockFace

src/pages/layout/proContent/index.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Layout, FloatButton, theme, Space } from 'antd'
33
import { useLocation } from 'react-router-dom'
44
import { VerticalAlignTopOutlined } from '@ant-design/icons'
55
import { getKeyName } from '@utils/publicFn'
6-
import { useProTabContext } from '@src/components/hooks/proTabsContext'
6+
import { useProTabContext } from '@hooks/proTabsContext'
7+
import ClockFace from '@stateless/ClockFace'
78
import ProBreadcrumb from './breadcrumb'
89
import ProTabs from '../proTabs'
910
import styles from './index.module.less'
@@ -47,7 +48,10 @@ const ProContent = () => {
4748
return (
4849
<Layout className={styles.layout} id="fullScreen">
4950
<Header className="layout-header" style={{ background: colorBgLayout }}>
50-
<ProBreadcrumb />
51+
<section className="flex items-center justify-between">
52+
<ProBreadcrumb />
53+
<ClockFace />
54+
</section>
5155
</Header>
5256
<Content className="layout-content" id="fullScreenContent" style={{ background: colorBgContainer }}>
5357
<ProTabs panesItem={panesItem} tabActiveKey={tabActiveKey} />

0 commit comments

Comments
 (0)