chat_message_documentation.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.chat_message)
  4. def main_demo() -> None:
  5. ui.chat_message('Hello NiceGUI!',
  6. name='Robot',
  7. stamp='now',
  8. avatar='https://robohash.org/ui')
  9. @doc.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. @doc.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. @doc.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. )
  26. @doc.demo('Chat message with child elements', '''
  27. You can add child elements to a chat message.
  28. ''')
  29. def child_elements():
  30. with ui.chat_message():
  31. ui.label('Guess where I am!')
  32. ui.image('https://picsum.photos/id/249/640/360').classes('w-64')
  33. doc.reference(ui.chat_message)