diff --git a/solara/components/togglebuttons.py b/solara/components/togglebuttons.py index 3880d1f0c..fec1d84d3 100644 --- a/solara/components/togglebuttons.py +++ b/solara/components/togglebuttons.py @@ -1,6 +1,6 @@ from typing import Callable, Dict, List, Optional, TypeVar, Union, cast, overload -import ipyvuetify as v # type: ignore +import ipyvuetify as v import reacton from typing_extensions import Literal @@ -50,36 +50,6 @@ def ToggleButtonsSingle( ... -@overload -@solara.value_component(None) -def ToggleButtonsSingle( - value: Union[T, solara.Reactive[T]], - values: List[T] = ..., - children: List[reacton.core.Element] = ..., - on_value: Optional[Callable[[T], None]] = ..., - dense: bool = ..., - mandatory: Literal[True] = ..., - classes: List[str] = ..., - style: Union[str, Dict[str, str], None] = ..., -) -> reacton.core.ValueElement[v.BtnToggle, T]: - ... - - -@overload -@solara.value_component(None) -def ToggleButtonsSingle( - value: Union[Optional[T], solara.Reactive[Optional[T]]] = None, - values: List[T] = ..., - children: List[reacton.core.Element] = ..., - on_value: Optional[Callable[[T], None]] = ..., - dense: bool = ..., - mandatory: Literal[False] = ..., - classes: List[str] = ..., - style: Union[str, Dict[str, str], None] = ..., -) -> reacton.core.ValueElement[v.BtnToggle, T]: - ... - - @solara.value_component(None) def ToggleButtonsSingle( value: Union[None, T, Optional[T], solara.Reactive[T], solara.Reactive[Optional[T]]] = None, @@ -146,6 +116,8 @@ def Page(): class_ = _combine_classes(classes) style_flat = solara.util._flatten_style(style) # TODO: make type safe + # typing is ignored below due to an issue with the typing of use_reactive; Typechecker expects a different type than is given. If expected type is + # given instead, a similar error shows up in typing of argument. reactive_value = solara.use_reactive(value, on_value) # type: ignore children = [solara.Button(label=str(value)) for value in values] + children values = values + [_get_button_value(button) for button in children] # type: ignore @@ -153,10 +125,6 @@ def Page(): # (see https://github.com/widgetti/solara/issues/282) # TODO: set index to 0 on python side (after #282 is resolved) index, set_index = solara.use_state_or_update(values.index(reactive_value.value) if reactive_value.value is not None else None, key="index") - # When mandatory = True, index should not be None, but we are letting the front-end take care of setting index to 0 because of a bug - # (see https://github.com/widgetti/solara/issues/282) - # TODO: set index to 0 on python side (after #282 is resolved) - index, set_index = solara.use_state_or_update(values.index(reactive_value.value) if reactive_value.value is not None else None, key="index") def on_index(index): set_index(index) @@ -172,7 +140,6 @@ def on_index(index): ) -@overload @overload @solara.value_component(None) def ToggleButtonsMultiple( @@ -208,7 +175,7 @@ def ToggleButtonsMultiple( value: Union[Optional[List[T]], solara.Reactive[List[T]], solara.Reactive[Optional[List[T]]]] = [], values: List[T] = [], children: List[reacton.core.Element] = [], - on_value: Union[Callable[[Optional[List[T]]], None], None] = None, + on_value: Union[Callable[[List[T]], None], None] = None, dense: bool = False, mandatory: bool = False, classes: List[str] = [], @@ -244,7 +211,7 @@ def Page(): """ class_ = _combine_classes(classes) style_flat = solara.util._flatten_style(style) - # Similar approach to select.py + # See comment regarding typing issue in ToggleButtonsSingle reactive_value = solara.use_reactive(value, on_value) # type: ignore children = [solara.Button(label=str(value)) for value in values] + children allvalues = values + [_get_button_value(button) for button in children]