A general composer frame: a rounded card with a focus border, removable quote chips, a multiline input that grows with its content, an inline send / stop button and a disabled state. For places where you type a passage and send it, such as Copilot questions and notes; the conversation composer adds collapsed / expanded layouts on top of it (ChatComposerFrame). It owns no draft or sending logic.
Status: experimental · Components: ComposerFrame
Import
Section titled “Import”import { ComposerFrame } from 'nacre/chat'Controlled value / onChange; Return goes to onSubmit, Shift+Return inserts a line. The input grows from one line up to maxHeight (108 by default), then scrolls. The inline send button appears only with onSend and is disabled when canSend is false; chips sit above the input and each can be removed.
import { Text, View, signal } from 'nsh'import { TEXT_SIZE, TOUCH } from 'nacre'import { ComposerFrame } from 'nacre/chat'import type { ComposerChip } from 'nacre/chat'
export function ComposerUsage() { const text = signal('') const sent = signal<string[]>([]) const chips = signal<ComposerChip[]>([ { id: 'q1', text: 'What’s the allotment rate, roughly?' }, ]) const canSend = () => text().trim() !== '' || chips().length > 0 const send = () => { if (!canSend()) return sent.update((list) => [...list, text()]) text.set('') chips.set([]) } return ( <View class="w-[420px] max-w-full gap-2"> <ComposerFrame testID="demo-composer-frame" value={text()} onChange={(value) => text.set(value)} onSubmit={send} placeholder="Ask anything" chips={chips()} onRemoveChip={(id) => chips.update((list) => list.filter((chip) => chip.id !== id))} onSend={send} sendIcon="sparkles" canSend={canSend()} /> <Text testID="demo-composer-frame-sent" class={`${TOUCH ? 'px-4' : ''} ${TEXT_SIZE.small} text-muted-foreground`}>{`$Sent ${sent().length}`}</Text> </View> )}Examples
Section titled “Examples”While generating (streaming) with onStop given, the send button at the end of the row becomes a stop button; it turns back into send once stopped.
import { View, signal } from 'nsh'import { ComposerFrame } from 'nacre/chat'
export function ComposerStreaming() { const text = signal('') const streaming = signal(true) return ( <View class="w-[420px] max-w-full"> <ComposerFrame testID="demo-composer-streaming" value={text()} onChange={(value) => text.set(value)} placeholder="Follow up" streaming={streaming()} onStop={() => streaming.set(false)} onSend={() => streaming.set(true)} canSend={text().trim() !== ''} /> </View> )}Disabled
Section titled “Disabled”disabled only applies to the input area: the fill turns secondary and the border goes away, the built-in input is read-only, chips cannot be removed and the built-in send is disabled; app buttons placed in trailing / footer stay pressable (“Start conversation” after a chat ends).
import { View, signal } from 'nsh'import { Button } from 'nacre'import { ComposerFrame } from 'nacre/chat'
export function ComposerDisabled() { const started = signal(false) return ( <View class="w-[420px] max-w-full h-[120px]"> <ComposerFrame testID="demo-composer-disabled" class="flex-1" disabled={!started()} stacked placeholder="This conversation has ended" footer={ <> <View class="flex-1" /> <Button testID="demo-composer-start" variant="primary" size="sm" onPress={() => started.set(true)}> Start conversation </Button> </> } /> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Return | In the input: submit (onSubmit) |
| Shift+Return | In the input: new line |
| Tab | Move between chip remove buttons, the input and the send button |
Accessibility
Section titled “Accessibility”- The input reads accessibilityLabel (the placeholder by default).
- Send, stop and chip remove buttons each have a name, defaulting to the library’s text (Send, Stop, Remove).
- When disabled, the built-in input and send are reported unavailable; the frame itself is not in the accessibility tree.
Do / Don’t
Section titled “Do / Don’t”Do
- Let the app decide whether sending is allowed and pass canSend
- Truncated chip text shows in full on hover (built in)
- When disabled, offer the next step in trailing / footer (start a conversation)
Don’t
- Rely on the disabled look alone to block sending (the app’s send logic must check too)
- Put draft or queue logic in the frame
- Use it directly for the conversation composer (use ChatComposerFrame, which collapses / expands)
Property descriptions follow the Chinese source comments.
ComposerFrame
Section titled “ComposerFrame”| Prop | Type | Default | Description |
|---|---|---|---|
focused |
boolean |
— | 编辑器或框里的按钮有焦点:描边换 ring 50% + 15% 光晕。不给时跟内置输入框的焦点走 |
disabled |
boolean |
— | 输入区禁用:底换 secondary、去掉描边,内置输入框不可编辑、chip 不能删、内置发送不可点; leading / trailing / footer 里应用自己的按钮不受影响(会话已结束时的「发起会话」) |
align |
'end' | 'center' |
— | 一行里各件的纵向对齐:end(默认,输入长高时按钮留在末行)/ center(固定一行高的收起态) |
overlay |
JSX.Element |
— | 叠在框上的浮层锚点(联想、写作助手);放在最前,不占排版 |
chips |
readonly ComposerChip[] |
— | 可删的引用 chip,排在输入上方 |
onRemoveChip |
(id: string) => void |
— | |
removeChipLabel |
string |
— | chip 删除钮的读屏名,默认「移除」 |
header |
JSX.Element |
— | chip 区下方、输入上方的自由内容(引用条、待发附件) |
leading |
JSX.Element |
— | 横排时输入前(选图 +) |
trailing |
JSX.Element |
— | 横排时输入后、内置发送钮前(快捷键提示、应用自己的发送) |
stacked |
boolean |
— | 竖排:chip 与 header、输入、footer 上下排,leading / trailing / 内置发送不显示;默认横排一行 |
footer |
JSX.Element |
— | 竖排时的底部一行(工具栏、发送提示、发送) |
onFooterWidth |
(width: number) => void |
— | 底部一行的宽(窄时应用可以藏掉发送提示) |
onPress |
() => void |
— | 点框里的空白处:应用把焦点交给编辑器 |
value |
string |
— | 内置输入框的值(受控);给了 children 时不用 |
onChange |
(value: string) => void |
— | |
onSubmit |
() => void |
— | Return 提交(Shift+Return 换行);能不能发由应用判断 |
placeholder |
string |
— | |
accessibilityLabel |
string |
— | 内置输入框的读屏名,默认同 placeholder |
inputRef |
(node: InputRef) => void |
— | |
maxHeight |
number |
108 |
内置输入框随内容长高的上限(pt),超过后内部滚动 |
onSend |
() => void |
— | 给了就在行尾放内置发送钮(主色圆钮) |
sendLabel |
string |
— | 发送钮读屏名,默认「发送」 |
sendIcon |
IconName |
'send' |
发送钮图标,默认 send |
canSend |
boolean |
— | 能不能发(有内容、身份就绪);false 时发送钮禁用 |
streaming |
boolean |
— | 生成中:有 onStop 时行尾换成停止钮 |
onStop |
() => void |
— | |
stopLabel |
string |
— | 停止钮读屏名,默认「停止」 |
class |
string |
— | 根节点的布局类(外边距、flex),不改颜色 |
testID |
string |
— | 根节点;输入 ${testID}-input、发送 ${testID}-send、停止 ${testID}-stop、chip 区 ${testID}-chips、chip ${testID}-chip、删除 ${testID}-chip-remove |
children |
JSX.Element |
— | 自带的编辑器(富文本);不给时用内置的多行输入框 |
* required