@flexilla/collapsible
Version:
A utility for creating collapsible sections in web applications, conserving space and improving user experience.
1 lines • 642 B
JavaScript
import{afterTransition as e}from"@flexilla/utilities";const t=(e,t)=>{e.setAttribute(`aria-hidden`,t===`open`?`false`:`true`),e.setAttribute(`data-state`,t)},n=(e,n=`close`,r=`0px`)=>{e.style.height=n===`open`?`auto`:r,t(e,n)},r=n=>{if(n.getAttribute(`data-state`)===`open`)return;t(n,`open`);let r=n.scrollHeight;n.style.height=`${r}px`,e({element:n,callback:()=>{n.getAttribute(`data-state`)===`open`&&(n.style.height=`auto`)}})},i=(e,n=`0px`)=>{e.getAttribute(`data-state`)!==`close`&&(e.style.height=`${e.scrollHeight}px`,e.offsetHeight,e.style.height=n,t(e,`close`))};export{i as collapseElement,r as expandElement,n as initCollapsible};