Skip to content

Commit

Permalink
Revert "revert to radio buttons"
Browse files Browse the repository at this point in the history
Specific request by Sean not sure who to listen to πŸ€·β€β™‚οΈ
This reverts commit a4f768c.
  • Loading branch information
SanderGi committed Oct 6, 2023
1 parent a4f768c commit d4a1290
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
26 changes: 26 additions & 0 deletions gooey_ui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,32 @@ def tabs(labels: list[str]) -> list[state.NestingCtx]:
return [state.NestingCtx(tab) for tab in parent.children]


def controllable_tabs(
labels: list[str], key: str
) -> tuple[list[state.NestingCtx], int]:
index = state.session_state.get(key, 0)
for i, label in enumerate(labels):
if button(
label,
key=f"tab-{i}",
type="primary",
className="replicate-nav",
style={
"background": "black" if i == index else "white",
"color": "white" if i == index else "black",
},
):
state.session_state[key] = index = i
state.experimental_rerun()
ctxs = []
for i, label in enumerate(labels):
if i == index:
ctxs += [div(className="tab-content")]
else:
ctxs += [div(className="tab-content", style={"display": "none"})]
return ctxs, index


def columns(
spec,
*,
Expand Down
24 changes: 8 additions & 16 deletions recipes/QRCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,18 @@ def render_form_v2(self):

st.session_state.setdefault(
"__qr_input_type_index",
"0"
0
if st.session_state.get("qr_code_data")
else "1"
else 1
if st.session_state.get("vcard_data")
else "2",
else 2,
)
st.radio(
"",
options=["0", "1", "2"],
(url, vCard, existing), index = st.controllable_tabs(
["πŸ–ŠοΈ Link or Text", "πŸ“‡ Contact vCard", "πŸ“· Existing QR Code"],
key="__qr_input_type_index",
format_func=lambda x: [
"πŸ–ŠοΈ Link or Text",
"πŸ“‡ Contact vCard",
"πŸ“· Existing QR Code",
][int(x)],
)
index = st.session_state.get("__qr_input_type_index", "0")

if index == "0":
with url:
st.text_area(
"""
### πŸ”— URL
Expand All @@ -187,7 +180,7 @@ def render_form_v2(self):
'A shortened URL enables the QR code to be more beautiful and less "QR-codey" with fewer blocky pixels.'
)

if index == "2":
with existing:
st.file_uploader(
"""
### πŸ“· QR Code Image
Expand All @@ -201,8 +194,7 @@ def render_form_v2(self):
'A shortened URL enables the QR code to be more beautiful and less "QR-codey" with fewer blocky pixels.'
)

if index == "1":
print("hi")
with vCard:
st.caption(
"We'll use the prompt above to create a beautiful QR code that when scanned on a phone, will add the info below as a contact. Great for conferences and geeky parties."
)
Expand Down

0 comments on commit d4a1290

Please sign in to comment.