@erag/vue-toastification 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +175 -171
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,171 +1,175 @@
|
|
|
1
|
-
# @erag/vue-toastification
|
|
2
|
-
|
|
3
|
-
A lightweight, high-performance, and customizable Toast Notification library for **Vue 3**. Built with **TypeScript** and the Composition API.
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
import
|
|
41
|
-
import '
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
app.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- `
|
|
101
|
-
- `
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
|
143
|
-
|
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
1
|
+
# @erag/vue-toastification
|
|
2
|
+
|
|
3
|
+
A lightweight, high-performance, and customizable Toast Notification library for **Vue 3**. Built with **TypeScript** and the Composition API.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## 🚀 Features
|
|
14
|
+
|
|
15
|
+
- **Vue 3 Composition API** support.
|
|
16
|
+
- **Fully Typed** with TypeScript.
|
|
17
|
+
- **Lightweight** & Zero dependencies.
|
|
18
|
+
- **Scoped CSS**: Uses `erag-` prefix to prevent CSS conflicts with frameworks like Bootstrap or Tailwind.
|
|
19
|
+
- **Customizable**: Control position, duration, and content easily.
|
|
20
|
+
- **4 Built-in Types**: Success, Error, Warning, and Info.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📦 Installation
|
|
25
|
+
|
|
26
|
+
Install the package via npm:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @erag/vue-toastification
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ⚙️ Setup
|
|
36
|
+
|
|
37
|
+
Register the plugin in your main Vue application file (usually `main.ts` or `main.js`). **Don't forget to import the CSS file.**
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { createApp } from 'vue';
|
|
41
|
+
import App from './App.vue';
|
|
42
|
+
|
|
43
|
+
// 1. Import the plugin and styles
|
|
44
|
+
import ToastPlugin from '@erag/vue-toastification';
|
|
45
|
+
import '@erag/vue-toastification/dist/style.css';
|
|
46
|
+
|
|
47
|
+
const app = createApp(App);
|
|
48
|
+
|
|
49
|
+
// 2. Use the plugin (Optional: Set default position)
|
|
50
|
+
app.use(ToastPlugin, {
|
|
51
|
+
position: 'bottom-right' // Default: bottom-right
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
app.mount('#app');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 💡 Usage
|
|
60
|
+
|
|
61
|
+
You can use the `useToast` composable anywhere in your components to trigger notifications.
|
|
62
|
+
|
|
63
|
+
### 1. Basic Usage (All Types)
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<script setup lang="ts">
|
|
67
|
+
import { useToast } from '@erag/vue-toastification';
|
|
68
|
+
|
|
69
|
+
// Destructure the methods you need
|
|
70
|
+
const { success, error, warning, info } = useToast();
|
|
71
|
+
|
|
72
|
+
const showNotifications = () => {
|
|
73
|
+
// success(message, title, duration?)
|
|
74
|
+
success('Data saved successfully!', 'Good Job');
|
|
75
|
+
|
|
76
|
+
// error(message, title, duration?)
|
|
77
|
+
error('Something went wrong.', 'Error Occurred');
|
|
78
|
+
|
|
79
|
+
// warning(message, title, duration?)
|
|
80
|
+
warning('Your session is about to expire.', 'Warning');
|
|
81
|
+
|
|
82
|
+
// info(message, title, duration?)
|
|
83
|
+
info('New update available.', 'Info');
|
|
84
|
+
};
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<button @click="showNotifications">Show Toasts</button>
|
|
89
|
+
</template>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### 2. Changing Position Dynamically
|
|
95
|
+
|
|
96
|
+
You can change the position of the toasts at runtime using `setPosition`.
|
|
97
|
+
|
|
98
|
+
**Available Positions:**
|
|
99
|
+
|
|
100
|
+
- `top-left`
|
|
101
|
+
- `top-center`
|
|
102
|
+
- `top-right`
|
|
103
|
+
- `bottom-left`
|
|
104
|
+
- `bottom-center`
|
|
105
|
+
- `bottom-right`
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const { setPosition, info } = useToast();
|
|
109
|
+
|
|
110
|
+
const moveToTop = () => {
|
|
111
|
+
setPosition('top-center');
|
|
112
|
+
info('I am now at the Top Center!', 'Position Changed');
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### 3. Custom Duration
|
|
119
|
+
|
|
120
|
+
By default, toasts disappear after **4500ms (4.5 seconds)**. You can override this for specific notifications.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const { success, error } = useToast();
|
|
124
|
+
|
|
125
|
+
// Disappears quickly (1 second)
|
|
126
|
+
const quickToast = () => {
|
|
127
|
+
success('Quick save!', 'Done', 1000);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Stays longer (8 seconds)
|
|
131
|
+
const longToast = () => {
|
|
132
|
+
error('Please read this error carefully...', 'Important', 8000);
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 🎨 API Reference
|
|
139
|
+
|
|
140
|
+
### `useToast()` Methods
|
|
141
|
+
|
|
142
|
+
| Method | Arguments | Description |
|
|
143
|
+
| ------------- | -------------------------------------------------- | ---------------------------------------- |
|
|
144
|
+
| `success` | `(msg: string, title?: string, duration?: number)` | Triggers a green success toast. |
|
|
145
|
+
| `error` | `(msg: string, title?: string, duration?: number)` | Triggers a red error toast. |
|
|
146
|
+
| `warning` | `(msg: string, title?: string, duration?: number)` | Triggers an orange warning toast. |
|
|
147
|
+
| `info` | `(msg: string, title?: string, duration?: number)` | Triggers a blue info toast. |
|
|
148
|
+
| `setPosition` | `(position: ToastPosition)` | Updates the global container position. |
|
|
149
|
+
| `remove` | `(id: number)` | Manually removes a specific toast by ID. |
|
|
150
|
+
|
|
151
|
+
### Global Options
|
|
152
|
+
|
|
153
|
+
When registering the plugin:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
app.use(ToastPlugin, {
|
|
157
|
+
position: 'top-right' // Sets the initial position
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 🛡️ CSS & Styling
|
|
164
|
+
|
|
165
|
+
This library uses the **`erag-`** prefix for all CSS classes to ensure it never breaks your existing UI (Tailwind, Bootstrap, etc.).
|
|
166
|
+
|
|
167
|
+
- Container: `.erag-toast-container`
|
|
168
|
+
- Toast Card: `.erag-toast`
|
|
169
|
+
- Themes: `.erag-success`, `.erag-error`, etc.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## 📄 License
|
|
174
|
+
|
|
175
|
+
MIT License © Er Amit Gupta
|