Skip to content

Commit

Permalink
- add class keyword
Browse files Browse the repository at this point in the history
- typing style
  • Loading branch information
lp9052 committed Jun 30, 2023
1 parent 706606a commit eeaae64
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions solara/components/switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Union
from typing import Callable, Dict, List, Optional, Union

import reacton.ipyvuetify as v

Expand All @@ -8,11 +8,13 @@
@solara.value_component(bool)
def Switch(
*,
label=None,
label: str = None,
value: Union[bool, solara.Reactive[bool]] = True,
on_value: Callable[[bool], None] = None,
disabled=False,
style: str = None,
disabled: bool = False,
children: list = [],
classes: List[str] = [],
style: Optional[Union[str, Dict[str, str]]] = None,
):
"""A switch component provides users the ability to choose between two distinct values. But aesthetically different
from a checkbox.
Expand Down Expand Up @@ -45,11 +47,23 @@ def Page():
* `value`: The current value of the switch (True or False).
* `on_value`: A callback that is called when the switch is toggled.
* `disabled`: If True, the switch is disabled and cannot be used.
* `style`: A string of CSS styles to apply to the switch.
* `children`: A list of child elements to display on the switch.
* `classes`: Additional CSS classes to apply.
* `style`: CSS style to apply.
"""
reactive_value = solara.use_reactive(value, on_value)
del value, on_value
children = []
if label is not None:
children = [label]
return v.Switch(label=label, v_model=reactive_value.value, on_v_model=reactive_value.set, disabled=disabled, style_=style, children=children)

if label:
children = [label] + children

return v.Switch(
label=label,
v_model=reactive_value.value,
on_v_model=reactive_value.set,
disabled=disabled,
class_=solara.util._combine_classes(classes),
style_=solara.util._flatten_style(style),
children=children,
)

0 comments on commit eeaae64

Please sign in to comment.