Create a button component that returns True when clicked.
(
label: str,
variant: str = "default",
disabled: bool = False,
loading: bool = False,
size: float = 1.0,
component_id: str | None = None,
**kwargs
)
| 89 | |
| 90 | @with_render_tracking("button") |
| 91 | def button( |
| 92 | label: str, |
| 93 | variant: str = "default", |
| 94 | disabled: bool = False, |
| 95 | loading: bool = False, |
| 96 | size: float = 1.0, |
| 97 | component_id: str | None = None, |
| 98 | **kwargs |
| 99 | ) -> ComponentReturn: |
| 100 | """Create a button component that returns True when clicked.""" |
| 101 | service = PreswaldService.get_instance() |
| 102 | |
| 103 | # Get current state or use default |
| 104 | current_value = service.get_component_state(component_id) |
| 105 | if current_value is None: |
| 106 | current_value = False |
| 107 | |
| 108 | component = { |
| 109 | "type": "button", |
| 110 | "id": component_id, |
| 111 | "label": label, |
| 112 | "variant": variant, |
| 113 | "disabled": disabled, |
| 114 | "loading": loading, |
| 115 | "size": size, |
| 116 | "value": current_value, |
| 117 | "onClick": True, # Always enable click handling |
| 118 | } |
| 119 | |
| 120 | return ComponentReturn(current_value, component) |
| 121 | |
| 122 | @with_render_tracking("chat") |
| 123 | def chat(source: str, table: str | None = None, component_id: str | None = None, **kwargs) -> ComponentReturn: |
no test coverage detected