@postnord/web-components
Version:
PostNord Web Components
5 lines • 1.32 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
import"@stencil/core/internal/client";import{r as i}from"./helpers.js";function t(t){return class extends t{constructor(){super()}animation;animationDurationDefault=400;animationDuration=this.animationDurationDefault;isClosing=!1;isExpanding=!1;animateDropdown(i,t,s,n){this.cancelAnimations(),this.setAnimationDuration(),i.dataset.moving="",this.animation=i.animate({height:[s,n]},{duration:this.animationDuration,easing:"cubic-bezier(0.6, 0, 0.2, 1)"}),this.animation.onfinish=()=>this.animationFinish(i),this.animation.oncancel=()=>t?this.isExpanding=!1:this.isClosing=!1}openDropdown(i,t){const{clientHeight:s,scrollHeight:n}=i,h=this.isClosing?s:0;i.style.height=`${n}px`,this.isExpanding=!0,this.animateDropdown(i,!0,`${h}px`,`${t||i.scrollHeight}px`)}closeDropdown(i,t){const{scrollHeight:s,clientHeight:n}=i,h=this.isExpanding?n:s;i.style.height="0px",this.isClosing=!0,this.animateDropdown(i,!1,`${t||h}px`,"0px")}animationFinish(i){this.cancelAnimations(),i.style.height=this.isClosing?"0px":"",delete i.dataset.moving,this.isClosing=!1,this.isExpanding=!1}cancelAnimations(){this.animation&&this.animation.cancel()}setAnimationDuration(){this.animationDuration=i()?0:this.animationDurationDefault}isMoving(){return this.isClosing||this.isExpanding}}}export{t as a}