Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add attributes retroactively #339

Open
staeter opened this issue Mar 14, 2022 · 1 comment
Open

Feature request: add attributes retroactively #339

staeter opened this issue Mar 14, 2022 · 1 comment

Comments

@staeter
Copy link

staeter commented Mar 14, 2022

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
@staeter staeter changed the title Feature: add attributes to an element Feature request: add attributes to an element Mar 14, 2022
@staeter staeter changed the title Feature request: add attributes to an element Feature request: add attributes retroactively Mar 14, 2022
@z5h
Copy link

z5h commented Mar 19, 2022

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)
            ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants