Explorar o código

introduce new ui.editor element

Falko Schindler hai 1 ano
pai
achega
ebb6fa54a9
Modificáronse 2 ficheiros con 26 adicións e 0 borrados
  1. 24 0
      nicegui/elements/editor.py
  2. 2 0
      nicegui/ui.py

+ 24 - 0
nicegui/elements/editor.py

@@ -0,0 +1,24 @@
+from typing import Any, Callable, Optional
+
+from .mixins.disableable_element import DisableableElement
+from .mixins.value_element import ValueElement
+
+
+class Editor(ValueElement, DisableableElement):
+
+    def __init__(self,
+                 *,
+                 placeholder: Optional[str] = None,
+                 value: str = '',
+                 on_change: Optional[Callable[..., Any]] = None,
+                 ) -> None:
+        """Editor
+
+        A code editor with syntax highlighting, based on `Quasar's QEditor <https://quasar.dev/vue-components/editor>`_.
+
+        :param value: initial value
+        :param on_change: callback to be invoked when the value changes
+        """
+        super().__init__(tag='q-editor', value=value, on_value_change=on_change)
+        if placeholder is not None:
+            self._props['placeholder'] = placeholder

+ 2 - 0
nicegui/ui.py

@@ -21,6 +21,7 @@ __all__ = [
     'date',
     'dialog',
     'echart',
+    'editor',
     'expansion',
     'grid',
     'html',
@@ -116,6 +117,7 @@ from .elements.dark_mode import DarkMode as dark_mode
 from .elements.date import Date as date
 from .elements.dialog import Dialog as dialog
 from .elements.echart import EChart as echart
+from .elements.editor import Editor as editor
 from .elements.expansion import Expansion as expansion
 from .elements.grid import Grid as grid
 from .elements.html import Html as html