aforemny/material-components-web-elm/2.0.0

NOTE: the latest version is 9.1.0

Material.List

Lists are continuous, vertical indexes of text or images.

Table of Contents

Resources

Basic Usage

import Material.List
    exposing
        ( list
        , listConfig
        , listItem
        , listItemConfig
        )


main =
    list listConfig
        [ listItem listItemConfig [ text "Line item" ]
        , listItem listItemConfig [ text "Line item" ]
        ]

List

list : ListConfig msg -> List (ListItem msg) -> Html msg

List view function

listConfig : ListConfig msg

Default configuration of a list

type alias ListConfig msg =
{ nonInteractive : Bool
, dense : Bool
, avatarList : Bool
, twoLine : Bool
, vertical : Bool
, wrapFocus : Bool
, additionalAttributes : List (Attribute msg)
}

Configuration of a list

List Item

listItem : ListItemConfig msg -> List (Html msg) -> ListItem msg

List item view function

listItemConfig : ListItemConfig msg

Default configuration of a list item

type alias ListItemConfig msg =
{ disabled : Bool
, selected : Bool
, activated : Bool
, href : Maybe String
, target : Maybe String
, additionalAttributes : List (Attribute msg)
, onClick : Maybe msg
}

Configuration of a list item

type ListItem msg

Type of a list item

List Variants

Two-Line List

Lists may be two-line lists by settings the twoLine configuration field to True. In that case, list items should wrap their contents inside listItemText and their first line in listItemPrimaryText and their second line in listItemSecondaryText.

list { listConfig | twoLine = True }
    [ listItem listItemConfig
        [ listItemText []
            [ listItemPrimaryText []
                [ text "First line" ]
            , listItemSecondaryText []
                [ text "Second line" ]
            ]
        ]
    ]
listItemText : List (Attribute msg) -> List (Html msg) -> Html msg

List item's text for list items in a two-line list

listItemPrimaryText : List (Attribute msg) -> List (Html msg) -> Html msg

First line of a two-line list item's text

listItemSecondaryText : List (Attribute msg) -> List (Html msg) -> Html msg

Second line of a two-line list item's text

Non-interactive List

Lists may be non-interactive by setting the nonInteractive configuration field to True.

list { listConfig | nonInteractive = True }
    [ listItem listItemConfig [ text "List item" ] ]

Dense List

Lists may be styled more compact by setting the dense configuration field to True.

list { listConfig | dense = True }
    [ listItem listItemConfig [ text "List item" ] ]

Avatar List

List item's graphics may be configured to appear larger by setting the avatarList configuration field to True.

This is particularly useful when a list item's graphic includes an image rather than an icon.

list { listConfig | dense = True }
    [ listItem listItemConfig
        [ listItemGraphic [] [ Html.img [] [] ]
        , text "List item"
        ]
    ]

List Group

Multiple related lists, such as folders and files in a file hierarchy, may be grouped using listGroup and labeled by listGroupSubheader.

listGroup []
    [ listGroupSubheader [] [ text "Folders" ]
    , list listConfig
        [ listItem [] [ text "Folder" ]
        , listItem [] [ text "Folder" ]
        ]
    , listGroupSubheader [] [ text "Files" ]
    , list listConfig
        [ listItem [] [ text "File" ]
        , listItem [] [ text "File" ]
        ]
    ]
listGroup : List (Attribute msg) -> List (Html msg) -> Html msg

List group view function

listGroupSubheader : List (Attribute msg) -> List (Html msg) -> ListItem msg

List group subheader view function

List Group Divider

Multiple lists within a group may be visually seperated by a list group divider.

listGroup []
    [ list listConfig
        [ listItem [] [ text "Folder" ]
        , listItem [] [ text "Folder" ]
        ]
    , listGroupDivider []
    , list listConfig
        [ listItem [] [ text "File" ]
        , listItem [] [ text "File" ]
        ]
    ]
listGroupDivider : List (Attribute msg) -> Html msg

List group divider view function

List Item Variants

In addition to their text child, lists may optionally contain a starting tile referred to as graphic and/ or a last tile referred to as meta.

List Item with Graphic

Common examples for graphics are icons and images, avatar images and selection controls such as checkboxes.

listItem listItemConf
    [ listItemGraphic [] [ icon iconConf "star" ]
    , text "List item"
    ]
listItemGraphic : List (Attribute msg) -> List (Html msg) -> Html msg

A list item's graphic tile

List Item with Meta

Common examples for metas are text, icons and images and selection controls.

listItem listItemConf
    [ text "List item"
    , listItemMeta [] [ icon iconConf "star" ]
    ]
listItemMeta : List (Attribute msg) -> List (Html msg) -> Html msg

A list item's meta tile

Disabled List Item

List items may be disabled by setting their disabled configuration field to True.

listItem { listItemConf | disabled = True }
    [ text "List item" ]

Selected List Item

List items may be disabled by setting their selected configuration field to True.

listItem { listItemConf | selected = True }
    [ text "List item" ]

Activated List Item

List items may be disabled by setting their activated configuration field to True.

listItem { listItemConf | activated = True }
    [ text "List item" ]

List items may specify the href attribute in which case the list item essentially behaves like a HTML a element. You may specify the configuration target target as well.

listItem [ href "https://elm-lang.org" ]
    [ text "Elm programming language" ]

Note that link list items cannot be disabled.

List Item Divider

List items may be seperated by a divider. The divider may optionally be inset so that it does not intersect the list item's graphic, or padded so that it does not intersect the list item's meta.

list listConfig
    [ listItem [] [ text "List item" ]
    , listItemDivider listItemDividerConfig
    , listItem [] [ text "List item" ]
    ]
listItemDivider : ListItemDividerConfig msg -> ListItem msg

List item divider view function

listItemDividerConfig : ListItemDividerConfig msg

Default configuration of a list item divider

type alias ListItemDividerConfig msg =
{ inset : Bool
, padded : Bool
, additionalAttributes : List (Attribute msg)
}

Configuration of a list item divider