ngx-prompt-kit

Composer

ngx-prompt-kit original — not part of ibelick/prompt-kit

A chat composer whose text box grows with the draft and then scrolls, with an expand toggle for long drafts, an optional attach button, slots for chips and a model selector, and a send button that becomes stop while a reply streams. The text box is a borderless hlmTextarea and every button an hlmBtn. Put it in whatever frame your layout needs; the examples use a plain bordered box.

Examples

Empty state

A composer centred in an empty chat. Enter sends, Shift+Enter adds a line; the + button opens a file picker.

What can I help with?

Busy and stop

While busy, the send button becomes a stop button that emits (stopped). Typing still works, but Enter won't send until the reply is done.

Long drafts

The text box grows up to maxHeight (here 160px) and then scrolls. Once it overflows, an expand toggle in the corner grows it to 60% of the viewport; sending shrinks it again.

With a model selector

Project a pk-model-selector into [pkComposerEnd] and anchor its panel to the whole composer via the public element.

Installation

Add the composer component (and the cn() utility) to your project.

ng generate ngx-prompt-kit:composer

It is built on spartan/ui, so add these helm components too: button, textarea.

ng g @spartan-ng/cli:ui button textarea

Component API

PkComposer

PropTypeDefaultDescription
valuestring '' The draft. Two-way bindable via [(value)], so a draft can survive navigation.
placeholderstring 'Message' Placeholder of the text box.
labelstring 'Message' Accessible name for the text box (a visually hidden label).
busyboolean false A reply is being generated: the send button becomes a stop button and Enter no longer sends.
disabledboolean false Disables the text box, the attach button and sending.
sendBlockedboolean false Keeps the send button disabled, e.g. while attachments upload.
maxHeightnumber 200 Height in px the text box grows to before it scrolls and the expand toggle appears.
attachableboolean false Shows the attach (+) button, which opens a file picker.
acceptstring '' File types the picker offers, as for <input type="file" accept>.
describedBystring '' Id(s) for the text box’s aria-describedby, e.g. a hint or error.
classstring '' Extra classes for the host.

PkComposer outputs & members

PropTypeDefaultDescription
submitted(text: string) => void — The trimmed draft, on Enter or the send button. The draft is then cleared and the box shrinks back.
stopped() => void — The stop button was pressed while busy.
filesPicked(files: File[]) => void — Files picked through the attach button.
elementElementRef<HTMLElement> — The composer’s element, e.g. to anchor a model selector’s panel to the whole composer.
expandedWritableSignal<boolean> — Whether the text box is grown to 60% of the viewport for long drafts.
focus()void — Focuses the text box. Clicks on the composer’s padding do this too.

PkComposer content projection

PropTypeDefaultDescription
[pkComposerTop]element — Above the text, e.g. attachment chips or an upload error.
[pkComposerStart]element — In the action row, after the attach button.
[pkComposerEnd]element — In the action row, before the send button, e.g. a model selector.