avatar.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Avatar components."""
  2. from typing import Set
  3. from pynecone.components.libs.chakra import ChakraComponent
  4. from pynecone.vars 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. def get_triggers(self) -> Set[str]:
  25. """Get the event triggers for the component.
  26. Returns:
  27. The event triggers.
  28. """
  29. return super().get_triggers() | {"on_error"}
  30. class AvatarBadge(ChakraComponent):
  31. """A wrapper that displays its content on the right corner of the avatar."""
  32. tag = "AvatarBadge"
  33. class AvatarGroup(ChakraComponent):
  34. """A wrapper to stack multiple Avatars together."""
  35. tag = "AvatarGroup"
  36. # The maximum number of visible avatars.
  37. max_: Var[int]
  38. # The space between the avatars in the group.
  39. spacing: Var[int]