image.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.var 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. @classmethod
  31. def get_triggers(cls) -> Set[str]:
  32. """Get the event triggers for the component.
  33. Returns:
  34. The event triggers.
  35. """
  36. return super().get_triggers() | {"on_error", "on_load"}