diff --git a/src/App.scss b/src/App.scss index eb442da..0386a36 100644 --- a/src/App.scss +++ b/src/App.scss @@ -1,7 +1,9 @@ .App { display: flex; + flex-direction: column; justify-content: center; align-items: center; + gap: 20px; width: 100%; height: 100%; } diff --git a/src/App.tsx b/src/App.tsx index 4f0cd48..2e93215 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,9 +1,11 @@ import './App.scss'; import Grid from './components/Grid/Grid'; +import Timer from './components/Timer/Timer'; const App = () => { return (
+
); diff --git a/src/assets/clock.tsx b/src/assets/clock.tsx new file mode 100644 index 0000000..912214d --- /dev/null +++ b/src/assets/clock.tsx @@ -0,0 +1,27 @@ +const Clock = (props: any) => { + return ( + + + + + ); +}; + +export default Clock; diff --git a/src/components/Timer/Timer.tsx b/src/components/Timer/Timer.tsx new file mode 100644 index 0000000..673fd21 --- /dev/null +++ b/src/components/Timer/Timer.tsx @@ -0,0 +1,42 @@ +// --------------------------------------------------------------------------------------------------------------------- +//! Imports +// --------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------ React -------------------------------------------------------- +import { useEffect, useState } from 'react'; +// --------------------------------------------------------------------------------------------------------------------- + +// ----------------------------------------------------- Assets -------------------------------------------------------- +import Clock from '../../assets/clock'; +import './styles.scss'; +// --------------------------------------------------------------------------------------------------------------------- + +const Timer = () => { + const [startedTime] = useState(Date.now()); + const [displayedTime, setDisplayedTime] = useState('00:00'); + + useEffect(() => { + const interval = setInterval(() => { + const elapsedTime = (Date.now() - startedTime) / 1000; + + const seconds = Math.floor(elapsedTime % 60); + const strSeconds = seconds < 10 ? `0${seconds}` : `${seconds}`; + + const minutes = Math.floor(elapsedTime / 60); + const strMinute = minutes < 10 ? `0${minutes}` : `${minutes}`; + + setDisplayedTime(`${strMinute}:${strSeconds}`); + }, 500); + + return () => clearInterval(interval); + }, [startedTime]); + + return ( +
+ +

{displayedTime}

+
+ ); +}; + +export default Timer; diff --git a/src/components/Timer/styles.scss b/src/components/Timer/styles.scss new file mode 100644 index 0000000..b4ff216 --- /dev/null +++ b/src/components/Timer/styles.scss @@ -0,0 +1,11 @@ +.timer { + display: grid; + grid-template-columns: 25px 40px; + align-items: center; + gap: 10px; + padding: 10px; + border-radius: 5px; + background-color: #ffdccb; + font-weight: 600; + color: #f39440; +}