Py.Cafe

iisakkirotko/

solara-text-input-example

Solara Text Input Example

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import solara
from typing import Union, Dict


@solara.component
def MyTextField(value: solara.Reactive[str], label: str="", label_style: Union[str, Dict[str, str]]=""):
    style_flat = solara.util._flatten_style(label_style)
    with solara.Row(style={"align-items": "center"}): # align-items makes all children float to the vertical center
        solara.Text(label, style=label_style)
        solara.InputText(label="", value=value, continuous_update=True)


@solara.component
def Page():
    name = solara.use_reactive("")
    MyTextField(name, "Enter your name", "color: red;")
    solara.Markdown(f"Your name is: {name.value}")