UNPKG

@coveord/plasma-mantine

Version:

A Plasma flavoured Mantine theme

26 lines (21 loc) 864 B
import {MutableRefObject, useEffect, useRef, useState} from 'react'; const getElementInnerHeight = (el: HTMLElement): number => { 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 = (): [number, MutableRefObject<HTMLDivElement>] => { const [height, setHeight] = useState(-1); const ref = useRef<HTMLDivElement>(); useEffect(() => { if (ref.current) { setHeight(getElementInnerHeight(ref.current.parentElement)); } }, [ref.current]); return [height, ref]; };