Lab // Index
Total: 07Component // Notification
05 of 07Toast Notification
Toast notification system with multiple toasts, stacking animations, and hover effects using Motion for React
Demo // Live
InteractiveInstall // Steps
Total: 02Step 01
Install dependencies
npm install motion lucide-reactStep 02
Copy and paste the following code into your project.
// Step 1: Add ToastProvider to your root layout (recommended for global usage)
// src/app/layout.tsx or src/components/toast-provider.tsx
'use client'
import { useToast } from '@/hooks/use-toast-notification'
import { ToastContainer } from '@/components/craft/toast-container'
export function ToastProvider() {
const { toasts, removeToast } = useToast()
return <ToastContainer toasts={toasts} onClose={removeToast} />
}
// Then in your layout.tsx:
import { ToastProvider } from '@/components/toast-provider'
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<ToastProvider />
</body>
</html>
)
}
// Step 2: Use the toast hook in any component
'use client'
import { useToast } from '@/hooks/use-toast-notification'
export default function MyComponent() {
const { success, warning, danger, info } = useToast()
return (
<div>
<button onClick={() => success('Success!', 'Your action was completed')}>
Show Success Toast
</button>
<button onClick={() => warning('Warning!', 'Please review your settings')}>
Show Warning Toast
</button>
<button onClick={() => danger('Error!', 'Something went wrong')}>
Show Error Toast
</button>
<button onClick={() => info('Info', 'Here is some information')}>
Show Info Toast
</button>
</div>
)
}Spec // Features
Total: 08- 01
Multiple toasts support
- 02
Stacking animations
- 03
Hover to expand
- 04
Auto-dismiss (configurable)
- 05
4 variants (success, warning, danger, info)
- 06
4 width options (sm, md, lg, full)
- 07
Mobile responsive
- 08
TypeScript support
Spec // Props
Total: 04| Component | Prop | Type | Default |
|---|---|---|---|
| Toast | variant | success | warning | danger | info | info |
| Toast | width | sm | md | lg | full | md |
| Toast | duration | number | 5000 |
| ToastContainer | maxVisible | number | 3 |