Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark mode feature added #3301

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState, useEffect } from 'react'
import Search from './Search'
import '../styles/SearchBarDesktopView.scss'
import { pageNames } from '../util/pageNames'
Expand All @@ -12,6 +12,30 @@ const Navbar = ({
mapOrHomeTitle,
shufflePeopleOnClick,
}: any) => {
const [isDarkMode, setIsDarkMode] = useState(false)

// Check if dark mode is already set in localStorage
useEffect(() => {
const savedTheme = localStorage.getItem('theme')
if (savedTheme === 'dark') {
setIsDarkMode(true)
document.body.classList.add('dark-mode')
}
}, [])

// Toggle dark mode
const handleDarkModeToggle = () => {
const newMode = !isDarkMode
setIsDarkMode(newMode)
if (newMode) {
document.body.classList.add('dark-mode')
localStorage.setItem('theme', 'dark')
} else {
document.body.classList.remove('dark-mode')
localStorage.setItem('theme', 'light')
}
}

return (
<div className="header-items flex flex-wrap justify-between">
<h1
Expand Down Expand Up @@ -50,6 +74,10 @@ const Navbar = ({
<Search onSearchChange={onSearchChange} />
</div>
)}
{/* Dark mode toggle button */}
<button onClick={handleDarkModeToggle} className="ml3 pointer">
{isDarkMode ? 'Light Mode' : 'Dark Mode'}
</button>
</div>
</div>
)
Expand Down
38 changes: 38 additions & 0 deletions src/styles/SearchBarDesktopView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,41 @@
display: none;
}
}
/* Light mode (default) */
body {
background-color: #f5f5f5;
color: #212121;
}

.header-items {
background-color: #212121;
color: #ffffff;
}

/* Dark mode */
body.dark-mode {
background-color: #212121;
color: #212121;
}

.header-items.dark-mode {
background-color: #333333;
color: #fff;
}

button {
background-color: var(--primary-color);
color: white;
border: none;
cursor: pointer;
padding: 0.5rem 1rem;
border-radius: 4px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 24px;
}

/* Dark mode button styles */
body.dark-mode button {
background-color: var(--secondary-color);
color: white;
}
38 changes: 38 additions & 0 deletions src/styles/SearchBarMobileView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,41 @@
top: 80%;
}
}
/* Light mode (default) */
body {
background-color: #f5f5f5;
color: #212121;
}

.header-items {
background-color: #212121;
color: #ffffff;
}

/* Dark mode */
body.dark-mode {
background-color: #212121;
color: #212121;
}

.header-items.dark-mode {
background-color: #333333;
color: #fff;
}

button {
background-color: var(--primary-color);
color: red;
border: none;
cursor: pointer;
padding: 0.5rem 1rem;
border-radius: 4px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 24px;
}

/* Dark mode button styles */
body.dark-mode button {
background-color: var(--secondary-color);
color: blue;
}
Loading