styled-ppx icon indicating copy to clipboard operation
styled-ppx copied to clipboard

Allow an empty %css rule?

Open davesnx opened this issue 3 years ago • 0 comments

I often find myself wanting to add some rules conditionally. Because I often use switch statement, (but it's true for ifs as well), all branches should have the same type. Because of that, I find myself with a need to add a property as a default value on the other side.

Example


let margin = (isLeft) =>
  switch isLeft {
  | true => %css("margin-left: 10px;")
  | false => %css("")
  }

module Component = %styled.div([
  %css("background-color: red;"),
  %css("border-radius: 20px;"),
  %css("box-sizing: border-box;"),
  margin(All),
])

%css("") is an invalid rule, since it's defined to not accept empty declarations.

In order to solve that I have 2 ideas:

  1. Support empty declarations on %css extension
  2. Create an %css.empty that transforms into an empty rule, such as CssJs.unsafe("", "")

Conclusion

Not particularly fan of either, that's why I open the issue. Both have problems of discovery and aren't obvious.

davesnx avatar Jul 29 '22 10:07 davesnx