A light notice for action results and errors that doesn’t interrupt work: call toast.show({ kind, message, … }) from anywhere, and mount
Phone: Light feedback for results and errors: on phones success toasts are skipped unless essential, and warnings and errors appear as a banner below the navigation bar.
Status: stable · Components: ToastHost
Import
Section titled “Import”import { ToastHost } from 'nacre'toast.show shows one toast; kind defaults to info. Mount ToastHost once at the app root (the app this page runs in already has it).
import { Button, toast, TOUCH } from 'nacre'
export function ToastUsage() { return ( <Button onPress={() => toast.show({ kind: 'success', message: 'Saved', essential: TOUCH })}> Save </Button> )}Examples
Section titled “Examples”Four kinds
Section titled “Four kinds”info / success / warning / error, told apart by icon and color: error is a circled X, warning a triangle; warnings and errors have a close button.
import { View } from 'nsh'import { Button, toast, TOUCH } from 'nacre'
export function ToastKinds() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Button variant="outline" onPress={() => toast.show({ message: 'Chat link copied' })}>Info</Button> <Button variant="outline" onPress={() => toast.show({ kind: 'success', message: 'Transferred to Chen Zhiyuan', essential: TOUCH })}>Success</Button> <Button variant="outline" onPress={() => toast.show({ kind: 'warning', message: 'The customer is offline; the message will be delivered when they’re back online' })}>Warning</Button> <Button variant="outline" onPress={() => toast.show({ kind: 'error', message: 'Failed to send. Check your network.' })}>Error</Button> </View> )}With an action
Section titled “With an action”action adds a button (“Retry”) that runs and dismisses the toast; toasts with an action can be closed manually.
import { Text, View, signal } from 'nsh'import { Button, toast, TEXT_SIZE } from 'nacre'
export function ToastRetry() { const attempts = signal(0) const send = () => { attempts.update((n) => n + 1) toast.show({ kind: 'error', message: 'Network error. The message wasn’t sent.', action: { label: 'Retry', onPress: send } }) } return ( <View class="flex-row items-center gap-3"> <Button variant="outline" onPress={send}>Send message</Button> <Text class={`${TEXT_SIZE.small} text-muted-foreground tabular-nums`}>{`$Attempts: ${attempts()}$`}</Text> </View> )}Description and deduplication
Section titled “Description and deduplication”description is a second line (up to 3 lines); a toast with the same key replaces the one still showing instead of stacking another, which suits repeated request errors; duration changes how long it stays.
import { Button, toast } from 'nacre'
export function ToastKeyed() { return ( <Button variant="outline" onPress={() => toast.show({ kind: 'error', key: 'customer-profile-error', message: 'Failed to load customer profile', description: 'The service is temporarily unavailable. Try again later; if it keeps failing, contact your administrator.', duration: 10000, }) } > Load customer profile </Button> )}Accessibility
Section titled “Accessibility”- Errors and warnings are role=“alert” and announced immediately; success and info toasts are announced politely without interrupting.
- Error, warning and action toasts have a close button; the action is an ordinary button reachable with Tab.
- The timer pauses while the pointer is over a toast and resumes with the remaining time when it leaves (at least 1 more second).
- On touch devices failure banners never dismiss themselves and have a 40pt close button; a notice pill collapses on tap.
Do / Don’t
Section titled “Do / Don’t”Do
- First ask whether the result shows on screen: if it does, don’t toast (a row leaving, a count changing is the feedback)
- Pass essential: true for successes the screen can’t show, such as copying to the clipboard or waiting for the other side to confirm
- Give errors a retry action
- Deduplicate repeated request errors with key
- Write the result (“Transferred to Chen Zhiyuan”), not “Success”
- Mount ToastHost only once, at the app root
Don’t
- Add a “Success” toast for a result already visible
- Put form validation errors only in a toast (show them next to the field)
- Ask the user to make a decision (use a dialog)
- Put must-see information only in a toast (it disappears in seconds)
- Fire several similar toasts at once
ToastHost
Section titled “ToastHost”No props.