list.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from typing import Any, Callable, Optional
  2. from typing_extensions import Self
  3. from ..element import Element
  4. from ..events import ClickEventArguments, handle_event
  5. from .mixins.disableable_element import DisableableElement
  6. from .mixins.text_element import TextElement
  7. class List(Element):
  8. def __init__(self) -> None:
  9. """List
  10. A list element based on Quasar's `QList <https://quasar.dev/vue-components/list-and-list-items#qlist-api>`_ component.
  11. It provides a container for list items.
  12. """
  13. super().__init__('q-list')
  14. class Item(DisableableElement):
  15. def __init__(self, *, on_click: Optional[Callable[..., Any]] = None) -> None:
  16. """List Item
  17. Creates a list item based on Quasar's `QItem <https://quasar.dev/vue-components/list-and-list-items#qitem-api>`_ component.
  18. The item should be placed inside a list element.
  19. """
  20. super().__init__(tag='q-item')
  21. if on_click:
  22. self.on_click(on_click)
  23. def on_click(self, callback: Callable[..., Any]) -> Self:
  24. """Add a callback to be invoked when the List Item is clicked."""
  25. self._props['clickable'] = True # idempotent
  26. self.on('click', lambda _: handle_event(callback, ClickEventArguments(sender=self, client=self.client)))
  27. return self
  28. class ItemSection(Element):
  29. def __init__(self) -> None:
  30. """
  31. List Item Section
  32. Creates an item section based on Quasar's `QItemList <https://quasar.dev/vue-components/list-and-list-items#qitemsection-api>`_ component.
  33. The section should be placed inside a list item element.
  34. """
  35. super().__init__('q-item-section')
  36. class ItemLabel(TextElement):
  37. def __init__(self, text: str = '') -> None:
  38. """
  39. List Item Label
  40. Creates an item label based on Quasar's `QItemLabel <https://quasar.dev/vue-components/list-and-list-items#qitemlabel-api>`_ component.
  41. :param text: text to be displayed (default: "")
  42. """
  43. super().__init__(tag='q-item-label', text=text)