diff --git a/lecture-pulse/src/context/ThemeContext.jsx b/lecture-pulse/src/context/ThemeContext.jsx new file mode 100644 index 0000000..f1f41f9 --- /dev/null +++ b/lecture-pulse/src/context/ThemeContext.jsx @@ -0,0 +1,37 @@ +import { createContext, useContext, useEffect, useState } from "react"; + +const ThemeContext = createContext(); +export const ThemeProvider = ({ children }) =>{ + const [theme,setTheme] = useState(() =>{ + return localStorage.getItem("theme") || "light"; + }) + + useEffect(() =>{ + const root = window.document.documentElement ; + + if (theme === "dark") { + root.classList.add("dark"); + } else { + root.classList.remove("dark"); + } + localStorage.setItem("theme",theme); + },[theme]); + + const toggleTheme = () => { + setTheme((prev) => + prev === "dark" ? "light" : "dark" + ); + }; + return ( + + {children} + + ); + +} +export const useTheme = () => useContext(ThemeContext) \ No newline at end of file diff --git a/lecture-pulse/src/main.jsx b/lecture-pulse/src/main.jsx index 2898346..07b7803 100644 --- a/lecture-pulse/src/main.jsx +++ b/lecture-pulse/src/main.jsx @@ -3,11 +3,15 @@ import { createRoot } from 'react-dom/client' import { BrowserRouter } from 'react-router-dom' import './index.css' import App from './App.jsx' +import { ThemeProvider } from './context/ThemeContext.jsx' createRoot(document.getElementById('root')).render( + - + + + , ) diff --git a/lecture-pulse/src/pages/Landing.jsx b/lecture-pulse/src/pages/Landing.jsx index 42498aa..d105793 100644 --- a/lecture-pulse/src/pages/Landing.jsx +++ b/lecture-pulse/src/pages/Landing.jsx @@ -9,12 +9,14 @@ import { GraduationCap, Menu, X, + Sun, + Moon, } from "lucide-react"; import { Link } from "react-router-dom"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import heroBg from "@/assets/hero-bg.png"; - +import { useTheme } from '../context/ThemeContext'; const features = [ { icon: Users, @@ -50,7 +52,7 @@ const stats = [ function Landing() { const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); - + const { theme, toggleTheme } = useTheme(); return (
{/* Navigation */} @@ -64,9 +66,91 @@ function Landing() { LecturePulse - + {/* Desktop Nav */}
+ {/* + */} + + @@ -76,7 +160,7 @@ function Landing() {
{/* Mobile Menu Button */} - +