module MappedInput exposing (..)
import Html exposing (Html, Attribute, select, text, input, option, select, div, span)
import Html.Events exposing (on, onInput)
import Html.Attributes exposing (name, value, disabled, selected, class)
import Json.Decode as Decode
import Validated exposing (Validated(..))
textInput : (String -> msg) -> Validated String String -> List (Html msg)
textInput tagger value =
case value of
Clean -> [ input [ class "input", onInput tagger ] [ ] ]
Valid x -> [ input [ class "input", onInput tagger ] [ text x ] ]
Invalid x error -> [ input [ class "input is-danger", onInput tagger ] [ text x ]
, span [ class "help is-danger" ] [ text error ]
]
selectInput : (Int -> msg) -> List String -> List (Html msg)
selectInput tagger options =
let
f index x = option [ value (toString index) ] [ text x ]
firstOption = option [ disabled True, selected True ] [ text "Please select" ]
rest = List.indexedMap (f) options
in
[ span [ class "select" ]
[ select [ onChange tagger ] <| [ firstOption ] ++ rest ]
]
onChange : (Int -> msg) -> Html.Attribute msg
onChange tagger =
on "change" <| Decode.map tagger <| Decode.at ["target", "selectedIndex"] Decode.int