chat_message_documentation.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. ui.chat_message('Hello NiceGUI!',
  5. name='Robot',
  6. stamp='now',
  7. avatar='https://robohash.org/ui')
  8. def more() -> None:
  9. @text_demo('HTML text', '''
  10. Using the `text_html` parameter, you can send HTML text to the chat.
  11. ''')
  12. def html_text():
  13. ui.chat_message('Without <strong>HTML</strong>')
  14. ui.chat_message('With <strong>HTML</strong>', text_html=True)
  15. @text_demo('Newline', '''
  16. You can use newlines in the chat message.
  17. ''')
  18. def newline():
  19. ui.chat_message('This is a\nlong line!')
  20. @text_demo('Multi-part messages', '''
  21. You can send multiple message parts by passing a list of strings.
  22. ''')
  23. def multiple_messages():
  24. ui.chat_message(['Hi! 😀', 'How are you?'])
  25. @text_demo('Chat message with child elements', '''
  26. You can add child elements to a chat message.
  27. ''')
  28. def child_elements():
  29. with ui.chat_message():
  30. ui.label('Guess where I am!')
  31. ui.image('https://picsum.photos/id/249/640/360').classes('w-64')