The Toast component provides a notification system that displays temporary messages to users. It's designed for success messages, error notifications, and other temporary feedback with action buttons.
import { Toast } from '@dashflowx/core'export default function ToastExample() {return (<Toast />)}
Preview:
The main toast component with notification functionality.
Action button within the toast.
Close button for the toast.
The underlying toast implementation.
Description text for the toast.
Provider for toast context.
Title text for the toast.
Viewport for rendering toasts.
import { Toast } from '@dashflowx/core'export default function BasicToast() {return (<Toast />)}
Preview:
import { Toast } from '@dashflowx/core'export default function CustomStyledToast() {return (<Toast className="border border-blue-500 rounded-lg p-4" />)}
Preview:
import { useToast } from '@/lib/use-toast'export default function SuccessToast() {const { toast } = useToast();return (<button onClick={() => toast({title: 'Success!',description: 'Your changes have been saved.',})}>Show Success Toast</button>)}
import { useToast } from '@/lib/use-toast'export default function ErrorToast() {const { toast } = useToast();return (<button onClick={() => toast({title: 'Error!',description: 'Something went wrong.',variant: 'destructive',})}>Show Error Toast</button>)}
import { useToast } from '@/lib/use-toast'import { ToastAction } from '@dashflowx/core'export default function ToastWithAction() {const { toast } = useToast();return (<button onClick={() => toast({title: 'File uploaded',description: 'Your file has been uploaded successfully.',action: (<ToastAction altText="View file">View</ToastAction>),})}>Show Toast with Action</button>)}
const successNotification = (<button onClick={() => toast({title: 'Success!',description: 'Data saved successfully!',})}>Save Data</button>);
const errorNotification = (<button onClick={() => toast({title: 'Error!',description: 'Failed to save data!',variant: 'destructive',})}>Save Data</button>);
const actionConfirmation = (<button onClick={() => toast({title: 'Item deleted',description: 'The item has been deleted.',action: (<ToastAction altText="Undo delete">Undo</ToastAction>),})}>Delete Item</button>);
const formValidation = (<button onClick={() => toast({title: 'Validation Error',description: 'Please fill in all required fields!',variant: 'destructive',})}>Submit Form</button>);
Use clear and concise toast messages.
// ✅ Good - Clear messagetoast({title: 'Data saved successfully!',description: 'Your changes have been applied.'})// ❌ Avoid - Unclear messagetoast({title: 'Done',description: 'OK'})
Set appropriate duration for different types of messages.
// ✅ Good - Appropriate durationtoast({title: 'Quick action completed!',duration: 2000})// ❌ Avoid - Too short or too longtoast({title: 'Message',duration: 100})
Maintain consistent styling across toast notifications.
// ✅ Good - Consistent stylingtoast({title: 'Message',className: 'standard-toast-style'})// ❌ Avoid - Inconsistent stylingtoast({title: 'Message',className: 'random-styles'})
Ensure toast notifications are accessible to all users.
// ✅ Good - Accessibletoast({title: 'Message',description: 'Additional context for screen readers'})// ❌ Avoid - Not accessibletoast({title: 'Message'})
Use appropriate actions for different contexts.
// ✅ Good - Appropriate actiontoast({title: 'File uploaded',action: <ToastAction altText="View file">View</ToastAction>})// ❌ Avoid - Inappropriate actiontoast({title: 'Success',action: <ToastAction altText="Random">Random</ToastAction>})
You can customize the toast appearance using CSS classes:
toast({title: 'Message',className: 'border border-gray-300 rounded-lg p-4'})
Use different themes for different contexts:
// Light themetoast({title: 'Message',className: 'bg-white border-gray-200'})// Dark themetoast({title: 'Message',className: 'bg-gray-900 border-gray-700 text-white'})// Brand themetoast({title: 'Message',className: 'bg-blue-50 border-blue-200'})
Use different sizes for different emphasis levels:
// Small toasttoast({title: 'Message',className: 'text-sm'})// Standard toasttoast({title: 'Message',className: 'text-base'})// Large toasttoast({title: 'Message',className: 'text-lg'})
Create dynamic toast content:
const showDynamicToast = (userName) => {toast({title: `Welcome back, ${userName}!`,description: 'You have 3 new messages.'});};
Add custom actions to toast notifications:
toast({title: 'File uploaded successfully!',action: (<ToastAction altText="View file" onClick={() => navigate('/files')}>View</ToastAction>)});
Use different toast variants:
const showToast = (type, message) => {toast({title: message,variant: type // 'default', 'destructive', 'success'});};
- Toaster: For toast container
- Alert: For alert messages
- Notification: For notifications
- Button: For toast triggers
- Icon: For toast icons
For the complete API reference and advanced usage patterns, see the Toast API documentation.
