1
0

container.py 1.5 KB

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