https://github.com/huanfe1/sonner-js
An opinionated toast component for Pure JS.
https://github.com/huanfe1/sonner-js
pure-javascript sonner toast
Last synced: about 1 month ago
JSON representation
An opinionated toast component for Pure JS.
- Host: GitHub
- URL: https://github.com/huanfe1/sonner-js
- Owner: huanfe1
- License: mit
- Created: 2025-03-13T04:11:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-29T12:26:27.000Z (3 months ago)
- Last Synced: 2025-12-01T14:00:38.393Z (3 months ago)
- Topics: pure-javascript, sonner, toast
- Language: TypeScript
- Homepage: https://sonner-js.huanfe1.com
- Size: 349 KB
- Stars: 9
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🍞 Sonner for Pure JS
An elegant toast component designed for Pure JavaScript
[](https://www.npmjs.com/package/sonner-js)
[](https://www.npmjs.com/package/sonner-js)
[](https://opensource.org/licenses/MIT)
Built on Sonner, optimized for pure JavaScript environments
---
## ✨ Features
- 🚀 **Zero Dependencies** - Pure JavaScript implementation, no frameworks required
- 📱 **Responsive Design** - Perfect adaptation for mobile and desktop
- 🎨 **Multiple Styles** - Support for success, error, warning, info and more types
- ⚡ **Lightweight** - Small bundle size with excellent performance
- 🔧 **Highly Customizable** - Rich configuration options
- 🌙 **Theme Support** - Built-in light and dark themes
- 📦 **Multi-format Support** - UMD, ESM, CommonJS formats
## 🚀 Quick Start
### Installation
```bash
npm install sonner-js
```
### Basic Usage
```javascript
import toast from 'sonner-js';
// Simple toast
toast('Hello World!');
// Toast with description
toast('Operation successful', {
description: 'Your data has been saved'
});
```
## 📖 Usage Guide
### Different Toast Types
```javascript
// Success toast
toast.success('Operation successful');
// Error toast
toast.error('Operation failed');
// Info toast
toast.info('This is an information');
// Warning toast
toast.warning('Please note');
```
### Toast with Action Buttons
```javascript
toast('Confirm action', {
action: {
label: 'Confirm',
onClick: () => console.log('User clicked confirm')
}
});
// With cancel button
toast('Confirm deletion', {
action: {
label: 'Cancel',
onClick: () => console.log('User cancelled operation'),
cancel: true
}
});
```
### Promise Handling
```javascript
const fetchData = () => fetch('/api/data');
toast.promise(fetchData, {
loading: 'Loading...',
success: 'Data loaded successfully',
error: 'Failed to load data'
});
```
### Update and Dismiss Toasts
```javascript
// Create toast and get ID
const toastId = toast('Processing...');
// Update toast
toast.success('Processing complete', { id: toastId });
// Dismiss specific toast
toast.dismiss(toastId);
// Dismiss all toasts
toast.dismiss();
```
### Permanent Toasts
```javascript
toast('Important notice', {
duration: 0 // Set to 0 for permanent display
});
```
## 🌐 CDN Usage
### UMD Format
```html
sonnerJS('Hello from CDN!');
```
### ESM Format
```html
import toast from 'https://cdn.jsdelivr.net/npm/sonner-js/+esm';
toast('Hello from ESM!');
```
## ⚙️ Configuration Options
```javascript
import toast from 'sonner-js';
// Global configuration
toast.config({
theme: 'dark', // 'light' | 'dark'
position: 'top-right', // Position
duration: 4000, // Duration in milliseconds
closeButton: true, // Show close button
richColors: true, // Rich colors
expand: true, // Expand animation
visibleToasts: 3, // Number of visible toasts
gap: 8, // Toast spacing
offset: 16, // Margin
mobileOffset: 16, // Mobile margin
dir: 'ltr' // Text direction
});
```
## 📄 License
MIT License - see [LICENSE](LICENSE) file for details.