Toast notification system for displaying success, error, warning, and info messages with auto-dismiss functionality, smooth animations, and comprehensive styling for different message types.
Container component for displaying multiple toast notifications with animated transitions and responsive positioning.
/**
* Toast container component for displaying notification messages
* @param messages - Array of toast messages to display
*/
export interface ToastProps {
messages: ToastMessage[];
}Events dispatched by the Toast system.
/**
* Events dispatched by Toast components
*/
interface ToastEvents {
/** Dispatched when a toast is closed, returns the toast ID */
close: CustomEvent<number>;
}Complete interface defining the structure of toast messages.
/**
* Interface defining toast message structure
* @param type - Message type determining icon and styling
* @param title - Toast title text
* @param message - Toast message content (supports HTML)
* @param id - Unique identifier for the toast
* @param duration - Auto-dismiss duration in seconds (null for no auto-dismiss)
* @param visible - Visibility state of the toast
*/
export interface ToastMessage {
type: "error" | "warning" | "info" | "success";
title: string;
message: string;
id: number;
duration: number | null;
visible: boolean;
}Individual toast message component with auto-dismiss timer and interactive close functionality.
/**
* Individual toast content component
* @param title - Toast title text
* @param message - Toast message content (HTML supported, sanitized)
* @param type - Message type for styling and icon selection
* @param id - Unique toast identifier
* @param duration - Auto-dismiss duration in seconds (default: 10)
* @param visible - Visibility state (default: true)
*/
export interface ToastContentProps {
title?: string;
message?: string;
type: "error" | "warning" | "info" | "success";
id: number;
duration?: number | null;
visible?: boolean;
}Usage Examples:
import { Toast, type ToastMessage } from "@gradio/statustracker";
// Basic toast usage
const messages: ToastMessage[] = [
{
type: "success",
title: "Success",
message: "Operation completed successfully",
id: 1,
duration: 5,
visible: true
},
{
type: "error",
title: "Error",
message: "Failed to process request",
id: 2,
duration: null, // No auto-dismiss
visible: true
}
];
<Toast messages={messages} on:close={handleToastClose} />
// Creating dynamic toast messages
let toastId = 1;
const toasts: ToastMessage[] = [];
function showSuccessToast(title: string, message: string) {
toasts.push({
type: "success",
title,
message,
id: toastId++,
duration: 5,
visible: true
});
toasts = toasts; // Trigger reactivity
}
function showErrorToast(title: string, message: string) {
toasts.push({
type: "error",
title,
message,
id: toastId++,
duration: null, // Persistent until manually closed
visible: true
});
toasts = toasts;
}
// HTML content in messages (sanitized automatically)
const htmlMessage: ToastMessage = {
type: "info",
title: "Information",
message: "Click <a href='#'>here</a> to learn more",
id: 3,
duration: 10,
visible: true
};Four message types are supported, each with distinct visual styling and icons:
"success""error""warning""info"Toast notifications support flexible auto-dismiss functionality:
duration to number of seconds for automatic dismissalduration to null for manual-only dismissalToasts are positioned with responsive design considerations:
Toast notifications include comprehensive accessibility support:
role="alert" for screen reader announcementsToast message content is automatically sanitized for security: