stack.py 1.2 KB

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