fix segmented_control (#3516)

* fix segmented_control

* fix 3.8 imports

* fix 3.8 typing

* add valid_parent for SegmentedControlItem
This commit is contained in:
Thomas Brandého 2024-06-19 17:47:49 +02:00 committed by GitHub
parent ffb24ceeee
commit 6ad679ad66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 13 deletions

View File

@ -1,8 +1,11 @@
"""SegmentedControl from Radix Themes.""" """SegmentedControl from Radix Themes."""
from types import SimpleNamespace from __future__ import annotations
from typing import Literal
from types import SimpleNamespace
from typing import List, Literal, Union
from reflex.event import EventHandler
from reflex.vars import Var from reflex.vars import Var
from ..base import LiteralAccentColor, RadixThemesComponent from ..base import LiteralAccentColor, RadixThemesComponent
@ -11,13 +14,15 @@ from ..base import LiteralAccentColor, RadixThemesComponent
class SegmentedControlRoot(RadixThemesComponent): class SegmentedControlRoot(RadixThemesComponent):
"""Root element for a SegmentedControl component.""" """Root element for a SegmentedControl component."""
tag = "SegmentedControl" tag = "SegmentedControl.Root"
# The size of the segmented control: "1" | "2" | "3" # The size of the segmented control: "1" | "2" | "3"
size: Var[Literal["1", "2", "3"]] size: Var[Literal["1", "2", "3"]]
# Variant of button: "classic" | "surface" | "soft" # Variant of button: "classic" | "surface"
variant: Var[Literal["classic", "surface", "soft"]] variant: Var[Literal["classic", "surface"]]
type: Var[Literal["single", "multiple"]]
# Override theme color for button # Override theme color for button
color_scheme: Var[LiteralAccentColor] color_scheme: Var[LiteralAccentColor]
@ -26,7 +31,13 @@ class SegmentedControlRoot(RadixThemesComponent):
radius: Var[Literal["none", "small", "medium", "large", "full"]] radius: Var[Literal["none", "small", "medium", "large", "full"]]
# The default value of the segmented control. # The default value of the segmented control.
default_value: Var[str] default_value: Var[Union[str, List[str]]]
value: Var[Union[str, List[str]]]
on_change: EventHandler[lambda e0: [e0]]
_rename_props = {"onChange": "onValueChange"}
class SegmentedControlItem(RadixThemesComponent): class SegmentedControlItem(RadixThemesComponent):
@ -37,6 +48,8 @@ class SegmentedControlItem(RadixThemesComponent):
# The value of the item. # The value of the item.
value: Var[str] value: Var[str]
_valid_parents: List[str] = ["SegmentedControlRoot"]
class SegmentedControl(SimpleNamespace): class SegmentedControl(SimpleNamespace):
"""SegmentedControl components namespace.""" """SegmentedControl components namespace."""

View File

@ -8,7 +8,8 @@ from reflex.vars import Var, BaseVar, ComputedVar
from reflex.event import EventChain, EventHandler, EventSpec from reflex.event import EventChain, EventHandler, EventSpec
from reflex.style import Style from reflex.style import Style
from types import SimpleNamespace from types import SimpleNamespace
from typing import Literal from typing import List, Literal, Union
from reflex.event import EventHandler
from reflex.vars import Var from reflex.vars import Var
from ..base import LiteralAccentColor, RadixThemesComponent from ..base import LiteralAccentColor, RadixThemesComponent
@ -22,10 +23,10 @@ class SegmentedControlRoot(RadixThemesComponent):
Union[Var[Literal["1", "2", "3"]], Literal["1", "2", "3"]] Union[Var[Literal["1", "2", "3"]], Literal["1", "2", "3"]]
] = None, ] = None,
variant: Optional[ variant: Optional[
Union[ Union[Var[Literal["classic", "surface"]], Literal["classic", "surface"]]
Var[Literal["classic", "surface", "soft"]], ] = None,
Literal["classic", "surface", "soft"], type: Optional[
] Union[Var[Literal["single", "multiple"]], Literal["single", "multiple"]]
] = None, ] = None,
color_scheme: Optional[ color_scheme: Optional[
Union[ Union[
@ -95,7 +96,12 @@ class SegmentedControlRoot(RadixThemesComponent):
Literal["none", "small", "medium", "large", "full"], Literal["none", "small", "medium", "large", "full"],
] ]
] = None, ] = None,
default_value: Optional[Union[Var[str], str]] = None, default_value: Optional[
Union[Var[Union[str, List[str]]], Union[str, List[str]]]
] = None,
value: Optional[
Union[Var[Union[str, List[str]]], Union[str, List[str]]]
] = None,
style: Optional[Style] = None, style: Optional[Style] = None,
key: Optional[Any] = None, key: Optional[Any] = None,
id: Optional[Any] = None, id: Optional[Any] = None,
@ -105,6 +111,9 @@ class SegmentedControlRoot(RadixThemesComponent):
on_blur: Optional[ on_blur: Optional[
Union[EventHandler, EventSpec, list, function, BaseVar] Union[EventHandler, EventSpec, list, function, BaseVar]
] = None, ] = None,
on_change: Optional[
Union[EventHandler, EventSpec, list, function, BaseVar]
] = None,
on_click: Optional[ on_click: Optional[
Union[EventHandler, EventSpec, list, function, BaseVar] Union[EventHandler, EventSpec, list, function, BaseVar]
] = None, ] = None,
@ -157,7 +166,7 @@ class SegmentedControlRoot(RadixThemesComponent):
Args: Args:
*children: Child components. *children: Child components.
size: The size of the segmented control: "1" | "2" | "3" size: The size of the segmented control: "1" | "2" | "3"
variant: Variant of button: "classic" | "surface" | "soft" variant: Variant of button: "classic" | "surface"
color_scheme: Override theme color for button color_scheme: Override theme color for button
radius: The radius of the segmented control: "none" | "small" | "medium" | "large" | "full" radius: The radius of the segmented control: "none" | "small" | "medium" | "large" | "full"
default_value: The default value of the segmented control. default_value: The default value of the segmented control.