UNPKG

@freshworks/crayons

Version:
1 lines 1.88 kB
import{c as cloneNodeWithEvents}from"./index-04e9b0fa.js";function createToastStack(t){if(!Object.prototype.hasOwnProperty.call(window,"fwRemoveToast"))window.addEventListener("fwRemoveToast",removeChildToast);var e=document.querySelector(".fw-toast-stack."+t.position);var o;if(e){o=e}else{o=document.createElement("div");o.className="fw-toast-stack "+t.position;o.style.cssText="position: fixed;\n z-index: 950;\n top: 10px;\n "+getStylePosition(t.position)+"\n background-color: $color-milk;\n max-width: 100%;\n max-height: 100%;";document.body.appendChild(o)}return o}function createToastNotification(t,e,o){if(t===void 0){t={}}var n=getProps(t,o);var i;if(t.contentref){var a=document.querySelector(t.contentref);i=cloneNodeWithEvents(a,true,true);n.content=""}else{i=document.createElement("fw-toast-message")}Object.entries(n).map((function(t){var e=t[0],o=t[1];if(o)i.setAttribute(kebabCase(e),o)}));e.appendChild(i)}function getStylePosition(t){switch(t){case"top-left":return"left: 10px;";case"top-right":return"right: 10px;";case"top-center":return"left: calc(50% - 200px);"}}function removeChildToast(t){var e=t.target;document.querySelectorAll(".fw-toast-stack").forEach((function(t){if(t.contains(e)){t.removeChild(e)}}))}function getProps(t,e){if(t===void 0){t={}}var o,n,i,a,c,r;var s=Object.assign({},{timeout:(o=t.timeout)!==null&&o!==void 0?o:e.timeout,type:(n=t.type)!==null&&n!==void 0?n:e.type,content:(i=t.content)!==null&&i!==void 0?i:e.content,actionLinkText:(a=t.actionLinkText)!==null&&a!==void 0?a:e.actionLinkText,sticky:(c=t.sticky)!==null&&c!==void 0?c:e.sticky,pauseOnHover:(r=t.pauseOnHover)!==null&&r!==void 0?r:e.pauseOnHover,open:true});return s}function kebabCase(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}export{createToastNotification as a,createToastStack as c};