notify_documentation.py 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. ui.button('Say hi!', on_click=lambda: ui.notify('Hi!', closeBtn='OK'))
  5. def more() -> None:
  6. @text_demo('Notification Types', '''
  7. There are different types that can be used to indicate the nature of the notification.
  8. ''')
  9. def notify_colors():
  10. ui.button('negative', on_click=lambda: ui.notify('error', type='negative'))
  11. ui.button('positive', on_click=lambda: ui.notify('success', type='positive'))
  12. ui.button('warning', on_click=lambda: ui.notify('warning', type='warning'))
  13. @text_demo('Multiline Notifications', '''
  14. To allow a notification text to span multiple lines, it is sufficient to pass the `mutliLine` keyword with `True`.
  15. 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.
  16. ''')
  17. def multiline():
  18. ui.html('<style>.multi-line-notification { white-space: pre-line; }</style>')
  19. ui.button('show', on_click=lambda: ui.notify(
  20. 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. \n'
  21. 'Hic quisquam non ad sit assumenda consequuntur esse inventore officia. \n'
  22. 'Corrupti reiciendis impedit vel, '
  23. 'fugit odit quisquam quae porro exercitationem eveniet quasi.',
  24. multiLine=True,
  25. classes='multi-line-notification',
  26. ))