Ver Fonte

update ui.expansion

Falko Schindler há 2 anos atrás
pai
commit
1b3e1feda9

+ 1 - 1
api_docs_and_examples.py

@@ -434,7 +434,7 @@ Alternatively, you can remove individual elements with `remove(element)`, where
         ui.button('Remove', on_click=lambda: container.remove(0))
         ui.button('Clear', on_click=container.clear)
 
-    # @example(ui.expansion)
+    @example(ui.expansion, skip=False)
     def expansion_example():
         with ui.expansion('Expand!', icon='work').classes('w-full'):
             ui.label('inside the expansion')

+ 18 - 0
nicegui/elements/expansion.py

@@ -0,0 +1,18 @@
+from typing import Optional
+
+from ..element import Element
+
+
+class Expansion(Element):
+
+    def __init__(self, text: str, *, icon: Optional[str] = None) -> None:
+        '''Expansion Element
+
+        Provides an expandable container.
+
+        :param text: title text
+        :param icon: optional icon (default: None)
+        '''
+        super().__init__('q-expansion-item')
+        self._props['label'] = text
+        self._props['icon'] = icon

+ 0 - 27
nicegui/elements/old/expansion.py

@@ -1,27 +0,0 @@
-from typing import Optional
-
-import justpy as jp
-
-from ..binding import BindableProperty, BindTextMixin
-from .group import Group
-
-
-class Expansion(Group, BindTextMixin):
-    text = BindableProperty()
-
-    def __init__(self, text: str, *, icon: Optional[str] = None):
-        '''Expansion Element
-
-        Provides an expandable container.
-
-        :param text: title text
-        :param icon: optional icon (default: None)
-        '''
-        view = jp.QExpansionItem(label=text, icon=icon, delete_flag=False, temp=False)
-        super().__init__(view)
-
-        self.text = text
-        self.bind_text_to(self.view, 'label')
-
-    def set_text(self, text: str):
-        self.text = text

+ 1 - 0
nicegui/ui.py

@@ -6,6 +6,7 @@ from .elements.card import CardSection as card_section
 from .elements.checkbox import Checkbox as checkbox
 from .elements.colors import Colors as colors
 from .elements.column import Column as column
+from .elements.expansion import Expansion as expansion
 from .elements.html import Html as html
 from .elements.icon import Icon as icon
 from .elements.image import Image as image