stepper.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """A component to indicate progress through a multi-step process."""
  2. from typing import List, Literal, Optional, Tuple
  3. from reflex.components.component import Component
  4. from reflex.components.libs.chakra import ChakraComponent, LiteralColorScheme
  5. from reflex.vars import Var
  6. class Stepper(ChakraComponent):
  7. """The parent container for a stepper."""
  8. tag = "Stepper"
  9. orientation: Var[Literal["vertical", "horizontal"]]
  10. # The color scheme to use for the stepper; default is blue.
  11. colorScheme: Var[LiteralColorScheme]
  12. # Chakra provides a useSteps hook to control the stepper.
  13. # Instead, use an integer state value to set progress in the stepper.
  14. # The index of the current step.
  15. index: Var[int]
  16. # The size of the steps in the stepper.
  17. size: Var[str]
  18. @classmethod
  19. def create(
  20. cls, *children, items: Optional[List[Tuple]] = None, **props
  21. ) -> Component:
  22. """Create a Stepper component.
  23. If the kw-args `items` is provided and is a list, they will be added as children.
  24. Args:
  25. *children: The children of the component.
  26. items (list): The child components for each step.
  27. **props: The properties of the component.
  28. Returns:
  29. The stepper component.
  30. """
  31. if len(children) == 0:
  32. children = []
  33. for indicator, layout, separator in items or []:
  34. children.append(
  35. Step.create(
  36. StepIndicator.create(indicator),
  37. layout,
  38. StepSeparator.create(separator),
  39. )
  40. )
  41. return super().create(*children, **props)
  42. class Step(ChakraComponent):
  43. """A component for an individual step in the stepper."""
  44. tag = "Step"
  45. class StepDescription(ChakraComponent):
  46. """The description text for a step component."""
  47. tag = "StepDescription"
  48. class StepIcon(ChakraComponent):
  49. """The icon displayed in a step indicator component."""
  50. tag = "StepIcon"
  51. class StepIndicator(ChakraComponent):
  52. """The component displaying the status of a step."""
  53. tag = "StepIndicator"
  54. class StepNumber(ChakraComponent):
  55. """The number of a step displayed in a step indicator component."""
  56. tag = "StepNumber"
  57. class StepSeparator(ChakraComponent):
  58. """The component separting steps."""
  59. tag = "StepSeparator"
  60. class StepStatus(ChakraComponent):
  61. """A component that displays a number or icon based on the status of a step."""
  62. # [not working yet]
  63. # active, complete, and incomplete should also be able to accept StepIcon or StepNumber components
  64. # currently, these props only support strings
  65. active: Var[str]
  66. complete: Var[str]
  67. incomplete: Var[str]
  68. tag = "StepStatus"
  69. class StepTitle(ChakraComponent):
  70. """The title text for a step component."""
  71. tag = "StepTitle"