segmented_control.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """SegmentedControl from Radix Themes."""
  2. from __future__ import annotations
  3. from types import SimpleNamespace
  4. from typing import List, Literal, Union
  5. from reflex.event import EventHandler
  6. from reflex.vars import Var
  7. from ..base import LiteralAccentColor, RadixThemesComponent
  8. class SegmentedControlRoot(RadixThemesComponent):
  9. """Root element for a SegmentedControl component."""
  10. tag = "SegmentedControl.Root"
  11. # The size of the segmented control: "1" | "2" | "3"
  12. size: Var[Literal["1", "2", "3"]]
  13. # Variant of button: "classic" | "surface"
  14. variant: Var[Literal["classic", "surface"]]
  15. type: Var[Literal["single", "multiple"]]
  16. # Override theme color for button
  17. color_scheme: Var[LiteralAccentColor]
  18. # The radius of the segmented control: "none" | "small" | "medium" | "large" | "full"
  19. radius: Var[Literal["none", "small", "medium", "large", "full"]]
  20. # The default value of the segmented control.
  21. default_value: Var[Union[str, List[str]]]
  22. value: Var[Union[str, List[str]]]
  23. on_change: EventHandler[lambda e0: [e0]]
  24. _rename_props = {"onChange": "onValueChange"}
  25. class SegmentedControlItem(RadixThemesComponent):
  26. """An item in the SegmentedControl component."""
  27. tag = "SegmentedControl.Item"
  28. # The value of the item.
  29. value: Var[str]
  30. _valid_parents: List[str] = ["SegmentedControlRoot"]
  31. class SegmentedControl(SimpleNamespace):
  32. """SegmentedControl components namespace."""
  33. root = staticmethod(SegmentedControlRoot.create)
  34. item = staticmethod(SegmentedControlItem.create)
  35. segmented_control = SegmentedControl()