danielnarey/elm-modular-ui/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Ui.Selector

UI Element: Selector

In an Elm program, option selection is handled by the program's update function. The constructors in this module automate part of the set-up for capturing input from selectors. They also provide built-in web accessibility features and default styling via Bulma element classes.

msg
-> { id : Int
, label : String
, checked : Bool
}
-> Element msg

Construct a checkbox that sends update messages like a button

  • To make the checkbox work as intended, the update function should handle the message by toggling a boolean value in the program's model (see example)

    --- MODEL ---

    type alias Model = { userAgrees : Bool , ... }

    initial : Model initial = { userAgrees = False , ... }

    --- UPDATE ---

    type Msg = ToggleUserAgrees | ...

    update : Msg -> Model -> Model update msg model = case msg of ToggleUserAgrees -> { model | userAgrees = model.userAgrees |> Basics.not }

      ...

    --- VIEW ---

    { id = 9 , label = "I agree to the terms and conditions" , checked = model.userAgrees } |> Ui.Selector.checkbox ToggleUserAgrees

  • HTML tag: <label> > <input type="checkbox" />

  • ARIA role: checkbox (default for checkbox input)

  • Element class: .checkbox

  • Available modifiers: none

  • Bulma CSS reference: https://bulma.io/documentation/form/checkbox/

(a -> msg)
-> { id : Int
, options : List ( String, a )
, selected : a
}
-> List (Element msg)
--- MODEL ---


type EmailFrequency
  = Daily
  | Weekly
  | Monthly


type alias Model =
  { emailFrequency : EmailFrequency
  , ...
  }


--- UPDATE ---


type Msg
  = UpdateEmailFrequency EmailFrequency
  | ...


update : Msg -> Model -> Model
update msg model =
  case msg of
    UpdateEmailFrequency option ->
      { model
      | emailFrequency = option
      }


    ...


--- VIEW ---


{ id = 10
, options =
  [ ("Every day", Daily)
  , ("Every week", Weekly)
  , ("Every month", Monthly)
  ]


, selected = model.emailFrequency
}
  |> Ui.Selector.radioButtons UpdateEmailFrequency
  • HTML tag: List of label > <input type="radio" />
  • ARIA role: radio (default for radio input)
  • Element class: .radio
  • Available modifiers: none
  • Bulma CSS reference: https://bulma.io/documentation/form/radio/