ngx-prompt-kit

Chat Container

A scroll area that auto-sticks to the bottom on new content — but only if the user is already there. For a back-to-bottom affordance, bind a spartan hlmBtn to the container's canScrollDown() and scrollToBottom(); pinToTop() holds a just-sent message at the top while the reply comes in.

Examples

Auto-scroll on new messages

Add a message; the container scrolls to keep up. Scroll up manually and the auto-scroll yields to you — the floating button takes you back.

U
Message 1 — chat scrolls to follow as new content arrives.
U
Message 2 — chat scrolls to follow as new content arrives.
U
Message 3 — chat scrolls to follow as new content arrives.
U
Message 4 — chat scrolls to follow as new content arrives.
U
Message 5 — chat scrolls to follow as new content arrives.

Installation

Add the chat-container component (and the cn() utility) to your project.

ng generate ngx-prompt-kit:chat-container

Component API

PkChatContainerRoot

PropTypeDefaultDescription
classstring — Extra classes for the scroll container.
isAtBottomSignal<boolean> — Read-only signal exposed via CHAT_CONTAINER_STATE.
scrollToBottom()(behavior?: ScrollBehavior) => void — Method to programmatically scroll to bottom. Ends a pin.
canScrollDownSignal<boolean> — Whether there is content below the view (the room kept under a pinned turn not counted). Bind a spartan hlmBtn to it for a back-to-bottom button.
pinToTop()(element: HTMLElement, offset?: number) => void — Scrolls a turn to the top of the view, offset px below the edge (16 by default), and holds it there while the reply below grows, keeping room under it as long as the reply is shorter than the view. Call it with a message the user just sent, as Claude does.

PkChatContainerContent

PropTypeDefaultDescription
classstring — Extra classes for the inner flex column.

PkChatContainerScrollAnchor

PropTypeDefaultDescription
classstring — Extra classes for the 1-pixel anchor element.