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 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
, onClick =
Msg.UuidGen (Msg.ForDialog << DialogMsg.OpenElementCreation)
}
|> 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)
)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" }
]
someListViewMarks every element as selected or not using a boolean-resulted lambda.
ListView.withSelected
(\{ id } -> id == model.selectedId)
someListViewSearchConfig assembles the required configuration for having a search field and filter.
{ 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
}
someListViewActionConfig assembles the required configuration for having an action bar at the bottom of the list.
{ label = "Create new element"
, icon = Icon.add
, onClick =
Msg.UuidGen (Msg.ForDialog << DialogMsg.OpenElementCreation)
}Replaces 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)
}
someListViewApplies Element.width to the component.
ListView.withWidth
(Element.fill |> Element.minimum 220)
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.