MenuButton#
Download this notebook from GitHub (right-click to download).
import panel as pn
import panel_material_ui as pmui
pn.extension()
The MenuButton
component is part of the Menu
family of components. Menu
components provide a structured way for users to navigate or choose between a series of defined items. In the case of MenuItem
, these items represent a series of actions to select from after opening the menu on a button click.
Each item in the MenuButton
list is defined by a dictionary with several supported keys:
Item Structure#
Each item can include the following keys:
label
(str, required): The text displayed for the breadcrumb item.href
(str, optional): A URL to link to. If provided, the breadcrumb becomes a link.icon
(str, optional): An icon to display next to the label.avatar
(str, optional): An avatar or image to show beside the label.
These dictionaries are passed to the component via the items parameter as a list. When one of the items
is selected it will be available on the value
parameter.
Since only the allowed keys are synced with the frontend, other information can be stored in the item dictionaries.
Parameters:#
Core#
active
(boolean
): Whether the dialog is visible.disabled
(boolean): Whether the button is clickable.items
(list
): Menu items to select from.value
(dict): The currently selected item.
Display#
color
(str): A button theme; should be one of'default'
(white),'primary'
(blue),'success'
(green),'info'
(yellow),'light'
(light), or'danger'
(red).description
(str | Bokeh Tooltip | pn.widgets.TooltipIcon): A description which is shown when the widget is hovered.icon
(str): An icon to render to the left of the button label. Either an SVG or an icon name which is loaded from Material UI Icons.icon_size
(str): Size of the icon as a string, e.g. 12px or 1em.label
(str): The title of the widget.variant
(str): The button style, either ‘solid’, ‘outlined’, ‘text’.
Styling#
sx
(dict): Component level styling API.theme_config
(dict): Theming API.
MenuButton
allows selecting between a number of items
:
menu_button = pmui.MenuButton(items=[
{'label': 'Open', 'icon': 'description'},
{'label': 'Save', 'icon': 'save'},
{'label': 'Exit', 'icon': 'close'},
], label='File', icon='storage')
menu_button
The MenuButton
also allows separating options into groups by adding a None
in between:
pmui.MenuButton(label="File", icon="save", items=[
{"label": "License", "icon": "law"},
None,
{"label": "About", "icon": "info"}
])
pn.Row(
pmui.MenuButton(name="File", icon="save", items=[
{"label": "License", "icon": "law"},
None,
{"label": "About", "icon": "info"}
]),
pmui.MenuButton(name="Help", icon='help', items=[
{"label": "Save", "icon": "law"},
{"label": "Exit", "icon": "info"}
])
)
Display Options#
color
#
pn.GridBox(*(
menu_button.clone(color=color)
for color in pmui.MenuButton.param.color.objects
), ncols=2)
variant
#
pn.Row(*(
menu_button.clone(variant=variant)
for variant in pmui.MenuButton.param.variant.objects
))
Controls#
The MenuButton
menu exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:
pn.Row(menu_button.controls(jslink=True), menu_button)
Download this notebook from GitHub (right-click to download).