r/javascript • • Jun 18 '20

Don't model dark mode with a boolean

https://dev.to/sebastienlorber/insight-4-don-t-model-dark-mode-with-a-boolean-ol1
2 Upvotes

15 comments sorted by

21

u/SocialAnxietyFighter Jun 18 '20

Doing things for future-proofness is rarely worth the extra implementation time and complexity in my experience. We are very bad at forecasting what the future will bring and the best solution IMO is to have it be well-built for the present or what you're 99.99% sure that will happen the coming months.

2

u/sebastienlorber Jun 18 '20

it's not extra implementation, it's just "choice": "light"/"dark" instead of true/false

2

u/SocialAnxietyFighter Jun 18 '20

Yeah but all these small changes do add up

6

u/Snapstromegon Jun 18 '20

First, I think this post belongs in r/webdev, because it's mainly about CSS and second I disagree with the author on his negation point. Best would be to use default styling and to use media queries to alter that default. That way you also support browser without support for those queries.

1

u/sebastienlorber Jun 18 '20

I probably didn't explain well my thoughts, but what I talk about is not specifically related to css.

More context here, where I try to find the best config option for a popular static site generator for documentation. https://github.com/facebook/docusaurus/pull/2939

In such context it's important to get the api right if we don't want to introduce breaking changes in the future to all our users.

1

u/Snapstromegon Jun 18 '20

In that case yes, it also includes JS. Nevertheless I think r/webdev would've been a better place for this.

16

u/Eggy1337 Jun 18 '20

This article is so stupid.

-2

u/Eggy1337 Jun 18 '20 edited Jun 18 '20
  1. No one in their right mind is using media queries which aren't widely supported without a fallback.

  2. No one in negating possibility of new values for this query. If they will be added to the spec and impement by browser vendors, people will adjust to it.

  3. Hacky solutions to setting color scheme shouldn't be supported by browsers.

  4. People will name their blog posts whatever they like.

  5. Value for this media query is literally "light | dark" in spec which you queted(!).

1

u/sebastienlorber Jun 18 '20

You focus too much on the css.

I probably didn't explain well my thoughts, but what I talk about is not specifically related to css.

More context here, where I try to find the best config option for a popular static site generator for documentation. https://github.com/facebook/docusaurus/pull/2939

In such context it's important to get the api right if we don't want to introduce breaking changes in the future to all lib users.

If you look at libs adding dark mode support you'll notice that they first name the lib like gatsby-dark-mode-plugin and expose the Conf as a boolean. I think this is a mistake, but yeah probably not a big deal.

1

u/Eggy1337 Jun 18 '20

Obviously those authors are limiting themselves to dark mode this way, but it doesn't break anything if more options are added to the spec later.

If you want to be more future proof going with original name is never a bad choice, like gatsby-prefers-color-scheme-plugin

And well, if they took that npm name and implemented it with boolean, you can always send PR.

1

u/sebastienlorber Jun 19 '20

Supporting color modes is not necessarily only a css thing. It does not have to be 100 in sync with thisediz query.

You can send PR for sure but a config breaking change is annoying where your project is used by thousands of users like it's the case here

1

u/ilovevue Jun 18 '20 edited Oct 10 '24

yam screw threatening noxious alleged shocking sort desert marble childlike

This post was mass deleted and anonymized with Redact

1

u/Eggy1337 Jun 18 '20

That's a mistake, I should've said media features(https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#Media_features)

prefers-color-scheme is not supported in old edge for instance.

1

u/ilovevue Jun 18 '20 edited Oct 10 '24

existence teeny dolls rustic retire degree quack gaze cagey enjoy

This post was mass deleted and anonymized with Redact