Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions nicegui/elements/popup_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import Optional

from ..elements.mixins.disableable_element import DisableableElement
from ..events import Handler, UiEventArguments, handle_event


class PopupEdit(DisableableElement):
def __init__(self, *,
on_show: Optional[Handler[UiEventArguments]] = None,
on_hide: Optional[Handler[UiEventArguments]] = None,) -> None:
"""Popup Edit

This element is based on Quasar's `QPopupEdit <https://quasar.dev/vue-components/popup-edit>`_ component.
It provides a popup editor that can be used to edit text or other content in a popup dialog.

NOTE: We only use the popup edit as a container for other elements.

- The JavaScript value of the popup edit will not be used.
- Rather, value handling is done by the child elements using `NiceGUI's data binding <https://nicegui.io/documentation/section_binding_properties>`_.

:param on_show: callback to execute when the popup editor is shown
:param on_hide: callback to execute when the popup editor is hidden
"""
super().__init__(tag='q-popup-edit')
if on_show:
self.on_show(on_show)
if on_hide:
self.on_hide(on_hide)

def show(self) -> None:
"""Open the popup editor."""
self.run_method('show')

def hide(self) -> None:
"""Close the popup editor."""
self.run_method('hide')

def on_show(self, callback: Handler[UiEventArguments]) -> None:
"""Register a handler to be called when the popup editor is shown.

:param handler: callback to execute when the popup editor is shown
"""
self.on('show', lambda: handle_event(callback, UiEventArguments(sender=self, client=self.client)), args=[])

def on_hide(self, callback: Handler[UiEventArguments]) -> None:
"""Register a handler to be called when the popup editor is hidden.

:param handler: callback to execute when the popup editor is hidden
"""
self.on('hide', lambda: handle_event(callback, UiEventArguments(sender=self, client=self.client)), args=[])
2 changes: 2 additions & 0 deletions nicegui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
'page_title',
'pagination',
'plotly',
'popup_edit',
'pyplot',
'query',
'radio',
Expand Down Expand Up @@ -206,6 +207,7 @@
from .elements.page_sticky import PageSticky as page_sticky
from .elements.pagination import Pagination as pagination
from .elements.plotly import Plotly as plotly
from .elements.popup_edit import PopupEdit as popup_edit
from .elements.progress import CircularProgress as circular_progress
from .elements.progress import LinearProgress as linear_progress
from .elements.pyplot import Matplotlib as matplotlib
Expand Down
18 changes: 18 additions & 0 deletions website/documentation/content/popup_edit_documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from nicegui import app, ui

from . import doc


@doc.demo(ui.popup_edit)
def main_demo() -> None:
# from nicegui import app, ui
app.storage.client['name'] = 'NiceGUI User'

with ui.label().bind_text_from(app.storage.client, 'name'):
with ui.popup_edit(on_show=lambda _: ui.notify('Shown!'),
on_hide=lambda _: ui.notify('Hidden!')) as popup:
ui.input().bind_value(app.storage.client, 'name')
ui.button('Force show popup edit', on_click=popup.show)


doc.reference(ui.popup_edit)
2 changes: 2 additions & 0 deletions website/documentation/content/section_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
badge_documentation,
button_documentation,
button_dropdown_documentation,
popup_edit_documentation,
button_group_documentation,
checkbox_documentation,
codemirror_documentation,
Expand Down Expand Up @@ -51,6 +52,7 @@
doc.intro(joystick_documentation)
doc.intro(input_documentation)
doc.intro(textarea_documentation)
doc.intro(popup_edit_documentation)
doc.intro(codemirror_documentation)
doc.intro(xterm_documentation)
doc.intro(number_documentation)
Expand Down