@abisheks238/react-toaster v1.1.0
@abisheks238/react-toaster
An advanced, customizable toast notification system for React applications with smart queue management, swipe gestures, and theming support.
๐ Features
- ๐ Multiple toast types: success, error, info, warning, loading, custom
- ๐จ Theming support: Light, dark, and auto themes
- ๐ฑ Swipe gestures: Dismiss toasts with swipe actions
- ๐ Smart queue management: Priority-based toast handling
- ๐ Flexible positioning: 7 different positions available
- โฑ๏ธ Auto-dismiss: Customizable duration with pause on hover
- ๐ฏ Action buttons: Add custom actions to toasts
- ๐ Sound & Vibration: Optional audio and haptic feedback
- ๐งฉ Fully typed: Complete TypeScript support
- ๐ญ Animations: Smooth enter/exit animations
- ๐ฆ Lightweight: Minimal bundle size
๐ฆ Installation
# npm
npm install @abisheks238/react-toaster
# yarn
yarn add @abisheks238/react-toaster
# pnpm
pnpm add @abisheks238/react-toaster
โ
Just Published! Latest version available on npm: v1.0.2
๐ Links
๐ Quick Start
1. Wrap your application with ToasterProvider
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { ToasterProvider } from '@abisheks238/react-toaster';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<ToasterProvider theme="auto" position="top-right">
<App />
</ToasterProvider>
</React.StrictMode>
);
2. Use the toaster in your components
import React from 'react';
import { useToaster } from '@abisheks238/react-toaster';
function MyComponent() {
const { success, error, info, warning, loading } = useToaster();
return (
<div>
<button onClick={() => success('Operation successful!')}>
Show Success Toast
</button>
<button onClick={() => error('Something went wrong.')}>
Show Error Toast
</button>
<button onClick={() => info('Here is some information.')}>
Show Info Toast
</button>
<button onClick={() => warning('Proceed with caution!')}>
Show Warning Toast
</button>
<button onClick={() => loading('Processing...')}>
Show Loading Toast
</button>
{/* Advanced usage with actions */}
<button
onClick={() =>
error('Failed to save changes', {
position: 'bottom-center',
duration: 10000,
actions: [
{
label: 'Retry',
onClick: (id) => console.log('Retry clicked', id),
style: 'primary'
},
{
label: 'Cancel',
onClick: (id) => console.log('Cancel clicked', id),
style: 'secondary'
}
],
onRetry: () => console.log('Retry action triggered'),
sound: true,
vibrate: true
})
}
>
Advanced Toast
</button>
</div>
);
}
๐ API Reference
ToasterProvider Props
interface ToasterProviderProps {
children: ReactNode;
theme?: 'light' | 'dark' | 'auto'; // Default: 'auto'
queue?: {
maxToasts?: number; // Default: 5
strategy?: 'fifo' | 'lifo' | 'priority'; // Default: 'fifo'
grouping?: boolean; // Default: false
maxPerGroup?: number; // Default: 3
};
defaultConfig?: Partial<ToastConfig>;
containerClassName?: string;
newestOnTop?: boolean; // Default: true
richColors?: boolean; // Default: true
closeButton?: boolean; // Default: true
}
useToaster Hook
const {
success,
error,
info,
warning,
loading,
custom,
update,
dismiss,
dismissAll,
dismissGroup,
pause,
resume,
retry,
undo,
setTheme,
setQueue
} = useToaster();
Toast Configuration Options
interface ToastConfig {
position?: 'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center' | 'center';
duration?: number; // milliseconds (default: 5000, use Infinity for persistent)
priority?: 'low' | 'normal' | 'high' | 'urgent';
dismissible?: boolean; // Default: true
pauseOnHover?: boolean; // Default: true
pauseOnFocusLoss?: boolean; // Default: true
swipe?: {
enabled: boolean; // Default: true
threshold: number; // Default: 100
velocity: number; // Default: 0.3
};
icon?: ReactNode | boolean; // Default: true
sound?: boolean; // Default: false
vibrate?: boolean; // Default: false
actions?: ToastAction[];
onClose?: () => void;
onUndo?: () => void;
onRetry?: () => void;
className?: string;
style?: CSSProperties;
groupId?: string;
stackable?: boolean;
}
๐จ Theming
The toaster automatically adapts to your system's color scheme when using theme="auto"
. You can also force light or dark themes:
<ToasterProvider theme="dark">
<App />
</ToasterProvider>
// Or change theme dynamically
const { setTheme } = useToaster();
setTheme('light');
๐ญ Advanced Features
Queue Management
const { setQueue } = useToaster();
// Configure queue behavior
setQueue({
maxToasts: 3,
strategy: 'priority', // Show high priority toasts first
grouping: true, // Group similar toasts
maxPerGroup: 2
});
Custom Actions
success('File uploaded successfully!', {
actions: [
{
label: 'View File',
onClick: (id) => openFile(),
style: 'primary'
},
{
label: 'Share',
onClick: (id) => shareFile(),
style: 'secondary'
}
],
onUndo: () => deleteFile() // Undo action
});
Swipe Gestures
info('Swipe me away!', {
swipe: {
enabled: true,
threshold: 150, // Pixels to trigger dismiss
velocity: 0.5 // Minimum swipe velocity
}
});
๐ง Troubleshooting
Package not showing in GitHub?
If your npm package isn't appearing in the GitHub "Packages" section:
- Wait for sync: GitHub can take up to 24 hours to detect new packages
- Verify repository URL: Check that your package.json has the correct repository URL
- Manual linking: Go to your repository Settings โ Packages โ Connect repository
Verification Commands
# Check package info
npm info @abisheks238/react-toaster
# Verify installation
npm install @abisheks238/react-toaster --dry-run
# Check repository link
npm view @abisheks238/react-toaster repository
Common Issues
- Import errors: Make sure you're importing from the correct path
- TypeScript issues: Ensure you have React types installed
- Styling not working: Import the CSS or configure Tailwind properly
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ What's New
v1.0.2 (Latest)
- โ Published to npm registry
- ๐ Linked to GitHub repository
- ๐ Enhanced documentation
- ๐ Fixed repository metadata
v1.0.1
- ๐จ Advanced theming support
- ๐ฑ Swipe gesture implementation
- ๐ Smart queue management
- ๐ฏ Action buttons support
๐ Stats
- ๐ฆ Bundle Size: < 50KB minified + gzipped
- ๐ฏ TypeScript: 100% coverage
- ๐งช React Support: 16.8+ (Hooks required)
- ๐ Browser Support: Modern browsers (ES2015+)
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with โค๏ธ by Abishek
- Inspired by modern toast notification patterns
- Powered by React and TypeScript
Made with โค๏ธ for the React community
๐ GitHub Package Detection
Note: If you don't see this package in the GitHub "Packages" section yet, don't worry! GitHub typically takes 12-24 hours to sync with npm. The package is live and ready to use.
Quick verification: Visit npm package page to confirm it's published successfully.