-
-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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 WYSIWYG editor based on `Quasar's QEditor <https://quasar.dev/vue-components/editor>`_. | ||
The value is a string containing the formatted text as HTML code. | ||
: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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
from nicegui import ui | ||
|
||
from .screen import Screen | ||
|
||
|
||
def test_editor(screen: Screen): | ||
editor = ui.editor(placeholder='Type something here') | ||
ui.markdown().bind_content_from(editor, 'value', backward=lambda v: f'HTML code:\n```\n{v}\n```') | ||
|
||
screen.open('/') | ||
screen.find_by_class('q-editor__content').click() | ||
screen.type('Hello\nworld!') | ||
screen.should_contain('Hello<div>world!</div>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from nicegui import ui | ||
|
||
|
||
def main_demo() -> None: | ||
editor = ui.editor(placeholder='Type something here') | ||
ui.markdown().bind_content_from(editor, 'value', | ||
backward=lambda v: f'HTML code:\n```\n{v}\n```') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters