logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKPlayground
  • Introduction
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
  • Confirmation
    • Think
    • ThoughtChain
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Feedback
    • Actions
    • FileCard
  • Others
    • 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 in chat scenarios.

Examples

API

Common Props Reference: Common Props

Bubble

AttributeDescriptionTypeDefaultVersion
placementBubble positionstart | endstart-
loadingLoading stateboolean--
loadingRenderCustom loading content renderer() => React.ReactNode--
contentBubble contentContentType--
contentRenderCustom content renderer(content: ContentType, info: InfoType ) => React.ReactNode--
editableEditableboolean | EditableBubbleOptionfalse-
typingTyping animation effectboolean | BubbleAnimationOption | ((content: ContentType, info: InfoType) => boolean | BubbleAnimationOption)false-
streamingStreaming modebooleanfalse-
variantBubble style variantfilled | outlined | shadow | borderlessfilled-
shapeBubble shapedefault | round | cornerdefault-
footerPlacementFooter slot positionouter-start | outer-end | inner-start | inner-endouter-start-
componentsSlot configuration{ header?: BubbleSlot; footer?: BubbleSlot; avatar?: BubbleSlot; extra?: BubbleSlot; }--
onTypingTyping animation callback(rendererContent: string, currentContent: string) => void--
onTypingCompleteTyping animation complete callback(content: string) => void--
onEditingCallback when content changes in editing mode(content: string) => void--

streaming

streaming notifies Bubble whether the current content is streaming input. In streaming mode, regardless of whether Bubble input animation is enabled, Bubble will not trigger the onTypingComplete callback until streaming becomes false, even if the current content is fully output. Only when streaming becomes false and the content is fully output will Bubble trigger onTypingComplete. This avoids multiple triggers due to unstable streaming and ensures only one trigger per streaming process.

In this example, you can try to force the streaming flag off:

  • If you enable input animation and perform slow loading, multiple triggers of onTypingComplete may occur because streaming speed cannot keep up with animation speed.
  • If you disable input animation, each streaming input will trigger onTypingComplete.

Bubble.List autoScroll Top Alignment

Bubble.List auto-scroll is a simple reverse sorting scheme. In a fixed-height Bubble.List, if the message content is insufficient to fill the height, the content is bottom-aligned. It is recommended not to set a fixed height for Bubble.List, but to set a fixed height for its parent container and use flex layout (display: flex and flex-direction: column). This way, Bubble.List adapts its height and aligns content to the top when content is sparse, as shown in the Bubble List demo.

tsx
<div style={{ height: 600, display: 'flex', flexDirection: 'column' }}>
<Bubble.List items={items} autoScroll />
</div>

If you do not want to use flex layout, you can set max-height for Bubble.List. When content is sparse, the height adapts and aligns to the top.

tsx
<Bubble.List items={items} autoScroll rootStyle={{ maxHeight: 600 }} />

Bubble.List Component API

AttributeDescriptionTypeDefaultVersion
itemsBubble data list, key and role required. When used with X SDK useXChat, you can pass status to help Bubble manage configuration(BubbleProps & { key: string | number, role: string , status: MessageStatus})[]--
autoScrollAuto-scrollbooleantrue-
roleRole default configurationRoleType--

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, info: InfoType) => React.ReactNode);

MessageStatus

typescript
type MessageStatus = 'local' | 'loading' | 'updating' | 'success' | 'error' | 'abort';

InfoType

typescript
type InfoType = {
status: MessageStatus;
};

EditableBubbleOption

typescript
interface EditableBubbleOption {
/**
* @description Whether editable
*/
editing?: boolean;
/**
* @description OK button
*/
okText?: React.ReactNode;
/**
* @description Cancel button
*/
cancelText?: React.ReactNode;
}

BubbleAnimationOption

typescript
interface BubbleAnimationOption {
/**
* @description Animation effect type, typewriter, fade-in
* @default 'fade-in'
*/
effect: 'typing' | 'fade-in';
/**
* @description Content step unit, array format for random interval
* @default 6
*/
step?: number | [number, number];
/**
* @description Animation trigger interval
* @default 100
*/
interval?: number;
/**
* @description Whether to keep the common prefix when restarting animation
* @default true
*/
keepPrefix?: boolean;
/**
* @description Suffix UI for typewriter effect
* @default undefined
*/
suffix?: React.ReactNode;
}

RoleType

typescript
type RoleProps = Pick<
BubbleProps,
| 'typing'
| 'variant'
| 'shape'
| 'placement'
| 'rootClassName'
| 'classNames'
| 'className'
| 'rootStyle'
| 'styles'
| 'style'
| 'loading'
| 'loadingRender'
| 'contentRender'
| 'footerPlacement'
| 'components'
> & { key: string | number; role: string };
export type FuncRoleProps = (data: BubbleData) => RoleProps;
export type RoleType = Partial<Record<'ai' | 'system' | 'user', RoleProps | FuncRoleProps>> &
Record<string, RoleProps | FuncRoleProps>;

Semantic DOM

Bubble

Bubble.List

Design Token

Global TokenHow to use?
Basic

Basic usage.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Variants 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
Bubble Header

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

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Bubble 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
Streaming

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 Markdown Content

Cooperate with x-markdown to achieve customized rendering content.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Editable Bubble

Editable bubble, support simple editing of string type content, and should be protected by XSS in onEditing when used.

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

align left
align right
header
align left
header
align right
footer
outer footer
footer
inner footer
footer
outer footer and align right
footer
inner footer and align left
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
editable bubble 1
editable bubble 2
Custom loading...
Mock user content.
Ant Design X
Feel free to use Ant Design !
  • root
    Bubble root
  • 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
AI
hello, Ant Design X
  • root
    Bubble list root node
  • bubble
    Bubble container
  • body
    Bubble main body container
  • avatar
    Bubble avatar outer container
  • header
    Bubble header container
  • content
    Bubble chat content container
  • footer
    Bubble footer container
  • extra
    Bubble sidebar container