aforemny/material-components-web-elm/1.0.1

NOTE: the latest version is 9.1.0

Material.Switch

Switches toggle the state of a single setting on or off. They are the preferred way to adjust settings on mobile.

Table of Contents

Resources

Basic Usage

Note that switches are usually used in conjunction with form fields. Refer to FormField for more information.

import Material.Switch exposing (switch, switchConfig)


type Msg
    = SwitchClicked


main =
    switch
        { switchConfig
            | on = True
            , onClick = Just SwitchClicked
        }

Switch

switch : SwitchConfig msg -> Html msg

Switch view function

type alias SwitchConfig msg =
{ checked : Bool
, disabled : Bool
, additionalAttributes : List (Attribute msg)
, onClick : Maybe msg
}

Configuration of a switch

switchConfig : SwitchConfig msg

Default configuration of a switch

On Switch

To set the state of a switch, set its on configuration field to a Bool value.

switch { switchConfig | on = True }

Disabled Switch

To disable a switch, set its disabled configuration field to True. Disabled switches cannot be interacted with and have no visual interaction effect.

switch { switchConfig | disabled = True }