avatar.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """Avatar components."""
  2. from __future__ import annotations
  3. from reflex.components.chakra import ChakraComponent, LiteralAvatarSize
  4. from reflex.event import EventHandler
  5. from reflex.vars import Var
  6. class Avatar(ChakraComponent):
  7. """The image that represents the user."""
  8. tag = "Avatar"
  9. # The default avatar used as fallback when name, and src is not specified.
  10. icon: Var[str]
  11. # The label of the icon.
  12. icon_label: Var[str]
  13. # If true, opt out of the avatar's fallback logic and renders the img at all times.
  14. ignore_fallback: Var[bool]
  15. # The name of the person in the avatar.
  16. name: Var[str]
  17. # If true, the Avatar will show a border around it. Best for a group of avatars.
  18. show_border: Var[bool]
  19. # The image url of the Avatar.
  20. src: Var[str]
  21. # List of sources to use for different screen resolutions.
  22. src_set: Var[str]
  23. # "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "full"
  24. size: Var[LiteralAvatarSize]
  25. # Fired when the image fails to load.
  26. on_error: EventHandler[lambda: []]
  27. class AvatarBadge(ChakraComponent):
  28. """A wrapper that displays its content on the right corner of the avatar."""
  29. tag = "AvatarBadge"
  30. class AvatarGroup(ChakraComponent):
  31. """A wrapper to stack multiple Avatars together."""
  32. tag = "AvatarGroup"
  33. # The maximum number of visible avatars.
  34. max_: Var[int]
  35. # The space between the avatars in the group.
  36. spacing: Var[int]