vue-toasts-lite 0.0.1 → 0.1.0
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/LICENSE +22 -0
- package/README.md +147 -35
- package/dist/index.d.ts +124 -0
- package/dist/index.js +246 -0
- package/dist/style.css +1 -0
- package/package.json +39 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 scheron
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,45 +1,157 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vue Toasts Lite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight toast notifications library for Vue 3.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- 🚀 Lightweight and easy to use
|
|
8
|
+
- 🎨 Multiple toast types (success, error, loading, warn)
|
|
9
|
+
- 📍 Multiple positions (can show in different corners simultaneously)
|
|
10
|
+
- ⚡️ Customizable duration, auto-close, and styling
|
|
11
|
+
- 🎯 TypeScript support
|
|
12
|
+
- 🎯 Promise support
|
|
13
|
+
- 🖱️ Pause on hover
|
|
8
14
|
|
|
9
|
-
##
|
|
15
|
+
## Installation
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install vue-toasts-lite
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
**Three steps to start using toasts:**
|
|
24
|
+
|
|
25
|
+
1. Install the package
|
|
26
|
+
2. Add `ToastsLiteProvider` to your app
|
|
27
|
+
3. Call `toasts.success()` from anywhere
|
|
15
28
|
|
|
16
|
-
|
|
29
|
+
### 1. Add the provider to your `App.vue`:
|
|
17
30
|
|
|
18
|
-
|
|
31
|
+
```vue
|
|
32
|
+
<script setup>
|
|
33
|
+
import { ToastsLiteProvider } from 'vue-toasts-lite'
|
|
34
|
+
import 'vue-toasts-lite/style.css'
|
|
35
|
+
</script>
|
|
19
36
|
|
|
20
|
-
|
|
37
|
+
<template>
|
|
38
|
+
<div>
|
|
39
|
+
<RouterView />
|
|
40
|
+
<ToastsLiteProvider />
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
```
|
|
21
44
|
|
|
22
|
-
|
|
45
|
+
### 2. Use anywhere in your app:
|
|
23
46
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
```vue
|
|
48
|
+
<script setup>
|
|
49
|
+
import { toasts } from 'vue-toasts-lite'
|
|
50
|
+
|
|
51
|
+
toasts.success('Hello!')
|
|
52
|
+
toasts.error('Something went wrong')
|
|
53
|
+
toasts.loading('Loading...')
|
|
54
|
+
toasts.warn('Warning message')
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
// Basic methods
|
|
62
|
+
toasts.success(message, options?)
|
|
63
|
+
toasts.error(message, options?)
|
|
64
|
+
toasts.loading(message, options?)
|
|
65
|
+
toasts.warn(message, options?)
|
|
66
|
+
|
|
67
|
+
// Advanced methods
|
|
68
|
+
toasts.add(options) // Create custom toast
|
|
69
|
+
toasts.update(id, options) // Update existing toast
|
|
70
|
+
toasts.remove(id?) // Remove toast(s)
|
|
71
|
+
toasts.clear() // Clear all toasts
|
|
72
|
+
toasts.promise(promise, options) // Handle promise states
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Options
|
|
76
|
+
|
|
77
|
+
| Option | Type | Default | Description |
|
|
78
|
+
|--------|------|---------|-------------|
|
|
79
|
+
| `message` | `string` | - | Message to display |
|
|
80
|
+
| `type` | `'success' \| 'error' \| 'loading' \| 'warn'` | `'success'` | Toast type |
|
|
81
|
+
| `duration` | `number` | `3000` | Duration in milliseconds |
|
|
82
|
+
| `autoClose` | `boolean` | `true` | Auto-close behavior |
|
|
83
|
+
| `position` | `ToastPosition` | `'top-center'` | Toast position |
|
|
84
|
+
| `id` | `string` | auto | Custom ID |
|
|
85
|
+
|
|
86
|
+
### Available Positions
|
|
87
|
+
|
|
88
|
+
`top-left`, `top-center`, `top-right`, `bottom-left`, `bottom-center`, `bottom-right`, `middle-center`
|
|
89
|
+
|
|
90
|
+
## Examples
|
|
91
|
+
|
|
92
|
+
### Basic Usage
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
// With options
|
|
96
|
+
toasts.success('Success!', { duration: 5000, position: 'bottom-right' })
|
|
97
|
+
|
|
98
|
+
// Multiple positions at once
|
|
99
|
+
toasts.success('Top', { position: 'top-center' })
|
|
100
|
+
toasts.error('Bottom', { position: 'bottom-right' })
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Update Toasts
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
const id = toasts.loading('Uploading...')
|
|
107
|
+
// Later
|
|
108
|
+
toasts.update(id, { type: 'success', message: 'Done!' })
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Promise Support
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
await toasts.promise(
|
|
115
|
+
fetchData(),
|
|
116
|
+
{
|
|
117
|
+
loading: 'Loading...',
|
|
118
|
+
success: 'Loaded!',
|
|
119
|
+
error: 'Failed!'
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Custom Controller
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
import { ToastsController } from 'vue-toasts-lite'
|
|
128
|
+
|
|
129
|
+
const notifications = new ToastsController()
|
|
130
|
+
notifications.success('Hello!')
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Styling
|
|
134
|
+
|
|
135
|
+
Customize colors and appearance with CSS variables:
|
|
136
|
+
|
|
137
|
+
### CSS Variables
|
|
138
|
+
|
|
139
|
+
```css
|
|
140
|
+
:root {
|
|
141
|
+
--tl-font-family: system-ui, -apple-system, sans-serif;
|
|
142
|
+
--tl-bg: hsl(0, 0%, 100%);
|
|
143
|
+
--tl-text: hsl(0, 0%, 20%);
|
|
144
|
+
--tl-border: hsl(0, 0%, 85%);
|
|
145
|
+
--tl-shadow: hsla(0, 0%, 0%, 0.1);
|
|
146
|
+
--tl-success: hsl(145, 63%, 42%);
|
|
147
|
+
--tl-error: hsl(0, 79%, 63%);
|
|
148
|
+
--tl-warn: hsl(45, 100%, 51%);
|
|
149
|
+
--tl-icon-color: hsl(0, 0%, 100%);
|
|
150
|
+
--tl-loading-border: hsl(0, 0%, 15%);
|
|
151
|
+
--tl-loading-bg: hsl(0, 0%, 98%);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ComponentOptionsMixin } from 'vue';
|
|
2
|
+
import { ComponentProvideOptions } from 'vue';
|
|
3
|
+
import { DefineComponent } from 'vue';
|
|
4
|
+
import { PublicProps } from 'vue';
|
|
5
|
+
|
|
6
|
+
export declare type Id = string;
|
|
7
|
+
|
|
8
|
+
export declare interface Toast {
|
|
9
|
+
add: (options: ToastOptions) => Id;
|
|
10
|
+
update: (id: Id, options: ToastOptions) => Id;
|
|
11
|
+
success: (message: string, options?: ToastSimpleOptions) => Id;
|
|
12
|
+
loading: (message: string, options?: ToastSimpleOptions) => Id;
|
|
13
|
+
error: (message: string, options?: ToastSimpleOptions) => Id;
|
|
14
|
+
warn: (message: string, options?: ToastSimpleOptions) => Id;
|
|
15
|
+
promise: <T>(promise: Promise<T>, options: ToastPromiseOptions) => Promise<Id>;
|
|
16
|
+
remove: (id?: Id) => void;
|
|
17
|
+
clear: () => void;
|
|
18
|
+
onToastsListChange: (callback: (toasts: ToastProps[]) => void) => () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export declare type ToastOptions = Partial<ToastProps>;
|
|
22
|
+
|
|
23
|
+
export declare type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "middle-center";
|
|
24
|
+
|
|
25
|
+
export declare type ToastPromiseOptions = {
|
|
26
|
+
loading: string;
|
|
27
|
+
success: string;
|
|
28
|
+
error: string;
|
|
29
|
+
position?: ToastPosition;
|
|
30
|
+
id?: Id;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export declare type ToastProps = {
|
|
34
|
+
/** toast id */
|
|
35
|
+
id: Id;
|
|
36
|
+
/** toast type */
|
|
37
|
+
type: ToastType;
|
|
38
|
+
/** toast message */
|
|
39
|
+
message: string;
|
|
40
|
+
/** auto close the toast */
|
|
41
|
+
autoClose: boolean;
|
|
42
|
+
/** duration in milliseconds */
|
|
43
|
+
duration: number;
|
|
44
|
+
/** Position of the toast on the screen. */
|
|
45
|
+
position?: ToastPosition;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export declare const toasts: ToastsController;
|
|
49
|
+
|
|
50
|
+
export declare class ToastsController implements Toast {
|
|
51
|
+
private counter;
|
|
52
|
+
private toasts;
|
|
53
|
+
constructor();
|
|
54
|
+
get toastList(): ToastProps[];
|
|
55
|
+
onToastsListChange(callback: (toasts: ToastProps[]) => void): () => void;
|
|
56
|
+
private ID;
|
|
57
|
+
private addOrUpdate;
|
|
58
|
+
/**
|
|
59
|
+
* Add a toast
|
|
60
|
+
* @param options - The options for the toast
|
|
61
|
+
* @returns The id of the toast
|
|
62
|
+
*/
|
|
63
|
+
add(options: ToastOptions): string;
|
|
64
|
+
/**
|
|
65
|
+
* Update a toast by id
|
|
66
|
+
* @param id - The id of the toast to update
|
|
67
|
+
* @param options - The options for the toast
|
|
68
|
+
* @returns The id of the toast
|
|
69
|
+
*/
|
|
70
|
+
update(id: Id, options: ToastOptions): string;
|
|
71
|
+
/**
|
|
72
|
+
* Remove a toast by id
|
|
73
|
+
* If no id is provided, all current toasts will be removed
|
|
74
|
+
* @param id - The id of the toast to remove
|
|
75
|
+
*/
|
|
76
|
+
remove(id?: Id): void;
|
|
77
|
+
/**
|
|
78
|
+
* Remove all current toasts
|
|
79
|
+
*/
|
|
80
|
+
clear(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Add a success toast
|
|
83
|
+
* @param message - The message to display in the toast
|
|
84
|
+
* @param options - The options for the toast
|
|
85
|
+
* @returns The id of the toast
|
|
86
|
+
*/
|
|
87
|
+
success(message: string, options?: Omit<ToastSimpleOptions, "type">): string;
|
|
88
|
+
/**
|
|
89
|
+
* Add an error toast
|
|
90
|
+
* @param message - The message to display in the toast
|
|
91
|
+
* @param options - The options for the toast
|
|
92
|
+
* @returns The id of the toast
|
|
93
|
+
*/
|
|
94
|
+
error(message: string, options?: Omit<ToastSimpleOptions, "type">): string;
|
|
95
|
+
/**
|
|
96
|
+
* Add a warning toast
|
|
97
|
+
* @param message - The message to display in the toast
|
|
98
|
+
* @param options - The options for the toast
|
|
99
|
+
* @returns The id of the toast
|
|
100
|
+
*/
|
|
101
|
+
warn(message: string, options?: Omit<ToastSimpleOptions, "type">): string;
|
|
102
|
+
/**
|
|
103
|
+
* Add a loading toast
|
|
104
|
+
* @param message - The message to display in the toast
|
|
105
|
+
* @param options - The options for the toast
|
|
106
|
+
* @returns The id of the toast
|
|
107
|
+
*/
|
|
108
|
+
loading(message: string, options?: Omit<ToastSimpleOptions, "type">): string;
|
|
109
|
+
/**
|
|
110
|
+
* Add a promise toast
|
|
111
|
+
* @param promise - The promise to display in the toast
|
|
112
|
+
* @param options - The options for the toast
|
|
113
|
+
* @returns The id of the toast
|
|
114
|
+
*/
|
|
115
|
+
promise<T>(promise: Promise<T>, options: ToastPromiseOptions): Promise<string>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export declare type ToastSimpleOptions = Partial<Omit<ToastProps, "message">>;
|
|
119
|
+
|
|
120
|
+
export declare const ToastsLiteProvider: DefineComponent<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
121
|
+
|
|
122
|
+
export declare type ToastType = "success" | "loading" | "error" | "warn";
|
|
123
|
+
|
|
124
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var O = (a, t, e) => t in a ? M(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
+
var v = (a, t, e) => O(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { defineComponent as C, ref as h, watchEffect as E, createElementBlock as f, openBlock as c, withModifiers as $, normalizeStyle as U, createCommentVNode as k, createElementVNode as _, normalizeClass as L, toDisplayString as D, computed as g, onBeforeUpdate as x, createBlock as b, Teleport as B, Fragment as T, renderList as w, createVNode as A, TransitionGroup as I, withCtx as N, unref as P } from "vue";
|
|
5
|
+
const S = {
|
|
6
|
+
key: 0,
|
|
7
|
+
class: "toasts-lite__icon"
|
|
8
|
+
}, V = { class: "toasts-lite__content" }, z = { class: "toasts-lite__content-message" }, F = /* @__PURE__ */ C({
|
|
9
|
+
__name: "ToastsLiteItem",
|
|
10
|
+
props: {
|
|
11
|
+
id: {},
|
|
12
|
+
type: {},
|
|
13
|
+
message: {},
|
|
14
|
+
autoClose: { type: Boolean },
|
|
15
|
+
duration: {},
|
|
16
|
+
position: {}
|
|
17
|
+
},
|
|
18
|
+
emits: ["close"],
|
|
19
|
+
setup(a, { expose: t, emit: e }) {
|
|
20
|
+
const o = a, n = e, l = h(null), p = h(0), d = h(0);
|
|
21
|
+
function s() {
|
|
22
|
+
l.value && clearTimeout(l.value), n("close");
|
|
23
|
+
}
|
|
24
|
+
function r() {
|
|
25
|
+
l.value && (clearTimeout(l.value), l.value = null, d.value = o.duration - (Date.now() - p.value));
|
|
26
|
+
}
|
|
27
|
+
function i() {
|
|
28
|
+
!l.value && d.value > 0 && (l.value = setTimeout(s, d.value));
|
|
29
|
+
}
|
|
30
|
+
return E(() => {
|
|
31
|
+
o.autoClose && (p.value = Date.now(), d.value = o.duration, l.value = setTimeout(s, o.duration));
|
|
32
|
+
}), t({
|
|
33
|
+
pause: r,
|
|
34
|
+
resume: i
|
|
35
|
+
}), (u, m) => (c(), f("div", {
|
|
36
|
+
class: "toasts-lite__toast",
|
|
37
|
+
style: U(`--toast-duration: ${a.duration}s;`),
|
|
38
|
+
onClick: $(s, ["prevent"])
|
|
39
|
+
}, [
|
|
40
|
+
["success", "error", "loading", "warn"].includes(a.type) ? (c(), f("div", S, [
|
|
41
|
+
_("div", {
|
|
42
|
+
class: L(`toasts-lite__${a.type}`)
|
|
43
|
+
}, null, 2)
|
|
44
|
+
])) : k("", !0),
|
|
45
|
+
_("div", V, [
|
|
46
|
+
_("div", z, D(a.message), 1)
|
|
47
|
+
])
|
|
48
|
+
], 4));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
class R extends Map {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
v(this, "subscribers", []);
|
|
55
|
+
}
|
|
56
|
+
set(e, o) {
|
|
57
|
+
return super.set(e, o), this.notify(), this;
|
|
58
|
+
}
|
|
59
|
+
delete(e) {
|
|
60
|
+
const o = super.delete(e);
|
|
61
|
+
return this.notify(), o;
|
|
62
|
+
}
|
|
63
|
+
clear() {
|
|
64
|
+
super.clear(), this.notify();
|
|
65
|
+
}
|
|
66
|
+
subscribe(e) {
|
|
67
|
+
return this.subscribers.push(e), () => {
|
|
68
|
+
this.subscribers = this.subscribers.filter((o) => o !== e);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
notify() {
|
|
72
|
+
this.subscribers.forEach((e) => e(Array.from(this.values())));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const j = {
|
|
76
|
+
type: "success",
|
|
77
|
+
message: "Hello from Toasts Lite",
|
|
78
|
+
autoClose: !0,
|
|
79
|
+
duration: 3e3,
|
|
80
|
+
position: "top-center"
|
|
81
|
+
};
|
|
82
|
+
class G {
|
|
83
|
+
constructor() {
|
|
84
|
+
v(this, "counter", 0);
|
|
85
|
+
v(this, "toasts");
|
|
86
|
+
this.toasts = new R();
|
|
87
|
+
}
|
|
88
|
+
get toastList() {
|
|
89
|
+
return Array.from(this.toasts.values());
|
|
90
|
+
}
|
|
91
|
+
onToastsListChange(t) {
|
|
92
|
+
return this.toasts.subscribe(t);
|
|
93
|
+
}
|
|
94
|
+
ID() {
|
|
95
|
+
return `toast:${Date.now().toString(16)}-${this.counter++}`;
|
|
96
|
+
}
|
|
97
|
+
addOrUpdate(t) {
|
|
98
|
+
let { id: e = this.ID(), ...o } = t;
|
|
99
|
+
if (this.toasts.has(e)) {
|
|
100
|
+
const n = this.toasts.get(e);
|
|
101
|
+
return Object.assign(n, o), this.toasts.set(e, n), e;
|
|
102
|
+
}
|
|
103
|
+
return this.toasts.set(e, { id: e, ...j, ...o }), e;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Add a toast
|
|
107
|
+
* @param options - The options for the toast
|
|
108
|
+
* @returns The id of the toast
|
|
109
|
+
*/
|
|
110
|
+
add(t) {
|
|
111
|
+
return this.addOrUpdate(t);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Update a toast by id
|
|
115
|
+
* @param id - The id of the toast to update
|
|
116
|
+
* @param options - The options for the toast
|
|
117
|
+
* @returns The id of the toast
|
|
118
|
+
*/
|
|
119
|
+
update(t, e) {
|
|
120
|
+
return this.addOrUpdate({ ...e, id: t });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Remove a toast by id
|
|
124
|
+
* If no id is provided, all current toasts will be removed
|
|
125
|
+
* @param id - The id of the toast to remove
|
|
126
|
+
*/
|
|
127
|
+
remove(t) {
|
|
128
|
+
t && !this.toasts.has(t) || (t ? this.toasts.delete(t) : this.clear());
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Remove all current toasts
|
|
132
|
+
*/
|
|
133
|
+
clear() {
|
|
134
|
+
this.toasts.clear();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Add a success toast
|
|
138
|
+
* @param message - The message to display in the toast
|
|
139
|
+
* @param options - The options for the toast
|
|
140
|
+
* @returns The id of the toast
|
|
141
|
+
*/
|
|
142
|
+
success(t, e) {
|
|
143
|
+
return this.addOrUpdate({ ...e, message: t, type: "success" });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Add an error toast
|
|
147
|
+
* @param message - The message to display in the toast
|
|
148
|
+
* @param options - The options for the toast
|
|
149
|
+
* @returns The id of the toast
|
|
150
|
+
*/
|
|
151
|
+
error(t, e) {
|
|
152
|
+
return this.addOrUpdate({ ...e, message: t, type: "error" });
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Add a warning toast
|
|
156
|
+
* @param message - The message to display in the toast
|
|
157
|
+
* @param options - The options for the toast
|
|
158
|
+
* @returns The id of the toast
|
|
159
|
+
*/
|
|
160
|
+
warn(t, e) {
|
|
161
|
+
return this.addOrUpdate({ ...e, message: t, type: "warn" });
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Add a loading toast
|
|
165
|
+
* @param message - The message to display in the toast
|
|
166
|
+
* @param options - The options for the toast
|
|
167
|
+
* @returns The id of the toast
|
|
168
|
+
*/
|
|
169
|
+
loading(t, e) {
|
|
170
|
+
return this.addOrUpdate({ ...e, message: t, type: "loading" });
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Add a promise toast
|
|
174
|
+
* @param promise - The promise to display in the toast
|
|
175
|
+
* @param options - The options for the toast
|
|
176
|
+
* @returns The id of the toast
|
|
177
|
+
*/
|
|
178
|
+
async promise(t, e) {
|
|
179
|
+
const o = this.loading(e.loading, { position: e.position, id: e.id });
|
|
180
|
+
try {
|
|
181
|
+
return await t, this.success(e.success, { position: e.position, id: o }), o;
|
|
182
|
+
} catch {
|
|
183
|
+
throw this.error(e.error, { position: e.position, id: o }), new Error(e.error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const y = new G(), H = ["onMouseenter", "onMouseleave"], K = /* @__PURE__ */ C({
|
|
188
|
+
__name: "ToastsLiteProvider",
|
|
189
|
+
setup(a) {
|
|
190
|
+
const t = h(y.toastList);
|
|
191
|
+
y.onToastsListChange((s) => {
|
|
192
|
+
t.value = s;
|
|
193
|
+
});
|
|
194
|
+
const e = g(() => {
|
|
195
|
+
const s = /* @__PURE__ */ new Map();
|
|
196
|
+
return t.value.forEach((r) => {
|
|
197
|
+
const i = r.position || "top-center";
|
|
198
|
+
s.has(i) || s.set(i, []), s.get(i).push(r);
|
|
199
|
+
}), s;
|
|
200
|
+
}), o = g(() => Array.from(e.value.keys())), n = h({});
|
|
201
|
+
x(() => {
|
|
202
|
+
for (const s of o.value)
|
|
203
|
+
n.value[s] = [];
|
|
204
|
+
});
|
|
205
|
+
function l(s) {
|
|
206
|
+
n.value[s] && n.value[s].forEach((r) => r == null ? void 0 : r.pause());
|
|
207
|
+
}
|
|
208
|
+
function p(s) {
|
|
209
|
+
n.value[s] && n.value[s].forEach((r) => r == null ? void 0 : r.resume());
|
|
210
|
+
}
|
|
211
|
+
function d(s, r) {
|
|
212
|
+
n.value[s] || (n.value[s] = []), r && "pause" in r && "resume" in r && n.value[s].push(r);
|
|
213
|
+
}
|
|
214
|
+
return (s, r) => (c(), b(B, { to: "body" }, [
|
|
215
|
+
(c(!0), f(T, null, w(o.value, (i) => (c(), f("div", {
|
|
216
|
+
key: i,
|
|
217
|
+
class: L(["toasts-lite__toast-container", `toasts-lite__${i}`]),
|
|
218
|
+
onMouseenter: (u) => l(i),
|
|
219
|
+
onMouseleave: (u) => p(i)
|
|
220
|
+
}, [
|
|
221
|
+
A(I, { name: "toasts-lite" }, {
|
|
222
|
+
default: N(() => [
|
|
223
|
+
(c(!0), f(T, null, w(e.value.get(i), (u) => (c(), b(F, {
|
|
224
|
+
id: u.id,
|
|
225
|
+
ref_for: !0,
|
|
226
|
+
ref: (m) => d(i, m),
|
|
227
|
+
key: u.id,
|
|
228
|
+
type: u.type,
|
|
229
|
+
message: u.message,
|
|
230
|
+
"auto-close": u.autoClose,
|
|
231
|
+
duration: u.duration,
|
|
232
|
+
position: u.position,
|
|
233
|
+
onClose: (m) => P(y).remove(u.id)
|
|
234
|
+
}, null, 8, ["id", "type", "message", "auto-close", "duration", "position", "onClose"]))), 128))
|
|
235
|
+
]),
|
|
236
|
+
_: 2
|
|
237
|
+
}, 1024)
|
|
238
|
+
], 42, H))), 128))
|
|
239
|
+
]));
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
export {
|
|
243
|
+
G as ToastsController,
|
|
244
|
+
K as ToastsLiteProvider,
|
|
245
|
+
y as toasts
|
|
246
|
+
};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--toasts-lite-font-family: var(--tl-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif);--toasts-lite-bg: var(--tl-bg, hsl(0, 0%, 100%));--toasts-lite-text: var(--tl-text, hsl(0, 0%, 20%));--toasts-lite-border: var(--tl-border, hsl(0, 0%, 85%));--toasts-lite-shadow: var(--tl-shadow, hsla(0, 0%, 0%, .1));--toasts-lite-success: var(--tl-success, hsl(145, 63%, 42%));--toasts-lite-error: var(--tl-error, hsl(0, 79%, 63%));--toasts-lite-warn: var(--tl-warn, hsl(45, 100%, 51%));--toasts-lite-icon-color: var(--tl-icon-color, hsl(0, 0%, 100%));--toasts-lite-loading-border-main: var(--tl-loading-border, hsl(0, 0%, 15%));--toasts-lite-loading-border-bg: var(--tl-loading-bg, hsl(0, 0%, 98%))}@keyframes scaleAnimation{0%{transform:scale(0);opacity:0}to{transform:scale(1);opacity:1}}@keyframes loadingRotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.toasts-lite-enter-active,.toasts-lite-leave-active{transition:opacity .3s ease,transform .3s ease}.toasts-lite-enter-from,.toasts-lite-leave-to{opacity:0;transform:translateY(-10px)}.toasts-lite__toast-container{position:fixed;z-index:9999;margin:10px;overflow:visible;display:flex;flex-direction:column;align-items:center;padding-top:12px;gap:12px;pointer-events:none}.toasts-lite__toast{font-family:var(--toasts-lite-font-family);display:flex;justify-content:center;align-items:center;background:var(--toasts-lite-bg);color:var(--toasts-lite-text);border:1px solid var(--toasts-lite-border);box-shadow:var(--toasts-lite-shadow) 0 0 10px;min-width:100px;max-width:1200px;padding:10px 20px;border-radius:8px;cursor:pointer;pointer-events:auto;text-overflow:ellipsis}.toasts-lite__icon{margin-right:12px}.toasts-lite__top-left{top:0;left:0}.toasts-lite__top-center{top:0;left:50%;transform:translate(-50%);min-width:80vw}.toasts-lite__top-right{top:0;right:0}.toasts-lite__bottom-left{bottom:0;left:0}.toasts-lite__bottom-center{bottom:0;left:50%;transform:translate(-50%)}.toasts-lite__bottom-right{bottom:0;right:0}.toasts-lite__middle-center{top:50%;left:50%;transform:translate(-50%,-50%)}.toasts-lite__success{width:20px;height:20px;border-radius:10px;background-color:var(--toasts-lite-success);position:relative;opacity:0;animation:scaleAnimation .3s cubic-bezier(.75,.885,.32,1.275) forwards;animation-delay:.1s}.toasts-lite__success:after{content:"";position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:12px;height:12px;mask-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3" stroke="black"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" /></svg>');-webkit-mask-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3" stroke="black"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" /></svg>');background-color:var(--toasts-lite-icon-color);background-size:100%;background-position:center;background-repeat:no-repeat}.toasts-lite__error{width:20px;height:20px;border-radius:10px;background-color:var(--toasts-lite-error);position:relative;opacity:0;animation:scaleAnimation .3s cubic-bezier(.75,.885,.32,1.275) forwards;animation-delay:.1s}.toasts-lite__error:after{content:"";position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:12px;height:12px;mask-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="4" stroke="black"><path stroke-linecap="round" stroke-linejoin="round" d="M6 6l12 12M18 6l-12 12" /></svg>');-webkit-mask-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="4" stroke="black"><path stroke-linecap="round" stroke-linejoin="round" d="M6 6l12 12M18 6l-12 12" /></svg>');background-color:var(--toasts-lite-icon-color);background-size:100%;background-position:center;background-repeat:no-repeat}.toasts-lite__warn{width:20px;height:20px;border-radius:10px;background-color:var(--toasts-lite-warn);position:relative;opacity:0;animation:scaleAnimation .3s cubic-bezier(.75,.885,.32,1.275) forwards;animation-delay:.1s}.toasts-lite__warn:after{content:"";position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:12px;height:12px;mask-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="5" stroke="currentColor" ><path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14" /></svg>');-webkit-mask-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="5" stroke="currentColor" ><path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14" /></svg>');background-color:var(--toasts-lite-icon-color);background-size:100%;background-position:center;background-repeat:no-repeat}.toasts-lite__loading{width:20px;height:20px;box-sizing:border-box;border:2px solid;border-radius:100%;border-color:var(--toasts-lite-loading-border-main);border-right-color:var(--toasts-lite-loading-border-bg);animation:loadingRotate 1s linear infinite}
|
package/package.json
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-toasts-lite",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"author": "scheron",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/scheron/vue-toasts-lite"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"description": "Lightweight toast notifications for Vue 3",
|
|
13
|
+
"keywords": [ "vue", "toast", "notification", "vue3" ],
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./style.css": "./dist/style.css"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"preview": "vite preview"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"vue": "^3.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^25.0.8",
|
|
36
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
|
+
"vite": "^5.0.0",
|
|
39
|
+
"vite-plugin-dts": "^4.5.4",
|
|
40
|
+
"vue": "^3.0.0"
|
|
41
|
+
}
|
|
10
42
|
}
|