skip section navigation

ChatMessage

ChatMessage displays one conversation entry: author, avatar, optional timestamp and content. your app owns the conversation, reactions and composer, so you can add only the actions that make sense for that message.

Mina
The **balcony garden** article has a useful list of shade-friendly herbs.

usage

svelte
<script>
	import { ChatMessage } from '@ciabi/loafkit-ui';
	let saved = $state(false);
</script>

<ChatMessage author="Mina" timestamp="9:42 AM" datetime="2026-11-17T09:42:00-05:00"
	text="The **balcony garden** article has a useful list of shade-friendly herbs.">
	{#snippet actions()}
		<button type="button" aria-pressed={saved} onclick={() => saved = !saved}>
			{saved ? 'Saved to Garden notes' : 'Save to Garden notes'}
		</button>
	{/snippet}
</ChatMessage>

composition

  • ChatMessage
    • children (replaces text)(optional)
    • actions()(optional)

message content

don’t put a live-region role on every message by habit. decide how incoming messages should be announced at the conversation level.

put a task inside a message

Mina

before we share the garden collection:

collection review 0 / 2

0 review tasks done

svelte
<script lang="ts">
import { ChatMessage, Checklist } from '@ciabi/loafkit-ui';
let messageTasks = $state<string[]>([]);
</script>

<ChatMessage author="Mina" text="this fallback text is replaced by children">
	<p>before we share the garden collection:</p>
	<Checklist legend="collection review" items={[{id:'links',label:'open the saved links'},{id:'intro',label:'add an introduction'}]} bind:value={messageTasks} summary />
</ChatMessage>
<p role="status">{messageTasks.length} review tasks done</p>

API reference

ChatMessage

Component
author

the visible speaker name.

avatarSrc

decorative avatar; without one the author’s first character is shown.

timestamp

the visible time label.

datetime

machine-readable time; enables a native time element.

text
Default: ''

Markdown message body when children is absent.

children

rich body content, replacing text.

actions

controls beneath the message body.

class
Default: ''

extra classes on the message article.

style

inline styles on the message article.