forked from reflex-dev/reflex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added html component (reflex-dev#98)
- Loading branch information
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |