被引用的原消息:气泡里的引用块(点了回到原文)与输入区上方的「回复 某人:…」条(带取消)。只管外观与点击,找原消息、定位、闪烁由应用做(参照 coss ChatReplyReference)。
状态:experimental · 组件:ChatReplyReference
引入
定位到「引入」import { ChatReplyReference } from 'nacre/chat'用法
定位到「用法」放在气泡里正文之后:作者、两行截断的摘要;点了由应用滚到原消息并闪烁。
import { Text, View, signal } from 'nsh'import { TEXT_SIZE } from 'nacre'import { ChatBubble, ChatReplyReference, chatTextClass } from 'nacre/chat'
export function ChatReplyUsage() { const located = signal(0) return ( <View class="flex-row flex-wrap items-center gap-4"> <ChatBubble side="outgoing" first> <Text class={`${TEXT_SIZE.body} ${chatTextClass('outgoing')}`}>改完之后新成交按港币结算</Text> <ChatReplyReference testID="demo-reply" author="林嘉怡" preview="结算币种在「资产 › 现金 › 结算币种」里改" onPress={() => located.update((n) => n + 1)} /> </ChatBubble> <Text testID="demo-reply-located" class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$已定位 ${located()}`}</Text> </View> )}示例
定位到「示例」图片、文件、已撤回
定位到「图片、文件、已撤回」图片与视频在 leading 放缩略图、不给摘要;文件给图标与文件名;原消息已撤回时 disabled,悬停说明原因。
手机:图片与视频在 leading 放缩略图、不给摘要;文件给图标与文件名;原消息已撤回时置灰不可点。
import { Text, View } from 'nsh'import { Icon, TEXT_SIZE } from 'nacre'import { ChatBubble, ChatReplyReference, chatTextClass } from 'nacre/chat'
export function ChatReplyKinds() { return ( <View class="flex-row flex-wrap items-start gap-4"> <ChatBubble side="incoming" first> <Text class={`${TEXT_SIZE.body} ${chatTextClass('incoming')}`}>就是这张</Text> <ChatReplyReference author="陈智源" leading={ <View class="w-10 h-10 rounded bg-muted items-center justify-center"> <Icon name="image" size={16} color="text-tertiary" /> </View> } /> </ChatBubble> <ChatBubble side="incoming" first> <Text class={`${TEXT_SIZE.body} ${chatTextClass('incoming')}`}>文件收到了吗?</Text> <ChatReplyReference leading={<Icon name="file" size={16} color="muted-foreground" />} preview="statement.pdf" /> </ChatBubble> <ChatBubble side="outgoing" first> <Text class={`${TEXT_SIZE.body} ${chatTextClass('outgoing')}`}>原消息已撤回</Text> <ChatReplyReference testID="demo-reply-disabled" author="陈智源" preview="加我微信私聊" disabled disabledHint="原消息已撤回" onPress={() => {}} /> </ChatBubble> </View> )}输入区的引用条
定位到「输入区的引用条」variant=“composer”:28 高的条,「回复 作者:」后跟单行摘要,点摘要回看原文,× 取消引用。
import { View, signal } from 'nsh'import { Button } from 'nacre'import { ChatReplyReference } from 'nacre/chat'
export function ChatReplyComposer() { const quoting = signal(true) return ( <View class="w-[420px] max-w-full gap-2"> <If when={quoting()} else={<Button testID="demo-reply-again" size="xs" onPress={() => quoting.set(true)}>再引用一次</Button>}> <ChatReplyReference variant="composer" testID="demo-reply-bar" prefix="回复" author="陈智源" preview="那中签率大概多少?" onPress={() => {}} onDismiss={() => quoting.set(false)} dismissLabel="取消引用" /> </If> </View> )}键盘
定位到「键盘」| 键 | 行为 |
|---|---|
| Tab | 聚焦到引用块或引用条的摘要 |
| Space / Return | 回到原消息 |
无障碍
定位到「无障碍」- 引用块读作按钮;composer 变体的可点区读「回复 作者」,取消钮读 dismissLabel。
- 已撤回的引用不可点,悬停提示原因。
该用 / 不该用
定位到「该用 / 不该用」该用
- 摘要用纯文本(去掉 Markdown 标记)
- 点了先定位、定位完再闪烁原消息
不该用
- 在引用块里放可交互的内容
- 原消息不可回看时仍可点
API
定位到「API」ChatReplyReference
定位到「ChatReplyReference」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
variant |
'message' | 'composer' |
— | message:气泡里被引用的原消息(点了回到原文); composer:输入区上方「回复 某人:…」条,带取消 |
author |
string |
— | 原消息作者 |
preview |
string |
— | 原消息摘要(文字、文件名);图片等用 leading 放缩略图,可不给 |
leading |
JSX.Element |
— | 摘要前的缩略图或类型图标(message 变体) |
prefix |
string |
— | composer 变体作者前的动词,如「回复」 |
disabled |
boolean |
— | 原消息不可回看(已撤回):不可点,悬停说明原因 |
disabledHint |
string |
— | |
onPress |
() => void |
— | |
onDismiss |
() => void |
— | composer 变体的取消 |
dismissLabel |
string |
— | |
accessibilityLabel |
string |
— | |
testID |
string |
— | 根节点;可点区 ${testID}-open、取消钮 ${testID}-dismiss、摘要 ${testID}-text |
class |
string |
— |
* 必填