Convenience functionality on
Html.Styled
static : Html.Styled.Html Basics.Never -> Html.Styled.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.Styled.text "abcdef")
.
nothing : Html.Styled.Html msg
Render nothing.
A more idiomatic way of rendering nothing compared to using
Html.Styled.text ""
directly.
viewIf : Basics.Bool -> Html.Styled.Html msg -> Html.Styled.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.Styled.Html msg) -> Html.Styled.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
, viewIfLazy
(not <| List.isEmpty model.errors)
(\() -> errorsView)
]
viewMaybe : (a -> Html.Styled.Html msg) -> Maybe a -> Html.Styled.Html msg
Renders Html.Styled.nothing
in case of Nothing, uses the provided function in case of Just.
viewMaybePost : Maybe Post -> Html Msg
viewMaybePost maybePost =
viewMaybe viewPost maybePost
viewPost : Post -> Html Msg