Giter Club home page Giter Club logo

Comments (3)

halfmoonui avatar halfmoonui commented on July 26, 2024 6

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.

halfmoonui avatar halfmoonui commented on July 26, 2024 1

@qgustavor You may have the right idea. I will look more into this.

from halfmoon.

qgustavor avatar qgustavor commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.