link.py 1005 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 = {"href": props.pop("href") if "href" in props else "#"}
  27. return NextLink.create(super().create(*children, **props), **kwargs)