html.py 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """A html component."""
  2. from typing import Dict
  3. from pynecone.components.layout.box import Box
  4. from pynecone.var import Var
  5. class Html(Box):
  6. """Render the html.
  7. Returns:
  8. The code to render the html component.
  9. """
  10. # The HTML to render.
  11. dangerouslySetInnerHTML: Var[Dict]
  12. @classmethod
  13. def create(cls, *children, **props):
  14. """Create a html component.
  15. Args:
  16. *children: The children of the component.
  17. **props: The props to pass to the component.
  18. Returns:
  19. The html component.
  20. Raises:
  21. ValueError: If children are not provided or more than one child is provided.
  22. """
  23. # If children are not prvided, throw an error.
  24. if len(children) != 1:
  25. raise ValueError("Must provide children to the html component.")
  26. else:
  27. props["dangerouslySetInnerHTML"] = {"__html": children[0]}
  28. # Create the component.
  29. return super().create(**props)