UNPKG

5.83 kBSource Map (JSON)View Raw
1{"version":3,"file":"native-toast.min.js","sources":["../node_modules/nano-assign/dist/nano-assign.common.js","../src/js/index.js"],"sourcesContent":["/*!\n * nano-assign v1.0.0\n * (c) 2017-present egoist <0x142857@gmail.com>\n * Released under the MIT License.\n */\n'use strict';\n\nvar index = function(obj) {\n var arguments$1 = arguments;\n\n for (var i = 1; i < arguments.length; i++) {\n // eslint-disable-next-line guard-for-in, prefer-rest-params\n for (var p in arguments[i]) { obj[p] = arguments$1[i][p]; }\n }\n return obj\n};\n\nmodule.exports = index;\n","import assign from 'nano-assign'\n\nlet prevToast = null\n\nconst icons = {\n warning: `<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-alert-circle\"><circle cx=\"12\" cy=\"12\" r=\"10\"></circle><line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"12\"></line><line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"16\"></line></svg>`,\n success: `<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-check-circle\"><path d=\"M22 11.08V12a10 10 0 1 1-5.93-9.14\"></path><polyline points=\"22 4 12 14.01 9 11.01\"></polyline></svg>`,\n info: `<svg viewBox=\"0 0 32 32\" width=\"32\" height=\"32\" fill=\"none\" stroke=\"currentcolor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"6.25%\"><path d=\"M16 14 L16 23 M16 8 L16 10\" /><circle cx=\"16\" cy=\"16\" r=\"14\" /></svg>`,\n error: `<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-alert-triangle\"><path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\"></path><line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\"></line><line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\"></line></svg>`\n}\n\nclass Toast {\n constructor({\n message = '',\n position = 'south-east',\n timeout = 3000,\n el = document.body,\n rounded = false,\n type = '',\n debug = false,\n edge = false,\n icon = true,\n closeOnClick = false,\n elements = []\n } = {}) {\n if (prevToast) {\n prevToast.destroy()\n }\n\n this.message = message\n this.position = position\n this.el = el\n this.timeout = timeout\n this.closeOnClick = closeOnClick\n\n this.toast = document.createElement('div')\n this.toast.className = `native-toast native-toast-${this.position}`\n\n if (type) {\n this.toast.className += ` native-toast-${type}`\n\n if (icon) {\n this.message = `<span class=\"native-toast-icon-${type}\">${icons[type] || ''}</span>${this.message}`\n }\n }\n\n const messageElement = document.createElement('div')\n messageElement.className = 'native-toast-message'\n messageElement.innerHTML = this.message\n\n ;[messageElement, ...elements].forEach(el => {\n this.toast.appendChild(el)\n })\n\n const isMobile = document.body.clientWidth < 768\n if (edge || isMobile) {\n this.toast.className += ' native-toast-edge'\n } else if (rounded) {\n this.toast.style.borderRadius = '33px'\n }\n\n this.el.appendChild(this.toast)\n\n prevToast = this\n\n this.show()\n if (!debug && timeout) {\n this.hide()\n }\n\n if (this.closeOnClick) {\n this.toast.addEventListener('click', () => {\n this.destroy()\n })\n }\n }\n\n show() {\n setTimeout(() => {\n this.toast.classList.add('native-toast-shown')\n }, 300)\n }\n\n hide() {\n setTimeout(() => {\n this.destroy()\n }, this.timeout)\n }\n\n destroy() {\n if (!this.toast) return\n\n this.toast.classList.remove('native-toast-shown')\n\n setTimeout(() => {\n if (this.toast) {\n this.el.removeChild(this.toast)\n this.toast = null\n }\n }, 300)\n }\n}\n\nfunction toast(options) {\n return new Toast(options)\n}\n\nfor (const type of ['success', 'info', 'warning', 'error']) {\n toast[type] = options => toast(assign({type}, options))\n}\n\nexport default toast\n\n"],"names":["obj","arguments$1","arguments","i","length","p","prevToast","icons","Toast","ref","document","body","destroy","message","position","el","timeout","closeOnClick","toast","createElement","className","this","type","icon","messageElement","innerHTML","elements","forEach","appendChild","isMobile","clientWidth","edge","rounded","style","borderRadius","show","debug","hide","addEventListener","options","classList","add","remove","removeChild","const","assign"],"mappings":"uLAOA,MAAY,SAASA,GAGnB,IAFA,IAAIC,EAAcC,UAETC,EAAI,EAAGA,EAAID,UAAUE,OAAQD,IAEpC,IAAK,IAAIE,KAAKH,UAAUC,GAAMH,EAAIK,GAAKJ,EAAYE,GAAGE,GAExD,OAAOL,GCZLM,EAAY,KAEVC,WACM,yUACA,6SACH,6OACC,sYAGJC,WACQC,gEACA,oCACC,6CACD,+BACLC,SAASC,sCACJ,+BACH,kCACC,gCACD,gCACA,wCACQ,uCAGXL,KACQM,eAGPC,QAAUA,OACVC,SAAWA,OACXC,GAAKA,OACLC,QAAUA,OACVC,aAAeA,OAEfC,MAAQR,SAASS,cAAc,YAC/BD,MAAME,UAAa,6BAA4BC,KAAc,SAE9DC,SACGJ,MAAME,WAAc,iBAAgBE,EAErCC,SACGV,QAAW,kCAAiCS,QAASf,EAAMe,IAAS,cAAYD,KAAa,cAIhGG,EAAiBd,SAASS,cAAc,SAC/BC,UAAY,yBACZK,UAAYJ,KAAKR,SAE9BW,UAAmBE,GAAUC,iBAAQZ,KAChCG,MAAMU,YAAYb,SAGnBc,EAAWnB,SAASC,KAAKmB,YAAc,IACzCC,GAAQF,OACLX,MAAME,WAAa,qBACfY,SACJd,MAAMe,MAAMC,aAAe,aAG7BnB,GAAGa,YAAYP,KAAKH,SAEbG,UAEPc,QACAC,GAASpB,QACPqB,OAGHhB,KAAKJ,mBACFC,MAAMoB,iBAAiB,qBACrB1B,aA+Bb,SAASM,EAAMqB,UACN,IAAI/B,EAAM+B,GA3BjBJ,+DAESjB,MAAMsB,UAAUC,IAAI,uBACxB,MAGLJ,+DAESzB,WACJS,KAAKL,UAGVJ,0CACOS,KAAKH,aAELA,MAAMsB,UAAUE,OAAO,4CAGtBrB,EAAKH,UACFH,GAAG4B,YAAYtB,EAAKH,SACpBA,MAAQ,OAEd,OAQP,IAAK0B,IAAMtB,KAAS,UAAW,OAAQ,UAAW,WAC1CA,YAAQiB,UAAWrB,EAAM2B,WAAeN"}
\No newline at end of file