aforemny/material-components-web-elm/2.1.2

NOTE: the latest version is 9.1.0

Material.Drawer

The MDC Navigation Drawer is used to organize access to destinations and other functionality on an app.

Table of Contents

Resources

Basic Usage

import Html exposing (Html, text)
import Html.Attributes exposing (style)
import Material.Drawer as Drawer
    exposing
        ( permanentDrawer
        , permanentDrawerConfig
        )
import Material.List
    exposing
        ( list
        , listConfig
        , listItem
        , listItemConfig
        )


main =
    Html.div
        [ style "display" "flex"
        , style "flex-flow" "row nowrap"
        ]
        [ permanentDrawer permanentDrawerConfig
            [ drawerContent []
                [ list listConfig
                    [ listItem listItemConfig
                        [ text "Home" ]
                    , listItem listItemConfig
                        [ text "Log out" ]
                    ]
                ]
            ]
        , Html.div [] [ text "Main Content" ]
        ]

Permanent Drawer

permanentDrawer : PermanentDrawerConfig msg -> List (Html msg) -> Html msg

Permanent drawer view function

Html.div
    [ style "display" "flex"
    , style "flex-flow" "row nowrap"
    ]
    [ permanentDrawer permanentDrawerConfig
        [ drawerContent [] [] ]
    , Html.div [] [ text "Main Content" ]
    ]
permanentDrawerConfig : PermanentDrawerConfig msg

Default configuration of a permanent drawer

type alias PermanentDrawerConfig msg =
{ additionalAttributes : List (Attribute msg) }

Configuration of a permanent drawer

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

Drawer content

Drawer with Header

Drawers can contain a header element which will not scroll with the rest of the drawer content. Things like account switchers and titles should live in the header element.

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

Drawer header view function

permanentDrawer permanentDrawerConfig
    [ drawerHeader []
        [ Html.h3 [ drawerTitle ] [ text "Title" ]
        , Html.h6 [ drawerSubtitle ] [ text "Subtitle" ]
        ]
    , drawerContent [] []
    ]
drawerTitle : Attribute msg

Attribute to mark the title text element of the drawer header

drawerSubtitle : Attribute msg

Attribute to mark the subtitle text element of the drawer header

Dismissible Drawer

Dismissible drawers are by default hidden off screen, and can slide into view. Dismissible drawers should be used when navigation is not common, and the main app content is prioritized.

dismissibleDrawer : DismissibleDrawerConfig msg -> List (Html msg) -> Html msg

Dismissible drawer view function

Html.div []
    [ dismissibleDrawer
        { dismissibleDrawerConfig | open = True }
        [ drawerContent [] [] ]
    , Html.div [ Drawer.appContent ]
        [ text "Main Content" ]
    ]
dismissibleDrawerConfig : DismissibleDrawerConfig msg

Default configuration of a dismissible drawer

type alias DismissibleDrawerConfig msg =
{ open : Bool
, additionalAttributes : List (Attribute msg)
, onClose : Maybe msg
}

Configuration of a dismissible drawer

appContent : Attribute msg

Dismissible drawer's app content marker

Apply this attribute to the page's content for open/close animation to work. The page content has to be the next sibling of the dismissible drawer.

Modal Drawer

Modal drawers are elevated above most of the app's UI and don't affect the screen's layout grid.

modalDrawer : ModalDrawerConfig msg -> List (Html msg) -> Html msg

Modal drawer view function

Html.div []
    [ modalDrawer
        { modalDrawerConfig
            | open = True
            , onClick = Just DrawerClosed
        }
        [ drawerContent [] [] ]
    , drawerScrim [] []
    , Html.div [] [ text "Main Content" ]
    ]
modalDrawerConfig : ModalDrawerConfig msg

Default configuration of a modal drawer

type alias ModalDrawerConfig msg =
{ open : Bool
, additionalAttributes : List (Attribute msg)
, onClose : Maybe msg
}

Configuration of a model drawer

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

Modal drawer's scrim element

Prevents the application from interaction while the modal drawer is open. Has to be the next sibling after the modalDrawer and before the page's content.