YuhuanStudioYunUIDocs
Chat

Chat Composer

A controlled, auto-growing textarea with Enter-to-send, a send/stop button, and attachment + toolbar slots.

A chat input composer: an auto-growing textarea, Enter-to-send (Shift+Enter for a newline), a send/stop button, and slots for attachment previews and a left toolbar. It's presentational and controlled — the host owns the value, the send/stop side effects, and any loading state. While loading, the send button becomes a stop button that calls onStop.

Import

tsx
1import { ChatComposer } from "@yuhuanowo/yunui/chat";

Example

Type and press Enter (or the send button). It logs each message, then simulates a 1.4s "generating" state where the button becomes Stop.

ChatComposer

Usage

tsx
1const [value, setValue] = useState("");
2const [loading, setLoading] = useState(false);
3 
4<ChatComposer
5 value={value}
6 onChange={setValue}
7 onSend={() => send(value)}
8 onStop={() => abort()}
9 loading={loading}
10 attachments={files.map((f) => <AttachmentChip key={f.id} file={f} />)}
11 toolbar={<AttachButton onPick={addFile} />}
12/>

Props

PropTypeDefaultDescription
allowSendEmptybooleanfalseAllow sending with empty text — e.g. when attachments alone make a valid message.
attachmentsReactNodeAttachment chips / previews, rendered above the textarea.
classNamestring
disabledbooleanfalse
labels{ send?: string; stop?: string; } | undefinedAccessible names for the composer's buttons.
loadingbooleanfalse
maxRowsnumber8Max rows before the textarea scrolls.
onChange*(value: string) => void
onSend*() => voidCalled when the user sends (Enter or the send button).
onStop(() => void)Called when the stop button is pressed while `loading`.
placeholderstringSend a message…
sendDisabledbooleanfalseForce-disable the send button even with text (e.g. invalid state).
toolbarReactNodeLeft-aligned toolbar (attach, mode, feature toggles, …).
value*string

On this page