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

Adding system agnostic dark mode without js #1195

Closed
hibatos opened this issue Jul 19, 2024 · 3 comments
Closed

Adding system agnostic dark mode without js #1195

hibatos opened this issue Jul 19, 2024 · 3 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@hibatos
Copy link

hibatos commented Jul 19, 2024

Hi,
first of all, awesome project, thanks for that.
But for all the praise I too have an improvement idea.

The current dark mode implementation purely bases on javascript execution in the browser.
This is a bit unfortunate, as some frameworks or tools such as SvelteKit expressly define themselves as being useable without frontend js execution.

This could be fixed rather easily by changing the dark mode configuration in the tailwind config from this:

...
const config = {
	darkMode: ["class"], // from this
	content: ["./src/**/*.{html,js,svelte,ts}"],
	safelist: ["dark"],
	theme: {
...

to this

...
const config = {
	darkMode: ['variant', [                                                //
             '@media (prefers-color-scheme: dark) { &:not(.light *) }',        // to this
             '&:is(.dark *)'                                                   //
 	]],
	content: ["./src/**/*.{html,js,svelte,ts}"],
	safelist: ["dark"],
	theme: {
...

as mentioned in the tailwind docs: https://tailwindcss.com/docs/dark-mode#using-multiple-selectors

As far as my testing goes, this does not have any adverse effects.

Regards
hibatos

@hibatos hibatos added the type: feature Introduction of new functionality to the application label Jul 19, 2024
@ieedan
Copy link
Contributor

ieedan commented Jul 19, 2024

I don't think this library is usable without JavaScript.

@hibatos
Copy link
Author

hibatos commented Jul 19, 2024

I don't think this library is usable without JavaScript.

Right, I have not thought of that...
I disabled js for testing and the rendering looked mostly fine, the functionality was limited, sure, but most still worked.

If people here don't use this feature, the request might be irrelevant.

Although I do think this is a more sane solution for doing the system default theme query in general.

@huntabyte
Copy link
Owner

I'm pretty sure JS would be required to get all the functionality that mode-watcher provides, which extends beyond just the system. This is great but doesn't cover the conversion of scrollbars and other native elements into the "application selected" theme, so you may end up with light-mode scrollbars on a dark-mode app and vice versa.

You can feel free to implement this yourself in your apps though! mode-watcher isn't forced on you to use, just there if you wish!

@huntabyte huntabyte closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

3 participants