@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
3 lines (2 loc) • 3.95 kB
JavaScript
;const r=require("vue"),o=require("../../../common/utils/NeonEventBus.cjs.js"),n=require("../../../common/enums/NeonAlertLevel.cjs.js"),i=require("../../../common/utils/NeonAlertService.cjs.js"),R=require("./container/NeonAlertContainer.vue.cjs.js"),W=require("./container/NeonToastContainer.vue.cjs.js"),a=require("../../../common/utils/NeonToastService.cjs.js"),l=require("../../../common/enums/NeonAlertPlacement.cjs.js"),v=require("../../../common/enums/NeonVerticalPosition.cjs.js"),V=r.defineComponent({name:"NeonAlert",components:{NeonAlertContainer:R,NeonToastContainer:W},props:{dismissible:{type:Boolean,default:!0},duration:{type:Number,default:2500}},setup(N){const A=r.ref([]),f=r.ref([]),E=r.ref([]),d=r.ref([]),m=r.ref([]),L=r.ref([]),c=r.ref(1),q=e=>{switch(e.placement||l.NeonAlertPlacement.TopRight){case l.NeonAlertPlacement.TopLeft:A.value=A.value.filter(t=>t.id!==e.id);break;case l.NeonAlertPlacement.TopRight:f.value=f.value.filter(t=>t.id!==e.id);break;case l.NeonAlertPlacement.BottomLeft:E.value=E.value.filter(t=>t.id!==e.id);break;case l.NeonAlertPlacement.BottomRight:d.value=d.value.filter(t=>t.id!==e.id);break}},T=(e,t)=>{const B=c.value;c.value=c.value+1;const s={dismissible:N.dismissible,...t,level:e,id:B};switch(t.placement||l.NeonAlertPlacement.TopRight){case l.NeonAlertPlacement.TopLeft:A.value.unshift(s);break;case l.NeonAlertPlacement.TopRight:f.value.unshift(s);break;case l.NeonAlertPlacement.BottomLeft:E.value.push(s);break;case l.NeonAlertPlacement.BottomRight:d.value.push(s);break}const u=t.duration===void 0?N.duration:t.duration;u>0&&!t.primaryAction&&setTimeout(()=>q(s),u)},I=e=>{switch(e.placement||v.NeonVerticalPosition.Top){case v.NeonVerticalPosition.Top:m.value=m.value.filter(t=>t.id!==e.id);break;case v.NeonVerticalPosition.Bottom:L.value=L.value.filter(t=>t.id!==e.id);break}},S=(e,t)=>{const B=c.value;c.value=c.value+1;const s={dismissible:N.dismissible,...t,level:e,id:B};switch(t.placement||v.NeonVerticalPosition.Top){case v.NeonVerticalPosition.Top:m.value.unshift(s);break;case v.NeonVerticalPosition.Bottom:L.value.push(s);break}const u=t.duration===void 0?N.duration:t.duration;u>0&&setTimeout(()=>I(s),u)},p=e=>{T(n.NeonAlertLevel.Info,e)},b=e=>{T(n.NeonAlertLevel.Success,e)},g=e=>{T(n.NeonAlertLevel.Warn,e)},y=e=>{T(n.NeonAlertLevel.Error,e)},h=e=>{S(n.NeonAlertLevel.Info,e)},P=e=>{S(n.NeonAlertLevel.Success,e)},K=e=>{S(n.NeonAlertLevel.Warn,e)},k=e=>{S(n.NeonAlertLevel.Error,e)};return r.onMounted(()=>{o.NeonEventBus.on(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Info),p),o.NeonEventBus.on(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Success),b),o.NeonEventBus.on(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Warn),g),o.NeonEventBus.on(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Error),y),o.NeonEventBus.on(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Info),h),o.NeonEventBus.on(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Success),P),o.NeonEventBus.on(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Warn),K),o.NeonEventBus.on(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Error),k)}),r.onUnmounted(()=>{o.NeonEventBus.off(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Info),p),o.NeonEventBus.off(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Success),b),o.NeonEventBus.off(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Warn),g),o.NeonEventBus.off(i.NeonAlertService.generateEventKey(n.NeonAlertLevel.Error),y),o.NeonEventBus.off(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Info),h),o.NeonEventBus.off(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Success),P),o.NeonEventBus.off(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Warn),K),o.NeonEventBus.off(a.NeonToastService.generateEventKey(n.NeonAlertLevel.Error),k)}),{topLeft:A,topRight:f,bottomLeft:E,bottomRight:d,top:m,bottom:L}}});module.exports=V;
//# sourceMappingURL=NeonAlert.cjs.js.map