From 1cea9afe6fe9c5a2160d43088ce2f3213f778f04 Mon Sep 17 00:00:00 2001 From: anish-work Date: Wed, 17 Jul 2024 20:18:50 +0530 Subject: [PATCH] use new code editor --- gooey_ui/components/__init__.py | 16 ++++++++++++++++ recipes/Functions.py | 6 ++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gooey_ui/components/__init__.py b/gooey_ui/components/__init__.py index c87e3a90d..40a41bd5a 100644 --- a/gooey_ui/components/__init__.py +++ b/gooey_ui/components/__init__.py @@ -367,6 +367,22 @@ def text_area( return value or "" +def code_editor( + value: str = "", + key: str = None, + **props, +) -> typing.Any: + value = str(state.session_state.setdefault(key, value) or "") + return state.RenderTreeNode( + name="code-editor", + props=dict( + name=key, + defaultValue=value, + **props, + ), + ).mount() + + def nrows_for_text( text: str, max_height_px: int, diff --git a/recipes/Functions.py b/recipes/Functions.py index 9175326e3..723aef00b 100644 --- a/recipes/Functions.py +++ b/recipes/Functions.py @@ -75,10 +75,8 @@ def run_v2( response.error = data.get("error") def render_form_v2(self): - st.text_area( - "##### " + field_title_desc(self.RequestModel, "code"), - key="code", - ) + st.caption("##### " + field_title_desc(self.RequestModel, "code")) + st.code_editor(key="code", language="javascript", height=300) def render_variables(self): variables_input(template_keys=["code"], allow_add=True)