breadcrumb.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. """Breadcrumb components."""
  2. from pynecone.components.component import Component
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.var import Var
  5. class Breadcrumb(ChakraComponent):
  6. """The parent container for breadcrumbs."""
  7. tag = "Breadcrumb"
  8. # The visual separator between each breadcrumb item
  9. separator: Var[str]
  10. # The left and right margin applied to the separator
  11. separator_margin: Var[str]
  12. @classmethod
  13. def create(cls, *children, items=None, **props) -> Component:
  14. """Create a breadcrumb component.
  15. If the kw-args `items` is provided and is a list, they will be added as children.
  16. Args:
  17. children: The children of the component.
  18. items (list): The items of the breadcrumb: (label, link)
  19. props: The properties of the component.
  20. Returns:
  21. The breadcrumb component.
  22. """
  23. if len(children) == 0:
  24. children = []
  25. for label, link in items or []:
  26. children.append(
  27. BreadcrumbItem.create(BreadcrumbLink.create(label, href=link))
  28. )
  29. return super().create(*children, **props)
  30. class BreadcrumbItem(ChakraComponent):
  31. """Individual breadcrumb element containing a link and a divider."""
  32. tag = "BreadcrumbItem"
  33. # Is the current page of the breadcrumb.
  34. is_current_page: Var[bool]
  35. # Is the last child of the breadcrumb.
  36. is_last_child: Var[bool]
  37. # The visual separator between each breadcrumb item
  38. separator: Var[str]
  39. # The left and right margin applied to the separator
  40. spacing: Var[str]
  41. # The href of the item.
  42. href: Var[str]
  43. class BreadcrumbSeparator(ChakraComponent):
  44. """The visual separator between each breadcrumb."""
  45. tag = "BreadcrumbSeparator"
  46. class BreadcrumbLink(ChakraComponent):
  47. """The breadcrumb link."""
  48. tag = "BreadcrumbLink"
  49. # Is the current page of the breadcrumb.
  50. is_current_page: Var[bool]