@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 2.98 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{r as i,h as s,H as t}from"./index-CElQfBOC.js";import{w as o,A as e}from"./common-7RW_NFNf.js";import{v as a}from"./align-DoCRbhrp.js";import{v as h}from"./show-C_i9p0dk.js";import{a as l}from"./align-floating-elements-DcJPtpqg.js";import{c as r}from"./clsx-eK3rPvPS.js";import{d as n,K as c}from"./events-CoPFQEiC.js";const v=(e,t)=>{o(e,"_on",(e=>"object"==typeof e&&null!==e),new Set(["PopoverCallbacksPropType {Events.onClose}"]),t)},d=class{constructor(e){i(this,e),this.hidePopoverByEscape=e=>{"Escape"===e.key&&this.hidePopover(e)},this.hidePopoverByClickOutside=e=>{this.host&&!this.host.contains(e.target)&&this.hidePopover(e)},this.catchHostAndTriggerElement=e=>{e&&(this.host=e,this.triggerElement=e.previousElementSibling)},this.catchPopoverElement=e=>{this.popoverElement=e},this.catchArrowElement=e=>{this.arrowElement=e},this._align="top",this._show=!1,this.state={_align:"top",_on:{},_show:!1,_visible:!1}}async showPopover(){this.addListenersToBody(),this.triggerElement&&this.popoverElement&&(await l({align:this._align,referenceElement:this.triggerElement,arrowElement:this.arrowElement,floatingElement:this.popoverElement}),this.state=Object.assign(Object.assign({},this.state),{_visible:!0}))}hidePopover(e){var t,s,o;this.state=Object.assign(Object.assign({},this.state),{_visible:!1}),this._show=!1,null===(t=this.triggerElement)||void 0===t||t.focus(),this.removeListenersToBody(),null===(o=null===(s=this.state._on)||void 0===s?void 0:s.onClose)||void 0===o||o.call(s,e),this.host&&n(this.host,c.close)}addListenersToBody(){var t;const s=e().body;s.addEventListener("keyup",this.hidePopoverByEscape),s.addEventListener("click",this.hidePopoverByClickOutside),null===(t=document.scrollingElement)||void 0===t||t.addEventListener("scroll",(()=>{this.showPopover()}),{passive:!0})}removeListenersToBody(){var t;const s=e().body;s.removeEventListener("keyup",this.hidePopoverByEscape),s.removeEventListener("click",this.hidePopoverByClickOutside),null===(t=document.scrollingElement)||void 0===t||t.removeEventListener("scroll",(()=>{this.showPopover()}))}render(){return s(t,{key:"53179ace5c0dfabbe1dd00ba8ddfe453ef55ccd5",ref:this.catchHostAndTriggerElement,class:"kol-popover"},s("div",{key:"f42aafe81aaa0a09526b4e9923a96133ee81c5d2",class:r("kol-popover__content",{"kol-popover__content--visible":this.state._visible}),ref:this.catchPopoverElement,hidden:!this.state._show},s("div",{key:"25719436c820c214a2e3c0fac47449f842c4f68c",class:r("kol-popover__arrow",`kol-popover__arrow--${this.state._align}`),ref:this.catchArrowElement}),s("slot",{key:"fff04758761fb36389c6698b17730b604981ca66"})))}validateAlign(e){a(this,e)}validateOn(e){v(this,e)}validateShow(e){h(this,e),e&&this.showPopover()}componentWillLoad(){this.validateAlign(this._align),this.validateShow(this._show)}static get watchers(){return{_align:["validateAlign"],_on:["validateOn"],_show:["validateShow"]}}};export{d as kol_popover_wc};