@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
154 lines (153 loc) • 5.36 kB
JavaScript
import { defineComponent as P, ref as u, onMounted as _, onUnmounted as M } from "vue";
import { NeonEventBus as n } from "../../../utils/common/event/NeonEventBus.es.js";
import { NeonAlertLevel as t } from "../../../model/feedback/alert/NeonAlertLevel.es.js";
import { NeonAlertService as a } from "../../../utils/feedback/alert/NeonAlertService.es.js";
import U from "./container/NeonAlertContainer.vue.es.js";
import V from "./container/NeonToastContainer.vue.es.js";
import { NeonToastService as i } from "../../../utils/feedback/toast/NeonToastService.es.js";
import { NeonAlertPlacement as s } from "../../../model/feedback/alert/NeonAlertPlacement.es.js";
import { NeonVerticalPosition as l } from "../../../model/common/position/NeonVerticalPosition.es.js";
import j from "./container/NeonDialogContainer.vue.es.js";
import { NeonDialogService as C } from "../../../utils/feedback/dialog/NeonDialogService.es.js";
const ee = P({
name: "NeonAlert",
components: {
NeonAlertContainer: U,
NeonToastContainer: V,
NeonDialogContainer: j
},
props: {
/**
* Whether alert messages are dismissible by clicking on them. This can also be set per alert message.
*/
dismissible: { type: Boolean, default: !0 },
/**
* Duration to display messages before removing them. This can also be set per alert message. Set the duration to 0 to
* disable the duration timer, NOTE: this requires the user to dismiss the alert by clicking on it.
*/
duration: { type: Number, default: 2500 }
},
setup(K) {
const v = u([]), m = u([]), d = u([]), p = u([]), E = u([]), g = u([]), T = u({
question: "",
title: "",
open: !1
}), f = u(1), q = (e) => {
switch (e.placement || s.TopRight) {
case s.TopLeft:
v.value = v.value.filter((o) => o.id !== e.id);
break;
case s.TopRight:
m.value = m.value.filter((o) => o.id !== e.id);
break;
case s.BottomLeft:
d.value = d.value.filter((o) => o.id !== e.id);
break;
case s.BottomRight:
p.value = p.value.filter((o) => o.id !== e.id);
break;
}
}, b = (e, o) => {
const c = f.value;
f.value = f.value + 1;
const r = {
dismissible: K.dismissible,
...o,
level: e,
id: c
};
switch (o.placement || s.TopRight) {
case s.TopLeft:
v.value.unshift(r);
break;
case s.TopRight:
m.value.unshift(r);
break;
case s.BottomLeft:
d.value.push(r);
break;
case s.BottomRight:
p.value.push(r);
break;
}
const y = o.duration === void 0 ? K.duration : o.duration;
y > 0 && !o.primaryAction && setTimeout(() => q(r), y);
}, D = (e) => {
switch (e.placement || l.Top) {
case l.Top:
E.value = E.value.filter((o) => o.id !== e.id);
break;
case l.Bottom:
g.value = g.value.filter((o) => o.id !== e.id);
break;
}
}, h = (e, o) => {
const c = f.value;
f.value = f.value + 1;
const r = {
dismissible: K.dismissible,
...o,
level: e,
id: c
};
switch (o.placement || l.Top) {
case l.Top:
E.value.unshift(r);
break;
case l.Bottom:
g.value.push(r);
break;
}
const y = o.duration === void 0 ? K.duration : o.duration;
y > 0 && setTimeout(() => D(r), y);
}, k = (e) => {
b(t.Info, e);
}, A = (e) => {
b(t.Success, e);
}, I = (e) => {
b(t.Warn, e);
}, N = (e) => {
b(t.Error, e);
}, S = (e) => {
h(t.Info, e);
}, R = (e) => {
h(t.Success, e);
}, B = (e) => {
h(t.Warn, e);
}, W = (e) => {
h(t.Error, e);
}, L = (e) => {
[E.value, g.value].forEach((o) => {
const c = o.findIndex((r) => r.key === e);
c >= 0 && o.splice(c, 1);
});
}, w = (e) => {
[m.value, p.value, v.value, d.value].forEach((o) => {
const c = o.findIndex((r) => r.key === e);
c >= 0 && o.splice(c, 1);
});
}, x = (e) => {
T.value = {
...e,
open: !0
};
};
return _(() => {
n.on(a.generateEventKey(t.Info), k), n.on(a.generateEventKey(t.Success), A), n.on(a.generateEventKey(t.Warn), I), n.on(a.generateEventKey(t.Error), N), n.on(a.removeEventKey, w), n.on(i.generateEventKey(t.Info), S), n.on(i.generateEventKey(t.Success), R), n.on(i.generateEventKey(t.Warn), B), n.on(i.generateEventKey(t.Error), W), n.on(i.removeEventKey, L), n.on(C.generateEventKey(), x);
}), M(() => {
n.off(a.generateEventKey(t.Info), k), n.off(a.generateEventKey(t.Success), A), n.off(a.generateEventKey(t.Warn), I), n.off(a.generateEventKey(t.Error), N), n.off(a.removeEventKey, w), n.off(i.generateEventKey(t.Info), S), n.off(i.generateEventKey(t.Success), R), n.off(i.generateEventKey(t.Warn), B), n.off(i.generateEventKey(t.Error), W), n.off(i.removeEventKey, L), n.off(C.generateEventKey(), x);
}), {
topLeft: v,
topRight: m,
bottomLeft: d,
bottomRight: p,
top: E,
bottom: g,
dialog: T
};
}
});
export {
ee as default
};
//# sourceMappingURL=NeonAlert.es.js.map