progress.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """Progress from Radix Themes."""
  2. from typing import Literal
  3. from reflex.components.component import Component
  4. from reflex.components.core.breakpoints import Responsive
  5. from reflex.components.radix.themes.base import LiteralAccentColor, RadixThemesComponent
  6. from reflex.style import Style
  7. from reflex.vars.base import Var
  8. class Progress(RadixThemesComponent):
  9. """A progress bar component."""
  10. tag = "Progress"
  11. # The value of the progress bar: 0 to max (default 100)
  12. value: Var[int]
  13. # The maximum progress value.
  14. max: Var[int]
  15. # The size of the progress bar: "1" | "2" | "3"
  16. size: Var[Responsive[Literal["1", "2", "3"]]]
  17. # The variant of the progress bar: "classic" | "surface" | "soft"
  18. variant: Var[Literal["classic", "surface", "soft"]]
  19. # The color theme of the progress bar
  20. color_scheme: Var[LiteralAccentColor]
  21. # Whether to render the progress bar with higher contrast color against background
  22. high_contrast: Var[bool]
  23. # Override theme radius for progress bar: "none" | "small" | "medium" | "large" | "full"
  24. radius: Var[Literal["none", "small", "medium", "large", "full"]]
  25. # The duration of the progress bar animation. Once the duration times out, the progress bar will start an indeterminate animation.
  26. duration: Var[str]
  27. # The color of the progress bar fill animation.
  28. fill_color: Var[str]
  29. @staticmethod
  30. def _color_selector(color: str) -> Style:
  31. """Return a style object with the correct color and css selector.
  32. Args:
  33. color: Color of the fill part.
  34. Returns:
  35. Style: Style object with the correct css selector and color.
  36. """
  37. return Style({".rt-ProgressIndicator": {"background_color": color}})
  38. @classmethod
  39. def create(cls, *children, **props) -> Component:
  40. """Create a Progress component.
  41. Args:
  42. *children: The children of the component.
  43. **props: The properties of the component.
  44. Returns:
  45. The Progress Component.
  46. """
  47. props.setdefault("width", "100%")
  48. if "fill_color" in props:
  49. color = props.get("fill_color", "")
  50. style = props.get("style", {})
  51. style = style | cls._color_selector(color)
  52. props["style"] = style
  53. return super().create(*children, **props)
  54. progress = Progress.create