Chat composer
npx shadcn add https://ui.klarhimmel.com/r/chat-composer.jsonCopy for AIDetailsAbout, 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
Import
Import
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
ChatComposer.label | string | required | Required: names the text box (not shown). |
ChatComposer.value | string | required | Required. 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) => void | required | Required. 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) => void | required | Enter or the send button, with text that may be sent. The app clears `value`. |
ChatComposer.placeholder | string | - | As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip). |
ChatComposer.busy | boolean | - | 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.disabled | boolean | - | As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip). |
ChatComposer.maxLength | number | - | Shows a count from 90 % of it; over it, send waits. |
ChatComposer.maxRows | number | 8 | Rows 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.menu | ComposerMenuItem[][] | - | 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.model | ComposerModel | - | The model, shown and changed on the right (Felix 18:53). Models and levels come from the app. |
ChatComposer.dictation | boolean | { 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.chips | ReactNode | - | Above the text, inside the box: attachments, what is open beside the chat, a long paste (ComposerChip). |
ChatComposer.canSendEmpty | boolean | - | 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.tools | ReactNode | - | Before send: a model picker, a mode toggle, a mic (ComposerTool). In the pill's row; below the text in a narrow box. |
ChatComposer.autoFocus | boolean | - | As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip). |
ChatComposer.inputRef | Ref<HTMLTextAreaElement> | - | |
ChatComposer.onPaste | (e: ClipboardEvent<HTMLTextAreaElement>) => void | - | |
ChatComposer.note | ReactNode | - | One small line under the box: a disclaimer ("Answers can be wrong."), a privacy link. |
ChatComposer.labels | Partial<ChatComposerLabels> | - | The buttons' names and the count. Pass them translated. |
ChatComposer.className | string | - | Extra classes, merged after the component's own. |
ComposerChip.icon | ReactNode | - | |
ComposerChip.children | ReactNode | required | |
ComposerChip.onRemove | () => void | - | |
ComposerChip.removeLabel | string | 'Remove' | |
ComposerChip.title | string | - | |
ComposerTool.icon | ReactNode | - | |
ComposerTool.children | ReactNode | - |