countdown icon indicating copy to clipboard operation
countdown copied to clipboard

Implementing `choose_light_or_dark()` outside of R

Open coatless opened this issue 2 years ago • 2 comments

In the R version of {countdown}, there's a quick comparison of values to select either a dark or light color value depending on what a user specifies. The relevant functions being used in R for this decision are from {prismatic}:

With #36, the CSS countdown variables now have a darkening characteristic applied:

https://github.com/gadenbuie/countdown/blob/9ee6b7fa18aadc3540031184d72a812abcd85381/lib/countdown.css#L4

From discussions in #35 we have:

I went with shading (darkening) in the CSS, but we could have tinted (lightend) as well with rgba(255, 255, 255, 0.1) or similar.

The question is how we'd know whether we should lighten or darken. But I'm okay waiting on that as well and working it out in follow up PRs.

If the CSS property color-contrast was implemented in browsers, then this would be a non-issue.

Options in the interim: JavaScript? Re-implement {prismatic} in the different languages? Wait for browser updates?

coatless avatar Feb 04 '24 04:02 coatless

In Python, two popular packages we could use appear to be:

  1. colour
  2. basic-colormath

In Quarto, I need to play with the shortcode a little more, but I have the sense we could address this with a class, like .dark. The current assumption in the CSS is that we have dark text on a light background, and a .dark class could flip that around. Those would only work for people who only want to pick three-four colors for the states, otherwise they'd have to specify all the colors. That seems like a reasonable compromise to me.

gadenbuie avatar Feb 05 '24 18:02 gadenbuie

@gadenbuie okidokie, I like both options!

Any thoughts as to the quarto-specific parameter option? color_darken: true?

Do you have any preference on the Python package? Glancing at py-htmltools, neither package suggested is being used.

https://github.com/posit-dev/py-htmltools/blob/a3a98259ee4c5164763a6f70b86e531c13a5bcc1/pyproject.toml#L30-L33

So, going over to usage statistics, we have:

Glancing at dependencies, we also have:

Lastly, for releases, we have:

  • colour: Nov 19, 2017 with version 0.1.5
  • basic-colormath: May 1, 2023 with version 0.1.0

Maybe we opt for basic-colormath over colour as we don't need that extensive of features?

coatless avatar Feb 06 '24 12:02 coatless