Skip to content

Collapse sidebar into small icons #468

@meteoDaniel

Description

@meteoDaniel

I would like to know how to manage collapsing sidebar into icon view like this example:

https://www.codeply.com/p/1TlcDLPfiE

This is an example how you can add icons to the collapsable sidebar example given in this project:

sidebar_header = dbc.Row(
    [
        dbc.Col(html.H2("Sidebar", className="display-4")),
        dbc.Col(
            [
                html.Button(
                    # use the Bootstrap navbar-toggler classes to style
                    html.Span(className="navbar-toggler-icon"),
                    className="navbar-toggler",
                    # the navbar-toggler classes don't set color
                    style={
                        "color": "rgba(0,0,0,.5)",
                        "border-color": "rgba(0,0,0,.1)",
                    },
                    id="navbar-toggle",
                ),
                html.Button(
                    # use the Bootstrap navbar-toggler classes to style
                    html.Span(className="navbar-toggler-icon"),
                    className="navbar-toggler",
                    # the navbar-toggler classes don't set color
                    style={
                        "color": "rgba(0,0,0,.5)",
                        "border-color": "rgba(0,0,0,.1)",
                    },
                    id="sidebar-toggle",
                ),
            ],
            # the column containing the toggle will be only as wide as the
            # toggle, resulting in the toggle being right aligned
            width="auto",
            # vertically align the toggle in the center
            align="center",
        ),
    ]
)

sidebar = html.Div(
    [
        sidebar_header,
        # we wrap the horizontal rule and short blurb in a div that can be
        # hidden on a small screen
        html.Div(
            [
                html.Hr(),
                html.P(
                    "A responsive sidebar layout with collapsible navigation "
                    "links.",
                    className="lead",
                ),
            ],
            id="blurb",
        ),
        # use the Collapse component to animate hiding / revealing links
        dbc.Collapse(
            dbc.Nav(
                [
                    dbc.NavLink([html.I(className='fa fa-desktop',
                                            style={'aria-hidden': 'true'},
                                            children=None), f" Overview"], href="/page-1", id="page-1-link"),
                    dbc.NavLink([html.I(className='fa fa-desktop',
                                            style={'aria-hidden': 'true'},
                                            children=None), f"Subpage"], href="/page-2", id="page-2-link"),
                    dbc.NavLink([html.I(className='fa fa-desktop',
                                            style={'aria-hidden': 'true'},
                                            children=None), f"Page 3"], href="/page-3", id="page-3-link"),
                ],
                vertical=True,
                pills=True,
            ),
            id="collapse",
        ),
    ],
    id="sidebar",
)

Add: https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css as external stylesheet.

Hopefully somebody has a small snippet. I guess this is something many people asking or searching for because it will rise up a dashboard made by dash with bootstrap components more and more to nice front end development with python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions