Skip to content

Toast

A Service for displaying toast notifications with multiple severity levels and customizable timing. Perfect for user feedback, status updates, and non-intrusive messaging in web applications.

Features

  • Multiple Notification Types: Error, Warning, Success, and Info toasts
  • Customizable Duration: Set custom display time for each toast
  • Interactive Controls: Pause on hover, resume on leave, click to dismiss
  • Auto-dismiss: Automatic closure with visual progress bar
  • Consistent Positioning: Top-end positioning for non-intrusive display

Service Reference

Toast Methods

The utility provides four main methods for different notification types:

typescript
toast.error(msg: string, delay?: number): void
toast.warn(msg: string, delay?: number): void
toast.success(msg: string, delay?: number): void
toast.info(msg: string, delay?: number): void

Parameters

ParameterTypeDefaultDescription
msgstring-The message to display in the toast
delaynumber3000Duration in milliseconds before auto-dismiss

Usage Examples

Basic Toast Notifications

typescript
import { Toast } from 'dolphin-components';

// Success notification
Toast.success('Data saved successfully!');

// Error notification
Toast.error('Failed to save data. Please try again.');

// Warning notification
Toast.warn('Your session will expire in 5 minutes.');

// Info notification
Toast.info('New update available. Click here to refresh.');

Custom Duration

typescript
// Quick notification (1 second)
toast.success('Copied to clipboard!', 1000);

// Long notification (10 seconds)
toast.error('Critical error occurred. Please contact support.', 10000);

// Permanent notification (very long duration)
toast.info('Please complete your profile setup.', 30000);

Common Use Cases

  • Form Validation: Show validation errors and success messages
  • API Responses: Display server response feedback
  • File Operations: Upload/download progress and results
  • User Authentication: Login/logout status messages
  • Real-time Updates: WebSocket notifications and alerts
  • Background Operations: Long-running task completion
  • System Status: Connection status and system alerts