+export function transitionHeight(element, animTime = 400) {
+ const startHeight = element.getBoundingClientRect().height;
+ const initialComputedStyles = getComputedStyle(element);
+ const startPaddingTop = initialComputedStyles.getPropertyValue('padding-top');
+ const startPaddingBottom = initialComputedStyles.getPropertyValue('padding-bottom');
+
+ return () => {
+ cleanupExistingElementAnimation(element);
+ const targetHeight = element.getBoundingClientRect().height;
+ const computedStyles = getComputedStyle(element);
+ const targetPaddingTop = computedStyles.getPropertyValue('padding-top');
+ const targetPaddingBottom = computedStyles.getPropertyValue('padding-bottom');
+ const animStyles = {
+ height: [`${startHeight}px`, `${targetHeight}px`],
+ overflow: ['hidden', 'hidden'],
+ paddingTop: [startPaddingTop, targetPaddingTop],
+ paddingBottom: [startPaddingBottom, targetPaddingBottom],
+ };
+
+ animateStyles(element, animStyles, animTime);
+ };
+}