st-ant-menu 0.0.18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. st_ant_menu-0.0.18/LICENSE +21 -0
  2. st_ant_menu-0.0.18/MANIFEST.in +1 -0
  3. st_ant_menu-0.0.18/PKG-INFO +124 -0
  4. st_ant_menu-0.0.18/README.md +105 -0
  5. st_ant_menu-0.0.18/setup.cfg +4 -0
  6. st_ant_menu-0.0.18/setup.py +26 -0
  7. st_ant_menu-0.0.18/st_ant_menu/__init__.py +132 -0
  8. st_ant_menu-0.0.18/st_ant_menu/frontend/build/asset-manifest.json +19 -0
  9. st_ant_menu-0.0.18/st_ant_menu/frontend/build/bootstrap.min.css +9500 -0
  10. st_ant_menu-0.0.18/st_ant_menu/frontend/build/index.html +1 -0
  11. st_ant_menu-0.0.18/st_ant_menu/frontend/build/precache-manifest.05c7b8bb9328961b3aab59d9f6f17ff0.js +22 -0
  12. st_ant_menu-0.0.18/st_ant_menu/frontend/build/service-worker.js +39 -0
  13. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/2.eb109dfa.chunk.js +3 -0
  14. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/2.eb109dfa.chunk.js.LICENSE.txt +66 -0
  15. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/2.eb109dfa.chunk.js.map +1 -0
  16. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/main.d3acb81e.chunk.js +2 -0
  17. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/main.d3acb81e.chunk.js.map +1 -0
  18. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/runtime-main.ac51b7c4.js +2 -0
  19. st_ant_menu-0.0.18/st_ant_menu/frontend/build/static/js/runtime-main.ac51b7c4.js.map +1 -0
  20. st_ant_menu-0.0.18/st_ant_menu.egg-info/PKG-INFO +124 -0
  21. st_ant_menu-0.0.18/st_ant_menu.egg-info/SOURCES.txt +22 -0
  22. st_ant_menu-0.0.18/st_ant_menu.egg-info/dependency_links.txt +1 -0
  23. st_ant_menu-0.0.18/st_ant_menu.egg-info/requires.txt +1 -0
  24. st_ant_menu-0.0.18/st_ant_menu.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 flucas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ recursive-include st_ant_menu/frontend/build *
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.4
2
+ Name: st_ant_menu
3
+ Version: 0.0.18
4
+ Summary: Streamlit Component for ANT Menu
5
+ Home-page: https://github.com/flucas96/st_ant_menu
6
+ Author:
7
+ Author-email:
8
+ Requires-Python: >=3.6
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: streamlit>=0.63
12
+ Dynamic: description
13
+ Dynamic: description-content-type
14
+ Dynamic: home-page
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: requires-python
18
+ Dynamic: summary
19
+
20
+ # Streamlit Ant Design Menu Component
21
+
22
+ This custom Streamlit component allows you to easily integrate an Ant Design menu into your Streamlit application. The component is built using [Ant Design](https://ant.design/) and provides a simple interface for creating a menu with nested items and icons.
23
+
24
+ <a href="https://flucas-component-overview.streamlit.app/?preselect=7" target="_blank">
25
+ <img src="https://img.shields.io/badge/Live%20Demo-Streamlit-red?style=for-the-badge&logo=streamlit" alt="Live Demo">
26
+ </a>
27
+
28
+ ## Features
29
+
30
+ - Hierarchical menu structure
31
+ - Ant Design icons support
32
+ - Light and dark theme support
33
+ - Customizable CSS styling
34
+ - Multiple selection (experimental)
35
+ - Auto-adjusting menu height
36
+ - Click event handling
37
+
38
+ ## Installation
39
+
40
+ To install this component, simply run:
41
+
42
+ ```bash
43
+ pip install st_ant_menu
44
+ ```
45
+
46
+ # Usage
47
+
48
+ First, import the **st_ant_menu** function from the package:
49
+ ```python
50
+ from st_ant_menu import st_ant_menu
51
+ ```
52
+
53
+ Then, create a menu data structure, and call st_ant_menu with the data:
54
+
55
+ menu_data = [
56
+ {
57
+ "key": "1",
58
+ "label": "Menu Item 1",
59
+ "icon": "UserOutlined",
60
+ },
61
+ {
62
+ "key": "2",
63
+ "label": "Menu Item 2",
64
+ "icon": "VideoCameraOutlined",
65
+ "disabled": True
66
+ },
67
+ {
68
+ "key": "3",
69
+ "label": "Menu Item 3",
70
+ "icon": "UploadOutlined",
71
+ "children": [
72
+ {
73
+ "key": "3-1",
74
+ "label": "Submenu Item 1",
75
+ "icon": "BarChartOutlined",
76
+ },
77
+ {
78
+ "key": "3-2",
79
+ "label": "Submenu Item 2",
80
+ "icon": "CloudOutlined",
81
+ },
82
+ ],
83
+ },
84
+ ]
85
+
86
+ selected_key = st_ant_menu(menu_data)
87
+
88
+
89
+ # API
90
+
91
+ st_ant_menu(
92
+ menu_data: List[Dict],
93
+ key: str = "first_menu",
94
+ defaultValue: Optional[str] = None,
95
+ defaultSelectedKeys: Optional[str] = None,
96
+ defaultOpenKeys: Optional[str] = None,
97
+ additionalHeight: int = 100,
98
+ multiple: bool = False,
99
+ css_styling: Optional[Dict] = None,
100
+ theme: str = "light",
101
+ menu_click: bool = False
102
+ ) -> Union[str, List[str]]
103
+
104
+
105
+
106
+ Parameters
107
+
108
+ 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.
109
+
110
+ 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".
111
+
112
+ defaultValue (Optional[str], optional): The default value to be displayed in the component. Defaults to None.
113
+
114
+ defaultSelectedKeys (Optional[str], optional): The default selected keys in the menu. Defaults to None.
115
+ defaultOpenKeys (Optional[str], optional): The default open keys in the menu. Defaults to None.
116
+ 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.
117
+ multiple (bool, optional): Whether the menu allows multiple selections. (Broken) Defaults to False.
118
+ css_styling (Optional[Dict], optional): A dictionary of CSS styling to be applied to the component. Defaults to None.
119
+ theme (str, optional): The theme of the menu. Can be either "light" or "dark". Defaults to "light".
120
+ 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.
121
+
122
+ Returns
123
+
124
+ 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.
@@ -0,0 +1,105 @@
1
+ # Streamlit Ant Design Menu Component
2
+
3
+ This custom Streamlit component allows you to easily integrate an Ant Design menu into your Streamlit application. The component is built using [Ant Design](https://ant.design/) and provides a simple interface for creating a menu with nested items and icons.
4
+
5
+ <a href="https://flucas-component-overview.streamlit.app/?preselect=7" target="_blank">
6
+ <img src="https://img.shields.io/badge/Live%20Demo-Streamlit-red?style=for-the-badge&logo=streamlit" alt="Live Demo">
7
+ </a>
8
+
9
+ ## Features
10
+
11
+ - Hierarchical menu structure
12
+ - Ant Design icons support
13
+ - Light and dark theme support
14
+ - Customizable CSS styling
15
+ - Multiple selection (experimental)
16
+ - Auto-adjusting menu height
17
+ - Click event handling
18
+
19
+ ## Installation
20
+
21
+ To install this component, simply run:
22
+
23
+ ```bash
24
+ pip install st_ant_menu
25
+ ```
26
+
27
+ # Usage
28
+
29
+ First, import the **st_ant_menu** function from the package:
30
+ ```python
31
+ from st_ant_menu import st_ant_menu
32
+ ```
33
+
34
+ Then, create a menu data structure, and call st_ant_menu with the data:
35
+
36
+ menu_data = [
37
+ {
38
+ "key": "1",
39
+ "label": "Menu Item 1",
40
+ "icon": "UserOutlined",
41
+ },
42
+ {
43
+ "key": "2",
44
+ "label": "Menu Item 2",
45
+ "icon": "VideoCameraOutlined",
46
+ "disabled": True
47
+ },
48
+ {
49
+ "key": "3",
50
+ "label": "Menu Item 3",
51
+ "icon": "UploadOutlined",
52
+ "children": [
53
+ {
54
+ "key": "3-1",
55
+ "label": "Submenu Item 1",
56
+ "icon": "BarChartOutlined",
57
+ },
58
+ {
59
+ "key": "3-2",
60
+ "label": "Submenu Item 2",
61
+ "icon": "CloudOutlined",
62
+ },
63
+ ],
64
+ },
65
+ ]
66
+
67
+ selected_key = st_ant_menu(menu_data)
68
+
69
+
70
+ # API
71
+
72
+ st_ant_menu(
73
+ menu_data: List[Dict],
74
+ key: str = "first_menu",
75
+ defaultValue: Optional[str] = None,
76
+ defaultSelectedKeys: Optional[str] = None,
77
+ defaultOpenKeys: Optional[str] = None,
78
+ additionalHeight: int = 100,
79
+ multiple: bool = False,
80
+ css_styling: Optional[Dict] = None,
81
+ theme: str = "light",
82
+ menu_click: bool = False
83
+ ) -> Union[str, List[str]]
84
+
85
+
86
+
87
+ Parameters
88
+
89
+ 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.
90
+
91
+ 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".
92
+
93
+ defaultValue (Optional[str], optional): The default value to be displayed in the component. Defaults to None.
94
+
95
+ defaultSelectedKeys (Optional[str], optional): The default selected keys in the menu. Defaults to None.
96
+ defaultOpenKeys (Optional[str], optional): The default open keys in the menu. Defaults to None.
97
+ 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.
98
+ multiple (bool, optional): Whether the menu allows multiple selections. (Broken) Defaults to False.
99
+ css_styling (Optional[Dict], optional): A dictionary of CSS styling to be applied to the component. Defaults to None.
100
+ theme (str, optional): The theme of the menu. Can be either "light" or "dark". Defaults to "light".
101
+ 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.
102
+
103
+ Returns
104
+
105
+ 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.
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ import setuptools
2
+
3
+
4
+ with open('README.md') as f:
5
+ long_desc = f.read()
6
+
7
+ setuptools.setup(
8
+ name="st_ant_menu",
9
+ version="0.0.18",
10
+ author="",
11
+ author_email="",
12
+ description="Streamlit Component for ANT Menu",
13
+ long_description=long_desc,
14
+ long_description_content_type='text/markdown',
15
+ url="https://github.com/flucas96/st_ant_menu",
16
+ packages=setuptools.find_packages(),
17
+ include_package_data=True,
18
+ classifiers=[],
19
+ python_requires=">=3.6",
20
+ install_requires=[
21
+ # By definition, a Custom Component depends on Streamlit.
22
+ # If your component has other Python dependencies, list
23
+ # them here.
24
+ "streamlit >= 0.63",
25
+ ],
26
+ )
@@ -0,0 +1,132 @@
1
+ import streamlit.components.v1 as components
2
+ import os
3
+
4
+ _RELEASE = True
5
+
6
+ if not _RELEASE:
7
+ # Declare the component with a given name and URL if we're not in release mode.
8
+ _component_func = components.declare_component(
9
+ # We give the component a simple, descriptive name ("my_component"
10
+ # does not fit this bill, so please choose something better for your
11
+ # own component :)
12
+ "st_ant_menu",
13
+ # Pass `url` here to tell Streamlit that the component will be served
14
+ # by the local dev server that you run via `npm run start`.
15
+ # (This is useful while your component is in development.)
16
+ url="http://localhost:3000",
17
+ )
18
+ else:
19
+ # When we're distributing a production version of the component, we'll
20
+ # replace the `url` param with `path`, and point it to to the component's
21
+ # build directory:
22
+ parent_dir = os.path.dirname(os.path.abspath(__file__))
23
+ build_dir = os.path.join(parent_dir, "frontend/build")
24
+ _component_func = components.declare_component("st_ant_menu", path=build_dir)
25
+
26
+
27
+ def validate_menu_data(menu_data):
28
+ if not isinstance(menu_data, list):
29
+ raise ValueError("menu_data must be a list of dictionaries")
30
+
31
+ for item in menu_data:
32
+ if not isinstance(item, dict):
33
+ raise ValueError("Each menu item must be a dictionary")
34
+
35
+ if "key" not in item or "label" not in item:
36
+ raise ValueError("Each menu item must have 'key' and 'label' fields")
37
+
38
+ if "label" in item and item["label"] is not None and not isinstance(item["label"], str):
39
+ raise ValueError("The 'label' field must be a string or null")
40
+
41
+ if "icon" in item and not isinstance(item["icon"], str):
42
+ raise ValueError("The 'icon' field must be a string")
43
+
44
+ if "children" in item:
45
+ if not isinstance(item["children"], list):
46
+ raise ValueError("The 'children' field must be a list of dictionaries")
47
+ validate_menu_data(item["children"])
48
+
49
+ if "type" in item and item["type"] not in [None, "group", "divider"]:
50
+ raise ValueError("The 'type' field must be either 'group', 'divider', or null")
51
+
52
+ if "disabled" in item and not isinstance(item["disabled"], bool):
53
+ raise ValueError("The 'disabled' field must be a boolean")
54
+
55
+
56
+ def st_ant_menu(menu_data = None, key="first_menu", defaultValue=[], defaultSelectedKeys=[], defaultOpenKeys=[], additionalHeight=0, multiple=False, css_styling=None, css_styling_menu=None,
57
+ generall_css_styling=None, theme="light",menu_click=False, iconSize=15, modus = "inline", inlineIndent=24, close_auto=True, custom_font_awesome_url = "https://kit.fontawesome.com/c7cbba6207.js",
58
+ iconMinWidth=20,return_value=True) :
59
+ """
60
+ Create a menu component that can be used in Streamlit.
61
+
62
+ generall_css_styling example:
63
+
64
+ .ant-menu-item-divider {
65
+ /* Add your custom styles for the divider here */
66
+ border-top: 3px solid red !important;
67
+ }
68
+
69
+
70
+ :param menu_data: The data to be displayed in the menu. Must be a list of dictionaries
71
+ that conform to the Ant Design Menu item specification. See
72
+ https://ant.design/components/menu/#Menu.Item for more information.
73
+ :param key: The key associated with the component. This is used to ensure that
74
+ the component is rendered properly when its value changes.
75
+ :param defaultValue: The default value to be displayed in the component.
76
+ :param defaultSelectedKeys: The default selected keys in the menu.
77
+ :param defaultOpenKeys: The default open keys in the menu.
78
+ :param additionalHeight: The additional height of the menu that should be added
79
+ to the Streamlit iframe height. This is used to ensure that the entire menu
80
+ is visible in the Streamlit app.
81
+ :param multiple: Whether the menu allows multiple selections. (Broken)
82
+ :param css_styling_menu: A dictionary of CSS styling to be applied to the Menu component.
83
+ :param theme: The theme of the menu. Can be either "light" or "dark".
84
+ :param iconSize: The size of the icons in the menu. Default is 15.
85
+ :param modus: The modus of the menu. Can be either "inline" or "horizontal".
86
+ :param inlineIndent: The indent of the menu items in inline modus. Default is 24.
87
+ :param close_auto: Whether the menus collapse if another one is opened. Default is True.
88
+ :param custom_font_awesome_url: The url of the font awesome library. Default is "https://kit.fontawesome.com/c7cbba6207.js".
89
+ :param iconMinWidth: The minimum width of the icons in the menu. Default is 30. - Used to make sure that the text always starts at the same position.
90
+ :param return_value: Whether the component should return a value. Default is True.
91
+
92
+ :return: The value of the component.
93
+ """
94
+ # css_styling is an alias for css_styling_menu (fixes #2)
95
+ if css_styling is not None and css_styling_menu is None:
96
+ css_styling_menu = css_styling
97
+
98
+ # Call the component function with the given parameters.
99
+ component_value = _component_func(
100
+ menu_data=menu_data,
101
+ key=key,
102
+ defaultSelectedKeys=defaultSelectedKeys,
103
+ defaultOpenKeys=defaultOpenKeys,
104
+ default=defaultValue,
105
+ multiple=multiple,
106
+ additionalHeight=additionalHeight,
107
+ css_styling_menu=css_styling_menu,
108
+ generall_css_styling=generall_css_styling,
109
+ theme = theme,
110
+ menu_click = menu_click,
111
+ iconSize = iconSize,
112
+ modus = modus,
113
+ inlineIndent = inlineIndent,
114
+ close_auto = close_auto,
115
+ custom_font_awesome_url = custom_font_awesome_url,
116
+ iconMinWidth = iconMinWidth
117
+ )
118
+ # Return the component value, handling the case where it's a list.
119
+ if return_value == True:
120
+ if menu_click == True:
121
+ if isinstance(component_value, list):
122
+ return component_value[0] if len(component_value) == 1 else component_value[-1]
123
+
124
+ if multiple == False:
125
+ if isinstance(component_value, list):
126
+ if len(component_value) == 0:
127
+ return None
128
+ else:
129
+ return component_value[0]
130
+
131
+
132
+ return component_value
@@ -0,0 +1,19 @@
1
+ {
2
+ "files": {
3
+ "main.js": "./static/js/main.d3acb81e.chunk.js",
4
+ "main.js.map": "./static/js/main.d3acb81e.chunk.js.map",
5
+ "runtime-main.js": "./static/js/runtime-main.ac51b7c4.js",
6
+ "runtime-main.js.map": "./static/js/runtime-main.ac51b7c4.js.map",
7
+ "static/js/2.eb109dfa.chunk.js": "./static/js/2.eb109dfa.chunk.js",
8
+ "static/js/2.eb109dfa.chunk.js.map": "./static/js/2.eb109dfa.chunk.js.map",
9
+ "index.html": "./index.html",
10
+ "precache-manifest.05c7b8bb9328961b3aab59d9f6f17ff0.js": "./precache-manifest.05c7b8bb9328961b3aab59d9f6f17ff0.js",
11
+ "service-worker.js": "./service-worker.js",
12
+ "static/js/2.eb109dfa.chunk.js.LICENSE.txt": "./static/js/2.eb109dfa.chunk.js.LICENSE.txt"
13
+ },
14
+ "entrypoints": [
15
+ "static/js/runtime-main.ac51b7c4.js",
16
+ "static/js/2.eb109dfa.chunk.js",
17
+ "static/js/main.d3acb81e.chunk.js"
18
+ ]
19
+ }