container.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """Declarative layout and common spacing props."""
  2. from __future__ import annotations
  3. from typing import Literal
  4. from reflex import el
  5. from reflex.style import STACK_CHILDREN_FULL_WIDTH
  6. from reflex.vars import Var
  7. from ..base import RadixThemesComponent
  8. LiteralContainerSize = Literal["1", "2", "3", "4"]
  9. class Container(el.Div, RadixThemesComponent):
  10. """Constrains the maximum width of page content.
  11. See https://www.radix-ui.com/themes/docs/components/container
  12. """
  13. tag = "Container"
  14. # The size of the container: "1" - "4" (default "3")
  15. size: Var[LiteralContainerSize] = Var.create_safe("3")
  16. @classmethod
  17. def create(
  18. cls,
  19. *children,
  20. padding: str = "16px",
  21. stack_children_full_width: bool = False,
  22. **props,
  23. ):
  24. """Create the container component.
  25. Args:
  26. children: The children components.
  27. padding: The padding of the container.
  28. stack_children_full_width: If True, any vstack/hstack children will have 100% width.
  29. props: The properties of the container.
  30. Returns:
  31. The container component.
  32. """
  33. if stack_children_full_width:
  34. props["style"] = {**STACK_CHILDREN_FULL_WIDTH, **props.pop("style", {})}
  35. return super().create(
  36. *children,
  37. padding=padding,
  38. **props,
  39. )