image.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """An image component."""
  2. from __future__ import annotations
  3. from typing import Optional, Set
  4. from pynecone.components.component import Component
  5. from pynecone.components.libs.chakra import ChakraComponent
  6. from pynecone.vars import Var
  7. class Image(ChakraComponent):
  8. """Display an image."""
  9. tag = "Image"
  10. # How to align the image within its bounds. It maps to css `object-position` property.
  11. align: Var[str]
  12. # Fallback Pynecone component to show if image is loading or image fails.
  13. fallback: Optional[Component] = None
  14. # Fallback image src to show if image is loading or image fails.
  15. fallback_src: Var[str]
  16. # How the image to fit within its bounds. It maps to css `object-fit` property.
  17. fit: Var[str]
  18. # The native HTML height attribute to the passed to the img.
  19. html_height: Var[str]
  20. # The native HTML width attribute to the passed to the img.
  21. html_width: Var[str]
  22. # If true, opt out of the fallbackSrc logic and use as img.
  23. ignore_fallback: Var[bool]
  24. # "eager" | "lazy"
  25. loading: Var[str]
  26. # The image src attribute.
  27. src: Var[str]
  28. # The image srcset attribute.
  29. src_set: Var[str]
  30. def get_triggers(self) -> Set[str]:
  31. """Get the event triggers for the component.
  32. Returns:
  33. The event triggers.
  34. """
  35. return super().get_triggers() | {"on_error", "on_load"}