arowM / elm-html-extra-internal / Batchable.Html.Extra

Convenience functionality on Html

static : Html Basics.Never -> Html msg

Embedding static html.

The type argument Never in Html Never tells us that the html has no event handlers attached, it will not generate any messages. We may want to embed such static html into arbitrary views, while using types to enforce the staticness. That is what this function provides.

Note: To call this function, the argument need not be literally of type Html Never. It suffices if it is a fully polymorphic (in the message type) Html value. For example, this works: static (Html.text "abcdef").

nothing : Html msg

Render nothing.

A more idiomatic way of rendering nothing compared to using Html.text "" directly.

viewIf : Basics.Bool -> Html msg -> Html msg

A function to only render html under a certain condition

fieldView : Model -> Html Msg
fieldView model =
    div
        []
        [ fieldInput model
        , viewIf
            (not <| List.isEmpty model.errors)
            errorsView
        ]

viewIfLazy : Basics.Bool -> (() -> Html msg) -> Html msg

Just like viewIf except its more performant. In viewIf, the html is always evaluated, even if its not rendered. viewIfLazy only evaluates your view function if it needs to. The trade off is your view function needs to accept a unit type (()) as its final parameter

fieldView : Model -> Html Msg
fieldView model =
    div
        []
        [ fieldInput model
        , viewIf
            (not <| List.isEmpty model.errors)
            errorsView
        ]