Skip to content

Instantly share code, notes, and snippets.

@ryan-senn
Created December 4, 2016 02:21
Show Gist options
  • Save ryan-senn/393aa768c9ea96cc48bb387433b4297b to your computer and use it in GitHub Desktop.
Save ryan-senn/393aa768c9ea96cc48bb387433b4297b to your computer and use it in GitHub Desktop.
module Common.LoadingButton exposing (loadingButton)
import Html exposing (Html, button, span, text)
import Html.Events exposing (onClick)
import Html.Attributes exposing (classList)
import Msg exposing (Msg)
loadingButton : String -> String -> Bool -> Msg.Msg -> Html Msg.Msg
loadingButton buttonText glyph isLoading onClickMsg =
let
glyphiconClasses =
[ ("glyphicon", True)
, ("glyphicon-" ++ glyph, not isLoading)
, ("glyphicon-refresh", isLoading)
, ("spin", isLoading)
]
buttonClasses =
[ ("btn", True)
, ("btn-success", True)
, ("pull-right", True)
, ("disabled", isLoading)
]
onClickMsg_ =
case isLoading of
True -> Msg.NoOp
False -> onClickMsg
in
button [ onClick onClickMsg_, classList buttonClasses ]
[ span [ classList glyphiconClasses ] []
, text <| " " ++ buttonText
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment