Skip to content

ChatMessage

ChatMessage presents a speaker label, message body and optional source as a user or assistant message.

01Preview

Tell me about the project.

A shared language for art and the web.

02Usage

Load @dg/ui/styles.css once in the root layout.

<script>
  import { ChatMessage } from "@dg/ui";
</script>

<ChatMessage role="user" text="Where is the archive?" />
<ChatMessage label="Guide" source="Collection index"><p>Open <a href="/archive">the archive</a>.</p></ChatMessage>

03Notes

  • Native HTML attributes, DOM callbacks, class and style are forwarded to the article; role is the message role, not an ARIA role.
  • Forwarding uses native attribute types; unknown props are not supported. Pass class as a string.
  • Contained message surfaces have soft 0.75rem corners; user and assistant layout remain distinct.
  • The message body takes the body role, even inside an interface context such as ChatWindow, and children inherit it. Plain text keeps its line breaks; compose .formatted in children for paragraph rhythm.

04Parameters

NameTypeDefaultDescription
role'user' | 'assistant'"assistant"Chooses message alignment, width and surface.
labelstringundefinedSpeaker name. Defaults to the built-in name for the role in the Page language, such as You or Assistant.
textstring""Escaped plain-text message, used when no children snippet is provided.
sourcestring""Optional source or attribution below the message.
childrenSnippetundefinedRich message content replacing text. The app is responsible for sanitizing any rendered HTML.

05Accessibility

Keep the speaker label meaningful. Plain text is escaped. The app must sanitize any untrusted HTML rendered in children; the component does not parse Markdown or validate source URLs.

Related subjects

distributed·gallery