Browse Source

#655 make expansion text optional; add demo for custom header

Falko Schindler 2 years ago
parent
commit
430175be5d

+ 3 - 2
nicegui/elements/expansion.py

@@ -5,7 +5,7 @@ from .mixins.value_element import ValueElement
 
 class Expansion(ValueElement):
 
-    def __init__(self, text: str, *, icon: Optional[str] = None, value: bool = False) -> None:
+    def __init__(self, text: Optional[str] = None, *, icon: Optional[str] = None, value: bool = False) -> None:
         '''Expansion Element
 
         Provides an expandable container.
@@ -15,7 +15,8 @@ class Expansion(ValueElement):
         :param value: whether the expansion should be opened on creation (default: `False`)
         '''
         super().__init__(tag='q-expansion-item', value=value, on_value_change=None)
-        self._props['label'] = text
+        if text is not None:
+            self._props['label'] = text
         self._props['icon'] = icon
 
     def open(self) -> None:

+ 13 - 0
website/more_documentation/expansion_documentation.py

@@ -1,6 +1,19 @@
 from nicegui import ui
 
+from ..documentation_tools import text_demo
+
 
 def main_demo() -> None:
     with ui.expansion('Expand!', icon='work').classes('w-full'):
         ui.label('inside the expansion')
+
+
+def more() -> None:
+    @text_demo('Expansion with Custom Header', '''
+        Instead of setting a plain-text title, you can fill the expansion header with UI elements by adding them to the "header" slot.
+    ''')
+    def expansion_with_custom_header():
+        with ui.expansion() as expansion:
+            with expansion.add_slot('header'):
+                ui.image('https://nicegui.io/logo.png').classes('w-16')
+            ui.label('What a nice GUI!')