@coveord/plasma-mantine
Version:
A Plasma flavoured Mantine theme
28 lines (27 loc) • 871 B
JavaScript
import { useEffect, useRef, useState } from 'react';
const getElementInnerHeight = (el)=>{
if (!el) {
return -1;
}
const fullHeight = el.getBoundingClientRect().height;
const cs = getComputedStyle(el);
const padding = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom);
const border = parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth);
return fullHeight - padding - border;
};
/**
* Computes the available height of the parent element on mount
*/ export const useParentHeight = ()=>{
const [height, setHeight] = useState(-1);
const ref = useRef(null);
useEffect(()=>{
if (ref.current?.parentElement) {
setHeight(getElementInnerHeight(ref.current.parentElement));
}
}, []);
return [
height,
ref
];
};
//# sourceMappingURL=useParentHeight.js.map