Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加setInputArea接口 #319

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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: 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
Loading