styled-ppx
styled-ppx copied to clipboard
Allow an empty %css rule?
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:
- Support empty declarations on
%cssextension - 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.