diff --git a/src/app/pages/ColorGame/ColorGame.jsx b/src/app/pages/ColorGame/ColorGame.jsx index c9d3db4a..4f58bb92 100644 --- a/src/app/pages/ColorGame/ColorGame.jsx +++ b/src/app/pages/ColorGame/ColorGame.jsx @@ -9,6 +9,7 @@ import { } from "./components/HexColorInput/HexColorInput"; import { Results } from "./components/Results/Results"; import Auto from "react-animate-height"; +import { Instructions } from "./components/Instructions/Instructions"; const generateRandomHexString = () => { const randomHex = []; @@ -24,6 +25,7 @@ export const ColorGame = memo(function ColorGame() { const [color, setColor] = useState(generateRandomHexString); const [report, setReport] = useState(); const [height, setHeight] = useState("auto"); + const contentRef = useRef(null); const resetColor = useCallback( () => setColor(generateRandomHexString()), @@ -41,7 +43,6 @@ export const ColorGame = memo(function ColorGame() { return () => resizeObserver.disconnect(); }, []); - const contentRef = useRef(null); return (
@@ -72,6 +73,7 @@ export const ColorGame = memo(function ColorGame() { {report && } +
); }); diff --git a/src/app/pages/ColorGame/ColorGame.module.scss b/src/app/pages/ColorGame/ColorGame.module.scss index 2c0be4b8..e2aaa710 100644 --- a/src/app/pages/ColorGame/ColorGame.module.scss +++ b/src/app/pages/ColorGame/ColorGame.module.scss @@ -12,7 +12,7 @@ gap: 20px; margin: 0 auto; - padding: 20px; + padding: 20px 20px 80px; box-sizing: border-box; @@ -31,6 +31,7 @@ width: 200px; border-radius: 8px; margin-bottom: 0px; + transition: width 250ms; } @media screen and (max-width: 900px) { diff --git a/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.jsx b/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.jsx index b5d7705f..2a89dbd7 100644 --- a/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.jsx +++ b/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.jsx @@ -1,4 +1,4 @@ -import { createRef, memo, useMemo, useState } from "react"; +import { createRef, memo, useEffect, useMemo, useState } from "react"; import cn from "./HexColorInput.module.scss"; import clsx from "clsx"; import { generateReport } from "./generateReport"; @@ -36,10 +36,15 @@ export const HexColorInput = memo(function HexColorInput({ resetColor, }) { const [guess, setGuess] = useState(EMPTY_GUESS); + const [showErrorMessage, setErrorMessage] = useState(false); const [input] = useState(() => Array.from({ length: 6 }, createRef)); const guessIsValid = useMemo(() => guess.join("").length === 6, [guess]); + useEffect(() => { + if (showErrorMessage) setTimeout(() => setErrorMessage(false), 2500); + }, [showErrorMessage]); + const ignoreEvent = (event) => { event.preventDefault(); }; @@ -61,7 +66,7 @@ export const HexColorInput = memo(function HexColorInput({ const handleInput = (index) => (event) => { const userKeyInput = event.nativeEvent.data.toUpperCase(); - if (!DIGITS.includes(userKeyInput)) return; + if (!DIGITS.includes(userKeyInput)) return setErrorMessage(true); setGuess((prev) => { const next = [...prev]; @@ -96,7 +101,7 @@ export const HexColorInput = memo(function HexColorInput({ return; case "ArrowRight": - if (index > 5) return; + if (index > 4) return; focusEndOfInput(input[index + 1].current); return; @@ -144,6 +149,9 @@ export const HexColorInput = memo(function HexColorInput({ refresh +
+ Only 0-9 and A-F are valid hex values. +
); }); diff --git a/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.module.scss b/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.module.scss index bb71bf4f..c34d0c61 100644 --- a/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.module.scss +++ b/src/app/pages/ColorGame/components/HexColorInput/HexColorInput.module.scss @@ -4,6 +4,7 @@ grid-template-columns: auto auto; gap: 20px; min-width: 600px; + transition: width 250ms; @media screen and (max-width: 1000px) { grid-template-columns: auto; @@ -16,7 +17,7 @@ } } - + .actions { display: grid; grid-template-columns: auto auto; @@ -27,7 +28,7 @@ display: grid; grid-template-columns: repeat(7, 32px); gap: 8px; - + input { border: none; border-bottom: 2px solid var(--gray); @@ -37,15 +38,15 @@ &::placeholder { opacity: 0.1; } - + &.underline { color: var(--gray); border: none; } } } - - button{ + + button { border: 2px solid var(--silver); padding: 0 20px; border-radius: 8px; @@ -57,12 +58,12 @@ color: var(--silver); font-weight: bold; cursor: not-allowed; - + &.allowed { color: var(--green); border-color: var(--green); cursor: pointer; - + &:hover { background-color: var(--green); color: var(--white); @@ -84,4 +85,26 @@ } } -} + + .error { + display: grid; + grid-column: 1 / 3; + color: transparent; + + transition: color 250ms; + font-size: 0.9em; + text-align: center; + + height: 0; + overflow: visible; + + &.visible { + color: var(--red); + } + + @media screen and (max-width: 1000px) { + height: auto; + grid-column: 1/ 2; + } + } +} \ No newline at end of file diff --git a/src/app/pages/ColorGame/components/Instructions/Instructions.jsx b/src/app/pages/ColorGame/components/Instructions/Instructions.jsx new file mode 100644 index 00000000..4a141ef0 --- /dev/null +++ b/src/app/pages/ColorGame/components/Instructions/Instructions.jsx @@ -0,0 +1,33 @@ +import clsx from "clsx"; +import { memo, useRef } from "react"; +import cn from "./Instructions.module.scss"; +import { Text } from "app/components"; +import COLOR_BREAKDOWN from "./breakdown.png"; + +export const Instructions = memo(function Instructions() { + return ( +
+
+ + How to play + +
+

+ Hex colors are made up of 6 hexadecimal characters (hexadecimals + are numbers that go from 0-9, A, B, C, D, E, F, rather than just + 0-9 in our normal decimal system) and are split into 3 sections: + Red, Green and Blue - commonly known as RGB. +

+ color hex code with individual groups color coded with highlights +

+ Each hex color is essentially a blend of these three primary + colors. Compared to traditional print (CYMK), adding more of + each color makes the overall color brighter so #FFFFFF would be + white and #000000 would be black. +

+
+ ); +}); diff --git a/src/app/pages/ColorGame/components/Instructions/Instructions.module.scss b/src/app/pages/ColorGame/components/Instructions/Instructions.module.scss new file mode 100644 index 00000000..12921d2e --- /dev/null +++ b/src/app/pages/ColorGame/components/Instructions/Instructions.module.scss @@ -0,0 +1,32 @@ +.container { + padding: 20px; + border: 2px solid var(--silver); + border-radius: 18px; + // width: min-content; + + .header { + display: grid; + grid-template-columns: 1fr auto; + width: 100%; + } + + p { + margin: 20px 0; + line-height: 1.3em; + width: fit-content; + font-size: 1.3em; + + @media screen and (max-width: 1000px) { + font-size: 1em; + } + + } + img { + margin: 0 auto; + max-height: 200px; + + @media screen and (max-width: 1000px) { + max-height: 100px; + } + } +} \ No newline at end of file diff --git a/src/app/pages/ColorGame/components/Instructions/breakdown.png b/src/app/pages/ColorGame/components/Instructions/breakdown.png new file mode 100644 index 00000000..79d55061 Binary files /dev/null and b/src/app/pages/ColorGame/components/Instructions/breakdown.png differ diff --git a/src/app/pages/ColorGame/components/Instructions/transformation.png b/src/app/pages/ColorGame/components/Instructions/transformation.png new file mode 100644 index 00000000..85a5f873 Binary files /dev/null and b/src/app/pages/ColorGame/components/Instructions/transformation.png differ diff --git a/src/app/pages/ColorGame/components/Leaderboard/Leaderboard.jsx b/src/app/pages/ColorGame/components/Leaderboard/Leaderboard.jsx index 0d395f07..2e209325 100644 --- a/src/app/pages/ColorGame/components/Leaderboard/Leaderboard.jsx +++ b/src/app/pages/ColorGame/components/Leaderboard/Leaderboard.jsx @@ -6,7 +6,7 @@ import Auto from "react-animate-height"; import { Text } from "app/components"; import { ScoreItem } from "./components/ScoreItem"; -const PADDING = 40; +const PADDING = 16; const HIGHSCORE_LOCALSTORAGE_KEY = "@duci/color-game-highscore"; export const Leaderboard = memo(function Leaderboard({ report }) { @@ -45,16 +45,12 @@ export const Leaderboard = memo(function Leaderboard({ report }) { }, []); return ( - -
- - High Scores - -
+
+ + High Scores + + +
{!highscores.length && (
No previous scores to show. @@ -64,7 +60,7 @@ export const Leaderboard = memo(function Leaderboard({ report }) { ))}
-
-
+ +
); }); diff --git a/src/app/pages/ColorGame/components/Results/Results.jsx b/src/app/pages/ColorGame/components/Results/Results.jsx index a322db08..67e6a8c9 100644 --- a/src/app/pages/ColorGame/components/Results/Results.jsx +++ b/src/app/pages/ColorGame/components/Results/Results.jsx @@ -3,14 +3,43 @@ import { memo } from "react"; import cn from "./Results.module.scss"; export const Results = memo(function Results({ report }) { + const actualColor = "#" + report.actual; + const guessColor = "#" + report.guess; + return (
You were {report.similarityPercentage.toFixed(2)}% of the way there! -
answer: #{report.actual}
-
you guessed: #{report.guess}
+
+
+
+ + ANSWER + +
+

{actualColor}

+
+
+
+
+
+
+ + GUESS + +
+

{guessColor}

+
+
+
); }); diff --git a/src/app/pages/ColorGame/components/Results/Results.module.scss b/src/app/pages/ColorGame/components/Results/Results.module.scss index f2a35521..cb866001 100644 --- a/src/app/pages/ColorGame/components/Results/Results.module.scss +++ b/src/app/pages/ColorGame/components/Results/Results.module.scss @@ -1,6 +1,62 @@ .container { text-align: center; - margin: 40px; display: grid; - gap: 8px; + margin-top: 20px; + + background-color: var(--silver); + border-radius: 8px; + width: 100%; + padding: 40px; + + .split { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 20px; + padding-top: 20px; + + .left { + text-align: left; + display: grid; + grid-template-columns: 1fr auto; + + .description { + display: grid; + place-content: center start; + } + } + + .right { + text-align: right; + display: grid; + grid-template-columns: auto 1fr; + + .description { + display: grid; + place-content: center end; + } + } + + .color { + font-size: 3em; + } + .box { + height: 120px; + width: 120px; + border-radius: 8px; + + } + @media screen and (max-width: 900px) { + grid-template-columns: 1fr; + + .box { + height: 60px; + width: 60px; + } + // .right + + .color { + font-size: 2em; + } + } + } } \ No newline at end of file