stepper.py 2.8 KB

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