Skip to content

Commit

Permalink
fix(modal): temporary fix for incompatible third-party modals
Browse files Browse the repository at this point in the history
  • Loading branch information
aarthy-dk committed Aug 16, 2024
1 parent 5a71652 commit 5cb0cf0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ dependencies = [
"streamlit-option-menu==0.3.6",
"streamlit-authenticator==0.2.3",
"streamlit-javascript==0.1.5",
"streamlit-modal==0.1.0",
"progress==1.6",
"beautifulsoup4==4.12.3",
"trino==0.327.0",
Expand Down
28 changes: 26 additions & 2 deletions testgen/ui/components/widgets/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,34 @@

import streamlit
import streamlit.components.v1 as components
from streamlit_modal import Modal as BaseModal

# This is a custom version of the "streamlit-modal" third-party library
# The original library is not compatible with streamlit 1.30+
# https://github.com/teamtv/streamlit_modal/issues/19

# This is temporary until we replace our modals with the new native st.dialog feature
# https://docs.streamlit.io/develop/api-reference/execution-flow/st.dialog

class Modal:

def __init__(self, title, key, padding=20, max_width=None):
self.title = title
self.padding = padding
self.max_width = max_width
self.key = key

def is_open(self):
return streamlit.session_state.get(f"{self.key}-opened", False)

def open(self):
streamlit.session_state[f"{self.key}-opened"] = True
streamlit.rerun()

def close(self, rerun=True):
streamlit.session_state[f"{self.key}-opened"] = False
if rerun:
streamlit.rerun()

class Modal(BaseModal):
@contextmanager
def container(self):
streamlit.markdown(self._modal_styles(), unsafe_allow_html=True)
Expand Down

0 comments on commit 5cb0cf0

Please sign in to comment.