# Chat composer

- **[Atoms](/components/)**

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

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

- **CLI**

  ```
  npx shadcn add https://ui.klarhimmel.com/r/chat-composer.json
  ```
- **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

- **ChatComposer.label**: Required: names the text box (not shown).
- **ChatComposer.value**: Required. The box's name (not shown), the text, and Enter or send with text that may go. The app clears value.
- **ChatComposer.onChange**: Required. The box's name (not shown), the text, and Enter or send with text that may go. The app clears value.
- **ChatComposer.onSend**: Enter or the send button, with text that may be sent. The app clears `value`.
- **ChatComposer.placeholder**: As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip).
- **ChatComposer.busy**: An answer is streaming: send becomes stop (or a quiet Working without onStop). Typing goes on.
- **ChatComposer.onStop**: An answer is streaming: send becomes stop; without onStop a quiet Working. Typing goes on.
- **ChatComposer.disabled**: As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip).
- **ChatComposer.maxLength**: Shows a count from 90 % of it; over it, send waits.
- **ChatComposer.maxRows**: Rows it grows to before it scrolls.
- **ChatComposer.attach**: Shows + at the start (a real file input). The app shows what was picked as chips.
- **ChatComposer.menu**: 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**: The model, shown and changed on the right (Felix 18:53). Models and levels come from the app.
- **ChatComposer.dictation**: 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**: Above the text, inside the box: attachments, what is open beside the chat, a long paste (ComposerChip).
- **ChatComposer.canSendEmpty**: 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**: 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**: As on a textarea; inputRef and onPaste reach the textarea too (focus it again, turn a long paste into a chip).
- **ChatComposer.inputRef**
- **ChatComposer.onPaste**
- **ChatComposer.note**: One small line under the box: a disclaimer ("Answers can be wrong."), a privacy link.
- **ChatComposer.labels**: The buttons' names and the count. Pass them translated.
- **ChatComposer.className**: Extra classes, merged after the component's own.
- **ComposerChip.icon**
- **ComposerChip.children**
- **ComposerChip.onRemove**
- **ComposerChip.removeLabel**
- **ComposerChip.title**
- **ComposerTool.icon**
- **ComposerTool.children**

[Previous](/components/agent-chat)

[Next](/components/rich-text-editor)
