GhostChatMessage reference
Package: @ghostvue/themes. Status: experimental (stability policy).
Themed chat message. Adds data-themed on the article root and a grid recipe: avatar column on the message's side, header above the bubble, footer below it. Start bubbles use the muted surface, end bubbles the primary action colors, with a transparent border for forced colors and static typing dots under reduced motion. Behavior matches @ghostvue/vue GhostChatMessage.
Generated from the component manifest. Edit the manifest or Vue source, then rebuild the docs.
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
side | GhostChatMessageSide | "start" | No | Forwarded inline side; end aligns the message to the inline end. |
status | GhostChatMessageStatus | "complete" | No | Forwarded arrival state; typing shows animated dots. |
typingLabel | string | "Typing" | No | Forwarded visually hidden typing label. |
Emits
None declared.
Models
None declared.
Slots
| Name | Description |
|---|---|
avatar | Avatar part, usually a GhostAvatar with aria-hidden. |
header | Author and time; names the article. |
default | Bubble content. |
footer | Delivery state, errors, and actions. |
Slot props: avatar
None declared.
Slot props: header
None declared.
Slot props: default
None declared.
Slot props: footer
None declared.
Exposed members
None declared.
Parts and data attributes
| Attribute | Value | Description |
|---|---|---|
data-part | root | Grid container with avatar, header, bubble, and footer areas. |
data-part | bubble | Rounded bubble, capped at about 80% of the log width and 40rem. |
CSS variables
| Name | Description |
|---|---|
--ghost-surface-muted-bg | Start bubble background. |
--ghost-surface-fg | Start bubble text. |
--ghost-action-primary-bg | End bubble background. |
--ghost-action-primary-fg | End bubble text and link color. |
--ghost-radius-lg | Bubble corner radius. |
--ghost-motion-duration-slow | Typing dot pulse timing. |
Accessibility
Role: article. APG pattern: https://www.w3.org/WAI/ARIA/apg/patterns/feed/.
Required ARIA attributes: none.
Keyboard
None declared.
Verification
Each category is reviewed separately. Automated keyboard and axe results do not attest manual or assistive-technology review.
| Category | Status | Evidence |
|---|---|---|
| Automated keyboard | Not reviewed | No declared key is mapped to a browser test yet. |
| Manual interaction | Not reviewed | No review recorded. |
| Assistive technology | Not reviewed | No review recorded. |
Examples
chat-message/streaming-chat
Log that follows a streamed reply, stops when the reader scrolls up, offers Jump to latest with an unread count, and announces arrivals in one status region.
Support chat
- Hi! How can I help with your workspace today?
- YOYouOur nightly report export did not arrive this morning.
- ASAssistantSorry about that. Which workspace is it, and when did the last export arrive?
- YOYouWorkspace "Northwind ops". The last one came on Sunday night.
- ASAssistantThanks. Is anything else failing, or only the export?
- YOYouOnly the export. Dashboards still load fine.
<script setup lang="ts">
import { onBeforeUnmount, ref, useId, useTemplateRef } from 'vue'
import { GhostVisuallyHidden } from '@ghostvue/vue'
import {
GhostAvatar,
GhostButton,
GhostChatMessage,
GhostCheckbox,
GhostInlineAlert,
GhostScrollArea,
GhostTextarea,
type GhostChatMessageStatus,
type GhostTextareaExposed,
} from '@ghostvue/themes'
interface ChatMessage {
id: number
author: string
mine: boolean
status: GhostChatMessageStatus
text: string
at: string
failed?: boolean
}
const ASSISTANT = 'Assistant'
const ME = 'You'
const REPLY =
'Thanks for the details. I checked your workspace: the nightly export ' +
'stopped after the storage key was rotated on Monday. Open Settings, then ' +
'Integrations, and reconnect the storage bucket with the new key. The next ' +
'export runs at 02:00 UTC and will include every report you missed this ' +
'week. Reply here if the export still fails after that.'
/** Milliseconds between simulated chunks of a streamed reply. */
const CHUNK_MS = 120
const headingId = useId()
const hintId = useId()
let nextId = 1
const messages = ref<ChatMessage[]>([
message(ASSISTANT, false, 'Hi! How can I help with your workspace today?'),
message(ME, true, 'Our nightly report export did not arrive this morning.'),
message(
ASSISTANT,
false,
'Sorry about that. Which workspace is it, and when did the last export arrive?',
),
message(
ME,
true,
'Workspace "Northwind ops". The last one came on Sunday night.',
),
message(
ASSISTANT,
false,
'Thanks. Is anything else failing, or only the export?',
),
message(ME, true, 'Only the export. Dashboards still load fine.'),
])
const draft = ref('')
const sending = ref(false)
const following = ref(true)
const unread = ref(0)
const announcement = ref('')
const dropNextReply = ref(false)
const composer = useTemplateRef<GhostTextareaExposed>('composer')
const timers = new Set<ReturnType<typeof setTimeout>>()
function later(callback: () => void, delay: number): void {
const timer = setTimeout(() => {
timers.delete(timer)
callback()
}, delay)
timers.add(timer)
}
onBeforeUnmount(() => {
for (const timer of timers) clearTimeout(timer)
timers.clear()
})
function message(
author: string,
mine: boolean,
text: string,
status: GhostChatMessageStatus = 'complete',
): ChatMessage {
const minutes = 30 + nextId
return {
id: nextId++,
author,
mine,
status,
text,
at: `2026-03-02T09:${String(minutes).padStart(2, '0')}:00Z`,
}
}
const timeFormat = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: '2-digit',
timeZone: 'UTC',
})
function formatTime(iso: string): string {
return timeFormat.format(new Date(iso))
}
function nowIso(): string {
return new Date().toISOString()
}
let clearAnnouncement: ReturnType<typeof setTimeout> | undefined
/**
* One polite status region for the whole log. Each announcement is a fresh
* change (clear, then write on a later tick), so two identical messages in a
* row are both spoken, and it is cleared again so browse mode does not find
* a stale copy after the log.
*/
function announce(text: string): void {
announcement.value = ''
if (clearAnnouncement) clearTimeout(clearAnnouncement)
later(() => {
announcement.value = text
clearAnnouncement = setTimeout(() => {
announcement.value = ''
}, 5000)
timers.add(clearAnnouncement)
}, 100)
}
function preview(text: string): string {
const words = text.split(/\s+/).slice(0, 6).join(' ')
return `${words}…`
}
function send(): void {
const text = draft.value.trim()
if (!text || sending.value) return
messages.value.push({ ...message(ME, true, text), at: nowIso() })
draft.value = ''
sending.value = true
// The user's own message is not announced; they just typed it.
later(startReply, 600)
}
function startReply(): void {
sending.value = false
const reply: ChatMessage = {
...message(ASSISTANT, false, '', 'typing'),
at: nowIso(),
}
messages.value.push(reply)
announce(`${ASSISTANT} is replying`)
const words = REPLY.split(' ')
const drop = dropNextReply.value
dropNextReply.value = false
let index = 0
const findReply = (): ChatMessage | undefined =>
messages.value.find((entry) => entry.id === reply.id)
const streamNext = (): void => {
const current = findReply()
if (!current) return
if (drop && index === 12) {
current.status = 'complete'
current.failed = true
// Replaces this message's arrival announcement.
announce('Reply failed')
return
}
if (index >= words.length) {
current.status = 'complete'
announce(`${ASSISTANT} replied: ${preview(current.text)}`)
if (!following.value) unread.value += 1
return
}
current.status = 'streaming'
current.text =
index === 0 ? (words[0] ?? '') : `${current.text} ${words[index] ?? ''}`
index += 1
later(streamNext, CHUNK_MS)
}
later(streamNext, 900)
}
function jumpToLatest(event: MouseEvent): void {
const button = event.currentTarget
// Keyboard activation moves focus to the composer before the button hides;
// a click or tap leaves focus alone so no virtual keyboard opens.
if (button instanceof HTMLElement && button.matches(':focus-visible')) {
composer.value?.focus()
}
// Setting the model scrolls to the bottom instantly and resumes following.
following.value = true
unread.value = 0
}
</script>
<template>
<section class="chat" :aria-labelledby="headingId">
<h2 :id="headingId" class="chat__title">Support chat</h2>
<div class="chat__log-frame">
<GhostScrollArea
v-model:stuck="following"
stick-to-bottom
label="Conversation"
class="chat__log"
>
<ol class="chat__messages" role="list">
<li v-for="entry in messages" :key="entry.id">
<GhostChatMessage
:side="entry.mine ? 'end' : 'start'"
:status="entry.status"
:typing-label="`${entry.author} is typing`"
>
<template #avatar>
<GhostAvatar
:name="entry.author"
size="sm"
aria-hidden="true"
/>
</template>
<template #header>
<span class="chat__author">{{ entry.author }}</span>
<time :datetime="entry.at">{{ formatTime(entry.at) }}</time>
</template>
<span class="chat__text">{{ entry.text }}</span>
<template v-if="entry.failed" #footer>
<GhostInlineAlert tone="danger">
<template #message>
Reply interrupted. Ask again to get the full answer.
</template>
</GhostInlineAlert>
</template>
</GhostChatMessage>
</li>
</ol>
</GhostScrollArea>
<GhostButton
v-if="!following"
class="chat__jump"
size="sm"
variant="soft"
tone="neutral"
@click="jumpToLatest"
>
Jump to latest<template v-if="unread"> ({{ unread }} new)</template>
</GhostButton>
</div>
<GhostVisuallyHidden role="status" aria-atomic="true">
{{ announcement }}
</GhostVisuallyHidden>
<form class="chat__composer" @submit.prevent="send">
<GhostTextarea
ref="composer"
v-model="draft"
class="chat__input"
submit-on-enter
auto-resize
:rows="1"
:max-rows="6"
:readonly="sending"
enterkeyhint="send"
aria-label="Message"
:aria-describedby="hintId"
/>
<GhostButton type="submit" :loading="sending">Send</GhostButton>
<p :id="hintId" class="chat__hint">
Enter to send, Shift+Enter for a new line
</p>
</form>
<label class="chat__option">
<GhostCheckbox v-model="dropNextReply" size="sm" />
Simulate a dropped connection on the next reply
</label>
</section>
</template>
<style scoped>
.chat {
display: flex;
flex-direction: column;
gap: var(--ghost-space-gap-sm);
block-size: 30rem;
max-inline-size: 40rem;
}
.chat__title {
border: 0;
font-size: var(--ghost-type-size-lg);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-tight);
margin: 0;
padding: 0;
}
/* The log takes the remaining height, so a growing composer shrinks it. */
.chat__log-frame {
display: flex;
flex: 1;
flex-direction: column;
min-block-size: 0;
position: relative;
}
.chat__log {
border: var(--ghost-border-hairline-width) solid var(--ghost-border-default);
border-radius: var(--ghost-radius-md);
flex: 1;
min-block-size: 0;
}
.chat__messages {
display: grid;
gap: var(--ghost-space-gap-md);
list-style: none;
margin: 0;
padding: var(--ghost-space-inset-sm);
}
.chat__messages > li {
margin: 0;
}
.chat__author {
color: var(--ghost-surface-fg);
font-weight: var(--ghost-type-weight-medium);
}
.chat__text {
white-space: pre-wrap;
}
.chat__jump {
inline-size: fit-content;
inset-block-end: var(--ghost-space-inset-sm);
inset-inline: 0;
margin-inline: auto;
position: absolute;
}
.chat__composer {
align-items: end;
display: grid;
gap: var(--ghost-space-gap-xs) var(--ghost-space-gap-sm);
grid-template-columns: minmax(0, 1fr) auto;
margin: 0;
}
.chat__hint {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
grid-column: 1 / -1;
margin: 0;
}
.chat__option {
align-items: center;
display: inline-flex;
font-size: var(--ghost-type-size-sm);
gap: var(--ghost-space-gap-xs);
}
</style>
chat-message/sides
Messages from another person on the start side and from the current user on the end side, each named by its header.
- ALAda LovelaceCan you review the release notes before the 2 PM cut?
- YOYouOn it. I will leave comments in the draft by 1:30.
<script setup lang="ts">
import { GhostAvatar, GhostChatMessage } from '@ghostvue/themes'
const messages = [
{
id: 1,
author: 'Ada Lovelace',
mine: false,
at: '2026-03-02T10:42:00Z',
time: '10:42',
text: 'Can you review the release notes before the 2 PM cut?',
},
{
id: 2,
author: 'You',
mine: true,
at: '2026-03-02T10:44:00Z',
time: '10:44',
text: 'On it. I will leave comments in the draft by 1:30.',
},
] as const
</script>
<template>
<ol class="chat-sides" role="list">
<li v-for="message in messages" :key="message.id">
<GhostChatMessage :side="message.mine ? 'end' : 'start'">
<template #avatar>
<GhostAvatar :name="message.author" size="sm" aria-hidden="true" />
</template>
<template #header>
<span class="chat-sides__author">{{ message.author }}</span>
<time :datetime="message.at">{{ message.time }}</time>
</template>
{{ message.text }}
</GhostChatMessage>
</li>
</ol>
</template>
<style scoped>
.chat-sides {
display: grid;
gap: var(--ghost-space-gap-md);
list-style: none;
margin: 0;
max-inline-size: 36rem;
padding: 0;
}
.chat-sides > li {
margin: 0;
}
.chat-sides__author {
color: var(--ghost-surface-fg);
font-weight: var(--ghost-type-weight-medium);
}
</style>
chat-message/typing
A reply that has not arrived yet, with animated dots and a visually hidden typing label.
- YouIs the staging deploy finished?
- GHGrace HopperGrace Hopper is typing
<script setup lang="ts">
import { GhostAvatar, GhostChatMessage } from '@ghostvue/themes'
</script>
<template>
<ol class="chat-typing" role="list">
<li>
<GhostChatMessage side="end">
<template #header>
<span class="chat-typing__author">You</span>
<time datetime="2026-03-02T10:44:00Z">10:44</time>
</template>
Is the staging deploy finished?
</GhostChatMessage>
</li>
<li>
<!-- The same instance later switches to streaming, then complete. -->
<GhostChatMessage status="typing" typing-label="Grace Hopper is typing">
<template #avatar>
<GhostAvatar name="Grace Hopper" size="sm" aria-hidden="true" />
</template>
<template #header>
<span class="chat-typing__author">Grace Hopper</span>
</template>
</GhostChatMessage>
</li>
</ol>
</template>
<style scoped>
.chat-typing {
display: grid;
gap: var(--ghost-space-gap-md);
list-style: none;
margin: 0;
max-inline-size: 36rem;
padding: 0;
}
.chat-typing > li {
margin: 0;
}
.chat-typing__author {
color: var(--ghost-surface-fg);
font-weight: var(--ghost-type-weight-medium);
}
</style>