Skip to content
Klarhimmel UI

Chat composer

npx shadcn add https://ui.klarhimmel.com/r/chat-composer.json
DetailsAbout, usage, props and more

The one chat input, a fully rounded pill: + opens files and the app's menu, a model pill, a mic, and send that shows with text and turns into a quiet stop while the answer streams. Grows into two rows when the text wraps.

Preview

menu-autumn.pdf
chat-composer.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { ChatComposer } from '@/components/klarhimmel/ui/chat-composer';

export default function Example() {
  return (
    <Theme theme="brand">
      <ChatComposer
        label="Message to the assistant"
        value="Change the opening hours"
        onChange={(text) => sessionStorage.setItem('draft', text)}
        onSend={(text) => console.log('send', text)}
      />
    </Theme>
  );
}

Import

Import

import { ChatComposer, ComposerChip, ComposerTool } from '@/components/klarhimmel/ui/chat-composer';
Files
chat-composer.tsx, in components/klarhimmel/ui/. With it: menu, theme, utils. npm: lucide-react.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
ChatComposer.labelstringrequiredRequired: names the text box (not shown).
ChatComposer.valuestringrequiredRequired. The box's name (not shown), the text, and Enter or send with text that may go. The app clears value.
ChatComposer.onChange(value: string) => voidrequiredRequired. The box's name (not shown), the text, and Enter or send with text that may go. The app clears value.
ChatComposer.onSend(text: string) => voidrequiredEnter or the send button, with text that may be sent. The app clears `value`.
ChatComposer.placeholderstring-As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip).
ChatComposer.busyboolean-An answer is streaming: send becomes stop (or a quiet Working without onStop). Typing goes on.
ChatComposer.onStop() => void-An answer is streaming: send becomes stop; without onStop a quiet Working. Typing goes on.
ChatComposer.disabledboolean-As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip).
ChatComposer.maxLengthnumber-Shows a count from 90 % of it; over it, send waits.
ChatComposer.maxRowsnumber8Rows it grows to before it scrolls.
ChatComposer.attach{ onFiles: (files: File[]) => void; accept?: string; multiple?: boolean }-Shows + at the start (a real file input). The app shows what was picked as chips.
ChatComposer.menuComposerMenuItem[][]-With it, + opens a menu above the box (+ turns into X while open): groups of the app's own items, a line between groups, submenus with a chevron. An item with `files: true` opens the file picker (needs attach). Without it, + opens the picker.
ChatComposer.modelComposerModel-The model, shown and changed on the right (Felix 18:53). Models and levels come from the app.
ChatComposer.dictationboolean | { lang?: string }-A mic for dictation (the browser's speech recognition writes into the box; no audio is kept). Hidden where the browser has none. `lang` is a BCP 47 tag ("sv-SE"); default: the page's language.
ChatComposer.chipsReactNode-Above the text, inside the box: attachments, what is open beside the chat, a long paste (ComposerChip).
ChatComposer.canSendEmptyboolean-Send works with no typed text, because the app has something else to send (an attachment picked as a chip; Klar Agent KA-155). The app decides: a chip that only says what is open beside the chat is not a message.
ChatComposer.toolsReactNode-Before send: a model picker, a mode toggle, a mic (ComposerTool). In the pill's row; below the text in a narrow box.
ChatComposer.autoFocusboolean-As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip).
ChatComposer.inputRefRef<HTMLTextAreaElement>-
ChatComposer.onPaste(e: ClipboardEvent<HTMLTextAreaElement>) => void-
ChatComposer.noteReactNode-One small line under the box: a disclaimer ("Answers can be wrong."), a privacy link.
ChatComposer.labelsPartial<ChatComposerLabels>-The buttons' names and the count. Pass them translated.
ChatComposer.classNamestring-Extra classes, merged after the component's own.
ComposerChip.iconReactNode-
ComposerChip.childrenReactNoderequired
ComposerChip.onRemove() => void-
ComposerChip.removeLabelstring'Remove'
ComposerChip.titlestring-
ComposerTool.iconReactNode-
ComposerTool.childrenReactNode-