@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 4.89 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{r as i,h as t,H as s,g as e}from"./index-136f59ac.js";import{b as h,a}from"./align-floating-elements-14bb4167.js";import{A as o,g as n}from"./index-88dea7b1.js";import"./i18n-01abf777.js";import"./bem-e4c3a2e6.js";import{K as l}from"./Span-89b9ae45.js";import{v as d}from"./align-a05c3d17.js";import{v as r}from"./label-5982d241.js";import"./i18n-45224cc3.js";import"./browser-f629a56a.js";import"./tslib.es6-1173d062.js";import"./clsx-09a06a12.js";import"./Icon-faa6cbca.js";import"./component-names-799e91e2.js";import"./markdown-f827f2ac.js";import"./InternalUnderlinedBadgeText-2e08c7cb.js";import"./isArray-7a60fa7f.js";import"./isObject-ffcbbb76.js";const c=(t,e)=>{o(t,"_badgeText",e)},f=(t,e)=>{o(t,"_id",e)},m=new Set;function b(t){m.forEach((t=>{t.style.setProperty("z-index","999")})),m.add(t),t.style.setProperty("z-index","1000")}function u(t){if(m.delete(t),m.size>0){const t=Array.from(m).pop();t&&t.style.setProperty("z-index","1000")}}const p=class{constructor(t){i(this,t),this.hasFocusIn=!1,this.hasMouseIn=!1,this.showTooltip=()=>{if(this.previousSibling&&this.tooltipElement){b(this.tooltipElement),this.tooltipElement.style.setProperty("display","block"),n().addEventListener("keyup",this.hideTooltipByEscape);const t=this.previousSibling,e=this.tooltipElement;this.cleanupAutoPositioning=h(t,e,(()=>{this.alignTooltip()}))}},this.hideTooltip=()=>{this.tooltipElement&&(u(this.tooltipElement),this.tooltipElement.style.setProperty("display","none"),this.tooltipElement.style.setProperty("visibility","hidden"),this.cleanupAutoPositioning&&(this.cleanupAutoPositioning(),this.cleanupAutoPositioning=void 0)),n().removeEventListener("keyup",this.hideTooltipByEscape)},this.hideTooltipByEscape=t=>{"Escape"===t.key&&this.hideTooltip()},this.addListeners=t=>{t.addEventListener("mouseenter",this.handleMouseEnter.bind(this)),t.addEventListener("mouseleave",this.handleMouseleave.bind(this)),t.addEventListener("focusin",this.handleFocusIn.bind(this)),t.addEventListener("focusout",this.handleFocusout.bind(this))},this.removeListeners=t=>{t.removeEventListener("mouseenter",this.handleMouseEnter.bind(this)),t.removeEventListener("mouseleave",this.handleMouseleave.bind(this)),t.removeEventListener("focusin",this.handleFocusIn.bind(this)),t.removeEventListener("focusout",this.handleFocusout.bind(this))},this.resyncListeners=(t,e,i=!1)=>{t&&this.removeListeners(t),e&&(i&&(this.previousSibling=e),this.addListeners(e))},this.catchTooltipElement=t=>{this.tooltipElement=t},this.catchArrowElement=t=>{this.arrowElement=t},this.showOrHideTooltip=()=>{clearTimeout(this.overFocusTimeout),this.overFocusTimeout=setTimeout((()=>{this.hasMouseIn||this.hasFocusIn?this.showTooltip():this.hideTooltip()}),300)},this._badgeText=void 0,this._align="top",this._id=void 0,this._label=void 0,this.state={_align:"top",_label:""}}async alignTooltip(){this.tooltipElement&&this.previousSibling&&await a({align:this._align,referenceElement:this.previousSibling,arrowElement:this.arrowElement,floatingElement:this.tooltipElement})}handleMouseEnter(){this.hasMouseIn=!0,this.showOrHideTooltip()}handleMouseleave(){this.hasMouseIn=!1,this.showOrHideTooltip()}handleFocusIn(){this.hasFocusIn=!0,this.showOrHideTooltip()}handleFocusout(){this.hasFocusIn=!1,this.showOrHideTooltip()}render(){return t(s,{key:"4852834fc19a0047920d45f7c571d81a99d0dcbe",class:"kol-tooltip"},""!==this.state._label&&t("div",{key:"2bdc1f7dfc7f7de90dcd3a37375b01daa4d78c79",class:"kol-tooltip__floating",ref:this.catchTooltipElement},t("div",{key:"0a029ee8f29d29f589873a7ce03630efcbb17b09",class:"kol-tooltip__arrow",ref:this.catchArrowElement}),t(l,{key:"5410f3fc83be087594be5fd4009d3bf832fc5b23",class:"kol-tooltip__content",id:this.state._id,badgeText:this._badgeText,label:this.state._label})))}validateBadgeText(t){c(this,t)}validateAlign(t){d(this,t)}validateId(t){f(this,t)}validateLabel(t){r(this,t,{required:!0})}componentWillLoad(){this.validateBadgeText(this._badgeText),this.validateAlign(this._align),this.validateId(this._id),this.validateLabel(this._label)}handleEventListeners(){var t;this.resyncListeners(this.previousSibling,null===(t=this.host)||void 0===t?void 0:t.previousElementSibling,!0),this.resyncListeners(this.tooltipElement,this.tooltipElement)}connectedCallback(){var t;this.previousSibling=null===(t=this.host)||void 0===t?void 0:t.previousElementSibling}componentDidRender(){this.handleEventListeners()}disconnectedCallback(){this.previousSibling&&(this.removeListeners(this.previousSibling),this.previousSibling=void 0),this.tooltipElement&&this.removeListeners(this.tooltipElement),this.cleanupAutoPositioning&&this.cleanupAutoPositioning()}get host(){return e(this)}static get watchers(){return{_badgeText:["validateBadgeText"],_align:["validateAlign"],_id:["validateId"],_label:["validateLabel"]}}};export{p as kol_tooltip_wc};