rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
213 stars 67 forks source link

fix(css): Don't modify CSS custom properties #402

Closed gadenbuie closed 10 months ago

gadenbuie commented 10 months ago

Fixes #397

In the CSS spec, custom properties have to start with -- and thereafter any character is allowed and is used literally: https://www.w3.org/TR/css-variables-1/#defining-variables

This PR updates css() to avoid making any changes to CSS properties in any way, while still conveniently converting camelCase, snake_case and dot.case properties (those that don't start with --) to kebab-case.

css(
  font_size = "12px",
  "--_color" = "red",
  "--is_color" = "true",
  "--thisValueIs" = 42
)
#> [1] "font-size:12px;--_color:red;--is_color:true;--thisValueIs:42;"