gotosocial icon indicating copy to clipboard operation
gotosocial copied to clipboard

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

Open tsmethurst opened this issue 2 years ago • 8 comments

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

tsmethurst avatar Dec 05 '22 10:12 tsmethurst

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.

benjaminbhollon avatar Nov 25 '23 22:11 benjaminbhollon

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

tsmethurst avatar Nov 26 '23 14:11 tsmethurst

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.

benjaminbhollon avatar Nov 26 '23 22:11 benjaminbhollon

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

turtlegarden avatar Nov 26 '23 23:11 turtlegarden

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.

benjaminbhollon avatar Nov 27 '23 01:11 benjaminbhollon

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

turtlegarden avatar Nov 27 '23 01:11 turtlegarden

Oh, ha, sure! XD

benjaminbhollon avatar Nov 27 '23 02:11 benjaminbhollon

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

tsmethurst avatar Nov 27 '23 12:11 tsmethurst