Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / lib / codex / modules / CdxMessage.cjs
blobbb0dab219f79ea9c2992a6bb59e1ea8454847807
1 "use strict";const s=require("vue"),t=require("./Icon.js"),f=require("./CdxButton.cjs"),v=require("./constants.js"),y=require("./useI18nWithOverride.js"),g=require("./_plugin-vue_export-helper.js"),p={notice:t.j4,error:t.p4,warning:t.H3,success:t.G7},C=s.defineComponent({name:"CdxMessage",components:{CdxButton:f,CdxIcon:t.CdxIcon},props:{type:{type:String,default:"notice",validator:v.statusTypeValidator},inline:{type:Boolean,default:!1},icon:{type:[String,Object],default:null},fadeIn:{type:Boolean,default:!1},allowUserDismiss:{type:Boolean,default:!1},dismissButtonLabel:{type:String,default:""},autoDismiss:{type:[Boolean,Number],default:!1,validator:e=>typeof e=="boolean"||typeof e=="number"&&e>0}},emits:["user-dismissed","auto-dismissed"],setup(e,{emit:i}){const o=s.ref(!1),a=s.computed(()=>e.inline===!1&&(e.dismissButtonLabel.length>0||e.allowUserDismiss)),d=y.useI18nWithOverride(s.toRef(e,"dismissButtonLabel"),"cdx-message-dismiss-button-label","Close"),l=s.computed(()=>e.autoDismiss===!1||e.type==="error"?!1:e.autoDismiss===!0?4e3:e.autoDismiss),n=s.computed(()=>({"cdx-message--inline":e.inline,"cdx-message--block":!e.inline,"cdx-message--user-dismissable":a.value,["cdx-message--".concat(e.type)]:!0})),c=s.computed(()=>e.icon&&e.type==="notice"?e.icon:p[e.type]),r=s.ref("");function u(m){o.value||(r.value=m==="user-dismissed"?"cdx-message-leave-active-user":"cdx-message-leave-active-system",o.value=!0,i(m))}return s.onMounted(()=>{e.type==="error"&&e.autoDismiss!==!1?s.warn('CdxMessage: Message with type="error" cannot use auto-dismiss'):l.value&&setTimeout(()=>u("auto-dismissed"),l.value)}),{dismissed:o,userDismissable:a,translatedDismissButtonLabel:d,rootClasses:n,leaveActiveClass:r,computedIcon:c,onDismiss:u,cdxIconClose:t._3}}}),b=["aria-live","role"],x={class:"cdx-message__content"};function B(e,i,o,a,d,l){const n=s.resolveComponent("cdx-icon"),c=s.resolveComponent("cdx-button");return s.openBlock(),s.createBlock(s.Transition,{name:"cdx-message",appear:e.fadeIn,"leave-active-class":e.leaveActiveClass},{default:s.withCtx(()=>[e.dismissed?s.createCommentVNode("v-if",!0):(s.openBlock(),s.createElementBlock("div",{key:0,class:s.normalizeClass(["cdx-message",e.rootClasses]),"aria-live":e.type!=="error"?"polite":void 0,role:e.type==="error"?"alert":void 0},[s.createVNode(n,{class:"cdx-message__icon--vue",icon:e.computedIcon},null,8,["icon"]),s.createElementVNode("div",x,[s.renderSlot(e.$slots,"default")]),e.userDismissable?(s.openBlock(),s.createBlock(c,{key:0,class:"cdx-message__dismiss-button",weight:"quiet",type:"button","aria-label":e.translatedDismissButtonLabel,onClick:i[0]||(i[0]=r=>e.onDismiss("user-dismissed"))},{default:s.withCtx(()=>[s.createVNode(n,{icon:e.cdxIconClose},null,8,["icon"])]),_:1},8,["aria-label"])):s.createCommentVNode("v-if",!0)],10,b))]),_:3},8,["appear","leave-active-class"])}const _=g._export_sfc(C,[["render",B]]);module.exports=_;