aforemny/material-components-web-elm/1.0.1

NOTE: the latest version is 9.1.0

Material.TopAppBar

Top App Bar acts as a container for items such as application title, navigation icon, and action items.

Table of Contents

Resources

Basic Usage

import Material.TopAppBar as TopAppBar
    exposing
        ( topAppBar
        , topAppBarConfig
        )


main =
    topAppBar topAppBarConfig
        [ TopAppBar.row []
            [ TopAppBar.section [ TopAppBar.alignStart ]
                [ iconButton
                    { iconButtonConfig
                        | additionalAttributes =
                            [ TopAppBar.navigationIcon ]
                    }
                    "menu"
                , Html.span [ TopAppBar.title ]
                    [ text "Title" ]
                ]
            ]
        ]

Top App Bar

Usually a top app bar contains one row with at least one start-aligned section. This is where you would normally place your navigation icon and title.

topAppBar : TopAppBarConfig msg -> List (Html msg) -> Html msg

Top app bar view function

topAppBarConfig : TopAppBarConfig msg

Default configuration of a top app bar

type alias TopAppBarConfig msg =
{ dense : Bool
, fixed : Bool
, additionalAttributes : List (Attribute msg)
}

Configuration of a top app bar

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

A row is the first child of a top app bar. It contains the top app bar's sections.

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

Sections subdivide the top app bar's rows. A section may be start- or end-aligned. Usually, the first section is start-aligned and contains the top app bar's navigation icon and title.

alignEnd : Attribute msg

End-align a top app bar's section

alignStart : Attribute msg

Start-align a top app bar's section

title : Attribute msg

Apply this attribute to a element to mark it as the top app bar's title

Top App Bar with Action Items

A top app bar can contain action items that are placed on the opposite side of the navigation icon. To do so, add another end-aligned section to the top app bar's row. Do not forget to set the actionItem attribute on the icons.

topAppBar topAppBarConfig
    [ TopAppBar.row []
        [ TopAppBar.section [ TopAppBar.alignStart ]
            [ iconButton
                { iconButtonConfig
                    | additionalAttributes =
                        [ TopAppBar.navigationIcon ]
                }
                "menu"
            , Html.span [ TopAppBar.title ]
                [ text "Title" ]
            ]
        , TopAppBar.section [ TopAppBar.alignEnd ]
            [ iconButton
                { iconButtonConfig
                    | additionalAttributes =
                        [ TopAppBar.actionItem ]
                }
                "print"
            , iconButton
                { iconButtonConfig
                    | additionalAttributes =
                        [ TopAppBar.actionItem ]
                }
                "bookmark"
            ]
        ]
    ]
actionItem : Attribute msg

Apply this attribute to a icon button to mark it as a top app bar's action item

Fixed Variant

To make a top app bar fixed to the top, set its fixed configuration field to True. Since a fixed top app bar would overlay the pages content, an appropriate margin has to be applied to the page's content.

topAppBar { topAppBarConfig | fixed = True } []
fixedAdjust : Attribute msg

Appropriate padding for a fixed top app bar.

Apply this to the page's content so that a fixed top app bar does not overlay the content.

denseFixedAdjust : Attribute msg

Appropriate padding for a dense fixed top app bar.

Apply this to the page's content so that a fixed top app bar does not overlay the content.

Appropriate padding for a dense prominent fixed top app bar.

Apply this to the page's content so that a fixed top app bar does not overlay the content.

prominentFixedAdjust : Attribute msg

Appropriate padding for a prominent fixed top app bar.

Apply this to the page's content so that a fixed top app bar does not overlay the content.

shortFixedAdjust : Attribute msg

Appropriate padding for a short fixed top app bar.

Apply this to the page's content so that a fixed top app bar does not overlay the content.

Short Variant

Short top app bars collapse to the navigation icon side when scrolled.

shortTopAppBar topAppBarConfig []
shortTopAppBar : TopAppBarConfig msg -> List (Html msg) -> Html msg

Short top app bar view function

Short Always Closed Variant

A short top app bar can be configured to always appear closed.

shortCollapsedtopAppBar topAppBarConfig []
shortCollapsedTopAppBar : TopAppBarConfig msg -> List (Html msg) -> Html msg

Short always closed top app bar view function

Prominent Variant

To make a top app bar taller than the default, you may use a prominent top app bar.

prominentTopAppBar topAppBarConfig []
prominentTopAppBar : TopAppBarConfig msg -> List (Html msg) -> Html msg

Prominent top app bar view function

Dense Variant

To make a top app bar shorter than the default, set its dense configuration field to True.

topAppBar { topAppBarConfig | dense = True }