A lightweight, elegant, and fully reactive toast notification system designed specifically for Zog.js.
- Zero Dependencies: Works directly with Zog.js core.
- Automatic Styling: Injects its own CSS—no extra files to import.
- Positioning: 6 configurable positions (e.g.,
top-right,bottom-center). - Smart Animations: Smooth entry/exit animations based on screen position.
- Types: Built-in support for
success,error,warning, andinfo. - Global Access: Accessible via
window.$toastor anywhere in your app logic.
npm install zogjs @zogjs/toastimport { use, createApp } from 'zogjs';
import { ZogToast } from '@zogjs/toast';In your main application entry point (e.g., main.js), register the plugin using use(). You can pass configuration options here.
// main.js
import { createApp, use } from 'zogjs';
import { ZogToast } from '@zogjs/toast';
// Install with options
use(ZogToast, {
position: 'top-right', // 'top-right', 'top-left', 'bottom-center', etc.
defaultDuration: 3000 // Time in ms before auto-dismiss
});
createApp(() => {
return {
title: 'My Zog App'
};
}).mount('#app');You can trigger notifications from anywhere in your application logic or directly from your HTML templates.
// Inside a function or setup block
$toast.success('Post saved successfully!');
$toast.error('Connection failed.');
$toast.warning('Battery low.');
$toast.info('New version available.');<button @click="$toast.success('Item added to cart!')">
Add to Cart
</button>
<button @click="$toast.error('Action denied', 5000)">
Delete Item
</button>You can pass an options object when installing the plugin:
| Option | Type | Default | Description |
|---|---|---|---|
position |
String |
'bottom-right' |
Where toasts appear on screen. |
defaultDuration |
Number |
3000 |
Duration (ms) before auto-dismiss. Set to 0 to disable. |
top-righttop-lefttop-centerbottom-rightbottom-leftbottom-center
The global $toast object provides the following methods:
Displays a green success notification with a checkmark icon.
Displays a red error notification.
Displays a yellow warning notification.
Displays a blue informational notification.
Generic method to add a toast manually.
- type:
'success' | 'error' | 'warning' | 'info'
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.