Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing dark and light mode features in this website. #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@
.read-the-docs {
color: #888;
} */
body.light {
background-color: #ffffff;
color: #000000;
}

body.dark {
background-color: #000000;
color: #ffffff;
}
5 changes: 3 additions & 2 deletions Frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import SideBarWithNav from "./Components/CommonModule/SideBarModule/SideBar";
import Gallery from "./Components/GalleryModule/Gallery";
import "./App.css";
import { ThemeProvider } from "./ThemeContext";

function App() {
return (
<>
<ThemeProvider>
<SideBarWithNav />
<Gallery />
</>
</ThemeProvider>
);
}

Expand Down
10 changes: 10 additions & 0 deletions Frontend/src/Components/CommonModule/NavBarModule/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React, { useContext } from "react";
import Search from "/SearchIcon.svg";
import Profile from "/ProfileIcon.svg";
import Style from "./NavBar.module.css";
import { ThemeContext } from "../../../ThemeContext";

const NavBar = () => {

const { theme, toggleTheme } = useContext(ThemeContext);


return (
<nav className={Style.navbar}>
<div className={Style.MainContainer}>
Expand All @@ -28,6 +34,10 @@ const NavBar = () => {
<button className={Style.profileButton}>
<img src={Profile} alt="Profile" />
</button>

<button className={Style.themeToggle} onClick={toggleTheme}>
{theme === "dark" ? "☀️" : "🌙"}
</button>
</div>
</div>
</nav>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
display: flex;
align-items: center;
margin: 0;
background-color: white;
/* background-color: white; */
border-radius: 10px;
}

Expand Down
24 changes: 24 additions & 0 deletions Frontend/src/ThemeContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { createContext, useState, useEffect } from "react";

export const ThemeContext = createContext();

export const ThemeProvider = ({ children }) => {
const [theme, setTheme] = useState(
localStorage.getItem("theme") || "light"
);

useEffect(() => {
document.body.className = theme;
localStorage.setItem("theme", theme);
}, [theme]);

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

return (
<ThemeContext.Provider value={{ theme, toggleTheme }}>
{children}
</ThemeContext.Provider>
);
};
10 changes: 0 additions & 10 deletions Frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,3 @@
:root {
--font-family: 'Comfortaa', sans-serif;
}

body {
margin: 0;
font-family: var(--font-family);
background-image: url("../public/BACKGROUND.svg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
}
Loading