stack.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """Stack components."""
  2. from __future__ import annotations
  3. from reflex.components.component import Component
  4. from ..base import LiteralAlign, LiteralSpacing
  5. from .flex import Flex
  6. class Stack(Flex):
  7. """A stack component."""
  8. @classmethod
  9. def create(
  10. cls,
  11. *children,
  12. spacing: LiteralSpacing = "2",
  13. align: LiteralAlign = "start",
  14. **props,
  15. ) -> Component:
  16. """Create a new instance of the component.
  17. Args:
  18. *children: The children of the stack.
  19. spacing: The spacing between each stack item.
  20. align: The alignment of the stack items.
  21. **props: The properties of the stack.
  22. Returns:
  23. The stack component.
  24. """
  25. return super().create(
  26. *children,
  27. spacing=spacing,
  28. align=align,
  29. **props,
  30. )
  31. class VStack(Stack):
  32. """A vertical stack component."""
  33. def _apply_theme(self, theme: Component):
  34. self.style.update({"flex_direction": "column"})
  35. class HStack(Stack):
  36. """A horizontal stack component."""
  37. def _apply_theme(self, theme: Component):
  38. self.style.update({"flex_direction": "row"})