UNPKG

@govbr-ds/core

Version:

Padrão Digital de Governo

2 lines 3.53 kB
!function t(e,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define("core",[],i):"object"==typeof exports?exports.core=i():e.core=i()}(self,(()=>(()=>{var t=()=>{},e,i=()=>{};(()=>{class t{constructor(t,e){this.name=t,this.component=e,this.activator=e.previousSibling.previousSibling;const i=e.getAttribute("place"),o=["top","right","bottom","left"];this.popover=e.hasAttribute("popover"),this.notification=e.classList.contains("br-notification"),this.timer=e.getAttribute("timer");const s=this.notification?"bottom":"top";this.active=e.hasAttribute("active"),this.placement=o.includes(i)?i:s,this.popperInstance=null,this.showEvents=["mouseenter","click","focus"],this.hideEvents=["mouseleave","blur"],this.closeTimer=null,this._create(),this._setBehavior()}_setBehavior(){if(this.activator&&this.showEvents.forEach((t=>{this.activator.addEventListener(t,(t=>{this._show(t)}))})),this.popover){const t=undefined;this.component.querySelector(".close").addEventListener("click",(t=>{this._hide(t,this.component),this._toggleActivatorIcon()}))}else this.hideEvents.forEach((t=>{this.activator.addEventListener(t,(t=>{this._hide(t,this.component)}))}))}_create(){if(this._setLayout(),this.notification)this.component.setAttribute("notification",""),this.popperInstance=createPopper(this.activator,this.component,{modifiers:[{name:"offset",options:{offset:[0,10]}},{name:"preventOverflow",options:{altAxis:!1,mainAxis:!0}}],placement:this.placement,strategy:"fixed"});else{let t=new DOMRect;const e=new DOMRect;t=this.activator.getBoundingClientRect();const i=document.body.clientWidth;"right"===this.placement&&(this.placement=t.x+t.width+e.width>i?"top":this.placement),"left"===this.placement&&(this.placement=t.x-e.width>0?this.placement:"top"),this.popperInstance=createPopper(this.activator,this.component,{modifiers:[{name:"offset",options:{offset:[0,8]}},{name:"preventOverflow",options:{altAxis:!0,mainAxis:!0,tether:!1}}],placement:this.placement})}}_show(t){this.component.style.display="unset",this.component.setAttribute("data-show",""),this.component.style.zIndex=99,this._fixPosition(),this.component.style.visibility="visible",this.timer&&(clearTimeout(this.closeTimer),this.closeTimer=setTimeout(this._hide,this.timer,t,this.component))}_hide(t,e){e.removeAttribute("data-show"),e.style.zIndex=-1,e.style.visibility="hidden",clearTimeout(e.closeTimer)}_setLayout(){const t=document.createElement("div");if(t.setAttribute("data-popper-arrow",""),this.component.querySelectorAll(".arrow").length<1&&t.classList.add("arrow"),this.component.appendChild(t),this.popover){const t=document.createElement("button");t.setAttribute("type","button"),t.classList.add("close");const e=document.createElement("i");e.classList.add("fas","fa-times"),t.appendChild(e),this.component.appendChild(t)}}_toggleActivatorIcon(){const t=this.activator.querySelector("button svg");t&&(t.classList.toggle("fa-angle-down"),t.classList.toggle("fa-angle-up")),this.activator.toggleAttribute("active")}_fixPosition(){this.notification&&setTimeout((()=>{const t=this.activator.getBoundingClientRect();this.component.style=`position: fixed !important; top: ${t.top+t.height+10}px !important; left: auto; right: 8px; display: unset; bottom: auto;`,this.component.querySelector(".arrow").style=`position: absolute; left: auto; right: ${document.body.clientWidth-t.right+t.width/5}px !important;`}),10)}}var e=null})(),t();var o={};return i(),o})())); //# sourceMappingURL=tooltip.min.js.map