toggle light mode
parent
0917aa4f4c
commit
cd28eb6e04
15
src/App.js
15
src/App.js
|
@ -2,9 +2,13 @@ import React, { useState, useEffect } from "react";
|
|||
import LangDropdown from "./components/LangDropdown";
|
||||
import SearchBar from "./components/SearchBar";
|
||||
import SearchResult from "./components/SearchResult";
|
||||
import LightSwitch from "./components/LightSwitch";
|
||||
import axios from "axios";
|
||||
import Fuse from "fuse.js";
|
||||
|
||||
import SunImg from "./img/sun.png"
|
||||
import MoonImg from "./img/moon.png"
|
||||
|
||||
const fpb = null;
|
||||
|
||||
// eslint-disable-next-line
|
||||
|
@ -104,6 +108,8 @@ function App() {
|
|||
const [searchParams, setSearchParams] = useState({ title: "" });
|
||||
const [searchResults, setSearchResults] = useState([]);
|
||||
const [sectionResults, setSectionResults] = useState([]);
|
||||
const [lightMode, setLightMode] = useState(true);
|
||||
|
||||
// eslint-disable-next-line
|
||||
const [error, setError] = useState("");
|
||||
|
||||
|
@ -199,8 +205,13 @@ function App() {
|
|||
});
|
||||
}
|
||||
return (
|
||||
<div className="frontPage">
|
||||
<h1>Free Programming Books</h1>
|
||||
<div className="frontPage" style={{color: lightMode ? "black" : "white", backgroundColor: lightMode ? "white" : "black"}}>
|
||||
<img src={lightMode ? SunImg: MoonImg}
|
||||
onClick = {()=>setLightMode(!lightMode)} style={{width: "100px", height: "100px",display: "block",
|
||||
marginLeft: "auto",
|
||||
marginRight: "auto",
|
||||
}}/>
|
||||
<h1>Free Programming Books</h1>
|
||||
<div>
|
||||
<SearchBar changeParameter={changeParameter} />
|
||||
<LangDropdown changeParameter={changeParameter} data={data} />
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
|
||||
function LightSwitch(App){
|
||||
const [lightMode, setLightMode] = useState(false);
|
||||
return (
|
||||
<img src={lightMode ? "https://toppng.com/uploads/preview/sun-11545692406nbrflpmao0.png" : "https://www.kindpng.com/picc/m/293-2939577_clip-art-drawing-of-moon-and-stars-star.png"}
|
||||
onClick = {()=>setLightMode(!lightMode)} style={{width: "100px", height: "100px",display: "block",
|
||||
marginLeft: "auto",
|
||||
marginRight: "auto",
|
||||
}}/>
|
||||
)
|
||||
}
|
||||
|
||||
export default LightSwitch;
|
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
After Width: | Height: | Size: 95 KiB |
Binary file not shown.
After Width: | Height: | Size: 285 KiB |
Loading…
Reference in New Issue