link.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """A link component."""
  2. from pynecone.components.component import Component
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.components.navigation.nextlink import NextLink
  5. from pynecone.var import Var
  6. class Link(ChakraComponent):
  7. """Link to another page."""
  8. tag = "Link"
  9. # The rel.
  10. rel: Var[str]
  11. # The page to link to.
  12. href: Var[str]
  13. # The text to display.
  14. text: Var[str]
  15. # If true, the link will open in new tab.
  16. is_external: Var[bool]
  17. @classmethod
  18. def create(cls, *children, **props) -> Component:
  19. """Create a NextJS link component, wrapping a Chakra link component.
  20. Args:
  21. *children: The children to pass to the component.
  22. **props: The attributes to pass to the component.
  23. Returns:
  24. The component.
  25. """
  26. kwargs = {}
  27. if "href" in props:
  28. kwargs["href"] = props.pop("href")
  29. else:
  30. kwargs["href"] = "#"
  31. return NextLink.create(super().create(*children, **props), **kwargs)