# Composer

> The input at the bottom of a chat, taken apart: a root that owns the draft and eight parts that read it — a growing textarea, a send button that becomes a stop button, a toolbar, a model picker, an attachment row with its chips, and a completion menu you can mount twice on the same draft for / commands and @ mentions.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: AI Chat
- Tags: ai, chat, composer, input, compound
- Types: `ComposerProps`, `ComposerInputProps`, `ComposerSubmitProps`, `ComposerToolbarProps`, `ComposerModelPickerProps`, `ComposerAttachmentsProps`, `ComposerAttachmentProps`, `ComposerCommandMenuProps`, `ComposerContext`
- Docs: https://fancy-ui.rama.app/docs/components/composer
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/composer

## Import

```tsx
import { Composer } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | `""` | The draft text, bindable. Cleared by a successful submit; the attachments are not, since only the consumer knows whether an upload is still in flight |
| `attachments` | `AttachmentData[]` | `[]` | Files riding along with the draft, bindable. The consumer owns uploading them and pushing the results here |
| `disabled` | `boolean` | `false` | Blocks typing, sending, and attaching. Every part reads it off the context, so one flag takes the whole composition inert |
| `streaming` | `boolean` | `false` | A response is arriving: the send button becomes a stop button, the textarea goes readonly rather than disabled, and a submit is refused whatever triggered it |
| `placeholder` | `string` | — | Placeholder for the default input. Ignored once children replaces the composition — the ComposerInput inside it carries its own |
| `onSubmit` | `(payload: { text: string; attachments: AttachmentData[] }) => void` | — | Called with the trimmed draft and a snapshot of the attachments. Never fires on an empty draft that carries no files |
| `onStop` | `() => void` | — | Called when the stop button is pressed while streaming |
| `onAttach` | `(files: File[]) => void` | — | Called with the files handed to the picker. Upload them, then push the results onto attachments — the composer never uploads anything itself |
| `sound` | `boolean` | `false` | Plays press on send and stop, select on a model or command pick and open/close on the model menu, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `children` | Replaces the default input-and-send-row composition entirely: mount the parts in whatever order the layout needs |
| `accessory` | An overlay covering the composer — a voice panel, a drop target, a confirmation. It sits above the composition rather than replacing it, so the draft is still there when it lifts |

## Example

```tsx
import { useEffect, useRef, useState } from "react";
import { Composer } from "fancy-ui-react";

export function ComposerExample() {
	const [draft, setDraft] = useState("");
	const [reply, setReply] = useState("");
	const [streaming, setStreaming] = useState(false);

	const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);

	useEffect(() => () => clearTimeout(timer.current), []);

	function stop() {
		clearTimeout(timer.current);
		setStreaming(false);
	}

	function send({ text }: { text: string }) {
		setReply(`You asked: "${text}"`);
		setStreaming(true);
		// Stand-in for a request: the send button is a stop button until it lands.
		clearTimeout(timer.current);
		timer.current = setTimeout(() => setStreaming(false), 1200);
	}

	return (
		<div className="flex w-full max-w-xl flex-col gap-3">
			{reply ? (
				<p className="bg-muted text-foreground rounded-2xl px-4 py-3 text-sm">{reply}</p>
			) : null}
			<Composer
				value={draft}
				onValueChange={setDraft}
				streaming={streaming}
				placeholder="Ask anything"
				onSubmit={send}
				onStop={stop}
			/>
		</div>
	);
}
```
