Skip to content

Bubble

使用import { Bubble } from 'vue-element-plus-x'
文档
Edit this pageChangelogFeedback

💌 Info

Version 2.0.0 removed the built-in Typewriter component. For Markdown rendering functionality, please use x-markdown-vue

Introduction

Bubble is a chat bubble component, commonly used in chat scenarios. It can display conversation content, supports custom avatars, headers, content, footers, and has loading state display.

Code Examples

Basic Usage

hello world !

Simplest integration method.

Avatar and Placement

cover
Good morning, how are you?
What a beautiful day!
Hi, good morning, I'm fine!
Hi, good morning, I'm fine! Thank you!

Set custom avatar through #avatar. Set position through placement property, provides start, end two option values.

💡 Tip

😸 Built-in element-plus el-avatar component. But to avoid property name conflicts, for example: el-avatar and Bubble's shape property. You need to use the following properties to set

  1. Properties
  • avatar Set avatar placeholder image
  • avatar-size Set avatar placeholder size 👉This property is number type in el-avatar component, note that in this component it's string type for better custom style properties😊
  • avatar-gap Set distance between avatar and bubble
  • avatar-shape Set avatar shape
  • avatar-icon Set avatar placeholder icon
  • avatar-src-set Set avatar image srcset attribute
  • avatar-alt Set avatar image alt attribute
  • avatar-fit Set avatar placeholder image fill mode
  1. Events
  • @avatar-error Triggered when avatar loading fails.

Loading State

loading...
Thank you for using Element-Plus-X 🌹 Please wait...
State:

Set loading state through loading property. Supports custom loading state content display through #loading slot.

💌 Info

#loading slot has higher priority, built-in loading styles will be disabled. But the loading property can still control the loading state.

Custom Content

cover
😊 Welcome to element-plus-x, I'm a custom bubble
Recommended Content Custom Bubble
🥤 How to rest effectively after long hours of work?
💌 What's the secret to maintaining a positive mindset?
🔥 How to stay calm under tremendous pressure?

Customize bubble content through #content slot.

💌 Info

#content slot has higher priority, content property will be disabled. no-padding property can disable bubble content padding.

Variants and Shapes

filled
filled + round
filled + corner
borderless
borderless + round
borderless + corner
outlined
outlined + round
outlined + corner
shadow
shadow + round
shadow + corner
round
corner
placement end

Set bubble's built-in style format through variant property. Set bubble's shape through shape property. Of course you can also combine them and use them together.

💌 Info

By default, variant is filled, shape is round.

When shape is corner, placement="end" will automatically flip the bubble so that the top-right corner radius pointer points to the user.

Theme Overrides (themeOverrides)

Override Bubble theme tokens via ConfigProvider.themeOverrides. See the full token list and template:

When enabled, bubble content becomes narrower.
Start bubble: gradient background, larger radius and stronger shadow after overrides.
End bubble: use themeOverrides to build a consistent glass-like theme.

Override Bubble theme tokens via ConfigProvider.themeOverrides (background, border, radius, padding, width, etc.) for a clear before/after contrast.

Using with x-markdown-vue

Starting from v2.0.0, the Typewriter component has been removed. For Markdown rendering functionality, please use x-markdown-vue or see the dedicated page: XMarkdown.

Installation

bash
pnpm add x-markdown-vue
pnpm add katex
pnpm add shiki shiki-stream

💡 Tip

If you need code block syntax highlighting, please install shiki and shiki-stream. Otherwise, you may see this error in the console: Streaming highlighter initialization failed: Error: Failed to load shiki-stream module

Full Demo

Basic Usage (Supports formulas, code blocks, task lists)
cover
Streaming Rendering

Use enable-animate property to achieve typewriter effect, simulating AI streaming output

cover

Supports formulas, code blocks, task lists, and streaming rendering.

Basic Usage

vue
<template>
  <Bubble :avatar="avatar" placement="start">
    <template #content>
      <MarkdownRenderer :markdown="content" />
    </template>
  </Bubble>
</template>

<script setup>
import { ref } from 'vue';
import { MarkdownRenderer } from 'x-markdown-vue';
import 'x-markdown-vue/style';

const avatar = ref('https://example.com/avatar.png');
const content = ref('**Hello** World!\n\nThis is **Markdown** content');
</script>

Streaming Rendering (Alternative to Typing Effect)

vue
<template>
  <Bubble :avatar="avatar" placement="start">
    <template #content>
      <MarkdownRenderer :markdown="content" :enable-animate="true" />
    </template>
  </Bubble>
</template>

<script setup>
import { ref } from 'vue';
import { MarkdownRenderer } from 'x-markdown-vue';
import 'x-markdown-vue/style';

const content = ref('');
</script>

Properties

Property Name
TypeDefaultDescription
contentString''Text content to display inside the bubble
placementString'start'Bubble position, options are 'start' or 'end', representing left and right sides respectively.
avatarString''Image URL for the bubble avatar
loadingBooleanfalseWhether to show loading state. When true, loading state will be displayed inside the bubble.
shapeStringnullBubble shape, options are 'round' (rounded corners) or 'corner' (angular).
variantString'filled'Bubble style variant, options are 'filled' (filled), 'borderless' (no border), 'outlined' (outline), 'shadow' (shadow).
noStyleBooleanfalseWhether to remove styles, when true, removes built-in padding and background color from the bubble
maxWidthString'500px'Maximum width of bubble content.
avatar-sizeString''Set avatar placeholder size
avatar-gapString'12px'Set gap value between avatar and bubble
avatar-shapeString''Avatar shape, options are 'circle' (circular) or 'square' (square).
avatar-iconString''Avatar icon, priority higher than avatar, supports passing icon names like 'user'.
avatar-src-setString''Set avatar image srcset attribute
avatar-altString''Set avatar image alt attribute
avatar-fitString'cover'Set avatar image object-fit attribute, options: 'cover', 'contain', 'fill', 'none', 'scale-down'

Events

Event NameParametersTypeDescription
@avatarErrorref instanceFunctionTriggered when avatar loading fails

Ref Instance Methods

Property NameTypeDescription
restartFunctionRestart.
destroyFunctionActively destroy Bubble component.

Slots

Slot NameParametersTypeDescription
#avatar-SlotCustom avatar display content
#header-SlotCustom bubble top display content
#content-SlotCustom bubble display content
#loading-SlotCustom bubble loading state display content
#footer-SlotCustom bubble bottom display content

Features

  1. Layout Direction - Supports left alignment (start) and right alignment (end)
  2. Content Types - Supports plain text, custom slot content
  3. Loading State - Built-in loading animation, supports custom loading content
  4. Visual Effects - Provides multiple shapes and variants (rounded/angular corners, filled/outlined/shadow, etc.)
  5. Flexible Slots - Provides avatar, header, content, footer, loading state and other slots