avatar.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from typing import Optional
  2. from .mixins.color_elements import BackgroundColorElement, TextColorElement
  3. class Avatar(BackgroundColorElement, TextColorElement):
  4. TEXT_COLOR_PROP = 'text-color'
  5. def __init__(self,
  6. icon: Optional[str] = None, *,
  7. color: Optional[str] = 'primary',
  8. text_color: Optional[str] = None,
  9. size: Optional[str] = None,
  10. font_size: Optional[str] = None,
  11. square: bool = False,
  12. rounded: bool = False,
  13. ) -> None:
  14. """Avatar
  15. A avatar element wrapping Quasar's
  16. `QAvatar <https://quasar.dev/vue-components/avatar>`_ component.
  17. :param icon: name of the icon or image path with "img:" prefix (e.g. "map", "img:path/to/image.png")
  18. :param color: background color (either a Quasar, Tailwind, or CSS color or `None`, default: "primary")
  19. :param text_color: color name from the Quasar Color Palette (e.g. "primary", "teal-10")
  20. :param size: size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl) (e.g. "16px", "2rem")
  21. :param font_size: size in CSS units, including unit name, of the content (icon, text) (e.g. "18px", "2rem")
  22. :param square: removes border-radius so borders are squared (default: False)
  23. :param rounded: applies a small standard border-radius for a squared shape of the component (default: False)
  24. """
  25. super().__init__(tag='q-avatar', background_color=color, text_color=text_color)
  26. if icon is not None:
  27. self._props['icon'] = icon
  28. self._props['square'] = square
  29. self._props['rounded'] = rounded
  30. if size is not None:
  31. self._props['size'] = size
  32. if font_size is not None:
  33. self._props['font-size'] = font_size