streamlit-react-components 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit_react_components/__init__.py +40 -0
- streamlit_react_components/_frontend/index.css +1 -0
- streamlit_react_components/_frontend/index.html +13 -0
- streamlit_react_components/_frontend/index.js +63 -0
- streamlit_react_components/common/__init__.py +21 -0
- streamlit_react_components/common/button_group.py +57 -0
- streamlit_react_components/common/chart_legend.py +49 -0
- streamlit_react_components/common/data_table.py +65 -0
- streamlit_react_components/common/metric_row.py +47 -0
- streamlit_react_components/common/panel.py +43 -0
- streamlit_react_components/common/section_header.py +59 -0
- streamlit_react_components/common/stat_card.py +54 -0
- streamlit_react_components/common/step_indicator.py +51 -0
- streamlit_react_components/form/__init__.py +11 -0
- streamlit_react_components/form/checkbox_group.py +61 -0
- streamlit_react_components/form/form_select.py +69 -0
- streamlit_react_components/form/form_slider.py +69 -0
- streamlit_react_components-0.1.0.dist-info/METADATA +18 -0
- streamlit_react_components-0.1.0.dist-info/RECORD +21 -0
- streamlit_react_components-0.1.0.dist-info/WHEEL +5 -0
- streamlit_react_components-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Common display components."""
|
|
2
|
+
|
|
3
|
+
from .panel import panel
|
|
4
|
+
from .section_header import section_header
|
|
5
|
+
from .stat_card import stat_card
|
|
6
|
+
from .metric_row import metric_row
|
|
7
|
+
from .data_table import data_table
|
|
8
|
+
from .step_indicator import step_indicator
|
|
9
|
+
from .button_group import button_group
|
|
10
|
+
from .chart_legend import chart_legend
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"panel",
|
|
14
|
+
"section_header",
|
|
15
|
+
"stat_card",
|
|
16
|
+
"metric_row",
|
|
17
|
+
"data_table",
|
|
18
|
+
"step_indicator",
|
|
19
|
+
"button_group",
|
|
20
|
+
"chart_legend",
|
|
21
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""ButtonGroup component - A group of action buttons."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def button_group(
|
|
16
|
+
buttons: List[Dict[str, Any]],
|
|
17
|
+
style: Optional[Dict[str, Any]] = None,
|
|
18
|
+
class_name: str = "",
|
|
19
|
+
key: Optional[str] = None,
|
|
20
|
+
) -> Optional[str]:
|
|
21
|
+
"""
|
|
22
|
+
Display a group of action buttons.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
buttons: List of button configs, each with:
|
|
26
|
+
- id: Unique identifier
|
|
27
|
+
- label: Button text (optional)
|
|
28
|
+
- icon: Button icon/emoji (optional)
|
|
29
|
+
- color: Button color: "blue", "green", "red", "yellow" (optional)
|
|
30
|
+
- disabled: Whether button is disabled (optional)
|
|
31
|
+
style: Inline CSS styles as a dictionary
|
|
32
|
+
class_name: Tailwind CSS classes
|
|
33
|
+
key: Unique key for the component
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
The ID of the clicked button, or None if no click
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
clicked = button_group(
|
|
40
|
+
buttons=[
|
|
41
|
+
{"id": "view", "icon": "👁️"},
|
|
42
|
+
{"id": "edit", "icon": "✏️"},
|
|
43
|
+
{"id": "approve", "icon": "✓", "color": "green"},
|
|
44
|
+
{"id": "reject", "icon": "✕", "color": "red"}
|
|
45
|
+
]
|
|
46
|
+
)
|
|
47
|
+
if clicked == "approve":
|
|
48
|
+
approve_item()
|
|
49
|
+
"""
|
|
50
|
+
return _component(
|
|
51
|
+
component="button_group",
|
|
52
|
+
buttons=buttons,
|
|
53
|
+
style=style,
|
|
54
|
+
className=class_name,
|
|
55
|
+
key=key,
|
|
56
|
+
default=None,
|
|
57
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""ChartLegend component - A chart legend with colored indicators."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def chart_legend(
|
|
16
|
+
items: List[Dict[str, str]],
|
|
17
|
+
style: Optional[Dict[str, Any]] = None,
|
|
18
|
+
class_name: str = "",
|
|
19
|
+
key: Optional[str] = None,
|
|
20
|
+
) -> None:
|
|
21
|
+
"""
|
|
22
|
+
Display a chart legend with colored indicators.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
items: List of legend items, each with:
|
|
26
|
+
- color: CSS color value (e.g., "#3b82f6", "rgb(59,130,246)")
|
|
27
|
+
- label: Legend label text
|
|
28
|
+
style: Inline CSS styles as a dictionary
|
|
29
|
+
class_name: Tailwind CSS classes
|
|
30
|
+
key: Unique key for the component
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
chart_legend(
|
|
34
|
+
items=[
|
|
35
|
+
{"color": "#94a3b8", "label": "Historical"},
|
|
36
|
+
{"color": "#ef4444", "label": "Outlier"},
|
|
37
|
+
{"color": "#8b5cf6", "label": "Prophet"},
|
|
38
|
+
{"color": "#10b981", "label": "ARIMA"}
|
|
39
|
+
]
|
|
40
|
+
)
|
|
41
|
+
"""
|
|
42
|
+
_component(
|
|
43
|
+
component="chart_legend",
|
|
44
|
+
items=items,
|
|
45
|
+
style=style,
|
|
46
|
+
className=class_name,
|
|
47
|
+
key=key,
|
|
48
|
+
default=None,
|
|
49
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""DataTable component - A styled data table with click support."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def data_table(
|
|
16
|
+
columns: List[Dict[str, Any]],
|
|
17
|
+
rows: List[Dict[str, Any]],
|
|
18
|
+
show_header: bool = True,
|
|
19
|
+
style: Optional[Dict[str, Any]] = None,
|
|
20
|
+
class_name: str = "",
|
|
21
|
+
key: Optional[str] = None,
|
|
22
|
+
) -> Optional[Dict[str, Any]]:
|
|
23
|
+
"""
|
|
24
|
+
Display a styled data table with row click support.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
columns: List of column definitions, each with:
|
|
28
|
+
- key: Data key in each row
|
|
29
|
+
- label: Column header text
|
|
30
|
+
- align: "left", "center", or "right" (optional)
|
|
31
|
+
- format: "number" or "percent" (optional)
|
|
32
|
+
- colorByValue: True to color based on status values (optional)
|
|
33
|
+
rows: List of row data dictionaries
|
|
34
|
+
show_header: Whether to show the header row (default True)
|
|
35
|
+
style: Inline CSS styles as a dictionary
|
|
36
|
+
class_name: Tailwind CSS classes
|
|
37
|
+
key: Unique key for the component
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Dictionary with rowIndex and rowData when a row is clicked, None otherwise
|
|
41
|
+
|
|
42
|
+
Example:
|
|
43
|
+
columns = [
|
|
44
|
+
{"key": "site", "label": "Site"},
|
|
45
|
+
{"key": "util", "label": "Utilization", "align": "right", "format": "percent"},
|
|
46
|
+
{"key": "status", "label": "Status", "colorByValue": True}
|
|
47
|
+
]
|
|
48
|
+
rows = [
|
|
49
|
+
{"site": "AML_14", "util": 94, "status": "above"},
|
|
50
|
+
{"site": "ADL", "util": 72, "status": "within"}
|
|
51
|
+
]
|
|
52
|
+
clicked = data_table(columns=columns, rows=rows)
|
|
53
|
+
if clicked:
|
|
54
|
+
st.write(f"Clicked row: {clicked['rowData']}")
|
|
55
|
+
"""
|
|
56
|
+
return _component(
|
|
57
|
+
component="data_table",
|
|
58
|
+
columns=columns,
|
|
59
|
+
rows=rows,
|
|
60
|
+
showHeader=show_header,
|
|
61
|
+
style=style,
|
|
62
|
+
className=class_name,
|
|
63
|
+
key=key,
|
|
64
|
+
default=None,
|
|
65
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""MetricRow component - A key-value display row."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def metric_row(
|
|
16
|
+
label: str,
|
|
17
|
+
value: str,
|
|
18
|
+
value_color: str = "",
|
|
19
|
+
style: Optional[Dict[str, Any]] = None,
|
|
20
|
+
class_name: str = "",
|
|
21
|
+
key: Optional[str] = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
"""
|
|
24
|
+
Display a key-value metric row.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
label: The metric label (left side)
|
|
28
|
+
value: The metric value (right side)
|
|
29
|
+
value_color: Tailwind text color class for the value (e.g., "text-green-400")
|
|
30
|
+
style: Inline CSS styles as a dictionary
|
|
31
|
+
class_name: Tailwind CSS classes
|
|
32
|
+
key: Unique key for the component
|
|
33
|
+
|
|
34
|
+
Example:
|
|
35
|
+
metric_row(label="Mean", value="78.4%")
|
|
36
|
+
metric_row(label="Trend", value="↑ +0.4%/mo", value_color="text-green-400")
|
|
37
|
+
"""
|
|
38
|
+
_component(
|
|
39
|
+
component="metric_row",
|
|
40
|
+
label=label,
|
|
41
|
+
value=value,
|
|
42
|
+
valueColor=value_color,
|
|
43
|
+
style=style,
|
|
44
|
+
className=class_name,
|
|
45
|
+
key=key,
|
|
46
|
+
default=None,
|
|
47
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Panel component - A styled container wrapper."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def panel(
|
|
16
|
+
children: str = "",
|
|
17
|
+
style: Optional[Dict[str, Any]] = None,
|
|
18
|
+
class_name: str = "",
|
|
19
|
+
key: Optional[str] = None,
|
|
20
|
+
) -> None:
|
|
21
|
+
"""
|
|
22
|
+
Display a styled panel/card container.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
children: HTML content to render inside the panel
|
|
26
|
+
style: Inline CSS styles as a dictionary (e.g., {"background": "#1e293b"})
|
|
27
|
+
class_name: Tailwind CSS classes (e.g., "bg-slate-900 p-4")
|
|
28
|
+
key: Unique key for the component
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
panel(
|
|
32
|
+
children="<h3>Title</h3><p>Content here</p>",
|
|
33
|
+
class_name="mt-4"
|
|
34
|
+
)
|
|
35
|
+
"""
|
|
36
|
+
_component(
|
|
37
|
+
component="panel",
|
|
38
|
+
children=children,
|
|
39
|
+
style=style,
|
|
40
|
+
className=class_name,
|
|
41
|
+
key=key,
|
|
42
|
+
default=None,
|
|
43
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""SectionHeader component - A styled section title with optional actions."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def section_header(
|
|
16
|
+
title: str,
|
|
17
|
+
icon: str = "",
|
|
18
|
+
actions: Optional[List[Dict[str, Any]]] = None,
|
|
19
|
+
style: Optional[Dict[str, Any]] = None,
|
|
20
|
+
class_name: str = "",
|
|
21
|
+
key: Optional[str] = None,
|
|
22
|
+
) -> Optional[str]:
|
|
23
|
+
"""
|
|
24
|
+
Display a section header with optional action buttons.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
title: The header title text
|
|
28
|
+
icon: Optional emoji or icon to display before the title
|
|
29
|
+
actions: List of action button configs, each with:
|
|
30
|
+
- id: Unique identifier for the action
|
|
31
|
+
- label: Button text (optional)
|
|
32
|
+
- icon: Button icon (optional)
|
|
33
|
+
- color: Button color: "blue", "green", "red", "yellow" (optional)
|
|
34
|
+
style: Inline CSS styles as a dictionary
|
|
35
|
+
class_name: Tailwind CSS classes
|
|
36
|
+
key: Unique key for the component
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
The ID of the clicked action button, or None if no click
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
clicked = section_header(
|
|
43
|
+
title="Dashboard",
|
|
44
|
+
icon="📊",
|
|
45
|
+
actions=[{"id": "refresh", "label": "Refresh", "color": "blue"}]
|
|
46
|
+
)
|
|
47
|
+
if clicked == "refresh":
|
|
48
|
+
st.rerun()
|
|
49
|
+
"""
|
|
50
|
+
return _component(
|
|
51
|
+
component="section_header",
|
|
52
|
+
title=title,
|
|
53
|
+
icon=icon,
|
|
54
|
+
actions=actions or [],
|
|
55
|
+
style=style,
|
|
56
|
+
className=class_name,
|
|
57
|
+
key=key,
|
|
58
|
+
default=None,
|
|
59
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""StatCard component - A styled statistics display card."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, Optional, Union
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def stat_card(
|
|
16
|
+
label: str,
|
|
17
|
+
value: Union[str, int, float],
|
|
18
|
+
color: str = "blue",
|
|
19
|
+
icon: str = "",
|
|
20
|
+
style: Optional[Dict[str, Any]] = None,
|
|
21
|
+
class_name: str = "",
|
|
22
|
+
key: Optional[str] = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Display a styled statistics card with a label and value.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
label: The description label (e.g., "Total Users")
|
|
29
|
+
value: The statistic value to display
|
|
30
|
+
color: Accent color: "blue", "green", "red", "yellow", "purple"
|
|
31
|
+
icon: Optional emoji or icon to display with the label
|
|
32
|
+
style: Inline CSS styles as a dictionary
|
|
33
|
+
class_name: Tailwind CSS classes
|
|
34
|
+
key: Unique key for the component
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
stat_card(
|
|
38
|
+
label="Within Threshold",
|
|
39
|
+
value="4",
|
|
40
|
+
color="green",
|
|
41
|
+
style={"minWidth": "150px"}
|
|
42
|
+
)
|
|
43
|
+
"""
|
|
44
|
+
_component(
|
|
45
|
+
component="stat_card",
|
|
46
|
+
label=label,
|
|
47
|
+
value=str(value),
|
|
48
|
+
color=color,
|
|
49
|
+
icon=icon,
|
|
50
|
+
style=style,
|
|
51
|
+
className=class_name,
|
|
52
|
+
key=key,
|
|
53
|
+
default=None,
|
|
54
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""StepIndicator component - A multi-step wizard progress indicator."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def step_indicator(
|
|
16
|
+
steps: List[str],
|
|
17
|
+
current_step: int,
|
|
18
|
+
style: Optional[Dict[str, Any]] = None,
|
|
19
|
+
class_name: str = "",
|
|
20
|
+
key: Optional[str] = None,
|
|
21
|
+
) -> Optional[int]:
|
|
22
|
+
"""
|
|
23
|
+
Display a multi-step wizard progress indicator.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
steps: List of step labels (e.g., ["Supply Plan", "Levers", "Review"])
|
|
27
|
+
current_step: Current active step (1-indexed)
|
|
28
|
+
style: Inline CSS styles as a dictionary
|
|
29
|
+
class_name: Tailwind CSS classes
|
|
30
|
+
key: Unique key for the component
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
The step number that was clicked, or None if no click
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
step = step_indicator(
|
|
37
|
+
steps=["Supply Plan", "Levers", "Review"],
|
|
38
|
+
current_step=2
|
|
39
|
+
)
|
|
40
|
+
if step:
|
|
41
|
+
st.session_state.step = step
|
|
42
|
+
"""
|
|
43
|
+
return _component(
|
|
44
|
+
component="step_indicator",
|
|
45
|
+
steps=steps,
|
|
46
|
+
currentStep=current_step,
|
|
47
|
+
style=style,
|
|
48
|
+
className=class_name,
|
|
49
|
+
key=key,
|
|
50
|
+
default=None,
|
|
51
|
+
)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""CheckboxGroup component - A group of checkboxes."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def checkbox_group(
|
|
16
|
+
items: List[Dict[str, Any]],
|
|
17
|
+
label: str = "",
|
|
18
|
+
style: Optional[Dict[str, Any]] = None,
|
|
19
|
+
class_name: str = "",
|
|
20
|
+
key: Optional[str] = None,
|
|
21
|
+
) -> List[str]:
|
|
22
|
+
"""
|
|
23
|
+
Display a group of checkboxes.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
items: List of checkbox items, each with:
|
|
27
|
+
- id: Unique identifier
|
|
28
|
+
- label: Display label
|
|
29
|
+
- checked: Initial checked state (optional, default False)
|
|
30
|
+
label: Optional group label
|
|
31
|
+
style: Inline CSS styles as a dictionary
|
|
32
|
+
class_name: Tailwind CSS classes
|
|
33
|
+
key: Unique key for the component
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
List of checked item IDs
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
selected = checkbox_group(
|
|
40
|
+
label="Parameters",
|
|
41
|
+
items=[
|
|
42
|
+
{"id": "vphp", "label": "VPHP Hold", "checked": True},
|
|
43
|
+
{"id": "lot_co", "label": "Lot C/O", "checked": True},
|
|
44
|
+
{"id": "batch", "label": "Batch Size"}
|
|
45
|
+
]
|
|
46
|
+
)
|
|
47
|
+
# Returns: ["vphp", "lot_co"] if those are checked
|
|
48
|
+
"""
|
|
49
|
+
# Get default checked items
|
|
50
|
+
default_checked = [item["id"] for item in items if item.get("checked", False)]
|
|
51
|
+
|
|
52
|
+
result = _component(
|
|
53
|
+
component="checkbox_group",
|
|
54
|
+
label=label,
|
|
55
|
+
items=items,
|
|
56
|
+
style=style,
|
|
57
|
+
className=class_name,
|
|
58
|
+
key=key,
|
|
59
|
+
default=default_checked,
|
|
60
|
+
)
|
|
61
|
+
return result if result is not None else default_checked
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""FormSelect component - A styled dropdown select input."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, List, Optional, Union
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def form_select(
|
|
16
|
+
label: str,
|
|
17
|
+
options: List[Union[str, Dict[str, str]]],
|
|
18
|
+
value: str = "",
|
|
19
|
+
groups: Optional[List[Dict[str, Any]]] = None,
|
|
20
|
+
style: Optional[Dict[str, Any]] = None,
|
|
21
|
+
class_name: str = "",
|
|
22
|
+
key: Optional[str] = None,
|
|
23
|
+
) -> str:
|
|
24
|
+
"""
|
|
25
|
+
Display a styled dropdown select input.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
label: Label text for the select
|
|
29
|
+
options: List of options, either strings or dicts with {value, label}
|
|
30
|
+
value: Currently selected value
|
|
31
|
+
groups: Optional list of option groups, each with:
|
|
32
|
+
- label: Group header text
|
|
33
|
+
- options: List of options in this group
|
|
34
|
+
style: Inline CSS styles as a dictionary
|
|
35
|
+
class_name: Tailwind CSS classes
|
|
36
|
+
key: Unique key for the component
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
The currently selected value
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
# Simple string options
|
|
43
|
+
site = form_select(
|
|
44
|
+
label="Site",
|
|
45
|
+
options=["AML_14", "ADL", "Devens"],
|
|
46
|
+
value="AML_14"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# With option groups
|
|
50
|
+
version = form_select(
|
|
51
|
+
label="Base On",
|
|
52
|
+
groups=[
|
|
53
|
+
{"label": "Baselines", "options": ["Baseline v7"]},
|
|
54
|
+
{"label": "Scenarios", "options": ["Q2 Demand Surge"]}
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
"""
|
|
58
|
+
result = _component(
|
|
59
|
+
component="form_select",
|
|
60
|
+
label=label,
|
|
61
|
+
options=options,
|
|
62
|
+
value=value,
|
|
63
|
+
groups=groups,
|
|
64
|
+
style=style,
|
|
65
|
+
className=class_name,
|
|
66
|
+
key=key,
|
|
67
|
+
default=value,
|
|
68
|
+
)
|
|
69
|
+
return result if result is not None else value
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""FormSlider component - A styled range slider input."""
|
|
2
|
+
|
|
3
|
+
import streamlit.components.v1 as components
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Dict, Any, Optional
|
|
6
|
+
|
|
7
|
+
_FRONTEND_DIR = Path(__file__).parent.parent / "_frontend"
|
|
8
|
+
|
|
9
|
+
_component = components.declare_component(
|
|
10
|
+
"streamlit_react_components",
|
|
11
|
+
path=str(_FRONTEND_DIR),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def form_slider(
|
|
16
|
+
label: str,
|
|
17
|
+
value: float,
|
|
18
|
+
min_val: float,
|
|
19
|
+
max_val: float,
|
|
20
|
+
step: float = 1,
|
|
21
|
+
unit: str = "",
|
|
22
|
+
color: str = "blue",
|
|
23
|
+
style: Optional[Dict[str, Any]] = None,
|
|
24
|
+
class_name: str = "",
|
|
25
|
+
key: Optional[str] = None,
|
|
26
|
+
) -> float:
|
|
27
|
+
"""
|
|
28
|
+
Display a styled range slider input.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
label: Label text for the slider
|
|
32
|
+
value: Current value
|
|
33
|
+
min_val: Minimum value
|
|
34
|
+
max_val: Maximum value
|
|
35
|
+
step: Step increment (default 1)
|
|
36
|
+
unit: Unit suffix to display (e.g., "%", "hrs")
|
|
37
|
+
color: Accent color: "blue", "green", "red", "yellow", "purple"
|
|
38
|
+
style: Inline CSS styles as a dictionary
|
|
39
|
+
class_name: Tailwind CSS classes
|
|
40
|
+
key: Unique key for the component
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
The current slider value
|
|
44
|
+
|
|
45
|
+
Example:
|
|
46
|
+
threshold = form_slider(
|
|
47
|
+
label="Upper Threshold",
|
|
48
|
+
value=90,
|
|
49
|
+
min_val=75,
|
|
50
|
+
max_val=100,
|
|
51
|
+
unit="%",
|
|
52
|
+
color="red"
|
|
53
|
+
)
|
|
54
|
+
"""
|
|
55
|
+
result = _component(
|
|
56
|
+
component="form_slider",
|
|
57
|
+
label=label,
|
|
58
|
+
value=value,
|
|
59
|
+
minVal=min_val,
|
|
60
|
+
maxVal=max_val,
|
|
61
|
+
step=step,
|
|
62
|
+
unit=unit,
|
|
63
|
+
color=color,
|
|
64
|
+
style=style,
|
|
65
|
+
className=class_name,
|
|
66
|
+
key=key,
|
|
67
|
+
default=value,
|
|
68
|
+
)
|
|
69
|
+
return float(result) if result is not None else value
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: streamlit-react-components
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reusable React-based Streamlit components with Tailwind CSS styling
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/your-org/streamlit-react-components
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: streamlit>=1.24.0
|