mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-11-28 18:24:04 +03:00
Add V2 of html extra attributes'
This commit is contained in:
parent
6a7c6c2f02
commit
06651d8292
40
src/Nri/Ui/Html/Attributes/V2.elm
Normal file
40
src/Nri/Ui/Html/Attributes/V2.elm
Normal 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
|
Loading…
Reference in New Issue
Block a user