link: as_={NextLink} for next 13 compatibility (#1138)

This commit is contained in:
Masen Furer 2023-06-05 20:21:47 -07:00 committed by GitHub
parent 5fd428e92f
commit 8f7f2536f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,9 @@
"""A link component.""" """A link component."""
from pynecone.components.component import Component
from pynecone.components.libs.chakra import ChakraComponent from pynecone.components.libs.chakra import ChakraComponent
from pynecone.components.navigation.nextlink import NextLink from pynecone.components.navigation.nextlink import NextLink
from pynecone.vars import Var from pynecone.utils import imports
from pynecone.vars import BaseVar, Var
class Link(ChakraComponent): class Link(ChakraComponent):
@ -21,21 +21,10 @@ class Link(ChakraComponent):
text: Var[str] text: Var[str]
# What the link renders to. # What the link renders to.
as_: Var[str] = "span" # type: ignore as_: Var[str] = BaseVar.create("{NextLink}", is_local=False) # type: ignore
# If true, the link will open in new tab. # If true, the link will open in new tab.
is_external: Var[bool] is_external: Var[bool]
@classmethod def _get_imports(self) -> imports.ImportDict:
def create(cls, *children, **props) -> Component: return {**super()._get_imports(), **NextLink(href=self.href)._get_imports()}
"""Create a NextJS link component, wrapping a Chakra link component.
Args:
*children: The children to pass to the component.
**props: The attributes to pass to the component.
Returns:
The component.
"""
kwargs = {"href": props.pop("href") if "href" in props else "#"}
return NextLink.create(super().create(*children, **props), **kwargs)