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 #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Dark mode #21

wants to merge 4 commits into from

Conversation

epicmeme
Copy link
Member

No description provided.

epicmeme added 3 commits August 20, 2022 23:05
- New icons Sun + Moon
- utils/colorScheme.ts
    - Detects browser settings
    - Overrides browser settings on click
- index.css
    - Implemented dark mode
@epicmeme epicmeme requested a review from StelFoog August 20, 2022 21:37
Copy link
Member

@Cactooz Cactooz left a 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.

Copy link
Member

@StelFoog StelFoog left a 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>();
Copy link
Member

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"

Copy link
Member

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);
Copy link
Member

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused imports

Comment on lines 23 to 25
--primary: 64, 104, 125;
--primary-medium: 46, 81, 99;
--primary-dark: 28, 42, 51;
Copy link
Member

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));
Copy link
Member

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
Copy link
Member

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'.

Comment on lines +7 to +8
if (localStorage.getItem('theme')) {
if (localStorage.getItem('theme') == 'dark') {
Copy link
Member

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'

Comment on lines +11 to +14
} else if (!window.matchMedia) {
//matchMedia method not supported
return false;
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
Copy link
Member

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)')

Comment on lines +20 to +22
if (theme == 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
Copy link
Member

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) {
Copy link
Member

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.

@Cactooz Cactooz linked an issue Aug 21, 2022 that may be closed by this pull request
@Cactooz Cactooz added the enhancement New feature or request label Sep 5, 2022
@StelFoog StelFoog added this to the v1.0.0 milestone Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dark mode
3 participants