Skip to main content

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​

Storybook

Read Only​

Storybook

With System And AI​

Storybook

Controlled​

Storybook

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​

VariantWhat it is
defaultComposer with Send.
aiSparkle button suggests a reply.
readOnlyLock 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​

PropTypeDefaultDescription
messagesChatThreadMessage[]uncontrolledArray<ChatMessage props & {text}> (controlled; pair with onMessagesChange)
defaultMessagesChatThreadMessage[][]Initial messages (uncontrolled); the thread appends what the user sends
onMessagesChange(messages: ChatThreadMessage[]) => voidnoneCalled with the new list after a send
titlestringnone (no header)Header name (patient or colleague), with an avatar
subtitleReactNodenoneHeader second line (MRN, reply time)
placeholderstring"Write a message"Composer placeholder
aibooleanfalseShows the "Suggest a reply with AI" button
readOnlybooleanfalseReplaces the composer with a lock banner
lockTextReactNode"Read-only preview. Sending is blocked for staff."Lock banner text
onSend(text: string) => voidnone(text) => void: called with the trimmed text when the user sends
onSuggest() => voidnoneCalled 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>
KindNameDescription
property / JSON attributemessagesArray<ChatMessage props & {text}> (controlled; pair with onMessagesChange); default uncontrolled
property / JSON attributedefault-messages / defaultMessagesInitial messages (uncontrolled); the thread appends what the user sends; default []
attributetitleHeader name (patient or colleague), with an avatar; default none (no header)
attributeplaceholderComposer placeholder; default "Write a message"
attributeaiShows the "Suggest a reply with AI" button; default false
attributeread-only / readOnlyReplaces the composer with a lock banner; default false
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
eventco-messages-changeCalled with the new list after a send; default none (React: onMessagesChange)
eventco-send(text) => void: called with the trimmed text when the user sends; default none (React: onSend)
eventco-suggestCalled by the AI button; never sends on its own; default none (React: onSuggest)
eventco-change (React: onChange)
eventco-input (React: onInput)
slotsubtitleHeader second line (MRN, reply time); default none Plain text also works as the `subtitle` attribute.
slotlock-textLock banner text; default "Read-only preview. Sending is blocked for staff." Plain text also works as the `lock-text` attribute.