Parcourir la source

feat: Chat add canSend API (#3063)

* feat: Chat add canSend API

* chore: Modify the API version number in the documentation
YyumeiZhang il y a 3 semaines
Parent
commit
4ce3c8c3d2

+ 1 - 0
content/plus/chat/index-en-US.md

@@ -1606,6 +1606,7 @@ render(DefaultChat);
 |------|--------|-------|-------|
 | align | Dialog layout, supports `leftRight`,`leftAlign` | string | `leftRight` |
 | bottomSlot | bottom slot for chat | React.ReactNode | - |
+| canSend | Whether the send button is enabled. Normally, no settings are needed; the component internally determines whether sending is enabled. If settings are configured, the settings will prevail. Added in v2.90.0. | boolean |
 | chatBoxRenderConfig | chatBox rendering configuration | ChatBoxRenderConfig | - |
 | chats | Controlled conversation list | Message | - |
 | className | Custom class name | string | - |

+ 1 - 0
content/plus/chat/index.md

@@ -1609,6 +1609,7 @@ render(DefaultChat);
 |------|--------|-------|-------|
 | align | 对话布局方式,支持 `leftRight`、`leftAlign` | string | `leftRight` |
 | bottomSlot | 底部插槽 | React.ReactNode | - |
+| canSend | 发送按钮是否可以发送。通常无需设置,由内部逻辑决定。如有设置,以此设置为准,v2.90.0 新增 | boolean |
 | chatBoxRenderConfig | chatBox 渲染配置 | ChatBoxRenderConfig | - |
 | chats | 受控对话列表 | Message | - |
 | className | 自定义类名 | string | - |

+ 6 - 1
packages/semi-foundation/chat/inputboxFoundation.ts

@@ -60,7 +60,12 @@ export default class InputBoxFoundation <P = Record<string, any>, S = Record<str
 
     getDisableSend = () => {
         const { content, attachment } = this.getStates();
-        const { disableSend: disableSendInProps } = this.getProps();
+        const { disableSend: disableSendInProps, canSend } = this.getProps();
+        // 如果用户设置了 canSend API,则使用 canSend 值
+        // If the user has configured the canSend API, then the canSend value will be used.
+        if (typeof canSend === 'boolean') {
+            return !canSend;
+        }
         /** 不能发送的条件:(满足任1)
          *  1. props 中禁止发送;2. 没有文本输入,且没有上传文件; 3.上传文件中有状态不为 success 的
          *  Conditions under which content cannot be sent: (any one of the following conditions must be met)

+ 3 - 1
packages/semi-ui/chat/index.tsx

@@ -291,7 +291,8 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
             customMarkDownComponents, mode, showClearContext,
             placeholder, inputBoxCls, inputBoxStyle,
             hintStyle, hintCls, uploadProps, uploadTipProps,
-            sendHotKey, renderDivider, markdownRenderProps, enableUpload
+            sendHotKey, renderDivider, markdownRenderProps, enableUpload,
+            canSend,
         } = this.props;
         const { backBottomVisible, chats, wheelScroll, uploadAreaVisible } = this.state;
         let showStopGenerateFlag = false;
@@ -389,6 +390,7 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
                     </span>)}
                     {/* input area */}
                     <InputBox
+                        canSend={canSend}
                         showClearContext={showClearContext}
                         uploadRef={this.uploadRef}
                         manualUpload={this.adapter.manualUpload}

+ 2 - 0
packages/semi-ui/chat/interface.ts

@@ -29,6 +29,7 @@ export interface CommonChatsProps {
 export interface ChatProps extends CommonChatsProps {
     style?: React.CSSProperties;
     className?: string;
+    canSend?: boolean;
     hints?: string[];
     renderHintBox?: (props: {content: string; index: number;onHintClick: () => void}) => React.ReactNode;
     onHintClick?: (hint: string) => void;
@@ -158,6 +159,7 @@ export interface ChatBoxProps extends Omit<CommonChatsProps, "chats"> {
 }
 
 export interface InputBoxProps {
+    canSend?: boolean;
     showClearContext?: boolean;
     sendHotKey?: 'enter' | 'shift+enter';
     placeholder: string;