# 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-vue` (Vue 3.5+ + 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/vue/src/components/composer

## Import

```vue
<script setup lang="ts">
import { Composer } from 'fancy-ui-vue';
</script>
```

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

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

Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in a Vue template; when one differs from the Svelte name, the Svelte name follows in parentheses. Snippets become named slots (`#default` is the default snippet), a prop the Vue port declares as a model is a `v-model:<name>` (except `ref`, exposed via `defineExpose({ ref })`: put a template ref on the component and read `.ref`) and callbacks are listeners (`onclick` is `@click`). Every component sets `inheritAttrs: false`: `class` is a declared prop, merged where the Svelte component applies it (not always the root element), and only when the props table below lists it; other attributes do not fall through unless the package README lists the component as forwarding native attributes. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/vue#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model:value` (Svelte `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 |
| `v-model:attachments` (Svelte `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 |
| `@submit` (Svelte `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 |
| `@stop` (Svelte `onStop`) | `() => void` | — | Called when the stop button is pressed while streaming |
| `@attach` (Svelte `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 |

## Slots

| Slot | Description |
| --- | --- |
| `#default` (Svelte `children`) | Replaces the default input-and-send-row composition entirely: mount the parts in whatever order the layout needs |
| `#accessory` (Svelte `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

```vue
<script setup lang="ts">
import { onBeforeUnmount, ref } from "vue";
import { Composer } from "fancy-ui-vue";

const draft = ref("");
const reply = ref("");
const streaming = ref(false);

let timer: ReturnType<typeof setTimeout> | undefined;

onBeforeUnmount(() => clearTimeout(timer));

function stop() {
	clearTimeout(timer);
	streaming.value = false;
}

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

<template>
	<div class="flex w-full max-w-xl flex-col gap-3">
		<p v-if="reply" class="bg-muted text-foreground rounded-2xl px-4 py-3 text-sm">{{ reply }}</p>
		<Composer
			v-model:value="draft"
			:streaming="streaming"
			placeholder="Ask anything"
			:on-submit="send"
			:on-stop="stop"
		/>
	</div>
</template>
```
