Skip to content

ChatBubble 聊天气泡

像素风格的聊天气泡组件,用于构建对话界面。

名称分类说明类型默认值
placement? 风格气泡位置方向'start' | 'end''start'
type? 风格颜色类型'primary' | 'success' | 'info' | 'warning' | 'danger'
color? 颜色自定义十六进制颜色string
name? 内容发送者名称string
time? 内容时间戳string
status? 内容底部状态文本string
default? 插槽气泡消息内容
avatar? 插槽头像区域
header? 插槽自定义头部(覆盖 name/time)
footer? 插槽自定义底部(覆盖 status)

基础用法

使用 placement 控制气泡显示的方向。默认为 start(左侧)。

<template>
  <div class="demo-chat">
    <px-chat-bubble name="Alice" time="12:30">
      Hey! How's it going?
    </px-chat-bubble>
    <px-chat-bubble placement="end" name="Bob" time="12:31">
      Pretty good, thanks! Working on a pixel art project.
    </px-chat-bubble>
  </div>
</template>

<style scoped>
.demo-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
</style>

类型

使用 type 属性设置气泡的颜色主题。

<template>
  <div class="demo-chat">
    <px-chat-bubble type="primary">Primary message</px-chat-bubble>
    <px-chat-bubble type="success">Success message</px-chat-bubble>
    <px-chat-bubble type="info">Info message</px-chat-bubble>
    <px-chat-bubble type="warning">Warning message</px-chat-bubble>
    <px-chat-bubble type="danger">Danger message</px-chat-bubble>
  </div>
</template>

<style scoped>
.demo-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
</style>

头像

使用 avatar 插槽在气泡旁添加头像。

<template>
  <div class="demo-chat">
    <px-chat-bubble name="Alice" time="12:30">
      <template #avatar>
        <px-avatar size="small">A</px-avatar>
      </template>
      Hey! Check out this pixel art.
    </px-chat-bubble>
    <px-chat-bubble placement="end" name="Bob" time="12:31">
      <template #avatar>
        <px-avatar size="small">B</px-avatar>
      </template>
      Looks awesome!
    </px-chat-bubble>
  </div>
</template>

<style scoped>
.demo-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
</style>

头部和底部

使用 nametimestatus 属性来显示发送者信息和投递状态。

<template>
  <div class="demo-chat">
    <px-chat-bubble name="Alice" time="12:30" status="Delivered">
      I'll send you the files tonight.
    </px-chat-bubble>
    <px-chat-bubble placement="end" name="Bob" time="12:31" status="Seen">
      Great, no rush!
    </px-chat-bubble>
  </div>
</template>

<style scoped>
.demo-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
</style>

自定义颜色

使用 color 属性为气泡设置自定义十六进制颜色。

<template>
  <div class="demo-chat">
    <px-chat-bubble color="#8b5cf6" name="Violet">
      Custom purple bubble!
    </px-chat-bubble>
    <px-chat-bubble placement="end" color="#f59e0b" name="Amber">
      Custom amber bubble!
    </px-chat-bubble>
  </div>
</template>

<style scoped>
.demo-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
</style>

对话

组合多个聊天气泡来构建完整的对话布局。

<template>
  <div class="demo-chat">
    <px-chat-bubble name="Alice" time="14:00">
      <template #avatar>
        <px-avatar size="small">A</px-avatar>
      </template>
      Have you tried the new pixel component library?
    </px-chat-bubble>
    <px-chat-bubble placement="end" type="primary" name="Bob" time="14:01">
      <template #avatar>
        <px-avatar size="small">B</px-avatar>
      </template>
      Yes! Sakana Element is great for retro-themed UIs.
    </px-chat-bubble>
    <px-chat-bubble name="Alice" time="14:02" status="Delivered">
      <template #avatar>
        <px-avatar size="small">A</px-avatar>
      </template>
      I love the pixel borders and drop shadows.
    </px-chat-bubble>
    <px-chat-bubble placement="end" type="success" name="Bob" time="14:03" status="Seen">
      <template #avatar>
        <px-avatar size="small">B</px-avatar>
      </template>
      The ChatBubble component even has a stepped pixel tail!
    </px-chat-bubble>
  </div>
</template>

<style scoped>
.demo-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
</style>