Skip to content

Instantly share code, notes, and snippets.

@freakingawesome
Last active June 1, 2016 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save freakingawesome/875fbad5d4f8c5f1d982 to your computer and use it in GitHub Desktop.
Save freakingawesome/875fbad5d4f8c5f1d982 to your computer and use it in GitHub Desktop.
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