Toast
Ephemeral notification toasts with auto-dismiss, variants, and optional actions.
Installation
npx @obi/ui add toastPreview
bottom right · stacks upward
Usage
import { ToastProvider, useToast } from '@/src/components/Toast/Toast';
// 1. Wrap your app (or layout) with ToastProvider
export default function Layout({ children }) {
return (
<ToastProvider position="bottom-right">
{children}
</ToastProvider>
);
}
// 2. Call useToast() anywhere inside the tree
function MyComponent() {
const { toast } = useToast();
return (
<button
onClick={() => toast({
title: 'Saved',
description: 'Your changes were saved.',
variant: 'success',
duration: 4000,
})}
>
Save
</button>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
| position | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'bottom-right' | Where toasts appear on screen. |
| title | string | undefined | Bold heading text. |
| description | string | undefined | Body message. |
| variant | 'default' | 'success' | 'warning' | 'danger' | 'default' | Color and icon style. |
| duration | number | 4000 | Auto-dismiss delay in ms. |
| action | { label: string; onClick: () => void } | undefined | Optional action button. |