Chat
Description
A component to display a chat
ChatArea is a scrolling transcript built for streaming replies. It follows the live edge while the reader is at the bottom, stops following the moment they scroll up so new content doesn't pull them back, and shows a scroll-to-latest button to re-engage. Call .ScrollAnchor() on a ChatMessage (typically the user's turn) to mark a turn boundary — the transcript settles that message near the top (with a configurable PreviousItemPeek) so the following reply grows into the screen below it. Busy(true/false) toggles aria-busy while a reply streams. ChatMessage content is wrapped in a DeltaComponent, so .ReplaceContent(...) can be called repeatedly to animate streamed/typed text.
Sample
API reference
public class ChatArea : IComponentA chat transcript surface that lays out a sequence of messages with sender attribution, avatars and timestamps. It keeps streamed replies in view while the reader is at the live edge, stops following the moment the reader scrolls away, and offers a scroll-to-latest button to re-engage.
- Namespace
- Tesserae
- Implements
- IComponent
Constructors
| Name | Description |
|---|---|
| ChatArea | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| IsAtBottom | Gets whether the transcript is currently scrolled to (or within a few pixels of) the bottom. |
| IsFollowingOutput | Gets whether the transcript is currently following streamed output (auto-scrolling to the live edge). |
public bool IsAtBottom { get ; }Gets whether the transcript is currently scrolled to (or within a few pixels of) the bottom.
Methods
| Name | Description |
|---|---|
| OnScroll | Registers a callback invoked when the scroll event fires. |
| OnFocus | Registers a callback invoked when the focus event fires. |
| OnBlur | Registers a callback invoked when the blur event fires. |
| Background | Gets or sets the CSS background of the component. |
| DefaultScrollPosition | Sets where the transcript settles when it is first populated (or re-populated after Clear). |
| PreviousItemPeek | Sets how many pixels of the previous turn stay visible above an anchored message when a new turn begins. |
| Busy | Toggles the aria-busy state on the transcript; set it while a turn is streaming so screen readers can defer announcements until the reply completes. |
| Add | Adds the given item to the component. |
| PrependRange | Inserts a batch of older messages at the top of the transcript while preserving the reader's current scroll position (so loading history above the fold does not move what they are reading). |
| RebuildPreservingScroll | Runs a repopulation (typically Clear followed by a batch of Add calls) while preserving the reader's scroll position: if they were at the live edge it stays pinned to the bottom, otherwise their current position is restored so re-rendering the transcript does not yank them around. |
| Clear | Clears the component's current state. |
| ScrollToEnd | Scrolls to the bottom of the transcript and re-engages following of streamed output. |
| ScrollToStart | Scrolls to the top of the transcript. |
| ScrollToMessage | Scrolls the message with the given identifier into view. Returns false if no such message is mounted. |
| Render | Renders the component's root HTML element. |
public ChatArea OnScroll(ComponentEventHandler<ChatArea, Event> onScroll)Registers a callback invoked when the scroll event fires.
public ChatArea OnFocus(ComponentEventHandler<ChatArea, Event> onFocus)Registers a callback invoked when the focus event fires.
public ChatArea OnBlur(ComponentEventHandler<ChatArea, Event> onBlur)Registers a callback invoked when the blur event fires.
public ChatArea Background(string color)Gets or sets the CSS background of the component.
public ChatArea DefaultScrollPosition(StartPosition position)Sets where the transcript settles when it is first populated (or re-populated after Clear).
public ChatArea PreviousItemPeek(int pixels)Sets how many pixels of the previous turn stay visible above an anchored message when a new turn begins.
public ChatArea Busy(bool isBusy)Toggles the aria-busy state on the transcript; set it while a turn is streaming so screen readers can defer announcements until the reply completes.
public ChatArea PrependRange(IEnumerable<ChatMessage> older)Inserts a batch of older messages at the top of the transcript while preserving the reader's current scroll position (so loading history above the fold does not move what they are reading).
public ChatArea RebuildPreservingScroll(Action populate)Runs a repopulation (typically Clear followed by a batch of Add calls) while preserving the reader's scroll position: if they were at the live edge it stays pinned to the bottom, otherwise their current position is restored so re-rendering the transcript does not yank them around.
public ChatArea ScrollToEnd(bool smooth = false)Scrolls to the bottom of the transcript and re-engages following of streamed output.
public ChatArea ScrollToStart(bool smooth = false)Scrolls to the top of the transcript.
public bool ScrollToMessage(string identifier, bool smooth = true)Scrolls the message with the given identifier into view. Returns false if no such message is mounted.
Events
| Name | Description |
|---|---|
| Scrolled | Raised when scrolled occurs. |
| ReceivedFocus | Raised when received focus occurs. |
| LostFocus | Raised when lost focus occurs. |
public event ComponentEventHandler<ChatArea, Event> ScrolledRaised when scrolled occurs.
public event ComponentEventHandler<ChatArea, Event> ReceivedFocusRaised when received focus occurs.
public class ChatMessage : IComponentWithID, IComponent- Namespace
- Tesserae
- Implements
- IComponentWithID, IComponent
Constructors
| Name | Description |
|---|---|
| ChatMessage | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| Identifier | Gets or sets the identifier. |
| ContentHash | Gets or sets the content hash. |
| BubbleBackground | Gets or sets the bubble background. |
| IsAnchor | Gets whether this message is a turn boundary that the transcript should settle near the top when a new turn begins. |
public string Identifier { get; private set; }Gets or sets the identifier.
public string ContentHash { get; private set; }Gets or sets the content hash.
public string BubbleBackground { get; private set; }Gets or sets the bubble background.
Methods
| Name | Description |
|---|---|
| Animated | Configures the component to animated. |
| ScrollAnchor | Marks this message as a turn boundary. When it is added, the transcript treats it as the start of a new turn: it re-engages following and settles the message near the top of the viewport (with a peek of the previous turn above), so the reply that follows grows into the screen below it. |
| LeftAligned | Configures the left aligned on the component. |
| RightAligned | Configures the right aligned on the component. |
| FullWidth | Stretches the component to the full width of its parent. |
| MaxWidth | Gets or sets the CSS max-width of the component. |
| Background | Gets or sets the CSS background of the component. |
| WithReferences | Returns the component configured with the given references. |
| ReplaceContent | Replaces the content in the component. |
| KeepVisible | Configures the keep visible on the component. |
| Render | Renders the component's root HTML element. |
public ChatMessage ScrollAnchor()Marks this message as a turn boundary. When it is added, the transcript treats it as the start of a new turn: it re-engages following and settles the message near the top of the viewport (with a peek of the previous turn above), so the reply that follows grows into the screen below it.
public ChatMessage LeftAligned()Configures the left aligned on the component.
public ChatMessage RightAligned()Configures the right aligned on the component.
public ChatMessage FullWidth()Stretches the component to the full width of its parent.
public ChatMessage MaxWidth()Gets or sets the CSS max-width of the component.
public ChatMessage Background(string color)Gets or sets the CSS background of the component.
| Overload | |
|---|---|
| WithReferences(IEnumerable<IComponent>) | Returns the component configured with the given references. |
| WithReferences(IComponent) | Returns the component configured with the given references. |
public ChatMessage ReplaceContent(IComponent newContent)Replaces the content in the component.