Toast Component
A modern, accessible toast notification system using the native Popover API. Supports multiple types, positions, and programmatic usage.Features
- ✅ Native Popover API: Uses browser-native popover for better performance
- ✅ Multiple Types: Success, Danger, Warning, Info
- ✅ Flexible Positioning: Top/Bottom × Center/Right
- ✅ Auto-dismiss: Configurable duration or manual dismiss
- ✅ Programmatic API: Easy-to-use toast manager
- ✅ Beautiful Design: Glassmorphism with smooth animations
- ✅ Dark Mode: Full dark mode support
- ✅ Type-Safe: Full TypeScript support
Installation
The component is available in@monorepo/solid-pkg-ui:
Setup
Add theToastContainer to your app root or layout:
Usage
Programmatic API (Recommended)
The easiest way to show toasts is using thetoast manager:
Component Usage
You can also use theToast component directly:
API Reference
toast Manager
Methods
| Method | Signature | Description |
|---|---|---|
success | (message: string, options?) => string | Show success toast |
danger | (message: string, options?) => string | Show error toast |
warning | (message: string, options?) => string | Show warning toast |
info | (message: string, options?) => string | Show info toast |
show | (toast: ToastProps) => string | Show custom toast |
remove | (id: string) => void | Remove toast by ID |
Options
Toast Component Props
Types
Best Practices
-
Use Appropriate Types:
success: Confirmations, successful operationsdanger: Errors, failures, critical issueswarning: Warnings, confirmations neededinfo: General information, tips
-
Set Reasonable Durations:
- Success: 3000ms (3 seconds)
- Error: 5000ms (5 seconds)
- Warning: 0 (manual dismiss) or 7000ms
- Info: 4000ms
-
Keep Messages Concise:
- Title: 1-3 words
- Message: 1-2 sentences max
-
Choose the Right Position:
top-right: Default, non-intrusivetop-center: Important notificationsbottom-right: Background processesbottom-center: Form validations
Accessibility
- ✅ Keyboard accessible (close with Escape)
- ✅ Screen reader friendly
- ✅ High contrast colors
- ✅ Clear visual indicators
- ✅ Proper ARIA labels