logoAnt Design X

DesignDevelopmentComponentsX SDKX MarkdownPlayground
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
  • Confirmation
    • Think
    • ThoughtChain
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Feedback
    • Actions
  • Tools
    • useXAgent
    • useXChat
    • XStream
    • XRequest
    • XProvider

Bubble

A bubble component for chat.
Importimport { Bubble } from "@ant-design/x";
Sourcecomponents/bubble
Docs
Edit this pageChangelog

Resources

Ant Design
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

Often used when chatting.

Examples

API

Common Props Reference: Common Props

Bubble

AttributesDescriptionTypeDefaultVersion
prefixClsCustom class prefixesstring--
rootStyleRoot Node StyleReact.CSSProperties--
stylesSemantic structure styleRecord<SemanticDOM, CSSProperties>-
rootClassNameRoot node class namestring--
classNamesSemantic structure classRecord<SemanticDOM, string>-
placementBubble Locationstart | endstart-
loadingLoad Statusboolean--
loadingRenderCustom loading content rendering() => React.ReactNode--
contentBubble ContentsContentType--
contentRenderCustom content rendering(content: ContentType) => React.ReactNode--
typingTyping Animation Effectsboolean | BubbleAnimationOptionfalse-
streamingWhether it is streamingbooleanfalse-
variantBubble style variantsfilled | outlined | shadow | borderlessfilled-
shapeBubble Shapedefault | round | cornerdefault-
footerPlacementBottom Slot Positionouter-start | outer-end | inner-start | inner-endouter-start-
componentsExpand Slot Configuration{ header?: BubbleSlot; footer?: BubbleSlot; avatar?: BubbleSlot; extra?: BubbleSlot; }--
onTypingAnimation Execution Callback(rendererContent: string, currentContent: string) => void--
onTypingCompleteAnimation end callback(content: string) => void--

streaming

streaming can be passed to tell Bubble if the current content is a streaming input. When in streaming mode, with or without Bubble input animation, the Bubble will not trigger the onTypingComplete callback until streaming becomes false, even if the current content has fully outputted. This avoids the issue of multiple triggers of onTypingComplete callbacks due to unstable streaming, ensuring that only onTypingComplete is triggered once during a streaming process.

In this example, you can try to force the streaming flag to be turned off while

  • If you enable input animations, onTypingComplete will be triggered multiple times when performing a load slowly because the streaming speed cannot keep up with the animation speed.
  • If you turn off the input animation, onTypingComplete will be triggered every time you stream the input.

Bubble.List Component API

AttributesDescriptionTypeDefaultVersion
prefixClsCustom class prefixesstring--
rootClassNameRoot node class namestring--
rootStyleRoot Node StyleReact.CSSProperties--
itemsBubble data list, key, role required(BubbleProps & { key: string | number, role: string }) []--
autoScrollWhether to auto-scrollbooleantrue-
roleRole default configurationPartial<Record<ai | system | user, RoleType>> & Record<string, RoleType>--

ContentType

Default type

typescript
type ContentType = React.ReactNode | AnyObject | string | number;

Custom type usage

tsx
type CustomContentType {
...
}
<Bubble<CustomContentType> {... props} />

BubbleSlot

typescript
type BubbleSlot<ContentType> = React.ReactNode | ((content: ContentType) => React.ReactNode);

BubbleAnimationOption

typescript
interface BubbleAnimationOption {
/**
* @description Animation effect type, typewriter, fade
*/
effect: 'typing' | 'fade-in';
/**
* @description Content step units, array format as random intervals
*/
step?: number | [number, number];
/**
* @description Animation trigger interval
*/
interval?: number;
/**
* @description Whether to restart an animation with the common prefix of the text
*/
keepPrefix?: boolean;
/**
* @description Stepping UI under typewriter effect
*/
suffix?: React.ReactNode;
}

RoleType

typescript
type RoleType = Pick<
BubbleProps,
| 'typing'
| 'variant'
| 'shape'
| 'placement'
| 'rootClassName'
| 'classNames'
| 'className'
| 'rootStyle'
| 'styles'
| 'style'
| 'loading'
| 'loadingRender'
| 'contentRender'
| 'footerPlacement'
| 'components'
> & { key: string | number; role: string };

Semantic DOM

Design Token

Global TokenHow to use?
basic

Basic usage.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
ariants and shapes

variant and shape, borderless Bubble is suitable for rendering custom-styled content.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
sidebar and placement

Bubble sidebar and placement, placement will change the position of the primary and secondary sidebars.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
header

Bubble header, placement will change the alignment of the header.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
footer

Bubble footer, not affected by placement, use footerPlacement to control the rendering position of the footer.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
loading

Control the loading state by loading prop.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
animation

Animation effect. It only works if content is a string or contentRender renders a string. Non-string scenes require custom rendering animations. When it takes effect, if content remains unchanged and other configurations change, the animation does not re-execute.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
stream

Stream. streaming can be passed to tell Bubble if the current content is a streaming input.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
custom rendered content

Custom rendering content.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
render the markdown content

Cooperate with x-markdown to achieve customized rendering content.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Bubble.List

Bubble list with preset styles, supports automatic scrolling, supports using role to define different types of bubbles and set properties. Bubble.List is a controlled component, and Bubble is internally memoized, so it is recommended to use setState callback form to modify the items property, and try to ensure the stability of the configuration of non-essential rendering data items, so as to ensure the high performance rendering of Bubble.List.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Bubble.List Ref

Bubble.List ref.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
semantic customization

Sample for adjusting the bubble effect through semantic and loading customization.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
render charts using GPT-Vis

Cooperate with @antv/GPT-Vis to achieve customized rendering chart of LLM stream output.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Ant Design X
filled - default
filled - round
filled - corner left
filled - corner right
outlined - default
outlined - round
outlined - corner left
outlined - corner right
shadow - default
shadow - round
shadow - corner left
shadow - corner right

borderless bubble

左对齐
右对齐
header
左对齐 header
header
右对齐 header
footer
外气泡尾外气泡尾
footer
内气泡尾内气泡尾
footer
外气泡尾外气泡尾-右对齐
footer
内气泡尾内气泡尾-左对齐
Loading state:
非流式数据 / Non-streaming data:
动画效果 / Animation effects:
保留公共前缀 / Preserve common prefix:
流式数据 / steaming data:
强制关闭流式标志 / Force close the streaming flag:
启用动画 / Enable animation:
onTypingComplete 触发次数 / trigger times: 0
Preview
Ant Design X
Custom loading...
Mock user content.
Ant Design X
Feel free to use Ant Design !
  • body
    Wrapper element of the body
  • avatar
    Wrapper element of the avatar
  • header
    Wrapper element of the header
  • content
    Wrapper element of the content
  • footer
    Wrapper element of the footer
  • extra
    Wrapper element of the extra