notify_documentation.py 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class NotifyDocumentation(UiElementDocumentation, element=ui.notify):
  4. def main_demo(self) -> None:
  5. ui.button('Say hi!', on_click=lambda: ui.notify('Hi!', close_button='OK'))
  6. def more(self) -> None:
  7. @self.demo('Notification Types', '''
  8. There are different types that can be used to indicate the nature of the notification.
  9. ''')
  10. def notify_colors():
  11. ui.button('negative', on_click=lambda: ui.notify('error', type='negative'))
  12. ui.button('positive', on_click=lambda: ui.notify('success', type='positive'))
  13. ui.button('warning', on_click=lambda: ui.notify('warning', type='warning'))
  14. @self.demo('Multiline Notifications', '''
  15. To allow a notification text to span multiple lines, it is sufficient to set `multi_line=True`.
  16. If manual newline breaks are required (e.g. `\\n`), you need to define a CSS style and pass it to the notification as shown in the example.
  17. ''')
  18. def multiline():
  19. ui.html('<style>.multi-line-notification { white-space: pre-line; }</style>')
  20. ui.button('show', on_click=lambda: ui.notify(
  21. 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. \n'
  22. 'Hic quisquam non ad sit assumenda consequuntur esse inventore officia. \n'
  23. 'Corrupti reiciendis impedit vel, '
  24. 'fugit odit quisquam quae porro exercitationem eveniet quasi.',
  25. multi_line=True,
  26. classes='multi-line-notification',
  27. ))