tabs.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from typing import Any, Callable, Optional
  2. from .. import globals
  3. from ..element import Element
  4. from .mixins.value_element import ValueElement
  5. class Tabs(ValueElement):
  6. def __init__(self, *,
  7. value: Any = None,
  8. on_change: Optional[Callable] = None) -> None:
  9. """Tabs
  10. This element represents `Quasar's QTabs <https://quasar.dev/vue-components/tabs#qtabs-api>`_ component.
  11. It contains individual tabs.
  12. :param value: name of the tab to be initially selected
  13. :param on_change: callback to be executed when the selected tab changes
  14. """
  15. super().__init__(tag='q-tabs', value=value, on_value_change=on_change)
  16. self.panels: Optional[TabPanels] = None
  17. class Tab(Element):
  18. def __init__(self, name: str, label: Optional[str] = None, icon: Optional[str] = None) -> None:
  19. """Tab
  20. This element represents `Quasar's QTab <https://quasar.dev/vue-components/tabs#qtab-api>`_ component.
  21. It is a child of a `Tabs` element.
  22. :param name: name of the tab (the value of the `Tabs` element)
  23. :param label: label of the tab (default: `None`, meaning the same as `name`)
  24. :param icon: icon of the tab (default: `None`)
  25. """
  26. super().__init__('q-tab')
  27. self._props['name'] = name
  28. self._props['label'] = label if label is not None else name
  29. if icon:
  30. self._props['icon'] = icon
  31. self.tabs = globals.get_slot().parent
  32. class TabPanels(ValueElement):
  33. def __init__(self,
  34. tabs: Tabs, *,
  35. value: Any = None,
  36. on_change: Optional[Callable] = None,
  37. animated: bool = True,
  38. ) -> None:
  39. """Tab Panels
  40. This element represents `Quasar's QTabPanels <https://quasar.dev/vue-components/tab-panels#qtabpanels-api>`_ component.
  41. It contains individual tab panels.
  42. :param tabs: the `Tabs` element that controls this element
  43. :param value: name of the tab panel to be initially visible
  44. :param on_change: callback to be executed when the visible tab panel changes
  45. :param animated: whether the tab panels should be animated (default: `True`)
  46. """
  47. super().__init__(tag='q-tab-panels', value=value, on_value_change=on_change)
  48. tabs.bind_value(self, 'value')
  49. self._props['animated'] = animated
  50. class TabPanel(Element):
  51. def __init__(self, name: str) -> None:
  52. """Tab Panel
  53. This element represents `Quasar's QTabPanel <https://quasar.dev/vue-components/tab-panels#qtabpanel-api>`_ component.
  54. It is a child of a `TabPanels` element.
  55. :param name: name of the tab panel (the value of the `TabPanels` element)
  56. """
  57. super().__init__('q-tab-panel')
  58. self._props['name'] = name