放在内容流里、一直在的状态说明:加载失败、结果被截断、未匹配到客户、负责人冲突、邀评提示。淡语气底 + 图标 + 文字,可带操作按钮、可关闭;不浮起、不自动消失。
状态:experimental · 组件:Alert
引入
定位到「引入」import { Alert } from 'nacre'用法
定位到「用法」正文写一句话,tone 按严重程度选;默认 md(页面级),图标跟语气走。
import { View } from 'nsh'import { Alert } from 'nacre'
export function AlertUsage() { return ( <View class="w-[420px] max-w-full"> <Alert tone="warning" testID="alert-usage"> 未匹配到客户档案,可手动关联客户 </Alert> </View> )}示例
定位到「示例」反色卡内提示
定位到「反色卡内提示」xs 沿用卡片的底色与内边距。主色卡上的图标、文字和关闭钮随 inverse 取前景色。
import { Alert, Card } from 'nacre'
export function AlertInverse() { return ( <Card size="xs" surface="inverse"> <Alert testID="alert-inverse" size="xs" tone="warning" surface="inverse"> 暂时无法接听来电 </Alert> </Card> )}五种语气
定位到「五种语气」neutral 一般说明,info 提醒,success 已完成,warning 结果不完整或要留意,destructive 失败。不同严重程度别都用 warning。
import { View } from 'nsh'import { Alert } from 'nacre'
export function AlertTones() { return ( <View class="w-[420px] max-w-full gap-2"> <Alert testID="alert-neutral">结束会话后客户会收到满意度邀请</Alert> <Alert tone="info" testID="alert-info">未识别客户,小记不会进入客户服务记录</Alert> <Alert tone="success" testID="alert-success">已邀请客户评价</Alert> <Alert tone="warning" testID="alert-warning">结果过多,只显示前 50 条,请补充条件</Alert> <Alert tone="destructive" testID="alert-destructive">数据加载失败</Alert> </View> )}失败与重试
定位到「失败与重试」actions 放库的 Button:没有标题时在右侧,按钮和 size 同档(md 用 sm、sm 用 xs)。destructive 默认立即宣读。
手机:手机上按钮排在正文下方,按钮与提示条同档;destructive 默认立即宣读。
import { Text, View, signal } from 'nsh'import { Alert, Button, TEXT_SIZE } from 'nacre'
export function AlertRetry() { const failed = signal(true) const attempts = signal(0) return ( <View class="w-[420px] max-w-full gap-2"> <If when={failed()} else={<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>已重新加载</Text>} > <Alert tone="destructive" testID="alert-retry" actions={ <Button size="sm" variant="outline" testID="alert-retry-button" onPress={() => { attempts.update((n) => n + 1) failed.set(false) }} > 重新加载 </Button> } > 看板数据加载失败,请稍后重试 </Alert> </If> <Text testID="alert-retry-count" class={`${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>{`$重试次数:${attempts()}`}</Text> </View> )}标题与正文
定位到「标题与正文」有 title 时标题用语气色、正文降为次要色,操作排在正文下面,适合窄栏(智能回答失败)。
import { View } from 'nsh'import { Alert, Button, TOUCH } from 'nacre'
export function AlertTitled() { return ( <View class={TOUCH ? 'w-full' : 'w-[300px] max-w-full'}> <Alert tone="destructive" testID="alert-titled" title="智能回答失败" actions={ <Button size="sm" variant="outline"> 重试 </Button> } > 模型服务超时,可以重试一次 </Alert> </View> )}小号与可关闭
定位到「小号与可关闭」size=“sm” 放在右栏、表单、对话框里;dismissible + onDismiss 给关闭钮,显不显示由调用方的状态决定。
import { View, signal } from 'nsh'import { Alert, Button, TOUCH } from 'nacre'
export function AlertCompact() { const open = signal(true) return ( <View class={TOUCH ? 'w-full gap-2' : 'w-[300px] max-w-full gap-2'}> <If when={open()} else={ <Button size="xs" variant="outline" testID="alert-compact-reset" onPress={() => open.set(true)}> 再显示 </Button> } > <Alert tone="warning" size="sm" testID="alert-compact" announce="off" dismissible onDismiss={() => open.set(false)}> 陈智源也在处理这张工单 </Alert> </If> <Alert tone="info" size="sm" testID="alert-compact-info"> AI 已根据会话内容生成草稿,请核对后提交 </Alert> </View> )}无障碍
定位到「无障碍」- announce 决定读屏怎么宣读:assertive 是 role=“alert”、立即打断;polite 等读屏空闲时读;off 不宣读。默认 destructive 是 assertive,其余 polite。
- 页面一打开就在的说明(未匹配、未绑定)用 polite 或 off,别用 assertive 抢焦点;用户操作后才出现的失败用 assertive。
- 图标只是装饰,含义写在文字里;操作按钮与关闭钮 Tab 可达,关闭钮的读屏名默认「关闭」。
该用 / 不该用
定位到「该用 / 不该用」该用
- 按严重程度选语气,失败才用 destructive
- 失败给「重试」动作
- 文案说清楚发生了什么、接下来怎么办
- 一处只放一条,多条合并成一段
不该用
- 几秒就该消失的操作结果(用 toast)
- 要用户做决定(用对话框)
- 空列表的说明(用 EmptyState)
- 在提示条里放主按钮(用 outline / secondary)
API
定位到「API」Alert
定位到「Alert」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
tone |
AlertTone |
'neutral' |
|
title |
string |
— | 一行粗体标题;有标题时正文降为次要色,操作放在正文下面 |
children |
JSX.Element |
— | 正文:一句话文案,或自己排的文字节点 |
icon |
IconName |
— | 行首图标,默认按语气(info / check / warning / circle-x);neutral 默认 info |
actions |
JSX.Element |
— | 操作按钮(库的 Button,sm 用 xs、md 用 sm):没有标题时在右侧,有标题时在正文下面 |
dismissible |
boolean |
— | 行尾给一个关闭钮,点了调 onDismiss;提示条显不显示由调用方决定 |
onDismiss |
() => void |
— | |
dismissLabel |
string |
— | 关闭钮的读屏名,默认「关闭」 |
announce |
AlertAnnounce |
— | 出现与内容变化时读屏怎么宣读;默认 destructive 是 assertive,其余 polite |
size |
'xs' | 'sm' | 'md' |
'md' |
xs 嵌入卡内,无底色和内边距;sm 用在窄栏,md 为页面级 |
surface |
'default' | 'inverse' |
— | inverse 放在主色实底上,图标、文字与关闭钮统一使用对应的前景色 |
testID |
string |
— | |
class |
string |
— | 根节点的布局类(外边距、宽度) |
* 必填