Feature request: add attributes retroactively
staeter opened this issue · 1 comments
staeter commented
I find myself wanting to add attributes to an element I've initiated in an other function quite often.
addAttributes : List (Element.Attribute msg) -> Element msg -> Element.msg
It would be useful whenever you want to overwrite some attributes
redButton =
Element.Input.button
[ Element.Background.color (Element.rgb 1 0 0) ]
{...}
blueButton =
addAttributes [ Element.Background.color (Element.rgb 1 0 0) ] redButton
Also when you want to move it around without encapsulating it and adding a parent in between
movedButton topLeft =
addAttributes [ Element.moveDown point.y, Element.moveRight point.x ] redButton
z5h commented
You can already do something like this:
withAttributes :
List (Element.Attribute msg)
-> (List (Element.Attribute msg) -> a)
-> (List (Element.Attribute msg) -> a)
withAttributes attributes constructor =
\newAttributes ->
constructor (newAttributes ++ attributes)
and then
redButton =
Input.button |> withAttributes [ Background.color (Element.rgb 1 0 0) ]
redBorderedButton =
redButton
|> withAttributes
[ Border.width 1
, Border.color (Element.rgb 1 0 0)
]