Skip to content

Commit

Permalink
mandatory attribute and typing for ToggleButtons
Browse files Browse the repository at this point in the history
  • Loading branch information
iisakkirotko committed Sep 7, 2023
2 parents cb20904 + 944d7ca commit 365d79b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions solara/components/togglebuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ 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,
Expand Down Expand Up @@ -123,6 +153,10 @@ 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)
Expand All @@ -142,6 +176,7 @@ def on_index(index):
)


@overload
@overload
@solara.value_component(None)
def ToggleButtonsMultiple(
Expand Down

0 comments on commit 365d79b

Please sign in to comment.