Skip to main content

Streamlit Component for ANT Menu

Project description

Streamlit Ant Design Menu Component

This custom Streamlit component allows you to easily integrate an Ant Design menu into your Streamlit application. The component is built using Ant Design and provides a simple interface for creating a menu with nested items and icons.

Live Demo

Features

  • Hierarchical menu structure
  • Ant Design icons support
  • Light and dark theme support
  • Customizable CSS styling
  • Multiple selection (experimental)
  • Auto-adjusting menu height
  • Click event handling

Installation

To install this component, simply run:

pip install st_ant_menu

Usage

First, import the st_ant_menu function from the package:

from st_ant_menu import st_ant_menu

Then, create a menu data structure, and call st_ant_menu with the data:

menu_data = [
{
    "key": "1",
    "label": "Menu Item 1",
    "icon": "UserOutlined",
},
{
    "key": "2",
    "label": "Menu Item 2",
    "icon": "VideoCameraOutlined",
    "disabled": True
},
{
    "key": "3",
    "label": "Menu Item 3",
    "icon": "UploadOutlined",
    "children": [
        {
            "key": "3-1",
            "label": "Submenu Item 1",
            "icon": "BarChartOutlined",
        },
        {
            "key": "3-2",
            "label": "Submenu Item 2",
            "icon": "CloudOutlined",
        },
    ],
},
]

selected_key = st_ant_menu(menu_data)

API

st_ant_menu(
menu_data: List[Dict],
key: str = "first_menu",
defaultValue: Optional[str] = None,
defaultSelectedKeys: Optional[str] = None,
defaultOpenKeys: Optional[str] = None,
additionalHeight: int = 100,
multiple: bool = False,
css_styling: Optional[Dict] = None,
theme: str = "light",
menu_click: bool = False
) -> Union[str, List[str]]

Parameters

menu_data (List[Dict]): The data to be displayed in the menu. Must be a list of dictionaries that conform to the Ant Design Menu item specification. See https://ant.design/components/menu/#Menu.Item for more information.

key (str, optional): The key associated with the component. This is used to ensure that the component is rendered properly when its value changes. Defaults to "first_menu".

defaultValue (Optional[str], optional): The default value to be displayed in the component. Defaults to None.

defaultSelectedKeys (Optional[str], optional): The default selected keys in the menu. Defaults to None. defaultOpenKeys (Optional[str], optional): The default open keys in the menu. Defaults to None. additionalHeight (int, optional): The additional height of the menu that should be added to the Streamlit iframe height. This is used to ensure that the entire menu is visible in the Streamlit app. Defaults to 100. multiple (bool, optional): Whether the menu allows multiple selections. (Broken) Defaults to False. css_styling (Optional[Dict], optional): A dictionary of CSS styling to be applied to the component. Defaults to None. theme (str, optional): The theme of the menu. Can be either "light" or "dark". Defaults to "light". menu_click (bool, optional): Set this to True to return the list of open keys on menu click, False will only return the selected key. Defaults to False.

Returns

Union[str, List[str]]: The value of the component. If menu_click is set to True, it will return a list of open keys, otherwise it will return the selected key.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

st_ant_menu-0.0.18.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

st_ant_menu-0.0.18-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file st_ant_menu-0.0.18.tar.gz.

File metadata

  • Download URL: st_ant_menu-0.0.18.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for st_ant_menu-0.0.18.tar.gz
Algorithm Hash digest
SHA256 af0eeaa4edc319c32525e00b4241030e4a1ec9ea4bce52f2fee1f443f8253029
MD5 fd69908522b119a96107daf614cf4440
BLAKE2b-256 add9c8fa563a90a662c790c394a92dd0d82f169a13606b3bddb3b5c9f000aa58

See more details on using hashes here.

File details

Details for the file st_ant_menu-0.0.18-py3-none-any.whl.

File metadata

  • Download URL: st_ant_menu-0.0.18-py3-none-any.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for st_ant_menu-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 5828f9ac4517f5a26415562c5732b680cbdd176a13a722bdaf8786ab65cd4702
MD5 311ee1abe788ec68fc28e056fdbe373a
BLAKE2b-256 36035e20f2429d20692d769abd69678832a95fa95b5810465a830f027e6624c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page