Skip to content

Commit

Permalink
Implementing dark and light mode features in this website.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amarkr1717 committed Jan 18, 2025
1 parent c4a88bc commit b5a8612
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
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;
}

0 comments on commit b5a8612

Please sign in to comment.