mirror of
https://github.com/correl/elm-mdl.git
synced 2024-12-18 11:06:18 +00:00
Enables style to also handle custom attributes
This commit is contained in:
parent
03cb5fca28
commit
d05ca57a00
1 changed files with 20 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
module Material.Style
|
module Material.Style
|
||||||
( Style
|
( Style
|
||||||
, styled
|
, styled
|
||||||
, cs, cs', css, css'
|
, cs, cs', css, css', attrib
|
||||||
, stylesheet
|
, stylesheet
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ add to or remove from the contents of an already constructed class Attribute.)
|
||||||
@docs Style
|
@docs Style
|
||||||
|
|
||||||
# Constructors
|
# Constructors
|
||||||
@docs cs, cs', css, css'
|
@docs cs, cs', css, css', attrib
|
||||||
|
|
||||||
# Application
|
# Application
|
||||||
@docs styled
|
@docs styled
|
||||||
|
@ -41,9 +41,16 @@ import Html.Attributes
|
||||||
type Style
|
type Style
|
||||||
= Class String
|
= Class String
|
||||||
| CSS (String, String)
|
| CSS (String, String)
|
||||||
|
| Attr (String, String)
|
||||||
| NOP
|
| NOP
|
||||||
|
|
||||||
|
|
||||||
|
attrOf : Style -> Maybe (String, String)
|
||||||
|
attrOf style =
|
||||||
|
case style of
|
||||||
|
Attr attrib -> Just attrib
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
cssOf : Style -> Maybe (String, String)
|
cssOf : Style -> Maybe (String, String)
|
||||||
cssOf style =
|
cssOf style =
|
||||||
case style of
|
case style of
|
||||||
|
@ -75,10 +82,14 @@ Note that if you do specify `style`, `class`, or `classList` attributes in
|
||||||
-}
|
-}
|
||||||
styled : (List Attribute -> a) -> List Style -> List Attribute -> a
|
styled : (List Attribute -> a) -> List Style -> List Attribute -> a
|
||||||
styled ctor styles attrs =
|
styled ctor styles attrs =
|
||||||
|
let
|
||||||
|
styleAttrs = (List.filterMap attrOf styles)
|
||||||
|
|> List.map (\attrib -> Html.Attributes.attribute (fst attrib) ( snd attrib))
|
||||||
|
in
|
||||||
ctor
|
ctor
|
||||||
( Html.Attributes.style (List.filterMap cssOf styles)
|
( Html.Attributes.style (List.filterMap cssOf styles)
|
||||||
:: Html.Attributes.class (String.join " " (List.filterMap classOf styles))
|
:: Html.Attributes.class (String.join " " (List.filterMap classOf styles))
|
||||||
:: attrs
|
:: List.append attrs styleAttrs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,6 +114,12 @@ css : String -> String -> Style
|
||||||
css key value =
|
css key value =
|
||||||
CSS (key, value)
|
CSS (key, value)
|
||||||
|
|
||||||
|
{-| Add a custom attribute
|
||||||
|
-}
|
||||||
|
attrib : String -> String -> Style
|
||||||
|
attrib key value =
|
||||||
|
Attr (key, value)
|
||||||
|
|
||||||
|
|
||||||
{-| Conditionally add a CSS style to a component
|
{-| Conditionally add a CSS style to a component
|
||||||
-}
|
-}
|
||||||
|
|
Loading…
Reference in a new issue