height-transition
Version:
Simple height transition for collapse elements.
3 lines (2 loc) • 988 B
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.heightTransition=t(e.react)}(this,function(e){var t="default"in e?e.default:e;return function(n){var r=e.useRef(null),i=function(){r.current.style.height=r.current.scrollHeight+"px",0!==r.current.clientHeight&&(r.current.style.height="0px")};e.useEffect(function(){return r.current.style.height="auto",r.current.style.overflow="hidden",r.current.style.transition="height "+(n.time?n.time:"300ms")+" "+(n.animation?n.animation:"ease"),window.addEventListener("transitionend",c),n.toggle.current.addEventListener("click",i),function(){window.removeEventListener("transitionend",c),n.toggle.current.removeEventListener("click",i)}});var c=function(){0!==r.current.clientHeight&&(r.current.style.height="auto")};return t.createElement("div",{style:n.styles,ref:r},n.children)}});
//# sourceMappingURL=heightTransition.umd.js.map