An Autocomplete component in Elm because typing is hard.
Code up a simple, static set of items for Autocomplete:
main : Signal Html.Html
main =
StartApp.Simple.start
{ model = Autocomplete.init [ "elm", "makes", "coding", "life", "easy" ]
, update = Autocomplete.update
, view = Autocomplete.view
}
Or make you a fetching, dynamic Autocomplete for great good:
fetchMoreItems : String -> Task Effects.Never (List String)
fetchMoreItems url =
Http.url url []
|> Http.getString
|> Task.toMaybe
|> Task.map responseToItems
responseToItems : Maybe String -> List String
responseToItems maybeString =
case maybeString of
Just string ->
String.lines string
Nothing ->
[]
getItemsTask : String -> Int -> Task Effects.Never (List String)
getItemsTask value index =
fetchMoreItems "https://raw.githubusercontent.com/first20hours/google-10000-english/master/20k.txt"
app =
let
config =
Autocomplete.Config.defaultConfig
|> Autocomplete.Config.setLoadingDisplay (img [ src "assets/loading.svg" ] [])
in
StartApp.start
{ init = Autocomplete.initWithConfig [] getItemsTask config
, update = Autocomplete.update
, view = Autocomplete.view
, inputs = []
}
main =
app.html
port tasks : Signal (Task.Task Never ())
port tasks =
app.tasks