html.py 1021 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """A html component."""
  2. from typing import Dict
  3. from reflex.components.layout.box import Box
  4. from reflex.vars 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[str, str]]
  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 provided, 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)