knob.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from typing import Union
  2. from ..dependencies import register_component
  3. from ..element import Element
  4. from ..ui import icon
  5. class Knob(Element):
  6. def __init__(
  7. self,
  8. color: str = 'primary',
  9. center_color: str = 'white',
  10. track_color: str = 'secondary',
  11. size: str = '',
  12. icon_name: Union[str, None] = None,
  13. icon_color: str = 'black',
  14. icon_size: str = '1rem',
  15. ) -> None:
  16. """Knob
  17. This element is based on Quasar's `QKnob <https://quasar.dev/vue-components/knob>`_ component.
  18. The element is used to take a number input from the user through mouse/touch panning.
  19. :param color: color name for component, examples: primary, teal-10.
  20. :param center_color: color name for the center part of the component, examples: primary, teal-10.
  21. :param track_color: color name for the track of the component, examples: primary, teal-10.
  22. :param size: size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl), examples: 16px, 2rem.
  23. :param icon: name for the icon in the center of thecomponent, examples: volume_up, volume_down.
  24. :param icon_color: color name for the icon in the center of the component, examples: primary, teal-10.
  25. :param icon_size: size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl), examples: 16px, 2rem.
  26. """
  27. super().__init__('q-knob')
  28. self._props['color'] = color
  29. self._props['center-color'] = center_color
  30. self._props['track-color'] = track_color
  31. self._props['size'] = size
  32. if icon_name is not None:
  33. self._props['show-value'] = True # FIXME: make it possible to show numerical values, in addition to icons
  34. with self:
  35. icon(icon_name)