@wikimedia/codex
Version:
Codex Design System for Wikimedia
2 lines (1 loc) • 1.74 kB
JavaScript
;var z=Object.defineProperty,D=Object.defineProperties;var S=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var h=(o,e,t)=>e in o?z(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,a=(o,e)=>{for(var t in e||(e={}))$.call(e,t)&&h(o,t,e[t]);if(g)for(var t of g(e))j.call(e,t)&&h(o,t,e[t]);return o},u=(o,e)=>D(o,S(e));const d=require("vue"),r=d.reactive({toasts:[]}),f=new Map,q=d.ref(!1),A=d.ref(!1);function E(){const o=d.useId(),e={value:0};function t(n){const{message:s,contentRef:i,type:c,icon:C,actionButton:U,preventUserDismiss:l,autoDismiss:p,onUserDismissed:b,onAutoDismissed:x}=n;if(s===void 0&&!i)throw new Error("Toast: provide either message or contentRef in options.");const T="".concat(o,"-").concat(e.value++);return i&&f.set(T,i),r.toasts.push({id:T,message:s,type:c!=null?c:"notice",icon:C,actionButton:U,autoDismiss:p!=null?p:!1,preventUserDismiss:l!=null?l:!1,onUserDismissed:b,onAutoDismissed:x}),T}function I(n){const s=r.toasts.findIndex(i=>i.id===n);s!==-1&&(r.toasts.splice(s,1),f.delete(n))}function v(n,s){const i=r.toasts.find(c=>c.id===n);i&&Object.assign(i,s)}function w(){r.toasts.length=0,f.clear()}function y(n,s={}){return t(u(a({},s),{message:n,type:"success"}))}function R(n,s={}){return t(u(a({},s),{message:n,type:"error"}))}function m(n,s={}){return t(u(a({},s),{message:n,type:"notice"}))}function B(n,s={}){return t(u(a({},s),{message:n,type:"warning"}))}return{show:t,dismiss:I,update:v,clear:w,success:y,error:R,info:m,warning:B}}exports.contentRefsById=f;exports.isToastContainerInitialized=A;exports.isUserTouchingToastRef=q;exports.toastStore=r;exports.useToast=E;