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

[Cub] Dark mode based on user preferred mode #23

Closed
mmaismma opened this issue Aug 29, 2020 · 4 comments
Closed

[Cub] Dark mode based on user preferred mode #23

mmaismma opened this issue Aug 29, 2020 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mmaismma
Copy link
Member

mmaismma commented Aug 29, 2020

Description
Cub's Contraption has a dark mode in the beta version which can be toggled by typing invert.
Currently, it will only switch the mode if you type the word on the webpage. But it would be smart to automatically change the mode according to the mode the user is using for the system.

Possible solution(s)
This feature can be obtained with the CSS media feature prefers-color-scheme. As MDN states

The prefers-color-scheme CSS media feature is used to detect if the user has requested the system to use a light or dark color theme.

If the media feature returns dark open the page in dark mode, and if it returns light open the webpage in light mode.

@mmaismma mmaismma added enhancement New feature or request good first issue Good for newcomers labels Aug 29, 2020
@mmaismma mmaismma added this to the Cub's Contraption v1.0.1 milestone Oct 8, 2020
@mmaismma mmaismma pinned this issue Oct 10, 2020
@shee35
Copy link

shee35 commented Oct 10, 2020

can I work on this issue @mmaismma ?

@mmaismma
Copy link
Member Author

Why not? Everyone is welcome!

@shee35
Copy link

shee35 commented Oct 11, 2020

Why not? Everyone is welcome!

👍

@mmaismma
Copy link
Member Author

The dark mode is toggled by toggling dark in the body's classList by the function darken(). Since CSS cannot add or remove classes, we will need to also use Javascript for this purpose. We will check if the user has preferred dark mode with the CSS media-feature prefers-color-scheme with Javascript's window.matchMedia().
When the window loads, check for window.matchMedia('(prefers-color-scheme: dark)').matches, if it returns true, call darken().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants