wrap.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """Container to stack elements with spacing."""
  2. from typing import Optional
  3. from reflex.components.chakra import ChakraComponent
  4. from reflex.components.component import Component
  5. from reflex.vars import Var
  6. class Wrap(ChakraComponent):
  7. """Layout component used to add space between elements and wrap automatically if there isn't enough space."""
  8. tag = "Wrap"
  9. # How to align the items.
  10. align: Optional[Var[str]] = None
  11. # The flex direction of the wrap.
  12. direction: Optional[Var[str]] = None
  13. # How to justify the items.
  14. justify: Optional[Var[str]] = None
  15. # Whether to wrap children in `rx.wrap_item`.
  16. should_wrap_children: Optional[Var[bool]] = None
  17. # The spacing between the items.
  18. spacing: Optional[Var[str]] = None
  19. # The horizontal spacing between the items.
  20. spacing_x: Optional[Var[str]] = None
  21. # The vertical spacing between the items.
  22. spacing_y: Optional[Var[str]] = None
  23. @classmethod
  24. def create(cls, *children, items=None, **props) -> Component:
  25. """Return a wrap component.
  26. Args:
  27. *children: The children of the component.
  28. items (list): The items of the wrap component.
  29. **props: The properties of the component.
  30. Returns:
  31. The wrap component.
  32. """
  33. if len(children) == 0:
  34. children = []
  35. for item in items or []:
  36. children.append(WrapItem.create(*item))
  37. return super().create(*children, **props)
  38. class WrapItem(ChakraComponent):
  39. """Item of the Wrap component."""
  40. tag = "WrapItem"