switch.py 891 B

1234567891011121314151617181920212223
  1. from typing import Callable
  2. import justpy as jp
  3. from .bool_element import BoolElement
  4. class Switch(BoolElement):
  5. def __init__(self,
  6. text: str = '',
  7. value: bool = False,
  8. on_change: Callable = None,
  9. design: str = '',
  10. classes: str = '',
  11. ):
  12. """Switch Element
  13. :param text: the label to display next to the switch
  14. :param value: set to `True` if initally it should be active; default is `False`
  15. :param design: Quasar props to alter the appearance (see `their reference <https://quasar.dev/vue-components/switch>`_)
  16. :param on_click: callback which is invoked when state is changed by the user
  17. """
  18. view = jp.QToggle(text=text, input=self.handle_change)
  19. super().__init__(view, value, on_change, design=design, classes=classes)