1
0

stack.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Stack components."""
  2. from __future__ import annotations
  3. from reflex.components.component import Component
  4. from reflex.vars.base import Var
  5. from ..base import LiteralAlign, LiteralSpacing
  6. from .flex import Flex, LiteralFlexDirection
  7. class Stack(Flex):
  8. """A stack component."""
  9. # The spacing between each stack item.
  10. spacing: Var[LiteralSpacing] = Var.create("3")
  11. # The alignment of the stack items.
  12. align: Var[LiteralAlign] = Var.create("start")
  13. @classmethod
  14. def create(
  15. cls,
  16. *children,
  17. **props,
  18. ) -> Component:
  19. """Create a new instance of the component.
  20. Args:
  21. *children: The children of the stack.
  22. **props: The properties of the stack.
  23. Returns:
  24. The stack component.
  25. """
  26. # Apply the default classname
  27. given_class_name = props.pop("class_name", [])
  28. if not isinstance(given_class_name, list):
  29. given_class_name = [given_class_name]
  30. props["class_name"] = ["rx-Stack", *given_class_name]
  31. return super().create(
  32. *children,
  33. **props,
  34. )
  35. class VStack(Stack):
  36. """A vertical stack component."""
  37. # The direction of the stack.
  38. direction: Var[LiteralFlexDirection] = Var.create("column")
  39. class HStack(Stack):
  40. """A horizontal stack component."""
  41. # The direction of the stack.
  42. direction: Var[LiteralFlexDirection] = Var.create("row")
  43. stack = Stack.create
  44. hstack = HStack.create
  45. vstack = VStack.create