Skip to content

Commit

Permalink
feat: 添加setInputArea接口 (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
222chaos authored Sep 19, 2024
1 parent d6ab517 commit d6ae691
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/ProChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export interface ProChatInstance<T = Record<string, any>> {
message: Partial<ChatMessage<T>>,
userType: 'assistant' | 'user',
) => ChatMessage<T>;

setInputAreaValue: (value: string) => void;
}

export type ProChatChatReference<T = Record<string, any>> = MutableRefObject<
Expand Down Expand Up @@ -529,6 +531,7 @@ export function ProChat<
inputAreaRender={inputAreaRender}
inputRender={inputRender}
inputAreaProps={inputAreaProps}
chatRef={chatRef}
actionStyle={styles?.chatInputAction}
sendAreaStyle={styles?.chatSendAreaStyle}
areaStyle={styles?.chatInputArea}
Expand Down
14 changes: 11 additions & 3 deletions src/components/ProChatInputArea/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useRefFunction } from '@/hooks/useRefFunction';
import { ChatMessage } from '@/index';
import { ChatMessage, ProChatChatReference } from '@/index';
import { ProChatLocale } from '@/locale';
import { SendOutlined } from '@ant-design/icons';
import { Button, ButtonProps, ConfigProvider, Flex } from 'antd';
import cx from 'classnames';
import { useContext, useMemo, useRef, useState } from 'react';
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
import AnimationItem from '../Animation';
import { ProChatActionBar, ProChatActionBarProps } from './ActionBar';
import { MentionsTextArea, MentionsTextAreaProps } from './AutoCompleteTextArea';
Expand Down Expand Up @@ -75,6 +75,8 @@ export type ChatInputAreaProps = {
* Locale configuration for the ProChat component.
*/
locale?: ProChatLocale;

chatRef?: ProChatChatReference;
/**
* Callback function to clear the message input.
*/
Expand Down Expand Up @@ -133,6 +135,7 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
onMessageSend,
actionStyle,
locale,
chatRef,
mentionRequest,
actionsRender,
} = props || {};
Expand All @@ -144,7 +147,12 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
const prefixClass = getPrefixCls('pro-chat-input-area');

const { wrapSSR, hashId } = useStyle(prefixClass);

useEffect(() => {
if (!chatRef || !chatRef.current) return;
chatRef.current.setInputAreaValue = (value) => {
setMessage(value);
};
}, [chatRef]);
const send = useRefFunction(async () => {
if (onSend && message) {
const success = await onSend(message);
Expand Down

0 comments on commit d6ae691

Please sign in to comment.