Skip to content

Commit

Permalink
Clean up some of the examples to work correctly with panels
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed committed Oct 13, 2023
1 parent f1e238e commit f9f9fd6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions plugins/ui/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ c = counter()

## Text field (string)

You can create a [TextField](https://react-spectrum.adobe.com/react-spectrum/TextField.html) that takes input from the user.
You can create a [TextField](https://react-spectrum.adobe.com/react-spectrum/TextField.html) that takes input from the user. You can also use a [Flex](https://react-spectrum.adobe.com/react-spectrum/Flex.html) component to display multiple components in a row (or column, depending on the `direction` argument).

```python
import deephaven.ui as ui
Expand All @@ -58,7 +58,11 @@ from deephaven.ui import use_state
def my_input():
text, set_text = use_state("hello")

return [ui.text_field(value=text, on_change=set_text), ui.text(f"You typed {text}")]
return ui.flex(
ui.text_field(value=text, on_change=set_text),
ui.text(f"You typed {text}"),
direction="column",
)


mi = my_input()
Expand All @@ -78,10 +82,11 @@ from deephaven.ui import use_state
@ui.component
def checkbox_example():
liked, set_liked = use_state(True)
return [
return ui.flex(
ui.checkbox("I liked this", is_selected=liked, on_change=set_liked),
ui.text("You liked this" if liked else "You didn't like this"),
]
direction="column",
)


ce = checkbox_example()
Expand All @@ -103,11 +108,12 @@ def form_example():
name, set_name = use_state("Homer")
age, set_age = use_state(36)

return [
return ui.flex(
ui.text_field(value=name, on_change=set_name),
ui.slider(value=age, on_change=set_age),
ui.text(f"Hello {name}, you are {age} years old"),
]
direction="column",
)


fe = form_example()
Expand Down Expand Up @@ -136,7 +142,12 @@ from deephaven.ui import use_state
def text_filter_table(source, column):
value, set_value = use_state("FISH")
t = source.where(f"{column}=`{value}`")
return [ui.text_field(value=value, on_change=set_value), t]
return ui.flex(
ui.text_field(value=value, on_change=set_value),
t,
direction="column",
flex_grow=1,
)


pp = text_filter_table(stocks, "sym")
Expand Down Expand Up @@ -179,7 +190,7 @@ def stock_widget_table(source, default_sym="", default_exchange=""):
else error_message
)

return [ui.flex(ti1, ti2), t1]
return ui.flex(ui.flex(ti1, ti2), t1, direction="column", flex_grow=1)


swt = stock_widget_table(stocks, "", "")
Expand Down Expand Up @@ -217,7 +228,7 @@ def stock_widget_plot(source, default_sym="", default_exchange=""):
.show()
)

return [ui.flex(ti1, ti2), t1, p]
return ui.flex(ui.flex(ti1, ti2), t1, p, direction="column", flex_grow=1)


swp = stock_widget_plot(stocks, "CAT", "TPET")
Expand Down

0 comments on commit f9f9fd6

Please sign in to comment.