소스 검색

fix segmented_control (#3516)

* fix segmented_control

* fix 3.8 imports

* fix 3.8 typing

* add valid_parent for SegmentedControlItem
Thomas Brandého 11 달 전
부모
커밋
6ad679ad66
2개의 변경된 파일34개의 추가작업 그리고 12개의 파일을 삭제
  1. 18 5
      reflex/components/radix/themes/components/segmented_control.py
  2. 16 7
      reflex/components/radix/themes/components/segmented_control.pyi

+ 18 - 5
reflex/components/radix/themes/components/segmented_control.py

@@ -1,8 +1,11 @@
 """SegmentedControl from Radix Themes."""
 """SegmentedControl from Radix Themes."""
 
 
+from __future__ import annotations
+
 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
@@ -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: Var[Literal["classic", "surface", "soft"]]
+    # Variant of button: "classic" | "surface"
+    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."""

+ 16 - 7
reflex/components/radix/themes/components/segmented_control.pyi

@@ -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[
-                Var[Literal["classic", "surface", "soft"]],
-                Literal["classic", "surface", "soft"],
-            ]
+            Union[Var[Literal["classic", "surface"]], Literal["classic", "surface"]]
+        ] = None,
+        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.