@pijushgupta/toastbite 1.0.6
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 +21 -0
- package/dist/toastbite.cjs.js +1 -0
- package/dist/toastbite.css +1 -0
- package/dist/toastbite.es.js +102 -0
- package/dist/toastbite.umd.js +1 -0
- package/package.json +50 -0
- package/src/components/Toast.vue +35 -0
- package/src/components/ToastTemplate.vue +8 -0
- package/src/components/Toastify.vue +30 -0
- package/src/components/useToast.js +34 -0
- package/src/index.js +12 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Pijush Gupta
|
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.
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),p=(o,e)=>{const n=o.__vccOpts||o;for(const[c,s]of e)n[c]=s;return n},v={};function _(o,e){return t.openBlock(),t.createElementBlock("div",null,e[0]||(e[0]=[t.createStaticVNode('<div><div class="toast-top-left top-left"></div></div><div><div class="toast-top-center top-center"></div></div><div><div class="toast-top-right top-right"></div></div><div><div class="toast-bottom-left bottom-left"></div></div><div><div class="toast-bottom-center bottom-center"></div></div><div><div class="toast-bottom-right bottom-right"></div></div>',6)]))}const f=p(v,[["render",_]]),r=t.reactive([]);function h({location:o,title:e,content:n,icon:c,iconColor:s,timeout:i=2e3}){var l;r.push({id:Date.now(),iconColor:s||"toast-blue dark:toast-blue",location:["top-left","top-right","top-center","bottom-left","bottom-right","bottom-center"].includes(o)?`.${o}`:".bottom-right",title:e,content:n,icon:c,timeout:i}),((l=r[0])==null?void 0:l.timeout)!==!1&&setTimeout(()=>{var a;d((a=r[0])==null?void 0:a.id)},r[0].timeout)}function d(o){const e=r.findIndex(n=>n.id===o);e!==-1&&r.splice(e,1)}function u(){return{toasts:r,addToast:h,removeToast:d}}const b={id:"toast-default",class:"toast-card",role:"alert"},g=["innerHTML"],k={class:"toast-title"},E={class:"toast-content"},N=["onClick"],T={__name:"Toastify",setup(o){const{removeToast:e,toasts:n}=u();return(c,s)=>(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n),i=>(t.openBlock(),t.createBlock(t.Teleport,{key:i.id,to:i.location},[t.createElementVNode("div",b,[t.createElementVNode("div",{class:t.normalizeClass([i.iconColor,"toast-icon-wrap"]),innerHTML:i.icon},null,10,g),t.createElementVNode("div",null,[t.createElementVNode("div",k,t.toDisplayString(i.title),1),t.createElementVNode("div",E,t.toDisplayString(i.content),1)]),t.createElementVNode("button",{type:"button",class:"toast-close",onClick:l=>t.unref(e)(i.id),"aria-label":"Close"},s[0]||(s[0]=[t.createElementVNode("span",{class:"sr-only"},"Close",-1),t.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"icon icon-tabler icons-tabler-outline icon-tabler-x"},[t.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),t.createElementVNode("path",{d:"M18 6l-12 12"}),t.createElementVNode("path",{d:"M6 6l12 12"})],-1)]),8,N)])],8,["to"]))),128))}},V={__name:"ToastTemplate",setup(o){return(e,n)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.createVNode(f),t.createVNode(T)],64))}},m=document.createElement("div");document.body.appendChild(m);app=t.createApp(V);app.mount(m);exports.useToast=u;
|
@@ -0,0 +1 @@
|
|
1
|
+
.toast-top-left{pointer-events:none;position:fixed;z-index:40;box-sizing:border-box;display:flex;min-height:100vh;width:600px;flex-direction:column;padding:.25rem}.toast-top-center{pointer-events:none;position:fixed;z-index:40;box-sizing:border-box;display:flex;min-height:100vh;width:600px;flex-direction:column;align-items:center;padding:.25rem}.toast-top-right{pointer-events:none;position:fixed;z-index:40;box-sizing:border-box;display:flex;min-height:100vh;width:600px;flex-direction:column;align-items:flex-end;padding:.25rem}.toast-bottom-left{pointer-events:none;position:fixed;z-index:40;box-sizing:border-box;display:flex;min-height:100vh;width:600px;flex-direction:column;padding:.25rem}.toast-bottom-center{pointer-events:none;position:fixed;z-index:40;box-sizing:border-box;display:flex;min-height:100vh;width:600px;flex-direction:column;align-items:center;padding:.25rem}.toast-bottom-right{pointer-events:none;position:fixed;z-index:40;box-sizing:border-box;display:flex;min-height:100vh;width:600px;flex-direction:column;align-items:flex-end;padding:.25rem}@media (min-width: 768px){.toast-top-left{left:1rem;top:1rem}.toast-top-center{left:50%;top:1rem;margin-left:-300px}.toast-top-right{right:1rem;top:1rem}.toast-bottom-left{left:1rem;bottom:1rem;flex-direction:column-reverse}.toast-bottom-center{left:50%;bottom:1rem;margin-left:-300px;flex-direction:column-reverse}.toast-bottom-right{right:1rem;bottom:1rem;flex-direction:column-reverse}}.toast-blue{background-color:#e1effe;color:#3f83f8}.dark .dark\:toast-blue{background-color:#1e429f;color:#c3ddfd}.toast-red{background-color:#fde8e8;color:#f05252}.dark .dark\:toast-red{background-color:#9b1c1c;color:#fbd5d5}.toast-orange{background-color:#feecdc;color:#ff5a1f}.dark .dark\:toast-orange{background-color:#8a2c0d;color:#fcd9bd}.toast-amber{background-color:#fef3c7;color:#f59e0b}.dark .dark\:toast-amber{background-color:#92400e;color:#fde68a}.toast-yellow{background-color:#fdf6b2;color:#c27803}.dark .dark\:toast-yellow{background-color:#723b13;color:#fce96a}.toast-lime{background-color:#ecfccb;color:#84cc16}.dark .dark\:toast-lime{background-color:#3f6212;color:#d9f99d}.toast-green{background-color:#def7ec;color:#0e9f6e}.dark .dark\:toast-green{background-color:#03543f;color:#bcf0da}.toast-emerald{background-color:#d1fae5;color:#10b981}.dark .dark\:toast-emerald{background-color:#065f46;color:#a7f3d0}.toast-teal{background-color:#d5f5f6;color:#0694a2}.dark .dark\:toast-teal{background-color:#05505c;color:#afecef}.toast-cyan{background-color:#cffafe;color:#06b6d4}.dark .dark\:toast-cyan{background-color:#155e75;color:#a5f3fc}.toast-sky{background-color:#e0f2fe;color:#0ea5e9}.dark .dark\:toast-sky{background-color:#075985;color:#bae6fd}.toast-indigo{background-color:#e5edff;color:#6875f5}.dark .dark\:toast-indigo{background-color:#42389d;color:#cddbfe}.toast-violet{background-color:#ede9fe;color:#8b5cf6}.dark .dark\:toast-violet{background-color:#5b21b6;color:#ddd6fe}.toast-purple{background-color:#edebfe;color:#9061f9}.dark .dark\:toast-purple{background-color:#5521b5;color:#dcd7fe}.toast-fuchsia{background-color:#fae8ff;color:#d946ef}.dark .dark\:toast-fuchsia{background-color:#86198f;color:#f5d0fe}.toast-pink{background-color:#fce8f3;color:#e74694}.dark .dark\:toast-pink{background-color:#99154b;color:#fad1e8}.toast-rose{background-color:#ffe4e6;color:#f43f5e}.dark .dark\:toast-rose{background-color:#9f1239;color:#fecdd3}.toast-slate{background-color:#f1f5f9;color:#64748b}.dark .dark\:toast-slate{background-color:#1e293b;color:#e2e8f0}.toast-gray{background-color:#f3f4f6;color:#6b7280}.dark .dark\:toast-gray{background-color:#1f2937;color:#e5e7eb}.toast-zinc{background-color:#f4f4f5;color:#71717a}.dark .dark\:toast-zinc{background-color:#27272a;color:#e4e4e7}.toast-neutral{background-color:#f5f5f5;color:#737373}.dark .dark\:toast-neutral{background-color:#262626;color:#e5e5e5}.toast-stone{background-color:#f5f5f4;color:#78716c}.dark .dark\:toast-stone{background-color:#292524;color:#e7e5e4}.toast-card{pointer-events:auto;z-index:50;margin-top:.25rem;margin-bottom:.25rem;display:flex;width:100%;max-width:20rem;align-items:center;border-radius:.5rem;background-color:#fff;padding:1rem;color:#6b7280;box-shadow:0 1px 3px #0000001a,0 1px 2px -1px #0000001a}.dark .toast-card{background-color:#1f2937;color:#9ca3af}.toast-icon-wrap{display:inline-flex;height:2rem;width:2rem;flex-shrink:0;align-items:center;justify-content:center;border-radius:.5rem}.toast-title{margin-inline-start:.75rem;font-size:.875rem;line-height:1.25rem;font-weight:600}.toast-content{margin-inline-start:.75rem;font-size:.875rem;line-height:1.25rem;font-weight:400}.toast-close{margin:-.375rem;margin-inline-start:auto;display:inline-flex;height:2rem;width:2rem;align-items:center;justify-content:center;border-radius:.5rem;padding:.375rem;color:#9ca3af}.toast-close:hover{background-color:#f3f4f6;color:#111827}.toast-close:hover:is(.dark *){background-color:#374151;color:#fff}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import { createElementBlock as d, openBlock as l, createStaticVNode as b, reactive as g, Fragment as _, renderList as k, unref as p, createBlock as T, Teleport as x, createElementVNode as o, normalizeClass as w, toDisplayString as u, createVNode as m, createApp as C } from "vue";
|
2
|
+
const y = (e, t) => {
|
3
|
+
const n = e.__vccOpts || e;
|
4
|
+
for (const [c, s] of t)
|
5
|
+
n[c] = s;
|
6
|
+
return n;
|
7
|
+
}, M = {};
|
8
|
+
function B(e, t) {
|
9
|
+
return l(), d("div", null, t[0] || (t[0] = [
|
10
|
+
b('<div><div class="toast-top-left top-left"></div></div><div><div class="toast-top-center top-center"></div></div><div><div class="toast-top-right top-right"></div></div><div><div class="toast-bottom-left bottom-left"></div></div><div><div class="toast-bottom-center bottom-center"></div></div><div><div class="toast-bottom-right bottom-right"></div></div>', 6)
|
11
|
+
]));
|
12
|
+
}
|
13
|
+
const $ = /* @__PURE__ */ y(M, [["render", B]]), r = g([]);
|
14
|
+
function E({ location: e, title: t, content: n, icon: c, iconColor: s, timeout: i = 2e3 }) {
|
15
|
+
var a;
|
16
|
+
r.push({
|
17
|
+
id: Date.now(),
|
18
|
+
iconColor: s || "toast-blue dark:toast-blue",
|
19
|
+
location: ["top-left", "top-right", "top-center", "bottom-left", "bottom-right", "bottom-center"].includes(e) ? `.${e}` : ".bottom-right",
|
20
|
+
title: t,
|
21
|
+
content: n,
|
22
|
+
icon: c,
|
23
|
+
timeout: i
|
24
|
+
}), ((a = r[0]) == null ? void 0 : a.timeout) !== !1 && setTimeout(() => {
|
25
|
+
var v;
|
26
|
+
f((v = r[0]) == null ? void 0 : v.id);
|
27
|
+
}, r[0].timeout);
|
28
|
+
}
|
29
|
+
function f(e) {
|
30
|
+
const t = r.findIndex((n) => n.id === e);
|
31
|
+
t !== -1 && r.splice(t, 1);
|
32
|
+
}
|
33
|
+
function H() {
|
34
|
+
return { toasts: r, addToast: E, removeToast: f };
|
35
|
+
}
|
36
|
+
const L = {
|
37
|
+
id: "toast-default",
|
38
|
+
class: "toast-card",
|
39
|
+
role: "alert"
|
40
|
+
}, N = ["innerHTML"], V = { class: "toast-title" }, z = { class: "toast-content" }, D = ["onClick"], S = {
|
41
|
+
__name: "Toastify",
|
42
|
+
setup(e) {
|
43
|
+
const { removeToast: t, toasts: n } = H();
|
44
|
+
return (c, s) => (l(!0), d(_, null, k(p(n), (i) => (l(), T(x, {
|
45
|
+
key: i.id,
|
46
|
+
to: i.location
|
47
|
+
}, [
|
48
|
+
o("div", L, [
|
49
|
+
o("div", {
|
50
|
+
class: w([i.iconColor, "toast-icon-wrap"]),
|
51
|
+
innerHTML: i.icon
|
52
|
+
}, null, 10, N),
|
53
|
+
o("div", null, [
|
54
|
+
o("div", V, u(i.title), 1),
|
55
|
+
o("div", z, u(i.content), 1)
|
56
|
+
]),
|
57
|
+
o("button", {
|
58
|
+
type: "button",
|
59
|
+
class: "toast-close",
|
60
|
+
onClick: (a) => p(t)(i.id),
|
61
|
+
"aria-label": "Close"
|
62
|
+
}, s[0] || (s[0] = [
|
63
|
+
o("span", { class: "sr-only" }, "Close", -1),
|
64
|
+
o("svg", {
|
65
|
+
xmlns: "http://www.w3.org/2000/svg",
|
66
|
+
width: "24",
|
67
|
+
height: "24",
|
68
|
+
viewBox: "0 0 24 24",
|
69
|
+
fill: "none",
|
70
|
+
stroke: "currentColor",
|
71
|
+
"stroke-width": "2",
|
72
|
+
"stroke-linecap": "round",
|
73
|
+
"stroke-linejoin": "round",
|
74
|
+
class: "icon icon-tabler icons-tabler-outline icon-tabler-x"
|
75
|
+
}, [
|
76
|
+
o("path", {
|
77
|
+
stroke: "none",
|
78
|
+
d: "M0 0h24v24H0z",
|
79
|
+
fill: "none"
|
80
|
+
}),
|
81
|
+
o("path", { d: "M18 6l-12 12" }),
|
82
|
+
o("path", { d: "M6 6l12 12" })
|
83
|
+
], -1)
|
84
|
+
]), 8, D)
|
85
|
+
])
|
86
|
+
], 8, ["to"]))), 128));
|
87
|
+
}
|
88
|
+
}, j = {
|
89
|
+
__name: "ToastTemplate",
|
90
|
+
setup(e) {
|
91
|
+
return (t, n) => (l(), d(_, null, [
|
92
|
+
m($),
|
93
|
+
m(S)
|
94
|
+
], 64));
|
95
|
+
}
|
96
|
+
}, h = document.createElement("div");
|
97
|
+
document.body.appendChild(h);
|
98
|
+
app = C(j);
|
99
|
+
app.mount(h);
|
100
|
+
export {
|
101
|
+
H as useToast
|
102
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(s,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(s=typeof globalThis<"u"?globalThis:s||self,t(s.Toastbite={},s.Vue))})(this,function(s,t){"use strict";const _=(o,e)=>{const n=o.__vccOpts||o;for(const[l,c]of e)n[l]=c;return n},h={};function b(o,e){return t.openBlock(),t.createElementBlock("div",null,e[0]||(e[0]=[t.createStaticVNode('<div><div class="toast-top-left top-left"></div></div><div><div class="toast-top-center top-center"></div></div><div><div class="toast-top-right top-right"></div></div><div><div class="toast-bottom-left bottom-left"></div></div><div><div class="toast-bottom-center bottom-center"></div></div><div><div class="toast-bottom-right bottom-right"></div></div>',6)]))}const u=_(h,[["render",b]]),r=t.reactive([]);function k({location:o,title:e,content:n,icon:l,iconColor:c,timeout:i=2e3}){var d;r.push({id:Date.now(),iconColor:c||"toast-blue dark:toast-blue",location:["top-left","top-right","top-center","bottom-left","bottom-right","bottom-center"].includes(o)?`.${o}`:".bottom-right",title:e,content:n,icon:l,timeout:i}),((d=r[0])==null?void 0:d.timeout)!==!1&&setTimeout(()=>{var f;a((f=r[0])==null?void 0:f.id)},r[0].timeout)}function a(o){const e=r.findIndex(n=>n.id===o);e!==-1&&r.splice(e,1)}function p(){return{toasts:r,addToast:k,removeToast:a}}const g={id:"toast-default",class:"toast-card",role:"alert"},T=["innerHTML"],E={class:"toast-title"},V={class:"toast-content"},N=["onClick"],v={__name:"Toastify",setup(o){const{removeToast:e,toasts:n}=p();return(l,c)=>(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(n),i=>(t.openBlock(),t.createBlock(t.Teleport,{key:i.id,to:i.location},[t.createElementVNode("div",g,[t.createElementVNode("div",{class:t.normalizeClass([i.iconColor,"toast-icon-wrap"]),innerHTML:i.icon},null,10,T),t.createElementVNode("div",null,[t.createElementVNode("div",E,t.toDisplayString(i.title),1),t.createElementVNode("div",V,t.toDisplayString(i.content),1)]),t.createElementVNode("button",{type:"button",class:"toast-close",onClick:d=>t.unref(e)(i.id),"aria-label":"Close"},c[0]||(c[0]=[t.createElementVNode("span",{class:"sr-only"},"Close",-1),t.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"icon icon-tabler icons-tabler-outline icon-tabler-x"},[t.createElementVNode("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),t.createElementVNode("path",{d:"M18 6l-12 12"}),t.createElementVNode("path",{d:"M6 6l12 12"})],-1)]),8,N)])],8,["to"]))),128))}},y={__name:"ToastTemplate",setup(o){return(e,n)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.createVNode(u),t.createVNode(v)],64))}},m=document.createElement("div");document.body.appendChild(m),app=t.createApp(y),app.mount(m),s.useToast=p,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pijushgupta/toastbite",
|
3
|
+
"version": "1.0.6",
|
4
|
+
"description": "A simple Vue toast notification library",
|
5
|
+
"main": "dist/toastbite.cjs.js",
|
6
|
+
"module": "dist/toastbite.es.js",
|
7
|
+
"browser": "dist/toastbite.umd.js",
|
8
|
+
"scripts": {
|
9
|
+
"build": "vite build",
|
10
|
+
"dev": "vite"
|
11
|
+
},
|
12
|
+
"exports": {
|
13
|
+
".":{
|
14
|
+
"import": "./dist/toastbite.es.js",
|
15
|
+
"require": "./dist/toastbite.cjs.js",
|
16
|
+
"default": "./dist/toastbite.umd.js"
|
17
|
+
},
|
18
|
+
"./dist/toastbite.css":"./dist/toastbite.css"
|
19
|
+
|
20
|
+
},
|
21
|
+
"files": [
|
22
|
+
"dist",
|
23
|
+
"src",
|
24
|
+
"index.js"
|
25
|
+
],
|
26
|
+
"repository": {
|
27
|
+
"type": "git",
|
28
|
+
"url": "git+https://github.com/Pijushgupta/toastbite.git"
|
29
|
+
},
|
30
|
+
"keywords": [
|
31
|
+
"vue",
|
32
|
+
"toast",
|
33
|
+
"notification",
|
34
|
+
"vue3"
|
35
|
+
],
|
36
|
+
"author": "Pijush Gupta",
|
37
|
+
"license": "MIT",
|
38
|
+
"peerDependencies": {
|
39
|
+
"vue": "^3.0.0"
|
40
|
+
},
|
41
|
+
"bugs": {
|
42
|
+
"url": "https://github.com/Pijushgupta/toastbite/issues"
|
43
|
+
},
|
44
|
+
"homepage": "https://github.com/Pijushgupta/toastbite#readme",
|
45
|
+
"devDependencies": {
|
46
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
47
|
+
"vite": "^6.1.0",
|
48
|
+
"vue": "^3.5.13"
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<!-- Toast.vue -->
|
2
|
+
<!-- Toast wrapper to host Toastify html -->
|
3
|
+
<template>
|
4
|
+
|
5
|
+
<div>
|
6
|
+
<div>
|
7
|
+
<!-- top-left -->
|
8
|
+
<div class="toast-top-left top-left"></div>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div>
|
12
|
+
<!-- top-center -->
|
13
|
+
<div class="toast-top-center top-center"></div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div>
|
17
|
+
<!-- top-right -->
|
18
|
+
<div class="toast-top-right top-right"></div>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div>
|
22
|
+
<!-- bottom-left -->
|
23
|
+
<div class="toast-bottom-left bottom-left"></div>
|
24
|
+
</div>
|
25
|
+
<div>
|
26
|
+
<!-- bottom-center -->
|
27
|
+
<div class="toast-bottom-center bottom-center"></div>
|
28
|
+
</div>
|
29
|
+
<div>
|
30
|
+
<!-- bottom-right -->
|
31
|
+
<div class="toast-bottom-right bottom-right"></div>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</template>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<!-- Toastify.vue -->
|
2
|
+
<!-- actual toast html -->
|
3
|
+
<script setup>
|
4
|
+
import { useToast } from "./useToast";
|
5
|
+
|
6
|
+
const {removeToast,toasts} = useToast();
|
7
|
+
|
8
|
+
</script>
|
9
|
+
|
10
|
+
<template>
|
11
|
+
|
12
|
+
<Teleport v-for="toast in toasts" :key="toast.id" :to="toast.location">
|
13
|
+
<div id="toast-default" class="toast-card" role="alert">
|
14
|
+
<!-- icon area -->
|
15
|
+
<div :class="toast.iconColor" class="toast-icon-wrap" v-html=" toast.icon"></div>
|
16
|
+
<!-- icon area ends -->
|
17
|
+
<div>
|
18
|
+
<div class="toast-title"> {{ toast.title }}</div>
|
19
|
+
<div class="toast-content">{{ toast.content }}</div>
|
20
|
+
</div>
|
21
|
+
<button type="button"
|
22
|
+
class="toast-close"
|
23
|
+
@click="removeToast(toast.id)" aria-label="Close">
|
24
|
+
<span class="sr-only">Close</span>
|
25
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 6l-12 12" /><path d="M6 6l12 12" /></svg>
|
26
|
+
</button>
|
27
|
+
</div>
|
28
|
+
</Teleport>
|
29
|
+
|
30
|
+
</template>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
//useToast.js
|
2
|
+
// composable : Its to create and maintain a global toast store and manage that.
|
3
|
+
import { reactive } from "vue";
|
4
|
+
|
5
|
+
const toasts = reactive([]);
|
6
|
+
|
7
|
+
function addToast({ location, title, content, icon,iconColor,timeout = 2000}) {
|
8
|
+
toasts.push({
|
9
|
+
id: Date.now(),
|
10
|
+
iconColor:iconColor?iconColor:'toast-blue dark:toast-blue',
|
11
|
+
location: ['top-left', 'top-right', 'top-center', 'bottom-left', 'bottom-right', 'bottom-center'].includes(location) ? `.${location}` : '.bottom-right',
|
12
|
+
title,
|
13
|
+
content,
|
14
|
+
icon,
|
15
|
+
timeout
|
16
|
+
});
|
17
|
+
|
18
|
+
// Auto-remove after 5s
|
19
|
+
if(toasts[0]?.timeout !== false ){
|
20
|
+
setTimeout(() => {
|
21
|
+
removeToast(toasts[0]?.id);
|
22
|
+
},toasts[0].timeout);
|
23
|
+
}
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
function removeToast(id) {
|
28
|
+
const index = toasts.findIndex((t) => t.id === id);
|
29
|
+
if (index !== -1) toasts.splice(index, 1);
|
30
|
+
}
|
31
|
+
|
32
|
+
export function useToast() {
|
33
|
+
return { toasts, addToast, removeToast };
|
34
|
+
}
|
package/src/index.js
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
import '../styles/Toastbite.css'
|
2
|
+
import ToastTemplate from "./components/ToastTemplate.vue";
|
3
|
+
import { useToast } from "./components/useToast.js";
|
4
|
+
import { createApp } from 'vue';
|
5
|
+
|
6
|
+
const div = document.createElement("div");
|
7
|
+
document.body.appendChild(div);
|
8
|
+
app = createApp(ToastTemplate);
|
9
|
+
app.mount(div);
|
10
|
+
|
11
|
+
export {useToast}
|
12
|
+
|