html.py 979 B

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