stack.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 = "3",
  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. # Apply the default classname
  27. given_class_name = props.pop("class_name", [])
  28. if isinstance(given_class_name, str):
  29. given_class_name = [given_class_name]
  30. props["class_name"] = ["rx-Stack", *given_class_name]
  31. return super().create(
  32. *children,
  33. spacing=spacing,
  34. align=align,
  35. **props,
  36. )
  37. class VStack(Stack):
  38. """A vertical stack component."""
  39. # The direction of the stack.
  40. direction: Var[LiteralFlexDirection] = "column" # type: ignore
  41. class HStack(Stack):
  42. """A horizontal stack component."""
  43. # The direction of the stack.
  44. direction: Var[LiteralFlexDirection] = "row" # type: ignore