@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
39 lines (38 loc) • 1.32 kB
JavaScript
;
"use client";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useStepAnimation;
var _react = require("react");
var _useIsomorphicLayoutEffect = require("../../../../shared/helpers/useIsomorphicLayoutEffect.js");
function useStepAnimation({
activeIndexRef,
stepElementRef,
executeLayoutAnimationRef
}) {
const activeIndex = activeIndexRef.current;
const indexRef = (0, _react.useRef)(activeIndex);
(0, _react.useEffect)(() => {
indexRef.current = activeIndex;
}, [activeIndex]);
const executeLayoutAnimation = (0, _react.useCallback)(() => {
window.requestAnimationFrame(() => {
try {
const elements = stepElementRef.current.querySelectorAll('.dnb-forms-step > *, .dnb-forms-button-row > *');
elements.forEach((element, i) => {
element.style.setProperty('--element-index', String(i + 1));
element.classList.add('appear-fx');
});
} catch (error) {}
});
}, [stepElementRef]);
executeLayoutAnimationRef.current = executeLayoutAnimation;
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
if (activeIndex === indexRef.current) {
return;
}
executeLayoutAnimation();
}, [activeIndex, executeLayoutAnimation]);
}
//# sourceMappingURL=useStepAnimation.js.map