or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdloading-components.mdstatus-tracking.mdtoast-notifications.md
tile.json

toast-notifications.mddocs/

Toast Notifications

Toast notification system for displaying success, error, warning, and info messages with auto-dismiss functionality, smooth animations, and comprehensive styling for different message types.

Capabilities

Toast Component

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[];
}

Toast Events

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>;
}

ToastMessage Interface

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;
}

ToastContent Component

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
};

Toast Message Types

Four message types are supported, each with distinct visual styling and icons:

Success Toast

  • Type: "success"
  • Icon: Success/checkmark icon
  • Color: Green theme
  • Usage: Confirmation of successful operations

Error Toast

  • Type: "error"
  • Icon: Error/X icon
  • Color: Red theme
  • Usage: Error notifications and failed operations

Warning Toast

  • Type: "warning"
  • Icon: Warning/exclamation icon
  • Color: Yellow/orange theme
  • Usage: Cautionary messages and non-critical issues

Info Toast

  • Type: "info"
  • Icon: Info/i icon
  • Color: Blue/gray theme
  • Usage: General information and status updates

Auto-Dismiss Behavior

Toast notifications support flexible auto-dismiss functionality:

  • Timed Dismiss: Set duration to number of seconds for automatic dismissal
  • Persistent: Set duration to null for manual-only dismissal
  • Default Duration: 10 seconds when duration is not specified
  • Visual Timer: Animated progress bar shows remaining time

Toast Positioning and Layout

Toasts are positioned with responsive design considerations:

  • Desktop: Fixed positioning in top-right corner with consistent width
  • Mobile: Responsive width adapting to screen size with appropriate margins
  • Stacking: Multiple toasts stack vertically with smooth animations
  • Animation: Fade in/out transitions with flip animations for reordering

Accessibility Features

Toast notifications include comprehensive accessibility support:

  • ARIA Roles: Proper role="alert" for screen reader announcements
  • Keyboard Navigation: Tab-accessible close buttons
  • Screen Reader Support: Appropriate labeling and announcements
  • High Contrast: Support for high contrast and dark themes
  • Focus Management: Proper focus handling for interactive elements

Content Sanitization

Toast message content is automatically sanitized for security:

  • HTML Support: Basic HTML tags are supported in message content
  • XSS Prevention: Malicious scripts and dangerous HTML are removed
  • Link Support: Safe links with proper attributes are preserved
  • Text Formatting: Basic text formatting tags are maintained