I have one checkbox that changes the color theme to dark or light. But I want to add three more checkboxes which will also be the color of the page, that is, I want to have 4 checkboxes where the first one will change the page color to black, the second white, the third to green and the fourth to red
App.js
import React, { useState, useEffect } from "react";
import "./App.css";
import ReactDOM from 'react-dom';
export default function App() {
const [dark, setDark] = useState(getMode);
useEffect(() => {
localStorage.setItem("dark", JSON.stringify(dark));
}, [dark]);
function getMode() {
const savedmode = JSON.parse(localStorage.getItem("dark"));
return savedmode || false;
}
return (
<div className={dark ? "black" : "light"} style={{ height: "100vh" }}>
<nav>
<div className="toggle-container">
<span style={{ color: dark ? "grey" : "yellow" }}>☀︎</span>
<span className="toggle">
<input
checked={dark}
onChange={() => setDark((prevMode) => !prevMode)}
id="checkbox"
className="checkbox"
type="checkbox"
/>
<label htmlFor="checkbox" />
</span>
<span style={{ color: dark ? "slateblue" : "grey" }}>☾</span>
</div>
</nav>
<div style={{ textAlign: "center" }}>
<h1>{dark ? "darkmode" : "lightmode"}</h1>
<p>This is dark mode content</p>
<h1>The darkmode is implemented by reactjs</h1>
</div>
</div>
);
}
App.css
.black {
background-color: black;
color: white;
}
.light {
background-color: blanchedalmond;
color: black;
}
.nav {
background-color: blue;
color: white;
}
.toggle-container {
background-color: blue;
padding: 20px;
display: flex;
justify-content: center;
}