From 01d3cbe30d73cd3c11692060287d8398ebb1bca8 Mon Sep 17 00:00:00 2001 From: Shubham Lal Date: Thu, 4 Apr 2024 17:10:42 +0530 Subject: [PATCH] client: add small theme-toggle button --- client/src/components/button/toggle-theme.tsx | 2 +- .../src/components/sidebar/left-sidebar.css | 22 ++++++++++-- .../src/components/sidebar/left-sidebar.tsx | 29 +++++++++++---- client/src/components/sidebar/profile.css | 31 ++++++++++++---- client/src/components/sidebar/profile.tsx | 35 +++++++++++++------ 5 files changed, 93 insertions(+), 26 deletions(-) diff --git a/client/src/components/button/toggle-theme.tsx b/client/src/components/button/toggle-theme.tsx index 27b58e0..78049eb 100644 --- a/client/src/components/button/toggle-theme.tsx +++ b/client/src/components/button/toggle-theme.tsx @@ -11,7 +11,7 @@ const ToggleTheme = () => { } return ( -
+
{ const location = useLocation(); const navigate = useNavigate(); const { setRoute, isAuthenticated, setAuthTab } = useAuthStore(); + const { theme, setTheme } = useNavStore(); const handleLinkClick = (href: string, name: string) => { if (name === "Create Debate") { @@ -22,6 +25,12 @@ const LeftSidebar = () => { else navigate(href); }; + const handleToggleTheme = () => { + const newTheme = theme === Theme.Light ? Theme.Dark : Theme.Light; + document.querySelector("body")?.setAttribute('data-theme', newTheme); + setTheme(newTheme); + } + return ( ) diff --git a/client/src/components/sidebar/profile.css b/client/src/components/sidebar/profile.css index e487086..b55270b 100644 --- a/client/src/components/sidebar/profile.css +++ b/client/src/components/sidebar/profile.css @@ -22,15 +22,10 @@ font-size: 17.5px; background-color: var(--explore_input_bg); color: var(--body_color); - transition: 0.2s ease-in-out; -} - -.profile__wrapper .login-btn:hover { - background-color: var(--body_color); - color: var(--body_background); } .profile__image, +.theme-btn, .modal-profile__image { width: 40px; height: 40px; @@ -42,6 +37,12 @@ flex-shrink: 0; } + +.theme-btn { + display: none; + background-color: var(--explore_input_bg); +} + .modal-profile__image { width: 45px; height: 45px; @@ -55,6 +56,18 @@ object-fit: cover; } +.theme-btn .sun { + width: 50%; + height: 50%; + object-fit: cover; +} + +.theme-btn .moon { + width: 65%; + height: 65%; + object-fit: cover; +} + .modal-profile__info { display: flex; flex-direction: column; @@ -158,4 +171,8 @@ border-bottom: 1px solid var(--nav_border); border-radius: 0; } -} + + .theme-btn { + display: grid; + } +} \ No newline at end of file diff --git a/client/src/components/sidebar/profile.tsx b/client/src/components/sidebar/profile.tsx index b3aeb1b..73aba7a 100644 --- a/client/src/components/sidebar/profile.tsx +++ b/client/src/components/sidebar/profile.tsx @@ -1,7 +1,7 @@ import "./profile.css"; import { useEffect } from "react"; import { Link, useNavigate } from "react-router-dom"; -import { useNavStore } from "../../store/useNavStore"; +import { Theme, useNavStore } from "../../store/useNavStore"; import { AuthStatus, AuthTab, useAuthStore } from "../../store/useAuthStore"; import ToggleTheme from "../button/toggle-theme"; import useLogout from "../../hooks/useLogout"; @@ -13,9 +13,15 @@ import { FaRegUser } from "react-icons/fa"; const Profile = () => { const navigate = useNavigate(); - const { expand, setExpand } = useNavStore(); + const { expand, setExpand, theme, setTheme } = useNavStore(); const { isAuthenticated, setIsAuthenticated, user, setUser, authTab, setAuthTab } = useAuthStore(); + const handleToggleTheme = () => { + const newTheme = theme === Theme.Light ? Theme.Dark : Theme.Light; + document.querySelector("body")?.setAttribute('data-theme', newTheme); + setTheme(newTheme); + } + useEffect(() => { const handleClickOutside = (event: MouseEvent) => { const target = event.target as HTMLElement; @@ -55,14 +61,23 @@ const Profile = () => { )}
) : ( - + <> + + + )} {expand && (