From ae136ab6b589ec8babd2790ad5b857073009fef0 Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Wed, 16 Jul 2025 10:20:53 +0200 Subject: [PATCH 1/7] add show_close_button option --- streamlit_modal/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/streamlit_modal/__init__.py b/streamlit_modal/__init__.py index 794b28e..bb98f01 100644 --- a/streamlit_modal/__init__.py +++ b/streamlit_modal/__init__.py @@ -13,7 +13,7 @@ class Modal: - def __init__(self, title, key, padding=20, max_width=744): + def __init__(self, title, key, padding=20, max_width=744, show_close_button=True): """ :param title: title of the Modal shown in the h1 :param key: unique key identifying this modal instance @@ -24,6 +24,7 @@ def __init__(self, title, key, padding=20, max_width=744): self.padding = padding self.max_width = str(max_width) + "px" self.key = key + self.show_close_button = show_close_button def is_open(self): return st.session_state.get(f'{self.key}-opened', False) @@ -114,10 +115,11 @@ def container(self): if self.title: with title: st.header(self.title) - with close_button: - close_ = st.button('X', key=f'{self.key}-close') - if close_: - self.close() + if self.show_close_button: + with close_button: + close_ = st.button('X', key=f'{self.key}-close') + if close_: + self.close() _container.divider() From 8923077b88f47482da57c2d5c45bbfdd1c138f10 Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Mon, 11 Aug 2025 10:38:53 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ae562df..eaead96 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ -# Streamlit modal +# st-modal -Modal support for streamlit. The hackish way. +Modal support for streamlit. A fork from https://github.com/teamtv/streamlit_modal with a few adjustments. ## Example ```python import streamlit as st -from streamlit_modal import Modal +from st_modal import Modal import streamlit.components.v1 as components - modal = Modal( "Demo Modal", key="demo-modal", @@ -44,5 +43,5 @@ if modal.is_open(): ## Install ```shell script -pip install streamlit-modal +pip install st-modal ``` From 5d93604498688758fbe666a4918a1887b4b61fa7 Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Mon, 11 Aug 2025 10:58:32 +0200 Subject: [PATCH 3/7] update pckge name --- examples/simple.py | 2 +- examples/with_sidebar.py | 2 +- pyproject.toml | 40 +++++++++++++++++++++++ setup.py | 6 ++-- {streamlit_modal => st_modal}/__init__.py | 0 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 pyproject.toml rename {streamlit_modal => st_modal}/__init__.py (100%) diff --git a/examples/simple.py b/examples/simple.py index 0c3af13..75fe671 100644 --- a/examples/simple.py +++ b/examples/simple.py @@ -1,5 +1,5 @@ import streamlit as st -from streamlit_modal import Modal +from st_modal import Modal import streamlit.components.v1 as components diff --git a/examples/with_sidebar.py b/examples/with_sidebar.py index 8136314..6607bc0 100644 --- a/examples/with_sidebar.py +++ b/examples/with_sidebar.py @@ -1,5 +1,5 @@ import streamlit as st -from streamlit_modal import Modal +from st_modal import Modal import streamlit.components.v1 as components diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7cf65d7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,40 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "st-modal" +version = "1.0.0" +description = "Modal for streamlit" +readme = "README.md" +license = {text = "BSD"} +authors = [ + {name = "Peter van Lunteren"} +] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: BSD License", + "Topic :: Scientific/Engineering", + "Development Status :: 4 - Beta", + "Framework :: Streamlit" +] +keywords = ["streamlit", "modal", "dialog", "ui", "component"] +dependencies = [ + "streamlit", + "deprecation" +] +requires-python = ">=3.7" + +[tool.setuptools] +packages = ["st_modal"] + +[tool.setuptools.package-data] +st_modal = ["*.py"] \ No newline at end of file diff --git a/setup.py b/setup.py index 2bb2185..f9679e8 100644 --- a/setup.py +++ b/setup.py @@ -7,11 +7,11 @@ def setup_package(): readme = f.read() setup( - name="streamlit_modal", + name="st-modal", install_requires=['streamlit', 'deprecation'], version="0.1.2", - author="Koen Vossen", - author_email="info@koenvossen.nl", + author="Peter van Lunteren", + author_email="", url="https://github.com/teamtv/streamlit_modal", packages=setuptools.find_packages(), license="BSD", diff --git a/streamlit_modal/__init__.py b/st_modal/__init__.py similarity index 100% rename from streamlit_modal/__init__.py rename to st_modal/__init__.py From a586afc223c16a2e71bd315d8b99babd7c76364e Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Mon, 11 Aug 2025 11:00:37 +0200 Subject: [PATCH 4/7] update readme --- README.md | 68 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index eaead96..c8f784f 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,55 @@ # st-modal -Modal support for streamlit. A fork from https://github.com/teamtv/streamlit_modal with a few adjustments. +A modern modal dialog component for Streamlit applications. This is a fork of the original [streamlit_modal](https://github.com/teamtv/streamlit_modal) with improvements and adjustments. -## Example +## Installation + +```bash +pip install st-modal +``` + +## Quick Start ```python import streamlit as st from st_modal import Modal -import streamlit.components.v1 as components - -modal = Modal( - "Demo Modal", - key="demo-modal", - - # Optional - padding=20, # default value - max_width=744 # default value -) -open_modal = st.button("Open") -if open_modal: +# Create modal +modal = Modal("My Modal", key="my-modal") + +# Trigger to open modal +if st.button("Open Modal"): modal.open() +# Modal content if modal.is_open(): with modal.container(): - st.write("Text goes here") + st.write("Hello from inside the modal!") + + value = st.slider("Pick a value", 0, 100, 50) + st.write(f"Selected: {value}") + + if st.button("Close", key="close-modal"): + modal.close() +``` - html_string = ''' -

HTML string in RED

+## API Reference - - ''' - components.html(html_string) +### Modal Class - st.write("Some fancy text") - value = st.checkbox("Check me") - st.write(f"Checkbox checked: {value}") +```python +Modal(title, key, padding=20, max_width=744, show_close_button=True) ``` -## Install - -```shell script -pip install st-modal -``` +**Parameters:** +- `title` (str): Title displayed at the top of the modal +- `key` (str): Unique identifier for the modal (required) +- `padding` (int): Internal padding in pixels (default: 20) +- `max_width` (int): Maximum width in pixels (default: 744) +- `show_close_button` (bool): Whether to show the X close button (default: True) + +**Methods:** +- `modal.open()`: Opens the modal and triggers a rerun +- `modal.close()`: Closes the modal and triggers a rerun +- `modal.is_open()`: Returns True if modal is currently open +- `modal.container()`: Context manager for adding content to the modal \ No newline at end of file From 672dab6fd87652347aa2a1d2c680b3eeafede70b Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Wed, 5 Nov 2025 13:33:33 +0100 Subject: [PATCH 5/7] add params to hide title and divider --- pyproject.toml | 7 ++++++- setup.py | 37 ------------------------------------- st_modal/__init__.py | 14 ++++++++++---- 3 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index 7cf65d7..18c425c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "st-modal" -version = "1.0.0" +version = "0.1.3" description = "Modal for streamlit" readme = "README.md" license = {text = "BSD"} @@ -33,6 +33,11 @@ dependencies = [ ] requires-python = ">=3.7" +[project.urls] +Homepage = "https://github.com/PetervanLunteren/st-modal" +Repository = "https://github.com/PetervanLunteren/st-modal" +Issues = "https://github.com/PetervanLunteren/st-modal/issues" + [tool.setuptools] packages = ["st_modal"] diff --git a/setup.py b/setup.py deleted file mode 100644 index f9679e8..0000000 --- a/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -import setuptools -from distutils.core import setup - - -def setup_package(): - with open("README.md", "r") as f: - readme = f.read() - - setup( - name="st-modal", - install_requires=['streamlit', 'deprecation'], - version="0.1.2", - author="Peter van Lunteren", - author_email="", - url="https://github.com/teamtv/streamlit_modal", - packages=setuptools.find_packages(), - license="BSD", - description="Modal for streamlit", - long_description=readme, - long_description_content_type="text/markdown", - classifiers=[ - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "License :: OSI Approved", - "Topic :: Scientific/Engineering", - ] - ) - - -if __name__ == "__main__": - setup_package() \ No newline at end of file diff --git a/st_modal/__init__.py b/st_modal/__init__.py index bb98f01..5d84c09 100644 --- a/st_modal/__init__.py +++ b/st_modal/__init__.py @@ -13,18 +13,23 @@ class Modal: - def __init__(self, title, key, padding=20, max_width=744, show_close_button=True): + def __init__(self, title, key, padding=20, max_width=744, show_close_button=True, show_title=True, show_divider=True): """ :param title: title of the Modal shown in the h1 :param key: unique key identifying this modal instance :param padding: padding of the content within the modal :param max_width: maximum width this modal should use + :param show_close_button: whether to show the X close button + :param show_title: whether to show the title header + :param show_divider: whether to show the divider line below the header """ self.title = title self.padding = padding self.max_width = str(max_width) + "px" self.key = key self.show_close_button = show_close_button + self.show_title = show_title + self.show_divider = show_divider def is_open(self): return st.session_state.get(f'{self.key}-opened', False) @@ -112,7 +117,7 @@ def container(self): _container = st.container() title, close_button = _container.columns([0.9, 0.1]) - if self.title: + if self.show_title and self.title: with title: st.header(self.title) if self.show_close_button: @@ -120,8 +125,9 @@ def container(self): close_ = st.button('X', key=f'{self.key}-close') if close_: self.close() - - _container.divider() + + if self.show_divider: + _container.divider() components.html( f""" From c15e26aaad39574661cced91b97afa59b4cf3192 Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Wed, 5 Nov 2025 13:38:42 +0100 Subject: [PATCH 6/7] upadte versioning and readme --- README.md | 4 +++- pyproject.toml | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c8f784f..d580b17 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ if modal.is_open(): ### Modal Class ```python -Modal(title, key, padding=20, max_width=744, show_close_button=True) +Modal(title, key, padding=20, max_width=744, show_close_button=True, show_title=True, show_divider=True) ``` **Parameters:** @@ -47,6 +47,8 @@ Modal(title, key, padding=20, max_width=744, show_close_button=True) - `padding` (int): Internal padding in pixels (default: 20) - `max_width` (int): Maximum width in pixels (default: 744) - `show_close_button` (bool): Whether to show the X close button (default: True) +- `show_title` (bool): Whether to show the title header (default: True) +- `show_divider` (bool): Whether to show the divider line below the header (default: True) **Methods:** - `modal.open()`: Opens the modal and triggers a rerun diff --git a/pyproject.toml b/pyproject.toml index 18c425c..69dbf35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "st-modal" -version = "0.1.3" +version = "1.0.1" description = "Modal for streamlit" readme = "README.md" license = {text = "BSD"} @@ -23,8 +23,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", "License :: OSI Approved :: BSD License", "Topic :: Scientific/Engineering", - "Development Status :: 4 - Beta", - "Framework :: Streamlit" + "Development Status :: 4 - Beta" ] keywords = ["streamlit", "modal", "dialog", "ui", "component"] dependencies = [ From 92d0303ae61a87d7cc821f4dc4cbd78eff479919 Mon Sep 17 00:00:00 2001 From: Peter van Lunteren Date: Wed, 5 Nov 2025 13:41:02 +0100 Subject: [PATCH 7/7] bump package version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 69dbf35..dc40217 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "st-modal" -version = "1.0.1" +version = "1.0.2" description = "Modal for streamlit" readme = "README.md" license = {text = "BSD"}