-
Notifications
You must be signed in to change notification settings - Fork 1
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 #21
base: master
Are you sure you want to change the base?
Conversation
- New icons Sun + Moon - utils/colorScheme.ts - Detects browser settings - Overrides browser settings on click - index.css - Implemented dark mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--primary-contrasty
that is used for comments needs to have another color in dark mode, it's barely visible. Otherwise, everything looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good, but many small things that should be improved. Also make sure to squash all commits into one that includes Resolves #2
in the commit comment ^^
import { detectColorScheme, switchTheme } from '../util/colorScheme'; | ||
|
||
const ColorSchemeToggle = () => { | ||
const [dark, setDark] = useState<boolean>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be explicitly "light", "dark" or "system"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value should also not be managed by a component, instead I suggest using context
}, []); | ||
|
||
const handleClick = (): void => { | ||
setDark((_prev) => !_prev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leading with an underscore in variable name is generally used to mark a variable as unused (this is the way VSC deals with it). Also the more explicit previous
would be preferred.
@@ -8,6 +8,8 @@ import { useSearch } from '../context/searchContext'; | |||
import FilterModal from './FilterModal'; | |||
import Search from '../icons/Search'; | |||
import Clear from '../icons/Clear'; | |||
import { detectColorScheme, switchTheme } from '../util/colorScheme'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused imports
--primary: 64, 104, 125; | ||
--primary-medium: 46, 81, 99; | ||
--primary-dark: 28, 42, 51; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also be altered using dark mode to ensure good contrast
overflow-x: hidden; | ||
text-overflow: ellipsis; | ||
> li { | ||
background-color: rgba(var(--background)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be unneeded?
import React from 'react'; | ||
|
||
function detectColorScheme(): boolean { | ||
var theme = 'light'; //default to light |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theme should be typed to 'light' | 'dark'
.
if (localStorage.getItem('theme')) { | ||
if (localStorage.getItem('theme') == 'dark') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer if the LS key was defined as a const and specified to this application (as seen in bookmarksContext
to remove risk of collision when on localhost). E.g. const LS_THEME_KEY = 'in-songbook:theme'
} else if (!window.matchMedia) { | ||
//matchMedia method not supported | ||
return false; | ||
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be one case window.matchMedia?.('(prefers-color-scheme: dark)')
if (theme == 'dark') { | ||
document.documentElement.setAttribute('data-theme', 'dark'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only to detect what color scheme to use, this function should not set data-theme
return theme === 'dark'; | ||
} | ||
|
||
function switchTheme(dark: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be using explicit strings instead of a boolean.
No description provided.