list.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """List components."""
  2. from pynecone.components import Component
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.var import Var
  5. class List(ChakraComponent):
  6. """Display a list of items."""
  7. tag = "List"
  8. # The space between each list item
  9. spacing: Var[str]
  10. # Shorthand prop for listStylePosition
  11. style_position: Var[str]
  12. # Shorthand prop for listStyleType
  13. style_type: Var[str]
  14. @classmethod
  15. def create(cls, *children, items=None, **props) -> Component:
  16. """Create a list component.
  17. Args:
  18. children: The children of the component.
  19. items: A list of items to add to the list.
  20. props: The properties of the component.
  21. Returns:
  22. The list component.
  23. """
  24. if len(children) == 0:
  25. children = []
  26. for item in items or []:
  27. children.append(ListItem.create(*item))
  28. return super().create(*children, **props)
  29. class ListItem(ChakraComponent):
  30. """A single list item."""
  31. tag = "ListItem"
  32. class OrderedList(List):
  33. """An ordered list component with numbers."""
  34. tag = "OrderedList"
  35. class UnorderedList(List):
  36. """An unordered list component with bullets."""
  37. tag = "UnorderedList"