Skip to content

Commit 2aee8e3

Browse files
committed
add iconPosition prop to Tabs component
1 parent 45d7761 commit 2aee8e3

3 files changed

Lines changed: 62 additions & 13 deletions

File tree

chartlets.py/CHANGES.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Version 0.1.8 (in development)
22

3+
* Added `iconPosition` to `Tabs` Component. (#135)
4+
35
## Version 0.1.7 (from 2025/12/03)
46

57
* Updated dependencies
@@ -11,10 +13,10 @@
1113

1214
## Version 0.1.5 (from 2025/03/21)
1315

14-
* Add `multiple` property for `Select` component to enable the
16+
* Added `multiple` property for `Select` component to enable the selection
1517
of multiple elements.
1618

17-
* Add support for `Python 3.13`
19+
* Added support for `Python 3.13`
1820

1921

2022
## Version 0.1.4 (from 2025/03/06)

chartlets.py/chartlets/components/tabs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class Tab(Component):
1212
icon: str | None = None
1313
"""The tab icon's name."""
1414

15+
iconPosition: str | None = None
16+
""" The position of the icon relative to the label.
17+
One of "bottom" | "end" | "start" | "top".
18+
Defaults to "top".
19+
"""
20+
1521
label: str | None = None
1622
"""The tab label."""
1723

chartlets.py/demo/my_extension/my_panel_8.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Box,
1010
VegaChart,
1111
Table,
12-
IconButton,
1312
Button,
1413
)
1514
from chartlets.components.table import TableColumn, TableRow
@@ -47,12 +46,21 @@ def render_panel(
4746
]
4847

4948
open_button = Button(
50-
id="open_button", startIcon="Insights", text="Please click here!"
49+
id="open_button", text="Show component!", style={"margin": "20px"}
5150
)
5251

53-
table = Table(id="table", rows=rows, columns=columns, hover=True)
52+
table = Table(
53+
id="table",
54+
rows=rows,
55+
columns=columns,
56+
hover=True,
57+
style={"width": "250px", "margin": "30px"},
58+
)
59+
60+
info_text = Typography(
61+
id="info_text", children=["This is a text."], style={"color": "pink"}
62+
)
5463

55-
info_text = Typography(id="info_text", children=["This is a text."])
5664
chart = VegaChart(
5765
id="chart",
5866
chart=(
@@ -61,15 +69,32 @@ def render_panel(
6169
.encode(x=alt.X("x:N", title="x"), y=alt.Y("a:Q", title="a"))
6270
.properties(width=290, height=300, title="Vega charts")
6371
),
64-
style={"flexGrow": 1},
72+
style={"flexGrow": 1, "margin": "10px"},
6573
)
6674

67-
tab1 = Tab(id="tab1", label="Tab 1", children=[table])
75+
tab1 = Tab(
76+
id="tab1",
77+
label="Tab 1",
78+
children=[table],
79+
style={"backgroundColor": "darkblue", "padding": "1px"},
80+
)
6881
tab2 = Tab(id="tab2", label="Tab 2", children=[info_text])
69-
tab3 = Tab(id="tab3", label="Tab 3", children=[chart])
82+
tab3 = Tab(
83+
id="tab3",
84+
label="Tab 3",
85+
children=[chart],
86+
style={
87+
"color": "darkseagreen",
88+
"backgroundColor": "darkgreen",
89+
"padding": "1px",
90+
},
91+
)
7092

7193
tabs = Tabs(
72-
id="tabs", value=0, children=[tab1, tab2, tab3], style={"visibility": "hidden"}
94+
id="tabs",
95+
value=0,
96+
children=[tab1, tab2, tab3],
97+
style={"visibility": "hidden"},
7398
)
7499

75100
return Box(
@@ -84,6 +109,22 @@ def render_panel(
84109

85110

86111
# noinspection PyUnusedLocal
87-
@panel.callback(Input("open_button", "clicked"), Output("tabs", "style"))
88-
def tabs_on_open(ctx: Context, button) -> dict:
89-
return {"visibility": "visible"}
112+
@panel.callback(
113+
Input("open_button", "clicked"),
114+
Input("tabs", "style"),
115+
Output("tabs", "style"),
116+
Output("open_button", "text"),
117+
)
118+
def tabs_on_open(ctx: Context, button, style) -> tuple[dict, str]:
119+
visibility = style["visibility"]
120+
121+
if visibility == "hidden":
122+
return (
123+
{**style, "visibility": "visible"},
124+
"Hide component!",
125+
)
126+
else:
127+
return (
128+
{**style, "visibility": "hidden"},
129+
"Show component!",
130+
)

0 commit comments

Comments
 (0)