chat_message_documentation.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from nicegui import ui
  2. from ..model import UiElementDocumentation
  3. class ChatMessageDocumentation(UiElementDocumentation, element=ui.chat_message):
  4. def main_demo(self) -> None:
  5. ui.chat_message('Hello NiceGUI!',
  6. name='Robot',
  7. stamp='now',
  8. avatar='https://robohash.org/ui')
  9. def more(self) -> None:
  10. @self.add_markdown_demo('HTML text', '''
  11. Using the `text_html` parameter, you can send HTML text to the chat.
  12. ''')
  13. def html_text():
  14. ui.chat_message('Without <strong>HTML</strong>')
  15. ui.chat_message('With <strong>HTML</strong>', text_html=True)
  16. @self.add_markdown_demo('Newline', '''
  17. You can use newlines in the chat message.
  18. ''')
  19. def newline():
  20. ui.chat_message('This is a\nlong line!')
  21. @self.add_markdown_demo('Multi-part messages', '''
  22. You can send multiple message parts by passing a list of strings.
  23. ''')
  24. def multiple_messages():
  25. ui.chat_message(['Hi! 😀', 'How are you?'])
  26. @self.add_markdown_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')