Skip to main content

Toast

A notification message that appears temporarily to provide feedback about an action.

Interactive Demo

Click the buttons to trigger toast notifications.

Variants

With Description

Progress bar

Set showProgress to render a thin bar that drains over the toast's duration — gives the user a visual hint of how long the toast will remain.

Mobile considerations

  • Toast surface uses .tui-glass (Tier 3) — translucent + backdrop-blur on capable browsers, opaque fallback elsewhere.
  • On prefers-reduced-motion: reduce, slide-in animation is replaced with instant fade.
  • Toast container should be wrapped in <SafeAreaView edges={['top']}> so notifications clear iOS notch / status bar.

Usage

import { Toast } from 'trust-ui';

function Example() {
const [toasts, setToasts] = useState([]);

const addToast = () => {
const id = Date.now().toString();
setToasts((prev) => [...prev, { id, variant: 'success', message: 'Saved!' }]);
};

const removeToast = (id) => {
setToasts((prev) => prev.filter((t) => t.id !== id));
};

return (
<>
<Button onClick={addToast}>Show Toast</Button>
{toasts.map((toast) => (
<Toast key={toast.id} {...toast} onClose={() => removeToast(toast.id)} />
))}
</>
);
}

Props

PropTypeDefaultDescription
idstring-Unique identifier for the toast
variant'success' | 'danger' | 'warning' | 'info'-Visual variant
messagestring-Main message text
descriptionstring-Optional description below the message
durationnumber4000Auto-dismiss duration in milliseconds
showProgressbooleanfalseShow a thin bar that drains over duration
onClose() => void-Callback when toast is closed
classNamestring-Additional CSS class name
styleCSSProperties-Additional inline styles