ChatComposerFrame
The shell of a conversation’s composer: a rounded card with a focus border, in two layouts, collapsed (one row) and expanded (quote / attachments, editor, toolbar). It owns no draft, sending, uploads or quick replies; the app puts those in its slots (after the frame of coss Composer).
Status: experimental · Components: ChatComposerFrame
Import
Section titled “Import”import { ChatComposerFrame } from 'nacre/chat'Expanded: header holds the quote bar and pending attachments, children is the editor, footer holds the toolbar, send hint and send button. Pass focused while the editor has focus: the border turns ring at 60% with a 15% halo (lighter than an ordinary field, since the composer is always there).
import { Text, View, signal } from 'nsh'import { Input } from 'nsh/base'import { ChatComposerFrame, ChatReplyReference } from 'nacre/chat'import { IconButton, TEXT_SIZE, TOUCH } from 'nacre'
export function ChatComposerUsage() { const focused = signal(false) const text = signal('') const quoting = signal(true) return ( <View class="w-[520px] max-w-full h-[160px]"> <ChatComposerFrame testID="demo-composer" class="flex-1" focused={focused()} header={ <If when={quoting()}> <ChatReplyReference variant="composer" class="mx-3 mt-2" prefix="Reply to" author="Chen Zhiyuan" preview="What’s the allotment rate, roughly?" onDismiss={() => quoting.set(false)} dismissLabel="Cancel quote" /> </If> } footer={ <> <IconButton icon="image" label="Image" /> <IconButton icon="sparkles" label="Writing assistant" /> <View class="flex-1" /> <If when={!TOUCH}><Text class={`shrink-0 ${TEXT_SIZE.caption} text-muted-foreground mr-2`}>⏎ to send</Text></If> <IconButton testID="demo-composer-send" icon="send" variant="primary" size="md" label="Send" disabled={!text().trim()} onPress={() => text.set('')} /> </> } > <Input testID="demo-composer-input" accessibilityLabel="Message" value={text()} onChange={(e) => text.set(e.value)} onFocus={() => focused.set(true)} onBlur={() => focused.set(false)} placeholder="Write a message…" class={`flex-1 px-3 pt-2 ${TEXT_SIZE.body} text-foreground placeholder:text-muted-foreground`} /> </ChatComposerFrame> </View> )}Examples
Section titled “Examples”Collapsed
Section titled “Collapsed”collapsed: one row with leading (the image +), the editor and trailing (shortcut hint, send); header and footer are hidden. When to collapse (300ms after it blurs while empty) is the app’s call.
Phone: collapsed: one row with the attach (+) button, the editor and send; header and footer are hidden.
import { Text, View } from 'nsh'import { ChatComposerFrame } from 'nacre/chat'import { IconButton, TEXT_SIZE, TOUCH } from 'nacre'
export function ChatComposerCollapsed() { return ( <View class="w-[520px] max-w-full h-12"> <ChatComposerFrame testID="demo-composer-collapsed" class="flex-1" focused={false} collapsed leading={<IconButton icon="plus" variant="secondary" round label="Image" />} trailing={ <View class="flex-row items-center gap-2"> <If when={!TOUCH}><Text class={`${TEXT_SIZE.caption} text-muted-foreground`}>⌘/ Quick replies</Text></If> <IconButton icon="send" variant="primary" size="md" disabled label="Send" /> </View> } > <Text class={`flex-1 min-w-0 truncate px-2 ${TEXT_SIZE.body} text-muted-foreground`}>Reply to Chen Zhiyuan…</Text> </ChatComposerFrame> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Move between the editor and the buttons in the frame; Return to send and other shortcuts belong to the app’s editor |
Accessibility
Section titled “Accessibility”- The shell itself is not in the accessibility tree; the editor and the send button carry their own names.
- disabled only looks disabled: the app must disable the editor and sending too.
Do / Don’t
Section titled “Do / Don’t”Do
- Hand focus to the editor when the empty part of the frame is pressed (onPress)
- Use ChatReplyReference variant=“composer” for the quote bar
- Hide the send hint when narrow with onFooterWidth
Don’t
- Put the draft or sending logic in the shell
- Rely on the disabled look alone to block sending
Property descriptions follow the Chinese source comments.
ChatComposerFrame
Section titled “ChatComposerFrame”| Prop | Type | Default | Description |
|---|---|---|---|
focused * |
boolean |
— | 编辑器或框里的按钮有焦点:描边换 ring 60% + 15% 光晕(常驻输入区比普通输入框轻一档) |
collapsed |
boolean |
— | 收起态:一行(leading、编辑器、trailing 横排),没有 header 与 footer; 展开态:header、编辑器、footer 竖排 |
disabled |
boolean |
— | 输入区禁用外观(secondary 底、无描边),见 ComposerFrame;编辑器与发送要由应用自己禁用 |
overlay |
JSX.Element |
— | 叠在框上的浮层锚点(写作助手、快捷回复联想);放在最前,不占排版 |
header |
JSX.Element |
— | 展开态编辑器上方:引用条(ChatReplyReference variant=“composer”)、待发附件 |
leading |
JSX.Element |
— | 收起态编辑器前(选图 +) |
trailing |
JSX.Element |
— | 收起态编辑器后(快捷键提示、发送) |
footer |
JSX.Element |
— | 展开态底部一行(工具栏、发送提示、发送) |
onFooterWidth |
(width: number) => void |
— | 底部一行的宽(窄时应用可以藏掉发送提示) |
onPress |
() => void |
— | 点框里的空白处:应用把焦点交给编辑器 |
class |
string |
— | |
testID |
string |
— | |
children * |
JSX.Element |
— | 编辑器 |
* required