PaackEng/elm-ui-dropdown/1.0.0

NOTE: the latest version is 3.3.0

Dropdown

Elm UI Dropdown.

type State item

Opaque type that holds the current state

type alias Model =
    { dropdownState : Dropdown.State String
    }
init : String -> State item

Create a new state. You must pass a unique identifier for each dropdown component.

{
    ...
    dropdownState = Dropdown.init "country-dropdown"
}
type Msg item

Opaque type for the internal dropdown messages

type Config item msg

Opaque type that holds the current config

dropdownConfig =
    Dropdown.basic DropdownMsg OptionPicked Element.text Element.text
(Msg item -> msg)
-> (Maybe item -> msg)
-> (item -> Element msg)
-> (Bool -> Bool -> item -> Element msg)
-> Config item msg

Create a basic configuration. This takes:

- The message to wrap all the internal messages of the dropdown
- A message to trigger when an item is selected
- A function to get the Element to display from an item, to be used in the select part of the dropdown
- A function to get the Element to display from an item, to be used in the item list of the dropdown


Dropdown.basic DropdownMsg OptionPicked Element.text Element.text
(Msg item -> msg)
-> (Maybe item -> msg)
-> (item -> Element msg)
-> (Bool -> Bool -> item -> Element msg)
-> (item -> String)
-> Config item msg

Create a filterable configuration. This takes:

- The message to wrap all the internal messages of the dropdown
- A message to trigger when an item is selected
- A function to get the Element to display from an item, to be used in the select part of the dropdown
- A function to get the Element to display from an item, to be used in the item list of the dropdown
- A function to get the text representation from an item, to be used when filtering elements in the list


Dropdown.basic DropdownMsg OptionPicked Element.text Element.text
withContainerAttributes : List (Attribute msg) -> Config item msg -> Config item msg

Sets the container visual attributes, default is empty

Dropdown.withContainerAttributes [ width (px 300) ] config
withPromptElement : Element msg -> Config item msg -> Config item msg

Sets the content of the Select, default is "-- Select --"

Dropdown.withPromptElement (el [ Font.color (rgb255 123 123 123) ] <| text "Pick one") config
withSelectAttributes : List (Attribute msg) -> Config item msg -> Config item msg

Sets the select visual attributes, default is empty

Dropdown.withSelectAttributes [ Border.width 1, Border.rounded 5, paddingXY 16 8 ] config
withSearchAttributes : List (Attribute msg) -> Config item msg -> Config item msg

Sets the search visual attributes, default is empty

Dropdown.withSearchAttributes [ Border.width 0, padding 0 ] config
{ openButton : Element msg
, closeButton : Element msg
}
-> Config item msg
-> Config item msg

Sets the open and close buttons' visual attributes, default is empty

Dropdown.withOpenCloseButtons { openButton = text "+", closeButton = "-" } config
withListAttributes : List (Attribute msg) -> Config item msg -> Config item msg

Sets the item list visual attributes, default is empty

Dropdown.withListAttributes [ Border.width 1, Border.rounded ] config
Config item msg
-> Msg item
-> State item
-> List item
-> ( State item, Cmd msg )

Update the component state

DropdownMsg subMsg ->
    let
        ( updated, cmd ) =
            Dropdown.update dropdownConfig subMsg model.dropdownState model.items
    in
        ( { model | dropdownState = updated }, cmd )
view : Config item msg -> State item -> List item -> Element msg

Render the view

Dropdown.view dropdownConfig model.dropdownState model.items