Skip to content

Instantly share code, notes, and snippets.

@evancz
Created August 4, 2016 07:00
Show Gist options
  • Save evancz/bd916b9e4b48efbdb095b5fa9f09f6cf to your computer and use it in GitHub Desktop.
Save evancz/bd916b9e4b48efbdb095b5fa9f09f6cf to your computer and use it in GitHub Desktop.
module Autocomplete exposing
( State
)
{-|
-}
type State
empty : State
reset : State -> State
-- SIMPLE
update : Msg -> State -> (State, Maybe String)
view : Int -> State -> List String -> Html Msg
-- CUSTOM
type Msg
type UpdateConfig msg
customUpdate : UpdateConfig msg -> Msg -> State -> (State, Maybe msg)
customView : ViewConfig a -> Int -> State -> List a -> Html Msg
type ViewConfig a
defaultViewConfig : ViewConfig String
customViewConfig : (a -> String) -> ViewConfig a
veryCustomViewConfig
: { toId : a -> String
, ul : List (Attribute Never)
, li : Bool -> a -> HtmlDetails Never
}
-> ViewConfig a
module Autocomplete exposing
( State
)
-- MODEL
type State =
State
{ key : Maybe String
, mouse : Maybe String
}
empty : State
empty =
State { key = Nothing, mouse = Nothing }
reset : State -> State
reset (State { key, mouse }) =
State { key = Nothing, mouse = mouse }
-- UPDATE
type Msg
= KeyChange String
| WentTooLow
| WentTooFar
| MouseEnter String
| MouseLeave String
| MouseClick String
type alias UpdateConfig msg =
{ onKeyDown : KeyCode -> Bool
, onChoose : String -> msg
, onTooLow : Maybe msg
, onTooHigh : Maybe msg
}
update : UpdateConfig msg -> Msg -> State -> (State, Maybe msg)
update config msg state =
case msg of
Change id ->
...
WentTooLow ->
( { key = Nothing, mouse = state.mouse }
, Just wentToLowMsg
)
WentTooFar ->
( { key = Nothing, mouse = state.mouse }
, Just wentToFarMsg
)
view : Config a -> Int -> State -> List a -> Html Msg
view config howManyToShow state data =
ul
[ onKeyDown
-- if down then
]
[ li customAttributes customChildren
]
type alias Config a =
{ toId : a -> String
, ul : List (Attribute Never)
, li : Bool -> a -> HtmlDetails Never
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment