Add import aliases (#452)
This commit is contained in:
parent
d1ff7d481f
commit
d709ab9e03
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import typing
|
import typing
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Callable, Dict, List, Optional, Set, Type, Union
|
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
|
||||||
|
|
||||||
from pynecone import constants, utils
|
from pynecone import constants, utils
|
||||||
from pynecone.base import Base
|
from pynecone.base import Base
|
||||||
@ -234,6 +234,15 @@ class Component(Base, ABC):
|
|||||||
"""
|
"""
|
||||||
return EVENT_ARG
|
return EVENT_ARG
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_alias(cls) -> Optional[str]:
|
||||||
|
"""Get the alias for the component.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The alias.
|
||||||
|
"""
|
||||||
|
return None
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Represent the component in React.
|
"""Represent the component in React.
|
||||||
|
|
||||||
@ -257,7 +266,9 @@ class Component(Base, ABC):
|
|||||||
The tag to render.
|
The tag to render.
|
||||||
"""
|
"""
|
||||||
# Create the base tag.
|
# Create the base tag.
|
||||||
tag = Tag(name=self.tag)
|
alias = self.get_alias()
|
||||||
|
name = alias if alias is not None else self.tag
|
||||||
|
tag = Tag(name=name)
|
||||||
|
|
||||||
# Add component props to the tag.
|
# Add component props to the tag.
|
||||||
props = {attr: getattr(self, attr) for attr in self.get_props()}
|
props = {attr: getattr(self, attr) for attr in self.get_props()}
|
||||||
@ -387,7 +398,9 @@ class Component(Base, ABC):
|
|||||||
|
|
||||||
def _get_imports(self) -> ImportDict:
|
def _get_imports(self) -> ImportDict:
|
||||||
if self.library is not None and self.tag is not None:
|
if self.library is not None and self.tag is not None:
|
||||||
return {self.library: {self.tag}}
|
alias = self.get_alias()
|
||||||
|
tag = self.tag if alias is None else " as ".join([self.tag, alias])
|
||||||
|
return {self.library: {tag}}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_imports(self) -> ImportDict:
|
def get_imports(self) -> ImportDict:
|
||||||
@ -525,14 +538,6 @@ class CustomComponent(Component):
|
|||||||
custom_components |= self.get_component().get_custom_components(seen=seen)
|
custom_components |= self.get_component().get_custom_components(seen=seen)
|
||||||
return custom_components
|
return custom_components
|
||||||
|
|
||||||
def _render(self) -> Tag:
|
|
||||||
"""Define how to render the component in React.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The tag to render.
|
|
||||||
"""
|
|
||||||
return Tag(name=self.tag).add_props(**self.props)
|
|
||||||
|
|
||||||
def get_prop_vars(self) -> List[BaseVar]:
|
def get_prop_vars(self) -> List[BaseVar]:
|
||||||
"""Get the prop vars.
|
"""Get the prop vars.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Table components."""
|
"""Table components."""
|
||||||
|
|
||||||
from typing import Any, List
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from pynecone import utils
|
from pynecone import utils
|
||||||
from pynecone.components.component import Component, ImportDict
|
from pynecone.components.component import Component, ImportDict
|
||||||
@ -37,6 +37,15 @@ class DataTable(Gridjs):
|
|||||||
# Enable pagination.
|
# Enable pagination.
|
||||||
pagination: Var[bool]
|
pagination: Var[bool]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_alias(cls) -> Optional[str]:
|
||||||
|
"""Get the alias for the component.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The alias.
|
||||||
|
"""
|
||||||
|
return "DataTableGrid"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, *children, **props):
|
def create(cls, *children, **props):
|
||||||
"""Create a datatable component.
|
"""Create a datatable component.
|
||||||
|
Loading…
Reference in New Issue
Block a user