PXD
v0.2.1-dev

Bubble

Show the conversation.

Default

The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
<template>
  <PBubble role="system">The Evil Rabbit Jumped over the Fence</PBubble>
  <PBubble role="user">The Evil Rabbit Jumped over the Fence</PBubble>
</template>

Variant

The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
<template>
  <PBubble variant="ghost" role="system">The Evil Rabbit Jumped over the Fence</PBubble>
  <PBubble variant="default" role="assistant">The Evil Rabbit Jumped over the Fence</PBubble>
  <PBubble variant="primary" role="user">The Evil Rabbit Jumped over the Fence</PBubble>
  <PBubble variant="secondary" role="assistant">The Evil Rabbit Jumped over the Fence</PBubble>
</template>

Loading

<script setup>
import { ref } from 'vue'

const loading = ref(true)
</script>

<template>
  <PToggle v-model="loading" active-label="Loading" />
  <PBubble role="system" :loading="loading">The Evil Rabbit Jumped over the Fence</PBubble>
</template>

Avatar

The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
<template>
  <PBubble role="system" avatar="https://avatars.githubusercontent.com/u/47918504?s=48&v=4">The Evil Rabbit Jumped over the Fence</PBubble>
  <PBubble role="user" avatar="https://avatars.githubusercontent.com/u/47918504?s=48&v=4">The Evil Rabbit Jumped over the Fence</PBubble>
  <PBubble role="user" avatar="https://avatars.githubusercontent.com/u/47918504?s=48&v=4">The Evil Rabbit Jumped over the Fence</PBubble>
</template>
System
The Evil Rabbit Jumped over the Fence
18:30:00
The Evil Rabbit Jumped over the Fence
<script setup>
import RefreshClockwiseIcon from '@gdsicon/vue/refresh-clockwise'
import PencilEditIcon from '@gdsicon/vue/pencil-edit'
</script>

<template>
  <PBubble role="system" header="System">
    The Evil Rabbit Jumped over the Fence

    <template #footer>
      <PButton size="sm" variant="ghost" icon>
        <RefreshClockwiseIcon class="text-gray-900" />
      </PButton>
    </template>
  </PBubble>

  <PBubble role="user">
    The Evil Rabbit Jumped over the Fence

    <template #header>
      18:30:00
    </template>

    <template #footer>
      <PButton size="sm" variant="ghost" icon>
        <PencilEditIcon class="text-gray-900" />
      </PButton>
    </template>
  </PBubble>
</template>

Reactions

Use the reactions slot to render anything below the message body — vote buttons, counts, reply hints.

The Evil Rabbit Jumped over the Fence
Helpful?
The Evil Rabbit Jumped over the Fence
👍12👎3
<script setup>
import ThumbDownIcon from '@gdsicon/vue/thumb-down'
import ThumbUpIcon from '@gdsicon/vue/thumb-up'
</script>

<template>
  <PBubble role="assistant" text="The Evil Rabbit Jumped over the Fence">
    <template #reactions>
      <PFeedbackBar label="Helpful?" />
    </template>
  </PBubble>

  <PBubble role="user" text="The Evil Rabbit Jumped over the Fence">
    <template #reactions>
      <span class="rounded-full bg-gray-900 pl-1.5 pr-2 py-0.5">👍12</span>
      <span class="rounded-full bg-gray-900 pl-1.5 pr-2 py-0.5">👎3</span>
    </template>
  </PBubble>
</template>

Group

By default, the PBubbleGroup component always shows the latest data at the bottom.

The Evil Rabbit Jumped over the Fence
The Evil Rabbit Jumped over the Fence
<script setup>
import { ref } from 'vue'

const messages = ref([
  { role: 'system', message: 'The Evil Rabbit Jumped over the Fence' },
  { role: 'user', message: 'The Evil Rabbit Jumped over the Fence' },
])

function addMessage() {
  messages.value.push({
    role: Math.random() > 0.5 ? 'system' : 'user',
    message: 'The Evil Rabbit Jumped over the Fence ' + Date.now(),
  })
}
</script>

<template>
  <PButton class="mb-2" @click="addMessage">Add Message</PButton>

  <PBubbleGroup class="max-h-40">
    <PBubble v-for="m of messages" :role="m.role" :text="m.message" />
  </PBubbleGroup>
</template>

PBubbleGroup shows a vertical fader by default; pass :fader="false" to hide it.

Group With Virtual Scroll

Pass data together with virtual to enable virtual scrolling for large message lists.

<script setup>
import { ref } from 'vue'

const messages = ref(
  Array.from({ length: 50 }, (_, i) => ({
    id: i,
    role: i % 2 === 0 ? 'system' : 'user',
    message: `The Evil Rabbit Jumped over the Fence ${i}`,
  })),
)

function addMessage() {
  messages.value.push({
    id: messages.value.length,
    role: Math.random() > 0.5 ? 'system' : 'user',
    message: 'The Evil Rabbit Jumped over the Fence ' + Date.now(),
  })
}
</script>

<template>
  <PButton class="mb-2" @click="addMessage">Add Message</PButton>

  <PBubbleGroup class="max-h-80" :data="messages" data-key="id" virtual>
    <template #item="{ item }">
      <PBubble :role="item.role" :text="item.message" />
    </template>
  </PBubbleGroup>
</template>

Props

NameTypeDefaultDescription
role'user' | 'system' | 'assistant'systemMessage author, user is right-aligned, system and assistant are left-aligned
textstring-Message content rendered when the default slot is empty
headerstring-Text shown above the bubble
avatarstring-Avatar image URL rendered before the bubble, the avatar slot overrides it
loadingboolean-Replace the message content with a spinner
variant'default' | 'primary' | 'secondary' | 'ghost''default'Bubble appearance: default uses the neutral surface, primary the brand color with inverted text, secondary a gray surface, ghost a transparent background without border
interactivebooleantrueShow hover feedback, set to false for read-only messages

Slots

NameDescription
defaultMessage body, falls back to the text prop.
avatarAvatar image, falls back to the avatar prop.
headerText shown above the bubble, falls back to the header prop.
reactionsContent rendered below the message body, such as vote buttons or counts.
footerAction area rendered below the bubble.

BubbleGroup Props

NameTypeDefaultDescription
dataany[]-Data array rendered through the item slot
virtualbooleanfalseEnable virtual scrolling, requires data
data-keystring-Unique key field name for list items
item-sizenumber | ((index: number) => number)80Height of an unmeasured row when virtual is enabled, or a per-index guess
over-scannumber3Number of items to render beyond the visible area when virtual is enabled
faderbooleantrueShow a vertical gradient fader when messages overflow

fader-size, fader-color and fader-direction are forwarded to the inner PStickToBottom; the direction defaults to vertical.

BubbleGroup Slots

NameDescription
defaultDefault slot (used when data is not provided)
itemScoped slot for data mode: { item, index }

BubbleGroup Methods

NameTypeDescription
scrollSourceVirtualListScrollSourcePosition and scroll source for PToc’s data-driven outline, tracking the virtualized messages.
forceStickToBottom() => voidScroll to the bottom and re-enable auto-follow — call it when the data set is replaced (a new conversation), since the instance survives a same-component route switch.

Source

Source