avatar.py 1.6 KB

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