Comments (3)
There is actually support for this via JavaScript:
Attribute that sets the color scheme via prefers-color-scheme
If you add that attribute to your DOM's body, the user's preferred color preference (if any) will be used to set the theme on the very first page load. Let me know if this solves your issue.
from halfmoon.
@qgustavor You may have the right idea. I will look more into this.
from halfmoon.
In those lines a "darkModeOn" cookie is set even on load if one is not already set. Would not be better setting this cookie only on user interaction? In this way if someone changes their color preference, the old one, stored in the cookie, would not be used.
In the way it's currently implemented the dark mode setting don't updates if someone changes the setting with the page already open. Some months ago I made an experiment on that: if a user changes browser/OS dark mode setting while the page is opened it will update automatically and it allows a per-website overwrite (demo). Sadly the way I implemented is not scalable - the CSS code needs to be duplicated to handle both media query based dark mode and per-website based dark mode - so I think it's not a good option for Halfmoon.
I think it's better to just add a note in the docs explaining that the dark mode is set in the page load (so changing "emulate CSS media feature..." will not update the page automatically) and that it will respect the prefers-color-scheme media query until the user overwrites this preference by calling halfmoon.toggleDarkMode()
someway (like the button in the example from the documentation or the keyboard shortcut).
from halfmoon.
Related Issues (20)
- Modal close event HOT 3
- Select does not work properly in mobile
- set color mode instead of toggle js HOT 2
- [Feature request] Put label before switch
- Sidebar, darkmode and modals are not automatically toggled as expected. HOT 5
- halfmoon doesn't support rtl? HOT 2
- require problem while using with sveltekit. HOT 1
- this.stickyAlerts is undefined HOT 1
- Will the project continue? HOT 2
- Text centering inside buttons
- Default sidebar with small screen results in offscreen content HOT 2
- Halfmoon documentation isn't available anymore HOT 37
- is this project dead? HOT 27
- Version update messed up page layout completely HOT 3
- Provide CSS only alternatives using Dialog and Popover API.
- CSS only form validation HOT 1
- Website is down HOT 1
- Typo in dropdowns page code snippet
- input type = date, just use this that way?
- Docs website for v1.x.x is down HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from halfmoon.