UI.ListView is a styled searchable row list.
The main variation (select-lists) has the capability of having one of its rows selected.
The developer is responsible for coding the row's view. While this component then applies the borders and the click event. Also, it can optionally filter when having a search bar, and add an action bar.
view : RenderConfig -> Model -> Element Msg
view renderConfig model =
ListView.selectList Msg.SelectElement
elementToKey
elementView
|> ListView.withItems model.myListElements
|> ListView.withSearchField
{ label = "Search for elements matching name.."
, searchMsg = Msg.FilterSet
, currentFilter =
Maybe.map
(\str -> ( str, elementHasString ))
model.currentFilter
}
|> ListView.withActionBar
{ label = "Create new element"
, icon = Icon.add
, action =
DialogMsg.OpenElementCreation
|> Msg.ForDialog
|> Action.DispatchMsg
}
|> ListView.withSelected
(\{ id } ->
Maybe.map (.id >> (==) id) model.selectedElement
|> Maybe.withDefault False
)
|> ListView.withWidth Element.fill
|> ListView.renderElement renderConfig
elementHasString : String -> Element -> Bool
elementHasString str { name } =
String.contains str nameThe main variation of UI.ListView.
Click an element, and it will be selected.
ListView.selectList Msg.SelectElement
(\{ name } ->
Element.el [ Element.padding 8 ]
(Element.text name)
)A UI.ListView without built-in selection support.
ListView.simpleList
(\{ name } ->
Element.el [ Element.padding 8 ]
(Element.text name)
)Configuration required to render a toggleable-list.
{ detailsShowLabel = "Show details" -- For accessibility only
, detailsCollapseLabel = "Hide details" -- For accessibility only
, toCover =
\{ name } ->
-- ListView.ToggleableCover
{ title = name, caption = Nothing }
, toDetails =
\{ age } ->
[ ( "Age", Element.text age ) ]
, selectMsg = Msg.ElementSelect
}What is displayed in a collapsed toggleable-list.
{ title = "Some item"
, caption = Just "Created at 2020-06-10"
}Toggleable-lists are a variation of select-lists where the selected element expands with details while all other's details keep collapsed.
We recommend using UI.Table instead, as it uses toggleable-lists for its responsive mode.
ListView.toggleableList
{ detailsShowLabel = "Show details" -- For accessibility only
, detailsCollapseLabel = "Hide details" -- For accessibility only
, toCover =
\{ name } ->
{ title = name, caption = Nothing }
, toDetails =
\{ age } ->
[ ( "Age", Element.text age ) ]
, selectMsg = Msg.ElementSelect
}
|> ListView.withItems model.items
|> ListView.withSelected isElementSelected
|> ListView.renderElement renderConfigNOTE: Toggleable-list elements' view is not codable.
Replaces the component's list of elements.
ListView.withItems
[ { id = 0, name = "Catarina" }
, { id = 1, name = "Gabriel" }
]
someListViewAdds a message to be dispatched when an item is selected.
ListView.withItems Msg.ElementSelect
someListViewMarks every element as selected or not using a boolean-resulted lambda.
ListView.withSelected
(\{ id } -> id == model.selectedId)
someListViewAdd id attribute to the HTML tags of the elements and the list itself.
ListView.selectList
Msg.SelectDrink
softDrinkToString
softDrinkView
|> ListView.withDomId "softDrinks"Generates:
< ... id="softDriks">
<... id="fanta">...</...>
<... id="coke">...</...>
<... id="drPepper">...</...>
</...>NOTE: Only when withDomId is used children have ids.
Adds a header above the list.
ListView.withHeader "ListView Header" someListViewSearchConfig assembles the required configuration for having a search field and filter.
{ title = "Elements"
, label = "Search for elements matching name.."
, searchMsg = Msg.FilterSet
, currentFilter =
Maybe.map
(\str -> ( str, elementHasString ))
model.currentFilter
}Replaces the component's search-field and allow filtering the elements.
ListView.withSearchFied
{ detailsShowLabel = "Show details" -- For accessibility only
, detailsCollapseLabel = "Hide details" -- For accessibility only
, toCover =
\{ name } ->
-- ListView.ToggleableCover
{ title = name, caption = Nothing }
, toDetails =
\{ age } ->
[ ( "Age", Element.text age ) ]
, selectMsg = Msg.ElementSelect
}
someListViewReplaces the component's action-bar. An action-bar is an additional pre-styled stick row that, when clicked, triggers an action.
ListView.withActionBar
{ label = "Create new element"
, icon = Icon.add
, onClick =
Msg.UuidGen (Msg.ForDialog << DialogMsg.OpenElementCreation)
}
someListViewAdds button to toggle a custom menu element.
ListView.withCustomExtraMenu customDropdownView
someListViewApplies Element.width to the component.
ListView.withWidth
(Element.fill |> Element.minimum 220)
someListViewThe selected item can be styled using ListView.withSelectStyle.
backgroundColor: The color in which the background assumes for selected items.
When Nothing no color is applied.Overwrite the appearance of the selected item.
ListView.withSelectStyle
{ backgroundColor = Palette.color toneDanger brightnessMiddle }
someListViewEnd of the builder's life. The result of this function is a ready-to-insert Elm UI's Element.
The
ListView object msgtype is used for describing the component for later rendering.