Skip to content

Commit dfe4adb

Browse files
committed
Allow configurable title in text_io
1 parent 25144c0 commit dfe4adb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

mesop/examples/text_io.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
@me.page(path="/text_io", title="Text I/O Example")
88
def app():
9-
mel.text_io(upper_case_stream)
9+
mel.text_io(
10+
upper_case_stream,
11+
title="Text I/O Example",
12+
)
1013

1114

1215
def upper_case_stream(s: str):

mesop/labs/io.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class State:
1313

1414
def text_io(
1515
transform: Callable[[str], Generator[str, None, None] | str],
16+
*,
17+
title: str | None = None,
1618
):
1719
"""Creates a simple UI which takes in a text input and returns a text output.
1820
@@ -21,6 +23,7 @@ def text_io(
2123
2224
Args:
2325
transform: Function that takes in a string input and either returns or yields a string output.
26+
title: Headline text to display at the top of the UI
2427
"""
2528

2629
def on_input(e: me.InputEvent):
@@ -50,14 +53,18 @@ def on_click_clear(e: me.ClickEvent):
5053
background="#f0f4f8",
5154
padding=me.Padding(top=24, left=24, right=24, bottom=24),
5255
height="100%",
56+
display="flex",
57+
flex_direction="column",
5358
)
5459
):
60+
if title:
61+
me.text(title, type="headline-5")
5562
with me.box(
5663
style=me.Style(
5764
margin=me.Margin(left="auto", right="auto"),
5865
width="min(1024px, 100%)",
5966
gap="24px",
60-
height="100%",
67+
flex_grow=1,
6168
display="flex",
6269
flex_wrap="wrap",
6370
)

0 commit comments

Comments
 (0)