Skip to content

How to make it work with tailwindcss (add to the wiki) #20

@rolojf

Description

@rolojf

First of all, thanks for this Andrew.

I want to share some code that I think It's working for me.
Please consider (after making any changes you think necessary) making it available for others on the wiki, or readme or any where you see fit.
I know you give concise instructions about this, in the documentation.
But having this code available, might save some time and make it easy to adopt this package.

The code is about using Simple.Animation.Animated.custom with the packages: rffeldman/elm-css and matheus23/elm-default-tailwind-modules.

Here is it:

import Html.Styled as Htmls exposing (Html, div, text)
import Html.Styled.Attributes as Attr exposing (class, css)
import Tailwind.Utilities as Tw


animaStyleNode :
    (List (Htmls.Attribute msg) -> List (Htmls.Html msg) -> Htmls.Html msg)
    -> Animation
    -> List (Htmls.Attribute msg)
    -> List (Htmls.Html msg)
    -> Htmls.Html msg
animaStyleNode node animation attributes children =
    Animated.custom
        (\className stylesheet ->
            node
                (class className :: attributes)
                (Htmls.node
                    "style"
                    []
                    [ text stylesheet ]
                    :: children
                )
        )
        animation

htmlsExample : Htmls.Html msg
htmlsExample =
    animaStyleNode div
        flash
        [ css [ Tw.text_white, Tw.text_center, Tw.mx_4, Tw.p_6 ] ]
        [ text "I'm animating!" ]

flash : Animation
flash =
    Animation.steps
        { startAt = [ P.opacity 0, P.backgroundColor "#0382c8" ]
        , options = [ Animation.loop ]
        }
        [ Animation.step 1000 [ P.opacity 1, P.backgroundColor "rgb(19 228 187)" ]
        , Animation.step 1000 [ P.opacity 0, P.backgroundColor "#0382c8" ]
        ]

I think this way of styling (with tailwindcss) is gaining momentum.
A am also very interested in seeing what changes you would make to the code.

Regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions