4 ms·
You can also `import Html.Attributes as Attr` and do `Attr.style "foo" "bar"`, or `import Html.Attributes exposing (style)` and do `style "foo" "bar"`. Or, you
by nateabele 5y ago
You can also `import Html.Attributes as Attr` and do `Attr.style "foo" "bar"`, or `import Html.Attributes exposing (style)` and do `style "foo" "bar"`.
Or, you know, since it's a composable ML-style functional language, you can grab a package like elm-css[0] and do:
makeRectangle answer =
div
[ css
[ width (px 140)
, height (px 100)
, marginTop (px 10)
, paddingTop (px 5)
, paddingLeft (px 5)
, backgroundColor (getColor (Tuple.second answer))
, border3 (px 5) solid black
]
]
[
...
]
...which gives you full compile-time type-checked styles with a no-crash guarantee. Can Clojure Spec give you the same in your example above?
Incidentally, it's also less noisy than the equivalent block of Clojure code. Elm isn't perfect, and definitely gets verbose at points, but if you're going to criticize, make an informed comparison.
[0] https://package.elm-lang.org/packages/rtfeldman/elm-css/latest/Css https://package.elm-lang.org/packages/rtfeldman/elm-css/late...