Kaynağa Gözat

add tooltip method

Falko Schindler 2 yıl önce
ebeveyn
işleme
e8df344169
3 değiştirilmiş dosya ile 11 ekleme ve 4 silme
  1. 4 3
      api_docs_and_examples.py
  2. 6 0
      nicegui/element.py
  3. 1 1
      nicegui/elements/tooltip.py

+ 4 - 3
api_docs_and_examples.py

@@ -452,12 +452,13 @@ Alternatively, you can remove individual elements with `remove(element)`, where
     @example('''#### Tooltips
 
 Simply call the `tooltip(text:str)` method on UI elements to provide a tooltip.
+
+For more artistic control you can nest tooltip elements and apply props, classes and styles.
 ''', skip=False)
     def tooltips_example():
-        with ui.label('Tooltips...'):
-            ui.tooltip('...are shown on mouse over')
+        ui.label('Tooltips...').tooltip('...are shown on mouse over')
         with ui.button().props('icon=thumb_up'):
-            ui.tooltip('I like this')
+            ui.tooltip('I like this').classes('bg-green')
 
     @example(ui.notify, skip=False)
     def notify_example():

+ 6 - 0
nicegui/element.py

@@ -116,6 +116,12 @@ class Element(ABC, Visibility):
             self.update()
         return self
 
+    def tooltip(self, text: str):
+        with self:
+            tooltip = Element('q-tooltip')
+            tooltip._text = text
+        return self
+
     def on(self, type: str, handler: Optional[Callable], args: List[str] = []):
         if handler:
             self._event_listeners.append(EventListener(element_id=self.id, type=type, args=args, handler=handler))

+ 1 - 1
nicegui/elements/tooltip.py

@@ -3,7 +3,7 @@ from .mixins.text_element import TextElement
 
 class Tooltip(TextElement):
 
-    def __init__(self, text: str = '') -> None:
+    def __init__(self, text: str) -> None:
         """Tooltip
 
         Can be placed in another element to show additional information on hover.