# Chat Message

`ChatMessage` renders one `UIMessage` with the [Message](https://vitehub.dev/docs/ui/message) parts. User text sits at the end in a secondary [Bubble](https://vitehub.dev/docs/ui/bubble). Other roles reply at the start without a frame. `MessageParts` renders the content. Use it alone, or let `Chat` render one per message.

_Interactive preview available on the rendered documentation page._


## Installation

Install `@vite-hub/ui` as [Installation](https://vitehub.dev/docs/ui/installation) shows. `vite-hub/nuxt` auto-imports the component. In Vue with Vite, import it from `vite-hub/ui`:

```ts
import { ChatMessage } from "vite-hub/ui";
```

## Usage

```ts
import { ChatMessage } from "vite-hub/ui";
```

```vue
<ChatMessage :message="message" :streaming="status === 'streaming'">
  <template #actions="{ message }">
    <UButton icon="i-lucide-copy" aria-label="Copy message" variant="ghost" @click="copy(message)" />
  </template>
</ChatMessage>
```

## Composition

Each slot fills one part of the [Message](https://vitehub.dev/docs/ui/message). An unused slot renders nothing.

```text
Message, aligned to the end for the user and to the start for others
├── MessageAvatar, with the leading slot
└── MessageContent
    ├── MessageHeader, with the header slot
    ├── body, or the default slot
    │   ├── user: Bubble > BubbleContent > MessageParts
    │   └── assistant and system: MessageParts
    └── MessageFooter, with the actions slot
```

## Features

- Passes the part slots to `MessageParts`.
- Optional header, avatar, and action slots.
- Takes its accessible name from the message role.

## User Message with a Header

Use the `header` slot for details above the body, such as an attachment count. File parts render as download links or image previews.

_Interactive preview available on the rendered documentation page._


## Streaming with a Custom Avatar

Set `streaming` while the response arrives, so text and reasoning parts stream. The `leading` slot replaces the avatar.

_Interactive preview available on the rendered documentation page._


## Accessibility

- The message is named **User message**, **Assistant message**, or **System message**. Pass `aria-label` to change it.
- Give icon-only action buttons an `aria-label`.

## API Reference

### ChatMessage

Renders one message as a `Message` with its parts.

#### Props

| Prop        | Type                      | Default  | Description                                               |
| ----------- | ------------------------- | -------- | --------------------------------------------------------- |
| `message`   | `UIMessage`               | Required | The message to render.                                    |
| `streaming` | `boolean`                 | `false`  | Renders text and reasoning parts as streaming. |

Other attributes, such as `class`, go to the `Message` root.

#### Slots

| Slot       | Scope             | Description                                         |
| ---------- | ----------------- | --------------------------------------------------- |
| `default`  | `{ message }`     | Replaces the whole body. |
| `header`   | `{ message }`     | Content above the body, such as files or details. |
| `leading`  | `{ message }`     | Replaces the avatar or role marker.                 |
| `actions`  | `{ message }`     | Copy, retry, feedback, or other actions. |
| Part slots | `{ part, index }` | Passed to `MessageParts`, such as `text`, `tool`, or `fallback`. |

## Related

- [Message parts](https://vitehub.dev/docs/ui/message-parts) renders the content of a message.
- [Chat](https://vitehub.dev/docs/ui/chat) renders a list of messages.
- [Markdown](https://vitehub.dev/docs/ui/markdown) renders text parts.

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/ui.md)
- [AI components](https://vitehub.dev/raw/docs/ui/ai-components.md)
- [Blocks](https://vitehub.dev/raw/docs/ui/blocks/chat-app.md)
- [Parts](https://vitehub.dev/raw/docs/ui/message.md)
- Chat
  - [Chat](https://vitehub.dev/raw/docs/ui/chat.md)
  - [Chat Message](https://vitehub.dev/raw/docs/ui/chat-message.md) (this page)
  - [Message Parts](https://vitehub.dev/raw/docs/ui/message-parts.md)
  - [Markdown](https://vitehub.dev/raw/docs/ui/markdown.md)
  - [Prompt Input](https://vitehub.dev/raw/docs/ui/prompt-input.md)
  - [Chat Session](https://vitehub.dev/raw/docs/ui/chat-session.md)
  - [Agent Session](https://vitehub.dev/raw/docs/ui/agent-session.md)
  - [Filter Search](https://vitehub.dev/raw/docs/ui/filter-search.md)
- [Collaboration](https://vitehub.dev/raw/docs/ui/avatar-stack.md)
- [Agent work](https://vitehub.dev/raw/docs/ui/tool-list.md)
- [Utilities](https://vitehub.dev/raw/docs/ui/attachments.md)

Next: [Message Parts](https://vitehub.dev/raw/docs/ui/message-parts.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
