From 14da9f50105f3bde55cff2daf48b71d9fe170d6f Mon Sep 17 00:00:00 2001 From: Aryan Ramesh Jain <138214350+jainaryan04@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:31:39 +0530 Subject: [PATCH 1/2] initial #469: add hook and toggle --- frontend/src/Pages/Herosection.jsx | 4 +++- frontend/src/components/ThemeToggle.jsx | 32 +++++++++++++++++++++++++ frontend/src/hooks/useDarkMode.js | 16 +++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/ThemeToggle.jsx create mode 100644 frontend/src/hooks/useDarkMode.js diff --git a/frontend/src/Pages/Herosection.jsx b/frontend/src/Pages/Herosection.jsx index 750dcf4..3fbc936 100644 --- a/frontend/src/Pages/Herosection.jsx +++ b/frontend/src/Pages/Herosection.jsx @@ -1,5 +1,6 @@ import React from "react"; import "./Herosection.css"; +import ThemeToggle from "../components/ThemeToggle" import logo from "../assets/stationsaarthi.svg"; import navigationsvg from "../assets/svg/navigation.svg"; import bookingsvg from "../assets/svg/bookings.svg"; @@ -56,8 +57,9 @@ const Herosection = () => { return ( <>
-
+
+
diff --git a/frontend/src/components/ThemeToggle.jsx b/frontend/src/components/ThemeToggle.jsx new file mode 100644 index 0000000..d7d0c43 --- /dev/null +++ b/frontend/src/components/ThemeToggle.jsx @@ -0,0 +1,32 @@ +import { FaSun, FaMoon } from 'react-icons/fa'; +import useDarkMode from '../hooks/useDarkMode'; +import "../../src/index.css"; + +const ThemeSwitcher = () => { + const [theme, setTheme] = useDarkMode(); + const isDarkMode = theme === 'dark'; + + return ( +
+ + + +
+ ); +}; + +export default ThemeSwitcher; \ No newline at end of file diff --git a/frontend/src/hooks/useDarkMode.js b/frontend/src/hooks/useDarkMode.js new file mode 100644 index 0000000..1513686 --- /dev/null +++ b/frontend/src/hooks/useDarkMode.js @@ -0,0 +1,16 @@ +import { useState, useEffect } from 'react'; + +const useDarkMode = () => { + const [theme, setTheme] = useState(() => localStorage.getItem('theme') || 'light'); + + useEffect(() => { + const root = document.documentElement; + const isDark = theme === 'dark'; + root.classList.toggle('dark', isDark); + localStorage.setItem('theme', theme); + }, [theme]); + + return [theme, setTheme]; +}; + +export default useDarkMode; \ No newline at end of file From fea54e947ed1c7a587dc6f1beb85c83d78a0d6a1 Mon Sep 17 00:00:00 2001 From: Aryan Ramesh Jain <138214350+jainaryan04@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:05:19 +0530 Subject: [PATCH 2/2] implements #469 for landing page --- frontend/src/Pages/Herosection.jsx | 52 +++++++++++++++--------------- frontend/src/Pages/hamburger.jsx | 5 +-- frontend/src/components/navbar.jsx | 2 +- frontend/src/components/popup.jsx | 16 ++++----- frontend/src/hooks/useDarkMode.js | 2 ++ frontend/tailwind.config.js | 7 ++-- 6 files changed, 44 insertions(+), 40 deletions(-) diff --git a/frontend/src/Pages/Herosection.jsx b/frontend/src/Pages/Herosection.jsx index 3fbc936..a6e72a0 100644 --- a/frontend/src/Pages/Herosection.jsx +++ b/frontend/src/Pages/Herosection.jsx @@ -57,7 +57,7 @@ const Herosection = () => { return ( <>
-
+
@@ -68,7 +68,7 @@ const Herosection = () => {
@@ -79,7 +79,7 @@ const Herosection = () => {
-

+

Namaste !! Yatree{" "}

@@ -94,7 +94,7 @@ const Herosection = () => {


-
+
{ src={contributorsvg} alt="" className=" - bg-blue-200 border-2 border-blue-100 rounded-full + bg-blue-200 border-2 border-blue-100 rounded-full dark:bg-black w-[64px] h-[64px] p-2 " /> -

Contributors

+

Contributors

{ src={navigationsvg} alt="" srcset="" - className="bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" + className="dark:bg-black bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" /> -
{ src={bookingsvg} alt="" srcset="" - className="bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg " + className="bg-blue-200 border-2 dark:bg-black border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg " />
{ src={stationsvg} alt="" srcset="" - className="bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" + className="bg-blue-200 dark:bg-black border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" /> -
{ src={mapsvg} alt="" srcset="" - className="bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" + className="bg-blue-200 dark:bg-black border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" />{" "}
@@ -190,15 +190,15 @@ const Herosection = () => { src={schedulesvg} alt="" srcset="" - className="bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" + className="bg-blue-200 dark:bg-black border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg" />
@@ -211,22 +211,22 @@ const Herosection = () => { src={noticationsvg} alt="" srcset="" - className="bg-blue-200 border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg " + className="bg-blue-200 dark:bg-black border-2 border-blue-200 rounded-full w-[64px] h-[64px] p-2 shadow-lg " />{" "}
-
+
-

Saarthi

+

Saarthi

); diff --git a/frontend/src/Pages/hamburger.jsx b/frontend/src/Pages/hamburger.jsx index 83d24a8..d581f49 100644 --- a/frontend/src/Pages/hamburger.jsx +++ b/frontend/src/Pages/hamburger.jsx @@ -214,8 +214,8 @@ const Hamburger = () => { return (
- - + + { onChange={handleSearchChange} onFocus={handleFocus} onBlur={handleBlur} + className="dark:bg-black dark:text-white dark:placeholder:text-gray-300" /> {showSearch && searchTerm && } diff --git a/frontend/src/components/navbar.jsx b/frontend/src/components/navbar.jsx index 00c09a5..6953bbf 100644 --- a/frontend/src/components/navbar.jsx +++ b/frontend/src/components/navbar.jsx @@ -93,7 +93,7 @@ const Navbar = () => { return ( <> {/* Navigation Toggle for All Screens (Mobile and Larger Screens) */} -
+
diff --git a/frontend/src/components/popup.jsx b/frontend/src/components/popup.jsx index 37495e7..d24c3f8 100644 --- a/frontend/src/components/popup.jsx +++ b/frontend/src/components/popup.jsx @@ -28,10 +28,10 @@ const Popup = () => { return ( isVisible && ( -
-
+
+
-

Welcome to Station Saarthi

-

Travel without stress. Sign in now!

+

Welcome to Station Saarthi

+

Travel without stress. Sign in now!

setEmail(e.target.value)} @@ -54,12 +54,12 @@ const Popup = () => { />
-

+

By signing in, I agree to Station Saarthi's{' '} Terms of Service and{' '} Privacy Policy. diff --git a/frontend/src/hooks/useDarkMode.js b/frontend/src/hooks/useDarkMode.js index 1513686..b391abf 100644 --- a/frontend/src/hooks/useDarkMode.js +++ b/frontend/src/hooks/useDarkMode.js @@ -7,8 +7,10 @@ const useDarkMode = () => { const root = document.documentElement; const isDark = theme === 'dark'; root.classList.toggle('dark', isDark); + console.log(`Theme set to ${theme}, dark mode is ${isDark ? 'enabled' : 'disabled'}`); localStorage.setItem('theme', theme); }, [theme]); + return [theme, setTheme]; }; diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js index 6bdcac8..52339c9 100644 --- a/frontend/tailwind.config.js +++ b/frontend/tailwind.config.js @@ -1,9 +1,10 @@ /** @type {import('tailwindcss').Config} */ export default { content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'], + darkMode: 'class', theme: { - extend: {}, + extend: { + }, }, plugins: [], -} - +};