link.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.vars 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. # What the link renders to.
  16. as_: Var[str] = "span" # type: ignore
  17. # If true, the link will open in new tab.
  18. is_external: Var[bool]
  19. @classmethod
  20. def create(cls, *children, **props) -> Component:
  21. """Create a NextJS link component, wrapping a Chakra link component.
  22. Args:
  23. *children: The children to pass to the component.
  24. **props: The attributes to pass to the component.
  25. Returns:
  26. The component.
  27. """
  28. kwargs = {"href": props.pop("href") if "href" in props else "#"}
  29. return NextLink.create(super().create(*children, **props), **kwargs)