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 ( <>
+
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: [], -} - +};