Skip to content

Commit

Permalink
add support for button
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Mar 3, 2024
1 parent 3eaadd7 commit 50a1a83
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="streamfy",
version="0.1.6",
version="0.1.7",
author="",
author_email="",
description="",
Expand Down
19 changes: 14 additions & 5 deletions streamfy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 17 additions & 8 deletions streamfy/frontend/src/Streamfy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
</b-breadcrumb-item>
</b-breadcrumb>
<b-button
v-else-if="args.component == 'button'"
v-bind="args"
@click="click(args)">
{{ args.text}}
</b-button>
<b-taginput
v-else-if="args.component == 'taginput'"
v-model="tags"
v-model="result"
v-bind="args"
@focus="focused"
@blur="blured"
Expand All @@ -42,7 +46,7 @@ export default {
props: ["args"],
data() {
return {
tags: [],
result: [],
jdata: undefined,
}
},
Expand All @@ -60,12 +64,17 @@ export default {
setTimeout(() => 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() {
Expand Down

0 comments on commit 50a1a83

Please sign in to comment.