wrap.py 1.4 KB

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