Skip to content

Commit

Permalink
Merge pull request #8 from DumitruDruta/theme-switch
Browse files Browse the repository at this point in the history
Theme switch
  • Loading branch information
hollowM1ke authored Nov 22, 2023
2 parents 141d135 + a7e3a4e commit 679b218
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "^5.0.0"
"react-scripts": "^5.0.0",
"react-switch": "^7.0.0"
},
"main": "/index.js",
"devDependencies": {},
"name": "vy6j3f",
"description": null,
"version": "0.0.0",
Expand Down
11 changes: 10 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from "react";
import ReactSwitch from "react-switch";


function Square({ value, onSquareClick }) {
return (
Expand Down Expand Up @@ -57,6 +59,11 @@ export default function Game() {
const [currentMove, setCurrentMove] = useState(0);
const xIsNext = currentMove % 2 === 0;
const currentSquares = history[currentMove];
const [theme, setTheme] = useState("dark");

const toggleTheme = () => {
setTheme((curr) => (curr === "light" ? "dark" : "light"));
};

function handlePlay(nextSquares) {
const nextHistory = [...history.slice(0, currentMove + 1), nextSquares];
Expand Down Expand Up @@ -85,7 +92,9 @@ export default function Game() {
});

return (
<div className="game">
<div className="game" id={theme}>
<label>{theme === "light" ? "Light Mode" : "Dark Mode"}</label>
<ReactSwitch onChange={toggleTheme} checked={theme === "dark"} />
<div className="game-board">
<Board xIsNext={xIsNext} squares={currentSquares} onPlay={handlePlay} />
</div>
Expand Down
30 changes: 29 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
box-sizing: border-box;
}




body {
font-family: sans-serif;
margin: 20px;
Expand Down Expand Up @@ -89,6 +92,31 @@ body {
margin-left: 20px;
}

#light {
color: #000;
background-color: #fff;
}

#light .square {
color: #000;
background-color: #fff;
}

#dark {
color: #fff;
background-color: #000000;
}

#dark .square {
color: #fff;
background-color: #000000;
}

#dark button {
color: #fff;
background-color: #5c5c5c;
}

.X {
color: blue;
}
Expand Down Expand Up @@ -121,4 +149,4 @@ body {
content: counter(move);
margin-right: 16px;
font-weight: bold;
}
}

0 comments on commit 679b218

Please sign in to comment.