MCPcopy
hub / github.com/StructuredLabs/preswald / selectbox

Function selectbox

preswald/interfaces/components.py:680–707  ·  view source on GitHub ↗

Create a select component with consistent ID based on label.

(
    label: str,
    options: list[str],
    default: str | None = None,
    size: float = 1.0,
    component_id: str | None = None,
    **kwargs
)

Source from the content-addressed store, hash-verified

678
679@with_render_tracking("selectbox")
680def selectbox(
681 label: str,
682 options: list[str],
683 default: str | None = None,
684 size: float = 1.0,
685 component_id: str | None = None,
686 **kwargs
687) -> ComponentReturn:
688 """Create a select component with consistent ID based on label."""
689 service = PreswaldService.get_instance()
690 current_value = service.get_component_state(component_id)
691 if current_value is None:
692 current_value = (
693 default if default is not None else (options[0] if options else None)
694 )
695
696 component = {
697 "type": "selectbox",
698 "id": component_id,
699 "label": label,
700 "options": options,
701 "value": current_value,
702 "size": size,
703 }
704
705 logger.debug(f"[selectbox] ID={component_id}, selected={current_value}")
706
707 return ComponentReturn(current_value, component)
708
709
710@with_render_tracking("separator")

Callers 1

selectbox_demoFunction · 0.90

Calls 3

ComponentReturnClass · 0.90
get_component_stateMethod · 0.80
get_instanceMethod · 0.45

Tested by

no test coverage detected