Each and every widget can be customized by modifying the Style Type.
{- Make a button fill the full width -}
Widget.textButton
( Material.containedButton
|> Customize.element [Element.width Element.fill]
)
{ onPress = Just PressedButton
, text = "Press Button"
}A simple style type would be the following:
type alias MyStyle =
{ element : List (Attribute msg) }
myWidget : MyStyle -> Element msg
myWidget style =
Element.el style.element <| Element.noneA styling for a simple Elm-Ui button would be like this:
type alias MyStyle =
{ elementButton : List (Attribute msg) }
myWidget : MyStyle -> Element msg
myWidget style =
Element.button style.elementButton
{ onPress = Just Something
, label = Element.none
}We can also style the content of an element.
type alias MyStyle =
{ element : List (Attribute msg)
, content : List (Attribute msg)
}
myWidget : MyStyle -> Element msg
myWidget style =
Element.el style.element <|
Element.el style.content <|
Element.noneIf the content is just a text (or paragraph), then we use contentText instead:
type alias MyStyle =
{ element : List (Attribute msg)
, contentText : List (Attribute msg)
}
myWidget : MyStyle -> Element msg
myWidget style =
Element.el style.element <|
Element.text style.contentText <|
"Hello World"If some content is in front, we use contentInFront:
type alias MyStyle =
{ element : List (Attribute msg)
, content : List (Attribute msg)
, contentInFront : List (Attribute msg)
}
myWidget : MyStyle -> Element msg
myWidget style =
Element.el
(style.element
++ [ Element.contentInFront <|
Element.el style.contentInFront <|
Element.none
]
)
<|
Element.el style.contentInFront <|
Element.noneWe can include styling that depends on some state.
type alias MyStyle =
{ element : List (Attribute msg)
, ifDisabled : List (Attribute msg)
, otherwise : List (Attribute msg)
}
myWidget : MyStyle -> Bool -> Element msg
myWidget style isDisabled =
Element.el
(style.element
++ (if isDisabled then
style.ifDisabled
else
style.otherwise
)
)
<|
Element.none