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

FEATURE: automatic dark mode #10341

Merged
merged 5 commits into from
Aug 4, 2020
Merged

FEATURE: automatic dark mode #10341

merged 5 commits into from
Aug 4, 2020

Conversation

pmusaraj
Copy link
Contributor

@pmusaraj pmusaraj commented Jul 30, 2020

This is a first step to adding automatic dark mode color theme switching. It's only a v1, the feature will be fine-tuned in the near future.

Here's what the PR does. First, a new SCSS file is added at color_definitions.scss that serves to output all SCSS variables as CSS custom properties. This file is compiled and included in the app as a separate stylesheet.

Next, the PR adds the default_dark_mode_color_scheme_id site setting, disabled by default and hidden for now. When a valid dark scheme id is set, the app loads a second stylesheet with the dark scheme's color definitions. When the browser/OS is in dark mode using (prefers-color-scheme: dark), the dark color scheme will apply.

Last but not least, the PR mass replaces SCSS color variables with CSS custom properties, so that automatic dark mode switching can happen when enabled.

@pmusaraj pmusaraj changed the title FEATURE: Add support for auto dark mode styling FEATURE: automatic dark mode Jul 30, 2020
@pmusaraj pmusaraj marked this pull request as ready for review July 31, 2020 01:27
Copy link
Contributor

@eviltrout eviltrout left a comment

Choose a reason for hiding this comment

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

I am going to trust the search/replace process here because there are 142 files changed and that's impossible to do by eye. It does look very clean and elegant though!

@davidtaylorhq
Copy link
Member

When pulling this locally I see

ActionController::RoutingError (No route matches [GET] "/stylesheets/color_definitions_my%20dark&20scheme_7f691385c8d34e95bd5c737d05672f71da4fcdfb.css")

Possibly because my color scheme name has a space in it?

@pmusaraj
Copy link
Contributor Author

Yes, because of the space. I'll fix.

@pmusaraj pmusaraj merged commit c937afc into master Aug 4, 2020
@pmusaraj pmusaraj deleted the automatic-dark-mode branch August 4, 2020 02:57
@nlalonde
Copy link
Member

nlalonde commented Aug 4, 2020

With a new site I'm getting Couldn't find Theme with 'id'=-1

lib/stylesheet/manager.rb:

Theme.find(SiteSetting.default_theme_id).color_scheme || ColorScheme.base

@pmusaraj
Copy link
Contributor Author

pmusaraj commented Aug 4, 2020

Thanks @nlalonde, should be fixed in 266c0c5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants