Add V2 of html extra attributes'

This commit is contained in:
Tessa Kelly 2018-06-15 09:02:45 -07:00
parent 6a7c6c2f02
commit 06651d8292

View File

@ -0,0 +1,40 @@
module Nri.Ui.Html.Attributes.V2 exposing (includeIf, none)
{-| Extras for working with Html.Attributes.
This is the new version of Nri.Ui.Html.Attributes.Extra.
@docs none, includeIf
-}
import Html.Styled exposing (Attribute)
import Html.Styled.Attributes as Attributes
import Json.Encode as Encode
{-| Represents an attribute with no semantic meaning, useful for conditionals.
This is implemented such that whenever Html.Attributes.Extra.none is encountered
by VirtualDom it will set a meaningless property on the element object itself to
null:
domNode['Html.Attributes.Extra.none'] = null
It's totally safe and lets us clean up conditional and maybe attributes
-}
none : Attribute msg
none =
Attributes.property "Html.Attributes.Extra.none" Encode.null
{-| conditionally include an attribute. Useful for CSS classes generated with
`UniqueClass`!
-}
includeIf : Bool -> Attribute msg -> Attribute msg
includeIf cond attr =
if cond then
attr
else
none