avatar.py 1.5 KB

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