aforemny/material-components-web-elm/3.0.2

NOTE: the latest version is 9.1.0

Material.IconToggle

Icon toggles allow users to take actions and make choices with a single tap.

Table of Contents

Resources

Basic Usage

import Material.IconToggle as IconToggle


type Msg
    = Clicked


main =
    IconToggle.iconToggle
        (IconToggle.config
            |> IconToggle.setOn True
            |> IconToggle.setOnChange Clicked
        )
        { offIcon = "favorite_outlined"
        , onIcon = "favorite"
        }

Configuration

type Config msg

Icon toggle configuration

Default icon toggle configuration

Configuration Options

setOnChange : msg -> Config msg -> Config msg

Specify a message when the user changes the icon toggle

setOn : Bool -> Config msg -> Config msg

Specify whether an icon toggle is on

setDisabled : Bool -> Config msg -> Config msg

Specify whether an icon toggle is disabled

Disabled icon buttons cannot be interacted with and have no visual interaction effect.

setLabel : Maybe String -> Config msg -> Config msg

Specify the HTML5 aria-label attribute of an icon toggle

setAttributes : List (Attribute msg) -> Config msg -> Config msg

Specify additional attributes

Icon Toggle

Icon toggles are a variant of icon buttons that change the icon when their state changes.

IconToggle.iconToggle
    (IconToggle.config |> IconToggle.setOn True)
    { offIcon = "favorite_border"
    , onIcon = "favorite"
    }
Config msg
-> { onIcon : String
, offIcon : String
}
-> Html msg

Icon toggle view function

On Icon Toggle

To set an icon toggle to its on state, set its setOn configuration option to True.

IconToggle.iconToggle
    (IconToggle.config |> IconToggle.setOn True)
    { offIcon = "favorite_border"
    , onIcon = "favorite"
    }

Disabled Icon Toggle

To disable an icon toggle, set its setDisabled configuration option to True. Disabled icon buttons cannot be interacted with and have no visual interaction effect.

IconToggle.iconToggle
    (IconToggle.config |> IconToggle.setDisabled True)
    { offIcon = "favorite_border"
    , onIcon = "favorite"
    }

Labeled Icon Toggle

To set the HTML5 arial-label attribute of an icon toggle, use its setLabel configuration option.

IconToggle.iconToggle
    (IconToggle.config
        |> IconToggle.setLabel (Just "Add to favorites")
    )
    { offIcon = "favorite_border"
    , onIcon = "favorite"
    }