superseriousbusiness / gotosocial

Fast, fun, small ActivityPub server.
https://docs.gotosocial.org
GNU Affero General Public License v3.0
3.86k stars 338 forks source link

[accessibility/frontend] Use client's `prefers-color-scheme` on the web frontend #1214

Open tsmethurst opened 1 year ago

tsmethurst commented 1 year ago

Originally posted by @bremensaki in https://github.com/superseriousbusiness/gotosocial/issues/714#issuecomment-1327991017

benjaminbhollon commented 1 year ago

I'd be happy to look into implementing this; I've done a fair bit of work with designing accessible CSS and am someone directly affected by the lack of a light mode stylesheet (my astigmatism makes it uncomfortable/difficult to read light-on-dark).

If you're looking for an outside contributor on this, let me know; I'll get to work.

tsmethurst commented 1 year ago

If you feel like having a crack at it, that would be great! I'm not really sure what the steps involved for this one would be: I myself am clueless about how to have light + dark css in the same stylesheet (?), how to store / modify the user's preference, and how to flip between it in a way that can work without JS. So, input welcome :)

benjaminbhollon commented 1 year ago

Okay, got it.

So to kind of outline what I'm imagining:

Without JS, we can use a @media query to detect when the browser prefers dark mode:

@media (prefers-color-scheme: dark) {
    /* styles go here */
}

Then what I can also do to add the possibility for users to override that is have the theme switch based on a class or attribute; in my own code I use the data-theme attribute set to light or dark to override the prefers-color-scheme.

If that sounds good I can start implementing it.

turtlegarden commented 1 year ago

Yeah, I think that sounds ideal. Then, no JS is needed and the server can set the data-theme, and only the sass variables need to be changed (and they can simply be put in a @media block as mentioned above).

benjaminbhollon commented 1 year ago

Awesome, I'll start looking at the code, then. Haven't worked with sass much (I mostly use plain CSS), so it might take a bit to figure out setting things up.

turtlegarden commented 1 year ago

(wait, we should get tobi's approval, I'm not tobi!)

benjaminbhollon commented 1 year ago

Oh, ha, sure! XD

tsmethurst commented 1 year ago

I'm not tobi!

Aren't we all, in a way, tobi? In our hearts? I think so.

Anyway, I think this approach sounds fine. I'd like to hear if @f0x52 has any input too :)

VirtualWolf commented 6 days ago

Hey @benjaminbhollon did you end up getting anywhere with this? :)

benjaminbhollon commented 6 days ago

I never did, I'm sorry. I think once all the different color schemes came into play (whatever release that was?) I forgot this was something that still needs doing.

VirtualWolf commented 6 days ago

All good! I was thinking of taking a look at it and didn't want to step on anyone's toes if it was most of the way to being implemented already.

benjaminbhollon commented 5 days ago

My toes are safe, implement away! ;D

CDN18 commented 5 days ago

I've already merged the corresponding default theme on my instance using prefers-color-scheme and have been using it for a while without any issues. If this only involves changes to the theme CSS code, I think I can go ahead and submit a PR.

VirtualWolf commented 5 days ago

Oh nice! I think this issue is kind of two things? Don't default to dark mode but detect the user preference:

Without JS, we can use a @media query to detect when the browser prefers dark mode

But in addition, the option to switch between them:

Then what I can also do to add the possibility for users to override that is have the theme switch based on a class or attribute

Yours would cover the first, which I think would be a big improvement on its own.