Last active
June 1, 2016 22:05
-
-
Save freakingawesome/875fbad5d4f8c5f1d982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
import StartApp.Simple as StartApp | |
import Signal exposing (..) | |
import Effects exposing (Never) | |
import Task | |
import Keyboard | |
import Char | |
import String exposing (..) | |
type alias Model = | |
{ value : String | |
, words : List String | |
} | |
initialModel : Model | |
initialModel = | |
{ value = "" | |
, words = | |
[ "chair", "sofa", "table", "stove", "cabinet", "tv", "rug", "radio", "stereo" ] | |
} | |
main = | |
StartApp.start | |
{ model = initialModel | |
, view = view | |
, update = update | |
} | |
title : String -> Html | |
title message = | |
message | |
|> Html.text | |
pageHeader : Html | |
pageHeader = | |
h1 | |
[ ] | |
[ title "Hello" ] | |
pageFooter : Html | |
pageFooter = | |
footer | |
[ ] | |
[ a [ href "#" ] | |
[ text "Hello" ] | |
] | |
inputField : Address Action -> Html | |
inputField address = | |
input | |
[ type' "text" | |
, on "input" targetValue (Signal.message address << SetValue) | |
] | |
[ ] | |
view : Address Action -> Model -> Html | |
view address model = | |
div | |
[ id "container" ] | |
[ pageHeader | |
, inputField address | |
, autocomplete model | |
, pageFooter | |
] | |
autocomplete model = | |
let | |
matches = | |
List.filter (startsWith model.value) model.words | |
in | |
div [] | |
[ div [] [ text <| "Autocomplete input: " ++ model.value ] | |
, div [] [ text "Autocomplete matches: " ] | |
, div [] <| List.map (\w -> div [] [ text w ]) matches | |
] | |
type Action | |
= SetValue String | |
update action model = | |
case action of | |
SetValue value -> | |
{ model | value = value } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment