From 50a1a83257a7ab1332c1671276c7cf17c28e69f9 Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Sun, 3 Mar 2024 13:39:41 -0800 Subject: [PATCH] add support for button --- setup.py | 2 +- streamfy/__init__.py | 19 ++++++++++++++----- streamfy/frontend/src/Streamfy.vue | 25 +++++++++++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index e81447e..e229697 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="streamfy", - version="0.1.6", + version="0.1.7", author="", author_email="", description="", diff --git a/streamfy/__init__.py b/streamfy/__init__.py index 12666ef..618bf0f 100644 --- a/streamfy/__init__.py +++ b/streamfy/__init__.py @@ -27,6 +27,16 @@ def hyphen_case_keys(args): snaked[new_key] = value return snaked +def breadcrumb(**kwargs): + hyphened = hyphen_case_keys(kwargs) + component_value = _component_func(component="breadcrumb", **hyphened) + return component_value + +def button(**kwargs): + hyphened = hyphen_case_keys(kwargs) + component_value = _component_func(component="button", **hyphened) + return component_value + def taginput(**kwargs): hyphened = hyphen_case_keys(kwargs) component_value = _component_func(component="taginput", **hyphened) @@ -37,16 +47,15 @@ def table(**kwargs): component_value = _component_func(component="table", **hyphened) return component_value -def breadcrumb(**kwargs): - hyphened = hyphen_case_keys(kwargs) - component_value = _component_func(component="breadcrumb", **hyphened) - return component_value - if not _RELEASE: st.subheader("Breadcrumb") item = breadcrumb(items=[{"text": "A"}, {"text": "B"}]) st.write(item) + st.subheader("Button") + if button(text = "Click!"): + st.write("Clicked!") + st.subheader("Tags") tags = taginput(data=["A", "B", "C"], allow_new=True, open_on_focus=True, type="is-info", aria_close_label="Remove", placeholder="Choose letter") st.write(tags) diff --git a/streamfy/frontend/src/Streamfy.vue b/streamfy/frontend/src/Streamfy.vue index f8408e7..5c7ee4c 100644 --- a/streamfy/frontend/src/Streamfy.vue +++ b/streamfy/frontend/src/Streamfy.vue @@ -8,15 +8,19 @@ v-for="item in args.items" :key="item.text" v-bind="item" - tag="router-link" - to="#" - @click="click(item.text)" + @click="click(item)" >{{item.text}} + + {{ args.text}} + Streamlit.setFrameHeight(), 200); }, click(value) { - Streamlit.setComponentValue(value) + this.result = value }, }, watch: { - tags() { - Streamlit.setComponentValue([...this.tags]); + result() { + if (this.result?.length) + Streamlit.setComponentValue([...this.result]); + else if (typeof(this.result) == 'object') + Streamlit.setComponentValue(Object.assign({}, this.result)); + else + Streamlit.setComponentValue(this.result); }, }, setup() {