@chief-editor/ui
Version:
UI Component for chief editor
1 lines • 1.25 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var util_1=require("@co-hooks/util"),react_1=require("react");function useSecondChildExpandAnimation(e,t){var i=react_1.useRef(!1),n=t.disabled,r=t.duration,h=void 0===r?400:r,d=t.expanded,o=t.ignoreInitialRender,a=void 0===o||o;return function(){if(!(a&&!i.current||n)){var t=function(i){handleAnimationTick(e.current,t,i,d)};t.bodyHeight=0,t.headHeight=0;var r=util_1.animate("linear",h,t),o=r[0],l=r[1];return o(),function(){t(1),l()}}i.current=!0}}function handleAnimationTick(e,t,i,n){if(e){if(!t.headHeight||!t.bodyHeight){if(!e.firstElementChild||!e.lastElementChild)return;t.headHeight=e.firstElementChild.getBoundingClientRect().height,t.bodyHeight=e.lastElementChild.getBoundingClientRect().height}n?i>=.5?e.style.removeProperty("height"):(i=util_1.presets.easeOut(2*i),e.style.setProperty("height",i*t.bodyHeight+t.headHeight+"px")):i>=1?e.style.removeProperty("height"):i>=.5?(i=util_1.presets.easeIn(2*(1-i)),e.style.setProperty("height",i*t.bodyHeight+t.headHeight+"px")):e.style.getPropertyValue("height")!==t.bodyHeight+t.headHeight+"px"&&e.style.setProperty("height",t.bodyHeight+t.headHeight+"px")}}exports.useSecondChildExpandAnimation=useSecondChildExpandAnimation;