# ChatPanel

> The shell a conversation lives in: a sticky header, a transcript that pins itself to the bottom while an answer arrives and offers the way back once you scroll up, and a sticky composer row.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: AI Chat
- Tags: ai, chat, panel, shell, compound
- Types: `ChatPanelProps`, `ChatEmptyStateProps`
- Docs: https://fancy-ui.rama.app/docs/components/chat-panel
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/chat-panel

## Import

```tsx
import { ChatPanel } 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 |
| --- | --- | --- | --- |
| `streaming` | `boolean` | `false` | Whether a reply is still arriving; pins the transcript to its bottom until the reader scrolls up |
| `empty` | `boolean` | `false` | Renders the emptyState snippet in place of the message stream |
| `returnLabel` | `string` | `"Jump to latest"` | Label on the pill offered once the reader scrolls away from the bottom |
| `sound` | `boolean` | `false` | Plays press on the jump-to-latest pill, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `header` | Sticky top region: a title, a model name, a close button |
| `children` | The message stream, filling the scroll region |
| `composer` | Sticky bottom region — where Composer belongs |
| `emptyState` | Rendered instead of children while empty — where ChatEmptyState belongs |

## Example

```tsx
import { useState } from "react";
import { ChatMessage, ChatPanel, Composer } from "fancy-ui-react";

interface Turn {
	id: string;
	role: "user" | "assistant";
	content: string;
}

export function ChatPanelExample() {
	const [turns, setTurns] = useState<Turn[]>([
		{ id: "t1", role: "user", content: "Why does my transcript jump around?" },
		{
			id: "t2",
			role: "assistant",
			content:
				"Something is scrolling it for you on every chunk, even when you were reading above.",
		},
	]);
	const [draft, setDraft] = useState("");

	function send({ text }: { text: string }) {
		setTurns((current) => [
			...current,
			{ id: `t${current.length + 1}`, role: "user", content: text },
		]);
	}

	return (
		<div className="h-[26rem] w-full max-w-xl">
			<ChatPanel
				header={
					<div className="flex items-center justify-between px-4 py-3">
						<p className="text-sm font-semibold">Scrolling behaviour</p>
					</div>
				}
				composer={
					<div className="p-3">
						<Composer
							value={draft}
							onValueChange={setDraft}
							placeholder="Ask a follow-up"
							onSubmit={send}
						/>
					</div>
				}
			>
				<div className="flex flex-col gap-5 px-4 py-4">
					{turns.map((turn) => (
						<ChatMessage key={turn.id} role={turn.role} content={turn.content} />
					))}
				</div>
			</ChatPanel>
		</div>
	);
}
```
