logoAnt Design X

DesignDevelopmentComponentsX MarkdownX SDKPlayground
  • Introduction
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
  • Confirmation
    • Sources
    • 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 page...
Changelog
loading

When To Use

Often used in chat scenarios.

Examples

Bubble.List 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--

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);

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;
}

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

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, extra?: AnyObject })[]--
autoScrollAuto-scrollbooleantrue-
roleRole default configurationRoleType--

MessageStatus

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

InfoType

When used in conjunction with useXChat, key can be used as MessageId,and extra can be used as a custom parameter.

typescript
type InfoType = {
status?: MessageStatus;
key?: string | number;
extra?: AnyObject;
};

RoleType

typescript
export type RoleProps = Pick<
BubbleProps<any>,
| 'typing'
| 'variant'
| 'shape'
| 'placement'
| 'rootClassName'
| 'classNames'
| 'className'
| 'styles'
| 'style'
| 'loading'
| 'loadingRender'
| 'contentRender'
| 'footerPlacement'
| 'components'
| 'editable'
| 'onTyping'
| 'onTypingComplete'
| 'onEditConfirm'
| 'onEditCancel'
>;
export type FuncRoleProps = (data: BubbleItemType) => RoleProps;
export type DividerRoleProps = Partial<DividerBubbleProps>;
export type FuncDividerRoleProps = (data: BubbleItemType) => DividerRoleProps;
export type RoleType = Partial<
'ai' | 'system' | 'user', RoleProps | FuncRoleProps>
> & { divider: DividerRoleProps | FuncDividerRoleProps } & Record<
string,
RoleProps | FuncRoleProps
>;

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 style={{ maxHeight: 600 }} />

Bubble.List role and Custom Bubble

Both the role and items attributes of Bubble.List can be configured for bubbles, where the role configuration is used as the default and can be omitted. item.role is used to specify the bubble role for the data item, which will be matched with Bubble.List.role. The items itself can also be configured with bubble attributes, with higher priority than the role configuration. The final bubble configuration is: { ...role[item.role], ...item }.

Special note: We provide four default fields for role, ai, user, system, divider. Among these, system and divider are reserved fields. If item.role is assigned either of them, Bubble.List will render this bubble data as Bubble.System (role = 'system') or Bubble.Divider (role = 'divider').

Therefore, if you want to customize the rendering of system Bubble or divider Bubble, you should use other names.

Customize the rendering Bubble, you can refer to the rendering method of reference in this example.

Bubble.System

Common Props Reference: Common Props

AttributeDescriptionTypeDefaultVersion
contentBubble contentContentType--
variantBubble style variantfilled | outlined | shadow | borderlessshadow-
shapeBubble shapedefault | round | cornerdefault-

Bubble.Divider

Common Props Reference: Common Props

AttributeDescriptionTypeDefaultVersion
contentBubble content,same as Divider.childrenContentType--
dividerPropsDivider propsDivider--

Semantic DOM

Bubble

Bubble.System

Bubble.Divider

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
System Bubble

Bubble of system information.

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

Bubble of divider.

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
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
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
List extra

Implement custom extension capabilities in conjunction with extension parameters.

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
Hello, this is a system message
Hello, this is a system message
ok
Hello, this is a system message
cancel
message 1
Solid
message 2
Dashed
message 3
Dotted
message 4
Plain Text
message 5
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
Ant Design X
editable bubble 1
editable bubble 2
Custom loading...
Mock user content.
Custom loading...
Mock user content.
Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content.
Mock user content.
Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content.
Mock user content.
Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content.
Mock user content.
Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome content. Mock welcome 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
Feel free to use Ant Design !
  • root
    Bubble root
  • body
    Wrapper element of the body
  • content
    Wrapper element of the content
Feel free to use Ant Design !
  • root
    Bubble root
  • body
    Wrapper element of the body
  • content
    Wrapper element of the content
AI
hello, Ant Design X
divider
Welcome to Ant Design X
  • root
    Bubble list root node
  • bubble
    Bubble root
  • 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
  • system
    Bubble.System root
  • divider
    Bubble.Divider root