|
@@ -1,5 +1,6 @@
|
|
from typing import Callable, Optional
|
|
from typing import Callable, Optional
|
|
|
|
|
|
|
|
+from .icon import Icon
|
|
from .mixins.value_element import ValueElement
|
|
from .mixins.value_element import ValueElement
|
|
|
|
|
|
|
|
|
|
@@ -10,16 +11,26 @@ class Input(ValueElement):
|
|
placeholder: Optional[str] = None,
|
|
placeholder: Optional[str] = None,
|
|
value: str = '',
|
|
value: str = '',
|
|
password: bool = False,
|
|
password: bool = False,
|
|
|
|
+ password_toggle_button: bool = False,
|
|
on_change: Optional[Callable] = None) -> None:
|
|
on_change: Optional[Callable] = None) -> None:
|
|
"""Text Input
|
|
"""Text Input
|
|
|
|
|
|
:param label: displayed label for the text input
|
|
:param label: displayed label for the text input
|
|
:param placeholder: text to show if no value is entered
|
|
:param placeholder: text to show if no value is entered
|
|
:param value: the current value of the text input
|
|
:param value: the current value of the text input
|
|
- :param password: whether to hide the input
|
|
|
|
|
|
+ :param password: whether to hide the input (default: False)
|
|
|
|
+ :param password_toggle_button: whether to show a button to toggle the password visibility (default: False)
|
|
:param on_change: callback to execute when the input is confirmed by leaving the focus
|
|
:param on_change: callback to execute when the input is confirmed by leaving the focus
|
|
"""
|
|
"""
|
|
super().__init__(tag='q-input', value=value, on_value_change=on_change)
|
|
super().__init__(tag='q-input', value=value, on_value_change=on_change)
|
|
self._props['label'] = label
|
|
self._props['label'] = label
|
|
self._props['placeholder'] = placeholder
|
|
self._props['placeholder'] = placeholder
|
|
self._props['type'] = 'password' if password else 'text'
|
|
self._props['type'] = 'password' if password else 'text'
|
|
|
|
+
|
|
|
|
+ if password_toggle_button:
|
|
|
|
+ with self.add_slot('append'):
|
|
|
|
+ def toggle_type(_):
|
|
|
|
+ is_hidden = self._props.get('type') == 'password'
|
|
|
|
+ icon.props(f'name={"visibility" if is_hidden else "visibility_off"}')
|
|
|
|
+ self.props(f'type={"text" if is_hidden else "password"}')
|
|
|
|
+ icon = Icon('visibility_off').classes('cursor-pointer').on('click', toggle_type)
|