@chief-editor/ui
Version:
UI Component for chief editor
1 lines • 826 B
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var use_1=require("@rc-hooks/use"),react_1=require("react");function useModalHeight(e){var t=use_1.useShallowState(void 0),i=t[0],a=t[1],h=e.height,r=e.minHeight,u=e.maxHeight,n=use_1.useRefGetter({height:parseHeight(h),minHeight:parseHeight(r),maxHeight:parseHeight(u)});return{height:i,containerResize:react_1.useCallback((function(e){var t=n(),i=calcHeight(t.maxHeight,e.height,1/0),h=calcHeight(t.minHeight,e.height,0),r=calcHeight(t.height,e.height,1/0);a((function(){var e=Math.min(Math.max(r,h),Math.max(i,h));return e===1/0?void 0:e}))}),[])}}function parseHeight(e){return null==e?null:"number"==typeof e?e:e.indexOf("%")>0?parseFloat(e)/100:parseFloat(e)}function calcHeight(e,t,i){return null==e?i:e<=1?t*e:e}exports.useModalHeight=useModalHeight;