Skip to content

Commit b0ee3e8

Browse files
committed
Introduced Typography component and using it in a 3rd demo panel
1 parent 03a466d commit b0ee3e8

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from .box import Box
22
from .button import Button
3+
from .checkbox import Checkbox
34
from .dropdown import Dropdown
45
from .plot import Plot
6+
from .typography import Typography
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from dataclasses import dataclass
2+
3+
from dashipy import Component
4+
5+
6+
@dataclass(frozen=True)
7+
class Typography(Component):
8+
text: str | None = None

dashipy/my_extension/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from dashipy import Extension
22
from .my_panel_1 import panel as my_panel_1
33
from .my_panel_2 import panel as my_panel_2
4+
from .my_panel_3 import panel as my_panel_3
45

56
ext = Extension(__name__)
67
ext.add(my_panel_1)
78
ext.add(my_panel_2)
9+
ext.add(my_panel_3)

dashipy/my_extension/my_panel_3.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from dashipy import Component, Input, Output
2+
from dashipy.components import Box, Dropdown, Checkbox, Typography
3+
from dashipy.demo.contribs import Panel
4+
from dashipy.demo.context import Context
5+
6+
7+
panel = Panel(__name__, title="Panel C")
8+
9+
10+
COLORS = [("red", 0), ("green", 1), ("blue", 2), ("yellow", 3)]
11+
12+
13+
@panel.layout(
14+
Input(kind="AppState", property="selectedDatasetId"),
15+
)
16+
def render_panel(
17+
ctx: Context,
18+
dataset_id: str = "",
19+
) -> Component:
20+
21+
opaque = False
22+
color = 0
23+
24+
opaque_checkbox = Checkbox(
25+
id="opaque",
26+
value=opaque,
27+
label="Opaque",
28+
)
29+
30+
color_dropdown = Dropdown(
31+
id="color",
32+
value=color,
33+
label="Color",
34+
options=COLORS,
35+
style={"flexGrow": 0, "minWidth": 80},
36+
)
37+
38+
info_text = Typography(
39+
id="info_text", text=update_info_text(ctx, dataset_id, opaque, color)
40+
)
41+
42+
return Box(
43+
style={
44+
"display": "flex",
45+
"flexDirection": "column",
46+
"width": "100%",
47+
"height": "100%",
48+
"gap": "6px",
49+
},
50+
children=[opaque_checkbox, color_dropdown, info_text],
51+
)
52+
53+
54+
# noinspection PyUnusedLocal
55+
@panel.callback(
56+
Input(kind="AppState", property="selectedDatasetId"),
57+
Input("opaque"),
58+
Input("color"),
59+
Output("info_text", "text"),
60+
)
61+
def update_info_text(
62+
ctx: Context,
63+
dataset_id: str = "",
64+
opaque: bool = False,
65+
color: int = 0,
66+
) -> str:
67+
opaque = opaque or False
68+
color = color if color is not None else 0
69+
return (
70+
f"The dataset is {dataset_id},"
71+
f" the color is {COLORS[color][0]} and"
72+
f" it {'is' if opaque else 'is not'} opaque"
73+
)

0 commit comments

Comments
 (0)