Buttons allow users to take actions and make choices with a single tap.
import Material.Button as Button
type Msg
= Clicked
main =
Button.text
(Button.config |> Button.setOnClick Clicked)
"Text"Default configuration of a button
Specify a message when the user clicks a button
Specify whether the button features an icon
Specify whether a button's icon is a trailing icon.
Trailing icons are displayed after the button's label rather than before.
Specify whether the button is disabled
Disabled buttons cannot be interacted with and do not have no visual interaction effect.
Specify whether a button is dense
Dense buttons feature smaller than normal padding.
Specify whether a button is a link button.
Link buttons behave like normal HTML5 anchor tags. Note that link buttons cannot be disabled and ignore that configuration option.
Specify the target for a link button.
Note that this configuration option will be ignored by buttons that do not also
set setHref.
Specify additional attributes
Buttons may appear in different variants. Use text or outlined if you want
a button that is flush with the surface, and use raised or unelevated for a
button that is contained.
Text button variant (flush without outline)
Outlined button variant (flush with outline)
Raised button variant (contained with elevation)
Unelevated button variant (contained without elevation)
To add an icon to a button, use its setIcon configuration option to specify
the name of a Material Icon. If you want the icon
to be positioned after the button's label, also set the setTrailingIcon
configuration option to True.
Button.text
(Button.config |> Button.setIcon (Just "favorite"))
"Like"Button.text
(Button.config
|> Button.setIcon (Just "favorite")
|> Button.setTrailingIcon True
)
"Like"To disable a button, use its setDisabled configuration option. Disabled
buttons cannot be interacted with and have no visual interaction effect.
Button.text
(Button.config |> Button.setDisabled True)
"Disabled"To make a button's text and container margins slightly smaller, use its setDense
configuration option.
Button.text
(Button.config |> Button.setDense True)
"Dense"To make a button essentially behave like a HTML anchor element, use its
setHref configution option. You may use its setTarget configuration option
to specify a target.
Button.text
(Button.config
|> Button.setHref (Just "https://elm-lang.org")
)
"Visit"Note that link buttons cannot be disabled.
You may programatically focus a button by assigning an id attribute to it and
use Browser.Dom.focus.
Button.text
(Button.config
|> Button.setAttributes
[ Html.Attributes.id "my-button" ]
)
"Button"
Configuration of a button