Live data from Hacker News

Show HN: Darken – Darkmode Made Easy

github.com

11–20 of 61 posts

Re: Show HN: Darken – Darkmode Made Easy

#11
Speaking of dark mode. How bizarre is it that after all this time Apple finally puts something in iOS, and IT JUST MADE THINGS WORSE.

In the beginning there was invert colors. Then came smart invert - it worked with some things, failed with others, but was generally pretty good.

Dark mode (by way of prefers-color-scheme etc) should make things awesome in the long run, but at least for now all that's happened is to keep things dark I have to juggle fucking THREE different switches - and end up having to fall back to classic invert most of the time. Smart invert basically stopped functioning with iOS 13.

Properly implemented they could've had a fallback css override a la DarkReader and just put an extra switch per-website, crowdsourcing the results, as well as keep their own database/system override for lazy developers with already-dark apps who refuse to respect wishes (nudge nudge, Spotify...).

Ok, this is ranty, but this is such a weird regression touted as a "feature". Poor form.

Re: Show HN: Darken – Darkmode Made Easy

#13

Do you do anything different to other libraries like dark mode.js? https://github.com/sandoche/Darkmode.js

Darkmode.js uses `mix-blend-mode` to invert the colors on the pages and offer a class based custom style system.

Here you also have the class based custom styles but also have a CSS variables based styling system. You can chose what value will take a variable depending on the current state of the darkmode.

See the readme of the github page for more informations, ask again if you need additional informations.

Re: Show HN: Darken – Darkmode Made Easy

#16
post #12

I think a before and after screenshot, with minimal configuration, would help to understand what it does, and see the "quality" of the results.

It has a demo page, "hidden" in the repo's description but not in README.md:

https://colinespinas.github.io/darken/

Re: Show HN: Darken – Darkmode Made Easy

#17
post #16
post #12

I think a before and after screenshot, with minimal configuration, would help to understand what it does, and see the "quality" of the results.

It has a demo page, "hidden" in the repo's description but not in README.md: https://colinespinas.github.io/darken/

You have a badge "Demo Available" too, I'll maybe do a more clear link.

Re: Show HN: Darken – Darkmode Made Easy

#18
OK, but from a designer's perspective, you want to be careful with just inverting colours. The contrast is way too strong here from the demo you offered and the visited link 'purple' is already bleeding on black.

Have a read of an article such as this one, and be smart about colour translation. You might need to calculate contrast or offer a contrast setting as a minimum, and watch for shadows.

https://uxdesign.cc/turn-the-lights-off-designing-the-dark-m...

Side note: I've been really happy with the "Dark Reader" plugin on various browsers. Have a look at it and see how it handles brightness (+/-) and contrast (+/-).

Re: Show HN: Darken – Darkmode Made Easy

#19
post #18

OK, but from a designer's perspective, you want to be careful with just inverting colours. The contrast is way too strong here from the demo you offered and the visited link 'purple' is already bleeding on black. Have a read of an article such as this one, and be smart about colour translation. You might need to calculate contrast or offer a contrast setting as a minimum, and watch for shadows. https://uxdesign.cc/tu…

This API do not invert colors, it uses CSS variables and classes for more customization. No mix-blend-mode or anything. The demo has been done quickly this afternoon, I'll probably change it for the next version.

Re: Show HN: Darken – Darkmode Made Easy

#20
The actual code behind this is short and straightforward: https://github.com/ColinEspinas/darken/blob/master/src/index.... For myself, I think it gets the balance of complexity wrong: it focuses on shifting various things into JavaScript, rather than doing it all in CSS using the (prefers-color-scheme) media query, and rewriting media queries to achieve manual switching.

As a demonstration of the alternative approach I advocate, see what I came up with for my own website: https://chrismorgan.info/blog/dark-theme-implementation/. This uses native CSS techniques, working completely without JavaScript, merely using JavaScript to allow the user to manually switch, retaining that preference for future page loads and optimising page loading just about as far as is possible when doing it client-side to minimise the probability of a flash of inverted content if you manually switched to the opposite of what (prefers-color-scheme) would have chosen.

The main thing that my approach doesn’t do that this thing does is dispatching an event, so that other JavaScript could conveniently be notified of a theme change. This is fairly deliberate on my part (I deliberately do all theme switching with CSS, and have no JavaScript that needs to change anything for dark mode), but could readily be added to what I wrote if desired.

With my approach (for which I will also clarify that the JavaScript is deliberately written for compactness, not some theoretical notion of maintainability or extensibility), the example:

  Toggle darkmode
  
    const darkmode = new darken({
      toggle: "#dm-toggle",
      variables: {
        "--primary-color": ["#ffffff", "#000000"],
        "--secondary-color": ["#000000", "#ffffff"],
      }
    });
  
… would be written more like this:

  
    // (Add the button to the document in JS,
    // since it’ll only work if this JS runs anyway.)
  
  
    body {
      --primary-color: #ffffff;
      --secondary-color: #000000;
    }
  
  
    body {
      --primary-color: #000000;
      --secondary-color: #ffffff;
    }
  
(Two style blocks because my thing doesn’t deal with `@media … { … }` inline in CSS, because I don’t need it. You could make it do it if you really wanted to.)

I find this approach much more manageable, and it allows adding custom CSS rules for dark mode (which I definitely use), rather than just setting CSS custom properties.

Post reply on HN