UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue)

2 lines (1 loc) 5.7 kB
import t from"primevue/toasteventbus";import e from"primevue/ripple";import{resolveDirective as s,openBlock as n,createBlock as o,createVNode as a,toDisplayString as i,withDirectives as r,createCommentVNode as l,resolveComponent as m,Teleport as p,mergeProps as c,TransitionGroup as g,withCtx as d,Fragment as u,renderList as f}from"vue";import{DomHandler as h}from"primevue/utils";var x={emits:["close"],props:{message:null},closeTimeout:null,mounted(){this.message.life&&(this.closeTimeout=setTimeout((()=>{this.close()}),this.message.life))},methods:{close(){this.$emit("close",this.message)},onCloseClick(){this.closeTimeout&&clearTimeout(this.closeTimeout),this.close()}},computed:{containerClass(){return["p-toast-message",{"p-toast-message-info":"info"===this.message.severity,"p-toast-message-warn":"warn"===this.message.severity,"p-toast-message-error":"error"===this.message.severity,"p-toast-message-success":"success"===this.message.severity}]},iconClass(){return["p-toast-message-icon pi",{"pi-info-circle":"info"===this.message.severity,"pi-exclamation-triangle":"warn"===this.message.severity,"pi-times":"error"===this.message.severity,"pi-check":"success"===this.message.severity}]}},directives:{ripple:e}};const b={class:"p-toast-message-content"},y={class:"p-toast-message-text"},v={class:"p-toast-summary"},k={class:"p-toast-detail"},w=a("span",{class:"p-toast-icon-close-icon pi pi-times"},null,-1);x.render=function(t,e,m,p,c,g){const d=s("ripple");return n(),o("div",{class:g.containerClass,role:"alert","aria-live":"assertive","aria-atomic":"true"},[a("div",b,[a("span",{class:g.iconClass},null,2),a("div",y,[a("span",v,i(m.message.summary),1),a("div",k,i(m.message.detail),1)]),!1!==m.message.closable?r((n(),o("button",{key:0,class:"p-toast-icon-close p-link",onClick:e[1]||(e[1]=(...t)=>g.onCloseClick&&g.onCloseClick(...t)),type:"button"},[w],512)),[[d]]):l("",!0)])],2)};var C=0,T={inheritAttrs:!1,props:{group:{type:String,default:null},position:{type:String,default:"top-right"},autoZIndex:{type:Boolean,default:!0},baseZIndex:{type:Number,default:0}},data:()=>({messages:[]}),mounted(){t.on("add",(t=>{this.group==t.group&&this.add(t)})),t.on("remove-group",(t=>{this.group===t&&(this.messages=[])})),t.on("remove-all-groups",(()=>{this.messages=[]})),this.updateZIndex()},beforeUpdate(){this.updateZIndex()},methods:{add(t){null==t.id&&(t.id=C++),this.messages=[...this.messages,t]},remove(t){let e=-1;for(let s=0;s<this.messages.length;s++)if(this.messages[s]===t){e=s;break}this.messages.splice(e,1)},updateZIndex(){this.autoZIndex&&(this.$refs.container.style.zIndex=String(this.baseZIndex+h.generateZIndex()))}},components:{ToastMessage:x},computed:{containerClass(){return"p-toast p-component p-toast-"+this.position}}};!function(t,e){void 0===e&&(e={});var s=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===s&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}}("\n.p-toast {\n position: fixed;\n width: 25rem;\n}\n.p-toast-message-content {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: start;\n -ms-flex-align: start;\n align-items: flex-start;\n}\n.p-toast-message-text {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n}\n.p-toast-top-right {\n\ttop: 20px;\n\tright: 20px;\n}\n.p-toast-top-left {\n\ttop: 20px;\n\tleft: 20px;\n}\n.p-toast-bottom-left {\n\tbottom: 20px;\n\tleft: 20px;\n}\n.p-toast-bottom-right {\n\tbottom: 20px;\n\tright: 20px;\n}\n.p-toast-top-center {\n\ttop: 20px;\n left: 50%;\n margin-left: -10em;\n}\n.p-toast-bottom-center {\n\tbottom: 20px;\n\tleft: 50%;\n margin-left: -10em;\n}\n.p-toast-center {\n\tleft: 50%;\n\ttop: 50%;\n min-width: 20vw;\n -webkit-transform: translate(-50%, -50%);\n transform: translate(-50%, -50%);\n}\n.p-toast-icon-close {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n overflow: hidden;\n position: relative;\n}\n.p-toast-icon-close.p-link {\n\tcursor: pointer;\n}\n\n/* Animations */\n.p-toast-message-enter-from {\n opacity: 0;\n -webkit-transform: translateY(50%);\n transform: translateY(50%);\n}\n.p-toast-message-leave-from {\n max-height: 1000px;\n}\n.p-toast .p-toast-message.p-toast-message-leave-to {\n max-height: 0;\n opacity: 0;\n margin-bottom: 0;\n overflow: hidden;\n}\n.p-toast-message-enter-active {\n -webkit-transition: transform .3s, opacity .3s;\n -webkit-transition: opacity .3s, -webkit-transform .3s;\n transition: opacity .3s, -webkit-transform .3s;\n transition: transform .3s, opacity .3s;\n transition: transform .3s, opacity .3s, -webkit-transform .3s;\n}\n.p-toast-message-leave-active {\n -webkit-transition: max-height .45s cubic-bezier(0, 1, 0, 1), opacity .3s, margin-bottom .3s;\n transition: max-height .45s cubic-bezier(0, 1, 0, 1), opacity .3s, margin-bottom .3s;\n}\n"),T.render=function(t,e,s,i,r,l){const h=m("ToastMessage");return n(),o(p,{to:"body"},[a("div",c({ref:"container",class:l.containerClass},t.$attrs),[a(g,{name:"p-toast-message",tag:"div"},{default:d((()=>[(n(!0),o(u,null,f(r.messages,(t=>(n(),o(h,{key:t.id,message:t,onClose:e[1]||(e[1]=t=>l.remove(t))},null,8,["message"])))),128))])),_:1})],16)])};export default T;