A status note that stays in the content flow: a failed load, truncated results, an unmatched customer, an owner conflict, an invitation hint. A light tone-tinted fill with an icon and text, optionally with actions and a close button; it doesn’t float and doesn’t go away on its own.
Status: experimental · Components: Alert
Import
Section titled “Import”import { Alert } from 'nacre'Write one sentence as the content and pick tone by severity; md (page level) is the default and the icon follows the tone.
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"> No customer profile matched. You can link a customer manually. </Alert> </View> )}Examples
Section titled “Examples”Inline inverse alert
Section titled “Inline inverse alert”Use xs inside a card. On an inverse surface the icon, text and dismiss button use the primary foreground.
import { Alert, Card } from 'nacre'
export function AlertInverse() { return ( <Card size="xs" surface="inverse"> <Alert testID="alert-inverse" size="xs" tone="warning" surface="inverse"> Incoming calls are unavailable </Alert> </Card> )}Five tones
Section titled “Five tones”neutral for plain notes, info for reminders, success for done, warning for incomplete results or things to watch, destructive for failures. Don’t make everything a 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">The customer gets a satisfaction survey when the chat ends</Alert> <Alert tone="info" testID="alert-info">Customer not identified; notes won’t be added to their service history</Alert> <Alert tone="success" testID="alert-success">Rating invitation sent</Alert> <Alert tone="warning" testID="alert-warning">Too many results; showing the first 50. Narrow your search.</Alert> <Alert tone="destructive" testID="alert-destructive">Failed to load data</Alert> </View> )}Failure and retry
Section titled “Failure and retry”Put library Buttons in actions: without a title they sit on the right; match the button to size (sm for md, xs for sm). destructive is announced right away by default.
Phone: On phones the buttons sit below the text at the alert’s size; destructive is announced immediately by default.
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`}>Reloaded</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) }} > Reload </Button> } > Failed to load the dashboard. Try again later. </Alert> </If> <Text testID="alert-retry-count" class={`${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>{`$Retries: ${attempts()}`}</Text> </View> )}Title and body
Section titled “Title and body”With a title, the title takes the tone color, the body drops to the secondary color and actions go below the body — good for narrow columns (a failed AI answer).
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="AI answer failed" actions={ <Button size="sm" variant="outline"> Retry </Button> } > The model service timed out. You can try again. </Alert> </View> )}Small and dismissible
Section titled “Small and dismissible”size=“sm” goes in right panels, forms and dialogs; dismissible + onDismiss add a close button, and whether the alert shows is up to the caller’s state.
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)}> Show again </Button> } > <Alert tone="warning" size="sm" testID="alert-compact" announce="off" dismissible onDismiss={() => open.set(false)}> Chen Zhiyuan is also handling this ticket </Alert> </If> <Alert tone="info" size="sm" testID="alert-compact-info"> AI drafted this from the chat. Review before submitting. </Alert> </View> )}Accessibility
Section titled “Accessibility”- announce decides how screen readers announce it: assertive is role=“alert” and interrupts right away; polite waits until the reader is idle; off doesn’t announce. destructive defaults to assertive, everything else to polite.
- Notes that are there as soon as the page opens (unmatched, not linked) use polite or off — don’t steal attention with assertive; failures that appear after a user action use assertive.
- The icon is decorative; put the meaning in the text. Action buttons and the close button are reachable with Tab; the close button is named “Close” by default.
Do / Don’t
Section titled “Do / Don’t”Do
- Pick the tone by severity; use destructive only for failures
- Offer “Retry” on failures
- Say what happened and what to do next
- Keep one alert per spot; merge several into one
Don’t
- Use it for action results that should fade in seconds (use toast)
- Ask the user to decide (use a dialog)
- Explain an empty list (use EmptyState)
- Put a primary button in an alert (use outline / secondary)
Property descriptions follow the Chinese source comments.
| Prop | Type | Default | Description |
|---|---|---|---|
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 |
— | 根节点的布局类(外边距、宽度) |
* required