Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion content/plus/chat/index-en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@ render(DefaultChat);
| topSlot | top slot for chat | React.ReactNode | - |
| uploadProps | Upload component properties, refer to details [Upload](/en-US/input/upload#API%20%E5%8F%82%E8%80%83) | UploadProps | - |
| uploadTipProps | Upload component prompt attribute, refer to details [Tooltip](/en-US/show/tooltip#API%20%E5%8F%82%E8%80%83) | TooltipProps | - |
| allowSend | Whether to allow sending text and files in the input box, controlled prop, default true | boolean | true |


#### RoleConfig
Expand Down Expand Up @@ -1692,4 +1693,4 @@ render(DefaultChat);

## Design Token

<DesignToken/>
<DesignToken/>
1 change: 1 addition & 0 deletions content/plus/chat/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ render(DefaultChat);
| onInputChange | 输入区域信息变化时触发 | (props: { value?: string, attachment?: FileItem[] }) => void; | - |
| onMessageBadFeedback | 消息负向反馈时触发 | (message: Message) => void | - |
| onMessageCopy | 复制消息时触发 | (message: Message) => void | - |
| allowSend | 是否允许输入框发送文本和文件,受控属性,默认 true | boolean | true |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个位置不太对。后续估计得加一下prompt 约束,要按字母序改。

| onMessageDelete | 删除消息时触发 | (message: Message) => void | - |
| onMessageGoodFeedback | 消息正向反馈时触发 | (message: Message) => void | - |
| onMessageReset | 重置消息时触发 | (message: Message) => void | - |
Expand Down
6 changes: 6 additions & 0 deletions packages/semi-ui/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
uploadTipProps: PropTypes.object,
mode: PropTypes.string,
markdownRenderProps: PropTypes.object,
/**
* 是否允许输入框发送文字消息和文件
* 默认true,受控属性
*/
allowSend: PropTypes.bool,
};

static defaultProps = getDefaultPropsFromGlobalConfig(Chat.__SemiComponentName__, {
Expand Down Expand Up @@ -386,6 +391,7 @@ class Chat extends BaseComponent<ChatProps, ChatState> {
</span>)}
{/* input area */}
<InputBox
allowSend={this.props.allowSend}
showClearContext={showClearContext}
uploadRef={this.uploadRef}
manualUpload={this.adapter.manualUpload}
Expand Down
12 changes: 8 additions & 4 deletions packages/semi-ui/chat/inputBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { PREFIX_INPUT_BOX } = cssClasses;
const { SEND_HOT_KEY } = strings;
const textAutoSize = { minRows: 1, maxRows: 5 };

// 新增 allowSend props,控制输入和发送
class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {

inputAreaRef: React.RefObject<any>;
Expand Down Expand Up @@ -64,7 +65,7 @@ class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {
}

renderUploadButton = () => {
const { uploadProps, uploadRef, uploadTipProps, clickUpload } = this.props;
const { uploadProps, uploadRef, uploadTipProps, clickUpload, allowSend = true } = this.props;
if (!clickUpload) {
return null;
}
Expand All @@ -76,6 +77,7 @@ class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {
[className]: className
}),
onChange: this.foundation.onAttachmentAdd,
disabled: !allowSend,
};
const uploadNode = <Upload
ref={uploadRef}
Expand All @@ -86,6 +88,7 @@ class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {
className={`${PREFIX_INPUT_BOX}-uploadButton`}
icon={<IconChainStroked size="extra-large" />}
theme='borderless'
disabled={!allowSend}
/>}
</Upload>;
return (uploadTipProps ? <Tooltip {...uploadTipProps}><span>{uploadNode}</span></Tooltip> : uploadNode);
Expand Down Expand Up @@ -129,9 +132,10 @@ class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {

renderSendButton = () => {
const disabledSend = this.foundation.getDisableSend();
const { allowSend = true } = this.props;
return (
<Button
disabled={disabledSend}
disabled={disabledSend || !allowSend}
theme='solid'
type='primary'
className={`${PREFIX_INPUT_BOX}-sendButton`}
Expand All @@ -143,7 +147,7 @@ class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {
}

render() {
const { onClearContext, renderInputArea, onSend, style, className, showClearContext } = this.props;
const { onClearContext, renderInputArea, onSend, style, className, showClearContext, allowSend = true } = this.props;
const clearNode = this.renderClearButton();
const uploadNode = this.renderUploadButton();
const inputNode = this.renderInputArea();
Expand Down Expand Up @@ -181,4 +185,4 @@ class InputBox extends BaseComponent<InputBoxProps, InputBoxState> {
}
}

export default InputBox;
export default InputBox;
11 changes: 10 additions & 1 deletion packages/semi-ui/chat/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface ChatProps extends CommonChatsProps {
onClear?: () => void;
onInputChange?: (props: { value?: string; attachment?: FileItem[] }) => void;
onMessageSend?: (content: string, attachment: FileItem[]) => void;
/**
* 是否允许输入框发送文字消息和文件
* 默认true,受控属性
*/
allowSend?: boolean;
inputBoxStyle?: React.CSSProperties;
inputBoxCls?: string;
renderInputArea?: (props?: RenderInputAreaProps) => ReactNode;
Expand Down Expand Up @@ -173,7 +178,11 @@ export interface InputBoxProps {
onClearContext?: (e: any) => void;
onInputChange?: (props: {inputValue: string; attachment: FileItem[]}) => void;
clickUpload?: boolean;
pasteUpload?: boolean
pasteUpload?: boolean;
/**
* 是否允许输入框发送文字消息和文件,默认true
*/
allowSend?: boolean
}

export interface InputBoxState {
Expand Down