Skip to content

Commit

Permalink
修改为新的icon
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Aug 1, 2024
1 parent 6a5c4b3 commit 202900e
Show file tree
Hide file tree
Showing 9 changed files with 3,874 additions and 3,050 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const nextConfig = {

## 🔨 Usage

```jsx
```tsx
import { ProChat } from '@ant-design/pro-chat';

export default () => (
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const nextConfig = {

## 🔨 使用

```jsx
```tsx
import { ProChat } from '@ant-design/pro-chat';

export default () => (
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/whyUseProChat.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The effect is as follows

Similarly, ProChat's request API is also compatible with traditional non streaming requests:

```jsx
```tsx
import { ProChat } from '@ant-design/pro-chat';
import { useTheme } from 'antd-style';

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/whyUseProChat.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ProChat 作为 AI 会话的前端解决方案,自然默认集成了这项流

而同样的,ProChat 的 request api 也兼容传统的非流式请求:

```jsx
```tsx
import { ProChat } from '@ant-design/pro-chat';
import { useTheme } from 'antd-style';

Expand Down
6,823 changes: 3,821 additions & 3,002 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/components/ProChat/demos/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default () => {
inputAreaProps={{
rows: 1,
}}
autocompleteRequest={async () => {
return ['table', 'docs', 'tools ', '参数配置', '你是谁', '联系我'].map((item) => ({
value: item,
label: item,
}));
}}
sendMessageRequest={() => {
return new Promise((resolve) => {
setTimeout(() => {
Expand Down
41 changes: 19 additions & 22 deletions src/components/ProChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,28 +416,24 @@ export function ProChat<
return chatList;
});

useImperativeHandle(
chatRef,
() => {
return {
stopGenerateMessage,
clearMessage,
sendMessage,
getChatList,
getChatLoadingMessage,
setMessageItem,
genMessageRecord,
scrollToBottom: () => {
(chatListContainerRef as any)?.current?.scrollTo({
behavior: 'smooth',
left: 0,
top: chatListContainerRef.current?.scrollHeight || 99999,
});
},
} as ProChatInstance<T>;
},
[chatRef],
);
useImperativeHandle(chatRef, () => {
return {
stopGenerateMessage,
clearMessage,
sendMessage,
getChatList,
getChatLoadingMessage,
setMessageItem,
genMessageRecord,
scrollToBottom: () => {
(chatListContainerRef as any)?.current?.scrollTo({
behavior: 'smooth',
left: 0,
top: chatListContainerRef.current?.scrollHeight || 99999,
});
},
} as ProChatInstance<T>;
}, [chatRef]);

const scrollToBottom = useMemo(() => {
if (chatListContainerRef.current) {
Expand Down Expand Up @@ -527,6 +523,7 @@ export function ProChat<
typing={!!loadingMessage?.id}
placeholder={placeholder || '请输入消息...'}
onMessageSend={sendMessage}
mentionRequest={props.autocompleteRequest}
stopGenerateMessage={stopGenerateMessage}
clearMessage={clearMessage}
areaRef={areaHtml}
Expand Down
39 changes: 19 additions & 20 deletions src/components/ProChatInputArea/AutoCompleteTextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Input } from 'antd';
import { TextAreaProps } from 'antd/es/input';
import { Mentions, MentionsProps } from 'antd';
import { useState } from 'react';

/**
* Props for the MentionsTextArea component.
*/
export type MentionsTextAreaProps = TextAreaProps & {
export type MentionsTextAreaProps = MentionsProps & {
/**
* A function that is called when a mention is requested.
* @param value - The value of the mention.
Expand Down Expand Up @@ -33,14 +33,12 @@ export type MentionsTextAreaProps = TextAreaProps & {
export const MentionsTextArea: React.FC<MentionsTextAreaProps> = (props) => {
const { disabled, mentionRequest, ...rest } = props;

// const [options, setOptions] = useState<{ value: string; label: string }[]>([]);
const [options, setOptions] = useState<{ value: string; label: string }[]>([]);
return (
<Input.TextArea
<Mentions
className={props.className}
disabled={disabled}
autoSize={{
minRows: rest.rows || 5,
}}
autoSize
rows={rest.rows || 5}
{...rest}
style={{
Expand All @@ -54,19 +52,20 @@ export const MentionsTextArea: React.FC<MentionsTextAreaProps> = (props) => {
height: 'auto',
...rest.style,
}}
// options={options}
// onSelect={(value) => {
// props.onChange?.({ target: { value } } as any);
// setOptions([]);
// }}
// prefix="/"
// onSearch={async (value, prefix) => {
// const result = await mentionRequest?.(value);
// setOptions((result as any[]) || []);
// rest?.onSearch?.(value, prefix);
// }}
options={options}
onSelect={(value) => {
props.onChange?.(value?.value);
setOptions([]);
}}
prefix="/"
onSearch={async (value, prefix) => {
if (!mentionRequest) return [];
const result = await mentionRequest?.(value);
setOptions((result as any[]) || []);
rest?.onSearch?.(value, prefix);
}}
onPressEnter={(e) => {
// if (open && options.length > 0) return;
if (options.length > 0) return;
props.onPressEnter?.(e);
}}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/components/ProChatInputArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export type ChatInputAreaProps = {
sendButtonStyle?: React.CSSProperties;

sendAreaStyle?: React.CSSProperties;

mentionRequest?: (value: string) => Promise<{ value: string; label?: string }[]>;
};

/**
Expand All @@ -131,6 +133,7 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
onMessageSend,
actionStyle,
locale,
mentionRequest,
actionsRender,
} = props || {};

Expand Down Expand Up @@ -160,13 +163,13 @@ export const ChatInputArea = (props: ChatInputAreaProps) => {
*/
const defaultAutoCompleteTextAreaProps = {
placeholder: placeholder,
mentionRequest,
...inputAreaProps,
className: cx(inputAreaProps?.className, `${prefixClass}-input`, hashId),
value: message,
onChange: (value) => {
setMessage(value.target.value);
setMessage(value);
},
autoSize: { maxRows: 8 },
onCompositionStart: () => {
isChineseInput.current = true;
},
Expand Down

0 comments on commit 202900e

Please sign in to comment.