-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and extract race clock component
- Loading branch information
1 parent
f8fe803
commit 24842ae
Showing
5 changed files
with
127 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.racetimer { | ||
z-index: 1; | ||
cursor: pointer; | ||
align-self: flex-start; | ||
background: var(--black10-color); | ||
font-size: 7rem; | ||
padding: 0.25em; | ||
width: 100vw; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: flex-start; | ||
border-top: 2px solid black; | ||
} | ||
|
||
.racetimer_unlit { | ||
color: var(--darkorange-color); | ||
text-align: center; | ||
} | ||
|
||
.racetimer_unlit_sss { | ||
font-size: 0.66em; | ||
color: var(--darkorange-color); | ||
text-align: center; | ||
} | ||
|
||
.racetimer_lit { | ||
color: var(--neonorange-color); | ||
text-shadow: 0 0 3px white, 0 0 12px var(--neonorange-color), | ||
0 0 48px var(--neonorange-color); | ||
text-align: center; | ||
} | ||
|
||
.racetimer_lit_sss { | ||
font-size: 0.66em; | ||
color: var(--neonorange-color); | ||
text-shadow: 0 0 3px white, 0 0 12px var(--neonorange-color), | ||
0 0 48px var(--neonorange-color); | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import styles from "./RaceClock.module.css"; | ||
|
||
interface ReactClockProps { | ||
isRaceReady: boolean; | ||
minutes: number; | ||
seconds: number; | ||
ms: number; | ||
onClick: (event: any) => void; | ||
} | ||
|
||
const resetClockRaceOff = ["0:00", "", ".00", ""]; | ||
const resetClockRaceOn = ["0:0", "0", "", ".00"]; | ||
const getDisplayParts = ( | ||
isRaceReady: boolean, | ||
minutes: number, | ||
seconds: number, | ||
ms: number | ||
) => { | ||
if (minutes === 0 && seconds === 0 && ms === 0) { | ||
return isRaceReady ? resetClockRaceOn : resetClockRaceOff; | ||
} | ||
|
||
let unlit = ""; | ||
let unlitMs = ""; | ||
let lit = ""; | ||
let litMs = ""; | ||
ms = Math.floor(ms / 10); | ||
|
||
if (minutes === 0) { | ||
if (seconds < 10) { | ||
unlit = "0:0"; | ||
lit = seconds.toString(); | ||
} else { | ||
unlit = "0:"; | ||
lit = seconds.toString(); | ||
} | ||
} else { | ||
lit = `${minutes}:${seconds.toString().padStart(2, "0")}`; | ||
} | ||
litMs = `.${ms.toString().padStart(2, "0")}`; | ||
|
||
return [unlit, lit, unlitMs, litMs]; | ||
}; | ||
|
||
export const RaceClock: React.FC<ReactClockProps> = ({ | ||
isRaceReady, | ||
minutes, | ||
seconds, | ||
ms, | ||
onClick, | ||
}) => { | ||
const [displayUnlit, displayLit, displayUnlitMs, displayLitMs] = | ||
getDisplayParts(isRaceReady, minutes, seconds, ms); | ||
|
||
return ( | ||
<div className={styles.racetimer} onClick={onClick}> | ||
<span className={styles.racetimer_unlit}>{displayUnlit}</span> | ||
<span className={styles.racetimer_lit}>{displayLit}</span> | ||
<span className={styles.racetimer_unlit_sss}>{displayUnlitMs}</span> | ||
<span className={styles.racetimer_lit_sss}>{displayLitMs}</span> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { RaceClock } from "./RaceClock/RaceClock"; | ||
import { RaceTree } from "./RaceTree/RaceTree"; | ||
import { | ||
RaceTreeLight, | ||
RaceTreeLightColor, | ||
} from "./RaceTreeLight/RaceTreeLight"; | ||
|
||
export { RaceTree, RaceTreeLight, RaceTreeLightColor }; | ||
export { RaceClock, RaceTree, RaceTreeLight, RaceTreeLightColor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters