lemur-react
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -13,2 +13,3 @@ export * from './src/Display.js'; | ||
export * from './src/useNavigation.js'; | ||
export * from './src/useTargetHeight.js'; | ||
export * from './src/useTimeout.js'; | ||
@@ -15,0 +16,0 @@ export * from './src/useViewportRatio.js'; |
@@ -340,2 +340,26 @@ import { useMemo, useEffect, useState, useRef, useCallback } from "react"; | ||
} | ||
const calculateTargetHeight = (node) => { | ||
const assign = node; | ||
const currentHeight = node.offsetHeight; | ||
assign.style.height = "auto"; | ||
const targetHeight = node.offsetHeight; | ||
assign.style.height = `${String(currentHeight)}px`; | ||
return targetHeight; | ||
}; | ||
function useTargetHeight(ref, active) { | ||
const [targetHeight, setTargetHeight] = useState(0); | ||
const updateTargetHeight = useCallback(() => { | ||
if (ref.current) { | ||
const newTargetHeight = calculateTargetHeight(ref.current); | ||
setTargetHeight(newTargetHeight); | ||
} | ||
}, [ref]); | ||
useEffect(() => { | ||
if (active) { | ||
updateTargetHeight(); | ||
} | ||
return void 0; | ||
}, [ref, updateTargetHeight, active]); | ||
return { targetHeight, updateTargetHeight }; | ||
} | ||
export { | ||
@@ -354,2 +378,3 @@ Display, | ||
useNavigation, | ||
useTargetHeight, | ||
useTimeout, | ||
@@ -356,0 +381,0 @@ useViewportRatio, |
{ | ||
"name": "lemur-react", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "React utils based on unpublished work for the LemurCMS rewritten in Typescript", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46234
37
467