From c6549654b8d23a424bbc5ad18211b30312b27e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 10 Apr 2024 20:40:37 +0800 Subject: [PATCH 01/72] =?UTF-8?q?feat:=20=F0=9F=94=A5=20New=20Component:?= =?UTF-8?q?=20ChatBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/index.test.ts.snap | 1 + .../chatbox/__tests__/demo-extend.test.ts | 3 ++ components/chatbox/__tests__/demo.test.ts | 3 ++ components/chatbox/__tests__/image.test.ts | 5 +++ components/chatbox/__tests__/index.test.tsx | 0 components/chatbox/demo/basic.md | 7 ++++ components/chatbox/demo/basic.tsx | 10 +++++ components/chatbox/index.en-US.md | 41 ++++++++++++++++++ components/chatbox/index.tsx | 39 +++++++++++++++++ components/chatbox/index.zh-CN.md | 42 +++++++++++++++++++ components/chatbox/style/index.ts | 28 +++++++++++++ components/index.ts | 2 + components/theme/interface/components.ts | 2 + 13 files changed, 183 insertions(+) create mode 100644 components/chatbox/__tests__/demo-extend.test.ts create mode 100644 components/chatbox/__tests__/demo.test.ts create mode 100644 components/chatbox/__tests__/image.test.ts create mode 100644 components/chatbox/__tests__/index.test.tsx create mode 100644 components/chatbox/demo/basic.md create mode 100644 components/chatbox/demo/basic.tsx create mode 100644 components/chatbox/index.en-US.md create mode 100644 components/chatbox/index.tsx create mode 100644 components/chatbox/index.zh-CN.md create mode 100644 components/chatbox/style/index.ts diff --git a/components/__tests__/__snapshots__/index.test.ts.snap b/components/__tests__/__snapshots__/index.test.ts.snap index 50f2581df9e6..9fb5d00c4aef 100644 --- a/components/__tests__/__snapshots__/index.test.ts.snap +++ b/components/__tests__/__snapshots__/index.test.ts.snap @@ -16,6 +16,7 @@ exports[`antd exports modules correctly 1`] = ` "Card", "Carousel", "Cascader", + "ChatBox", "Checkbox", "Col", "Collapse", diff --git a/components/chatbox/__tests__/demo-extend.test.ts b/components/chatbox/__tests__/demo-extend.test.ts new file mode 100644 index 000000000000..4940e499e235 --- /dev/null +++ b/components/chatbox/__tests__/demo-extend.test.ts @@ -0,0 +1,3 @@ +import { extendTest } from '../../../tests/shared/demoTest'; + +extendTest('chatbox'); diff --git a/components/chatbox/__tests__/demo.test.ts b/components/chatbox/__tests__/demo.test.ts new file mode 100644 index 000000000000..549211096c11 --- /dev/null +++ b/components/chatbox/__tests__/demo.test.ts @@ -0,0 +1,3 @@ +import demoTest from '../../../tests/shared/demoTest'; + +demoTest('chatbox'); diff --git a/components/chatbox/__tests__/image.test.ts b/components/chatbox/__tests__/image.test.ts new file mode 100644 index 000000000000..7e79d7a14b77 --- /dev/null +++ b/components/chatbox/__tests__/image.test.ts @@ -0,0 +1,5 @@ +import { imageDemoTest } from '../../../tests/shared/imageTest'; + +describe('chatbox image', () => { + imageDemoTest('chatbox'); +}); diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/components/chatbox/demo/basic.md b/components/chatbox/demo/basic.md new file mode 100644 index 000000000000..f42f59988c60 --- /dev/null +++ b/components/chatbox/demo/basic.md @@ -0,0 +1,7 @@ +## zh-CN + +按钮有五种类型:主按钮、次按钮、虚线按钮、文本按钮和链接按钮。主按钮在同一个操作区域最多出现一次。 + +## en-US + +There are `primary` button, `default` button, `dashed` button, `text` button and `link` button in antd. diff --git a/components/chatbox/demo/basic.tsx b/components/chatbox/demo/basic.tsx new file mode 100644 index 000000000000..79fd181b98a6 --- /dev/null +++ b/components/chatbox/demo/basic.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { ChatBox } from 'antd'; + +const App: React.FC = () => ( +
+ +
+); + +export default App; diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md new file mode 100644 index 000000000000..4f90bc5bdd08 --- /dev/null +++ b/components/chatbox/index.en-US.md @@ -0,0 +1,41 @@ +--- +category: Components +group: Data Display +title: ChatBox +description: A bubble component for chat. +cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAAAAAAAADrJ8AQ/original +coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*D70qQJJmzhgAAAAAAAAAAAAADrJ8AQ/original +demo: + cols: 2 +tag: 5.17.0 +--- + +## When To Use + +Often used when chatting. + +## Examples + + +Basic + +## API + +Common props ref:[Common props](/docs/react/common-props) + +> This component is available since `antd@5.17.0`. + +### ChatBox + +| Property | Description | Type | Default | Version | +| --- | --- | --- | --- | --- | +| avatar | Avatar component | `React.ReactNode` | - | | +| placement | Direction of Message | `start \| end` | `start` | | +| loading | Loading state of Message | `React.ReactNode` | - | | +| step | Show message with stepping motion | `boolean \| { step?: number, interval?: number }` | `false` | | +| content | Content of ChatBox | `string` | - | | +| contentRender | Display cuztomized content | `(content?: string) => ReactNode` | - | | + +## Design Token + + diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx new file mode 100644 index 000000000000..ef954ff61ab0 --- /dev/null +++ b/components/chatbox/index.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import classnames from 'classnames'; + +import { ConfigContext } from '../config-provider'; +import type { ConfigConsumerProps } from '../config-provider'; +import useStyle from './style'; + +export interface ChatBoxProps { + prefixCls?: string; + className?: string; + style?: React.CSSProperties; + avatar?: React.ReactNode; + placement?: 'start' | 'end'; + loading?: React.ReactNode; + step?: boolean | { step?: number; interval?: number }; + content?: string; + contentRender?: (content?: string) => React.ReactNode; +} + +const ChatBox: React.FC = (props) => { + const { prefixCls: customizePrefixCls, className, style } = props; + const { direction, getPrefixCls } = React.useContext(ConfigContext); + const prefixCls = getPrefixCls('chatbox', customizePrefixCls); + const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); + const mergedCls = classnames(className, prefixCls, hashId, cssVarCls, { + [`${prefixCls}-rtl`]: direction === 'rtl', + }); + return wrapCSSVar( +
+ Chat Box +
, + ); +}; + +if (process.env.NODE_ENV !== 'production') { + ChatBox.displayName = 'ChatBox'; +} + +export default ChatBox; diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md new file mode 100644 index 000000000000..b78c72968135 --- /dev/null +++ b/components/chatbox/index.zh-CN.md @@ -0,0 +1,42 @@ +--- +category: Components +group: 数据展示 +title: ChatBox +subtitle: 聊天框 +description: 用于聊天的气泡组件。 +cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAAAAAAAADrJ8AQ/original +coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*D70qQJJmzhgAAAAAAAAAAAAADrJ8AQ/original +demo: + cols: 2 +tag: 5.17.0 +--- + +## 何时使用 + +常用于聊天的时候。 + +## 代码演示 + + +基本 + +## API + +通用属性参考:[通用属性](/docs/react/common-props) + +> 自 `antd@5.17.0` 版本开始提供该组件。 + +### ChatBox + +| 属性 | 说明 | 类型 | 默认值 | 版本 | +| --- | --- | --- | --- | --- | +| avatar | 展示头像 | `React.ReactNode` | - | | +| placement | 信息位置 | `start \| end` | `start` | | +| loading | 聊天内容加载状态 | `React.ReactNode` | - | | +| step | 聊天内容动画 | `boolean \| { step?: number, interval?: number }` | `false` | | +| content | 聊天内容 | `string` | - | | +| contentRender | 自定义渲染内容 | `(content?: string) => ReactNode` | - | | + +## 主题变量(Design Token) + + diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts new file mode 100644 index 000000000000..6ba58a2882d5 --- /dev/null +++ b/components/chatbox/style/index.ts @@ -0,0 +1,28 @@ +import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; +import { genStyleHooks, mergeToken } from '../../theme/internal'; + +export interface ComponentToken { + // Component token here +} + +export interface ChatBoxToken extends FullToken<'ChatBox'> { + // +} + +const genChatBoxStyle: GenerateStyle = () => ({ + // +}); + +export const prepareComponentToken: GetDefaultToken<'ChatBox'> = () => ({ + // +}); + +// ============================== Export ============================== +export default genStyleHooks( + 'ChatBox', + (token) => { + const chatBoxToken = mergeToken(token); + return genChatBoxStyle(chatBoxToken); + }, + prepareComponentToken, +); diff --git a/components/index.ts b/components/index.ts index c1f5f82764f9..addad52522bc 100644 --- a/components/index.ts +++ b/components/index.ts @@ -28,6 +28,8 @@ export { default as Carousel } from './carousel'; export type { CarouselProps } from './carousel'; export { default as Cascader } from './cascader'; export type { CascaderProps } from './cascader'; +export { default as ChatBox } from './chatbox'; +export type { ChatBoxProps } from './chatbox'; export { default as Checkbox } from './checkbox'; export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox'; export { default as Col } from './col'; diff --git a/components/theme/interface/components.ts b/components/theme/interface/components.ts index 2ecbe62e32c8..d27a084cd7cc 100644 --- a/components/theme/interface/components.ts +++ b/components/theme/interface/components.ts @@ -12,6 +12,7 @@ import type { ComponentToken as CalendarComponentToken } from '../../calendar/st import type { ComponentToken as CardComponentToken } from '../../card/style'; import type { ComponentToken as CarouselComponentToken } from '../../carousel/style'; import type { ComponentToken as CascaderComponentToken } from '../../cascader/style'; +import type { ComponentToken as ChatBoxComponentToken } from '../../chatbox/style'; import type { ComponentToken as CheckboxComponentToken } from '../../checkbox/style'; import type { ComponentToken as CollapseComponentToken } from '../../collapse/style'; import type { ComponentToken as ColorPickerComponentToken } from '../../color-picker/style'; @@ -76,6 +77,7 @@ export interface ComponentTokenMap { Card?: CardComponentToken; Carousel?: CarouselComponentToken; Cascader?: CascaderComponentToken; + ChatBox?: ChatBoxComponentToken; Checkbox?: CheckboxComponentToken; ColorPicker?: ColorPickerComponentToken; Collapse?: CollapseComponentToken; From d25df53ed26cdc5ea6872a7413457f37128bb6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 10 Apr 2024 22:27:07 +0800 Subject: [PATCH 02/72] chore: rename folder chatbox => chat-box --- .../__snapshots__/demo-extend.test.ts.snap | 13 +++++++++++++ .../__tests__/__snapshots__/demo.test.ts.snap | 11 +++++++++++ .../__tests__/__snapshots__/index.test.tsx.snap | 9 +++++++++ .../__tests__/demo-extend.test.ts | 2 +- .../{chatbox => chat-box}/__tests__/demo.test.ts | 2 +- .../{chatbox => chat-box}/__tests__/image.test.ts | 4 ++-- components/chat-box/__tests__/index.test.tsx | 8 ++++++++ components/chat-box/demo/basic.md | 7 +++++++ components/{chatbox => chat-box}/demo/basic.tsx | 0 components/{chatbox => chat-box}/index.en-US.md | 0 components/{chatbox => chat-box}/index.tsx | 5 +++-- components/{chatbox => chat-box}/index.zh-CN.md | 0 components/{chatbox => chat-box}/style/index.ts | 5 ++--- components/chatbox/__tests__/index.test.tsx | 0 components/chatbox/demo/basic.md | 7 ------- components/index.ts | 4 ++-- components/theme/interface/components.ts | 2 +- 17 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap create mode 100644 components/chat-box/__tests__/__snapshots__/demo.test.ts.snap create mode 100644 components/chat-box/__tests__/__snapshots__/index.test.tsx.snap rename components/{chatbox => chat-box}/__tests__/demo-extend.test.ts (72%) rename components/{chatbox => chat-box}/__tests__/demo.test.ts (71%) rename components/{chatbox => chat-box}/__tests__/image.test.ts (52%) create mode 100644 components/chat-box/__tests__/index.test.tsx create mode 100644 components/chat-box/demo/basic.md rename components/{chatbox => chat-box}/demo/basic.tsx (100%) rename components/{chatbox => chat-box}/index.en-US.md (100%) rename components/{chatbox => chat-box}/index.tsx (84%) rename components/{chatbox => chat-box}/index.zh-CN.md (100%) rename components/{chatbox => chat-box}/style/index.ts (81%) delete mode 100644 components/chatbox/__tests__/index.test.tsx delete mode 100644 components/chatbox/demo/basic.md diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap new file mode 100644 index 000000000000..82b1b67c6c35 --- /dev/null +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = ` +
+
+ Chat Box +
+
+`; + +exports[`renders components/chat-box/demo/basic.tsx extend context correctly 2`] = `[]`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap new file mode 100644 index 000000000000..c52f88158893 --- /dev/null +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` +
+
+ Chat Box +
+
+`; diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000000..acab1c29bf6a --- /dev/null +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = ` +
+ Chat Box +
+`; diff --git a/components/chatbox/__tests__/demo-extend.test.ts b/components/chat-box/__tests__/demo-extend.test.ts similarity index 72% rename from components/chatbox/__tests__/demo-extend.test.ts rename to components/chat-box/__tests__/demo-extend.test.ts index 4940e499e235..b4d9d9c58948 100644 --- a/components/chatbox/__tests__/demo-extend.test.ts +++ b/components/chat-box/__tests__/demo-extend.test.ts @@ -1,3 +1,3 @@ import { extendTest } from '../../../tests/shared/demoTest'; -extendTest('chatbox'); +extendTest('chat-box'); diff --git a/components/chatbox/__tests__/demo.test.ts b/components/chat-box/__tests__/demo.test.ts similarity index 71% rename from components/chatbox/__tests__/demo.test.ts rename to components/chat-box/__tests__/demo.test.ts index 549211096c11..818365aa325f 100644 --- a/components/chatbox/__tests__/demo.test.ts +++ b/components/chat-box/__tests__/demo.test.ts @@ -1,3 +1,3 @@ import demoTest from '../../../tests/shared/demoTest'; -demoTest('chatbox'); +demoTest('chat-box'); diff --git a/components/chatbox/__tests__/image.test.ts b/components/chat-box/__tests__/image.test.ts similarity index 52% rename from components/chatbox/__tests__/image.test.ts rename to components/chat-box/__tests__/image.test.ts index 7e79d7a14b77..d1b453c649b1 100644 --- a/components/chatbox/__tests__/image.test.ts +++ b/components/chat-box/__tests__/image.test.ts @@ -1,5 +1,5 @@ import { imageDemoTest } from '../../../tests/shared/imageTest'; -describe('chatbox image', () => { - imageDemoTest('chatbox'); +describe('chat-box image', () => { + imageDemoTest('chat-box'); }); diff --git a/components/chat-box/__tests__/index.test.tsx b/components/chat-box/__tests__/index.test.tsx new file mode 100644 index 000000000000..a48247d11c0b --- /dev/null +++ b/components/chat-box/__tests__/index.test.tsx @@ -0,0 +1,8 @@ +import ChatBox from '..'; +import mountTest from '../../../tests/shared/mountTest'; +import rtlTest from '../../../tests/shared/rtlTest'; + +describe('chat-box', () => { + mountTest(ChatBox); + rtlTest(ChatBox); +}); diff --git a/components/chat-box/demo/basic.md b/components/chat-box/demo/basic.md new file mode 100644 index 000000000000..673339b1ba7d --- /dev/null +++ b/components/chat-box/demo/basic.md @@ -0,0 +1,7 @@ +## zh-CN + +基础用法。 + +## en-US + +Basic usage. diff --git a/components/chatbox/demo/basic.tsx b/components/chat-box/demo/basic.tsx similarity index 100% rename from components/chatbox/demo/basic.tsx rename to components/chat-box/demo/basic.tsx diff --git a/components/chatbox/index.en-US.md b/components/chat-box/index.en-US.md similarity index 100% rename from components/chatbox/index.en-US.md rename to components/chat-box/index.en-US.md diff --git a/components/chatbox/index.tsx b/components/chat-box/index.tsx similarity index 84% rename from components/chatbox/index.tsx rename to components/chat-box/index.tsx index ef954ff61ab0..3621e5427d13 100644 --- a/components/chatbox/index.tsx +++ b/components/chat-box/index.tsx @@ -8,6 +8,7 @@ import useStyle from './style'; export interface ChatBoxProps { prefixCls?: string; className?: string; + rootClassName?: string; style?: React.CSSProperties; avatar?: React.ReactNode; placement?: 'start' | 'end'; @@ -18,11 +19,11 @@ export interface ChatBoxProps { } const ChatBox: React.FC = (props) => { - const { prefixCls: customizePrefixCls, className, style } = props; + const { prefixCls: customizePrefixCls, className, rootClassName, style } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const mergedCls = classnames(className, prefixCls, hashId, cssVarCls, { + const mergedCls = classnames(className, rootClassName, prefixCls, hashId, cssVarCls, { [`${prefixCls}-rtl`]: direction === 'rtl', }); return wrapCSSVar( diff --git a/components/chatbox/index.zh-CN.md b/components/chat-box/index.zh-CN.md similarity index 100% rename from components/chatbox/index.zh-CN.md rename to components/chat-box/index.zh-CN.md diff --git a/components/chatbox/style/index.ts b/components/chat-box/style/index.ts similarity index 81% rename from components/chatbox/style/index.ts rename to components/chat-box/style/index.ts index 6ba58a2882d5..ffe2156f62bf 100644 --- a/components/chatbox/style/index.ts +++ b/components/chat-box/style/index.ts @@ -2,7 +2,7 @@ import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/inte import { genStyleHooks, mergeToken } from '../../theme/internal'; export interface ComponentToken { - // Component token here + // } export interface ChatBoxToken extends FullToken<'ChatBox'> { @@ -17,8 +17,7 @@ export const prepareComponentToken: GetDefaultToken<'ChatBox'> = () => ({ // }); -// ============================== Export ============================== -export default genStyleHooks( +export default genStyleHooks<'ChatBox'>( 'ChatBox', (token) => { const chatBoxToken = mergeToken(token); diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/components/chatbox/demo/basic.md b/components/chatbox/demo/basic.md deleted file mode 100644 index f42f59988c60..000000000000 --- a/components/chatbox/demo/basic.md +++ /dev/null @@ -1,7 +0,0 @@ -## zh-CN - -按钮有五种类型:主按钮、次按钮、虚线按钮、文本按钮和链接按钮。主按钮在同一个操作区域最多出现一次。 - -## en-US - -There are `primary` button, `default` button, `dashed` button, `text` button and `link` button in antd. diff --git a/components/index.ts b/components/index.ts index addad52522bc..921c143508db 100644 --- a/components/index.ts +++ b/components/index.ts @@ -28,8 +28,8 @@ export { default as Carousel } from './carousel'; export type { CarouselProps } from './carousel'; export { default as Cascader } from './cascader'; export type { CascaderProps } from './cascader'; -export { default as ChatBox } from './chatbox'; -export type { ChatBoxProps } from './chatbox'; +export { default as ChatBox } from './chat-box'; +export type { ChatBoxProps } from './chat-box'; export { default as Checkbox } from './checkbox'; export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox'; export { default as Col } from './col'; diff --git a/components/theme/interface/components.ts b/components/theme/interface/components.ts index d27a084cd7cc..e62223bfce08 100644 --- a/components/theme/interface/components.ts +++ b/components/theme/interface/components.ts @@ -12,7 +12,7 @@ import type { ComponentToken as CalendarComponentToken } from '../../calendar/st import type { ComponentToken as CardComponentToken } from '../../card/style'; import type { ComponentToken as CarouselComponentToken } from '../../carousel/style'; import type { ComponentToken as CascaderComponentToken } from '../../cascader/style'; -import type { ComponentToken as ChatBoxComponentToken } from '../../chatbox/style'; +import type { ComponentToken as ChatBoxComponentToken } from '../../chat-box/style'; import type { ComponentToken as CheckboxComponentToken } from '../../checkbox/style'; import type { ComponentToken as CollapseComponentToken } from '../../collapse/style'; import type { ComponentToken as ColorPickerComponentToken } from '../../color-picker/style'; From 1aa99bb60daf24a540f6f0355c97d5cd4c6f812b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 10 Apr 2024 23:14:42 +0800 Subject: [PATCH 03/72] test: update snap --- tests/__snapshots__/index.test.ts.snap | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/__snapshots__/index.test.ts.snap b/tests/__snapshots__/index.test.ts.snap index 0a4758fc7e28..299402aa7b9f 100644 --- a/tests/__snapshots__/index.test.ts.snap +++ b/tests/__snapshots__/index.test.ts.snap @@ -16,6 +16,7 @@ exports[`antd dist files exports modules correctly 1`] = ` "Card", "Carousel", "Cascader", + "ChatBox", "Checkbox", "Col", "Collapse", From b1153e81d84000d45af3f707d7f6ee1d1a27a164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 10 Apr 2024 23:52:38 +0800 Subject: [PATCH 04/72] test: update snap --- components/chat-box/index.tsx | 12 ++++++++---- scripts/__snapshots__/check-site.ts.snap | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 3621e5427d13..e55a5cbcdec8 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import classnames from 'classnames'; +import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; @@ -19,16 +19,20 @@ export interface ChatBoxProps { } const ChatBox: React.FC = (props) => { - const { prefixCls: customizePrefixCls, className, rootClassName, style } = props; + const { prefixCls: customizePrefixCls, className, rootClassName, style, avatar, content } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const mergedCls = classnames(className, rootClassName, prefixCls, hashId, cssVarCls, { + const mergedCls = classNames(className, rootClassName, prefixCls, hashId, cssVarCls, { [`${prefixCls}-rtl`]: direction === 'rtl', }); + if (typeof content !== 'string') { + return null; + } return wrapCSSVar(
- Chat Box + {avatar} + {content}
, ); }; diff --git a/scripts/__snapshots__/check-site.ts.snap b/scripts/__snapshots__/check-site.ts.snap index 65a17fcc0085..fc6a7e98decd 100644 --- a/scripts/__snapshots__/check-site.ts.snap +++ b/scripts/__snapshots__/check-site.ts.snap @@ -56,6 +56,10 @@ exports[`site test Component components/checkbox en Page 1`] = `3`; exports[`site test Component components/checkbox zh Page 1`] = `3`; +exports[`site test Component components/chat-box en Page 1`] = `1`; + +exports[`site test Component components/chat-box zh Page 1`] = `1`; + exports[`site test Component components/collapse en Page 1`] = `2`; exports[`site test Component components/collapse zh Page 1`] = `2`; From 82e4cdc3bb79892818816969c6270cc71d3a2143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 11 Apr 2024 00:04:28 +0800 Subject: [PATCH 05/72] feat: add more props --- .../__snapshots__/demo-extend.test.ts.snap | 4 +-- .../__tests__/__snapshots__/demo.test.ts.snap | 4 +-- .../__snapshots__/index.test.tsx.snap | 6 ++--- components/chat-box/index.tsx | 25 +++++++++++++------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index 82b1b67c6c35..371a866f02ff 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -3,9 +3,9 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = `
- Chat Box + 你好你好你好
`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index c52f88158893..bdcf5169c09b 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -3,9 +3,9 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = `
- Chat Box + 你好你好你好
`; diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap index acab1c29bf6a..2160eedb3c36 100644 --- a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -2,8 +2,6 @@ exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = `
- Chat Box -
+ class="ant-chatbox ant-chatbox-start ant-chatbox-rtl" +/> `; diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index e55a5cbcdec8..a2270cd9adaa 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -19,16 +19,27 @@ export interface ChatBoxProps { } const ChatBox: React.FC = (props) => { - const { prefixCls: customizePrefixCls, className, rootClassName, style, avatar, content } = props; + const { + prefixCls: customizePrefixCls, + className, + rootClassName, + style, + avatar, + content, + placement = 'start', + } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const mergedCls = classNames(className, rootClassName, prefixCls, hashId, cssVarCls, { - [`${prefixCls}-rtl`]: direction === 'rtl', - }); - if (typeof content !== 'string') { - return null; - } + const mergedCls = classNames( + className, + rootClassName, + prefixCls, + hashId, + cssVarCls, + `${prefixCls}-${placement}`, + { [`${prefixCls}-rtl`]: direction === 'rtl' }, + ); return wrapCSSVar(
{avatar} From bb69469955ddc3c7adf9a5b300062a92c5b101bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Fri, 12 Apr 2024 01:11:13 +0800 Subject: [PATCH 06/72] feat: add style --- .../__snapshots__/demo-extend.test.ts.snap | 25 +++++++++- .../__tests__/__snapshots__/demo.test.ts.snap | 25 +++++++++- .../__snapshots__/index.test.tsx.snap | 9 +++- components/chat-box/demo/basic.tsx | 9 ++-- components/chat-box/index.tsx | 18 ++++++- components/chat-box/style/index.ts | 49 +++++++++++++++++-- 6 files changed, 119 insertions(+), 16 deletions(-) diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index 371a866f02ff..38808cad30a1 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1,11 +1,32 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = ` -
+
- 你好你好你好 +
+
+ 你好你好你好 +
+
+
+
+ 你好你好你好 +
+
`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index bdcf5169c09b..4a2a35442ce2 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -1,11 +1,32 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` -
+
- 你好你好你好 +
+
+ 你好你好你好 +
+
+
+
+ 你好你好你好 +
+
`; diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap index 2160eedb3c36..c18a62e603c9 100644 --- a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -3,5 +3,12 @@ exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = `
+> +
+
+
`; diff --git a/components/chat-box/demo/basic.tsx b/components/chat-box/demo/basic.tsx index 79fd181b98a6..0e8347ac8552 100644 --- a/components/chat-box/demo/basic.tsx +++ b/components/chat-box/demo/basic.tsx @@ -1,10 +1,11 @@ import React from 'react'; -import { ChatBox } from 'antd'; +import { ChatBox, Flex } from 'antd'; const App: React.FC = () => ( -
- -
+ + + + ); export default App; diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index a2270cd9adaa..f77c88c0de45 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -40,11 +40,25 @@ const ChatBox: React.FC = (props) => { `${prefixCls}-${placement}`, { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); - return wrapCSSVar( -
+ + let [startNode, endNode] = [ +
{avatar} +
, +
{content}
, + ]; + + if (placement === 'end') { + [startNode, endNode] = [endNode, startNode]; + } + + return wrapCSSVar( +
+ {startNode} + {endNode} +
, ); }; diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index ffe2156f62bf..d236c6cbc36c 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -1,3 +1,5 @@ +import { unit } from '@ant-design/cssinjs'; + import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; @@ -6,12 +8,46 @@ export interface ComponentToken { } export interface ChatBoxToken extends FullToken<'ChatBox'> { - // + messageMaxWidth: number; + avatarGap: number; } -const genChatBoxStyle: GenerateStyle = () => ({ - // -}); +const genChatBoxStyle: GenerateStyle = (token) => { + const { componentCls, messageMaxWidth, avatarGap } = token; + return { + [componentCls]: { + display: 'flex', + gap: avatarGap, + maxWidth: '100%', + [`&${componentCls}-start`]: { + justifyContent: 'flex-start', + }, + [`&${componentCls}-end`]: { + justifyContent: 'flex-end', + }, + [`&${componentCls}-rtl`]: { + direction: 'rtl', + }, + [`& ${componentCls}-avatar`]: { + backgroundColor: token.colorText, + borderRadius: '50%', + width: 32, + height: 32, + minWidth: 32, + minHeight: 32, + }, + [`& ${componentCls}-content`]: { + padding: `${unit(token.paddingSM)} ${unit(token.padding)}`, + color: token.colorText, + fontSize: token.fontSize, + maxWidth: unit(messageMaxWidth), + backgroundColor: token.colorInfoBg, + borderRadius: token.borderRadiusLG, + boxShadow: token.boxShadowTertiary, + }, + }, + }; +}; export const prepareComponentToken: GetDefaultToken<'ChatBox'> = () => ({ // @@ -20,7 +56,10 @@ export const prepareComponentToken: GetDefaultToken<'ChatBox'> = () => ({ export default genStyleHooks<'ChatBox'>( 'ChatBox', (token) => { - const chatBoxToken = mergeToken(token); + const chatBoxToken = mergeToken(token, { + messageMaxWidth: 720, + avatarGap: token.paddingXS, + }); return genChatBoxStyle(chatBoxToken); }, prepareComponentToken, From a7e814672b84fec512830c679e235003e02a8fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Fri, 12 Apr 2024 18:35:18 +0800 Subject: [PATCH 07/72] style: fix style --- components/chat-box/demo/basic.tsx | 17 +++++++++++++---- components/chat-box/index.tsx | 17 ++--------------- components/chat-box/style/index.ts | 15 +++++++-------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/components/chat-box/demo/basic.tsx b/components/chat-box/demo/basic.tsx index 0e8347ac8552..1e20b9016754 100644 --- a/components/chat-box/demo/basic.tsx +++ b/components/chat-box/demo/basic.tsx @@ -1,10 +1,19 @@ import React from 'react'; -import { ChatBox, Flex } from 'antd'; +import { UserOutlined } from '@ant-design/icons'; +import { Avatar, ChatBox, Flex } from 'antd'; const App: React.FC = () => ( - - - + + } />} + /> + } />} + /> ); diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index f77c88c0de45..cfa3286f3489 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -41,23 +41,10 @@ const ChatBox: React.FC = (props) => { { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); - let [startNode, endNode] = [ -
- {avatar} -
, -
- {content} -
, - ]; - - if (placement === 'end') { - [startNode, endNode] = [endNode, startNode]; - } - return wrapCSSVar(
- {startNode} - {endNode} + {avatar &&
{avatar}
} +
{content}
, ); }; diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index d236c6cbc36c..10722b15b6e8 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -20,23 +20,22 @@ const genChatBoxStyle: GenerateStyle = (token) => { gap: avatarGap, maxWidth: '100%', [`&${componentCls}-start`]: { - justifyContent: 'flex-start', + flexDirection: 'row', + justifyContent: 'start', }, [`&${componentCls}-end`]: { - justifyContent: 'flex-end', + flexDirection: 'row-reverse', + justifyContent: 'end', }, [`&${componentCls}-rtl`]: { direction: 'rtl', }, [`& ${componentCls}-avatar`]: { - backgroundColor: token.colorText, - borderRadius: '50%', - width: 32, - height: 32, - minWidth: 32, - minHeight: 32, + display: 'inline-flex', + justifyContent: 'center', }, [`& ${componentCls}-content`]: { + position: 'relative', padding: `${unit(token.paddingSM)} ${unit(token.padding)}`, color: token.colorText, fontSize: token.fontSize, From 13ee8051a18aa9d0fa5baed248cbdcc9a0ca5eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Fri, 12 Apr 2024 20:48:01 +0800 Subject: [PATCH 08/72] test: update snap --- .../__snapshots__/demo-extend.test.ts.snap | 60 +++++++++++++++++-- .../__tests__/__snapshots__/demo.test.ts.snap | 60 +++++++++++++++++-- .../__snapshots__/index.test.tsx.snap | 3 - components/chat-box/style/index.ts | 4 -- 4 files changed, 110 insertions(+), 17 deletions(-) diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index 38808cad30a1..291edc8e3e95 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -2,14 +2,39 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = `
+ > + + + + + +
@@ -19,14 +44,39 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`]
+
+ + + + + +
你好你好你好
-
`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index 4a2a35442ce2..0192c8359a49 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -2,14 +2,39 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = `
+ > + + + + + +
@@ -19,14 +44,39 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = `
+
+ + + + + +
你好你好你好
-
`; diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap index c18a62e603c9..cf60bfedf55e 100644 --- a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -4,9 +4,6 @@ exports[`chat-box rtl render component should be rendered correctly in RTL direc
-
diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index 10722b15b6e8..5fb36820b0e6 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -19,10 +19,6 @@ const genChatBoxStyle: GenerateStyle = (token) => { display: 'flex', gap: avatarGap, maxWidth: '100%', - [`&${componentCls}-start`]: { - flexDirection: 'row', - justifyContent: 'start', - }, [`&${componentCls}-end`]: { flexDirection: 'row-reverse', justifyContent: 'end', From e0b5de63c68c6b0ace93f38ff40695dded49a2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Fri, 12 Apr 2024 21:58:31 +0800 Subject: [PATCH 09/72] fix: fix --- components/chat-box/demo/basic.tsx | 4 +- components/chat-box/index.tsx | 63 +++++++++++++++++++++++++++++- components/chat-box/style/index.ts | 26 +++++++++++- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/components/chat-box/demo/basic.tsx b/components/chat-box/demo/basic.tsx index 1e20b9016754..7ae73c64702e 100644 --- a/components/chat-box/demo/basic.tsx +++ b/components/chat-box/demo/basic.tsx @@ -6,12 +6,12 @@ const App: React.FC = () => ( } />} /> } />} /> diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index cfa3286f3489..2e33eccc29e2 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -5,6 +5,11 @@ import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; import useStyle from './style'; +interface StepOption { + step: number; + interval: number; +} + export interface ChatBoxProps { prefixCls?: string; className?: string; @@ -13,11 +18,16 @@ export interface ChatBoxProps { avatar?: React.ReactNode; placement?: 'start' | 'end'; loading?: React.ReactNode; - step?: boolean | { step?: number; interval?: number }; + step?: boolean | StepOption; content?: string; contentRender?: (content?: string) => React.ReactNode; } +const defaultStep: StepOption = { + step: 1, + interval: 100, +}; + const ChatBox: React.FC = (props) => { const { prefixCls: customizePrefixCls, @@ -27,10 +37,56 @@ const ChatBox: React.FC = (props) => { avatar, content, placement = 'start', + step = true, } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); + + const [typedContent, setTypedContent] = React.useState(''); + const [showCursor, setShowCursor] = React.useState(false); + + const timerRef = React.useRef>(); + + const clearTimer = () => { + if (timerRef.current) { + clearInterval(timerRef.current); + } + }; + + const mergedStep = React.useMemo(() => { + if (step && typeof step === 'object') { + return { ...defaultStep, ...step }; + } + if (step === true) { + return defaultStep; + } + return step; + }, [step]); + + React.useEffect(() => { + if (!content) { + return; + } + if (mergedStep) { + setShowCursor(true); + let stepCount = 0; + const { step: totalStep, interval } = mergedStep; + timerRef.current = setInterval(() => { + stepCount += totalStep; + setTypedContent(content.slice(0, stepCount) ?? ''); + if (stepCount >= content.length) { + clearTimer(); + setShowCursor(false); + } + }, interval); + return () => { + clearTimer(); + setShowCursor(false); + }; + } + }, [content, mergedStep]); + const mergedCls = classNames( className, rootClassName, @@ -44,7 +100,10 @@ const ChatBox: React.FC = (props) => { return wrapCSSVar(
{avatar &&
{avatar}
} -
{content}
+
+ {mergedStep ? typedContent : content} + {showCursor && |} +
, ); }; diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index 5fb36820b0e6..87d418c48753 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -1,8 +1,20 @@ -import { unit } from '@ant-design/cssinjs'; +import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; +const cursorBlink = new Keyframes('CursorBlink', { + '0%': { + opacity: 1, + }, + '50%': { + opacity: 0, + }, + '100%': { + opacity: 1, + }, +}); + export interface ComponentToken { // } @@ -39,6 +51,18 @@ const genChatBoxStyle: GenerateStyle = (token) => { backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, + '&-typedCursor': { + position: 'absolute', + right: 14, + bottom: 14, + fontSize: token.fontSizeLG, + userSelect: 'none', + opacity: 1, + fontWeight: 900, + animationName: cursorBlink, + animationDuration: '0.7s', + animationIterationCount: 'infinite', + }, }, }, }; From f9824b8cb21cb147719e1b66be4ee8a9ca17521d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Fri, 12 Apr 2024 21:59:54 +0800 Subject: [PATCH 10/72] fix: fix --- components/chat-box/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 2e33eccc29e2..2d1896c48c36 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -37,7 +37,7 @@ const ChatBox: React.FC = (props) => { avatar, content, placement = 'start', - step = true, + step, } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); @@ -61,7 +61,7 @@ const ChatBox: React.FC = (props) => { if (step === true) { return defaultStep; } - return step; + return false; }, [step]); React.useEffect(() => { From b3d598a5472af62872d7c75a2d11d1437703c288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Fri, 12 Apr 2024 22:28:48 +0800 Subject: [PATCH 11/72] fix: fix --- components/chat-box/index.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 2d1896c48c36..e78108ad764f 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -10,6 +10,11 @@ interface StepOption { interval: number; } +const defaultStep: StepOption = { + step: 1, + interval: 100, +}; + export interface ChatBoxProps { prefixCls?: string; className?: string; @@ -23,11 +28,6 @@ export interface ChatBoxProps { contentRender?: (content?: string) => React.ReactNode; } -const defaultStep: StepOption = { - step: 1, - interval: 100, -}; - const ChatBox: React.FC = (props) => { const { prefixCls: customizePrefixCls, @@ -35,9 +35,10 @@ const ChatBox: React.FC = (props) => { rootClassName, style, avatar, - content, placement = 'start', step, + content, + contentRender, } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); @@ -100,10 +101,14 @@ const ChatBox: React.FC = (props) => { return wrapCSSVar(
{avatar &&
{avatar}
} -
- {mergedStep ? typedContent : content} - {showCursor && |} -
+ {typeof contentRender === 'function' ? ( + contentRender(content) + ) : ( +
+ {mergedStep ? typedContent : content} + {showCursor && |} +
+ )}
, ); }; From 30b4d0df4645ca9d7bc74e920db5e376e262a3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 00:06:01 +0800 Subject: [PATCH 12/72] fix: fix --- .../__snapshots__/demo-extend.test.ts.snap | 4 +- .../__tests__/__snapshots__/demo.test.ts.snap | 4 +- .../__snapshots__/index.test.tsx.snap | 10 +--- components/chat-box/index.tsx | 53 +++++-------------- components/chat-box/style/index.ts | 16 +++--- components/chat-box/useTyped.ts | 41 ++++++++++++++ 6 files changed, 68 insertions(+), 60 deletions(-) create mode 100644 components/chat-box/useTyped.ts diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index 291edc8e3e95..c5d474abea0f 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -38,7 +38,7 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`]
- 你好你好你好 + 晚上好,你吃过了吗?
- 你好你好你好 + 晚上好,你吃过了吗?
diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index 0192c8359a49..19ebade74584 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -38,7 +38,7 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = `
- 你好你好你好 + 晚上好,你吃过了吗?
- 你好你好你好 + 晚上好,你吃过了吗?
diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap index cf60bfedf55e..55a841c90c13 100644 --- a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -1,11 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = ` -
-
-
-`; +exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = `null`; diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index e78108ad764f..46a7cb38fe0d 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -4,8 +4,9 @@ import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; import useStyle from './style'; +import useTyped from './useTyped'; -interface StepOption { +export interface StepOption { step: number; interval: number; } @@ -24,7 +25,7 @@ export interface ChatBoxProps { placement?: 'start' | 'end'; loading?: React.ReactNode; step?: boolean | StepOption; - content?: string; + content: string; contentRender?: (content?: string) => React.ReactNode; } @@ -44,17 +45,6 @@ const ChatBox: React.FC = (props) => { const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const [typedContent, setTypedContent] = React.useState(''); - const [showCursor, setShowCursor] = React.useState(false); - - const timerRef = React.useRef>(); - - const clearTimer = () => { - if (timerRef.current) { - clearInterval(timerRef.current); - } - }; - const mergedStep = React.useMemo(() => { if (step && typeof step === 'object') { return { ...defaultStep, ...step }; @@ -65,28 +55,7 @@ const ChatBox: React.FC = (props) => { return false; }, [step]); - React.useEffect(() => { - if (!content) { - return; - } - if (mergedStep) { - setShowCursor(true); - let stepCount = 0; - const { step: totalStep, interval } = mergedStep; - timerRef.current = setInterval(() => { - stepCount += totalStep; - setTypedContent(content.slice(0, stepCount) ?? ''); - if (stepCount >= content.length) { - clearTimer(); - setShowCursor(false); - } - }, interval); - return () => { - clearTimer(); - setShowCursor(false); - }; - } - }, [content, mergedStep]); + const { typedContent, showCursor } = useTyped(content, mergedStep); const mergedCls = classNames( className, @@ -98,16 +67,20 @@ const ChatBox: React.FC = (props) => { { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); + const streamContent = ( + <> + {typedContent} + {showCursor && } + + ); + return wrapCSSVar(
{avatar &&
{avatar}
} - {typeof contentRender === 'function' ? ( + {contentRender ? ( contentRender(content) ) : ( -
- {mergedStep ? typedContent : content} - {showCursor && |} -
+
{mergedStep ? streamContent : content}
)}
, ); diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index 87d418c48753..e80fdb5b9388 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -3,7 +3,7 @@ import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; -const cursorBlink = new Keyframes('CursorBlink', { +const cursorBlink = new Keyframes('cursorBlink', { '0%': { opacity: 1, }, @@ -52,15 +52,17 @@ const genChatBoxStyle: GenerateStyle = (token) => { borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, '&-typedCursor': { - position: 'absolute', - right: 14, - bottom: 14, - fontSize: token.fontSizeLG, + display: 'inline-block', + width: 4, + height: '1em', + backgroundColor: token.colorText, + // borderRadius: token.borderRadiusXS, + transform: 'translate3d(0, 1px, 0)', + marginInlineStart: token.marginXXS, userSelect: 'none', opacity: 1, - fontWeight: 900, animationName: cursorBlink, - animationDuration: '0.7s', + animationDuration: '0.6s', animationIterationCount: 'infinite', }, }, diff --git a/components/chat-box/useTyped.ts b/components/chat-box/useTyped.ts new file mode 100644 index 000000000000..a83adc294ca2 --- /dev/null +++ b/components/chat-box/useTyped.ts @@ -0,0 +1,41 @@ +import React from 'react'; + +import type { StepOption } from '.'; + +const useTyped = (content: string, mergedStep: StepOption | false) => { + const [typedContent, setTypedContent] = React.useState(''); + const [showCursor, setShowCursor] = React.useState(false); + + const timerRef = React.useRef>(); + + const clearTimer = () => { + if (timerRef.current) { + clearInterval(timerRef.current); + } + }; + + React.useEffect(() => { + if (!content || !mergedStep) { + return; + } + setShowCursor(true); + let stepCount = 0; + const { step: totalStep, interval } = mergedStep; + timerRef.current = setInterval(() => { + stepCount += totalStep; + setTypedContent(content.slice(0, stepCount) ?? ''); + if (stepCount >= content.length) { + clearTimer(); + setShowCursor(false); + } + }, interval); + return () => { + clearTimer(); + setShowCursor(false); + }; + }, [content, mergedStep]); + + return { typedContent, showCursor } as const; +}; + +export default useTyped; From 6badfde33662742b53c7a8b6c6003f35a4601572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 00:10:45 +0800 Subject: [PATCH 13/72] fix: fix --- components/chat-box/index.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 46a7cb38fe0d..9b9bab563da0 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -57,6 +57,16 @@ const ChatBox: React.FC = (props) => { const { typedContent, showCursor } = useTyped(content, mergedStep); + const streamContent = React.useMemo( + () => ( + <> + {typedContent} + {showCursor && } + + ), + [typedContent, showCursor], + ); + const mergedCls = classNames( className, rootClassName, @@ -67,13 +77,6 @@ const ChatBox: React.FC = (props) => { { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); - const streamContent = ( - <> - {typedContent} - {showCursor && } - - ); - return wrapCSSVar(
{avatar &&
{avatar}
} From 4f9fd721f7c530b02d069a8661c21babe9cf37dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 00:14:48 +0800 Subject: [PATCH 14/72] fix: fix --- components/chat-box/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 9b9bab563da0..c5c6a856d783 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -83,7 +83,9 @@ const ChatBox: React.FC = (props) => { {contentRender ? ( contentRender(content) ) : ( -
{mergedStep ? streamContent : content}
+
+ {mergedStep !== false ? streamContent : content} +
)}
, ); From ae22830a9da1ef9334cacbc41ddcc65cb2ecf4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 21:27:21 +0800 Subject: [PATCH 15/72] fix: fix style --- components/chat-box/hooks/useMergedStep.ts | 23 +++++++++++++++++++++ components/chat-box/{ => hooks}/useTyped.ts | 2 +- components/chat-box/index.tsx | 18 +++------------- components/chat-box/style/index.ts | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 components/chat-box/hooks/useMergedStep.ts rename components/chat-box/{ => hooks}/useTyped.ts (96%) diff --git a/components/chat-box/hooks/useMergedStep.ts b/components/chat-box/hooks/useMergedStep.ts new file mode 100644 index 000000000000..2b7857ec94eb --- /dev/null +++ b/components/chat-box/hooks/useMergedStep.ts @@ -0,0 +1,23 @@ +import React from 'react'; + +import type { ChatBoxProps, StepOption } from '..'; + +const defaultOption: StepOption = { + step: 1, + interval: 100, +}; + +const useMergedStep = (step: ChatBoxProps['step']) => { + const mergedStep = React.useMemo(() => { + if (step && typeof step === 'object') { + return { ...defaultOption, ...step }; + } + if (step === true) { + return defaultOption; + } + return false; + }, [step]); + return mergedStep; +}; + +export default useMergedStep; diff --git a/components/chat-box/useTyped.ts b/components/chat-box/hooks/useTyped.ts similarity index 96% rename from components/chat-box/useTyped.ts rename to components/chat-box/hooks/useTyped.ts index a83adc294ca2..dbfc489d27ba 100644 --- a/components/chat-box/useTyped.ts +++ b/components/chat-box/hooks/useTyped.ts @@ -1,6 +1,6 @@ import React from 'react'; -import type { StepOption } from '.'; +import type { StepOption } from '..'; const useTyped = (content: string, mergedStep: StepOption | false) => { const [typedContent, setTypedContent] = React.useState(''); diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index c5c6a856d783..8f874794e07a 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -3,19 +3,15 @@ import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; +import useMergedStep from './hooks/useMergedStep'; +import useTyped from './hooks/useTyped'; import useStyle from './style'; -import useTyped from './useTyped'; export interface StepOption { step: number; interval: number; } -const defaultStep: StepOption = { - step: 1, - interval: 100, -}; - export interface ChatBoxProps { prefixCls?: string; className?: string; @@ -45,15 +41,7 @@ const ChatBox: React.FC = (props) => { const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const mergedStep = React.useMemo(() => { - if (step && typeof step === 'object') { - return { ...defaultStep, ...step }; - } - if (step === true) { - return defaultStep; - } - return false; - }, [step]); + const mergedStep = useMergedStep(step); const { typedContent, showCursor } = useTyped(content, mergedStep); diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index e80fdb5b9388..733b2de89234 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -53,7 +53,7 @@ const genChatBoxStyle: GenerateStyle = (token) => { boxShadow: token.boxShadowTertiary, '&-typedCursor': { display: 'inline-block', - width: 4, + width: token.lineWidthFocus, height: '1em', backgroundColor: token.colorText, // borderRadius: token.borderRadiusXS, From d2ea73d23eb05fccc1b8a04632a6b3b4703b323d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 21:57:42 +0800 Subject: [PATCH 16/72] fix: fix test case --- components/chat-box/hooks/useMergedStep.ts | 3 +++ components/chat-box/hooks/useTyped.ts | 2 +- components/chat-box/index.tsx | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/chat-box/hooks/useMergedStep.ts b/components/chat-box/hooks/useMergedStep.ts index 2b7857ec94eb..882329a63e97 100644 --- a/components/chat-box/hooks/useMergedStep.ts +++ b/components/chat-box/hooks/useMergedStep.ts @@ -15,6 +15,9 @@ const useMergedStep = (step: ChatBoxProps['step']) => { if (step === true) { return defaultOption; } + if (step === false) { + return false; + } return false; }, [step]); return mergedStep; diff --git a/components/chat-box/hooks/useTyped.ts b/components/chat-box/hooks/useTyped.ts index dbfc489d27ba..1a29ca381332 100644 --- a/components/chat-box/hooks/useTyped.ts +++ b/components/chat-box/hooks/useTyped.ts @@ -2,7 +2,7 @@ import React from 'react'; import type { StepOption } from '..'; -const useTyped = (content: string, mergedStep: StepOption | false) => { +const useTyped = (content?: string, mergedStep?: StepOption | false) => { const [typedContent, setTypedContent] = React.useState(''); const [showCursor, setShowCursor] = React.useState(false); diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 8f874794e07a..00cbdc31a510 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -21,7 +21,7 @@ export interface ChatBoxProps { placement?: 'start' | 'end'; loading?: React.ReactNode; step?: boolean | StepOption; - content: string; + content?: string; contentRender?: (content?: string) => React.ReactNode; } From 2d411453fa6bd3ad7ea27b1afc007cbddfad5489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 22:04:47 +0800 Subject: [PATCH 17/72] chore: rename --- components/chat-box/hooks/useMergedStep.ts | 9 +++------ components/chat-box/hooks/useTyped.ts | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/chat-box/hooks/useMergedStep.ts b/components/chat-box/hooks/useMergedStep.ts index 882329a63e97..e17bf80b6931 100644 --- a/components/chat-box/hooks/useMergedStep.ts +++ b/components/chat-box/hooks/useMergedStep.ts @@ -2,7 +2,7 @@ import React from 'react'; import type { ChatBoxProps, StepOption } from '..'; -const defaultOption: StepOption = { +const defaultStepOptions: StepOption = { step: 1, interval: 100, }; @@ -10,13 +10,10 @@ const defaultOption: StepOption = { const useMergedStep = (step: ChatBoxProps['step']) => { const mergedStep = React.useMemo(() => { if (step && typeof step === 'object') { - return { ...defaultOption, ...step }; + return { ...defaultStepOptions, ...step }; } if (step === true) { - return defaultOption; - } - if (step === false) { - return false; + return defaultStepOptions; } return false; }, [step]); diff --git a/components/chat-box/hooks/useTyped.ts b/components/chat-box/hooks/useTyped.ts index 1a29ca381332..9829e186174a 100644 --- a/components/chat-box/hooks/useTyped.ts +++ b/components/chat-box/hooks/useTyped.ts @@ -20,9 +20,9 @@ const useTyped = (content?: string, mergedStep?: StepOption | false) => { } setShowCursor(true); let stepCount = 0; - const { step: totalStep, interval } = mergedStep; + const { step, interval } = mergedStep; timerRef.current = setInterval(() => { - stepCount += totalStep; + stepCount += step; setTypedContent(content.slice(0, stepCount) ?? ''); if (stepCount >= content.length) { clearTimer(); From 36e6aa8035175e6e7a7297252be717513a488e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 22:25:00 +0800 Subject: [PATCH 18/72] demo: update demo --- .../__snapshots__/demo-extend.test.ts.snap | 18 ++++++++++++++++- .../__tests__/__snapshots__/demo.test.ts.snap | 16 ++++++++++++++- .../__snapshots__/index.test.tsx.snap | 10 +++++++++- .../chat-box/demo/avatar-and-placement.md | 7 +++++++ .../chat-box/demo/avatar-and-placement.tsx | 20 +++++++++++++++++++ components/chat-box/demo/basic.tsx | 18 ++--------------- components/chat-box/index.en-US.md | 1 + components/chat-box/index.tsx | 8 ++++++++ components/chat-box/index.zh-CN.md | 3 ++- 9 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 components/chat-box/demo/avatar-and-placement.md create mode 100644 components/chat-box/demo/avatar-and-placement.tsx diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index c5d474abea0f..d8e89e240584 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = ` +exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend context correctly 1`] = `
@@ -18,6 +18,7 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] aria-label="user" class="anticon anticon-user" role="img" + style="background-color: rgb(253, 227, 207);" >
+
+ hello world ! +
+
+`; + exports[`renders components/chat-box/demo/basic.tsx extend context correctly 2`] = `[]`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index 19ebade74584..4a712d9d6102 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` +exports[`renders components/chat-box/demo/avatar-and-placement.tsx correctly 1`] = `
@@ -18,6 +18,7 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` aria-label="user" class="anticon anticon-user" role="img" + style="background-color:#fde3cf" >
`; + +exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` +
+
+ hello world ! +
+
+`; diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap index 55a841c90c13..cf60bfedf55e 100644 --- a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -1,3 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = `null`; +exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = ` +
+
+
+`; diff --git a/components/chat-box/demo/avatar-and-placement.md b/components/chat-box/demo/avatar-and-placement.md new file mode 100644 index 000000000000..5ef31f33868a --- /dev/null +++ b/components/chat-box/demo/avatar-and-placement.md @@ -0,0 +1,7 @@ +## zh-CN + +通过 `avatar` 设置自定义头像,通过 `placement` 设置消息的位置,提供了 `start` 和 `end` 两个选项。 + +## en-US + +Set custom avatar by `avatar` prop, set the placement of the message by `placement` prop, which has two preset values: `start` and `end`. diff --git a/components/chat-box/demo/avatar-and-placement.tsx b/components/chat-box/demo/avatar-and-placement.tsx new file mode 100644 index 000000000000..b9be79b90f36 --- /dev/null +++ b/components/chat-box/demo/avatar-and-placement.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { UserOutlined } from '@ant-design/icons'; +import { Avatar, ChatBox, Flex } from 'antd'; + +const App: React.FC = () => ( + + } />} + /> + } />} + /> + +); + +export default App; diff --git a/components/chat-box/demo/basic.tsx b/components/chat-box/demo/basic.tsx index 7ae73c64702e..d7a048e0ddb9 100644 --- a/components/chat-box/demo/basic.tsx +++ b/components/chat-box/demo/basic.tsx @@ -1,20 +1,6 @@ import React from 'react'; -import { UserOutlined } from '@ant-design/icons'; -import { Avatar, ChatBox, Flex } from 'antd'; +import { ChatBox } from 'antd'; -const App: React.FC = () => ( - - } />} - /> - } />} - /> - -); +const App: React.FC = () => ; export default App; diff --git a/components/chat-box/index.en-US.md b/components/chat-box/index.en-US.md index 4f90bc5bdd08..ffa019db7414 100644 --- a/components/chat-box/index.en-US.md +++ b/components/chat-box/index.en-US.md @@ -18,6 +18,7 @@ Often used when chatting. Basic +placement and avatar ## API diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 00cbdc31a510..cee753f26fb6 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -8,7 +8,15 @@ import useTyped from './hooks/useTyped'; import useStyle from './style'; export interface StepOption { + /** + * @since 5.17.0 + * @default 1 + */ step: number; + /** + * @since 5.17.0 + * @default 100 + */ interval: number; } diff --git a/components/chat-box/index.zh-CN.md b/components/chat-box/index.zh-CN.md index b78c72968135..49a1560c2c0b 100644 --- a/components/chat-box/index.zh-CN.md +++ b/components/chat-box/index.zh-CN.md @@ -18,7 +18,8 @@ tag: 5.17.0 ## 代码演示 -基本 +基本用法 +支持位置和头像 ## API From 3b4d993147011398e46192c6a302ef3797cd6f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 22:43:25 +0800 Subject: [PATCH 19/72] fix: fix --- .../__snapshots__/demo-extend.test.ts.snap | 6 ++---- .../__tests__/__snapshots__/demo.test.ts.snap | 6 ++---- components/chat-box/demo/avatar-and-placement.tsx | 14 ++++++++++++-- components/chat-box/hooks/useMergedStep.ts | 6 +++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index d8e89e240584..81cfb1a507a8 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -12,13 +12,12 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend contex > } - - ), - [typedContent, showCursor], - ); - const mergedCls = classNames( className, rootClassName, @@ -79,8 +69,12 @@ const ChatBox: React.FC = (props) => { {contentRender ? ( contentRender(content) ) : ( -
- {mergedStep !== false ? streamContent : content} +
+ {mergedStep !== false ? typedContent : content}
)}
, diff --git a/components/chat-box/index.zh-CN.md b/components/chat-box/index.zh-CN.md index 49a1560c2c0b..89f5f8d3fc58 100644 --- a/components/chat-box/index.zh-CN.md +++ b/components/chat-box/index.zh-CN.md @@ -18,7 +18,7 @@ tag: 5.17.0 ## 代码演示 -基本用法 +基本 支持位置和头像 ## API diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index 733b2de89234..b1f3aca9b289 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -51,13 +51,20 @@ const genChatBoxStyle: GenerateStyle = (token) => { backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, - '&-typedCursor': { + [`&${componentCls}-start`]: { + borderRadius: `${token.borderRadiusLG} 0 0 ${token.borderRadiusLG}`, + }, + [`&${componentCls}-end`]: { + borderRadius: `0 ${token.borderRadiusLG} ${token.borderRadiusLG} 0`, + }, + [`&${componentCls}-rtl`]: { + borderRadius: `${token.borderRadiusLG} 0 0 ${token.borderRadiusLG}`, + }, + '&-cursorBlink::after': { display: 'inline-block', - width: token.lineWidthFocus, - height: '1em', - backgroundColor: token.colorText, - // borderRadius: token.borderRadiusXS, - transform: 'translate3d(0, 1px, 0)', + content: '"|"', + fontWeight: 900, + transform: 'translate3d(0, -1px, 0)', marginInlineStart: token.marginXXS, userSelect: 'none', opacity: 1, From 2249400f7efa345948860d2e3412b853a823372b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sat, 13 Apr 2024 23:11:00 +0800 Subject: [PATCH 21/72] fix: fix --- components/chat-box/style/index.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/components/chat-box/style/index.ts b/components/chat-box/style/index.ts index b1f3aca9b289..93a5640d55a6 100644 --- a/components/chat-box/style/index.ts +++ b/components/chat-box/style/index.ts @@ -32,8 +32,8 @@ const genChatBoxStyle: GenerateStyle = (token) => { gap: avatarGap, maxWidth: '100%', [`&${componentCls}-end`]: { - flexDirection: 'row-reverse', justifyContent: 'end', + flexDirection: 'row-reverse', }, [`&${componentCls}-rtl`]: { direction: 'rtl', @@ -51,15 +51,6 @@ const genChatBoxStyle: GenerateStyle = (token) => { backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, - [`&${componentCls}-start`]: { - borderRadius: `${token.borderRadiusLG} 0 0 ${token.borderRadiusLG}`, - }, - [`&${componentCls}-end`]: { - borderRadius: `0 ${token.borderRadiusLG} ${token.borderRadiusLG} 0`, - }, - [`&${componentCls}-rtl`]: { - borderRadius: `${token.borderRadiusLG} 0 0 ${token.borderRadiusLG}`, - }, '&-cursorBlink::after': { display: 'inline-block', content: '"|"', From ee1eaf3d8ef4bab9e798d02414d0ae60268ecdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 14 Apr 2024 00:49:17 +0800 Subject: [PATCH 22/72] fix: fix --- .../__snapshots__/demo-extend.test.ts.snap | 56 ++++++++++++++++++- .../__tests__/__snapshots__/demo.test.ts.snap | 54 +++++++++++++++++- .../chat-box/demo/avatar-and-placement.md | 2 +- components/chat-box/demo/stream-output.md | 7 +++ components/chat-box/demo/stream-output.tsx | 22 ++++++++ components/chat-box/index.en-US.md | 1 + components/chat-box/index.zh-CN.md | 1 + 7 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 components/chat-box/demo/stream-output.md create mode 100644 components/chat-box/demo/stream-output.tsx diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index 81cfb1a507a8..f681afdf8456 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -12,7 +12,7 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend contex > +
+
+ + + + + +
+ + +
+`; + +exports[`renders components/chat-box/demo/stream-output.tsx extend context correctly 2`] = `[]`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index c70837d89a9e..8e6a6c4f24bd 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -12,7 +12,7 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx correctly 1`] >
`; + +exports[`renders components/chat-box/demo/stream-output.tsx correctly 1`] = ` +
+
+
+ + + + + +
+
+
+ +
+`; diff --git a/components/chat-box/demo/avatar-and-placement.md b/components/chat-box/demo/avatar-and-placement.md index 5ef31f33868a..6928e1e1c2b8 100644 --- a/components/chat-box/demo/avatar-and-placement.md +++ b/components/chat-box/demo/avatar-and-placement.md @@ -1,6 +1,6 @@ ## zh-CN -通过 `avatar` 设置自定义头像,通过 `placement` 设置消息的位置,提供了 `start` 和 `end` 两个选项。 +通过 `avatar` 设置自定义头像,通过 `placement` 设置位置,提供了 `start`、`end` 两个选项。 ## en-US diff --git a/components/chat-box/demo/stream-output.md b/components/chat-box/demo/stream-output.md new file mode 100644 index 000000000000..27e52a5e6a9f --- /dev/null +++ b/components/chat-box/demo/stream-output.md @@ -0,0 +1,7 @@ +## zh-CN + +通过设置 `step` 属性,启用流式输出。 + +## en-US + +Enable streaming output by setting the `step` prop. diff --git a/components/chat-box/demo/stream-output.tsx b/components/chat-box/demo/stream-output.tsx new file mode 100644 index 000000000000..8f40f4f7446f --- /dev/null +++ b/components/chat-box/demo/stream-output.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { UserOutlined } from '@ant-design/icons'; +import { Avatar, Button, ChatBox, Flex } from 'antd'; + +const App: React.FC = () => { + const [, forceRender] = React.useReducer((x) => x + 1, 0); + return ( + + } />} + /> + + + ); +}; + +export default App; diff --git a/components/chat-box/index.en-US.md b/components/chat-box/index.en-US.md index ffa019db7414..8296d430b730 100644 --- a/components/chat-box/index.en-US.md +++ b/components/chat-box/index.en-US.md @@ -19,6 +19,7 @@ Often used when chatting. Basic placement and avatar +stream output ## API diff --git a/components/chat-box/index.zh-CN.md b/components/chat-box/index.zh-CN.md index 89f5f8d3fc58..658b93db7d7d 100644 --- a/components/chat-box/index.zh-CN.md +++ b/components/chat-box/index.zh-CN.md @@ -20,6 +20,7 @@ tag: 5.17.0 基本 支持位置和头像 +流式输出 ## API From 84e2bce2c880cc05695bb0bf5fb2dab2884b3e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 14 Apr 2024 23:33:42 +0800 Subject: [PATCH 23/72] fix: update demo --- .../__snapshots__/demo-extend.test.ts.snap | 107 ++++++++++++------ .../__tests__/__snapshots__/demo.test.ts.snap | 105 +++++++++++------ components/chat-box/demo/contentRender.md | 7 ++ components/chat-box/demo/contentRender.tsx | 32 ++++++ components/chat-box/demo/stream-output.tsx | 32 +++--- components/chat-box/hooks/useMergedStep.ts | 4 +- components/chat-box/hooks/useTyped.ts | 4 +- components/chat-box/index.en-US.md | 3 +- components/chat-box/index.tsx | 4 +- components/chat-box/index.zh-CN.md | 3 +- package.json | 4 +- 11 files changed, 213 insertions(+), 92 deletions(-) create mode 100644 components/chat-box/demo/contentRender.md create mode 100644 components/chat-box/demo/contentRender.tsx diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index f681afdf8456..fc98e59e5a50 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -97,53 +97,90 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] exports[`renders components/chat-box/demo/basic.tsx extend context correctly 2`] = `[]`; -exports[`renders components/chat-box/demo/stream-output.tsx extend context correctly 1`] = ` +exports[`renders components/chat-box/demo/contentRender.tsx extend context correctly 1`] = `
-
- + + -
- -
+
+`; + +exports[`renders components/chat-box/demo/contentRender.tsx extend context correctly 2`] = `[]`; + +exports[`renders components/chat-box/demo/stream-output.tsx extend context correctly 1`] = ` +
+
+ + + + - +
+ `; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index 8e6a6c4f24bd..f478163eb93b 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -93,52 +93,87 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = `
`; -exports[`renders components/chat-box/demo/stream-output.tsx correctly 1`] = ` +exports[`renders components/chat-box/demo/contentRender.tsx correctly 1`] = `
-
- + + -
-
+
-
+
+`; + +exports[`renders components/chat-box/demo/stream-output.tsx correctly 1`] = ` +
+
+ + + + - +
+
`; diff --git a/components/chat-box/demo/contentRender.md b/components/chat-box/demo/contentRender.md new file mode 100644 index 000000000000..a985e8857d5a --- /dev/null +++ b/components/chat-box/demo/contentRender.md @@ -0,0 +1,7 @@ +## zh-CN + +配合 `markdown-it` 实现自定义渲染内容。 + +## en-US + +Cooperate with `markdown-it` to achieve customized rendering content. diff --git a/components/chat-box/demo/contentRender.tsx b/components/chat-box/demo/contentRender.tsx new file mode 100644 index 000000000000..c0c3660cf4d8 --- /dev/null +++ b/components/chat-box/demo/contentRender.tsx @@ -0,0 +1,32 @@ +/* eslint-disable react/no-danger */ +import React from 'react'; +import { UserOutlined } from '@ant-design/icons'; +import { Avatar, ChatBox } from 'antd'; +import markdownit from 'markdown-it'; + +const style: React.CSSProperties = { + maxWidth: '100%', + padding: '12px 16px', + backgroundColor: '#f0f2f5', + border: '1px solid #d9d9d9', +}; + +const md = markdownit({ html: true, breaks: true, typographer: true }); + +const App: React.FC = () => { + const contentRender = React.useCallback((content?: string) => { + if (!content) { + return null; + } + return
; + }, []); + return ( + } />} + content={'# Title \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n ...'} + contentRender={contentRender} + /> + ); +}; + +export default App; diff --git a/components/chat-box/demo/stream-output.tsx b/components/chat-box/demo/stream-output.tsx index 8f40f4f7446f..db583c11a13a 100644 --- a/components/chat-box/demo/stream-output.tsx +++ b/components/chat-box/demo/stream-output.tsx @@ -1,21 +1,27 @@ import React from 'react'; import { UserOutlined } from '@ant-design/icons'; -import { Avatar, Button, ChatBox, Flex } from 'antd'; +import { Avatar, ChatBox } from 'antd'; + +const sentences = ['Feel free to use Ant Design !', '欢迎使用 Ant Design!']; + +const useLoopSentence = () => { + const [index, setIndex] = React.useState(0); + React.useEffect(() => { + setTimeout(() => { + setIndex((prevState) => (prevState ? 0 : 1)); + }, 4000); + }, [index]); + return sentences[index]; +}; const App: React.FC = () => { - const [, forceRender] = React.useReducer((x) => x + 1, 0); + const content = useLoopSentence(); return ( - - } />} - /> - - + } />} + /> ); }; diff --git a/components/chat-box/hooks/useMergedStep.ts b/components/chat-box/hooks/useMergedStep.ts index 97d7ab88f396..cbdb09881a5c 100644 --- a/components/chat-box/hooks/useMergedStep.ts +++ b/components/chat-box/hooks/useMergedStep.ts @@ -2,13 +2,13 @@ import React from 'react'; import type { ChatBoxProps, StepOption } from '..'; -const defaultStepOption: StepOption = { +const defaultStepOption: Required = { step: 1, interval: 100, }; const useMergedStep = (step: ChatBoxProps['step']) => { - const mergedStep = React.useMemo(() => { + const mergedStep = React.useMemo | false>(() => { if (step && typeof step === 'object') { return { ...defaultStepOption, ...step }; } diff --git a/components/chat-box/hooks/useTyped.ts b/components/chat-box/hooks/useTyped.ts index 9829e186174a..06f9b4fd98d9 100644 --- a/components/chat-box/hooks/useTyped.ts +++ b/components/chat-box/hooks/useTyped.ts @@ -2,7 +2,7 @@ import React from 'react'; import type { StepOption } from '..'; -const useTyped = (content?: string, mergedStep?: StepOption | false) => { +const useTyped = (content?: string, mergedStep?: Required | false) => { const [typedContent, setTypedContent] = React.useState(''); const [showCursor, setShowCursor] = React.useState(false); @@ -35,7 +35,7 @@ const useTyped = (content?: string, mergedStep?: StepOption | false) => { }; }, [content, mergedStep]); - return { typedContent, showCursor } as const; + return { typedContent, showCursor }; }; export default useTyped; diff --git a/components/chat-box/index.en-US.md b/components/chat-box/index.en-US.md index 8296d430b730..44db18a406bc 100644 --- a/components/chat-box/index.en-US.md +++ b/components/chat-box/index.en-US.md @@ -20,6 +20,7 @@ Often used when chatting. Basic placement and avatar stream output +content render ## API @@ -36,7 +37,7 @@ Common props ref:[Common props](/docs/react/common-props) | loading | Loading state of Message | `React.ReactNode` | - | | | step | Show message with stepping motion | `boolean \| { step?: number, interval?: number }` | `false` | | | content | Content of ChatBox | `string` | - | | -| contentRender | Display cuztomized content | `(content?: string) => ReactNode` | - | | +| contentRender | Display cuztomized content (If use `contentRender` prop, the typed effect needs to be implemented by yourself) | `(content?: string) => ReactNode` | - | | ## Design Token diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index 7a6dbbef5b58..a48effad6d5e 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -12,12 +12,12 @@ export interface StepOption { * @since 5.17.0 * @default 1 */ - step: number; + step?: number; /** * @since 5.17.0 * @default 100 */ - interval: number; + interval?: number; } export interface ChatBoxProps { diff --git a/components/chat-box/index.zh-CN.md b/components/chat-box/index.zh-CN.md index 658b93db7d7d..30d80ee5975e 100644 --- a/components/chat-box/index.zh-CN.md +++ b/components/chat-box/index.zh-CN.md @@ -21,6 +21,7 @@ tag: 5.17.0 基本 支持位置和头像 流式输出 +自定义渲染 ## API @@ -37,7 +38,7 @@ tag: 5.17.0 | loading | 聊天内容加载状态 | `React.ReactNode` | - | | | step | 聊天内容动画 | `boolean \| { step?: number, interval?: number }` | `false` | | | content | 聊天内容 | `string` | - | | -| contentRender | 自定义渲染内容 | `(content?: string) => ReactNode` | - | | +| contentRender | 自定义渲染内容(使用 `contentRender` 的话,打字效果需要自行实现) | `(content?: string) => ReactNode` | - | | ## 主题变量(Design Token) diff --git a/package.json b/package.json index 8140be3a4fe7..289117341ffa 100644 --- a/package.json +++ b/package.json @@ -205,6 +205,7 @@ "@types/jquery": "^3.5.29", "@types/jsdom": "^21.1.6", "@types/lodash": "^4.17.0", + "@types/markdown-it": "^14.0.1", "@types/minimist": "^1.2.5", "@types/node": "^20.12.6", "@types/nprogress": "^0.2.3", @@ -283,6 +284,7 @@ "lodash": "^4.17.21", "lunar-typescript": "^1.7.5", "lz-string": "^1.5.0", + "markdown-it": "^14.1.0", "minimist": "^1.2.8", "mockdate": "^3.0.5", "node-fetch": "^3.3.2", @@ -369,4 +371,4 @@ "tnpm": { "mode": "npm" } -} \ No newline at end of file +} From edc5a03a05f81feb0f5edd63f5fb94c925adf2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 11:27:09 +0800 Subject: [PATCH 24/72] test: add test case --- .../__snapshots__/demo-extend.test.ts.snap | 26 +++++++++---------- .../__tests__/__snapshots__/demo.test.ts.snap | 26 +++++++++---------- .../__snapshots__/index.test.tsx.snap | 20 +++++++++++--- components/chat-box/__tests__/index.test.tsx | 13 ++++++++-- components/chat-box/index.tsx | 4 +-- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index fc98e59e5a50..163ae2e88c10 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -5,10 +5,10 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend contex class="ant-flex ant-flex-align-stretch ant-flex-gap-middle ant-flex-vertical" >
晚上好,你吃过了吗?
晚上好,你吃过了吗?
@@ -85,10 +85,10 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend contex exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = `
hello world !
@@ -99,10 +99,10 @@ exports[`renders components/chat-box/demo/basic.tsx extend context correctly 2`] exports[`renders components/chat-box/demo/contentRender.tsx extend context correctly 1`] = `
`; diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap index f478163eb93b..5a1036c77599 100644 --- a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap @@ -5,10 +5,10 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx correctly 1`] class="ant-flex ant-flex-align-stretch ant-flex-gap-middle ant-flex-vertical" >
晚上好,你吃过了吗?
晚上好,你吃过了吗?
@@ -83,10 +83,10 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx correctly 1`] exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = `
hello world !
@@ -95,10 +95,10 @@ exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` exports[`renders components/chat-box/demo/contentRender.tsx correctly 1`] = `
`; diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap index cf60bfedf55e..3918f16aa5aa 100644 --- a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap @@ -1,11 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`chat-box ChatBox component work 1`] = ` +
+
+ test +
+
+`; + exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = `
+ class="ant-chat-box-content" + > + test +
`; diff --git a/components/chat-box/__tests__/index.test.tsx b/components/chat-box/__tests__/index.test.tsx index a48247d11c0b..329dffb1edb3 100644 --- a/components/chat-box/__tests__/index.test.tsx +++ b/components/chat-box/__tests__/index.test.tsx @@ -1,8 +1,17 @@ +import React from 'react'; + import ChatBox from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; +import { render } from '../../../tests/utils'; describe('chat-box', () => { - mountTest(ChatBox); - rtlTest(ChatBox); + mountTest(() => ); + rtlTest(() => ); + it('ChatBox component work', () => { + const { container } = render(); + const element = container.querySelector('.ant-chat-box'); + expect(element).toBeTruthy(); + expect(element).toMatchSnapshot(); + }); }); diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index a48effad6d5e..dac491106126 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -29,7 +29,7 @@ export interface ChatBoxProps { placement?: 'start' | 'end'; loading?: React.ReactNode; step?: boolean | StepOption; - content?: string; + content: string; contentRender?: (content?: string) => React.ReactNode; } @@ -46,7 +46,7 @@ const ChatBox: React.FC = (props) => { contentRender, } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); - const prefixCls = getPrefixCls('chatbox', customizePrefixCls); + const prefixCls = getPrefixCls('chat-box', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); const mergedStep = useMergedStep(step); From 7af6008f81a01d656dbbc1adcf31f8c466ae55b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 14:29:06 +0800 Subject: [PATCH 25/72] demo: update demo --- .../__snapshots__/demo-extend.test.ts.snap | 92 +++++++++++++++++++ .../__tests__/__snapshots__/demo.test.ts.snap | 90 ++++++++++++++++++ components/chat-box/demo/basic.tsx | 2 +- components/chat-box/demo/loading.md | 7 ++ components/chat-box/demo/loading.tsx | 22 +++++ components/chat-box/demo/stream-output.tsx | 4 +- components/chat-box/index.en-US.md | 9 +- components/chat-box/index.tsx | 18 ++-- components/chat-box/index.zh-CN.md | 3 +- 9 files changed, 232 insertions(+), 15 deletions(-) create mode 100644 components/chat-box/demo/loading.md create mode 100644 components/chat-box/demo/loading.tsx diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap index 163ae2e88c10..f70fdbe7781b 100644 --- a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -146,6 +146,98 @@ exports[`renders components/chat-box/demo/contentRender.tsx extend context corre exports[`renders components/chat-box/demo/contentRender.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chat-box/demo/loading.tsx extend context correctly 1`] = ` +
+
+
+ + + + + +
+
+
+ + + + + + +
+
+
+
+ Loading state: + +
+
+`; + +exports[`renders components/chat-box/demo/loading.tsx extend context correctly 2`] = `[]`; + exports[`renders components/chat-box/demo/stream-output.tsx extend context correctly 1`] = `
`; +exports[`renders components/chat-box/demo/loading.tsx correctly 1`] = ` +
+
+
+ + + + + +
+
+
+ + + + + + +
+
+
+
+ Loading state: + +
+
+`; + exports[`renders components/chat-box/demo/stream-output.tsx correctly 1`] = `
; +const App = () => ; export default App; diff --git a/components/chat-box/demo/loading.md b/components/chat-box/demo/loading.md new file mode 100644 index 000000000000..8f0c95770dff --- /dev/null +++ b/components/chat-box/demo/loading.md @@ -0,0 +1,7 @@ +## zh-CN + +通过 `loading` 属性控制加载状态。 + +## en-US + +Control the loading state by `loading` prop. diff --git a/components/chat-box/demo/loading.tsx b/components/chat-box/demo/loading.tsx new file mode 100644 index 000000000000..7111ad330906 --- /dev/null +++ b/components/chat-box/demo/loading.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { UserOutlined } from '@ant-design/icons'; +import { Avatar, ChatBox, Flex, Switch } from 'antd'; + +const App: React.FC = () => { + const [loading, setLoading] = React.useState(true); + return ( + + } />} + /> + + Loading state: + + + + ); +}; + +export default App; diff --git a/components/chat-box/demo/stream-output.tsx b/components/chat-box/demo/stream-output.tsx index db583c11a13a..381f06eb77f5 100644 --- a/components/chat-box/demo/stream-output.tsx +++ b/components/chat-box/demo/stream-output.tsx @@ -6,10 +6,12 @@ const sentences = ['Feel free to use Ant Design !', '欢迎使用 Ant Design!' const useLoopSentence = () => { const [index, setIndex] = React.useState(0); + const timer = React.useRef>(); React.useEffect(() => { - setTimeout(() => { + timer.current = setTimeout(() => { setIndex((prevState) => (prevState ? 0 : 1)); }, 4000); + return () => clearTimeout(timer.current); }, [index]); return sentences[index]; }; diff --git a/components/chat-box/index.en-US.md b/components/chat-box/index.en-US.md index 44db18a406bc..25bbf600786c 100644 --- a/components/chat-box/index.en-US.md +++ b/components/chat-box/index.en-US.md @@ -18,9 +18,10 @@ Often used when chatting. Basic -placement and avatar -stream output -content render +Placement and avatar +Stream output +Loading +Content render ## API @@ -34,7 +35,7 @@ Common props ref:[Common props](/docs/react/common-props) | --- | --- | --- | --- | --- | | avatar | Avatar component | `React.ReactNode` | - | | | placement | Direction of Message | `start \| end` | `start` | | -| loading | Loading state of Message | `React.ReactNode` | - | | +| loading | Loading state of Message | `boolean` | - | | | step | Show message with stepping motion | `boolean \| { step?: number, interval?: number }` | `false` | | | content | Content of ChatBox | `string` | - | | | contentRender | Display cuztomized content (If use `contentRender` prop, the typed effect needs to be implemented by yourself) | `(content?: string) => ReactNode` | - | | diff --git a/components/chat-box/index.tsx b/components/chat-box/index.tsx index dac491106126..75500099c9c6 100644 --- a/components/chat-box/index.tsx +++ b/components/chat-box/index.tsx @@ -3,6 +3,7 @@ import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; +import Spin from '../spin'; import useMergedStep from './hooks/useMergedStep'; import useTyped from './hooks/useTyped'; import useStyle from './style'; @@ -27,7 +28,7 @@ export interface ChatBoxProps { style?: React.CSSProperties; avatar?: React.ReactNode; placement?: 'start' | 'end'; - loading?: React.ReactNode; + loading?: boolean; step?: boolean | StepOption; content: string; contentRender?: (content?: string) => React.ReactNode; @@ -41,6 +42,7 @@ const ChatBox: React.FC = (props) => { style, avatar, placement = 'start', + loading = false, step, content, contentRender, @@ -63,19 +65,19 @@ const ChatBox: React.FC = (props) => { { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); + const mergedContentCls = classNames(`${prefixCls}-content`, { + [`${prefixCls}-content-cursorBlink`]: showCursor && !loading, + }); + + const contentNode = mergedStep !== false ? typedContent : content; + return wrapCSSVar(
{avatar &&
{avatar}
} {contentRender ? ( contentRender(content) ) : ( -
- {mergedStep !== false ? typedContent : content} -
+
{loading ? : contentNode}
)}
, ); diff --git a/components/chat-box/index.zh-CN.md b/components/chat-box/index.zh-CN.md index 30d80ee5975e..cee69fa28dc8 100644 --- a/components/chat-box/index.zh-CN.md +++ b/components/chat-box/index.zh-CN.md @@ -21,6 +21,7 @@ tag: 5.17.0 基本 支持位置和头像 流式输出 +加载中 自定义渲染 ## API @@ -35,7 +36,7 @@ tag: 5.17.0 | --- | --- | --- | --- | --- | | avatar | 展示头像 | `React.ReactNode` | - | | | placement | 信息位置 | `start \| end` | `start` | | -| loading | 聊天内容加载状态 | `React.ReactNode` | - | | +| loading | 聊天内容加载状态 | `boolean` | - | | | step | 聊天内容动画 | `boolean \| { step?: number, interval?: number }` | `false` | | | content | 聊天内容 | `string` | - | | | contentRender | 自定义渲染内容(使用 `contentRender` 的话,打字效果需要自行实现) | `(content?: string) => ReactNode` | - | | From a1a08f3b88b6c19df98a7a536fecf2c08d0dfe78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 15:37:32 +0800 Subject: [PATCH 26/72] test: add test case --- components/chat-box/__tests__/index.test.tsx | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/components/chat-box/__tests__/index.test.tsx b/components/chat-box/__tests__/index.test.tsx index 329dffb1edb3..4553d8bff1b8 100644 --- a/components/chat-box/__tests__/index.test.tsx +++ b/components/chat-box/__tests__/index.test.tsx @@ -14,4 +14,52 @@ describe('chat-box', () => { expect(element).toBeTruthy(); expect(element).toMatchSnapshot(); }); + + it('ChatBox support content', () => { + const { container } = render(); + const element = container.querySelector('.ant-chat-box .ant-chat-box-content'); + expect(element?.textContent).toBe('hello world'); + }); + + it('ChatBox support contentRender', () => { + const { container } = render( + {content}} + />, + ); + const element = container.querySelector('.ant-chat-box .test-contentRender'); + expect(element).toBeTruthy(); + expect(element?.textContent).toBe('test-contentRender'); + }); + + it('ChatBox support step', () => { + const { container } = render(); + const selectors = '.ant-chat-box .ant-chat-box-content'; + expect(container.querySelector(selectors)).toHaveClass( + 'ant-chat-box-content-cursorBlink', + ); + }); + + it('ChatBox support avatar', () => { + const { container } = render( + avatar} content="" />, + ); + expect(container.querySelector('.ant-chat-box .test-avatar')).toBeTruthy(); + }); + + it('ChatBox support loading', () => { + const { container } = render(); + expect( + container.querySelector('.ant-chat-box .ant-spin.ant-spin-spinning'), + ).toBeTruthy(); + }); + + it('ChatBox support placement', () => { + const { container, rerender } = render(); + const element = container.querySelector('.ant-chat-box'); + expect(element).toHaveClass('ant-chat-box-start'); + rerender(); + expect(element).toHaveClass('ant-chat-box-end'); + }); }); From 4aa79b546e44e1764099836ccb260b51993e1ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 18:41:32 +0800 Subject: [PATCH 27/72] chore: rename `chat-box` => `chatbox` --- .../__tests__/__snapshots__/demo-extend.test.ts.snap | 0 .../__tests__/__snapshots__/demo.test.ts.snap | 0 .../__tests__/__snapshots__/index.test.tsx.snap | 0 .../{chat-box => chatbox}/__tests__/demo-extend.test.ts | 0 components/{chat-box => chatbox}/__tests__/demo.test.ts | 0 components/{chat-box => chatbox}/__tests__/image.test.ts | 0 components/{chat-box => chatbox}/__tests__/index.test.tsx | 0 components/{chat-box => chatbox}/demo/avatar-and-placement.md | 0 .../{chat-box => chatbox}/demo/avatar-and-placement.tsx | 0 components/{chat-box => chatbox}/demo/basic.md | 0 components/{chat-box => chatbox}/demo/basic.tsx | 0 components/{chat-box => chatbox}/demo/contentRender.md | 0 components/{chat-box => chatbox}/demo/contentRender.tsx | 0 components/{chat-box => chatbox}/demo/loading.md | 0 components/{chat-box => chatbox}/demo/loading.tsx | 0 components/{chat-box => chatbox}/demo/stream-output.md | 0 components/{chat-box => chatbox}/demo/stream-output.tsx | 0 .../hooks/useMergedStep.ts => chatbox/hooks/useStep.ts} | 4 ++-- components/{chat-box => chatbox}/hooks/useTyped.ts | 0 components/{chat-box => chatbox}/index.en-US.md | 0 components/{chat-box => chatbox}/index.tsx | 4 ++-- components/{chat-box => chatbox}/index.zh-CN.md | 0 components/{chat-box => chatbox}/style/index.ts | 0 23 files changed, 4 insertions(+), 4 deletions(-) rename components/{chat-box => chatbox}/__tests__/__snapshots__/demo-extend.test.ts.snap (100%) rename components/{chat-box => chatbox}/__tests__/__snapshots__/demo.test.ts.snap (100%) rename components/{chat-box => chatbox}/__tests__/__snapshots__/index.test.tsx.snap (100%) rename components/{chat-box => chatbox}/__tests__/demo-extend.test.ts (100%) rename components/{chat-box => chatbox}/__tests__/demo.test.ts (100%) rename components/{chat-box => chatbox}/__tests__/image.test.ts (100%) rename components/{chat-box => chatbox}/__tests__/index.test.tsx (100%) rename components/{chat-box => chatbox}/demo/avatar-and-placement.md (100%) rename components/{chat-box => chatbox}/demo/avatar-and-placement.tsx (100%) rename components/{chat-box => chatbox}/demo/basic.md (100%) rename components/{chat-box => chatbox}/demo/basic.tsx (100%) rename components/{chat-box => chatbox}/demo/contentRender.md (100%) rename components/{chat-box => chatbox}/demo/contentRender.tsx (100%) rename components/{chat-box => chatbox}/demo/loading.md (100%) rename components/{chat-box => chatbox}/demo/loading.tsx (100%) rename components/{chat-box => chatbox}/demo/stream-output.md (100%) rename components/{chat-box => chatbox}/demo/stream-output.tsx (100%) rename components/{chat-box/hooks/useMergedStep.ts => chatbox/hooks/useStep.ts} (84%) rename components/{chat-box => chatbox}/hooks/useTyped.ts (100%) rename components/{chat-box => chatbox}/index.en-US.md (100%) rename components/{chat-box => chatbox}/index.tsx (95%) rename components/{chat-box => chatbox}/index.zh-CN.md (100%) rename components/{chat-box => chatbox}/style/index.ts (100%) diff --git a/components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap similarity index 100% rename from components/chat-box/__tests__/__snapshots__/demo-extend.test.ts.snap rename to components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap diff --git a/components/chat-box/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap similarity index 100% rename from components/chat-box/__tests__/__snapshots__/demo.test.ts.snap rename to components/chatbox/__tests__/__snapshots__/demo.test.ts.snap diff --git a/components/chat-box/__tests__/__snapshots__/index.test.tsx.snap b/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap similarity index 100% rename from components/chat-box/__tests__/__snapshots__/index.test.tsx.snap rename to components/chatbox/__tests__/__snapshots__/index.test.tsx.snap diff --git a/components/chat-box/__tests__/demo-extend.test.ts b/components/chatbox/__tests__/demo-extend.test.ts similarity index 100% rename from components/chat-box/__tests__/demo-extend.test.ts rename to components/chatbox/__tests__/demo-extend.test.ts diff --git a/components/chat-box/__tests__/demo.test.ts b/components/chatbox/__tests__/demo.test.ts similarity index 100% rename from components/chat-box/__tests__/demo.test.ts rename to components/chatbox/__tests__/demo.test.ts diff --git a/components/chat-box/__tests__/image.test.ts b/components/chatbox/__tests__/image.test.ts similarity index 100% rename from components/chat-box/__tests__/image.test.ts rename to components/chatbox/__tests__/image.test.ts diff --git a/components/chat-box/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx similarity index 100% rename from components/chat-box/__tests__/index.test.tsx rename to components/chatbox/__tests__/index.test.tsx diff --git a/components/chat-box/demo/avatar-and-placement.md b/components/chatbox/demo/avatar-and-placement.md similarity index 100% rename from components/chat-box/demo/avatar-and-placement.md rename to components/chatbox/demo/avatar-and-placement.md diff --git a/components/chat-box/demo/avatar-and-placement.tsx b/components/chatbox/demo/avatar-and-placement.tsx similarity index 100% rename from components/chat-box/demo/avatar-and-placement.tsx rename to components/chatbox/demo/avatar-and-placement.tsx diff --git a/components/chat-box/demo/basic.md b/components/chatbox/demo/basic.md similarity index 100% rename from components/chat-box/demo/basic.md rename to components/chatbox/demo/basic.md diff --git a/components/chat-box/demo/basic.tsx b/components/chatbox/demo/basic.tsx similarity index 100% rename from components/chat-box/demo/basic.tsx rename to components/chatbox/demo/basic.tsx diff --git a/components/chat-box/demo/contentRender.md b/components/chatbox/demo/contentRender.md similarity index 100% rename from components/chat-box/demo/contentRender.md rename to components/chatbox/demo/contentRender.md diff --git a/components/chat-box/demo/contentRender.tsx b/components/chatbox/demo/contentRender.tsx similarity index 100% rename from components/chat-box/demo/contentRender.tsx rename to components/chatbox/demo/contentRender.tsx diff --git a/components/chat-box/demo/loading.md b/components/chatbox/demo/loading.md similarity index 100% rename from components/chat-box/demo/loading.md rename to components/chatbox/demo/loading.md diff --git a/components/chat-box/demo/loading.tsx b/components/chatbox/demo/loading.tsx similarity index 100% rename from components/chat-box/demo/loading.tsx rename to components/chatbox/demo/loading.tsx diff --git a/components/chat-box/demo/stream-output.md b/components/chatbox/demo/stream-output.md similarity index 100% rename from components/chat-box/demo/stream-output.md rename to components/chatbox/demo/stream-output.md diff --git a/components/chat-box/demo/stream-output.tsx b/components/chatbox/demo/stream-output.tsx similarity index 100% rename from components/chat-box/demo/stream-output.tsx rename to components/chatbox/demo/stream-output.tsx diff --git a/components/chat-box/hooks/useMergedStep.ts b/components/chatbox/hooks/useStep.ts similarity index 84% rename from components/chat-box/hooks/useMergedStep.ts rename to components/chatbox/hooks/useStep.ts index cbdb09881a5c..e822d88df91e 100644 --- a/components/chat-box/hooks/useMergedStep.ts +++ b/components/chatbox/hooks/useStep.ts @@ -7,7 +7,7 @@ const defaultStepOption: Required = { interval: 100, }; -const useMergedStep = (step: ChatBoxProps['step']) => { +const useStep = (step: ChatBoxProps['step']) => { const mergedStep = React.useMemo | false>(() => { if (step && typeof step === 'object') { return { ...defaultStepOption, ...step }; @@ -20,4 +20,4 @@ const useMergedStep = (step: ChatBoxProps['step']) => { return mergedStep; }; -export default useMergedStep; +export default useStep; diff --git a/components/chat-box/hooks/useTyped.ts b/components/chatbox/hooks/useTyped.ts similarity index 100% rename from components/chat-box/hooks/useTyped.ts rename to components/chatbox/hooks/useTyped.ts diff --git a/components/chat-box/index.en-US.md b/components/chatbox/index.en-US.md similarity index 100% rename from components/chat-box/index.en-US.md rename to components/chatbox/index.en-US.md diff --git a/components/chat-box/index.tsx b/components/chatbox/index.tsx similarity index 95% rename from components/chat-box/index.tsx rename to components/chatbox/index.tsx index 75500099c9c6..f4df654b9404 100644 --- a/components/chat-box/index.tsx +++ b/components/chatbox/index.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; import Spin from '../spin'; -import useMergedStep from './hooks/useMergedStep'; +import useStep from './hooks/useStep'; import useTyped from './hooks/useTyped'; import useStyle from './style'; @@ -51,7 +51,7 @@ const ChatBox: React.FC = (props) => { const prefixCls = getPrefixCls('chat-box', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const mergedStep = useMergedStep(step); + const mergedStep = useStep(step); const { typedContent, showCursor } = useTyped(content, mergedStep); diff --git a/components/chat-box/index.zh-CN.md b/components/chatbox/index.zh-CN.md similarity index 100% rename from components/chat-box/index.zh-CN.md rename to components/chatbox/index.zh-CN.md diff --git a/components/chat-box/style/index.ts b/components/chatbox/style/index.ts similarity index 100% rename from components/chat-box/style/index.ts rename to components/chatbox/style/index.ts From 93f9e7dc63974b629ee8f0d2a5d46dde6c9b9253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 18:46:29 +0800 Subject: [PATCH 28/72] chore: rename `chat-box` => `chatbox` --- .../__snapshots__/index.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 2 +- components/chatbox/__tests__/index.test.tsx | 36 +++++++++---------- .../chatbox/demo/avatar-and-placement.tsx | 6 ++-- components/chatbox/demo/basic.tsx | 4 +-- components/chatbox/demo/contentRender.tsx | 4 +-- components/chatbox/demo/loading.tsx | 4 +-- components/chatbox/demo/stream-output.tsx | 4 +-- components/chatbox/hooks/useStep.ts | 4 +-- components/chatbox/index.en-US.md | 8 ++--- components/chatbox/index.tsx | 8 ++--- components/chatbox/index.zh-CN.md | 6 ++-- components/chatbox/style/index.ts | 14 ++++---- components/index.ts | 4 +-- components/theme/interface/components.ts | 4 +-- tests/__snapshots__/index.test.ts.snap | 2 +- 16 files changed, 56 insertions(+), 56 deletions(-) diff --git a/components/__tests__/__snapshots__/index.test.ts.snap b/components/__tests__/__snapshots__/index.test.ts.snap index 9fb5d00c4aef..8de60f5d3159 100644 --- a/components/__tests__/__snapshots__/index.test.ts.snap +++ b/components/__tests__/__snapshots__/index.test.ts.snap @@ -16,7 +16,7 @@ exports[`antd exports modules correctly 1`] = ` "Card", "Carousel", "Cascader", - "ChatBox", + "Chatbox", "Checkbox", "Col", "Collapse", diff --git a/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap b/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap index 3918f16aa5aa..7c4f226b3a86 100644 --- a/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`chat-box ChatBox component work 1`] = ` +exports[`chat-box Chatbox component work 1`] = `
diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 4553d8bff1b8..ea2913ba0fa7 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -1,29 +1,29 @@ import React from 'react'; -import ChatBox from '..'; +import Chatbox from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { render } from '../../../tests/utils'; describe('chat-box', () => { - mountTest(() => ); - rtlTest(() => ); - it('ChatBox component work', () => { - const { container } = render(); + mountTest(() => ); + rtlTest(() => ); + it('Chatbox component work', () => { + const { container } = render(); const element = container.querySelector('.ant-chat-box'); expect(element).toBeTruthy(); expect(element).toMatchSnapshot(); }); - it('ChatBox support content', () => { - const { container } = render(); + it('Chatbox support content', () => { + const { container } = render(); const element = container.querySelector('.ant-chat-box .ant-chat-box-content'); expect(element?.textContent).toBe('hello world'); }); - it('ChatBox support contentRender', () => { + it('Chatbox support contentRender', () => { const { container } = render( - {content}} />, @@ -33,33 +33,33 @@ describe('chat-box', () => { expect(element?.textContent).toBe('test-contentRender'); }); - it('ChatBox support step', () => { - const { container } = render(); + it('Chatbox support step', () => { + const { container } = render(); const selectors = '.ant-chat-box .ant-chat-box-content'; expect(container.querySelector(selectors)).toHaveClass( 'ant-chat-box-content-cursorBlink', ); }); - it('ChatBox support avatar', () => { + it('Chatbox support avatar', () => { const { container } = render( - avatar} content="" />, + avatar} content="" />, ); expect(container.querySelector('.ant-chat-box .test-avatar')).toBeTruthy(); }); - it('ChatBox support loading', () => { - const { container } = render(); + it('Chatbox support loading', () => { + const { container } = render(); expect( container.querySelector('.ant-chat-box .ant-spin.ant-spin-spinning'), ).toBeTruthy(); }); - it('ChatBox support placement', () => { - const { container, rerender } = render(); + it('Chatbox support placement', () => { + const { container, rerender } = render(); const element = container.querySelector('.ant-chat-box'); expect(element).toHaveClass('ant-chat-box-start'); - rerender(); + rerender(); expect(element).toHaveClass('ant-chat-box-end'); }); }); diff --git a/components/chatbox/demo/avatar-and-placement.tsx b/components/chatbox/demo/avatar-and-placement.tsx index 1d202cf1b013..7102fa7eef79 100644 --- a/components/chatbox/demo/avatar-and-placement.tsx +++ b/components/chatbox/demo/avatar-and-placement.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { UserOutlined } from '@ant-design/icons'; -import { Avatar, ChatBox, Flex } from 'antd'; +import { Avatar, Chatbox, Flex } from 'antd'; const fooAvatar: React.CSSProperties = { color: '#f56a00', @@ -14,12 +14,12 @@ const barAvatar: React.CSSProperties = { const App: React.FC = () => ( - } style={fooAvatar} />} /> - } style={barAvatar} />} diff --git a/components/chatbox/demo/basic.tsx b/components/chatbox/demo/basic.tsx index 4bca88fdf79a..329c4fd82e58 100644 --- a/components/chatbox/demo/basic.tsx +++ b/components/chatbox/demo/basic.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { ChatBox } from 'antd'; +import { Chatbox } from 'antd'; -const App = () => ; +const App = () => ; export default App; diff --git a/components/chatbox/demo/contentRender.tsx b/components/chatbox/demo/contentRender.tsx index c0c3660cf4d8..4347a000baa1 100644 --- a/components/chatbox/demo/contentRender.tsx +++ b/components/chatbox/demo/contentRender.tsx @@ -1,7 +1,7 @@ /* eslint-disable react/no-danger */ import React from 'react'; import { UserOutlined } from '@ant-design/icons'; -import { Avatar, ChatBox } from 'antd'; +import { Avatar, Chatbox } from 'antd'; import markdownit from 'markdown-it'; const style: React.CSSProperties = { @@ -21,7 +21,7 @@ const App: React.FC = () => { return
; }, []); return ( - } />} content={'# Title \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n ...'} contentRender={contentRender} diff --git a/components/chatbox/demo/loading.tsx b/components/chatbox/demo/loading.tsx index 7111ad330906..5812ff7b167b 100644 --- a/components/chatbox/demo/loading.tsx +++ b/components/chatbox/demo/loading.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { UserOutlined } from '@ant-design/icons'; -import { Avatar, ChatBox, Flex, Switch } from 'antd'; +import { Avatar, Chatbox, Flex, Switch } from 'antd'; const App: React.FC = () => { const [loading, setLoading] = React.useState(true); return ( - } />} diff --git a/components/chatbox/demo/stream-output.tsx b/components/chatbox/demo/stream-output.tsx index 381f06eb77f5..a8c74bd2b18b 100644 --- a/components/chatbox/demo/stream-output.tsx +++ b/components/chatbox/demo/stream-output.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { UserOutlined } from '@ant-design/icons'; -import { Avatar, ChatBox } from 'antd'; +import { Avatar, Chatbox } from 'antd'; const sentences = ['Feel free to use Ant Design !', '欢迎使用 Ant Design!']; @@ -19,7 +19,7 @@ const useLoopSentence = () => { const App: React.FC = () => { const content = useLoopSentence(); return ( - } />} diff --git a/components/chatbox/hooks/useStep.ts b/components/chatbox/hooks/useStep.ts index e822d88df91e..24c83f6b7ec8 100644 --- a/components/chatbox/hooks/useStep.ts +++ b/components/chatbox/hooks/useStep.ts @@ -1,13 +1,13 @@ import React from 'react'; -import type { ChatBoxProps, StepOption } from '..'; +import type { ChatboxProps, StepOption } from '..'; const defaultStepOption: Required = { step: 1, interval: 100, }; -const useStep = (step: ChatBoxProps['step']) => { +const useStep = (step: ChatboxProps['step']) => { const mergedStep = React.useMemo | false>(() => { if (step && typeof step === 'object') { return { ...defaultStepOption, ...step }; diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md index 25bbf600786c..6e6a7539eed9 100644 --- a/components/chatbox/index.en-US.md +++ b/components/chatbox/index.en-US.md @@ -1,7 +1,7 @@ --- category: Components group: Data Display -title: ChatBox +title: Chatbox description: A bubble component for chat. cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAAAAAAAADrJ8AQ/original coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*D70qQJJmzhgAAAAAAAAAAAAADrJ8AQ/original @@ -29,7 +29,7 @@ Common props ref:[Common props](/docs/react/common-props) > This component is available since `antd@5.17.0`. -### ChatBox +### Chatbox | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | @@ -37,9 +37,9 @@ Common props ref:[Common props](/docs/react/common-props) | placement | Direction of Message | `start \| end` | `start` | | | loading | Loading state of Message | `boolean` | - | | | step | Show message with stepping motion | `boolean \| { step?: number, interval?: number }` | `false` | | -| content | Content of ChatBox | `string` | - | | +| content | Content of Chatbox | `string` | - | | | contentRender | Display cuztomized content (If use `contentRender` prop, the typed effect needs to be implemented by yourself) | `(content?: string) => ReactNode` | - | | ## Design Token - + diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index f4df654b9404..ab61aa14c995 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -21,7 +21,7 @@ export interface StepOption { interval?: number; } -export interface ChatBoxProps { +export interface ChatboxProps { prefixCls?: string; className?: string; rootClassName?: string; @@ -34,7 +34,7 @@ export interface ChatBoxProps { contentRender?: (content?: string) => React.ReactNode; } -const ChatBox: React.FC = (props) => { +const Chatbox: React.FC = (props) => { const { prefixCls: customizePrefixCls, className, @@ -84,7 +84,7 @@ const ChatBox: React.FC = (props) => { }; if (process.env.NODE_ENV !== 'production') { - ChatBox.displayName = 'ChatBox'; + Chatbox.displayName = 'Chatbox'; } -export default ChatBox; +export default Chatbox; diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index cee69fa28dc8..207aaa488548 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -1,7 +1,7 @@ --- category: Components group: 数据展示 -title: ChatBox +title: Chatbox subtitle: 聊天框 description: 用于聊天的气泡组件。 cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAAAAAAAADrJ8AQ/original @@ -30,7 +30,7 @@ tag: 5.17.0 > 自 `antd@5.17.0` 版本开始提供该组件。 -### ChatBox +### Chatbox | 属性 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | @@ -43,4 +43,4 @@ tag: 5.17.0 ## 主题变量(Design Token) - + diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 93a5640d55a6..f2a61255b502 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -19,12 +19,12 @@ export interface ComponentToken { // } -export interface ChatBoxToken extends FullToken<'ChatBox'> { +export interface ChatboxToken extends FullToken<'Chatbox'> { messageMaxWidth: number; avatarGap: number; } -const genChatBoxStyle: GenerateStyle = (token) => { +const genChatboxStyle: GenerateStyle = (token) => { const { componentCls, messageMaxWidth, avatarGap } = token; return { [componentCls]: { @@ -68,18 +68,18 @@ const genChatBoxStyle: GenerateStyle = (token) => { }; }; -export const prepareComponentToken: GetDefaultToken<'ChatBox'> = () => ({ +export const prepareComponentToken: GetDefaultToken<'Chatbox'> = () => ({ // }); -export default genStyleHooks<'ChatBox'>( - 'ChatBox', +export default genStyleHooks<'Chatbox'>( + 'Chatbox', (token) => { - const chatBoxToken = mergeToken(token, { + const chatBoxToken = mergeToken(token, { messageMaxWidth: 720, avatarGap: token.paddingXS, }); - return genChatBoxStyle(chatBoxToken); + return genChatboxStyle(chatBoxToken); }, prepareComponentToken, ); diff --git a/components/index.ts b/components/index.ts index 921c143508db..9974ce0352d0 100644 --- a/components/index.ts +++ b/components/index.ts @@ -28,8 +28,8 @@ export { default as Carousel } from './carousel'; export type { CarouselProps } from './carousel'; export { default as Cascader } from './cascader'; export type { CascaderProps } from './cascader'; -export { default as ChatBox } from './chat-box'; -export type { ChatBoxProps } from './chat-box'; +export { default as Chatbox } from './chatbox'; +export type { ChatboxProps } from './chatbox'; export { default as Checkbox } from './checkbox'; export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox'; export { default as Col } from './col'; diff --git a/components/theme/interface/components.ts b/components/theme/interface/components.ts index e62223bfce08..a4d7f94a411d 100644 --- a/components/theme/interface/components.ts +++ b/components/theme/interface/components.ts @@ -12,7 +12,7 @@ import type { ComponentToken as CalendarComponentToken } from '../../calendar/st import type { ComponentToken as CardComponentToken } from '../../card/style'; import type { ComponentToken as CarouselComponentToken } from '../../carousel/style'; import type { ComponentToken as CascaderComponentToken } from '../../cascader/style'; -import type { ComponentToken as ChatBoxComponentToken } from '../../chat-box/style'; +import type { ComponentToken as ChatboxComponentToken } from '../../chatbox/style'; import type { ComponentToken as CheckboxComponentToken } from '../../checkbox/style'; import type { ComponentToken as CollapseComponentToken } from '../../collapse/style'; import type { ComponentToken as ColorPickerComponentToken } from '../../color-picker/style'; @@ -77,7 +77,7 @@ export interface ComponentTokenMap { Card?: CardComponentToken; Carousel?: CarouselComponentToken; Cascader?: CascaderComponentToken; - ChatBox?: ChatBoxComponentToken; + Chatbox?: ChatboxComponentToken; Checkbox?: CheckboxComponentToken; ColorPicker?: ColorPickerComponentToken; Collapse?: CollapseComponentToken; diff --git a/tests/__snapshots__/index.test.ts.snap b/tests/__snapshots__/index.test.ts.snap index 299402aa7b9f..e2d99a784e71 100644 --- a/tests/__snapshots__/index.test.ts.snap +++ b/tests/__snapshots__/index.test.ts.snap @@ -16,7 +16,7 @@ exports[`antd dist files exports modules correctly 1`] = ` "Card", "Carousel", "Cascader", - "ChatBox", + "Chatbox", "Checkbox", "Col", "Collapse", From 3b4e2205500c0f88a70dd0a84658e299134705c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 19:10:05 +0800 Subject: [PATCH 29/72] chore: rename `chat-box` => `chatbox` --- .../__snapshots__/demo-extend.test.ts.snap | 70 ++++++++++--------- .../__tests__/__snapshots__/demo.test.ts.snap | 60 ++++++++-------- .../__snapshots__/index.test.tsx.snap | 12 ++-- .../chatbox/__tests__/demo-extend.test.ts | 2 +- components/chatbox/__tests__/demo.test.ts | 2 +- components/chatbox/__tests__/image.test.ts | 4 +- components/chatbox/__tests__/index.test.tsx | 22 +++--- components/chatbox/demo/contentRender.tsx | 35 ++++------ components/chatbox/index.tsx | 28 +++++--- 9 files changed, 119 insertions(+), 116 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index f70fdbe7781b..1f61ae1288d9 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1,14 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend context correctly 1`] = ` +exports[`renders components/chatbox/demo/avatar-and-placement.tsx extend context correctly 1`] = `
晚上好,你吃过了吗?
晚上好,你吃过了吗?
@@ -81,28 +81,28 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend contex
`; -exports[`renders components/chat-box/demo/avatar-and-placement.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chatbox/demo/avatar-and-placement.tsx extend context correctly 2`] = `[]`; -exports[`renders components/chat-box/demo/basic.tsx extend context correctly 1`] = ` +exports[`renders components/chatbox/demo/basic.tsx extend context correctly 1`] = `
hello world !
`; -exports[`renders components/chat-box/demo/basic.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chatbox/demo/basic.tsx extend context correctly 2`] = `[]`; -exports[`renders components/chat-box/demo/contentRender.tsx extend context correctly 1`] = ` +exports[`renders components/chatbox/demo/contentRender.tsx extend context correctly 1`] = `
-

- Title -

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. -
+

+

+ Title +

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
… -

+

+
`; -exports[`renders components/chat-box/demo/contentRender.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chatbox/demo/contentRender.tsx extend context correctly 2`] = `[]`; -exports[`renders components/chat-box/demo/loading.tsx extend context correctly 1`] = ` +exports[`renders components/chatbox/demo/loading.tsx extend context correctly 1`] = `
`; -exports[`renders components/chat-box/demo/loading.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chatbox/demo/loading.tsx extend context correctly 2`] = `[]`; -exports[`renders components/chat-box/demo/stream-output.tsx extend context correctly 1`] = ` +exports[`renders components/chatbox/demo/stream-output.tsx extend context correctly 1`] = `
`; -exports[`renders components/chat-box/demo/stream-output.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chatbox/demo/stream-output.tsx extend context correctly 2`] = `[]`; diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 1cf5ad429fe2..7729272500b5 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -1,14 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders components/chat-box/demo/avatar-and-placement.tsx correctly 1`] = ` +exports[`renders components/chatbox/demo/avatar-and-placement.tsx correctly 1`] = `
晚上好,你吃过了吗?
晚上好,你吃过了吗?
@@ -81,24 +81,24 @@ exports[`renders components/chat-box/demo/avatar-and-placement.tsx correctly 1`]
`; -exports[`renders components/chat-box/demo/basic.tsx correctly 1`] = ` +exports[`renders components/chatbox/demo/basic.tsx correctly 1`] = `
hello world !
`; -exports[`renders components/chat-box/demo/contentRender.tsx correctly 1`] = ` +exports[`renders components/chatbox/demo/contentRender.tsx correctly 1`] = `
-

- Title -

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. -
+

+

+ Title +

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
… -

+

+
`; -exports[`renders components/chat-box/demo/loading.tsx correctly 1`] = ` +exports[`renders components/chatbox/demo/loading.tsx correctly 1`] = `
`; -exports[`renders components/chat-box/demo/stream-output.tsx correctly 1`] = ` +exports[`renders components/chatbox/demo/stream-output.tsx correctly 1`] = `
`; diff --git a/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap b/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap index 7c4f226b3a86..c3dbc3f1388d 100644 --- a/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/chatbox/__tests__/__snapshots__/index.test.tsx.snap @@ -1,23 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`chat-box Chatbox component work 1`] = ` +exports[`chatbox Chatbox component work 1`] = `
test
`; -exports[`chat-box rtl render component should be rendered correctly in RTL direction 1`] = ` +exports[`chatbox rtl render component should be rendered correctly in RTL direction 1`] = `
test
diff --git a/components/chatbox/__tests__/demo-extend.test.ts b/components/chatbox/__tests__/demo-extend.test.ts index b4d9d9c58948..4940e499e235 100644 --- a/components/chatbox/__tests__/demo-extend.test.ts +++ b/components/chatbox/__tests__/demo-extend.test.ts @@ -1,3 +1,3 @@ import { extendTest } from '../../../tests/shared/demoTest'; -extendTest('chat-box'); +extendTest('chatbox'); diff --git a/components/chatbox/__tests__/demo.test.ts b/components/chatbox/__tests__/demo.test.ts index 818365aa325f..549211096c11 100644 --- a/components/chatbox/__tests__/demo.test.ts +++ b/components/chatbox/__tests__/demo.test.ts @@ -1,3 +1,3 @@ import demoTest from '../../../tests/shared/demoTest'; -demoTest('chat-box'); +demoTest('chatbox'); diff --git a/components/chatbox/__tests__/image.test.ts b/components/chatbox/__tests__/image.test.ts index d1b453c649b1..7e79d7a14b77 100644 --- a/components/chatbox/__tests__/image.test.ts +++ b/components/chatbox/__tests__/image.test.ts @@ -1,5 +1,5 @@ import { imageDemoTest } from '../../../tests/shared/imageTest'; -describe('chat-box image', () => { - imageDemoTest('chat-box'); +describe('chatbox image', () => { + imageDemoTest('chatbox'); }); diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index ea2913ba0fa7..0b2ad516da65 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -5,19 +5,19 @@ import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { render } from '../../../tests/utils'; -describe('chat-box', () => { +describe('chatbox', () => { mountTest(() => ); rtlTest(() => ); it('Chatbox component work', () => { const { container } = render(); - const element = container.querySelector('.ant-chat-box'); + const element = container.querySelector('.ant-chatbox'); expect(element).toBeTruthy(); expect(element).toMatchSnapshot(); }); it('Chatbox support content', () => { const { container } = render(); - const element = container.querySelector('.ant-chat-box .ant-chat-box-content'); + const element = container.querySelector('.ant-chatbox .ant-chatbox-content'); expect(element?.textContent).toBe('hello world'); }); @@ -28,16 +28,16 @@ describe('chat-box', () => { contentRender={(content) => {content}} />, ); - const element = container.querySelector('.ant-chat-box .test-contentRender'); + const element = container.querySelector('.ant-chatbox .test-contentRender'); expect(element).toBeTruthy(); expect(element?.textContent).toBe('test-contentRender'); }); it('Chatbox support step', () => { const { container } = render(); - const selectors = '.ant-chat-box .ant-chat-box-content'; + const selectors = '.ant-chatbox .ant-chatbox-content'; expect(container.querySelector(selectors)).toHaveClass( - 'ant-chat-box-content-cursorBlink', + 'ant-chatbox-content-cursorBlink', ); }); @@ -45,21 +45,21 @@ describe('chat-box', () => { const { container } = render( avatar} content="" />, ); - expect(container.querySelector('.ant-chat-box .test-avatar')).toBeTruthy(); + expect(container.querySelector('.ant-chatbox .test-avatar')).toBeTruthy(); }); it('Chatbox support loading', () => { const { container } = render(); expect( - container.querySelector('.ant-chat-box .ant-spin.ant-spin-spinning'), + container.querySelector('.ant-chatbox .ant-spin.ant-spin-spinning'), ).toBeTruthy(); }); it('Chatbox support placement', () => { const { container, rerender } = render(); - const element = container.querySelector('.ant-chat-box'); - expect(element).toHaveClass('ant-chat-box-start'); + const element = container.querySelector('.ant-chatbox'); + expect(element).toHaveClass('ant-chatbox-start'); rerender(); - expect(element).toHaveClass('ant-chat-box-end'); + expect(element).toHaveClass('ant-chatbox-end'); }); }); diff --git a/components/chatbox/demo/contentRender.tsx b/components/chatbox/demo/contentRender.tsx index 4347a000baa1..abeb813a75eb 100644 --- a/components/chatbox/demo/contentRender.tsx +++ b/components/chatbox/demo/contentRender.tsx @@ -2,31 +2,24 @@ import React from 'react'; import { UserOutlined } from '@ant-design/icons'; import { Avatar, Chatbox } from 'antd'; +import type { ChatboxProps } from 'antd'; import markdownit from 'markdown-it'; -const style: React.CSSProperties = { - maxWidth: '100%', - padding: '12px 16px', - backgroundColor: '#f0f2f5', - border: '1px solid #d9d9d9', -}; - const md = markdownit({ html: true, breaks: true, typographer: true }); -const App: React.FC = () => { - const contentRender = React.useCallback((content?: string) => { - if (!content) { - return null; - } - return
; - }, []); - return ( - } />} - content={'# Title \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n ...'} - contentRender={contentRender} - /> - ); +const contentRender: ChatboxProps['contentRender'] = (content) => { + if (!content) { + return null; + } + return
; }; +const App: React.FC = () => ( + } />} + content={'# Title \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n ...'} + contentRender={contentRender} + /> +); + export default App; diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index ab61aa14c995..8e7c707d0d2e 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -48,7 +48,7 @@ const Chatbox: React.FC = (props) => { contentRender, } = props; const { direction, getPrefixCls } = React.useContext(ConfigContext); - const prefixCls = getPrefixCls('chat-box', customizePrefixCls); + const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); const mergedStep = useStep(step); @@ -65,20 +65,26 @@ const Chatbox: React.FC = (props) => { { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); - const mergedContentCls = classNames(`${prefixCls}-content`, { - [`${prefixCls}-content-cursorBlink`]: showCursor && !loading, - }); - - const contentNode = mergedStep !== false ? typedContent : content; + const mergedContent = React.useMemo(() => { + if (loading) { + return ; + } + if (mergedStep !== false) { + return typedContent; + } + return content; + }, [content, loading, mergedStep, typedContent]); return wrapCSSVar(
{avatar &&
{avatar}
} - {contentRender ? ( - contentRender(content) - ) : ( -
{loading ? : contentNode}
- )} +
+ {contentRender ? contentRender(content) : mergedContent} +
, ); }; From aa793e450eb15c9c5fbcfe1fe8fa3d2bc28ccd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 19:24:21 +0800 Subject: [PATCH 30/72] fix: update demo --- .dumi/theme/common/styles/Markdown.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.dumi/theme/common/styles/Markdown.tsx b/.dumi/theme/common/styles/Markdown.tsx index 692faf0a8f7e..9f8b321ea0ec 100644 --- a/.dumi/theme/common/styles/Markdown.tsx +++ b/.dumi/theme/common/styles/Markdown.tsx @@ -469,6 +469,12 @@ const GlobalStyle: React.FC = () => { margin-bottom: 0; } } + + .code-box[id^='chatbox-demo-'] { + .code-box-demo { + background-color: ${token.colorBgLayout}; + } + } `} /> ); From 8e0608eb1f9b9a1cebdcf6bccab60de9bc6aa7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 22:15:05 +0800 Subject: [PATCH 31/72] fix: fix --- .dumi/theme/common/styles/Markdown.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 4 ++-- .../__tests__/__snapshots__/demo.test.ts.snap | 4 ++-- components/chatbox/__tests__/index.test.tsx | 4 ++-- .../chatbox/demo/avatar-and-placement.tsx | 4 ++-- components/chatbox/demo/stream-output.tsx | 8 +++---- components/chatbox/hooks/useStep.ts | 23 ------------------- .../hooks/{useTyped.ts => useTypedEffect.ts} | 12 +++++----- components/chatbox/hooks/useTypingValue.ts | 23 +++++++++++++++++++ components/chatbox/index.en-US.md | 2 +- components/chatbox/index.tsx | 18 +++++++-------- components/chatbox/index.zh-CN.md | 2 +- 12 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 components/chatbox/hooks/useStep.ts rename components/chatbox/hooks/{useTyped.ts => useTypedEffect.ts} (74%) create mode 100644 components/chatbox/hooks/useTypingValue.ts diff --git a/.dumi/theme/common/styles/Markdown.tsx b/.dumi/theme/common/styles/Markdown.tsx index 9f8b321ea0ec..3222b57e00bb 100644 --- a/.dumi/theme/common/styles/Markdown.tsx +++ b/.dumi/theme/common/styles/Markdown.tsx @@ -472,7 +472,7 @@ const GlobalStyle: React.FC = () => { .code-box[id^='chatbox-demo-'] { .code-box-demo { - background-color: ${token.colorBgLayout}; + background-color: ${token.colorBgContainer}; } } `} diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 1f61ae1288d9..68432f0f3b2b 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -38,7 +38,7 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx extend context
- 晚上好,你吃过了吗? + Good morning, how are you ?
- 晚上好,你吃过了吗? + I'm fine, thank you !
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 7729272500b5..b6fe332fae71 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -38,7 +38,7 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx correctly 1`]
- 晚上好,你吃过了吗? + Good morning, how are you ?
- 晚上好,你吃过了吗? + I'm fine, thank you !
diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 0b2ad516da65..1ad8430a5b0a 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -33,8 +33,8 @@ describe('chatbox', () => { expect(element?.textContent).toBe('test-contentRender'); }); - it('Chatbox support step', () => { - const { container } = render(); + it('Chatbox support typing', () => { + const { container } = render(); const selectors = '.ant-chatbox .ant-chatbox-content'; expect(container.querySelector(selectors)).toHaveClass( 'ant-chatbox-content-cursorBlink', diff --git a/components/chatbox/demo/avatar-and-placement.tsx b/components/chatbox/demo/avatar-and-placement.tsx index 7102fa7eef79..d007a616db38 100644 --- a/components/chatbox/demo/avatar-and-placement.tsx +++ b/components/chatbox/demo/avatar-and-placement.tsx @@ -15,12 +15,12 @@ const barAvatar: React.CSSProperties = { const App: React.FC = () => ( } style={fooAvatar} />} /> } style={barAvatar} />} /> diff --git a/components/chatbox/demo/stream-output.tsx b/components/chatbox/demo/stream-output.tsx index a8c74bd2b18b..21b4086fd659 100644 --- a/components/chatbox/demo/stream-output.tsx +++ b/components/chatbox/demo/stream-output.tsx @@ -6,12 +6,12 @@ const sentences = ['Feel free to use Ant Design !', '欢迎使用 Ant Design!' const useLoopSentence = () => { const [index, setIndex] = React.useState(0); - const timer = React.useRef>(); + const timerRef = React.useRef>(); React.useEffect(() => { - timer.current = setTimeout(() => { + timerRef.current = setTimeout(() => { setIndex((prevState) => (prevState ? 0 : 1)); }, 4000); - return () => clearTimeout(timer.current); + return () => clearTimeout(timerRef.current); }, [index]); return sentences[index]; }; @@ -21,7 +21,7 @@ const App: React.FC = () => { return ( } />} /> ); diff --git a/components/chatbox/hooks/useStep.ts b/components/chatbox/hooks/useStep.ts deleted file mode 100644 index 24c83f6b7ec8..000000000000 --- a/components/chatbox/hooks/useStep.ts +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; - -import type { ChatboxProps, StepOption } from '..'; - -const defaultStepOption: Required = { - step: 1, - interval: 100, -}; - -const useStep = (step: ChatboxProps['step']) => { - const mergedStep = React.useMemo | false>(() => { - if (step && typeof step === 'object') { - return { ...defaultStepOption, ...step }; - } - if (step === true) { - return defaultStepOption; - } - return false; - }, [step]); - return mergedStep; -}; - -export default useStep; diff --git a/components/chatbox/hooks/useTyped.ts b/components/chatbox/hooks/useTypedEffect.ts similarity index 74% rename from components/chatbox/hooks/useTyped.ts rename to components/chatbox/hooks/useTypedEffect.ts index 06f9b4fd98d9..2671a42cb081 100644 --- a/components/chatbox/hooks/useTyped.ts +++ b/components/chatbox/hooks/useTypedEffect.ts @@ -1,8 +1,8 @@ import React from 'react'; -import type { StepOption } from '..'; +import type { TypingOption } from '..'; -const useTyped = (content?: string, mergedStep?: Required | false) => { +const useTypedEffect = (content?: string, mergedTyping?: Required | false) => { const [typedContent, setTypedContent] = React.useState(''); const [showCursor, setShowCursor] = React.useState(false); @@ -15,12 +15,12 @@ const useTyped = (content?: string, mergedStep?: Required | false) = }; React.useEffect(() => { - if (!content || !mergedStep) { + if (!content || !mergedTyping) { return; } setShowCursor(true); let stepCount = 0; - const { step, interval } = mergedStep; + const { step, interval } = mergedTyping; timerRef.current = setInterval(() => { stepCount += step; setTypedContent(content.slice(0, stepCount) ?? ''); @@ -33,9 +33,9 @@ const useTyped = (content?: string, mergedStep?: Required | false) = clearTimer(); setShowCursor(false); }; - }, [content, mergedStep]); + }, [content, mergedTyping]); return { typedContent, showCursor }; }; -export default useTyped; +export default useTypedEffect; diff --git a/components/chatbox/hooks/useTypingValue.ts b/components/chatbox/hooks/useTypingValue.ts new file mode 100644 index 000000000000..9bf2daaa1826 --- /dev/null +++ b/components/chatbox/hooks/useTypingValue.ts @@ -0,0 +1,23 @@ +import React from 'react'; + +import type { ChatboxProps, TypingOption } from '..'; + +const defaultTypingOption: Required = { + step: 1, + interval: 100, +}; + +const useTypingValue = (typing: ChatboxProps['typing']) => { + const mergedTyping = React.useMemo | false>(() => { + if (typing && typeof typing === 'object') { + return { ...defaultTypingOption, ...typing }; + } + if (typing === true) { + return defaultTypingOption; + } + return false; + }, [typing]); + return mergedTyping; +}; + +export default useTypingValue; diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md index 6e6a7539eed9..72eb43e74553 100644 --- a/components/chatbox/index.en-US.md +++ b/components/chatbox/index.en-US.md @@ -36,7 +36,7 @@ Common props ref:[Common props](/docs/react/common-props) | avatar | Avatar component | `React.ReactNode` | - | | | placement | Direction of Message | `start \| end` | `start` | | | loading | Loading state of Message | `boolean` | - | | -| step | Show message with stepping motion | `boolean \| { step?: number, interval?: number }` | `false` | | +| typing | Show message with typing motion | `boolean \| { step?: number, interval?: number }` | `false` | | | content | Content of Chatbox | `string` | - | | | contentRender | Display cuztomized content (If use `contentRender` prop, the typed effect needs to be implemented by yourself) | `(content?: string) => ReactNode` | - | | diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index 8e7c707d0d2e..fed2ee686033 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -4,11 +4,11 @@ import classNames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; import Spin from '../spin'; -import useStep from './hooks/useStep'; -import useTyped from './hooks/useTyped'; +import useTypedEffect from './hooks/useTypedEffect'; +import useTypingValue from './hooks/useTypingValue'; import useStyle from './style'; -export interface StepOption { +export interface TypingOption { /** * @since 5.17.0 * @default 1 @@ -29,7 +29,7 @@ export interface ChatboxProps { avatar?: React.ReactNode; placement?: 'start' | 'end'; loading?: boolean; - step?: boolean | StepOption; + typing?: boolean | TypingOption; content: string; contentRender?: (content?: string) => React.ReactNode; } @@ -43,7 +43,7 @@ const Chatbox: React.FC = (props) => { avatar, placement = 'start', loading = false, - step, + typing, content, contentRender, } = props; @@ -51,9 +51,9 @@ const Chatbox: React.FC = (props) => { const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); - const mergedStep = useStep(step); + const mergedTyping = useTypingValue(typing); - const { typedContent, showCursor } = useTyped(content, mergedStep); + const { typedContent, showCursor } = useTypedEffect(content, mergedTyping); const mergedCls = classNames( className, @@ -69,11 +69,11 @@ const Chatbox: React.FC = (props) => { if (loading) { return ; } - if (mergedStep !== false) { + if (mergedTyping !== false) { return typedContent; } return content; - }, [content, loading, mergedStep, typedContent]); + }, [content, loading, mergedTyping, typedContent]); return wrapCSSVar(
diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index 207aaa488548..fa6c2e9923d9 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -37,7 +37,7 @@ tag: 5.17.0 | avatar | 展示头像 | `React.ReactNode` | - | | | placement | 信息位置 | `start \| end` | `start` | | | loading | 聊天内容加载状态 | `boolean` | - | | -| step | 聊天内容动画 | `boolean \| { step?: number, interval?: number }` | `false` | | +| typing | 设置聊天内容打字动画 | `boolean \| { step?: number, interval?: number }` | `false` | | | content | 聊天内容 | `string` | - | | | contentRender | 自定义渲染内容(使用 `contentRender` 的话,打字效果需要自行实现) | `(content?: string) => ReactNode` | - | | From 1bc3e43fe51717e8839f86179c73b53d72428d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 22:32:01 +0800 Subject: [PATCH 32/72] fix: setInterval => setTimeout --- components/chatbox/hooks/useTypedEffect.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/components/chatbox/hooks/useTypedEffect.ts b/components/chatbox/hooks/useTypedEffect.ts index 2671a42cb081..0e965880b8e2 100644 --- a/components/chatbox/hooks/useTypedEffect.ts +++ b/components/chatbox/hooks/useTypedEffect.ts @@ -4,13 +4,13 @@ import type { TypingOption } from '..'; const useTypedEffect = (content?: string, mergedTyping?: Required | false) => { const [typedContent, setTypedContent] = React.useState(''); - const [showCursor, setShowCursor] = React.useState(false); + const [showCursor, setShowCursor] = React.useState(mergedTyping !== false); - const timerRef = React.useRef>(); + const timerRef = React.useRef>(); const clearTimer = () => { if (timerRef.current) { - clearInterval(timerRef.current); + clearTimeout(timerRef.current); } }; @@ -21,14 +21,19 @@ const useTypedEffect = (content?: string, mergedTyping?: Required setShowCursor(true); let stepCount = 0; const { step, interval } = mergedTyping; - timerRef.current = setInterval(() => { + + const typedTimer = () => { stepCount += step; setTypedContent(content.slice(0, stepCount) ?? ''); - if (stepCount >= content.length) { - clearTimer(); + if (stepCount < content.length) { + timerRef.current = setTimeout(typedTimer, interval); + } else { setShowCursor(false); } - }, interval); + }; + + typedTimer(); + return () => { clearTimer(); setShowCursor(false); From 70edfe122e1e4b1367c57f5f959164dd6406dd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 22:47:00 +0800 Subject: [PATCH 33/72] test: update test snap --- .../chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap | 4 +++- components/chatbox/__tests__/__snapshots__/demo.test.ts.snap | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 68432f0f3b2b..d2ad853f3b2d 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -274,7 +274,9 @@ exports[`renders components/chatbox/demo/stream-output.tsx extend context correc
`; diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index b6fe332fae71..3a75ef388c2d 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -265,7 +265,7 @@ exports[`renders components/chatbox/demo/stream-output.tsx correctly 1`] = `
`; From 323ef283ed226cf31dbfcc4b27b8575e8df2e189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Mon, 15 Apr 2024 23:15:43 +0800 Subject: [PATCH 34/72] test: update test snap --- scripts/__snapshots__/check-site.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/__snapshots__/check-site.ts.snap b/scripts/__snapshots__/check-site.ts.snap index fc6a7e98decd..5f8a207d2ab2 100644 --- a/scripts/__snapshots__/check-site.ts.snap +++ b/scripts/__snapshots__/check-site.ts.snap @@ -56,9 +56,9 @@ exports[`site test Component components/checkbox en Page 1`] = `3`; exports[`site test Component components/checkbox zh Page 1`] = `3`; -exports[`site test Component components/chat-box en Page 1`] = `1`; +exports[`site test Component components/chatbox en Page 1`] = `1`; -exports[`site test Component components/chat-box zh Page 1`] = `1`; +exports[`site test Component components/chatbox zh Page 1`] = `1`; exports[`site test Component components/collapse en Page 1`] = `2`; From 55fa7b0acaad1bdc409b0a8eb67c60df2edf7aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 00:24:17 +0800 Subject: [PATCH 35/72] docs: update docs --- components/chatbox/demo/stream-output.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chatbox/demo/stream-output.md b/components/chatbox/demo/stream-output.md index 27e52a5e6a9f..10d85de42da7 100644 --- a/components/chatbox/demo/stream-output.md +++ b/components/chatbox/demo/stream-output.md @@ -1,7 +1,7 @@ ## zh-CN -通过设置 `step` 属性,启用流式输出。 +通过设置 `typing` 属性,启用流式输出。 ## en-US -Enable streaming output by setting the `step` prop. +Enable streaming output by setting the `typing` prop. From 2182d102484bfe124ff5068cd042c9bdebb9762c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 09:22:13 +0800 Subject: [PATCH 36/72] demo: update demo --- .../__tests__/__snapshots__/demo-extend.test.ts.snap | 4 ++-- .../chatbox/__tests__/__snapshots__/demo.test.ts.snap | 2 +- components/chatbox/demo/stream-output.md | 7 ------- components/chatbox/demo/typing.md | 7 +++++++ components/chatbox/demo/{stream-output.tsx => typing.tsx} | 0 components/chatbox/index.en-US.md | 2 +- components/chatbox/index.zh-CN.md | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 components/chatbox/demo/stream-output.md create mode 100644 components/chatbox/demo/typing.md rename components/chatbox/demo/{stream-output.tsx => typing.tsx} (100%) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index d2ad853f3b2d..24a5dd5760ca 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -240,7 +240,7 @@ exports[`renders components/chatbox/demo/loading.tsx extend context correctly 1` exports[`renders components/chatbox/demo/loading.tsx extend context correctly 2`] = `[]`; -exports[`renders components/chatbox/demo/stream-output.tsx extend context correctly 1`] = ` +exports[`renders components/chatbox/demo/typing.tsx extend context correctly 1`] = `
@@ -280,4 +280,4 @@ exports[`renders components/chatbox/demo/stream-output.tsx extend context correc
`; -exports[`renders components/chatbox/demo/stream-output.tsx extend context correctly 2`] = `[]`; +exports[`renders components/chatbox/demo/typing.tsx extend context correctly 2`] = `[]`; diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 3a75ef388c2d..86588904062d 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -232,7 +232,7 @@ exports[`renders components/chatbox/demo/loading.tsx correctly 1`] = `
`; -exports[`renders components/chatbox/demo/stream-output.tsx correctly 1`] = ` +exports[`renders components/chatbox/demo/typing.tsx correctly 1`] = `
diff --git a/components/chatbox/demo/stream-output.md b/components/chatbox/demo/stream-output.md deleted file mode 100644 index 10d85de42da7..000000000000 --- a/components/chatbox/demo/stream-output.md +++ /dev/null @@ -1,7 +0,0 @@ -## zh-CN - -通过设置 `typing` 属性,启用流式输出。 - -## en-US - -Enable streaming output by setting the `typing` prop. diff --git a/components/chatbox/demo/typing.md b/components/chatbox/demo/typing.md new file mode 100644 index 000000000000..0715f21b0875 --- /dev/null +++ b/components/chatbox/demo/typing.md @@ -0,0 +1,7 @@ +## zh-CN + +通过设置 `typing` 属性,开启打字效果。 + +## en-US + +Enable typing output by setting the `typing` prop. diff --git a/components/chatbox/demo/stream-output.tsx b/components/chatbox/demo/typing.tsx similarity index 100% rename from components/chatbox/demo/stream-output.tsx rename to components/chatbox/demo/typing.tsx diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md index 72eb43e74553..f53315425a5b 100644 --- a/components/chatbox/index.en-US.md +++ b/components/chatbox/index.en-US.md @@ -19,8 +19,8 @@ Often used when chatting. Basic Placement and avatar -Stream output Loading +Typing effect Content render ## API diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index fa6c2e9923d9..fbb2c6b2e0d2 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -20,8 +20,8 @@ tag: 5.17.0 基本 支持位置和头像 -流式输出 加载中 +打字效果 自定义渲染 ## API From 9ee1fe638e281c5347e2718d588c2b63459d621d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 11:40:15 +0800 Subject: [PATCH 37/72] test: add test case --- components/chatbox/__tests__/index.test.tsx | 20 ++++++++++++++++- components/chatbox/hooks/useTypingValue.ts | 25 +++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 1ad8430a5b0a..3eec6087a5e6 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -1,13 +1,23 @@ +/* eslint-disable no-await-in-loop */ import React from 'react'; import Chatbox from '..'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; -import { render } from '../../../tests/utils'; +import { render, waitFakeTimer } from '../../../tests/utils'; describe('chatbox', () => { mountTest(() => ); rtlTest(() => ); + + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + }); + it('Chatbox component work', () => { const { container } = render(); const element = container.querySelector('.ant-chatbox'); @@ -62,4 +72,12 @@ describe('chatbox', () => { rerender(); expect(element).toHaveClass('ant-chatbox-end'); }); + + it('Chatbox support typing effect', async () => { + const { container } = render(); + const element = container.querySelector('.ant-chatbox .ant-chatbox-content'); + expect(element?.textContent).toBe('你'); + await waitFakeTimer(); + expect(element?.textContent).toBe('你好你好你好'); + }); }); diff --git a/components/chatbox/hooks/useTypingValue.ts b/components/chatbox/hooks/useTypingValue.ts index 9bf2daaa1826..9deaa290bc61 100644 --- a/components/chatbox/hooks/useTypingValue.ts +++ b/components/chatbox/hooks/useTypingValue.ts @@ -2,21 +2,28 @@ import React from 'react'; import type { ChatboxProps, TypingOption } from '..'; +function isObject(value: any): value is Record { + return value && typeof value === 'object'; +} + const defaultTypingOption: Required = { step: 1, interval: 100, }; const useTypingValue = (typing: ChatboxProps['typing']) => { - const mergedTyping = React.useMemo | false>(() => { - if (typing && typeof typing === 'object') { - return { ...defaultTypingOption, ...typing }; - } - if (typing === true) { - return defaultTypingOption; - } - return false; - }, [typing]); + const mergedTyping = React.useMemo | false>( + () => { + if (isObject(typing)) { + return { ...defaultTypingOption, ...typing }; + } + if (typing === true) { + return defaultTypingOption; + } + return false; + }, + isObject(typing) ? [typing.interval, typing.step] : [typing], + ); return mergedTyping; }; From 4c37e55d40a69af79c6dda4dc1b46d16da30032a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 11:40:50 +0800 Subject: [PATCH 38/72] test: add test case --- components/chatbox/__tests__/index.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 3eec6087a5e6..3750b914b337 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-await-in-loop */ import React from 'react'; import Chatbox from '..'; From ccdf17a6329d3b42d064028013ca4dff5ff559a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 13:58:19 +0800 Subject: [PATCH 39/72] feat: CP support Chatbox --- components/chatbox/hooks/useTypedEffect.ts | 2 +- components/chatbox/hooks/useTypingValue.ts | 2 +- components/chatbox/index.tsx | 63 ++++++++++------------ components/chatbox/interface.ts | 33 ++++++++++++ components/config-provider/context.ts | 4 ++ components/config-provider/index.en-US.md | 1 + components/config-provider/index.tsx | 4 ++ components/config-provider/index.zh-CN.md | 1 + components/index.ts | 2 +- 9 files changed, 73 insertions(+), 39 deletions(-) create mode 100644 components/chatbox/interface.ts diff --git a/components/chatbox/hooks/useTypedEffect.ts b/components/chatbox/hooks/useTypedEffect.ts index 0e965880b8e2..67620bb97baf 100644 --- a/components/chatbox/hooks/useTypedEffect.ts +++ b/components/chatbox/hooks/useTypedEffect.ts @@ -1,6 +1,6 @@ import React from 'react'; -import type { TypingOption } from '..'; +import type { TypingOption } from '../interface'; const useTypedEffect = (content?: string, mergedTyping?: Required | false) => { const [typedContent, setTypedContent] = React.useState(''); diff --git a/components/chatbox/hooks/useTypingValue.ts b/components/chatbox/hooks/useTypingValue.ts index 9deaa290bc61..bd1975327f54 100644 --- a/components/chatbox/hooks/useTypingValue.ts +++ b/components/chatbox/hooks/useTypingValue.ts @@ -1,6 +1,6 @@ import React from 'react'; -import type { ChatboxProps, TypingOption } from '..'; +import type { ChatboxProps, TypingOption } from '../interface'; function isObject(value: any): value is Record { return value && typeof value === 'object'; diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index fed2ee686033..7e831aae6791 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -1,45 +1,22 @@ import React from 'react'; -import classNames from 'classnames'; +import classnames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; import Spin from '../spin'; import useTypedEffect from './hooks/useTypedEffect'; import useTypingValue from './hooks/useTypingValue'; +import type { ChatboxProps } from './interface'; import useStyle from './style'; -export interface TypingOption { - /** - * @since 5.17.0 - * @default 1 - */ - step?: number; - /** - * @since 5.17.0 - * @default 100 - */ - interval?: number; -} - -export interface ChatboxProps { - prefixCls?: string; - className?: string; - rootClassName?: string; - style?: React.CSSProperties; - avatar?: React.ReactNode; - placement?: 'start' | 'end'; - loading?: boolean; - typing?: boolean | TypingOption; - content: string; - contentRender?: (content?: string) => React.ReactNode; -} - const Chatbox: React.FC = (props) => { const { prefixCls: customizePrefixCls, className, rootClassName, style, + classNames, + styles, avatar, placement = 'start', loading = false, @@ -47,7 +24,7 @@ const Chatbox: React.FC = (props) => { content, contentRender, } = props; - const { direction, getPrefixCls } = React.useContext(ConfigContext); + const { direction, chatbox, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); @@ -55,9 +32,10 @@ const Chatbox: React.FC = (props) => { const { typedContent, showCursor } = useTypedEffect(content, mergedTyping); - const mergedCls = classNames( + const mergedCls = classnames( className, rootClassName, + chatbox?.className, prefixCls, hashId, cssVarCls, @@ -65,6 +43,19 @@ const Chatbox: React.FC = (props) => { { [`${prefixCls}-rtl`]: direction === 'rtl' }, ); + const mergedAvatarCls = classnames( + `${prefixCls}-avatar`, + classNames?.avatar, + chatbox?.classNames?.avatar, + ); + + const mergedContentCls = classnames( + `${prefixCls}-content`, + classNames?.content, + chatbox?.classNames?.content, + { [`${prefixCls}-content-cursorBlink`]: showCursor && !loading }, + ); + const mergedContent = React.useMemo(() => { if (loading) { return ; @@ -76,13 +67,13 @@ const Chatbox: React.FC = (props) => { }, [content, loading, mergedTyping, typedContent]); return wrapCSSVar( -
- {avatar &&
{avatar}
} -
+
+ {avatar && ( +
+ {avatar} +
+ )} +
{contentRender ? contentRender(content) : mergedContent}
, diff --git a/components/chatbox/interface.ts b/components/chatbox/interface.ts new file mode 100644 index 000000000000..c89d5710c47b --- /dev/null +++ b/components/chatbox/interface.ts @@ -0,0 +1,33 @@ +export interface TypingOption { + /** + * @since 5.17.0 + * @default 1 + */ + step?: number; + /** + * @since 5.17.0 + * @default 100 + */ + interval?: number; +} + +export interface ChatboxProps { + prefixCls?: string; + rootClassName?: string; + className?: string; + style?: React.CSSProperties; + classNames?: { + avatar?: string; + content?: string; + }; + styles?: { + avatar?: React.CSSProperties; + content?: React.CSSProperties; + }; + avatar?: React.ReactNode; + placement?: 'start' | 'end'; + loading?: boolean; + typing?: boolean | TypingOption; + content: string; + contentRender?: (content?: string) => React.ReactNode; +} diff --git a/components/config-provider/context.ts b/components/config-provider/context.ts index a17eb6b1e28c..bf389c774a73 100644 --- a/components/config-provider/context.ts +++ b/components/config-provider/context.ts @@ -6,6 +6,7 @@ import type { AlertProps } from '../alert'; import type { BadgeProps } from '../badge'; import type { ButtonProps } from '../button'; import type { CardProps } from '../card'; +import type { ChatboxProps } from '../chatbox/interface'; import type { CollapseProps } from '../collapse'; import type { DrawerProps } from '../drawer'; import type { FlexProps } from '../flex/interface'; @@ -149,6 +150,8 @@ export type TagConfig = ComponentStyleConfig & Pick; +export type ChatboxConfig = ComponentStyleConfig & Pick; + export type DrawerConfig = ComponentStyleConfig & Pick; @@ -217,6 +220,7 @@ export interface ConfigConsumerProps { calendar?: ComponentStyleConfig; carousel?: ComponentStyleConfig; cascader?: ComponentStyleConfig; + chatbox?: ChatboxConfig; collapse?: CollapseConfig; floatButtonGroup?: FloatButtonGroupConfig; typography?: ComponentStyleConfig; diff --git a/components/config-provider/index.en-US.md b/components/config-provider/index.en-US.md index 9c5717683df9..f003e1f077ed 100644 --- a/components/config-provider/index.en-US.md +++ b/components/config-provider/index.en-US.md @@ -106,6 +106,7 @@ const { | breadcrumb | Set Breadcrumb common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | button | Set Button common props | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties }, autoInsertSpace?: boolean } | - | 5.6.0, autoInsertSpace: 5.17.0 | | card | Set Card common props | { className?: string, style?: React.CSSProperties, classNames?: [CardProps\["classNames"\]](/components/card#api), styles?: [CardProps\["styles"\]](/components/card#api) } | - | 5.7.0, `classNames` and `styles`: 5.14.0 | +| chatbox | Set Chatbox common props | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.17.0 | | calendar | Set Calendar common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | carousel | Set Carousel common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | cascader | Set Cascader common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index ec7d7a91f657..c05fb70a086d 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -19,6 +19,7 @@ import type { BadgeConfig, ButtonConfig, CardConfig, + ChatboxConfig, CollapseConfig, ComponentStyleConfig, ConfigConsumerProps, @@ -161,6 +162,7 @@ export interface ConfigProviderProps { calendar?: ComponentStyleConfig; carousel?: ComponentStyleConfig; cascader?: ComponentStyleConfig; + chatbox?: ChatboxConfig; collapse?: CollapseConfig; divider?: ComponentStyleConfig; drawer?: DrawerConfig; @@ -319,6 +321,7 @@ const ProviderChildren: React.FC = (props) => { calendar, carousel, cascader, + chatbox, collapse, typography, checkbox, @@ -417,6 +420,7 @@ const ProviderChildren: React.FC = (props) => { cascader, collapse, typography, + chatbox, checkbox, descriptions, divider, diff --git a/components/config-provider/index.zh-CN.md b/components/config-provider/index.zh-CN.md index f6fedb44675c..96d3d3bc1c33 100644 --- a/components/config-provider/index.zh-CN.md +++ b/components/config-provider/index.zh-CN.md @@ -109,6 +109,7 @@ const { | button | 设置 Button 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties }, autoInsertSpace?: boolean } | - | 5.6.0, autoInsertSpace: 5.17.0 | | calendar | 设置 Calendar 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | card | 设置 Card 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [CardProps\["classNames"\]](/components/card-cn#api), styles?: [CardProps\["styles"\]](/components/card-cn#api) } | - | 5.7.0, `classNames` 和 `styles`: 5.14.0 | +| chatbox | 设置 Chatbox 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.17.0 | | carousel | 设置 Carousel 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | cascader | 设置 Cascader 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | checkbox | 设置 Checkbox 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | diff --git a/components/index.ts b/components/index.ts index 9974ce0352d0..80232ae3cbe6 100644 --- a/components/index.ts +++ b/components/index.ts @@ -29,7 +29,7 @@ export type { CarouselProps } from './carousel'; export { default as Cascader } from './cascader'; export type { CascaderProps } from './cascader'; export { default as Chatbox } from './chatbox'; -export type { ChatboxProps } from './chatbox'; +export type { ChatboxProps } from './chatbox/interface'; export { default as Checkbox } from './checkbox'; export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox'; export { default as Col } from './col'; From 322bbb052e4e4d334274a583b39bbd6bc1ee2800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 14:14:59 +0800 Subject: [PATCH 40/72] test: add test case --- components/chatbox/__tests__/index.test.tsx | 22 ++++++++++++++++ .../config-provider/__tests__/style.test.tsx | 25 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 3750b914b337..4bbda57c6e93 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -79,4 +79,26 @@ describe('chatbox', () => { await waitFakeTimer(); expect(element?.textContent).toBe('你好你好你好'); }); + + it('Chatbox Should support Chatbox', () => { + const { container } = render( + avatar} + className="test-className" + classNames={{ avatar: 'test-avatar', content: 'test-content' }} + style={{ backgroundColor: 'green' }} + styles={{ avatar: { color: 'red' }, content: { color: 'blue' } }} + />, + ); + const element = container.querySelector('.ant-chatbox'); + const avatarElement = element?.querySelector('.ant-chatbox-avatar'); + const contentElement = element?.querySelector('.ant-chatbox-content'); + expect(element).toHaveClass('test-className'); + expect(avatarElement).toHaveClass('test-avatar'); + expect(contentElement).toHaveClass('test-content'); + expect(element).toHaveStyle({ backgroundColor: 'green' }); + expect(avatarElement).toHaveStyle({ color: 'red' }); + expect(contentElement).toHaveStyle({ color: 'blue' }); + }); }); diff --git a/components/config-provider/__tests__/style.test.tsx b/components/config-provider/__tests__/style.test.tsx index bfbbbef46e62..4488f4cb69a8 100644 --- a/components/config-provider/__tests__/style.test.tsx +++ b/components/config-provider/__tests__/style.test.tsx @@ -11,6 +11,7 @@ import Calendar from '../../calendar'; import Card from '../../card'; import Carousel from '../../carousel'; import Cascader from '../../cascader'; +import Chatbox from '../../chatbox'; import Checkbox from '../../checkbox'; import Collapse from '../../collapse'; import ColorPicker from '../../color-picker'; @@ -1575,4 +1576,28 @@ describe('ConfigProvider support style and className props', () => { const element = container.querySelector('.test-cp-icon'); expect(element).toBeTruthy(); }); + + it('CP Should support Chatbox', () => { + const { container } = render( + + avatar} /> + , + ); + const element = container.querySelector('.ant-chatbox'); + const avatarElement = element?.querySelector('.ant-chatbox-avatar'); + const contentElement = element?.querySelector('.ant-chatbox-content'); + expect(element).toHaveClass('test-cp-className'); + expect(avatarElement).toHaveClass('test-cp-avatar'); + expect(contentElement).toHaveClass('test-cp-content'); + expect(element).toHaveStyle({ backgroundColor: 'green' }); + expect(avatarElement).toHaveStyle({ color: 'red' }); + expect(contentElement).toHaveStyle({ color: 'blue' }); + }); }); From ebe1177dccfc23ecbcd040da079fe5ef93842ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 14:16:27 +0800 Subject: [PATCH 41/72] fix: fix type export --- components/chatbox/index.tsx | 2 ++ components/index.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index 7e831aae6791..f2ef694cc445 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -84,4 +84,6 @@ if (process.env.NODE_ENV !== 'production') { Chatbox.displayName = 'Chatbox'; } +export type { ChatboxProps }; + export default Chatbox; diff --git a/components/index.ts b/components/index.ts index 80232ae3cbe6..9974ce0352d0 100644 --- a/components/index.ts +++ b/components/index.ts @@ -29,7 +29,7 @@ export type { CarouselProps } from './carousel'; export { default as Cascader } from './cascader'; export type { CascaderProps } from './cascader'; export { default as Chatbox } from './chatbox'; -export type { ChatboxProps } from './chatbox/interface'; +export type { ChatboxProps } from './chatbox'; export { default as Checkbox } from './checkbox'; export type { CheckboxOptionType, CheckboxProps, CheckboxRef } from './checkbox'; export { default as Col } from './col'; From 0d370626402395b0af67375a10b460ee8017034c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 14:52:48 +0800 Subject: [PATCH 42/72] demo: update demo --- .../__snapshots__/demo-extend.test.ts.snap | 48 ++++++++++++++++++- .../__tests__/__snapshots__/demo.test.ts.snap | 48 ++++++++++++++++++- .../chatbox/demo/avatar-and-placement.tsx | 20 +++++++- 3 files changed, 112 insertions(+), 4 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 24a5dd5760ca..e646113ac460 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -41,6 +41,29 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx extend context Good morning, how are you ?
+
+ +
+ What a beautiful day ! +
+
@@ -75,7 +98,30 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx extend context
- I'm fine, thank you ! + Hi, Good morning, I'm fine ! +
+
+
+ +
+ thank you !
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 86588904062d..cc80cdc24b86 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -41,6 +41,29 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx correctly 1`] Good morning, how are you ?
+
+ +
+ What a beautiful day ! +
+
@@ -75,7 +98,30 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx correctly 1`]
- I'm fine, thank you ! + Hi, Good morning, I'm fine ! +
+
+
+ +
+ thank you !
diff --git a/components/chatbox/demo/avatar-and-placement.tsx b/components/chatbox/demo/avatar-and-placement.tsx index d007a616db38..1adc06c408b4 100644 --- a/components/chatbox/demo/avatar-and-placement.tsx +++ b/components/chatbox/demo/avatar-and-placement.tsx @@ -12,18 +12,34 @@ const barAvatar: React.CSSProperties = { backgroundColor: '#87d068', }; +const hideAvatar: React.CSSProperties = { + visibility: 'hidden', +}; + const App: React.FC = () => ( } style={fooAvatar} />} /> } + /> + } style={barAvatar} />} /> + } + /> ); From 92607b4a671ad7110ae50440bf8edaebb4e91904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 17:19:40 +0800 Subject: [PATCH 43/72] feat: add loading --- .../__snapshots__/demo-extend.test.ts.snap | 33 ++++++-------- .../__tests__/__snapshots__/demo.test.ts.snap | 33 ++++++-------- components/chatbox/__tests__/index.test.tsx | 5 +-- components/chatbox/index.tsx | 4 +- components/chatbox/loading.tsx | 23 ++++++++++ components/chatbox/style/index.ts | 43 ++++++++++++++++++- 6 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 components/chatbox/loading.tsx diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index e646113ac460..58c1e775f80b 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -232,28 +232,19 @@ exports[`renders components/chatbox/demo/loading.tsx extend context correctly 1`
-
- - - - - - -
+ + + +
-
- - - - - - -
+ + + +
{ it('Chatbox support loading', () => { const { container } = render(); - expect( - container.querySelector('.ant-chatbox .ant-spin.ant-spin-spinning'), - ).toBeTruthy(); + const selectors = '.ant-chatbox .ant-chatbox-content .ant-chatbox-dot'; + expect(container.querySelector(selectors)).toBeTruthy(); }); it('Chatbox support placement', () => { diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index f2ef694cc445..3c8f08e708a1 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -3,10 +3,10 @@ import classnames from 'classnames'; import { ConfigContext } from '../config-provider'; import type { ConfigConsumerProps } from '../config-provider'; -import Spin from '../spin'; import useTypedEffect from './hooks/useTypedEffect'; import useTypingValue from './hooks/useTypingValue'; import type { ChatboxProps } from './interface'; +import Loading from './loading'; import useStyle from './style'; const Chatbox: React.FC = (props) => { @@ -58,7 +58,7 @@ const Chatbox: React.FC = (props) => { const mergedContent = React.useMemo(() => { if (loading) { - return ; + return ; } if (mergedTyping !== false) { return typedContent; diff --git a/components/chatbox/loading.tsx b/components/chatbox/loading.tsx new file mode 100644 index 000000000000..32648b0bd137 --- /dev/null +++ b/components/chatbox/loading.tsx @@ -0,0 +1,23 @@ +/* eslint-disable react/no-array-index-key */ +import React from 'react'; + +interface LoadingProps { + prefixCls: string; +} + +const Loading: React.FC = (props) => { + const { prefixCls } = props; + return ( + + {Array.from({ length: 3 }).map((_, i) => ( + + ))} + + ); +}; + +if (process.env.NODE_ENV !== 'production') { + Loading.displayName = 'Loading'; +} + +export default Loading; diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index f2a61255b502..067af7dfc766 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -3,6 +3,18 @@ import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; +const loadingMove = new Keyframes('loadingMove', { + '0%': { + opacity: 0.3, + }, + '50%': { + opacity: 1, + }, + '100%': { + opacity: 0.3, + }, +}); + const cursorBlink = new Keyframes('cursorBlink', { '0%': { opacity: 1, @@ -29,7 +41,7 @@ const genChatboxStyle: GenerateStyle = (token) => { return { [componentCls]: { display: 'flex', - gap: avatarGap, + columnGap: avatarGap, maxWidth: '100%', [`&${componentCls}-end`]: { justifyContent: 'end', @@ -62,6 +74,35 @@ const genChatboxStyle: GenerateStyle = (token) => { animationName: cursorBlink, animationDuration: '0.6s', animationIterationCount: 'infinite', + animationTimingFunction: 'linear', + }, + [`${componentCls}-dot`]: { + position: 'relative', + display: 'flex', + alignItems: 'center', + height: '100%', + columnGap: token.marginXS, + '&-item': { + backgroundColor: token.colorPrimary, + borderRadius: '100%', + display: 'block', + width: 8, + height: 8, + opacity: 0.3, + animationName: loadingMove, + animationDuration: '1s', + animationIterationCount: 'infinite', + animationTimingFunction: 'linear', + '&:nth-child(1)': { + animationDelay: '0s', + }, + '&:nth-child(2)': { + animationDelay: '0.3s', + }, + '&:nth-child(3)': { + animationDelay: '0.6s', + }, + }, }, }, }, From 1ebe32bbe7d589cd4509f48a2571926b97115208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 17:29:40 +0800 Subject: [PATCH 44/72] fix: fix style --- components/chatbox/style/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 067af7dfc766..d076a15181be 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -6,12 +6,15 @@ import { genStyleHooks, mergeToken } from '../../theme/internal'; const loadingMove = new Keyframes('loadingMove', { '0%': { opacity: 0.3, + transform: 'scale(1)', }, '50%': { opacity: 1, + transform: 'scale(1.5)', }, '100%': { opacity: 0.3, + transform: 'scale(1)', }, }); @@ -86,9 +89,10 @@ const genChatboxStyle: GenerateStyle = (token) => { backgroundColor: token.colorPrimary, borderRadius: '100%', display: 'block', - width: 8, - height: 8, + width: 6, + height: 6, opacity: 0.3, + transform: 'scale(1)', animationName: loadingMove, animationDuration: '1s', animationIterationCount: 'infinite', From 2b258f19629c00aeaa880d799076fb20afd9f4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 17:40:36 +0800 Subject: [PATCH 45/72] fix: fix --- components/chatbox/style/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index d076a15181be..437e48b6689f 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -3,19 +3,15 @@ import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; -const loadingMove = new Keyframes('loadingMove', { +const loadingBlink = new Keyframes('loadingBlink', { '0%': { opacity: 0.3, transform: 'scale(1)', }, - '50%': { + '100%': { opacity: 1, transform: 'scale(1.5)', }, - '100%': { - opacity: 0.3, - transform: 'scale(1)', - }, }); const cursorBlink = new Keyframes('cursorBlink', { @@ -93,10 +89,11 @@ const genChatboxStyle: GenerateStyle = (token) => { height: 6, opacity: 0.3, transform: 'scale(1)', - animationName: loadingMove, - animationDuration: '1s', + animationName: loadingBlink, + animationDuration: '0.6s', animationIterationCount: 'infinite', animationTimingFunction: 'linear', + animationDirection: 'alternate', '&:nth-child(1)': { animationDelay: '0s', }, From 3f298f0553be5cadf21e5bb35fe0925b6558c5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 18:09:32 +0800 Subject: [PATCH 46/72] fix: fix style --- components/chatbox/style/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 437e48b6689f..dd40bc95a865 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -58,6 +58,7 @@ const genChatboxStyle: GenerateStyle = (token) => { padding: `${unit(token.paddingSM)} ${unit(token.padding)}`, color: token.colorText, fontSize: token.fontSize, + minHeight: 46, maxWidth: unit(messageMaxWidth), backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, @@ -77,9 +78,9 @@ const genChatboxStyle: GenerateStyle = (token) => { }, [`${componentCls}-dot`]: { position: 'relative', + height: '100%', display: 'flex', alignItems: 'center', - height: '100%', columnGap: token.marginXS, '&-item': { backgroundColor: token.colorPrimary, From d5e66afb4323bf2962ae8b332112248a4e11e062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 20:30:44 +0800 Subject: [PATCH 47/72] fix: fix style --- components/chatbox/style/index.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index dd40bc95a865..1d0f81744439 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -36,7 +36,19 @@ export interface ChatboxToken extends FullToken<'Chatbox'> { } const genChatboxStyle: GenerateStyle = (token) => { - const { componentCls, messageMaxWidth, avatarGap } = token; + const { + componentCls, + fontSize, + lineHeight, + messageMaxWidth, + avatarGap, + paddingSM, + padding, + paddingXXS, + marginXS, + colorText, + calc, + } = token; return { [componentCls]: { display: 'flex', @@ -55,10 +67,11 @@ const genChatboxStyle: GenerateStyle = (token) => { }, [`& ${componentCls}-content`]: { position: 'relative', - padding: `${unit(token.paddingSM)} ${unit(token.padding)}`, - color: token.colorText, + padding: `${unit(paddingSM)} ${unit(padding)}`, + color: colorText, fontSize: token.fontSize, - minHeight: 46, + lineHeight: token.lineHeight, + minHeight: calc(paddingSM).mul(2).add(calc(lineHeight).mul(fontSize)).equal(), maxWidth: unit(messageMaxWidth), backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, @@ -81,7 +94,8 @@ const genChatboxStyle: GenerateStyle = (token) => { height: '100%', display: 'flex', alignItems: 'center', - columnGap: token.marginXS, + columnGap: marginXS, + padding: `0 ${unit(paddingXXS)}`, '&-item': { backgroundColor: token.colorPrimary, borderRadius: '100%', From 6c1f4bc644f50037631064c84b9087db89060c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 21:54:20 +0800 Subject: [PATCH 48/72] demo: update demo --- .../chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap | 4 ++-- components/chatbox/__tests__/__snapshots__/demo.test.ts.snap | 4 ++-- components/chatbox/demo/avatar-and-placement.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 58c1e775f80b..d36e83d5816f 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -98,7 +98,7 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx extend context
- Hi, Good morning, I'm fine ! + Hi, good morning, I'm fine !
- thank you ! + Thank you !
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 29c320405e52..2b96a1e61b12 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -98,7 +98,7 @@ exports[`renders components/chatbox/demo/avatar-and-placement.tsx correctly 1`]
- Hi, Good morning, I'm fine ! + Hi, good morning, I'm fine !
- thank you ! + Thank you !
diff --git a/components/chatbox/demo/avatar-and-placement.tsx b/components/chatbox/demo/avatar-and-placement.tsx index 1adc06c408b4..02f7ab2adffb 100644 --- a/components/chatbox/demo/avatar-and-placement.tsx +++ b/components/chatbox/demo/avatar-and-placement.tsx @@ -31,12 +31,12 @@ const App: React.FC = () => ( /> } style={barAvatar} />} /> } /> From 8a01906a948aa3ce0a2bbed4d8f41d7c741406b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 16 Apr 2024 23:07:52 +0800 Subject: [PATCH 49/72] chore: update style --- components/chatbox/style/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 1d0f81744439..2302fd32272c 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -31,8 +31,7 @@ export interface ComponentToken { } export interface ChatboxToken extends FullToken<'Chatbox'> { - messageMaxWidth: number; - avatarGap: number; + maxWidthContent: number; } const genChatboxStyle: GenerateStyle = (token) => { @@ -40,10 +39,9 @@ const genChatboxStyle: GenerateStyle = (token) => { componentCls, fontSize, lineHeight, - messageMaxWidth, - avatarGap, paddingSM, padding, + paddingXS, paddingXXS, marginXS, colorText, @@ -52,7 +50,7 @@ const genChatboxStyle: GenerateStyle = (token) => { return { [componentCls]: { display: 'flex', - columnGap: avatarGap, + columnGap: paddingXS, maxWidth: '100%', [`&${componentCls}-end`]: { justifyContent: 'end', @@ -72,7 +70,7 @@ const genChatboxStyle: GenerateStyle = (token) => { fontSize: token.fontSize, lineHeight: token.lineHeight, minHeight: calc(paddingSM).mul(2).add(calc(lineHeight).mul(fontSize)).equal(), - maxWidth: unit(messageMaxWidth), + maxWidth: unit(token.maxWidthContent), backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, @@ -133,8 +131,7 @@ export default genStyleHooks<'Chatbox'>( 'Chatbox', (token) => { const chatBoxToken = mergeToken(token, { - messageMaxWidth: 720, - avatarGap: token.paddingXS, + maxWidthContent: 720, }); return genChatboxStyle(chatBoxToken); }, From e74db08b2a5d2b42f1829acc9750e61a9ce3ac5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 09:58:25 +0800 Subject: [PATCH 50/72] docs: add Semantic DOM --- components/chatbox/demo/_semantic.tsx | 36 +++++++++++++++++++++++++++ components/chatbox/index.en-US.md | 6 +++++ components/chatbox/index.zh-CN.md | 6 +++++ 3 files changed, 48 insertions(+) create mode 100644 components/chatbox/demo/_semantic.tsx diff --git a/components/chatbox/demo/_semantic.tsx b/components/chatbox/demo/_semantic.tsx new file mode 100644 index 000000000000..6e2fc3292bfa --- /dev/null +++ b/components/chatbox/demo/_semantic.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { UserOutlined } from '@ant-design/icons'; +import { Avatar, Chatbox } from 'antd'; + +import SemanticPreview from '../../../.dumi/components/SemanticPreview'; +import useLocale from '../../../.dumi/hooks/useLocale'; + +const locales = { + cn: { + avatar: '头像的外层容器', + content: '聊天内容的容器', + }, + en: { + avatar: 'Wrapper element of the avatar', + content: 'Wrapper element of the content', + }, +}; + +const App: React.FC = () => { + const [locale] = useLocale(locales); + return ( + + } />} + /> + + ); +}; + +export default App; diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md index f53315425a5b..969c454f1eb4 100644 --- a/components/chatbox/index.en-US.md +++ b/components/chatbox/index.en-US.md @@ -34,12 +34,18 @@ Common props ref:[Common props](/docs/react/common-props) | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | | avatar | Avatar component | `React.ReactNode` | - | | +| classNames | Semantic DOM class | [Record](#semantic-dom) | - | | +| styles | Semantic DOM style | [Record](#semantic-dom) | - | | | placement | Direction of Message | `start \| end` | `start` | | | loading | Loading state of Message | `boolean` | - | | | typing | Show message with typing motion | `boolean \| { step?: number, interval?: number }` | `false` | | | content | Content of Chatbox | `string` | - | | | contentRender | Display cuztomized content (If use `contentRender` prop, the typed effect needs to be implemented by yourself) | `(content?: string) => ReactNode` | - | | +## Semantic DOM + + + ## Design Token diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index fbb2c6b2e0d2..73cf48306695 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -35,12 +35,18 @@ tag: 5.17.0 | 属性 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | | avatar | 展示头像 | `React.ReactNode` | - | | +| classNames | 语义化结构 class | [Record](#semantic-dom) | - | | +| styles | 语义化结构 style | [Record](#semantic-dom) | - | | | placement | 信息位置 | `start \| end` | `start` | | | loading | 聊天内容加载状态 | `boolean` | - | | | typing | 设置聊天内容打字动画 | `boolean \| { step?: number, interval?: number }` | `false` | | | content | 聊天内容 | `string` | - | | | contentRender | 自定义渲染内容(使用 `contentRender` 的话,打字效果需要自行实现) | `(content?: string) => ReactNode` | - | | +## Semantic DOM + + + ## 主题变量(Design Token) From 6c3aac164c636f112ec3e19180568b48026585bb Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 17 Apr 2024 15:19:12 +0800 Subject: [PATCH 51/72] Update components/chatbox/style/index.ts Co-authored-by: MadCcc Signed-off-by: lijianan <574980606@qq.com> --- components/chatbox/style/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 2302fd32272c..38a25996da2f 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -31,7 +31,7 @@ export interface ComponentToken { } export interface ChatboxToken extends FullToken<'Chatbox'> { - maxWidthContent: number; + chatboxContentMaxWidth: number; } const genChatboxStyle: GenerateStyle = (token) => { From 651413713967ff0bf5c503200a526e8c159b6028 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 17 Apr 2024 15:19:30 +0800 Subject: [PATCH 52/72] Update components/chatbox/style/index.ts Co-authored-by: MadCcc Signed-off-by: lijianan <574980606@qq.com> --- components/chatbox/style/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 38a25996da2f..3b88b5d6a336 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -70,7 +70,7 @@ const genChatboxStyle: GenerateStyle = (token) => { fontSize: token.fontSize, lineHeight: token.lineHeight, minHeight: calc(paddingSM).mul(2).add(calc(lineHeight).mul(fontSize)).equal(), - maxWidth: unit(token.maxWidthContent), + maxWidth: token.maxWidthContent, backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, From 2bd530996d46a413f13ea46b6a87fb26548f25b1 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 17 Apr 2024 15:20:09 +0800 Subject: [PATCH 53/72] Update components/chatbox/style/index.ts Co-authored-by: MadCcc Signed-off-by: lijianan <574980606@qq.com> --- components/chatbox/style/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 3b88b5d6a336..347baf68862d 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -74,7 +74,7 @@ const genChatboxStyle: GenerateStyle = (token) => { backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, - '&-cursorBlink::after': { + '&-cursor-blink::after': { display: 'inline-block', content: '"|"', fontWeight: 900, From 2499d6fbb42734f1b7b503ae571efce2ea263ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 15:23:52 +0800 Subject: [PATCH 54/72] fix: fix --- components/chatbox/index.tsx | 2 +- components/chatbox/style/index.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index 3c8f08e708a1..33fa9df90cb6 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -53,7 +53,7 @@ const Chatbox: React.FC = (props) => { `${prefixCls}-content`, classNames?.content, chatbox?.classNames?.content, - { [`${prefixCls}-content-cursorBlink`]: showCursor && !loading }, + { [`${prefixCls}-content-cursor-blink`]: showCursor && !loading }, ); const mergedContent = React.useMemo(() => { diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 347baf68862d..4fe50370c1da 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -70,7 +70,7 @@ const genChatboxStyle: GenerateStyle = (token) => { fontSize: token.fontSize, lineHeight: token.lineHeight, minHeight: calc(paddingSM).mul(2).add(calc(lineHeight).mul(fontSize)).equal(), - maxWidth: token.maxWidthContent, + maxWidth: token.chatboxContentMaxWidth, backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, @@ -78,8 +78,6 @@ const genChatboxStyle: GenerateStyle = (token) => { display: 'inline-block', content: '"|"', fontWeight: 900, - transform: 'translate3d(0, -1px, 0)', - marginInlineStart: token.marginXXS, userSelect: 'none', opacity: 1, animationName: cursorBlink, @@ -131,7 +129,7 @@ export default genStyleHooks<'Chatbox'>( 'Chatbox', (token) => { const chatBoxToken = mergeToken(token, { - maxWidthContent: 720, + chatboxContentMaxWidth: 720, }); return genChatboxStyle(chatBoxToken); }, From 992478e981199885ae96b9093857b9b1f1791705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 19:07:42 +0800 Subject: [PATCH 55/72] docs: update docs --- .dumi/theme/common/styles/Markdown.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.dumi/theme/common/styles/Markdown.tsx b/.dumi/theme/common/styles/Markdown.tsx index 3222b57e00bb..692faf0a8f7e 100644 --- a/.dumi/theme/common/styles/Markdown.tsx +++ b/.dumi/theme/common/styles/Markdown.tsx @@ -469,12 +469,6 @@ const GlobalStyle: React.FC = () => { margin-bottom: 0; } } - - .code-box[id^='chatbox-demo-'] { - .code-box-demo { - background-color: ${token.colorBgContainer}; - } - } `} /> ); From dfb7be7ebf4119787ce1c05e3750f014c1c8398d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 20:27:05 +0800 Subject: [PATCH 56/72] fix: fix --- .../__snapshots__/demo-extend.test.ts.snap | 6 +++--- .../__tests__/__snapshots__/demo.test.ts.snap | 6 +++--- components/chatbox/__tests__/index.test.tsx | 2 +- components/chatbox/demo/contentRender.tsx | 2 +- components/chatbox/index.en-US.md | 2 +- components/chatbox/index.tsx | 14 ++++---------- components/chatbox/index.zh-CN.md | 2 +- components/chatbox/style/index.ts | 1 + 8 files changed, 15 insertions(+), 20 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index d36e83d5816f..0af4132960bf 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -178,7 +178,7 @@ exports[`renders components/chatbox/demo/contentRender.tsx extend context correc
-
+

Title

@@ -187,7 +187,7 @@ exports[`renders components/chatbox/demo/contentRender.tsx extend context correc

-
+
`; @@ -310,7 +310,7 @@ exports[`renders components/chatbox/demo/typing.tsx extend context correctly 1`]
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 2b96a1e61b12..8eb7921d0dcd 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -174,7 +174,7 @@ exports[`renders components/chatbox/demo/contentRender.tsx correctly 1`] = `
-
+

Title

@@ -183,7 +183,7 @@ exports[`renders components/chatbox/demo/contentRender.tsx correctly 1`] = `

-
+
`; @@ -302,7 +302,7 @@ exports[`renders components/chatbox/demo/typing.tsx correctly 1`] = `
`; diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 5251c1719d9b..ec89b0c7b941 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -46,7 +46,7 @@ describe('chatbox', () => { const { container } = render(); const selectors = '.ant-chatbox .ant-chatbox-content'; expect(container.querySelector(selectors)).toHaveClass( - 'ant-chatbox-content-cursorBlink', + 'ant-chatbox-content-cursor-blink', ); }); diff --git a/components/chatbox/demo/contentRender.tsx b/components/chatbox/demo/contentRender.tsx index abeb813a75eb..ebc338b64ef1 100644 --- a/components/chatbox/demo/contentRender.tsx +++ b/components/chatbox/demo/contentRender.tsx @@ -11,7 +11,7 @@ const contentRender: ChatboxProps['contentRender'] = (content) => { if (!content) { return null; } - return
; + return ; }; const App: React.FC = () => ( diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md index 969c454f1eb4..5293d0c92a2b 100644 --- a/components/chatbox/index.en-US.md +++ b/components/chatbox/index.en-US.md @@ -40,7 +40,7 @@ Common props ref:[Common props](/docs/react/common-props) | loading | Loading state of Message | `boolean` | - | | | typing | Show message with typing motion | `boolean \| { step?: number, interval?: number }` | `false` | | | content | Content of Chatbox | `string` | - | | -| contentRender | Display cuztomized content (If use `contentRender` prop, the typed effect needs to be implemented by yourself) | `(content?: string) => ReactNode` | - | | +| contentRender | Display cuztomized content | `(content?: string) => ReactNode` | - | | ## Semantic DOM diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index 33fa9df90cb6..d7f8f1aca1e2 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -56,15 +56,9 @@ const Chatbox: React.FC = (props) => { { [`${prefixCls}-content-cursor-blink`]: showCursor && !loading }, ); - const mergedContent = React.useMemo(() => { - if (loading) { - return ; - } - if (mergedTyping !== false) { - return typedContent; - } - return content; - }, [content, loading, mergedTyping, typedContent]); + const mergedText = mergedTyping !== false ? typedContent : content; + + const mergedcontent = contentRender ? contentRender(mergedText) : mergedText; return wrapCSSVar(
@@ -74,7 +68,7 @@ const Chatbox: React.FC = (props) => {
)}
- {contentRender ? contentRender(content) : mergedContent} + {loading ? : mergedcontent}
, ); diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index 73cf48306695..d8dc8055a33c 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -41,7 +41,7 @@ tag: 5.17.0 | loading | 聊天内容加载状态 | `boolean` | - | | | typing | 设置聊天内容打字动画 | `boolean \| { step?: number, interval?: number }` | `false` | | | content | 聊天内容 | `string` | - | | -| contentRender | 自定义渲染内容(使用 `contentRender` 的话,打字效果需要自行实现) | `(content?: string) => ReactNode` | - | | +| contentRender | 自定义渲染内容 | `(content?: string) => ReactNode` | - | | ## Semantic DOM diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 4fe50370c1da..2a2aaa3dbfa5 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -80,6 +80,7 @@ const genChatboxStyle: GenerateStyle = (token) => { fontWeight: 900, userSelect: 'none', opacity: 1, + lineHeight: token.lineHeight, animationName: cursorBlink, animationDuration: '0.6s', animationIterationCount: 'infinite', From a112882f13391a208120d9f018b8b4edb9b56ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 20:28:55 +0800 Subject: [PATCH 57/72] fix: fix --- .../__snapshots__/demo-extend.test.ts.snap | 11 ++--------- .../__tests__/__snapshots__/demo.test.ts.snap | 15 ++------------- components/chatbox/demo/contentRender.tsx | 3 ++- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 0af4132960bf..29ece0f75843 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -176,17 +176,10 @@ exports[`renders components/chatbox/demo/contentRender.tsx extend context correc
-

- Title -

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. -
-… -

+

diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 8eb7921d0dcd..a3dfd90f5cb3 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -172,19 +172,8 @@ exports[`renders components/chatbox/demo/contentRender.tsx correctly 1`] = `
- -

- Title -

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. -
-… -

-
-
+ class="ant-chatbox-content ant-chatbox-content-cursor-blink" + />
`; diff --git a/components/chatbox/demo/contentRender.tsx b/components/chatbox/demo/contentRender.tsx index ebc338b64ef1..4b632eb7163e 100644 --- a/components/chatbox/demo/contentRender.tsx +++ b/components/chatbox/demo/contentRender.tsx @@ -5,7 +5,7 @@ import { Avatar, Chatbox } from 'antd'; import type { ChatboxProps } from 'antd'; import markdownit from 'markdown-it'; -const md = markdownit({ html: true, breaks: true, typographer: true }); +const md = markdownit({ html: true, breaks: true }); const contentRender: ChatboxProps['contentRender'] = (content) => { if (!content) { @@ -16,6 +16,7 @@ const contentRender: ChatboxProps['contentRender'] = (content) => { const App: React.FC = () => ( } />} content={'# Title \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n ...'} contentRender={contentRender} From 412ed48f92dc514d05a7fa73ae10a1dba158862b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 20:55:46 +0800 Subject: [PATCH 58/72] chore: animationDuration 0.6s => 0.8s --- components/chatbox/__tests__/index.test.tsx | 2 +- components/chatbox/style/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index ec89b0c7b941..43dda4822315 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -79,7 +79,7 @@ describe('chatbox', () => { expect(element?.textContent).toBe('你好你好你好'); }); - it('Chatbox Should support Chatbox', () => { + it('Chatbox Should support classNames & styles', () => { const { container } = render( = (token) => { opacity: 1, lineHeight: token.lineHeight, animationName: cursorBlink, - animationDuration: '0.6s', + animationDuration: '0.8s', animationIterationCount: 'infinite', animationTimingFunction: 'linear', }, From e4fe3fc502d61fb235b264d67e8828d9e81cf556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 21:26:08 +0800 Subject: [PATCH 59/72] fix: fix --- components/chatbox/index.tsx | 2 +- components/chatbox/style/index.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index d7f8f1aca1e2..0d011212ab2b 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -53,7 +53,7 @@ const Chatbox: React.FC = (props) => { `${prefixCls}-content`, classNames?.content, chatbox?.classNames?.content, - { [`${prefixCls}-content-cursor-blink`]: showCursor && !loading }, + { [`${prefixCls}-content-cursor-blink`]: showCursor && !loading && !contentRender }, ); const mergedText = mergedTyping !== false ? typedContent : content; diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 27feb9dedf70..9e6f4876cae4 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -31,7 +31,7 @@ export interface ComponentToken { } export interface ChatboxToken extends FullToken<'Chatbox'> { - chatboxContentMaxWidth: number; + chatboxContentMaxWidth: number | string; } const genChatboxStyle: GenerateStyle = (token) => { @@ -129,8 +129,9 @@ export const prepareComponentToken: GetDefaultToken<'Chatbox'> = () => ({ export default genStyleHooks<'Chatbox'>( 'Chatbox', (token) => { + const { paddingXS, calc } = token; const chatBoxToken = mergeToken(token, { - chatboxContentMaxWidth: 720, + chatboxContentMaxWidth: `calc(100% - ${calc(paddingXS).add(32).equal()})`, }); return genChatboxStyle(chatBoxToken); }, From 7cda45bb9af65d1b09fcb422461939c5431fc1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 21:33:20 +0800 Subject: [PATCH 60/72] test: update test --- .../chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap | 2 +- components/chatbox/__tests__/__snapshots__/demo.test.ts.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 29ece0f75843..0f6ec8983393 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -176,7 +176,7 @@ exports[`renders components/chatbox/demo/contentRender.tsx extend context correc
`; From e318875aa4d667d6effda1f6f834831458da21df Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 17 Apr 2024 21:44:34 +0800 Subject: [PATCH 61/72] Update components/chatbox/index.tsx Co-authored-by: afc163 Signed-off-by: lijianan <574980606@qq.com> --- components/chatbox/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index 0d011212ab2b..b73ec7cb1e58 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -58,7 +58,7 @@ const Chatbox: React.FC = (props) => { const mergedText = mergedTyping !== false ? typedContent : content; - const mergedcontent = contentRender ? contentRender(mergedText) : mergedText; + const mergedContent = contentRender ? contentRender(mergedText) : mergedText; return wrapCSSVar(
From 2178cad1ee0e83baf53173c42b13176412cee724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 21:52:54 +0800 Subject: [PATCH 62/72] type: add React.HTMLAttributes --- components/chatbox/index.tsx | 5 +++-- components/chatbox/interface.ts | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index b73ec7cb1e58..5e3a3c65de95 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -23,6 +23,7 @@ const Chatbox: React.FC = (props) => { typing, content, contentRender, + ...otherProps } = props; const { direction, chatbox, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); @@ -61,14 +62,14 @@ const Chatbox: React.FC = (props) => { const mergedContent = contentRender ? contentRender(mergedText) : mergedText; return wrapCSSVar( -
+
{avatar && (
{avatar}
)}
- {loading ? : mergedcontent} + {loading ? : mergedContent}
, ); diff --git a/components/chatbox/interface.ts b/components/chatbox/interface.ts index c89d5710c47b..c7b096fb7276 100644 --- a/components/chatbox/interface.ts +++ b/components/chatbox/interface.ts @@ -11,11 +11,9 @@ export interface TypingOption { interval?: number; } -export interface ChatboxProps { +export interface ChatboxProps extends React.HTMLAttributes { prefixCls?: string; rootClassName?: string; - className?: string; - style?: React.CSSProperties; classNames?: { avatar?: string; content?: string; From 65b212090a69bf36e0b86b5fa112b4496a14782b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 22:44:46 +0800 Subject: [PATCH 63/72] chore: rename --- .../__snapshots__/demo-extend.test.ts.snap | 4 +-- .../__tests__/__snapshots__/demo.test.ts.snap | 4 +-- components/chatbox/__tests__/index.test.tsx | 5 ++-- components/chatbox/hooks/useTypedEffect.ts | 10 +++---- components/chatbox/index.tsx | 12 +++++---- components/chatbox/style/index.ts | 26 +++++++++---------- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 0f6ec8983393..cb828546aa38 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -272,7 +272,7 @@ exports[`renders components/chatbox/demo/loading.tsx extend context correctly 2` exports[`renders components/chatbox/demo/typing.tsx extend context correctly 1`] = `
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 64d09aad798e..09e60f547b80 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -260,7 +260,7 @@ exports[`renders components/chatbox/demo/loading.tsx correctly 1`] = ` exports[`renders components/chatbox/demo/typing.tsx correctly 1`] = `
`; diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 43dda4822315..55d7ca2a30d4 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -44,9 +44,8 @@ describe('chatbox', () => { it('Chatbox support typing', () => { const { container } = render(); - const selectors = '.ant-chatbox .ant-chatbox-content'; - expect(container.querySelector(selectors)).toHaveClass( - 'ant-chatbox-content-cursor-blink', + expect(container.querySelector('.ant-chatbox')).toHaveClass( + 'ant-chatbox-typing', ); }); diff --git a/components/chatbox/hooks/useTypedEffect.ts b/components/chatbox/hooks/useTypedEffect.ts index 67620bb97baf..1565ba5b955e 100644 --- a/components/chatbox/hooks/useTypedEffect.ts +++ b/components/chatbox/hooks/useTypedEffect.ts @@ -4,7 +4,7 @@ import type { TypingOption } from '../interface'; const useTypedEffect = (content?: string, mergedTyping?: Required | false) => { const [typedContent, setTypedContent] = React.useState(''); - const [showCursor, setShowCursor] = React.useState(mergedTyping !== false); + const [isTyping, setIsTyping] = React.useState(mergedTyping !== false); const timerRef = React.useRef>(); @@ -18,7 +18,7 @@ const useTypedEffect = (content?: string, mergedTyping?: Required if (!content || !mergedTyping) { return; } - setShowCursor(true); + setIsTyping(true); let stepCount = 0; const { step, interval } = mergedTyping; @@ -28,7 +28,7 @@ const useTypedEffect = (content?: string, mergedTyping?: Required if (stepCount < content.length) { timerRef.current = setTimeout(typedTimer, interval); } else { - setShowCursor(false); + setIsTyping(false); } }; @@ -36,11 +36,11 @@ const useTypedEffect = (content?: string, mergedTyping?: Required return () => { clearTimer(); - setShowCursor(false); + setIsTyping(false); }; }, [content, mergedTyping]); - return { typedContent, showCursor }; + return { typedContent, isTyping }; }; export default useTypedEffect; diff --git a/components/chatbox/index.tsx b/components/chatbox/index.tsx index 5e3a3c65de95..a48455b10446 100644 --- a/components/chatbox/index.tsx +++ b/components/chatbox/index.tsx @@ -23,7 +23,7 @@ const Chatbox: React.FC = (props) => { typing, content, contentRender, - ...otherProps + ...otherHtmlProps } = props; const { direction, chatbox, getPrefixCls } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('chatbox', customizePrefixCls); @@ -31,7 +31,7 @@ const Chatbox: React.FC = (props) => { const mergedTyping = useTypingValue(typing); - const { typedContent, showCursor } = useTypedEffect(content, mergedTyping); + const { typedContent, isTyping } = useTypedEffect(content, mergedTyping); const mergedCls = classnames( className, @@ -41,7 +41,10 @@ const Chatbox: React.FC = (props) => { hashId, cssVarCls, `${prefixCls}-${placement}`, - { [`${prefixCls}-rtl`]: direction === 'rtl' }, + { + [`${prefixCls}-rtl`]: direction === 'rtl', + [`${prefixCls}-typing`]: isTyping && !loading && !contentRender, + }, ); const mergedAvatarCls = classnames( @@ -54,7 +57,6 @@ const Chatbox: React.FC = (props) => { `${prefixCls}-content`, classNames?.content, chatbox?.classNames?.content, - { [`${prefixCls}-content-cursor-blink`]: showCursor && !loading && !contentRender }, ); const mergedText = mergedTyping !== false ? typedContent : content; @@ -62,7 +64,7 @@ const Chatbox: React.FC = (props) => { const mergedContent = contentRender ? contentRender(mergedText) : mergedText; return wrapCSSVar( -
+
{avatar && (
{avatar} diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 9e6f4876cae4..88ae27428488 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -59,6 +59,18 @@ const genChatboxStyle: GenerateStyle = (token) => { [`&${componentCls}-rtl`]: { direction: 'rtl', }, + [`&${componentCls}-typing ${componentCls}-content::after`]: { + display: 'inline-block', + content: '"|"', + fontWeight: 900, + userSelect: 'none', + opacity: 1, + lineHeight: token.lineHeight, + animationName: cursorBlink, + animationDuration: '0.8s', + animationIterationCount: 'infinite', + animationTimingFunction: 'linear', + }, [`& ${componentCls}-avatar`]: { display: 'inline-flex', justifyContent: 'center', @@ -74,19 +86,7 @@ const genChatboxStyle: GenerateStyle = (token) => { backgroundColor: token.colorInfoBg, borderRadius: token.borderRadiusLG, boxShadow: token.boxShadowTertiary, - '&-cursor-blink::after': { - display: 'inline-block', - content: '"|"', - fontWeight: 900, - userSelect: 'none', - opacity: 1, - lineHeight: token.lineHeight, - animationName: cursorBlink, - animationDuration: '0.8s', - animationIterationCount: 'infinite', - animationTimingFunction: 'linear', - }, - [`${componentCls}-dot`]: { + [`& ${componentCls}-dot`]: { position: 'relative', height: '100%', display: 'flex', From 321fc90e6ec717b9ff467a7d909001af81f243d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 17 Apr 2024 23:26:09 +0800 Subject: [PATCH 64/72] style: update loading --- .../__snapshots__/demo-extend.test.ts.snap | 90 +++++++++++++++++-- .../__tests__/__snapshots__/demo.test.ts.snap | 90 +++++++++++++++++-- components/chatbox/loading.tsx | 35 +++++++- components/chatbox/style/index.ts | 55 ++---------- 4 files changed, 200 insertions(+), 70 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index cb828546aa38..4d0afab8c182 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -228,15 +228,87 @@ exports[`renders components/chatbox/demo/loading.tsx extend context correctly 1` - - - + + + + + + + + + + + + + + + + + + +
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 09e60f547b80..65059f85eace 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -218,15 +218,87 @@ exports[`renders components/chatbox/demo/loading.tsx correctly 1`] = ` - - - + + + + + + + + + + + + + + + + + + +
diff --git a/components/chatbox/loading.tsx b/components/chatbox/loading.tsx index 32648b0bd137..4820af3d9af5 100644 --- a/components/chatbox/loading.tsx +++ b/components/chatbox/loading.tsx @@ -9,9 +9,38 @@ const Loading: React.FC = (props) => { const { prefixCls } = props; return ( - {Array.from({ length: 3 }).map((_, i) => ( - - ))} + + + + + + {Array.from({ length: 3 }).map((_, i) => ( + + + + ))} + + + + + ); }; diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 88ae27428488..194dca6bfb57 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -3,17 +3,6 @@ import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; -const loadingBlink = new Keyframes('loadingBlink', { - '0%': { - opacity: 0.3, - transform: 'scale(1)', - }, - '100%': { - opacity: 1, - transform: 'scale(1.5)', - }, -}); - const cursorBlink = new Keyframes('cursorBlink', { '0%': { opacity: 1, @@ -35,18 +24,8 @@ export interface ChatboxToken extends FullToken<'Chatbox'> { } const genChatboxStyle: GenerateStyle = (token) => { - const { - componentCls, - fontSize, - lineHeight, - paddingSM, - padding, - paddingXS, - paddingXXS, - marginXS, - colorText, - calc, - } = token; + const { componentCls, fontSize, lineHeight, paddingSM, padding, paddingXS, colorText, calc } = + token; return { [componentCls]: { display: 'flex', @@ -89,33 +68,11 @@ const genChatboxStyle: GenerateStyle = (token) => { [`& ${componentCls}-dot`]: { position: 'relative', height: '100%', - display: 'flex', + display: 'inline-flex', + justifyContent: 'center', alignItems: 'center', - columnGap: marginXS, - padding: `0 ${unit(paddingXXS)}`, - '&-item': { - backgroundColor: token.colorPrimary, - borderRadius: '100%', - display: 'block', - width: 6, - height: 6, - opacity: 0.3, - transform: 'scale(1)', - animationName: loadingBlink, - animationDuration: '0.6s', - animationIterationCount: 'infinite', - animationTimingFunction: 'linear', - animationDirection: 'alternate', - '&:nth-child(1)': { - animationDelay: '0s', - }, - '&:nth-child(2)': { - animationDelay: '0.3s', - }, - '&:nth-child(3)': { - animationDelay: '0.6s', - }, - }, + color: token.colorPrimary, + fontSize: token.fontSizeLG, }, }, }, From 05cd3b7b9c5a90d5caf1de1e031e822940a499f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 18 Apr 2024 12:26:23 +0800 Subject: [PATCH 65/72] fix: svg anima => css anima --- .../__snapshots__/demo-extend.test.ts.snap | 90 ++----------------- .../__tests__/__snapshots__/demo.test.ts.snap | 90 ++----------------- components/chatbox/loading.tsx | 39 +------- components/chatbox/style/index.ts | 49 ++++++++-- 4 files changed, 64 insertions(+), 204 deletions(-) diff --git a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap index 4d0afab8c182..cb828546aa38 100644 --- a/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -228,87 +228,15 @@ exports[`renders components/chatbox/demo/loading.tsx extend context correctly 1` - - - - - - - - - - - - - - - - - - - + + +
diff --git a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap index 65059f85eace..09e60f547b80 100644 --- a/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap +++ b/components/chatbox/__tests__/__snapshots__/demo.test.ts.snap @@ -218,87 +218,15 @@ exports[`renders components/chatbox/demo/loading.tsx correctly 1`] = ` - - - - - - - - - - - - - - - - - - - + + +
diff --git a/components/chatbox/loading.tsx b/components/chatbox/loading.tsx index 4820af3d9af5..b094f66e7954 100644 --- a/components/chatbox/loading.tsx +++ b/components/chatbox/loading.tsx @@ -9,44 +9,11 @@ const Loading: React.FC = (props) => { const { prefixCls } = props; return ( - - - - - - {Array.from({ length: 3 }).map((_, i) => ( - - - - ))} - - - - - + {Array.from({ length: 3 }).map((_, i) => ( + + ))} ); }; -if (process.env.NODE_ENV !== 'production') { - Loading.displayName = 'Loading'; -} - export default Loading; diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 194dca6bfb57..12c61c270970 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -3,6 +3,24 @@ import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; +const loadingBlink = new Keyframes('loadingBlink', { + '0%': { + transform: 'translateY(0)', + }, + '25%': { + transform: 'translateY(4px)', + }, + '50%': { + transform: 'translateY(0)', + }, + '75%': { + transform: 'translateY(-4px)', + }, + '100%': { + transform: 'translateY(0)', + }, +}); + const cursorBlink = new Keyframes('cursorBlink', { '0%': { opacity: 1, @@ -39,12 +57,11 @@ const genChatboxStyle: GenerateStyle = (token) => { direction: 'rtl', }, [`&${componentCls}-typing ${componentCls}-content::after`]: { - display: 'inline-block', content: '"|"', fontWeight: 900, userSelect: 'none', opacity: 1, - lineHeight: token.lineHeight, + marginInlineStart: '0.1em', animationName: cursorBlink, animationDuration: '0.8s', animationIterationCount: 'infinite', @@ -68,11 +85,31 @@ const genChatboxStyle: GenerateStyle = (token) => { [`& ${componentCls}-dot`]: { position: 'relative', height: '100%', - display: 'inline-flex', - justifyContent: 'center', + display: 'flex', alignItems: 'center', - color: token.colorPrimary, - fontSize: token.fontSizeLG, + columnGap: token.marginXS, + padding: `0 ${unit(token.paddingXXS)}`, + '&-item': { + backgroundColor: token.colorPrimary, + borderRadius: '100%', + display: 'block', + width: 4, + height: 4, + animationName: loadingBlink, + animationDuration: '0.8s', + animationIterationCount: 'infinite', + animationTimingFunction: 'linear', + animationDirection: 'alternate', + '&:nth-child(1)': { + animationDelay: '0s', + }, + '&:nth-child(2)': { + animationDelay: '0.2s', + }, + '&:nth-child(3)': { + animationDelay: '0.4s', + }, + }, }, }, }, From 2ea1781e2cc807288710a01f62645860376d7f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 18 Apr 2024 12:47:08 +0800 Subject: [PATCH 66/72] fix: fix style --- components/chatbox/style/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 12c61c270970..28bbe932c676 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -92,14 +92,12 @@ const genChatboxStyle: GenerateStyle = (token) => { '&-item': { backgroundColor: token.colorPrimary, borderRadius: '100%', - display: 'block', width: 4, height: 4, animationName: loadingBlink, animationDuration: '0.8s', animationIterationCount: 'infinite', animationTimingFunction: 'linear', - animationDirection: 'alternate', '&:nth-child(1)': { animationDelay: '0s', }, From e3684fff3be2c5c01139eb45242f06d8baba9559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 18 Apr 2024 14:53:05 +0800 Subject: [PATCH 67/72] chore: update css animation style --- components/chatbox/style/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index 28bbe932c676..db2b32a08fdb 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -3,20 +3,20 @@ import { Keyframes, unit } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; import { genStyleHooks, mergeToken } from '../../theme/internal'; -const loadingBlink = new Keyframes('loadingBlink', { +const loadingMove = new Keyframes('loadingMove', { '0%': { transform: 'translateY(0)', }, - '25%': { + '10%': { transform: 'translateY(4px)', }, - '50%': { + '20%': { transform: 'translateY(0)', }, - '75%': { + '30%': { transform: 'translateY(-4px)', }, - '100%': { + '40%': { transform: 'translateY(0)', }, }); @@ -94,8 +94,8 @@ const genChatboxStyle: GenerateStyle = (token) => { borderRadius: '100%', width: 4, height: 4, - animationName: loadingBlink, - animationDuration: '0.8s', + animationName: loadingMove, + animationDuration: '2s', animationIterationCount: 'infinite', animationTimingFunction: 'linear', '&:nth-child(1)': { From c75945ec179f5fd598ba5923f6da04d14714630d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 18 Apr 2024 16:07:44 +0800 Subject: [PATCH 68/72] demo: update demo --- components/chatbox/demo/contentRender.tsx | 37 ++++++++++++++++++----- components/chatbox/demo/typing.tsx | 7 +++-- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/components/chatbox/demo/contentRender.tsx b/components/chatbox/demo/contentRender.tsx index 4b632eb7163e..a0a9e39bc8d7 100644 --- a/components/chatbox/demo/contentRender.tsx +++ b/components/chatbox/demo/contentRender.tsx @@ -5,8 +5,26 @@ import { Avatar, Chatbox } from 'antd'; import type { ChatboxProps } from 'antd'; import markdownit from 'markdown-it'; +const sentences = [ + '# Title \n An enterprise-class UI design language and React UI library. \n ...丨', + '# 标题 \n 企业级产品设计体系,创造高效愉悦的工作体验。\n ...丨', +]; + const md = markdownit({ html: true, breaks: true }); +const useLoopSentence = () => { + const [index, setIndex] = React.useState(0); + const timerRef = React.useRef>(); + React.useEffect(() => { + timerRef.current = setTimeout( + () => setIndex((prevState) => (prevState ? 0 : 1)), + sentences[index].length * 100 + 1000, + ); + return () => clearTimeout(timerRef.current); + }, [index]); + return sentences[index]; +}; + const contentRender: ChatboxProps['contentRender'] = (content) => { if (!content) { return null; @@ -14,13 +32,16 @@ const contentRender: ChatboxProps['contentRender'] = (content) => { return ; }; -const App: React.FC = () => ( - } />} - content={'# Title \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n ...'} - contentRender={contentRender} - /> -); +const App: React.FC = () => { + const content = useLoopSentence(); + return ( + } />} + /> + ); +}; export default App; diff --git a/components/chatbox/demo/typing.tsx b/components/chatbox/demo/typing.tsx index 21b4086fd659..5e432508da83 100644 --- a/components/chatbox/demo/typing.tsx +++ b/components/chatbox/demo/typing.tsx @@ -8,9 +8,10 @@ const useLoopSentence = () => { const [index, setIndex] = React.useState(0); const timerRef = React.useRef>(); React.useEffect(() => { - timerRef.current = setTimeout(() => { - setIndex((prevState) => (prevState ? 0 : 1)); - }, 4000); + timerRef.current = setTimeout( + () => setIndex((prevState) => (prevState ? 0 : 1)), + sentences[index].length * 100 + 1000, + ); return () => clearTimeout(timerRef.current); }, [index]); return sentences[index]; From a82684915a9a00ef65d9a2fa345dcb740a308095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 18 Apr 2024 16:25:46 +0800 Subject: [PATCH 69/72] fix: add last-child --- components/chatbox/style/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chatbox/style/index.ts b/components/chatbox/style/index.ts index db2b32a08fdb..cbf4a86baafb 100644 --- a/components/chatbox/style/index.ts +++ b/components/chatbox/style/index.ts @@ -56,7 +56,7 @@ const genChatboxStyle: GenerateStyle = (token) => { [`&${componentCls}-rtl`]: { direction: 'rtl', }, - [`&${componentCls}-typing ${componentCls}-content::after`]: { + [`&${componentCls}-typing ${componentCls}-content:last-child::after`]: { content: '"|"', fontWeight: 900, userSelect: 'none', From 82ce5b5a9137d8672a8613a32db61e55028b6ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 28 Apr 2024 14:56:03 +0800 Subject: [PATCH 70/72] test: test --- components/chatbox/__tests__/index.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/chatbox/__tests__/index.test.tsx b/components/chatbox/__tests__/index.test.tsx index 55d7ca2a30d4..9289b0f43447 100644 --- a/components/chatbox/__tests__/index.test.tsx +++ b/components/chatbox/__tests__/index.test.tsx @@ -78,7 +78,7 @@ describe('chatbox', () => { expect(element?.textContent).toBe('你好你好你好'); }); - it('Chatbox Should support classNames & styles', () => { + it('Chatbox Should support className & classNames & style & styles', () => { const { container } = render( Date: Sat, 4 May 2024 00:25:36 +0800 Subject: [PATCH 71/72] chore: update since 5.17.0 => 5.18.0 --- components/chatbox/index.en-US.md | 4 ++-- components/chatbox/index.zh-CN.md | 4 ++-- components/chatbox/interface.ts | 4 ++-- components/chatbox/loading.tsx | 9 ++++----- components/config-provider/index.en-US.md | 2 +- components/config-provider/index.zh-CN.md | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/components/chatbox/index.en-US.md b/components/chatbox/index.en-US.md index 5293d0c92a2b..3a141450d7d2 100644 --- a/components/chatbox/index.en-US.md +++ b/components/chatbox/index.en-US.md @@ -7,7 +7,7 @@ cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAA coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*D70qQJJmzhgAAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 -tag: 5.17.0 +tag: 5.18.0 --- ## When To Use @@ -27,7 +27,7 @@ Often used when chatting. Common props ref:[Common props](/docs/react/common-props) -> This component is available since `antd@5.17.0`. +> This component is available since `antd@5.18.0`. ### Chatbox diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index d8dc8055a33c..46bece67c877 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -8,7 +8,7 @@ cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAA coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*D70qQJJmzhgAAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 -tag: 5.17.0 +tag: 5.18.0 --- ## 何时使用 @@ -28,7 +28,7 @@ tag: 5.17.0 通用属性参考:[通用属性](/docs/react/common-props) -> 自 `antd@5.17.0` 版本开始提供该组件。 +> 自 `antd@5.18.0` 版本开始提供该组件。 ### Chatbox diff --git a/components/chatbox/interface.ts b/components/chatbox/interface.ts index c7b096fb7276..fe89f9a255b1 100644 --- a/components/chatbox/interface.ts +++ b/components/chatbox/interface.ts @@ -1,11 +1,11 @@ export interface TypingOption { /** - * @since 5.17.0 + * @since 5.18.0 * @default 1 */ step?: number; /** - * @since 5.17.0 + * @since 5.18.0 * @default 100 */ interval?: number; diff --git a/components/chatbox/loading.tsx b/components/chatbox/loading.tsx index b094f66e7954..5e4bd3afcbe7 100644 --- a/components/chatbox/loading.tsx +++ b/components/chatbox/loading.tsx @@ -1,17 +1,16 @@ -/* eslint-disable react/no-array-index-key */ import React from 'react'; interface LoadingProps { - prefixCls: string; + prefixCls?: string; } const Loading: React.FC = (props) => { const { prefixCls } = props; return ( - {Array.from({ length: 3 }).map((_, i) => ( - - ))} + + + ); }; diff --git a/components/config-provider/index.en-US.md b/components/config-provider/index.en-US.md index f003e1f077ed..c60cf0a8b958 100644 --- a/components/config-provider/index.en-US.md +++ b/components/config-provider/index.en-US.md @@ -106,7 +106,7 @@ const { | breadcrumb | Set Breadcrumb common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | button | Set Button common props | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties }, autoInsertSpace?: boolean } | - | 5.6.0, autoInsertSpace: 5.17.0 | | card | Set Card common props | { className?: string, style?: React.CSSProperties, classNames?: [CardProps\["classNames"\]](/components/card#api), styles?: [CardProps\["styles"\]](/components/card#api) } | - | 5.7.0, `classNames` and `styles`: 5.14.0 | -| chatbox | Set Chatbox common props | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.17.0 | +| chatbox | Set Chatbox common props | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.18.0 | | calendar | Set Calendar common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | carousel | Set Carousel common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | cascader | Set Cascader common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | diff --git a/components/config-provider/index.zh-CN.md b/components/config-provider/index.zh-CN.md index 96d3d3bc1c33..601dce526caa 100644 --- a/components/config-provider/index.zh-CN.md +++ b/components/config-provider/index.zh-CN.md @@ -109,7 +109,7 @@ const { | button | 设置 Button 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties }, autoInsertSpace?: boolean } | - | 5.6.0, autoInsertSpace: 5.17.0 | | calendar | 设置 Calendar 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | card | 设置 Card 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [CardProps\["classNames"\]](/components/card-cn#api), styles?: [CardProps\["styles"\]](/components/card-cn#api) } | - | 5.7.0, `classNames` 和 `styles`: 5.14.0 | -| chatbox | 设置 Chatbox 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.17.0 | +| chatbox | 设置 Chatbox 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.18.0 | | carousel | 设置 Carousel 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | cascader | 设置 Cascader 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | checkbox | 设置 Checkbox 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | From d80985025c3f1d71bcdd9aef3ff4276bac89f8f9 Mon Sep 17 00:00:00 2001 From: li-jia-nan <574980606@qq.com> Date: Sat, 8 Jun 2024 18:03:05 +0800 Subject: [PATCH 72/72] docs: 5.18.0 => 5.19.0 --- components/chatbox/demo/_semantic.tsx | 4 ++-- components/chatbox/index.en-US.md | 4 ++-- components/chatbox/index.zh-CN.md | 4 ++-- components/chatbox/interface.ts | 4 ++-- components/config-provider/index.en-US.md | 2 +- components/config-provider/index.zh-CN.md | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/chatbox/demo/_semantic.tsx b/components/chatbox/demo/_semantic.tsx index 6e2fc3292bfa..6c93b9fce49d 100644 --- a/components/chatbox/demo/_semantic.tsx +++ b/components/chatbox/demo/_semantic.tsx @@ -21,8 +21,8 @@ const App: React.FC = () => { return ( This component is available since `antd@5.18.0`. +> This component is available since `antd@5.19.0`. ### Chatbox diff --git a/components/chatbox/index.zh-CN.md b/components/chatbox/index.zh-CN.md index 46bece67c877..d16f2cc4b5b5 100644 --- a/components/chatbox/index.zh-CN.md +++ b/components/chatbox/index.zh-CN.md @@ -8,7 +8,7 @@ cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*NMvqRZpuJfQAAAAAAA coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*D70qQJJmzhgAAAAAAAAAAAAADrJ8AQ/original demo: cols: 2 -tag: 5.18.0 +tag: 5.19.0 --- ## 何时使用 @@ -28,7 +28,7 @@ tag: 5.18.0 通用属性参考:[通用属性](/docs/react/common-props) -> 自 `antd@5.18.0` 版本开始提供该组件。 +> 自 `antd@5.19.0` 版本开始提供该组件。 ### Chatbox diff --git a/components/chatbox/interface.ts b/components/chatbox/interface.ts index fe89f9a255b1..6d51e133189e 100644 --- a/components/chatbox/interface.ts +++ b/components/chatbox/interface.ts @@ -1,11 +1,11 @@ export interface TypingOption { /** - * @since 5.18.0 + * @since 5.19.0 * @default 1 */ step?: number; /** - * @since 5.18.0 + * @since 5.19.0 * @default 100 */ interval?: number; diff --git a/components/config-provider/index.en-US.md b/components/config-provider/index.en-US.md index 7a1ac034ba9e..5bc4af31baca 100644 --- a/components/config-provider/index.en-US.md +++ b/components/config-provider/index.en-US.md @@ -106,7 +106,7 @@ const { | breadcrumb | Set Breadcrumb common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | button | Set Button common props | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties }, autoInsertSpace?: boolean } | - | 5.6.0, autoInsertSpace: 5.17.0 | | card | Set Card common props | { className?: string, style?: React.CSSProperties, classNames?: [CardProps\["classNames"\]](/components/card#api), styles?: [CardProps\["styles"\]](/components/card#api) } | - | 5.7.0, `classNames` and `styles`: 5.14.0 | -| chatbox | Set Chatbox common props | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.18.0 | +| chatbox | Set Chatbox common props | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.19.0 | | calendar | Set Calendar common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | carousel | Set Carousel common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | cascader | Set Cascader common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | diff --git a/components/config-provider/index.zh-CN.md b/components/config-provider/index.zh-CN.md index c6ad4cf8453a..69bf60f3e1c4 100644 --- a/components/config-provider/index.zh-CN.md +++ b/components/config-provider/index.zh-CN.md @@ -109,7 +109,7 @@ const { | button | 设置 Button 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties }, autoInsertSpace?: boolean } | - | 5.6.0, autoInsertSpace: 5.17.0 | | calendar | 设置 Calendar 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | card | 设置 Card 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [CardProps\["classNames"\]](/components/card-cn#api), styles?: [CardProps\["styles"\]](/components/card-cn#api) } | - | 5.7.0, `classNames` 和 `styles`: 5.14.0 | -| chatbox | 设置 Chatbox 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.18.0 | +| chatbox | 设置 Chatbox 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { avatar?: string; content?: string; }, styles?: { avatar?: CSSProperties, content?: CSSProperties } } | - | 5.19.0 | | carousel | 设置 Carousel 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | cascader | 设置 Cascader 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | checkbox | 设置 Checkbox 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |