streamlit-react-components 1.8.1.6__py3-none-any.whl → 1.8.1.7__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.
@@ -15,6 +15,7 @@ _component = components.declare_component(
15
15
 
16
16
  def button_group(
17
17
  buttons: List[Dict[str, Any]],
18
+ on_click: Optional[Callable] = None,
18
19
  on_change: Optional[Callable] = None,
19
20
  args: Optional[tuple] = None,
20
21
  kwargs: Optional[Dict[str, Any]] = None,
@@ -36,38 +37,32 @@ def button_group(
36
37
  - disabled: Whether button is disabled (optional)
37
38
  - style: Inline CSS styles dict for this button (optional)
38
39
  - className: Tailwind CSS classes for this button (optional)
39
- on_change: Optional callback function called when a button is clicked
40
- args: Optional tuple of args to pass to on_change callback
41
- kwargs: Optional dict of kwargs to pass to on_change callback
40
+ on_click: Optional callback fired on every click. Receives (button_id, *args, **kwargs)
41
+ on_change: Optional callback fired only when a different button is clicked.
42
+ Receives (*args, **kwargs)
43
+ args: Optional tuple of args to pass to callbacks
44
+ kwargs: Optional dict of kwargs to pass to callbacks
42
45
  style: Inline CSS styles as a dictionary
43
46
  class_name: Tailwind CSS classes
44
47
  theme: Optional theme dictionary. If None, uses active global theme.
45
48
  Set to False to disable theming for this component.
46
- key: Unique key for the component (required if on_change is used)
49
+ key: Unique key for the component (required if callbacks are used)
47
50
 
48
51
  Returns:
49
52
  The ID of the clicked button, or None if no click
50
53
 
51
54
  Example:
52
- # Using preset colors
55
+ def handle_click(button_id):
56
+ st.write(f"Clicked: {button_id}")
57
+
53
58
  clicked = button_group(
54
59
  buttons=[
55
- {"id": "view", "icon": "👁️"},
56
- {"id": "edit", "icon": "✏️"},
57
60
  {"id": "approve", "icon": "✓", "color": "green"},
58
61
  {"id": "reject", "icon": "✕", "color": "red"}
59
- ]
60
- )
61
-
62
- # Using hex colors and custom styling
63
- clicked = button_group(
64
- buttons=[
65
- {"id": "custom", "icon": "🎨", "color": "#ff5733"},
66
- {"id": "styled", "label": "Styled", "style": {"padding": "12px"}}
67
- ]
62
+ ],
63
+ on_click=handle_click,
64
+ key="my_buttons"
68
65
  )
69
- if clicked == "approve":
70
- approve_item()
71
66
  """
72
67
  # Resolve theme (None = use global, False = disable)
73
68
  from ..themes import get_active_theme
@@ -85,13 +80,17 @@ def button_group(
85
80
  default=None,
86
81
  )
87
82
 
88
- # Execute on_change callback if a button was clicked
89
- if on_change and key:
83
+ # Execute callbacks if a button was clicked
84
+ if key and result is not None:
90
85
  prev_key = f"_button_group_prev_{key}"
91
86
  prev_value = st.session_state.get(prev_key)
92
87
 
93
- # Only fire callback if a button was clicked (result not None) and it's different from previous
94
- if result is not None and result != prev_value:
88
+ # on_click fires on every click, with button_id as first arg
89
+ if on_click:
90
+ on_click(result, *(args or ()), **(kwargs or {}))
91
+
92
+ # on_change fires only when a different button is clicked
93
+ if on_change and result != prev_value:
95
94
  on_change(*(args or ()), **(kwargs or {}))
96
95
 
97
96
  # Always update previous value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: streamlit-react-components
3
- Version: 1.8.1.6
3
+ Version: 1.8.1.7
4
4
  Summary: Reusable React-based Streamlit components with Tailwind CSS styling
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/your-org/streamlit-react-components
@@ -6,7 +6,7 @@ streamlit_react_components/_frontend/index.css,sha256=nGAyY9oe87Ayha6-wUCCA2wQFW
6
6
  streamlit_react_components/_frontend/index.html,sha256=CjBEtVYlgT_q06BE16EHFrUrJZ6z0MCprrTg7qgAWzw,381
7
7
  streamlit_react_components/_frontend/index.js,sha256=K0w0MmanmChWxCP_brj60ot2DFfFM8jIboBNAYzmOtQ,5233921
8
8
  streamlit_react_components/common/__init__.py,sha256=l5BfFZdqjrdLG3sJnJrgahEiTgoBX92_aE0wp2tn_w0,606
9
- streamlit_react_components/common/button_group.py,sha256=XprEVyup7vQ2Oj6D4db2NRWDKL4C8PE_Qh8-DrjY290,3577
9
+ streamlit_react_components/common/button_group.py,sha256=pCBsGHuovxN4wKzu5B-SDRO0MECqKJy8MnCgeIkPgK8,3536
10
10
  streamlit_react_components/common/chart_legend.py,sha256=ylul6Os5A89S8fIJs7XpBdIk6uWijg_zwR1eB7u9wSw,1824
11
11
  streamlit_react_components/common/data_table.py,sha256=EzJqaIKmg5lPnjb3bWFIFoSGY6C1cpau5bBZYNKCk_Y,3483
12
12
  streamlit_react_components/common/metric_row.py,sha256=84KmKq_ECJ6kTozDSVTVVxN0G5TyGEgtDzl4V_bilAc,1704
@@ -22,7 +22,7 @@ streamlit_react_components/form/form_date_slider.py,sha256=FpKvY7uV5uTsLcjOQwPX_
22
22
  streamlit_react_components/form/form_select.py,sha256=bJFyN9at6nTyDcev_7l7pYDW_KhXHG2D7lSfNxPIPTQ,3964
23
23
  streamlit_react_components/form/form_slider.py,sha256=ZL1fCLCfanolmxOzuEQo28D1WYFy17uH0EuwbFwD7f8,4020
24
24
  streamlit_react_components/form/radio_group.py,sha256=ktmB37APMLiaUJGmP38hlA6I_diPyexkcNGXCvDXjw8,4098
25
- streamlit_react_components-1.8.1.6.dist-info/METADATA,sha256=TH14bZIr4FoxjxgXw9Kho_8Ko5DTVCDZwbXxVUBps6o,21679
26
- streamlit_react_components-1.8.1.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
27
- streamlit_react_components-1.8.1.6.dist-info/top_level.txt,sha256=3JFrl15-Uewx3BFMSzqrBufF9GmTS1LDKfShmg0R9VE,27
28
- streamlit_react_components-1.8.1.6.dist-info/RECORD,,
25
+ streamlit_react_components-1.8.1.7.dist-info/METADATA,sha256=xcuGDSzXWkfMfjZ71G12S5v6rH68f1booX_LvJiF7zI,21679
26
+ streamlit_react_components-1.8.1.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
27
+ streamlit_react_components-1.8.1.7.dist-info/top_level.txt,sha256=3JFrl15-Uewx3BFMSzqrBufF9GmTS1LDKfShmg0R9VE,27
28
+ streamlit_react_components-1.8.1.7.dist-info/RECORD,,