浏览代码

chat: support multiple message parts

Falko Schindler 2 年之前
父节点
当前提交
defa7e5f67
共有 2 个文件被更改,包括 6 次插入6 次删除
  1. 2 2
      nicegui/elements/chat_message.js
  2. 4 4
      nicegui/elements/chat_message.py

+ 2 - 2
nicegui/elements/chat_message.js

@@ -1,7 +1,7 @@
 export default {
   template: `
     <q-chat-message
-      :text="[text]"
+      :text="text"
       :name="name"
       :label="label"
       :stamp="stamp"
@@ -10,7 +10,7 @@ export default {
     />
   `,
   props: {
-    text: String,
+    text: Array,
     name: String,
     label: String,
     stamp: String,

+ 4 - 4
nicegui/elements/chat_message.py

@@ -1,4 +1,4 @@
-from typing import Optional
+from typing import List, Optional, Union
 
 from ..dependencies import register_component
 from ..element import Element
@@ -9,7 +9,7 @@ register_component('chat_message', __file__, 'chat_message.js')
 class ChatMessage(Element):
 
     def __init__(self,
-                 text: str, *,
+                 text: Union[str, List[str]], *,
                  name: Optional[str] = None,
                  label: Optional[str] = None,
                  stamp: Optional[str] = None,
@@ -20,7 +20,7 @@ class ChatMessage(Element):
 
         Based on Quasar's `Chat Message <https://quasar.dev/vue-components/chat/>`_ component.
 
-        :param text: the message body
+        :param text: the message body (can be a list of strings for multiple message parts)
         :param name: the name of the message author
         :param label: renders a label header/section only
         :param stamp: timestamp of the message
@@ -28,7 +28,7 @@ class ChatMessage(Element):
         :param sent: render as a sent message (so from current user) (default: False)
         """
         super().__init__('chat_message')
-        self._props['text'] = text
+        self._props['text'] = [text] if isinstance(text, str) else text
         if name is not None:
             self._props['name'] = name
         if label is not None: