Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add css styling to Fast Template for "active" menu item. #2604

Closed
MarcSkovMadsen opened this issue Aug 3, 2021 · 2 comments
Closed

Add css styling to Fast Template for "active" menu item. #2604

MarcSkovMadsen opened this issue Aug 3, 2021 · 2 comments
Labels
type: enhancement Minor feature or improvement to an existing feature

Comments

@MarcSkovMadsen
Copy link
Collaborator

The FastTemplate supports adding a nice menu to the sidebar as shown in the menu below. But it does not include css styling to support marking a menu item as "menu-item-active", i.e.

<li class="menu-item-active"><a href="/">ML Explainability</a></li>

please support this.

Menu Example

import panel as pn

pn.extension()

template=pn.template.FastListTemplate(title="App with Menu")

ACCENT_BASE_COLOR = template.accent_base_color

COLLAPSED_ICON = f"""<svg style="stroke: { ACCENT_BASE_COLOR }" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg" slot="collapsed-icon">
<path d="M15.2222 1H2.77778C1.79594 1 1 1.79594 1 2.77778V15.2222C1 16.2041 1.79594 17 2.77778 17H15.2222C16.2041 17 17 16.2041 17 15.2222V2.77778C17 1.79594 16.2041 1 15.2222 1Z" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M9 5.44446V12.5556" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M5.44446 9H12.5556" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>"""

EXPANDED_ICON = f"""<svg style="stroke: { ACCENT_BASE_COLOR }" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg" slot="expanded-icon">
<path d="M15.2222 1H2.77778C1.79594 1 1 1.79594 1 2.77778V15.2222C1 16.2041 1.79594 17 2.77778 17H15.2222C16.2041 17 17 16.2041 17 15.2222V2.77778C17 1.79594 16.2041 1 15.2222 1Z" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M5.44446 9H12.5556" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
"""

MENU_HTML=f"""
<fast-accordion id="menu">
    <fast-accordion-item slot="item" expanded>
        <h3 slot="heading" style="margin:0px">Introduction</h3>{ COLLAPSED_ICON }{ EXPANDED_ICON }
        <ul>
            <li><a href="introduction">Introduction</a></li>
        </ul>
    </fast-accordion-item>
    <fast-accordion-item slot="item" expanded>
        <h3 slot="heading" style="margin:0px">Example Apps</h3>{ COLLAPSED_ICON }{ EXPANDED_ICON }
        <ul>
            <li class="menu-item-active"><a href="/">ML Explainability</a></li>
            <li><a href="/">Plots and Tables with Events</a></li>
            <li><a href="/">Cross Filtering</a></li>
            <li><a href="/">Streaming Data</a></li>
        </ul>
    </fast-accordion-item>
</fast-according>
"""

template.sidebar_footer=MENU_HTML

template.servable()

image

@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Aug 3, 2021
@Stubatiger
Copy link
Contributor

Stubatiger commented Aug 3, 2021

Hey Marc,

what exactly do you mean by that?

Is this about adding the missing css to the templates or about setting the ''menu-item-active" css-class to the correct list item?

For the css i guess some basic

.menu-item-active
{
 background: #d3d3d3;
 border-radius: 35px;
 padding: 0px 20px;
 line-height: 50px;
}

would be enough already, though i do not know how to access the fast colors
highightmenu

For setting the correct css class, im not sure how to do that with panel, best way would be i guess some javascript which i have no clue of :(

( With the awesome-panel-extensions and the site/application pattern currently i can do that with using the register_post_view function and setting there a specific HTML for the current application into the sidebar with the correct list-item set.)

@MarcSkovMadsen
Copy link
Collaborator Author

It’s something like that. I have the css somewhere already. Will make PR ASAP.

MarcSkovMadsen pushed a commit that referenced this issue Aug 3, 2021
@MarcSkovMadsen MarcSkovMadsen added type: enhancement Minor feature or improvement to an existing feature and removed TRIAGE Default label for untriaged issues labels Aug 4, 2021
philippjfr pushed a commit that referenced this issue Aug 4, 2021
Co-authored-by: Marc Skov Madsen <masma@orsted.dk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants