UNPKG

@chief-editor/ui

Version:

UI Component for chief editor

1 lines 734 B
import{useRefGetter,useShallowState}from"@rc-hooks/use";import{useCallback}from"react";export function useModalHeight(e){var t=useShallowState(void 0),i=t[0],h=t[1],a=e.height,r=e.minHeight,n=e.maxHeight,g=useRefGetter({height:parseHeight(a),minHeight:parseHeight(r),maxHeight:parseHeight(n)});return{height:i,containerResize:useCallback((function(e){var t=g(),i=calcHeight(t.maxHeight,e.height,1/0),a=calcHeight(t.minHeight,e.height,0),r=calcHeight(t.height,e.height,1/0);h((function(){var e=Math.min(Math.max(r,a),Math.max(i,a));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}