Added html component (#98)
This commit is contained in:
parent
209f490bfc
commit
cf33e86edb
@ -7,6 +7,7 @@ from .container import Container
|
|||||||
from .flex import Flex
|
from .flex import Flex
|
||||||
from .foreach import Foreach
|
from .foreach import Foreach
|
||||||
from .grid import Grid, GridItem, ResponsiveGrid
|
from .grid import Grid, GridItem, ResponsiveGrid
|
||||||
|
from .html import Html
|
||||||
from .spacer import Spacer
|
from .spacer import Spacer
|
||||||
from .stack import Hstack, Stack, Vstack
|
from .stack import Hstack, Stack, Vstack
|
||||||
from .wrap import Wrap, WrapItem
|
from .wrap import Wrap, WrapItem
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
"""A box component that can contain other components."""
|
"""A box component that can contain other components."""
|
||||||
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from pynecone.components.libs.chakra import ChakraComponent
|
from pynecone.components.libs.chakra import ChakraComponent
|
||||||
from pynecone.components.tags import Tag
|
from pynecone.components.tags import Tag
|
||||||
from pynecone.var import Var
|
from pynecone.var import Var
|
||||||
|
40
pynecone/components/layout/html.py
Normal file
40
pynecone/components/layout/html.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""A html component."""
|
||||||
|
|
||||||
|
from pynecone.components.layout.box import Box
|
||||||
|
from pynecone.var import Var
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
|
||||||
|
class Html(Box):
|
||||||
|
"""Render the html.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The code to render the html component.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# The HTML to render.
|
||||||
|
dangerouslySetInnerHTML: Var[Dict]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(cls, *children, **props):
|
||||||
|
"""Create a html component.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*children: The children of the component.
|
||||||
|
**props: The props to pass to the component.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The html component.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If children are not provided or more than one child is provided.
|
||||||
|
"""
|
||||||
|
# If children are not prvided, throw an error.
|
||||||
|
if len(children) != 1:
|
||||||
|
raise ValueError("Must provide children to the html component.")
|
||||||
|
else:
|
||||||
|
|
||||||
|
props["dangerouslySetInnerHTML"] = {"__html": children[0]}
|
||||||
|
|
||||||
|
# Create the component.
|
||||||
|
return super().create(**props)
|
Loading…
Reference in New Issue
Block a user