@hakit/components
Version:
A series of components to work with @hakit/core
3 lines (2 loc) • 1.57 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("../../../emotion-react-jsx-runtime.browser.esm-D6BfYa4f.cjs"),u=require("react"),x=({isOpen:s,children:g,duration:i=300,className:y,style:R,onCollapseComplete:a})=>{const h=u.useRef(null),[c,l]=u.useState(s),[d,o]=u.useState(!0),m=u.useRef(!1),t=u.useRef(null),r=u.useRef(null),n=u.useRef(!1);return u.useLayoutEffect(()=>{const e=h.current;if(e){if(t.current&&(clearTimeout(t.current),t.current=null),r.current&&(cancelAnimationFrame(r.current),r.current=null),!m.current){m.current=!0,s?(l(!0),o(!1),e.style.height="auto",n.current=!1):(l(!1),n.current=!1);return}if(!n.current){if(s){if(c&&e.style.height==="auto")return;n.current=!0,l(!0),e.style.height="0px",r.current=requestAnimationFrame(()=>{const f=e.scrollHeight;o(!0),e.style.transition=`height ${i}ms ease`,e.style.height=`${f}px`,t.current=setTimeout(()=>{e.style.transition="",e.style.height="auto",n.current=!1,t.current=null},i)})}else{if(!c)return;n.current=!0;const f=e.scrollHeight;e.style.height=`${f}px`,r.current=requestAnimationFrame(()=>{o(!0),e.style.transition=`height ${i}ms ease`,e.style.height="0px",t.current=setTimeout(()=>{l(!1),n.current=!1,t.current=null,a&&a()},i)})}return()=>{t.current&&(clearTimeout(t.current),t.current=null),r.current&&(cancelAnimationFrame(r.current),r.current=null),n.current=!1}}}},[s,i,a,c]),A.jsx("div",{ref:h,className:y,style:{overflow:"hidden",height:s&&!d?"auto":void 0,...R},children:c?g:null})};exports.AutoHeight=x;
//# sourceMappingURL=index.js.map