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

Light and dark mode switch #974

Open
TrialDragon opened this issue Feb 16, 2024 · 10 comments
Open

Light and dark mode switch #974

TrialDragon opened this issue Feb 16, 2024 · 10 comments
Labels
C-Accessibility C-Feature A new feature, making something new possible C-Webdev

Comments

@TrialDragon
Copy link
Member

It would be a useful QoL feature for our users to be able to change from the dark mode to a light mode integrated into the site.

Origin: #3 (comment)

@Evrey
Copy link

Evrey commented May 20, 2024

It would be even better if the website just automatically changed its palette to light mode via the standard CSS @media prefers-color-scheme rule. +1 to this issue. I only visit the Bevy website with custom Stylus rules to turn it light.

@TrialDragon TrialDragon added the C-Feature A new feature, making something new possible label May 22, 2024
@lynnpepin
Copy link

@TrialDragon , I was looking into this, and I wanted your thoughts:

This can be done, and the best way to do it would be using CSS variables (which can respond dynamically to @media prefers-color-scheme), instead of SCSS variables (which are pre-processed into CSS).

To be specific, the Bevy website currently uses SCSS variables (see https://github.com/bevyengine/bevy-website/blob/main/sass/_vars.scss) which are pre-processed into CSS variables. E.g.

$subtitle-color: #999;

Because SCSS is only a pre-processor, these variables can't respond dynamically to @media prefers-color-scheme, e.g. with CSS variables, e.g.:

:root {
    @media (prefers-color-scheme: dark) {
        --subtitle-color: #999;
    }
    @media (prefers-color-scheme: light) {
        --subtitle-color: #777;
    }
}

I currently use CSS variables inside SCSS on my Zola-based blog to get auto light mode / dark mode (example: https://github.com/lynnpepin/lynndotpy_xyz/blob/main/sass/color/auto.scss). It works like a charm :D

Proposal: I was going to go through and replace the SCSS color variables with CSS variables, to respect prefers-color-scheme. I'll make a PR and link to this issue... But if anyone has a big objection to replacing SCSS variables with CSS variables, please let me know before I get too far, haha :)

@TrialDragon
Copy link
Member Author

But if anyone has a big objection to replacing SCSS variables with CSS variables, please let me know before I get too far, haha :)

I, personally, don't have any issue with using CSS variables instead of SCSS variables to be honest; I'm not even entirely sure why we used SCSS variables to begin with beyond we were writing SCSS, ergo, use SCSS variables.

@lynnpepin
Copy link

lynnpepin commented Aug 4, 2024

Awesome, happy to hear that :) I was able to spend a good few hours on this.

Re: SCSS variables, the only place SCSS variables were used were in a few lighten and darken calls. (CSS has that functionality as of 2023, e.g. color(var(--some-color) from srgb calc(r + 10%) calc(g + 10%) calc(b + 10%)), but SCSS doesn't support CSS calc, because calc was already an SCSS keyword...).

So, I pre-calculated the lighten and darken calls instead, and assigned them to variables! They should be off by no more than one bit due to rounding.

My fork is here: https://github.com/lynnpepin/bevy-website

There are a few outstanding issues though:

  • There are a few inline colors that don't respond to prefers-color-scheme yet.
  • The images are made for dark-mode and will need alternatives. This can be fixed by making them <picture>s which respond to prefers-color-scheme.
  • I haven't touched every accent, such as color-pink,
  • Code highlighting will need some attention (it's got its own block of colors).

Also, I kept the variable naming the same, but that means we have examples like --color-white: #090909; in light mode. Here are a few pics of how it looks so far:

image image image

@lynnpepin
Copy link

I'm not so deft at manipulating SVGs. Gonna take a crack at making inverted versions of the SVGs (i.e. a bevy-logo-light.svg for the existing bevy-logo-dark.svg). If anyone wants a PR for light/dark mode ready faster, it would be a huge help :D

@Evrey
Copy link

Evrey commented Aug 6, 2024

The images are made for dark-mode and will need alternatives.

A temporary work-around if logo images take too much time is to draw a box around all bright images. Here’s how that looks with my custom CSS:

image

(Well, it ain’t pretty, but iunno how much man power’s available for image editing.)

Probably the best solution is to edit the SVGs into having a thick black border around all shapes. In dark mode you just don’t see the borders, in light mode it’ll look outlined like many sprite-based games do for foreground objects.

@lynnpepin
Copy link

The images are made for dark-mode and will need alternatives.

A temporary work-around if logo images take too much time is to draw a box around all bright images. Here’s how that looks with my custom CSS:

I like this! I was able to figure out two workarounds:

  • I made a quick Python script to take SVGs and invert every hex code inside, and
  • Some places that already use CSS filter can have the prefers-color-scheme applied.

In the interest of getting feedback, I have a WIP build of the site with the new theme here! https://bevydocs.lynndotpy.dev/

Each image needs to be addressed individually, so I'm working on that bit by bit :)

@lynnpepin
Copy link

Working on the images and whatnot right now! Don't want to run into any duplication of work. Going to try and finish them up today and get the site updated for it

@lynnpepin
Copy link

Update: I have the light theme complete! But I'll also be creating a Javascript toggle, which will be another Whole Thing (tm) of work :)

For now, please please check out the preview here, and @ me if there's anything that looks ugly or bad or otherwise improvable :) https://bevydocs.lynndotpy.dev/

@lynnpepin
Copy link

For anyone coming to this, there is now a more recent PR by doup, building upon the previously linked PR, and looking very very good: #1771

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Accessibility C-Feature A new feature, making something new possible C-Webdev
Projects
None yet
Development

No branches or pull requests

4 participants