ChatThread
ComplexMessaging
<co-chat-thread>ChatThread is a full secure-message conversation: header, message log and composer with optional AI reply suggestion.
import { ChatThread } from 'health-components';
Examples
Showcase
Read Only
With System And AI
Controlled
Usage
<ChatThread title="Henna West" subtitle="MRN-100231" ai messages={thread} onSend={text => api.send(text)} />
When to use
- Staff to patient and staff to staff messaging.
When not to use
- Comment threads on a record: a Timeline.
Variants and states
| Variant | What it is |
|---|---|
| default | Composer with Send. |
| ai | Sparkle button suggests a reply. |
| readOnly | Lock banner instead of the composer (staff previewing the portal). |
Accessibility
- The log has role log so new messages are announced.
Do and don't
- Do: Show who a message is from and when.
- Don't: Auto-send AI replies.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
messages | ChatThreadMessage[] | uncontrolled | Array<ChatMessage props & {text}> (controlled; pair with onMessagesChange) |
defaultMessages | ChatThreadMessage[] | [] | Initial messages (uncontrolled); the thread appends what the user sends |
onMessagesChange | (messages: ChatThreadMessage[]) => void | none | Called with the new list after a send |
title | string | none (no header) | Header name (patient or colleague), with an avatar |
subtitle | ReactNode | none | Header second line (MRN, reply time) |
placeholder | string | "Write a message" | Composer placeholder |
ai | boolean | false | Shows the "Suggest a reply with AI" button |
readOnly | boolean | false | Replaces the composer with a lock banner |
lockText | ReactNode | "Read-only preview. Sending is blocked for staff." | Lock banner text |
onSend | (text: string) => void | none | (text) => void: called with the trimmed text when the user sends |
onSuggest | () => void | none | Called by the AI button; never sends on its own |
Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, onChange, onInput, plus className and event handlers on the root element.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-chat-thread>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-chat-thread title="…" placeholder="…" [messages]="messages" (co-messages-change)="onMessagesChange($event.detail)"></co-chat-thread>
| Kind | Name | Description |
|---|---|---|
| property / JSON attribute | messages | Array<ChatMessage props & {text}> (controlled; pair with onMessagesChange); default uncontrolled |
| property / JSON attribute | default-messages / defaultMessages | Initial messages (uncontrolled); the thread appends what the user sends; default [] |
| attribute | title | Header name (patient or colleague), with an avatar; default none (no header) |
| attribute | placeholder | Composer placeholder; default "Write a message" |
| attribute | ai | Shows the "Suggest a reply with AI" button; default false |
| attribute | read-only / readOnly | Replaces the composer with a lock banner; default false |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| event | co-messages-change | Called with the new list after a send; default none (React: onMessagesChange) |
| event | co-send | (text) => void: called with the trimmed text when the user sends; default none (React: onSend) |
| event | co-suggest | Called by the AI button; never sends on its own; default none (React: onSuggest) |
| event | co-change | (React: onChange) |
| event | co-input | (React: onInput) |
| slot | subtitle | Header second line (MRN, reply time); default none Plain text also works as the `subtitle` attribute. |
| slot | lock-text | Lock banner text; default "Read-only preview. Sending is blocked for staff." Plain text also works as the `lock-text` attribute. |